Merge lp:~ubuntu-clock-dev/ubuntu-clock-app/stopwatch-feature-extended into lp:~ubuntu-clock-dev/ubuntu-clock-app/stopwatch-feature-staging

Proposed by Nekhelesh Ramananthan
Status: Merged
Approved by: Nekhelesh Ramananthan
Approved revision: 382
Merged at revision: 379
Proposed branch: lp:~ubuntu-clock-dev/ubuntu-clock-app/stopwatch-feature-extended
Merge into: lp:~ubuntu-clock-dev/ubuntu-clock-app/stopwatch-feature-staging
Diff against target: 460 lines (+284/-16)
11 files modified
app/MainPage.qml (+15/-0)
app/stopwatch/LapListView.qml (+1/-1)
app/stopwatch/StopwatchPage.qml (+8/-14)
backend/CMakeLists.txt (+25/-0)
backend/modules/Stopwatch/LapHistory/backend.cpp (+34/-0)
backend/modules/Stopwatch/LapHistory/backend.h (+35/-0)
backend/modules/Stopwatch/LapHistory/history.cpp (+97/-0)
backend/modules/Stopwatch/LapHistory/history.h (+64/-0)
backend/modules/Stopwatch/LapHistory/qmldir (+2/-0)
debian/changelog (+1/-0)
debian/control (+2/-1)
To merge this branch: bzr merge lp:~ubuntu-clock-dev/ubuntu-clock-app/stopwatch-feature-extended
Reviewer Review Type Date Requested Status
Nekhelesh Ramananthan Approve
Bartosz Kosiorek Approve
Review via email: mp+268171@code.launchpad.net

Commit message

Added stopwatch feature to keep working in the background even if clock app is closed / phone is switched off.

Description of the change

Added stopwatch feature to keep working in the background even if clock app is closed / phone is switched off.

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

@bartosz I made the following changes to your MP,

1. Renamed plugin to Stopwatch.LapHistory. (Much before our discussion yesterday. We can get back to this in a MP during the weekend) For now let's leave it as such

2. Added comments, fixme to the plugin for better understandability.

3. Stopwatch laps are stored in com.ubuntu.clock.conf file itself in the [Stopwatch] category.

4. Removed the int count() function since we don't need it anymore in the QML side.

Personally I think this branch is ready and so I am approving. Feel free to go through it once more on your own, test it and then top-approve it. Then we merge it into the stopwatch-staging branch and the merge that branch to trunk tonight.

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

I tested the swipe delete feature and it works correctly. I tested on phone and desktop, with multiple clock app restarts to check the stopwatch running background feature and no errors. everything works as expected.

review: Approve
Revision history for this message
Bartosz Kosiorek (gang65) wrote :

It is working correctly for me

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

* Does the MP add/remove user visible strings? If Yes, has the pot file been
    updated?

No strings changed.

* Does the MP change the UI? If Yes, has it been approved by design?

Minor UX change that was approved.

* Did you perform an exploratory manual test run of your code change and any
    related functionality?

Extensive testing done on desktop and phone

* If the MP fixes a bug or implements a feature, are there accompanying unit
    and autopilot tests?

Not required

* Is the clock app trunk buildable and runnable using Qtcreator?

Yes
* Was the debian changelog updated?

No!

* Was the copyright years updated if necessary?

Yes

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

Please update debian changelog since you are fixing a bug/feature request. thnx

review: Needs Fixing
382. By Bartosz Kosiorek

