Merge lp:~nik90/ubuntu-clock-app/remember-clock-mode into lp:ubuntu-clock-app

Proposed by Nekhelesh Ramananthan
Status: Merged
Approved by: Nekhelesh Ramananthan
Approved revision: 45
Merged at revision: 24
Proposed branch: lp:~nik90/ubuntu-clock-app/remember-clock-mode
Merge into: lp:ubuntu-clock-app
Diff against target: 102 lines (+29/-3)
3 files modified
app/clock/Clock.qml (+8/-2)
app/clock/ClockPage.qml (+5/-1)
app/ubuntu-clock-app.qml (+16/-0)
To merge this branch: bzr merge lp:~nik90/ubuntu-clock-app/remember-clock-mode
Reviewer Review Type Date Requested Status
Victor Thompson Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Needs Fixing
Review via email: mp+226862@code.launchpad.net

Commit message

Clock mode is now saved in u1db to remember the user preference

Description of the change

Remember the clock mode chosen by the user by saving it U1db. This same u1db database will also be used for other purposes such as saving the world clocks, settings etc. Hence the database file is appropriately named "user-preference".

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
Victor Thompson (vthompson) wrote :

Echoing inline comments:

1. Could we rename the "clockMode" variable as part of this? It really should be something like "isDigital", "digitalMode" or similar since it is a bool variable.

2. Consider loading all the U1db.Documents in the main QML file so they are all co-located. Otherwise, in the future finding settings defaults, etc, might be difficult.

review: Needs Fixing
Revision history for this message
Victor Thompson (vthompson) wrote :

Also, I was going to suggest using the StateSaver [1] for this, but alas, it seems that it only saves the state when the app crashes and not when closed normally--which is how it originally appeared to be designed [2]:

bzr diff
=== modified file 'app/clock/ClockPage.qml'
--- app/clock/ClockPage.qml 2014-07-13 11:18:31 +0000
+++ app/clock/ClockPage.qml 2014-07-16 00:53:40 +0000
@@ -63,6 +63,8 @@
             anchors.verticalCenter: parent.top
             anchors.verticalCenterOffset: units.gu(20)
             anchors.horizontalCenter: parent.horizontalCenter
+
+ StateSaver.properties: "clockMode"
         }

[1] http://developer.ubuntu.com/api/qml/sdk-14.10/Ubuntu.Components.StateSaver/
[2] http://www.kryogenix.org/days/2014/01/23/saving-the-current-state-of-your-ubuntu-sdk-app-with-no-effort/

44. By Nekhelesh Ramananthan

Fixed reviewer comments

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 :

> Echoing inline comments:
>
> 1. Could we rename the "clockMode" variable as part of this? It really should
> be something like "isDigital", "digitalMode" or similar since it is a bool
> variable.
>
> 2. Consider loading all the U1db.Documents in the main QML file so they are
> all co-located. Otherwise, in the future finding settings defaults, etc, might
> be difficult.

Fixed in the latest rev

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

> Also, I was going to suggest using the StateSaver [1] for this, but alas, it
> seems that it only saves the state when the app crashes and not when closed
> normally--which is how it originally appeared to be designed [2]:
>
> bzr diff
> === modified file 'app/clock/ClockPage.qml'
> --- app/clock/ClockPage.qml 2014-07-13 11:18:31 +0000
> +++ app/clock/ClockPage.qml 2014-07-16 00:53:40 +0000
> @@ -63,6 +63,8 @@
> anchors.verticalCenter: parent.top
> anchors.verticalCenterOffset: units.gu(20)
> anchors.horizontalCenter: parent.horizontalCenter
> +
> + StateSaver.properties: "clockMode"
> }
>
> [1]
> http://developer.ubuntu.com/api/qml/sdk-14.10/Ubuntu.Components.StateSaver/
> [2] http://www.kryogenix.org/days/2014/01/23/saving-the-current-state-of-your-
> ubuntu-sdk-app-with-no-effort/

Ideally I would like to use this as well, however as you mentioned above statesaver only saves the state in case of an app crash. However I believe they are planning to add an option to save data permanently even when the app closes normally. Until that lands in the SDK, I am afraid we will have to use u1db.

Actually it would be even better if we could use the new Settings API which was designed to store app settings. But that hasn't landed either :/

45. By Nekhelesh Ramananthan

Fixed incorrect comment

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
Victor Thompson (vthompson) wrote :

Looks great!

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

Thnx for the review. Top Approving and merging.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/clock/Clock.qml'
2--- app/clock/Clock.qml 2014-07-12 00:01:23 +0000
3+++ app/clock/Clock.qml 2014-07-16 14:07:22 +0000
4@@ -32,7 +32,7 @@
5 property bool isStartup: true
6
7 // Property to keep track of the clock mode
8- property alias clockMode: clockModeFlipable.isDigital
9+ property alias isDigital: clockModeFlipable.isDigital
10
11 Component.onCompleted: {
12 clockOpenAnimation.start()
13@@ -112,7 +112,9 @@
14
15 MouseArea {
16 anchors.fill: parent
17- onClicked: clockFlipAnimation.start()
18+ onClicked: {
19+ clockFlipAnimation.start()
20+ }
21 }
22 }
23
24@@ -191,6 +193,10 @@
25 }
26
27 analogShadow.source = digitalShadow.source = ""
28+
29+ var isDigitalSetting = JSON.parse(JSON.stringify(clockModeDocument.contents))
30+ isDigitalSetting.digitalMode = isDigital
31+ clockModeDocument.contents = isDigitalSetting
32 }
33 }
34 }
35
36=== modified file 'app/clock/ClockPage.qml'
37--- app/clock/ClockPage.qml 2014-07-13 11:18:31 +0000
38+++ app/clock/ClockPage.qml 2014-07-16 14:07:22 +0000
39@@ -15,6 +15,7 @@
40 */
41
42 import QtQuick 2.0
43+import U1db 1.0 as U1db
44 import Ubuntu.Components 1.1
45 import "../components"
46 import "../components/Utils.js" as Utils
47@@ -29,7 +30,7 @@
48 property int _minThreshold: addCityButton.maxThreshold + units.gu(2)
49
50 // Property to keep track of the clock mode
51- property alias isDigital: clock.clockMode
52+ property alias isDigital: clock.isDigital
53
54 flickable: null
55
56@@ -60,9 +61,12 @@
57
58 Clock {
59 id: clock
60+
61 anchors.verticalCenter: parent.top
62 anchors.verticalCenterOffset: units.gu(20)
63 anchors.horizontalCenter: parent.horizontalCenter
64+
65+ isDigital: clockModeDocument.contents.digitalMode ? true : false
66 }
67
68 Label {
69
70=== modified file 'app/ubuntu-clock-app.qml'
71--- app/ubuntu-clock-app.qml 2014-07-11 19:11:24 +0000
72+++ app/ubuntu-clock-app.qml 2014-07-16 14:07:22 +0000
73@@ -15,6 +15,7 @@
74 */
75
76 import QtQuick 2.0
77+import U1db 1.0 as U1db
78 import Ubuntu.Components 1.1
79 import "clock"
80 import "alarm"
81@@ -74,6 +75,21 @@
82 onTriggered: clockPage.updateTime()
83 }
84
85+ // Database to store the user preferences locally
86+ U1db.Database {
87+ id: clockDB
88+ path: "user-preferences"
89+ }
90+
91+ // Document to store clock mode chosen by user
92+ U1db.Document {
93+ id: clockModeDocument
94+ create: true
95+ database: clockDB
96+ docId: "clockModeDocument"
97+ defaults: { "digitalMode": false }
98+ }
99+
100 AlarmModel {
101 id: alarmModel
102 Component.onCompleted: Utils.log(debugMode, "Alarm Database loaded")

Subscribers

People subscribed via source and target branches