Merge lp:~twstd-dev/ubuntu-clock-app/next-alarm into lp:ubuntu-clock-app

Proposed by twstd
Status: Rejected
Rejected by: Nekhelesh Ramananthan
Proposed branch: lp:~twstd-dev/ubuntu-clock-app/next-alarm
Merge into: lp:ubuntu-clock-app
Diff against target: 192 lines (+144/-3)
3 files modified
app/components/NextAlarm.qml (+60/-0)
app/components/Utils.js (+39/-0)
app/ubuntu-clock-app.qml (+45/-3)
To merge this branch: bzr merge lp:~twstd-dev/ubuntu-clock-app/next-alarm
Reviewer Review Type Date Requested Status
Nekhelesh Ramananthan Disapprove
Ubuntu Phone Apps Jenkins Bot continuous-integration Needs Fixing
Review via email: mp+231243@code.launchpad.net

Commit message

Fix for Bug #1290793

Description of the change

A fix for Bug #1290793

To post a comment you must log in.
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Here are some observations based on initial testing,
- When an alarm is set for several days later, it shows up "Next Alarm in 167h 20m". Would it be able to convert this into "Next Alarm in 3d 20h 20m" to make it more meaningful for the user.

- IMHO the string i18n.tr( "You have not set an alarm" ); is a bit too long to show in the bottom edge hint. I would prefer something like "No Active Alarms". However let me check with the designers tomorrow and update here what string they want to show.

- Comments style in this MP,

8 +/**
9 + * @brief A simple object that contains logic
10 + * to find and retrieve next alarm from the model.
11 + * We save only the date of an alarm, we don't need
12 + * other information.
13 + */

Please change to the format below. We are trying to maintain a consistency code style throughout the app.

/*
 A simple object that contains logic
 to find and retrieve next alarm from the model.
 We save only the date of an alarm, we don't need
 other information.
*/

Same thing applies to,

55 +/**
56 + * @brief Finds the time left to the provided date.
57 + *
58 + * @param[in] Date end_datetime is the date to find difference to
59 + * @return int - the amount of milliseconds left to the provided datetime
60 + */

Otherwise looks good. Nice work!

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

oh btw, do add copyright license headers to NextAlarm.qml,