Keep running stopwatch even when the clock or phone is turned off (LP: #1484942)

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

Approved!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/MainPage.qml'
2--- app/MainPage.qml 2015-08-20 15:32:48 +0000
3+++ app/MainPage.qml 2015-08-20 20:37:24 +0000
4@@ -19,6 +19,7 @@
5 import QtQuick 2.4
6 import Ubuntu.Components 1.2
7 import QtSystemInfo 5.0
8+import Qt.labs.settings 1.0
9 import "upstreamcomponents"
10 import "alarm"
11 import "clock"
12@@ -59,6 +60,14 @@
13 screenSaverEnabled: !stopwatchPage.running
14 }
15
16+ Settings {
17+ id: stopwatchState
18+ category: "Stopwatch"
19+ property alias startTime: stopwatchPage.startTime
20+ property alias running: stopwatchPage.running
21+ property alias oldDiff: stopwatchPage.oldDiff
22+ }
23+
24 VisualItemModel {
25 id: navigationModel
26 ClockPage {
27@@ -89,6 +98,12 @@
28 ListView {
29 id: listview
30
31+ // Show the stopwatch page on app startup if it is running
32+ Component.onCompleted: {
33+ if (stopwatchState.running)
34+ positionViewAtIndex(1, ListView.SnapPosition)
35+ }
36+
37 anchors {
38 top: headerRow.bottom
39 left: parent.left
40
41=== modified file 'app/stopwatch/LapListView.qml'
42--- app/stopwatch/LapListView.qml 2015-08-20 15:52:32 +0000
43+++ app/stopwatch/LapListView.qml 2015-08-20 20:37:24 +0000
44@@ -81,7 +81,7 @@
45 Action {
46 iconName: "delete"
47 onTriggered: {
48- lapsModel.remove(index, 1)
49+ lapHistory.removeLap(index)
50 }
51 }
52 ]
53
54=== modified file 'app/stopwatch/StopwatchPage.qml'
55--- app/stopwatch/StopwatchPage.qml 2015-08-17 12:14:10 +0000
56+++ app/stopwatch/StopwatchPage.qml 2015-08-20 20:37:24 +0000
57@@ -18,6 +18,7 @@
58
59 import QtQuick 2.4
60 import Ubuntu.Components 1.2
61+import Stopwatch.LapHistory 1.0
62
63 Item {
64 id: _stopwatchPage
65@@ -57,18 +58,7 @@
66 oldDiff = 0
67 startTime = new Date()
68 snapshot = startTime
69- lapsModel.clear()
70- }
71-
72- ListModel {
73- id: lapsModel
74- function addLap(totalTime) {
75- if (lapsModel.count === 0) {
76- append({"laptime": totalTime, "totaltime": totalTime})
77- } else {
78- insert(0, {"laptime": totalTime - lapsModel.get(0).totaltime, "totaltime": totalTime})
79- }
80- }
81+ lapHistory.clear()
82 }
83
84 Timer {
85@@ -134,7 +124,7 @@
86 onClicked: {
87 if (_stopwatchPage.running) {
88 _stopwatchPage.update()
89- lapsModel.addLap(_stopwatchPage.totalTimeDiff)
90+ lapHistory.addLap(_stopwatchPage.totalTimeDiff)
91 } else {
92 _stopwatchPage.clear()
93 }
94@@ -165,11 +155,15 @@
95 }
96 }
97
98+ LapHistory {
99+ id: lapHistory
100+ }
101+
102 Component {
103 id: lapListViewComponent
104 LapListView {
105 id: lapListView
106- model: lapsModel
107+ model: lapHistory
108 }
109 }
110 }
111
112=== modified file 'backend/CMakeLists.txt'
113--- backend/CMakeLists.txt 2015-07-16 21:02:18 +0000
114+++ backend/CMakeLists.txt 2015-08-20 20:37:24 +0000
115@@ -34,6 +34,12 @@
116 modules/GeoLocation/geolocation.cpp
117 )
118
119+set(
120+ stopwatchlaphistory_SRCS
121+ modules/Stopwatch/LapHistory/backend.cpp
122+ modules/Stopwatch/LapHistory/history.cpp
123+)
124+
125 add_library(timezone MODULE
126 ${timezone_SRCS}
127 )
128@@ -50,6 +56,11 @@
129 ${geolocation_SRCS}
130 )
131
132+add_library(stopwatchlaphistory MODULE
133+ ${stopwatchlaphistory_SRCS}
134+)
135+
136+
137 set_target_properties(timezone PROPERTIES
138 LIBRARY_OUTPUT_DIRECTORY Timezone
139 )
140@@ -66,10 +77,15 @@
141 LIBRARY_OUTPUT_DIRECTORY GeoLocation
142 )
143
144+set_target_properties(stopwatchlaphistory PROPERTIES
145+ LIBRARY_OUTPUT_DIRECTORY Stopwatch/LapHistory
146+)
147+
148 qt5_use_modules(datetime Gui Qml Quick)
149 qt5_use_modules(timezone Gui Qml Quick)
150 qt5_use_modules(alarmsettings Gui Qml Quick DBus)
151 qt5_use_modules(geolocation Gui Qml Quick)
152+qt5_use_modules(stopwatchlaphistory Qml)
153
154 # Copy qmldir file to build dir for running in QtCreator
155 add_custom_target(timezone-qmldir ALL
156@@ -92,6 +108,12 @@
157 DEPENDS ${QMLFILES}
158 )
159
160+add_custom_target(stopwatchlaphistory-qmldir ALL
161+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/modules/Stopwatch/LapHistory/qmldir ${CMAKE_CURRENT_BINARY_DIR}/Stopwatch/LapHistory
162+ DEPENDS ${QMLFILES}
163+)
164+
165+
166 # Install plugin file
167 install(TARGETS timezone DESTINATION ${MODULE_PATH}/Timezone/)
168 install(FILES modules/Timezone/qmldir DESTINATION ${MODULE_PATH}/Timezone/)
169@@ -104,3 +126,6 @@
170
171 install(TARGETS geolocation DESTINATION ${MODULE_PATH}/GeoLocation/)
172 install(FILES modules/GeoLocation/qmldir DESTINATION ${MODULE_PATH}/GeoLocation/)
173+
174+install(TARGETS stopwatchlaphistory DESTINATION ${MODULE_PATH}/Stopwatch/LapHistory/)
175+install(FILES modules/Stopwatch/LapHistory/qmldir DESTINATION ${MODULE_PATH}/Stopwatch/LapHistory/)
176
177=== added directory 'backend/modules/Stopwatch'
178=== added directory 'backend/modules/Stopwatch/LapHistory'
179=== added file 'backend/modules/Stopwatch/LapHistory/backend.cpp'
180--- backend/modules/Stopwatch/LapHistory/backend.cpp 1970-01-01 00:00:00 +0000
181+++ backend/modules/Stopwatch/LapHistory/backend.cpp 2015-08-20 20:37:24 +0000
182@@ -0,0 +1,34 @@
183+/*
184+ * Copyright (C) 2015 Canonical Ltd
185+ *
186+ * This file is part of Ubuntu Clock App
187+ *
188+ * Ubuntu Clock App is free software: you can redistribute it and/or modify
189+ * it under the terms of the GNU General Public License version 3 as
190+ * published by the Free Software Foundation.
191+ *
192+ * Ubuntu Clock App is distributed in the hope that it will be useful,
193+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
194+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
195+ * GNU General Public License for more details.
196+ *
197+ * You should have received a copy of the GNU General Public License
198+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
199+ */
200+
201+#include <QtQml>
202+#include <QtQml/QQmlContext>
203+#include "backend.h"
204+#include "history.h"
205+
206+void BackendPlugin::registerTypes(const char *uri)
207+{
208+ Q_ASSERT(uri == QLatin1String("Stopwatch.LapHistory"));
209+
210+ qmlRegisterType<LapHistory>(uri, 1, 0, "LapHistory");
211+}
212+
213+void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
214+{
215+ QQmlExtensionPlugin::initializeEngine(engine, uri);
216+}
217
218=== added file 'backend/modules/Stopwatch/LapHistory/backend.h'
219--- backend/modules/Stopwatch/LapHistory/backend.h 1970-01-01 00:00:00 +0000
220+++ backend/modules/Stopwatch/LapHistory/backend.h 2015-08-20 20:37:24 +0000
221@@ -0,0 +1,35 @@
222+/*
223+ * Copyright (C) 2015 Canonical Ltd
224+ *
225+ * This file is part of Ubuntu Clock App
226+ *
227+ * Ubuntu Clock App is free software: you can redistribute it and/or modify
228+ * it under the terms of the GNU General Public License version 3 as
229+ * published by the Free Software Foundation.
230+ *
231+ * Ubuntu Clock App is distributed in the hope that it will be useful,
232+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
233+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
234+ * GNU General Public License for more details.
235+ *
236+ * You should have received a copy of the GNU General Public License
237+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
238+ */
239+
240+#ifndef BACKEND_PLUGIN_H
241+#define BACKEND_PLUGIN_H
242+
243+#include <QtQml/QQmlEngine>
244+#include <QtQml/QQmlExtensionPlugin>
245+
246+class BackendPlugin : public QQmlExtensionPlugin
247+{
248+ Q_OBJECT
249+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
250+
251+public:
252+ void registerTypes(const char *uri);
253+ void initializeEngine(QQmlEngine *engine, const char *uri);
254+};
255+#endif // BACKEND_PLUGIN_H
256+
257
258=== added file 'backend/modules/Stopwatch/LapHistory/history.cpp'
259--- backend/modules/Stopwatch/LapHistory/history.cpp 1970-01-01 00:00:00 +0000
260+++ backend/modules/Stopwatch/LapHistory/history.cpp 2015-08-20 20:37:24 +0000
261@@ -0,0 +1,97 @@
262+/*
263+ * Copyright (C) 2015 Canonical Ltd
264+ *
265+ * This file is part of Ubuntu Clock App
266+ *
267+ * Ubuntu Clock App is free software: you can redistribute it and/or modify
268+ * it under the terms of the GNU General Public License version 3 as
269+ * published by the Free Software Foundation.
270+ *
271+ * Ubuntu Clock App is distributed in the hope that it will be useful,
272+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
273+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
274+ * GNU General Public License for more details.
275+ *
276+ * You should have received a copy of the GNU General Public License
277+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
278+ */
279+
280+#include "history.h"
281+
282+#include <QStandardPaths>
283+#include <QDebug>
284+
285+LapHistory::LapHistory(QObject *parent) :
286+ QAbstractListModel(parent),
287+ /*
288+ #FIXME: Change QStandardPaths::ConfigLocation to QStandardPaths::AppConfigLocation
289+ when Ubuntu Touch moves over to Qt 5.5. AppConfigLocation will directly return
290+ /home/phablet/.config/com.ubuntu.clock path.
291+ */
292+ m_settings(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/com.ubuntu.clock/com.ubuntu.clock.conf", QSettings::IniFormat)
293+{
294+ qDebug() << "[LOG] Loading laps from " << m_settings.fileName();
295+}
296+
297+int LapHistory::rowCount(const QModelIndex &parent) const
298+{
299+ /*
300+ QT's models also handle tables and tree views, so the index is not just a
301+ integer but consists of a parent, row and a column. Since we using a simple
302+ list model, let's ignore the parent. Q_UNUSED(parent) gets rid of the
303+ compiler warning about the unused variable.
304+ */
305+ Q_UNUSED(parent)
306+
307+ return m_settings.value("Stopwatch/laps").toList().count();
308+}
309+
310+QVariant LapHistory::data(const QModelIndex &index, int role) const
311+{
312+ switch (role) {
313+ case RoleTotalTime:
314+ return m_settings.value("Stopwatch/laps").toList().at(index.row());
315+ case RoleDiffToPrevious: {
316+ int previous = 0;
317+ if(index.row() != m_settings.value("Stopwatch/laps").toList().count() - 1)
318+ {
319+ previous = data(this->index(index.row() + 1), RoleTotalTime).toInt();
320+ }
321+ return m_settings.value("Stopwatch/laps").toList().at(index.row()).toInt() - previous;
322+ }
323+ }
324+ return QVariant();
325+}
326+
327+QHash<int, QByteArray> LapHistory::roleNames() const
328+{
329+ QHash< int, QByteArray> roles;
330+ roles.insert(RoleTotalTime, "totaltime");
331+ roles.insert(RoleDiffToPrevious, "laptime");
332+ return roles;
333+}
334+
335+void LapHistory::addLap(int timeDiff)
336+{
337+ QVariantList laps = m_settings.value("Stopwatch/laps").toList();
338+ beginInsertRows(QModelIndex(), 0, 0);
339+ laps.prepend(timeDiff);
340+ m_settings.setValue("Stopwatch/laps", laps);
341+ endInsertRows();
342+}
343+
344+void LapHistory::removeLap(int lapIndex)
345+{
346+ QVariantList laps = m_settings.value("Stopwatch/laps").toList();
347+ beginRemoveRows(QModelIndex(), lapIndex, lapIndex);
348+ laps.removeAt(lapIndex);
349+ m_settings.setValue("Stopwatch/laps", laps);
350+ endRemoveRows();
351+}
352+
353+void LapHistory::clear()
354+{
355+ beginResetModel();
356+ m_settings.setValue("Stopwatch/laps", QVariantList());
357+ endResetModel();
358+}
359
360=== added file 'backend/modules/Stopwatch/LapHistory/history.h'
361--- backend/modules/Stopwatch/LapHistory/history.h 1970-01-01 00:00:00 +0000
362+++ backend/modules/Stopwatch/LapHistory/history.h 2015-08-20 20:37:24 +0000
363@@ -0,0 +1,64 @@
364+/*
365+ * Copyright (C) 2015 Canonical Ltd
366+ *
367+ * This file is part of Ubuntu Clock App
368+ *
369+ * Ubuntu Clock App is free software: you can redistribute it and/or modify
370+ * it under the terms of the GNU General Public License version 3 as
371+ * published by the Free Software Foundation.
372+ *
373+ * Ubuntu Clock App is distributed in the hope that it will be useful,
374+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
375+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376+ * GNU General Public License for more details.
377+ *
378+ * You should have received a copy of the GNU General Public License
379+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
380+ */
381+
382+#ifndef HISTORY_H
383+#define HISTORY_H
384+
385+#include <QAbstractListModel>
386+#include <QSettings>
387+
388+class LapHistory : public QAbstractListModel
389+{
390+ Q_OBJECT
391+
392+public:
393+ enum Role {
394+ RoleTotalTime,
395+ RoleDiffToPrevious
396+ };
397+
398+ explicit LapHistory(QObject *parent = 0);
399+
400+ /*
401+ Let's override the pure virtual functions (the ones marked as
402+ "virtual" and have "= 0" in the end.
403+ */
404+ int rowCount(const QModelIndex &parent) const;
405+ QVariant data(const QModelIndex &index, int role) const;
406+
407+ /*
408+ As QML can't really deal with the Roles enum above, we need a mapping
409+ between the enum and strings
410+ */
411+ QHash<int, QByteArray> roleNames() const override;
412+
413+public slots:
414+ // Function to add a stopwatch lap
415+ void addLap(int timeDiff);
416+
417+ // Function to remove a stopwatch lap
418+ void removeLap(int lapIndex);
419+
420+ // Function to clear all stopwatch laps
421+ void clear();
422+
423+private:
424+ QSettings m_settings;
425+};
426+
427+#endif // HISTORY_H
428
429=== added file 'backend/modules/Stopwatch/LapHistory/qmldir'
430--- backend/modules/Stopwatch/LapHistory/qmldir 1970-01-01 00:00:00 +0000
431+++ backend/modules/Stopwatch/LapHistory/qmldir 2015-08-20 20:37:24 +0000
432@@ -0,0 +1,2 @@
433+module Stopwatch.LapHistory
434+plugin stopwatchlaphistory
435
436=== modified file 'debian/changelog'
437--- debian/changelog 2015-08-17 12:27:20 +0000
438+++ debian/changelog 2015-08-20 20:37:24 +0000
439@@ -7,6 +7,7 @@
440 * Fix default alarm time issue (LP: #1484926)
441 * Translate city and country names after language switch (LP: #1477492)
442 * Fix issue when unable to add city/country with apostrophes (LP: #1473074)
443+ * Keep running stopwatch even when the clock or phone is turned off (LP: #1484942)
444
445 [Nekhelesh Ramananthan]
446 * Increase the height of times in the alarm screen (LP: #1365428)
447
448=== modified file 'debian/control'
449--- debian/control 2015-08-13 18:44:07 +0000
450+++ debian/control 2015-08-20 20:37:24 +0000
451@@ -10,7 +10,8 @@
452 ubuntu-touch-sounds,
453 suru-icon-theme | ubuntu-mobile-icons,
454 qml-module-qttest,
455- qml-module-qtsysteminfo,
456+ qml-module-qtsysteminfo,
457+ qml-module-qt-labs-settings,
458 qtdeclarative5-u1db1.0,
459 qtdeclarative5-qtmultimedia-plugin,
460 qtdeclarative5-qtpositioning-plugin,

Subscribers

People subscribed via source and target branches

to all changes: