Merge lp:~nik90/ubuntu-clock-app/clock-sunrise into lp:ubuntu-clock-app/saucy

Proposed by Nekhelesh Ramananthan
Status: Merged
Approved by: Nekhelesh Ramananthan
Approved revision: 51
Merged at revision: 49
Proposed branch: lp:~nik90/ubuntu-clock-app/clock-sunrise
Merge into: lp:ubuntu-clock-app/saucy
Diff against target: 319 lines (+206/-19)
4 files modified
clock/AnalogClockFace.qml (+115/-1)
clock/AnalogClockHand.qml (+1/-1)
clock/ClockPage.qml (+57/-17)
clock/ClockScript.js (+33/-0)
To merge this branch: bzr merge lp:~nik90/ubuntu-clock-app/clock-sunrise
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Ubuntu Clock Developers Pending
Review via email: mp+161350@code.launchpad.net

Commit message

Basic implementation of Clock Sunrise/Sunset Feature using OpenWeatherMap online API.

Description of the change

This MP is a basic implementation of Clock Sunrise/Sunset Feature. It uses the OpenWeatherMap API to get the Sunrise/Sunset times.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed file 'common/AnalogClockFace.qml' => 'clock/AnalogClockFace.qml'
2--- common/AnalogClockFace.qml 2013-04-11 19:49:04 +0000
3+++ clock/AnalogClockFace.qml 2013-05-01 13:19:25 +0000
4@@ -20,7 +20,11 @@
5
6 import QtQuick 2.0
7 import Ubuntu.Components 0.1
8+import QtQuick.XmlListModel 2.0
9+import "ClockScript.js" as Cscript
10 import "../common/Constants.js" as Constants
11+import "../common/ClockUtils.js" as Utils
12+import "../common"
13
14 AnalogFaceBase {
15 id: clockRoot
16@@ -32,6 +36,8 @@
17 property alias hourHandRect: hourHand
18 property alias minuteHandRect: minuteHand
19 property alias secondsHandRect: secondsHand
20+ property real latitude: 52.01;
21+ property real longitude: 4.35;
22
23 function timeChanged(now) {
24 hours = now.getHours()
25@@ -39,6 +45,10 @@
26 seconds = now.getUTCSeconds();
27 }
28
29+ function reloadSunRiseModel () {
30+ sunRiseModel.reload()
31+ }
32+
33 // "API" of the analog face
34 // say you want add a mousearea to one of the hands
35 // (e.g. when doing a timepicker), just do
36@@ -50,7 +60,18 @@
37 }
38 */
39
40- pulseGlow: false
41+ pulseGlow: true
42+
43+ // TODO: Get the latitude and longitude using the platform API automatically instead of using static values.
44+ XmlListModel {
45+ id: sunRiseModel
46+
47+ source: Cscript.getUrlString(latitude, longitude)
48+ query: "/current/city"
49+
50+ XmlRole { name: "sunrise"; query: "sun/@rise/string()"; isKey: true }
51+ XmlRole { name: "sunset"; query: "sun/@set/string()"; isKey: true }
52+ }
53
54 AnalogClockHand {
55 id: hourHand
56@@ -89,4 +110,97 @@
57 color: Constants.pitchBlack
58 }
59 }
60+
61+ MouseArea {
62+ anchors.fill: parent
63+ onClicked: {
64+ // Only show the sunrise/sunset times after the XmlListModel is Ready.
65+ if (sunRiseModel.status == 1) {
66+ clockRoot.state == "" ? clockRoot.state = "easteregg" : clockRoot.state = "";
67+ }
68+ else {
69+ Utils.log("Sunrise/Sunset times not yet loaded.")
70+ }
71+ }
72+ }
73+
74+ Rectangle {
75+ id: easterEggCircle;
76+
77+ width: parent.width; height: parent.height
78+ radius: parent.radius
79+ z: parent.z + 100
80+ antialiasing: parent.antialiasing
81+ anchors.centerIn: parent
82+ color: Constants.brightWhite
83+ opacity: 0
84+ visible: opacity == 0 ? false : true
85+
86+ Column {
87+ spacing: units.gu(1)
88+ anchors.centerIn: parent
89+ width: parent.width
90+
91+ Label {
92+ id: sunriseLabel
93+ anchors.horizontalCenter: parent.horizontalCenter
94+
95+ fontSize: "large"
96+ text: i18n.tr("Sunrise")
97+ }
98+
99+ Label {
100+ id: sunriseTimeLabel
101+ anchors.horizontalCenter: parent.horizontalCenter
102+
103+ fontSize: "x-large"
104+ text: "Default"
105+ }
106+
107+ Rectangle {
108+ id: sunsetsunriseDivider
109+ width: parent.width - units.gu(12)
110+ height: units.gu(1) / 2
111+ anchors.horizontalCenter: parent.horizontalCenter
112+
113+ color: Constants.normalGrey
114+ }
115+
116+ Label {
117+ id: sunsetTimeLabel
118+ width: parent.width
119+ horizontalAlignment: Text.AlignHCenter
120+
121+ fontSize: "x-large"
122+ text: "Default"
123+ }
124+
125+ Label {
126+ id: sunsetLabel
127+ width: parent.width
128+ horizontalAlignment: Text.AlignHCenter
129+
130+ fontSize: "large"
131+ text: i18n.tr("Sunset")
132+ }
133+
134+ }
135+ }
136+
137+ states: [
138+ State {
139+ name: "easteregg"
140+ PropertyChanges { target: clockRoot; isForeground: false; }
141+ PropertyChanges { target: easterEggCircle; opacity: 1; }
142+ // TODO: Do some caching of data here. Store data locally to reduce API calls.
143+ PropertyChanges { target: sunriseTimeLabel; text: Cscript.getSunTime(sunRiseModel.get(0).sunrise); }
144+ PropertyChanges { target: sunsetTimeLabel; text: Cscript.getSunTime(sunRiseModel.get(0).sunset); }
145+ },
146+ State {
147+ name: ""
148+ PropertyChanges { target: clockRoot; isForeground: true }
149+ PropertyChanges { target: easterEggCircle; opacity: 0; }
150+ }
151+
152+ ]
153 }
154
155=== renamed file 'common/AnalogClockHand.qml' => 'clock/AnalogClockHand.qml'
156--- common/AnalogClockHand.qml 2013-04-12 23:18:36 +0000
157+++ clock/AnalogClockHand.qml 2013-05-01 13:19:25 +0000
158@@ -19,7 +19,7 @@
159 */
160
161 import QtQuick 2.0
162-import "Constants.js" as Constants
163+import "../common/Constants.js" as Constants
164
165 Rectangle {
166 id: hand
167
168=== modified file 'clock/ClockPage.qml'
169--- clock/ClockPage.qml 2013-04-16 13:26:43 +0000
170+++ clock/ClockPage.qml 2013-05-01 13:19:25 +0000
171@@ -20,8 +20,10 @@
172
173 import QtQuick 2.0
174 import Ubuntu.Components 0.1
175+import Ubuntu.Components.Popups 0.1 as Popups
176 import "../common/ClockUtils.js" as Utils
177
178+
179 /*!
180 \brief ClockPage is a page that lives inside the "Clock"-tab of the application
181 */
182@@ -31,12 +33,11 @@
183 Utils.log("ClockPage loaded");
184 currentTimeFormatted = Qt.formatTime(new Date());
185 selectedLocation = "USER'S LOCATION TODO"
186+
187+ // Obtaining the sunrise/sunset times as soon as clock page is loaded.
188+ clockFace.reloadSunRiseModel()
189 }
190
191- // Currently loaded clock face filename
192- // TODO better enumeration to filename mapping
193- property string currentClockFaceFilename: "../common/AnalogClockFace.qml"
194-
195 // Property to hold the formatted time string to show on the screen
196 property string currentTimeFormatted
197
198@@ -50,8 +51,8 @@
199 function onTimerUpdate(now) {
200 currentTimeFormatted = Qt.formatTime(now);
201
202- // Tell currently loaded clockface that time has changed
203- clockFaceLoader.item.timeChanged(now);
204+ // Update time
205+ clockFace.timeChanged(now)
206 }
207
208 Label {
209@@ -67,17 +68,8 @@
210 text: currentTimeFormatted
211 }
212
213- // TODO: load from settings which clock face to display
214- // TODO: create digital clock face
215- Loader {
216- id: clockFaceLoader
217-
218- anchors.centerIn: parent
219- source: currentClockFaceFilename
220-
221- Component.onCompleted: {
222- Utils.log("Clock face loaded from " + source);
223- }
224+ AnalogClockFace {
225+ id: clockFace
226 }
227
228 Label {
229@@ -92,4 +84,52 @@
230 text: selectedLocation
231 }
232
233+ Component {
234+ id: locationDialogComponent
235+
236+ Popups.Dialog {
237+ id: dialog
238+ title: "Location information"
239+ text: "Enter your latitude and longtitude"
240+
241+ TextField {
242+ id: latitudeField
243+ width: parent.width/2
244+ placeholderText: 'latitude'
245+ }
246+
247+ TextField {
248+ id: longitudeField
249+ width: parent.width/2
250+ placeholderText: 'longitude'
251+ }
252+
253+ Button {
254+ id: goButton
255+ text: 'Ok'
256+ color: 'green'
257+ onClicked: {
258+ clockFace.latitude = latitudeField.text
259+ clockFace.longitude = longitudeField.text
260+ PopupUtils.close(dialog)
261+ }
262+ }
263+ }
264+ }
265+
266+ tools: ToolbarActions {
267+ Action {
268+ id: locationAction
269+ objectName: "changeSubredditAction"
270+
271+ iconSource: Qt.resolvedUrl("../images/add.png")
272+ text: i18n.tr("Location")
273+
274+ onTriggered: {
275+ PopupUtils.open(locationDialogComponent, locationAction.itemHint)
276+ }
277+ }
278+ }
279+
280+
281 }
282
283=== added file 'clock/ClockScript.js'
284--- clock/ClockScript.js 1970-01-01 00:00:00 +0000
285+++ clock/ClockScript.js 2013-05-01 13:19:25 +0000
286@@ -0,0 +1,33 @@
287+/*
288+ * Copyright (C) 2013 Canonical Ltd
289+ *
290+ * This program is free software: you can redistribute it and/or modify
291+ * it under the terms of the GNU General Public License version 3 as
292+ * published by the Free Software Foundation.
293+ *
294+ * This program is distributed in the hope that it will be useful,
295+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
296+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
297+ * GNU General Public License for more details.
298+ *
299+ * You should have received a copy of the GNU General Public License
300+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
301+ *
302+ * Authored by: Nekhelesh Ramananthan <krnekhelesh@gmail.com>
303+ */
304+
305+.pragma library
306+
307+// Function to form the url string to make the API call
308+function getUrlString (lat, long) {
309+ var base_url,url;
310+ base_url = "http://api.openweathermap.org/data/2.5/weather?";
311+ url = base_url + "lat=" + lat + "&lon=" + long + "&mode=xml";
312+ return url;
313+}
314+
315+// Function to convert online data format "2013-04-20T19:40:30" to just "19:40:30"
316+function getSunTime (data) {
317+ var DateTime = data.split('T');
318+ return DateTime[1];
319+}

Subscribers

People subscribed via source and target branches