/*
 * Copyright (C) 2014 Canonical Ltd
 *
 * This file is part of Ubuntu Clock App
 *
 * Ubuntu Clock App is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * Ubuntu Clock App is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

60. By twstd

Adjust to the requested styling

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :

FAILED: Continuous integration, rev:60
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~twstd-dev/ubuntu-clock-app/next-alarm/+merge/231243/+edit-commit-message

http://91.189.93.70:8080/job/ubuntu-clock-app-ci/407/
Executed test runs:
    FAILURE: http://91.189.93.70:8080/job/ubuntu-clock-app-utopic-amd64-ci/54/console

Click here to trigger a rebuild:
http://91.189.93.70:8080/job/ubuntu-clock-app-ci/407/rebuild

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: 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
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

What's going on here? Is the jenkins environment not clean?

Merging 'lp:ubuntu-clock-app' in to 'work'.
Not attempting to fix packaging branch ancestry, missing pristine tar data for version 3.1.
Text conflict in app/ubuntu-clock-app.qml
1 conflicts encountered.
bzr: ERROR: Conflicts from merge

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

Jenkins is cool now. This branch requires updating as there are actual code conflicts with clock app trunk.

review: Needs Fixing
61. By twstd

Resolve merge conflict and update to the newset model signals

Revision history for this message
twstd (twstd-dev) wrote :

Resolved

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

The fix for this landed in another MP sometime back. Hereby disapproving this MP.

review: Disapprove

Unmerged revisions

61. By twstd

Resolve merge conflict and update to the newset model signals

60. By twstd

Adjust to the requested styling

59. By twstd

Refactor current next alarm functionality

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'app/components/NextAlarm.qml'
2--- app/components/NextAlarm.qml 1970-01-01 00:00:00 +0000
3+++ app/components/NextAlarm.qml 2014-09-06 16:43:29 +0000
4@@ -0,0 +1,60 @@
5+/*
6+ * Copyright (C) 2014 Canonical Ltd
7+ *
8+ * This file is part of Ubuntu Clock App
9+ *
10+ * Ubuntu Clock App is free software: you can redistribute it and/or modify
11+ * it under the terms of the GNU General Public License version 3 as
12+ * published by the Free Software Foundation.
13+ *
14+ * Ubuntu Clock App is distributed in the hope that it will be useful,
15+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+ * GNU General Public License for more details.
18+ *
19+ * You should have received a copy of the GNU General Public License
20+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21+ */
22+
23+import QtQuick 2.0
24+import Ubuntu.Components 1.1
25+
26+/*
27+ A simple object that contains logic
28+ to find and retrieve next alarm from the model.
29+ We save only the date of an alarm, we don't need
30+ other information.
31+*/
32+QtObject {
33+ property AlarmModel currentAlarmModel
34+ property var alarmDate
35+
36+ Component.onCompleted: {
37+ getNextAlarm();
38+ currentAlarmModel.onDataChanged.connect( getNextAlarm );
39+ currentAlarmModel.onCountChanged.connect( getNextAlarm );
40+ }
41+
42+ /*
43+ Goes throgh the list of registered
44+ alarams and gets the first enabled one.
45+ */
46+ function getNextAlarm() {
47+ var are_alarms_available = currentAlarmModel && currentAlarmModel.count;
48+
49+ if ( are_alarms_available ) {
50+ var alarms_count = currentAlarmModel.count;
51+
52+ for ( var index = 0; index < alarms_count; ++index ) {
53+ var current_alarm = currentAlarmModel.get( index );
54+
55+ if ( current_alarm.enabled ) {
56+ alarmDate = current_alarm.date;
57+ return;
58+ }
59+ }
60+ }
61+
62+ alarmDate = undefined;
63+ }
64+}
65
66=== modified file 'app/components/Utils.js'
67--- app/components/Utils.js 2014-07-17 12:21:45 +0000
68+++ app/components/Utils.js 2014-09-06 16:43:29 +0000
69@@ -23,3 +23,42 @@
70 console.log("[LOG]" + message)
71 }
72 }
73+
74+/*
75+ Finds the time left to the provided date.
76+*/
77+var get_time_left_to = ( function() {
78+ // private scope
79+ var m_current_datetime = null;
80+
81+ return function( end_datetime ) {
82+ m_current_datetime = new Date();
83+
84+ // if the given date is ealrier than the current one
85+ // just give back null instead of negative offset
86+ return m_current_datetime < end_datetime ? ( end_datetime - m_current_datetime ) : 0;
87+ };
88+} )();
89+
90+/*
91+ Converts the given amount of milliseconds to
92+ a object representing hours and minutes.
93+ NOTE: since we cannot reference Qt objects from JavaScript
94+ object is a required step.
95+*/
96+var milliseconds_to_object = function( datetime_offset ) {
97+ // increase by a minute, so we could make a nicer time
98+ // to the next alarm, otherwise a minute always missing
99+ // which makes it look odd
100+ datetime_offset += 60000;
101+
102+ var days_in_offset = Math.floor( datetime_offset / ( 3600000 * 24 ) );
103+ var hours_in_offset = Math.floor( datetime_offset / 3600000 % 24 );
104+ var minutes_in_offset = Math.floor( datetime_offset / 60000 % 60 );
105+
106+ return {
107+ days : days_in_offset,
108+ hours : hours_in_offset,
109+ minutes : minutes_in_offset
110+ }
111+};
112
113=== modified file 'app/ubuntu-clock-app.qml'
114--- app/ubuntu-clock-app.qml 2014-08-26 20:20:37 +0000
115+++ app/ubuntu-clock-app.qml 2014-09-06 16:43:29 +0000
116@@ -17,6 +17,7 @@
117 */
118
119 import QtQuick 2.3
120+import DateTime 1.0
121 import U1db 1.0 as U1db
122 import Ubuntu.Components 1.1
123 import "clock"
124@@ -80,6 +81,15 @@
125 Component.onCompleted: Utils.log(debugMode, "Alarm Database loaded")
126 }
127
128+ NextAlarm {
129+ id: nextAlarm
130+ currentAlarmModel: alarmModel
131+ }
132+
133+ DateTime {
134+ id: dateTime
135+ }
136+
137 PageStack {
138 id: mainStack
139
140@@ -88,6 +98,17 @@
141 ClockPage {
142 id: clockPage
143
144+ Connections {
145+ target: nextAlarm
146+ onAlarmDateChanged: clockPage.setEdgeTitle()
147+ }
148+
149+ Connections {
150+ target: dateTime
151+ onLocalTimeStringChanged: clockPage.setEdgeTitle()
152+ }
153+
154+
155 /*
156 #FIXME: When the SDK support hiding the header, then enable the
157 clock page title. This will then set the correct window title on
158@@ -97,10 +118,31 @@
159 */
160
161 /*
162- #TODO: The bottom edge title should reflect the time to the next
163- alarm. For instance it should read "Next alarm in 9h23m".
164+ Sets the title according to the time left
165+ until the next alarm to go off.
166 */
167- bottomEdgeTitle: i18n.tr("Alarms")
168+ function setEdgeTitle() {
169+ var title_to_set = i18n.tr( "No active alarms" );
170+
171+ if ( nextAlarm.alarmDate ) {
172+ var time_left_to_first_alarm = Utils.get_time_left_to( nextAlarm.alarmDate );
173+
174+ var time_object = Utils.milliseconds_to_object( time_left_to_first_alarm );
175+
176+ title_to_set = i18n.tr( "Next alarm in" );
177+
178+ if ( time_object.days ) {
179+ title_to_set += i18n.tr( " %1d" ).arg( time_object.days );
180+ }
181+
182+ title_to_set += i18n.tr( " %1h %2m" )
183+ .arg( time_object.hours )
184+ .arg( time_object.minutes );
185+ }
186+
187+ bottomEdgeTitle = title_to_set;
188+ }
189+
190 bottomEdgePageComponent: AlarmPage {}
191 }
192 }

Subscribers

People subscribed via source and target branches

to all changes: