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
=== modified file 'app/MainPage.qml'
--- app/MainPage.qml 2015-08-20 15:32:48 +0000
+++ app/MainPage.qml 2015-08-20 20:37:24 +0000
@@ -19,6 +19,7 @@
19import QtQuick 2.419import QtQuick 2.4
20import Ubuntu.Components 1.220import Ubuntu.Components 1.2
21import QtSystemInfo 5.021import QtSystemInfo 5.0
22import Qt.labs.settings 1.0
22import "upstreamcomponents"23import "upstreamcomponents"
23import "alarm"24import "alarm"
24import "clock"25import "clock"
@@ -59,6 +60,14 @@
59 screenSaverEnabled: !stopwatchPage.running60 screenSaverEnabled: !stopwatchPage.running
60 }61 }
6162
63 Settings {
64 id: stopwatchState
65 category: "Stopwatch"
66 property alias startTime: stopwatchPage.startTime
67 property alias running: stopwatchPage.running
68 property alias oldDiff: stopwatchPage.oldDiff
69 }
70
62 VisualItemModel {71 VisualItemModel {
63 id: navigationModel72 id: navigationModel
64 ClockPage {73 ClockPage {
@@ -89,6 +98,12 @@
89 ListView {98 ListView {
90 id: listview99 id: listview
91100
101 // Show the stopwatch page on app startup if it is running
102 Component.onCompleted: {
103 if (stopwatchState.running)
104 positionViewAtIndex(1, ListView.SnapPosition)
105 }
106
92 anchors {107 anchors {
93 top: headerRow.bottom108 top: headerRow.bottom
94 left: parent.left109 left: parent.left
95110
=== modified file 'app/stopwatch/LapListView.qml'
--- app/stopwatch/LapListView.qml 2015-08-20 15:52:32 +0000
+++ app/stopwatch/LapListView.qml 2015-08-20 20:37:24 +0000
@@ -81,7 +81,7 @@
81 Action {81 Action {
82 iconName: "delete"82 iconName: "delete"
83 onTriggered: {83 onTriggered: {
84 lapsModel.remove(index, 1)84 lapHistory.removeLap(index)
85 }85 }
86 }86 }
87 ]87 ]
8888
=== modified file 'app/stopwatch/StopwatchPage.qml'
--- app/stopwatch/StopwatchPage.qml 2015-08-17 12:14:10 +0000
+++ app/stopwatch/StopwatchPage.qml 2015-08-20 20:37:24 +0000
@@ -18,6 +18,7 @@
1818
19import QtQuick 2.419import QtQuick 2.4
20import Ubuntu.Components 1.220import Ubuntu.Components 1.2
21import Stopwatch.LapHistory 1.0
2122
22Item {23Item {
23 id: _stopwatchPage24 id: _stopwatchPage
@@ -57,18 +58,7 @@
57 oldDiff = 058 oldDiff = 0
58 startTime = new Date()59 startTime = new Date()
59 snapshot = startTime60 snapshot = startTime
60 lapsModel.clear()61 lapHistory.clear()
61 }
62
63 ListModel {
64 id: lapsModel
65 function addLap(totalTime) {
66 if (lapsModel.count === 0) {
67 append({"laptime": totalTime, "totaltime": totalTime})
68 } else {
69 insert(0, {"laptime": totalTime - lapsModel.get(0).totaltime, "totaltime": totalTime})
70 }
71 }
72 }62 }
7363
74 Timer {64 Timer {
@@ -134,7 +124,7 @@
134 onClicked: {124 onClicked: {
135 if (_stopwatchPage.running) {125 if (_stopwatchPage.running) {
136 _stopwatchPage.update()126 _stopwatchPage.update()
137 lapsModel.addLap(_stopwatchPage.totalTimeDiff)127 lapHistory.addLap(_stopwatchPage.totalTimeDiff)
138 } else {128 } else {
139 _stopwatchPage.clear()129 _stopwatchPage.clear()
140 }130 }
@@ -165,11 +155,15 @@
165 }155 }
166 }156 }
167157
158 LapHistory {
159 id: lapHistory
160 }
161
168 Component {162 Component {
169 id: lapListViewComponent163 id: lapListViewComponent
170 LapListView {164 LapListView {
171 id: lapListView165 id: lapListView
172 model: lapsModel166 model: lapHistory
173 }167 }
174 }168 }
175}169}
176170
=== modified file 'backend/CMakeLists.txt'
--- backend/CMakeLists.txt 2015-07-16 21:02:18 +0000
+++ backend/CMakeLists.txt 2015-08-20 20:37:24 +0000
@@ -34,6 +34,12 @@
34 modules/GeoLocation/geolocation.cpp34 modules/GeoLocation/geolocation.cpp
35)35)
3636
37set(
38 stopwatchlaphistory_SRCS
39 modules/Stopwatch/LapHistory/backend.cpp
40 modules/Stopwatch/LapHistory/history.cpp
41)
42
37add_library(timezone MODULE43add_library(timezone MODULE
38 ${timezone_SRCS}44 ${timezone_SRCS}
39)45)
@@ -50,6 +56,11 @@
50 ${geolocation_SRCS}56 ${geolocation_SRCS}
51)57)
5258
59add_library(stopwatchlaphistory MODULE
60 ${stopwatchlaphistory_SRCS}
61)
62
63
53set_target_properties(timezone PROPERTIES64set_target_properties(timezone PROPERTIES
54 LIBRARY_OUTPUT_DIRECTORY Timezone65 LIBRARY_OUTPUT_DIRECTORY Timezone
55)66)
@@ -66,10 +77,15 @@
66 LIBRARY_OUTPUT_DIRECTORY GeoLocation77 LIBRARY_OUTPUT_DIRECTORY GeoLocation
67)78)
6879
80set_target_properties(stopwatchlaphistory PROPERTIES
81 LIBRARY_OUTPUT_DIRECTORY Stopwatch/LapHistory
82)
83
69qt5_use_modules(datetime Gui Qml Quick)84qt5_use_modules(datetime Gui Qml Quick)
70qt5_use_modules(timezone Gui Qml Quick)85qt5_use_modules(timezone Gui Qml Quick)
71qt5_use_modules(alarmsettings Gui Qml Quick DBus)86qt5_use_modules(alarmsettings Gui Qml Quick DBus)
72qt5_use_modules(geolocation Gui Qml Quick)87qt5_use_modules(geolocation Gui Qml Quick)
88qt5_use_modules(stopwatchlaphistory Qml)
7389
74# Copy qmldir file to build dir for running in QtCreator90# Copy qmldir file to build dir for running in QtCreator
75add_custom_target(timezone-qmldir ALL91add_custom_target(timezone-qmldir ALL
@@ -92,6 +108,12 @@
92 DEPENDS ${QMLFILES}108 DEPENDS ${QMLFILES}
93)109)
94110
111add_custom_target(stopwatchlaphistory-qmldir ALL
112 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/modules/Stopwatch/LapHistory/qmldir ${CMAKE_CURRENT_BINARY_DIR}/Stopwatch/LapHistory
113 DEPENDS ${QMLFILES}
114)
115
116
95# Install plugin file117# Install plugin file
96install(TARGETS timezone DESTINATION ${MODULE_PATH}/Timezone/)118install(TARGETS timezone DESTINATION ${MODULE_PATH}/Timezone/)
97install(FILES modules/Timezone/qmldir DESTINATION ${MODULE_PATH}/Timezone/)119install(FILES modules/Timezone/qmldir DESTINATION ${MODULE_PATH}/Timezone/)
@@ -104,3 +126,6 @@
104126
105install(TARGETS geolocation DESTINATION ${MODULE_PATH}/GeoLocation/)127install(TARGETS geolocation DESTINATION ${MODULE_PATH}/GeoLocation/)
106install(FILES modules/GeoLocation/qmldir DESTINATION ${MODULE_PATH}/GeoLocation/)128install(FILES modules/GeoLocation/qmldir DESTINATION ${MODULE_PATH}/GeoLocation/)
129
130install(TARGETS stopwatchlaphistory DESTINATION ${MODULE_PATH}/Stopwatch/LapHistory/)
131install(FILES modules/Stopwatch/LapHistory/qmldir DESTINATION ${MODULE_PATH}/Stopwatch/LapHistory/)
107132
=== added directory 'backend/modules/Stopwatch'
=== added directory 'backend/modules/Stopwatch/LapHistory'
=== added file 'backend/modules/Stopwatch/LapHistory/backend.cpp'
--- backend/modules/Stopwatch/LapHistory/backend.cpp 1970-01-01 00:00:00 +0000
+++ backend/modules/Stopwatch/LapHistory/backend.cpp 2015-08-20 20:37:24 +0000
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2015 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 "history.h"
23
24void BackendPlugin::registerTypes(const char *uri)
25{
26 Q_ASSERT(uri == QLatin1String("Stopwatch.LapHistory"));
27
28 qmlRegisterType<LapHistory>(uri, 1, 0, "LapHistory");
29}
30
31void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
32{
33 QQmlExtensionPlugin::initializeEngine(engine, uri);
34}
035
=== added file 'backend/modules/Stopwatch/LapHistory/backend.h'
--- backend/modules/Stopwatch/LapHistory/backend.h 1970-01-01 00:00:00 +0000
+++ backend/modules/Stopwatch/LapHistory/backend.h 2015-08-20 20:37:24 +0000
@@ -0,0 +1,35 @@
1/*
2 * Copyright (C) 2015 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/Stopwatch/LapHistory/history.cpp'
--- backend/modules/Stopwatch/LapHistory/history.cpp 1970-01-01 00:00:00 +0000
+++ backend/modules/Stopwatch/LapHistory/history.cpp 2015-08-20 20:37:24 +0000
@@ -0,0 +1,97 @@
1/*
2 * Copyright (C) 2015 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 "history.h"
20
21#include <QStandardPaths>
22#include <QDebug>
23
24LapHistory::LapHistory(QObject *parent) :
25 QAbstractListModel(parent),
26 /*
27 #FIXME: Change QStandardPaths::ConfigLocation to QStandardPaths::AppConfigLocation
28 when Ubuntu Touch moves over to Qt 5.5. AppConfigLocation will directly return
29 /home/phablet/.config/com.ubuntu.clock path.
30 */
31 m_settings(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/com.ubuntu.clock/com.ubuntu.clock.conf", QSettings::IniFormat)
32{
33 qDebug() << "[LOG] Loading laps from " << m_settings.fileName();
34}
35
36int LapHistory::rowCount(const QModelIndex &parent) const
37{
38 /*
39 QT's models also handle tables and tree views, so the index is not just a
40 integer but consists of a parent, row and a column. Since we using a simple
41 list model, let's ignore the parent. Q_UNUSED(parent) gets rid of the
42 compiler warning about the unused variable.
43 */
44 Q_UNUSED(parent)
45
46 return m_settings.value("Stopwatch/laps").toList().count();
47}
48
49QVariant LapHistory::data(const QModelIndex &index, int role) const
50{
51 switch (role) {
52 case RoleTotalTime:
53 return m_settings.value("Stopwatch/laps").toList().at(index.row());
54 case RoleDiffToPrevious: {
55 int previous = 0;
56 if(index.row() != m_settings.value("Stopwatch/laps").toList().count() - 1)
57 {
58 previous = data(this->index(index.row() + 1), RoleTotalTime).toInt();
59 }
60 return m_settings.value("Stopwatch/laps").toList().at(index.row()).toInt() - previous;
61 }
62 }
63 return QVariant();
64}
65
66QHash<int, QByteArray> LapHistory::roleNames() const
67{
68 QHash< int, QByteArray> roles;
69 roles.insert(RoleTotalTime, "totaltime");
70 roles.insert(RoleDiffToPrevious, "laptime");
71 return roles;
72}
73
74void LapHistory::addLap(int timeDiff)
75{
76 QVariantList laps = m_settings.value("Stopwatch/laps").toList();
77 beginInsertRows(QModelIndex(), 0, 0);
78 laps.prepend(timeDiff);
79 m_settings.setValue("Stopwatch/laps", laps);
80 endInsertRows();
81}
82
83void LapHistory::removeLap(int lapIndex)
84{
85 QVariantList laps = m_settings.value("Stopwatch/laps").toList();
86 beginRemoveRows(QModelIndex(), lapIndex, lapIndex);
87 laps.removeAt(lapIndex);
88 m_settings.setValue("Stopwatch/laps", laps);
89 endRemoveRows();
90}
91
92void LapHistory::clear()
93{
94 beginResetModel();
95 m_settings.setValue("Stopwatch/laps", QVariantList());
96 endResetModel();
97}
098
=== added file 'backend/modules/Stopwatch/LapHistory/history.h'
--- backend/modules/Stopwatch/LapHistory/history.h 1970-01-01 00:00:00 +0000
+++ backend/modules/Stopwatch/LapHistory/history.h 2015-08-20 20:37:24 +0000
@@ -0,0 +1,64 @@
1/*
2 * Copyright (C) 2015 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 HISTORY_H
20#define HISTORY_H
21
22#include <QAbstractListModel>
23#include <QSettings>
24
25class LapHistory : public QAbstractListModel
26{
27 Q_OBJECT
28
29public:
30 enum Role {
31 RoleTotalTime,
32 RoleDiffToPrevious
33 };
34
35 explicit LapHistory(QObject *parent = 0);
36
37 /*
38 Let's override the pure virtual functions (the ones marked as
39 "virtual" and have "= 0" in the end.
40 */
41 int rowCount(const QModelIndex &parent) const;
42 QVariant data(const QModelIndex &index, int role) const;
43
44 /*
45 As QML can't really deal with the Roles enum above, we need a mapping
46 between the enum and strings
47 */
48 QHash<int, QByteArray> roleNames() const override;
49
50public slots:
51 // Function to add a stopwatch lap
52 void addLap(int timeDiff);
53
54 // Function to remove a stopwatch lap
55 void removeLap(int lapIndex);
56
57 // Function to clear all stopwatch laps
58 void clear();
59
60private:
61 QSettings m_settings;
62};
63
64#endif // HISTORY_H
065
=== added file 'backend/modules/Stopwatch/LapHistory/qmldir'
--- backend/modules/Stopwatch/LapHistory/qmldir 1970-01-01 00:00:00 +0000
+++ backend/modules/Stopwatch/LapHistory/qmldir 2015-08-20 20:37:24 +0000
@@ -0,0 +1,2 @@
1module Stopwatch.LapHistory
2plugin stopwatchlaphistory
03
=== modified file 'debian/changelog'
--- debian/changelog 2015-08-17 12:27:20 +0000
+++ debian/changelog 2015-08-20 20:37:24 +0000
@@ -7,6 +7,7 @@
7 * Fix default alarm time issue (LP: #1484926)7 * Fix default alarm time issue (LP: #1484926)
8 * Translate city and country names after language switch (LP: #1477492)8 * Translate city and country names after language switch (LP: #1477492)
9 * Fix issue when unable to add city/country with apostrophes (LP: #1473074) 9 * Fix issue when unable to add city/country with apostrophes (LP: #1473074)
10 * Keep running stopwatch even when the clock or phone is turned off (LP: #1484942)
1011
11 [Nekhelesh Ramananthan]12 [Nekhelesh Ramananthan]
12 * Increase the height of times in the alarm screen (LP: #1365428)13 * Increase the height of times in the alarm screen (LP: #1365428)
1314
=== modified file 'debian/control'
--- debian/control 2015-08-13 18:44:07 +0000
+++ debian/control 2015-08-20 20:37:24 +0000
@@ -10,7 +10,8 @@
10 ubuntu-touch-sounds,10 ubuntu-touch-sounds,
11 suru-icon-theme | ubuntu-mobile-icons,11 suru-icon-theme | ubuntu-mobile-icons,
12 qml-module-qttest,12 qml-module-qttest,
13 qml-module-qtsysteminfo, 13 qml-module-qtsysteminfo,
14 qml-module-qt-labs-settings,
14 qtdeclarative5-u1db1.0,15 qtdeclarative5-u1db1.0,
15 qtdeclarative5-qtmultimedia-plugin,16 qtdeclarative5-qtmultimedia-plugin,
16 qtdeclarative5-qtpositioning-plugin,17 qtdeclarative5-qtpositioning-plugin,

Subscribers

People subscribed via source and target branches

to all changes: