← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~nik90/ubuntu-clock-app/migrate-u1db-to-qtlabs into lp:ubuntu-clock-app

 

Nekhelesh Ramananthan has proposed merging lp:~nik90/ubuntu-clock-app/migrate-u1db-to-qtlabs into lp:ubuntu-clock-app.

Commit message:
Migrated user clock settings from u1db to qt.labs.settings.

Requested reviews:
  Ubuntu Clock Developers (ubuntu-clock-dev)

For more details, see:
https://code.launchpad.net/~nik90/ubuntu-clock-app/migrate-u1db-to-qtlabs/+merge/268384

Migrates clock settings such as user location settings, digital/analogue mode setting from u1db to Qt.labs.settings for the following reasons,

- Recommended by the SDK developers to store app settings using Qt.labs.settings
- Code syntax is also much easier to understand and maintain
- Future stopwatch branch is also using Qt.labs.settings to store stopwatch status. So this will be a good point to unify them.
-- 
Your team Ubuntu Clock Developers is requested to review the proposed merge of lp:~nik90/ubuntu-clock-app/migrate-u1db-to-qtlabs into lp:ubuntu-clock-app.
=== modified file 'app/clock/ClockPage.qml'
--- app/clock/ClockPage.qml	2015-08-07 11:45:17 +0000
+++ app/clock/ClockPage.qml	2015-08-18 20:39:18 +0000
@@ -74,12 +74,8 @@
 
                 // If this is the first time, then set location as Denied
                 // to indicate user denying clock app location access.
-                if (userLocationDocument.contents.location === "Null") {
-                    var locationData = JSON.parse
-                            (JSON.stringify(userLocationDocument.contents))
-
-                    locationData.location = "Denied"
-                    userLocationDocument.contents = locationData
+                if (clockLocationSetting.location === "Null") {
+                    clockLocationSetting.location = "Denied"
                 }
             }
         }
@@ -94,8 +90,8 @@
              Stop querying for the user location if it is found to be
              the same as the one stored in the app setting database
             */
-            if (userLongitude === userLocationDocument.contents.long ||
-                    userLatitude === userLocationDocument.contents.lat) {
+            if (userLongitude === clockLocationSetting.longitude ||
+                    userLatitude === clockLocationSetting.latitude) {
                 if (geoposition.active) {
                     console.log("[LOG]: Stopping geolocation update service")
                     geoposition.stop()
@@ -146,14 +142,9 @@
         }
 
         onLocationChanged: {
-            var locationData = JSON.parse
-                    (JSON.stringify(userLocationDocument.contents))
-
-            locationData.lat = geoposition.userLatitude
-            locationData.long = geoposition.userLongitude
-            locationData.location = userLocation.location
-
-            userLocationDocument.contents = locationData
+            clockLocationSetting.latitude = geoposition.userLatitude
+            clockLocationSetting.longitude = geoposition.userLongitude
+            clockLocationSetting.location = userLocation.location
 
             /*
              Stop querying the user coordinates once the user location has been
@@ -278,14 +269,14 @@
                 color: UbuntuColors.midAubergine
 
                 text: {
-                    if (userLocationDocument.contents.location === "Null"
-                            || userLocationDocument.contents.location === "Denied"
+                    if (clockLocationSetting.location === "Null"
+                            || clockLocationSetting.location === "Denied"
                             && geoposition.sourceError === PositionSource.NoError) {
                             return i18n.tr("Retrieving location...")
                     }
 
                     else {
-                        return userLocationDocument.contents.location
+                        return clockLocationSetting.location
                     }
                 }
             }

=== modified file 'app/clock/MainClock.qml'
--- app/clock/MainClock.qml	2015-05-27 16:03:23 +0000
+++ app/clock/MainClock.qml	2015-08-18 20:39:18 +0000
@@ -32,7 +32,7 @@
 
     isMainClock: true
 
-    isDigital: clockModeDocument.contents.digitalMode ? true : false
+    isDigital: clockSetting.digitalMode ? true : false
 
     Component.onCompleted: {
         clockOpenAnimation.start()

=== modified file 'app/components/Clock.qml'
--- app/components/Clock.qml	2015-08-14 05:34:49 +0000
+++ app/components/Clock.qml	2015-08-18 20:39:18 +0000
@@ -243,10 +243,7 @@
                 analogShadow.source = digitalShadow.source = ""
 
                 if(isMainClock) {
-                    var isDigitalSetting = JSON.parse
-                            (JSON.stringify(clockModeDocument.contents))
-                    isDigitalSetting.digitalMode = isDigital
-                    clockModeDocument.contents = isDigitalSetting
+                    clockSetting.digitalMode = isDigital
                 }
             }
         }

=== modified file 'app/ubuntu-clock-app.qml'
--- app/ubuntu-clock-app.qml	2015-07-15 22:31:52 +0000
+++ app/ubuntu-clock-app.qml	2015-08-18 20:39:18 +0000
@@ -18,7 +18,7 @@
 
 import QtQuick 2.4
 import DateTime 1.0
-import U1db 1.0 as U1db
+import Qt.labs.settings 1.0
 import Ubuntu.Components 1.2
 import "clock"
 import "components"
@@ -55,27 +55,18 @@
 
     Background {}
 
-    // Database to store the user preferences locally
-    U1db.Database {
-        id: clockDB
-        path: "user-preferences"
-    }
-
-    // Document to store clock mode chosen by user
-    U1db.Document {
-        id: clockModeDocument
-        create: true
-        database: clockDB
-        docId: "clockModeDocument"
-        defaults: { "digitalMode": false }
-    }
-
-    U1db.Document {
-        id: userLocationDocument
-        create: true
-        database: clockDB
-        docId: "userLocationDocument"
-        defaults: { "lat": "NaN", "long": "Nan", "location": "Null" }
+    Settings {
+        id: clockSetting
+        category: "Clock"
+        property bool digitalMode: false
+    }
+
+    Settings {
+        id: clockLocationSetting
+        category: "Location"
+        property string latitude: "NaN"
+        property string longitude: "NaN"
+        property string location: "Null"
     }
 
     DateTime {

=== modified file 'app/worldclock/UserWorldCityDelegate.qml'
--- app/worldclock/UserWorldCityDelegate.qml	2015-08-14 05:34:49 +0000
+++ app/worldclock/UserWorldCityDelegate.qml	2015-08-18 20:39:18 +0000
@@ -104,8 +104,8 @@
             }
 
             Component.onCompleted: {
-                isDigital = clockModeDocument.contents.digitalMode ? true : false
-                if (clockModeDocument.contents.digitalMode) {
+                isDigital = clockSetting.digitalMode ? true : false
+                if (clockSetting.digitalMode) {
                     digitalModeLoader.setSource
                             ("../components/DigitalMode.qml",
                              {

=== modified file 'debian/changelog'
--- debian/changelog	2015-08-16 20:53:03 +0000
+++ debian/changelog	2015-08-18 20:39:18 +0000
@@ -14,6 +14,7 @@
   * Added README.mergeproposal checklist to help with the review process.
   * Fix alarm interval information being inconsistent (LP: #1466000)
   * Changed default alarm sound (LP: #1354370)
+  * Migrated clock settings from U1db to Qt.labs.settings 1.0
 
   [Victor Thompson]
   * Show all README files in QtCreator 

=== modified file 'tests/unit/MockClockApp.qml'
--- tests/unit/MockClockApp.qml	2015-08-14 05:34:49 +0000
+++ tests/unit/MockClockApp.qml	2015-08-18 20:39:18 +0000
@@ -18,7 +18,7 @@
 
 import QtQuick 2.4
 import DateTime 1.0
-import U1db 1.0 as U1db
+import Qt.labs.settings 1.0
 import Ubuntu.Components 1.2
 import "../../app/clock"
 import "../../app/components"
@@ -39,25 +39,18 @@
     height: units.gu(70)
     applicationName: "com.ubuntu.fakeclock.test"
 
-    U1db.Database {
-        id: clockDB
-        path: "user-preferences"
-    }
-
-    U1db.Document {
-        id: clockModeDocument
-        create: true
-        database: clockDB
-        docId: "clockModeDocument"
-        defaults: { "digitalMode": false }
-    }
-
-    U1db.Document {
-        id: userLocationDocument
-        create: true
-        database: clockDB
-        docId: "userLocationDocument"
-        defaults: { "lat": "NaN", "long": "Nan", "location": "Null" }
+    Settings {
+        id: clockSetting
+        category: "Clock"
+        property bool digitalMode: false
+    }
+
+    Settings {
+        id: clockLocationSetting
+        category: "Location"
+        property string latitude: "NaN"
+        property string longitude: "NaN"
+        property string location: "Null"
     }
 
     DateTime {


References