Merge lp:~nik90/ubuntu-clock-app/implement-location-finding into lp:ubuntu-clock-app

Proposed by Nekhelesh Ramananthan
Status: Merged
Approved by: Nekhelesh Ramananthan
Approved revision: 88
Merged at revision: 165
Proposed branch: lp:~nik90/ubuntu-clock-app/implement-location-finding
Merge into: lp:ubuntu-clock-app
Diff against target: 770 lines (+451/-32)
14 files modified
CMakeLists.txt (+2/-2)
app/clock/ClockPage.qml (+126/-4)
app/ubuntu-clock-app.qml (+8/-0)
backend/CMakeLists.txt (+23/-0)
backend/modules/GeoLocation/backend.cpp (+34/-0)
backend/modules/GeoLocation/backend.h (+35/-0)
backend/modules/GeoLocation/geolocation.cpp (+100/-0)
backend/modules/GeoLocation/geolocation.h (+78/-0)
backend/modules/GeoLocation/qmldir (+2/-0)
debian/changelog (+1/-0)
debian/control (+2/-0)
po/com.ubuntu.clock.pot (+29/-25)
tests/unit/MockClockApp.qml (+9/-0)
ubuntu-clock-app.json (+2/-1)
To merge this branch: bzr merge lp:~nik90/ubuntu-clock-app/implement-location-finding
Reviewer Review Type Date Requested Status
Riccardo Padovani Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Nekhelesh Ramananthan Needs Fixing
Review via email: mp+231793@code.launchpad.net

Commit message

Adds user location finding to the clock app.

Description of the change

Adds user location finding to the clock app.

==== Testing ====

This MP requires extensive testing for different scenarios that I have listed below. Please comment below if any of the scenarios don't work as expected. I will be adding these scenarios to the manual test suite to ensure we don't regress with a new clock release.

### Prerequisites

I tested this on Mako RTM Stable Image #5. I expect it to work reliably with #5 and higher. Please execute the following commands before *each* case for a fresh clean testing environment.

- Clean up the ubuntu location service and clock app files (for a fresh start) by,
"stop ubuntu-location-service-trust-stored"
"rm -r .local/share/UbuntuLocationService"
"rm -r .local/share/com.ubuntu.clock"
"start ubuntu-location-service-trust-stored"

### Case 1: User opens clock app for the first time (previous location unknown and location service enabled)

- Once you open the clock app, you should be prompted the first time for allowing clock app to access GPS. Press "Allow" here. That's the sign it is working.

- The clock app should show "Retrieving Location". After GPS coordinates are obtained (should take few seconds at most), it should show your city or country.

- Restart the clock app. It should show you the last saved city immediately and not "Retrieving location" again.

### Case 2: User opens clock app for the first time (previous location unknown and location services denied)

- Once you open the clock app, in the location service trust store prompt, press "Deny"!.

- The clock app should now show "Location Service Error" to indicate that it cannot access the location service.

- Restart the clock app and it should still read "Location Service Error".

### Case 3: User opens clock app as usual (not first-time)

- Open the clock app and it should prompt as usual for access to GPS. Press "Allow". The user location should then be shown within a few seconds.

- Close clock app

- Run "sudo stop ubuntu-location-service"

- Reopen clock app. It should show previous saved location and *not* "Location Service Error!".

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: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

#blocked on bug 1359866

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
81. By Nekhelesh Ramananthan

Added some comments

82. By Nekhelesh Ramananthan

Added more comments and cleaned lat and long calculation

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

As bug 1359866 is now fixed, is this unblocked?

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

#unblocked This was part of the 3 MPs that I requested you to test since they are ready code wise.

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

#blocked I believe this MP requires silo-001 [1] (ubuntu-rtm) to land in rtm stable otherwise I wouldn't be able to release a new clock app. Unfortunately the person (thomas voss) who requested silo-001 is on vacation.

I did request QA to go ahead and test the silo considering that it is already in utopic, however I was told that due to a regression in the past, QA doesn't test silos which haven't been tested by the lander first.

I will keep updating this MP as I get more details.

 dbus-cpp 4.0.0+14.10.20140917~rtm-0ubuntu1
 location-service 2.1+14.10.20140917.1~rtm-0ubuntu1

[1] https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu-rtm/landing-001

review: Needs Fixing
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

I gather this is still un-testable due to the location stuff not being complete and landed?

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

> I gather this is still un-testable due to the location stuff not being
> complete and landed?

Yes, from what I know, the HERE location service is not reliably started on phone reboots, and also the HERE location fixes differ between RTM and Utopic images leading to different testing results. As such, I first would like the HERE service to be available on the different channels reliably before proceeding to fix this MP.

I say wait 1-2 weeks for HERE service to be reliable, after which I am going to postpone this to post-rtm since I am not comfortable landing a big MP this late in the development cycle.

83. By Nekhelesh Ramananthan

Merged trunk

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

I tested this on RTM Stable #5 Mako and it worked for all the use cases mentioned above in the MP description. I am a bit nervous about pushing this feature this late in the cycle. I would like some additional people like popey, davmor, and any others that come to mind to test this before we merge to trunk.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

#unblocked

84. By Nekhelesh Ramananthan

Fixed qml tests

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
85. By Nekhelesh Ramananthan

Added missing dependency which caused qml test to fail

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
86. By Nekhelesh Ramananthan

Added comments

87. By Nekhelesh Ramananthan

Updated pot file

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Mihir Soni (mihirsoni) wrote :

I have tested this and it works fine on the first glance,
I'll test more and will update here.

88. By Nekhelesh Ramananthan

Renamed backend location plugin to geolocation

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

On rtm #6 the app doesn't start, it is stucked on the splash screen, both with gps activated or deasctivated.

Also, it doesn't create a log, so unfortunately I cannot understand what's wrong. I created the click package twice, so I don't think is my failure.

Anyway, I left a inline comment about a doubt on the code.

review: Needs Information
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

If I launch it from QTC (instead of creating a clic package) works.

Tests work as expected, but if I launch the app with position deactivate from the indicator it says "Location Service Error" as expected, but when I turn on position service from indicator the app doesn't try to update location, but stays stucked on "Location Service Error"

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

> If I launch it from QTC (instead of creating a click package) works.
>
> Tests work as expected, but if I launch the app with position deactivate from
> the indicator it says "Location Service Error" as expected, but when I turn on
> position service from indicator the app doesn't try to update location, but
> stays stucked on "Location Service Error"

Yeah that's because the clock app you will need to restart the app to update the location. Currently the location is updated only on 2 conditions,

1. On application startup
2. If the clock app is brought to the foreground 30 mins later

It does not continuously keep searching for the user location since that would be bad for the battery. So in your situation where you disabled the position service and then renabled it, the clock app does not get a signal that you turned it on. So you will need to restart the clock app.

A better way of fixing your situation would be to add a refresh button which the user can press to search for the location, but we are way past UI freezes to get this done.

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

63 + Stop querying for the user location if it is found to be
64 + the same as the one stored in the app setting database
65 + */
66 + if (userLongitude === userLocationDocument.contents.long ||
67 + userLatitude === userLocationDocument.contents.lat) {

>Riccardo Padovani (rpadovani) wrote 1 hour ago:
>I don't understand that if. Why you use OR and not an AND? If a user takes a plane in Rome, and >lands in Barcellona, the lat is the same, so the position isn'update?

No no that's not what this if loop is for. It is basically there to ensure that no invalid long or lat is supplied the clock app. Normally when the application is started up, the lat and long returned is usually garbage values. So this if loop checks the validity of the coordinates.

So if *either* lat or long is invalid, then it returns. Only if both of them are valid, does it continue to search for the user's location.

Hope this answers your question.

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Yap, thanks Nik, now is definitely better :-)

Great work!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-09-27 10:36:56 +0000
+++ CMakeLists.txt 2014-11-04 15:58:17 +0000
@@ -111,9 +111,9 @@
111111
112add_custom_target("autopilot" chmod +x ${CMAKE_SOURCE_DIR}/tests/autopilot/run112add_custom_target("autopilot" chmod +x ${CMAKE_SOURCE_DIR}/tests/autopilot/run
113 COMMAND ${CMAKE_SOURCE_DIR}/tests/autopilot/run113 COMMAND ${CMAKE_SOURCE_DIR}/tests/autopilot/run
114 DEPENDS timezone timezone-qmldir alarmsettings alarmsettings-qmldir datetime datetime-qmldir114 DEPENDS timezone timezone-qmldir alarmsettings alarmsettings-qmldir datetime datetime-qmldir geolocation geolocation-qmldir
115 WORKING_DIRECTORY ./app)115 WORKING_DIRECTORY ./app)
116116
117add_custom_target("run" /usr/bin/qmlscene -I ${CMAKE_BINARY_DIR}/backend ${CMAKE_SOURCE_DIR}/app/ubuntu-clock-app.qml117add_custom_target("run" /usr/bin/qmlscene -I ${CMAKE_BINARY_DIR}/backend ${CMAKE_SOURCE_DIR}/app/ubuntu-clock-app.qml
118 DEPENDS timezone timezone-qmldir alarmsettings alarmsettings-qmldir datetime datetime-qmldir118 DEPENDS timezone timezone-qmldir alarmsettings alarmsettings-qmldir datetime datetime-qmldir geolocation geolocation-qmldir
119 WORKING_DIRECTORY ./app)119 WORKING_DIRECTORY ./app)
120120
=== modified file 'app/clock/ClockPage.qml'
--- app/clock/ClockPage.qml 2014-10-10 19:58:49 +0000
+++ app/clock/ClockPage.qml 2014-11-04 15:58:17 +0000
@@ -17,7 +17,10 @@
17 */17 */
1818
19import QtQuick 2.319import QtQuick 2.3
20import U1db 1.0 as U1db
21import QtPositioning 5.2
20import Ubuntu.Components 1.122import Ubuntu.Components 1.1
23import GeoLocation 1.0
21import "../alarm"24import "../alarm"
22import "../components"25import "../components"
23import "../upstreamcomponents"26import "../upstreamcomponents"
@@ -47,6 +50,110 @@
47 id: alarmUtils50 id: alarmUtils
48 }51 }
4952
53 PositionSource {
54 id: geoposition
55
56 // Property to store the time of the last GPS location update
57 property var lastUpdate
58
59 readonly property real userLongitude: position.coordinate.longitude
60
61 readonly property real userLatitude: position.coordinate.latitude
62
63 active: true
64 updateInterval: 1000
65
66 onSourceErrorChanged: {
67 // Stop querying user location if location service is not available
68 if (sourceError !== PositionSource.NoError) {
69 console.log("[Source Error]: Location Service Error")
70 geoposition.stop()
71 }
72 }
73
74 onPositionChanged: {
75 // Do not accept an invalid user location
76 if(!position.longitudeValid || !position.latitudeValid) {
77 return
78 }
79
80 /*
81 Stop querying for the user location if it is found to be
82 the same as the one stored in the app setting database
83 */
84 if (userLongitude === userLocationDocument.contents.long ||
85 userLatitude === userLocationDocument.contents.lat) {
86 if (geoposition.active) {
87 console.log("[LOG]: Stopping geolocation update service")
88 geoposition.stop()
89 }
90 return
91 }
92
93 else {
94 // Retrieve user location online after receiving the user's lat and lng.
95 userLocation.setSource(position.coordinate.latitude, position.coordinate.longitude)
96 }
97 }
98 }
99
100 Connections {
101 target: clockApp
102 onApplicationStateChanged: {
103 /*
104 If Clock App is brought from background after more than 30 mins,
105 query the user location to ensure it is up to date.
106 */
107 if(applicationState
108 && Math.abs(clock.analogTime - geoposition.lastUpdate) > 1800000) {
109 if(!geoposition.active)
110 geoposition.start()
111 }
112
113 else if (!applicationState) {
114 geoposition.lastUpdate = clock.analogTime
115 }
116 }
117 }
118
119 GeoLocation {
120 id: userLocation
121
122 function setSource(lat, lng) {
123 var url = String("%1%2%3%4%5")
124 .arg("http://api.geonames.org/findNearbyPlaceNameJSON?lat=")
125 .arg(lat)
126 .arg("&lng=")
127 .arg(lng)
128 .arg("&username=krnekhelesh&style=full")
129
130 console.log("[LOG]: Searching online for user location at " + url)
131
132 userLocation.source = url;
133 }
134
135 onLocationChanged: {
136 var locationData = JSON.parse
137 (JSON.stringify(userLocationDocument.contents))
138
139 locationData.lat = geoposition.userLatitude
140 locationData.long = geoposition.userLongitude
141 locationData.location = userLocation.location
142
143 userLocationDocument.contents = locationData
144
145 /*
146 Stop querying the user coordinates once the user location has been
147 determined and saved to disk
148 */
149 if(geoposition.active) {
150 console.log("[LOG]: Stopping geolocation update service")
151 geoposition.stop()
152 }
153
154 }
155 }
156
50 Flickable {157 Flickable {
51 id: _flickable158 id: _flickable
52159
@@ -100,6 +207,10 @@
100 id: clock207 id: clock
101 objectName: "clock"208 objectName: "clock"
102209
210 Component.onCompleted: {
211 geoposition.lastUpdate = analogTime
212 }
213
103 analogTime: clockTime214 analogTime: clockTime
104215
105 anchors {216 anchors {
@@ -130,9 +241,6 @@
130 opacity: settingsIcon.opacity241 opacity: settingsIcon.opacity
131 spacing: units.gu(1)242 spacing: units.gu(1)
132243
133 // TODO: Remove this once user location finding is implemented
134 visible: false
135
136 anchors {244 anchors {
137 top: date.bottom245 top: date.bottom
138 topMargin: units.gu(1)246 topMargin: units.gu(1)
@@ -149,10 +257,24 @@
149 Label {257 Label {
150 id: location258 id: location
151 objectName: "location"259 objectName: "location"
152 text: i18n.tr("Location")260
153 fontSize: "medium"261 fontSize: "medium"
154 anchors.verticalCenter: locationIcon.verticalCenter262 anchors.verticalCenter: locationIcon.verticalCenter
155 color: UbuntuColors.midAubergine263 color: UbuntuColors.midAubergine
264
265 text: {
266 if (userLocationDocument.contents.location === "Null") {
267 if(geoposition.sourceError !== PositionSource.NoError) {
268 return i18n.tr("Location Service Error!")
269 } else {
270 return i18n.tr("Retrieving location...")
271 }
272 }
273
274 else {
275 return userLocationDocument.contents.location
276 }
277 }
156 }278 }
157 }279 }
158280
159281
=== modified file 'app/ubuntu-clock-app.qml'
--- app/ubuntu-clock-app.qml 2014-10-11 17:53:39 +0000
+++ app/ubuntu-clock-app.qml 2014-11-04 15:58:17 +0000
@@ -71,6 +71,14 @@
71 defaults: { "digitalMode": false }71 defaults: { "digitalMode": false }
72 }72 }
7373
74 U1db.Document {
75 id: userLocationDocument
76 create: true
77 database: clockDB
78 docId: "userLocationDocument"
79 defaults: { "lat": "NaN", "long": "Nan", "location": "Null" }
80 }
81
74 DateTime {82 DateTime {
75 id: localTimeSource83 id: localTimeSource
76 updateInterval: 100084 updateInterval: 1000
7785
=== modified file 'backend/CMakeLists.txt'
--- backend/CMakeLists.txt 2014-09-12 05:05:03 +0000
+++ backend/CMakeLists.txt 2014-11-04 15:58:17 +0000
@@ -25,6 +25,12 @@
25 modules/Alarm/Settings/alarmsettings.cpp25 modules/Alarm/Settings/alarmsettings.cpp
26)26)
2727
28set(
29 geolocation_SRCS
30 modules/GeoLocation/backend.cpp
31 modules/GeoLocation/geolocation.cpp
32)
33
28add_library(timezone MODULE34add_library(timezone MODULE
29 ${timezone_SRCS}35 ${timezone_SRCS}
30)36)
@@ -37,6 +43,10 @@
37 ${alarmsettings_SRCS}43 ${alarmsettings_SRCS}
38)44)
3945
46add_library(geolocation MODULE
47 ${geolocation_SRCS}
48)
49
40set_target_properties(timezone PROPERTIES50set_target_properties(timezone PROPERTIES
41 LIBRARY_OUTPUT_DIRECTORY Timezone51 LIBRARY_OUTPUT_DIRECTORY Timezone
42)52)
@@ -49,9 +59,14 @@
49 LIBRARY_OUTPUT_DIRECTORY Alarm/Settings59 LIBRARY_OUTPUT_DIRECTORY Alarm/Settings
50)60)
5161
62set_target_properties(geolocation PROPERTIES
63 LIBRARY_OUTPUT_DIRECTORY GeoLocation
64)
65
52qt5_use_modules(datetime Gui Qml Quick)66qt5_use_modules(datetime Gui Qml Quick)
53qt5_use_modules(timezone Gui Qml Quick)67qt5_use_modules(timezone Gui Qml Quick)
54qt5_use_modules(alarmsettings Gui Qml Quick DBus)68qt5_use_modules(alarmsettings Gui Qml Quick DBus)
69qt5_use_modules(geolocation Gui Qml Quick)
5570
56# Copy qmldir file to build dir for running in QtCreator71# Copy qmldir file to build dir for running in QtCreator
57add_custom_target(timezone-qmldir ALL72add_custom_target(timezone-qmldir ALL
@@ -69,6 +84,11 @@
69 DEPENDS ${QMLFILES}84 DEPENDS ${QMLFILES}
70)85)
7186
87add_custom_target(geolocation-qmldir ALL
88 COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/modules/GeoLocation/qmldir ${CMAKE_CURRENT_BINARY_DIR}/GeoLocation
89 DEPENDS ${QMLFILES}
90)
91
72# Install plugin file92# Install plugin file
73install(TARGETS timezone DESTINATION ${MODULE_PATH}/Timezone/)93install(TARGETS timezone DESTINATION ${MODULE_PATH}/Timezone/)
74install(FILES modules/Timezone/qmldir DESTINATION ${MODULE_PATH}/Timezone/)94install(FILES modules/Timezone/qmldir DESTINATION ${MODULE_PATH}/Timezone/)
@@ -78,3 +98,6 @@
7898
79install(TARGETS alarmsettings DESTINATION ${MODULE_PATH}/Alarm/Settings/)99install(TARGETS alarmsettings DESTINATION ${MODULE_PATH}/Alarm/Settings/)
80install(FILES modules/Alarm/Settings/qmldir DESTINATION ${MODULE_PATH}/Alarm/Settings/)100install(FILES modules/Alarm/Settings/qmldir DESTINATION ${MODULE_PATH}/Alarm/Settings/)
101
102install(TARGETS geolocation DESTINATION ${MODULE_PATH}/GeoLocation/)
103install(FILES modules/GeoLocation/qmldir DESTINATION ${MODULE_PATH}/GeoLocation/)
81104
=== added directory 'backend/modules/GeoLocation'
=== added file 'backend/modules/GeoLocation/backend.cpp'
--- backend/modules/GeoLocation/backend.cpp 1970-01-01 00:00:00 +0000
+++ backend/modules/GeoLocation/backend.cpp 2014-11-04 15:58:17 +0000
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This file is part of Ubuntu Clock App
5 *
6 * Ubuntu Clock App is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * Ubuntu Clock App is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QtQml>
20#include <QtQml/QQmlContext>
21#include "backend.h"
22#include "geolocation.h"
23
24void BackendPlugin::registerTypes(const char *uri)
25{
26 Q_ASSERT(uri == QLatin1String("GeoLocation"));
27
28 qmlRegisterType<GeoLocation>(uri, 1, 0, "GeoLocation");
29}
30
31void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
32{
33 QQmlExtensionPlugin::initializeEngine(engine, uri);
34}
035
=== added file 'backend/modules/GeoLocation/backend.h'
--- backend/modules/GeoLocation/backend.h 1970-01-01 00:00:00 +0000
+++ backend/modules/GeoLocation/backend.h 2014-11-04 15:58:17 +0000
@@ -0,0 +1,35 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This file is part of Ubuntu Clock App
5 *
6 * Ubuntu Clock App is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * Ubuntu Clock App is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef BACKEND_PLUGIN_H
20#define BACKEND_PLUGIN_H
21
22#include <QtQml/QQmlEngine>
23#include <QtQml/QQmlExtensionPlugin>
24
25class BackendPlugin : public QQmlExtensionPlugin
26{
27 Q_OBJECT
28 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
29
30public:
31 void registerTypes(const char *uri);
32 void initializeEngine(QQmlEngine *engine, const char *uri);
33};
34#endif // BACKEND_PLUGIN_H
35
036
=== added file 'backend/modules/GeoLocation/geolocation.cpp'
--- backend/modules/GeoLocation/geolocation.cpp 1970-01-01 00:00:00 +0000
+++ backend/modules/GeoLocation/geolocation.cpp 2014-11-04 15:58:17 +0000
@@ -0,0 +1,100 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This file is part of Ubuntu Clock App
5 *
6 * Ubuntu Clock App is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * Ubuntu Clock App is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <QDebug>
20#include <QNetworkReply>
21#include <QNetworkRequest>
22#include <QJsonDocument>
23
24#include "geolocation.h"
25
26GeoLocation::GeoLocation(QObject *parent):
27 QObject(parent)
28{
29 m_nam = new QNetworkAccessManager(this);
30 connect(m_nam,
31 SIGNAL(finished(QNetworkReply*)),
32 this,
33 SLOT(networkReplyFinished(QNetworkReply*)));
34}
35
36QUrl GeoLocation::source() const
37{
38 return m_source;
39}
40
41QString GeoLocation::location() const
42{
43 return m_location;
44}
45
46void GeoLocation::setSource(const QUrl &source)
47{
48 if (m_source == source) {
49 // Don't set the source again if it is the same source being set again
50 return;
51 }
52
53 // Update the source and emit the changed signal to let QML know
54 m_source = source;
55 emit sourceChanged();
56
57 retrieveLocationFromJson();
58}
59
60void GeoLocation::retrieveLocationFromJson()
61{
62 // Define the request
63 QNetworkRequest request(m_source);
64
65 // Make the request to retrieve the data
66 m_nam->get(request);
67}
68
69void GeoLocation::networkReplyFinished(QNetworkReply *reply)
70{
71 if(reply->error() != QNetworkReply::NoError) {
72 qDebug() << "[LOG] Network error: " << reply->errorString();
73 return;
74 }
75
76 QByteArray data = reply->readAll();
77
78 QJsonDocument jsonDoc = QJsonDocument::fromJson(data);
79
80 QVariant cityData = jsonDoc.toVariant();
81
82 foreach (const QVariant &entry, cityData.toMap().value("geonames").toList())
83 {
84 auto data = entry.toMap();
85 auto adminName2 = data.value("adminName2").toString();
86 auto adminName1 = data.value("adminName1").toString();
87
88 if (!adminName2.isEmpty()) {
89 m_location = adminName2;
90 emit locationChanged();
91 }
92
93 else if (!adminName1.isEmpty()) {
94 m_location = adminName1;
95 emit locationChanged();
96 }
97 }
98
99 reply->deleteLater();
100}
0101
=== added file 'backend/modules/GeoLocation/geolocation.h'
--- backend/modules/GeoLocation/geolocation.h 1970-01-01 00:00:00 +0000
+++ backend/modules/GeoLocation/geolocation.h 2014-11-04 15:58:17 +0000
@@ -0,0 +1,78 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This file is part of Ubuntu Clock App
5 *
6 * Ubuntu Clock App is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * Ubuntu Clock App is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef LOCATION_H
20#define LOCATION_H
21
22#include <QObject>
23#include <QUrl>
24#include <QNetworkAccessManager>
25
26class GeoLocation : public QObject
27{
28 Q_OBJECT
29
30 // Property to set the user's longitude and latitude
31 Q_PROPERTY(QUrl source
32 READ source
33 WRITE setSource
34 NOTIFY sourceChanged)
35
36 // Property to return the user's location (cityname or countryname)
37 Q_PROPERTY(QString location
38 READ location
39 NOTIFY locationChanged)
40
41public:
42 GeoLocation(QObject *parent = 0);
43
44 // Function to read the json document source
45 QUrl source() const;
46
47 // Function to set the source
48 void setSource(const QUrl &source);
49
50 // Function to read the user's location
51 QString location() const;
52
53signals:
54 // Signal to notify the source has been changed
55 void sourceChanged();
56
57 // Signal to notify the location has been changed
58 void locationChanged();
59
60private slots:
61 // Function to process the json document when a reply is received
62 void networkReplyFinished(QNetworkReply *reply);
63
64private:
65 // Private copy of the source received from QML
66 QUrl m_source;
67
68 // Network access manager to request data from the online source
69 QNetworkAccessManager *m_nam;
70
71 // Private copy of the user location
72 QString m_location;
73
74 // Function to initiate the location retrieval process
75 void retrieveLocationFromJson();
76};
77
78#endif // LOCATION_H
079
=== added file 'backend/modules/GeoLocation/qmldir'
--- backend/modules/GeoLocation/qmldir 1970-01-01 00:00:00 +0000
+++ backend/modules/GeoLocation/qmldir 2014-11-04 15:58:17 +0000
@@ -0,0 +1,2 @@
1module GeoLocation
2plugin geolocation
03
=== modified file 'debian/changelog'
--- debian/changelog 2014-10-25 13:32:07 +0000
+++ debian/changelog 2014-11-04 15:58:17 +0000
@@ -55,6 +55,7 @@
55 * Updated QtQuick library imports to v2.355 * Updated QtQuick library imports to v2.3
56 * Switched bzr branch to lp:ubuntu-clock-app56 * Switched bzr branch to lp:ubuntu-clock-app
57 * Updated pot file name57 * Updated pot file name
58 * Added support for user location retrieval using GPS (LP: #1323198)
58 * Added header shortcut to select/deselect all alarm repeat options (LP: #1362089)59 * Added header shortcut to select/deselect all alarm repeat options (LP: #1362089)
59 * Added visual tweaks (80% opacity for disabled alarms) and show time to 60 * Added visual tweaks (80% opacity for disabled alarms) and show time to
60 next alarm when enabling an alarm.61 next alarm when enabling an alarm.
6162
=== modified file 'debian/control'
--- debian/control 2014-09-26 10:56:42 +0000
+++ debian/control 2014-11-04 15:58:17 +0000
@@ -12,6 +12,7 @@
12 qml-module-qttest,12 qml-module-qttest,
13 qtdeclarative5-u1db1.0,13 qtdeclarative5-u1db1.0,
14 qtdeclarative5-qtmultimedia-plugin,14 qtdeclarative5-qtmultimedia-plugin,
15 qtdeclarative5-qtpositioning-plugin,
15 qt5-default,16 qt5-default,
16 qtbase5-dev,17 qtbase5-dev,
17 qtdeclarative5-dev,18 qtdeclarative5-dev,
@@ -32,6 +33,7 @@
32 qtdeclarative5-ubuntu-ui-toolkit-plugin | qt-components-ubuntu,33 qtdeclarative5-ubuntu-ui-toolkit-plugin | qt-components-ubuntu,
33 qtdeclarative5-xmllistmodel-plugin,34 qtdeclarative5-xmllistmodel-plugin,
34 qtdeclarative5-qtmultimedia-plugin,35 qtdeclarative5-qtmultimedia-plugin,
36 qtdeclarative5-qtpositioning-plugin,
35 ubuntu-touch-sounds,37 ubuntu-touch-sounds,
36 suru-icon-theme | ubuntu-mobile-icons,38 suru-icon-theme | ubuntu-mobile-icons,
37 ${misc:Depends},39 ${misc:Depends},
3840
=== modified file 'po/com.ubuntu.clock.pot'
--- po/com.ubuntu.clock.pot 2014-10-15 09:53:08 +0000
+++ po/com.ubuntu.clock.pot 2014-11-04 15:58:17 +0000
@@ -8,7 +8,7 @@
8msgstr ""8msgstr ""
9"Project-Id-Version: \n"9"Project-Id-Version: \n"
10"Report-Msgid-Bugs-To: \n"10"Report-Msgid-Bugs-To: \n"
11"POT-Creation-Date: 2014-10-15 11:52+0200\n"11"POT-Creation-Date: 2014-11-04 16:55+0100\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"14"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -18,11 +18,11 @@
18"Content-Transfer-Encoding: 8bit\n"18"Content-Transfer-Encoding: 8bit\n"
1919
20#: ../app/alarm/AlarmLabel.qml:30 ../app/alarm/AlarmLabel.qml:5620#: ../app/alarm/AlarmLabel.qml:30 ../app/alarm/AlarmLabel.qml:56
21#: ../app/alarm/EditAlarmPage.qml:30321#: ../app/alarm/EditAlarmPage.qml:302
22msgid "Label"22msgid "Label"
23msgstr ""23msgstr ""
2424
25#: ../app/alarm/AlarmList.qml:78 ../app/alarm/AlarmPage.qml:10825#: ../app/alarm/AlarmList.qml:78 ../app/alarm/AlarmPage.qml:117
26#: ../app/worldclock/UserWorldCityList.qml:10126#: ../app/worldclock/UserWorldCityList.qml:101
27msgid "Delete"27msgid "Delete"
28msgstr ""28msgstr ""
@@ -36,27 +36,27 @@
36msgid "Alarm"36msgid "Alarm"
37msgstr ""37msgstr ""
3838
39#: ../app/alarm/AlarmPage.qml:58 ../app/worldclock/WorldCityList.qml:7939#: ../app/alarm/AlarmPage.qml:58 ../app/worldclock/WorldCityList.qml:80
40msgid "Back"40msgid "Back"
41msgstr ""41msgstr ""
4242
43#: ../app/alarm/AlarmPage.qml:7843#: ../app/alarm/AlarmPage.qml:87
44msgid "Select None"44msgid "Select None"
45msgstr ""45msgstr ""
4646
47#: ../app/alarm/AlarmPage.qml:80 ../app/alarm/AlarmRepeat.qml:3547#: ../app/alarm/AlarmPage.qml:89 ../app/alarm/AlarmRepeat.qml:35
48msgid "Select All"48msgid "Select All"
49msgstr ""49msgstr ""
5050
51#: ../app/alarm/AlarmPage.qml:13851#: ../app/alarm/AlarmPage.qml:149
52msgid "No saved alarms"52msgid "No saved alarms"
53msgstr ""53msgstr ""
5454
55#: ../app/alarm/AlarmPage.qml:13955#: ../app/alarm/AlarmPage.qml:150
56msgid "Tap the + icon to add an alarm"56msgid "Tap the + icon to add an alarm"
57msgstr ""57msgstr ""
5858
59#: ../app/alarm/AlarmRepeat.qml:31 ../app/alarm/EditAlarmPage.qml:29359#: ../app/alarm/AlarmRepeat.qml:31 ../app/alarm/EditAlarmPage.qml:292
60msgid "Repeat"60msgid "Repeat"
61msgstr ""61msgstr ""
6262
@@ -68,33 +68,33 @@
68#: ../app/alarm/AlarmSettingsPage.qml:55 ../app/alarm/AlarmSettingsPage.qml:5668#: ../app/alarm/AlarmSettingsPage.qml:55 ../app/alarm/AlarmSettingsPage.qml:56
69#: ../app/alarm/AlarmSettingsPage.qml:65 ../app/alarm/AlarmSettingsPage.qml:6669#: ../app/alarm/AlarmSettingsPage.qml:65 ../app/alarm/AlarmSettingsPage.qml:66
70#: ../app/alarm/AlarmSettingsPage.qml:67 ../app/alarm/AlarmSettingsPage.qml:6870#: ../app/alarm/AlarmSettingsPage.qml:67 ../app/alarm/AlarmSettingsPage.qml:68
71#: ../app/alarm/AlarmSettingsPage.qml:13971#: ../app/alarm/AlarmSettingsPage.qml:146
72#: ../app/alarm/AlarmSettingsPage.qml:20672#: ../app/alarm/AlarmSettingsPage.qml:215
73#, qt-format73#, qt-format
74msgid "%1 minutes"74msgid "%1 minutes"
75msgstr ""75msgstr ""
7676
77#: ../app/alarm/AlarmSettingsPage.qml:9377#: ../app/alarm/AlarmSettingsPage.qml:92
78msgid "Alarm volume"78msgid "Alarm volume"
79msgstr ""79msgstr ""
8080
81#: ../app/alarm/AlarmSettingsPage.qml:13881#: ../app/alarm/AlarmSettingsPage.qml:145
82msgid "Silence after"82msgid "Silence after"
83msgstr ""83msgstr ""
8484
85#: ../app/alarm/AlarmSettingsPage.qml:20585#: ../app/alarm/AlarmSettingsPage.qml:214
86msgid "Snooze for"86msgid "Snooze for"
87msgstr ""87msgstr ""
8888
89#: ../app/alarm/AlarmSettingsPage.qml:24989#: ../app/alarm/AlarmSettingsPage.qml:259
90msgid "Vibration"90msgid "Vibration"
91msgstr ""91msgstr ""
9292
93#: ../app/alarm/AlarmSettingsPage.qml:27893#: ../app/alarm/AlarmSettingsPage.qml:293
94msgid "Change time and date"94msgid "Change time and date"
95msgstr ""95msgstr ""
9696
97#: ../app/alarm/AlarmSound.qml:28 ../app/alarm/EditAlarmPage.qml:31697#: ../app/alarm/AlarmSound.qml:28 ../app/alarm/EditAlarmPage.qml:315
98msgid "Sound"98msgid "Sound"
99msgstr ""99msgstr ""
100100
@@ -150,12 +150,16 @@
150msgid "Edit alarm"150msgid "Edit alarm"
151msgstr ""151msgstr ""
152152
153#: ../app/alarm/EditAlarmPage.qml:337153#: ../app/alarm/EditAlarmPage.qml:336
154msgid "Delete alarm"154msgid "Delete alarm"
155msgstr ""155msgstr ""
156156
157#: ../app/clock/ClockPage.qml:152157#: ../app/clock/ClockPage.qml:268
158msgid "Location"158msgid "Location Service Error!"
159msgstr ""
160
161#: ../app/clock/ClockPage.qml:270
162msgid "Retrieving location..."
159msgstr ""163msgstr ""
160164
161#: ../app/worldclock/AddWorldCityButton.qml:30165#: ../app/worldclock/AddWorldCityButton.qml:30
@@ -207,23 +211,23 @@
207msgid "Select a city"211msgid "Select a city"
208msgstr ""212msgstr ""
209213
210#: ../app/worldclock/WorldCityList.qml:94214#: ../app/worldclock/WorldCityList.qml:109
211msgid "Search..."215msgid "Search..."
212msgstr ""216msgstr ""
213217
214#: ../app/worldclock/WorldCityList.qml:205218#: ../app/worldclock/WorldCityList.qml:214
215msgid "Searching for a city"219msgid "Searching for a city"
216msgstr ""220msgstr ""
217221
218#: ../app/worldclock/WorldCityList.qml:210222#: ../app/worldclock/WorldCityList.qml:219
219msgid "No City Found"223msgid "No City Found"
220msgstr ""224msgstr ""
221225
222#: ../app/worldclock/WorldCityList.qml:216226#: ../app/worldclock/WorldCityList.qml:225
223msgid "Unable to connect."227msgid "Unable to connect."
224msgstr ""228msgstr ""
225229
226#: ../app/worldclock/WorldCityList.qml:217230#: ../app/worldclock/WorldCityList.qml:226
227msgid "Please check your network connection and try again"231msgid "Please check your network connection and try again"
228msgstr ""232msgstr ""
229233
230234
=== modified file 'tests/unit/MockClockApp.qml'
--- tests/unit/MockClockApp.qml 2014-10-13 19:57:35 +0000
+++ tests/unit/MockClockApp.qml 2014-11-04 15:58:17 +0000
@@ -21,6 +21,7 @@
21import U1db 1.0 as U1db21import U1db 1.0 as U1db
22import Ubuntu.Components 1.122import Ubuntu.Components 1.1
23import "../../app/clock"23import "../../app/clock"
24import "../../app/components"
2425
25/*26/*
26 This file is meant to create a fake but fully fleshed clock app with its27 This file is meant to create a fake but fully fleshed clock app with its
@@ -52,6 +53,14 @@
52 defaults: { "digitalMode": false }53 defaults: { "digitalMode": false }
53 }54 }
5455
56 U1db.Document {
57 id: userLocationDocument
58 create: true
59 database: clockDB
60 docId: "userLocationDocument"
61 defaults: { "lat": "NaN", "long": "Nan", "location": "Null" }
62 }
63
55 DateTime {64 DateTime {
56 id: localTimeSource65 id: localTimeSource
57 updateInterval: 100066 updateInterval: 1000
5867
=== modified file 'ubuntu-clock-app.json'
--- ubuntu-clock-app.json 2014-08-18 21:37:23 +0000
+++ ubuntu-clock-app.json 2014-11-04 15:58:17 +0000
@@ -2,7 +2,8 @@
2 "policy_groups": [2 "policy_groups": [
3 "audio",3 "audio",
4 "calendar",4 "calendar",
5 "networking"5 "networking",
6 "location"
6 ],7 ],
7 "policy_version": 1.28 "policy_version": 1.2
8}9}
9\ No newline at end of file10\ No newline at end of file

Subscribers

People subscribed via source and target branches