← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

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

 

Nekhelesh Ramananthan has proposed merging lp:~ubuntu-clock-dev/ubuntu-clock-app/stopwatch-feature-extended into lp:~ubuntu-clock-dev/ubuntu-clock-app/stopwatch-feature-staging.

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

Requested reviews:
  Ubuntu Clock Developers (ubuntu-clock-dev)
Related bugs:
  Bug #1484942 in Ubuntu Clock App: "[clock][ux] Stopwatch should keep running (in the background) even when the phone/clock app is turned off"
  https://bugs.launchpad.net/ubuntu-clock-app/+bug/1484942

For more details, see:
https://code.launchpad.net/~ubuntu-clock-dev/ubuntu-clock-app/stopwatch-feature-extended/+merge/268171

Added stopwatch feature to keep working in the background even if clock app is closed / phone is switched off.
-- 
Your team Ubuntu Clock Developers is requested to review the proposed merge of lp:~ubuntu-clock-dev/ubuntu-clock-app/stopwatch-feature-extended into lp:~ubuntu-clock-dev/ubuntu-clock-app/stopwatch-feature-staging.
=== modified file 'app/MainPage.qml'
--- app/MainPage.qml	2015-08-13 18:13:33 +0000
+++ app/MainPage.qml	2015-08-16 13:19:14 +0000
@@ -19,6 +19,7 @@
 import QtQuick 2.4
 import Ubuntu.Components 1.2
 import QtSystemInfo 5.0
+import Qt.labs.settings 1.0
 import "upstreamcomponents"
 import "alarm"
 import "clock"
@@ -58,6 +59,13 @@
         screenSaverEnabled: !stopwatchPage.running
     }
 
+    Settings {
+        id: stopwatchState
+        property alias stopwatchStartTime: stopwatchPage.startTime
+        property alias stopwatchRunning: stopwatchPage.running
+        property alias stopwatchOldDiff: stopwatchPage.oldDiff
+    }
+
     VisualItemModel {
         id: navigationModel
         ClockPage {
@@ -118,6 +126,12 @@
     ListView {
         id: listview
 
+        // Show the stopwatch page on app startup if it is running
+        Component.onCompleted: {
+            if (stopwatchState.stopwatchRunning)
+                positionViewAtIndex(1, ListView.SnapPosition)
+        }
+
         anchors.fill: parent
         model: navigationModel
         orientation: ListView.Horizontal

=== modified file 'app/stopwatch/StopwatchPage.qml'
--- app/stopwatch/StopwatchPage.qml	2015-08-16 12:56:16 +0000
+++ app/stopwatch/StopwatchPage.qml	2015-08-16 13:19:14 +0000
@@ -18,6 +18,7 @@
 
 import QtQuick 2.4
 import Ubuntu.Components 1.2
+import LapHistory 1.0
 
 Item {
     id: _stopwatchPage
@@ -60,18 +61,7 @@
         oldDiff = 0
         startTime = new Date()
         snapshot = startTime
-        lapsModel.clear()
-    }
-
-    ListModel {
-        id: lapsModel
-        function addLap(totalTime) {
-            if (lapsModel.count === 0) {
-                append({"laptime": totalTime, "totaltime": totalTime})
-            } else {
-                insert(0, {"laptime": totalTime - lapsModel.get(0).totaltime, "totaltime": totalTime})
-            }
-        }
+        laphistory.clear()
     }
 
     Timer {
@@ -162,7 +152,8 @@
                 onClicked: {
                     if (_stopwatchPage.running) {
                         _stopwatchPage.update()
-                        lapsModel.addLap(_stopwatchPage.totalTimeDiff)
+
+                        laphistory.addLap(_stopwatchPage.totalTimeDiff);
                     } else {
                         _stopwatchPage.clear()
                     }
@@ -183,15 +174,19 @@
                 right: parent.right
                 topMargin: units.gu(1)
             }
-            height: units.gu(7) * lapsModel.count
+            height: units.gu(7) * 5//laphistory.count
             sourceComponent: !_stopwatchPage.running && _stopwatchPage.totalTimeDiff == 0 ? undefined : lapListViewComponent
         }
 
+        LapHistory {
+            id: laphistory
+        }
+
         Component {
             id: lapListViewComponent
             LapListView {
                 id: lapListView
-                model: lapsModel
+                model: laphistory
             }
         }
     }

=== modified file 'backend/CMakeLists.txt'
--- backend/CMakeLists.txt	2015-07-16 21:02:18 +0000
+++ backend/CMakeLists.txt	2015-08-16 13:19:14 +0000
@@ -34,6 +34,12 @@
     modules/GeoLocation/geolocation.cpp
 )
 
+set(
+    laphistory_SRCS
+    modules/LapHistory/backend.cpp
+    modules/LapHistory/history.cpp
+)
+
 add_library(timezone MODULE
     ${timezone_SRCS}
 )
@@ -50,6 +56,11 @@
     ${geolocation_SRCS}
 )
 
+add_library(laphistory MODULE
+    ${laphistory_SRCS}
+)
+
+
 set_target_properties(timezone PROPERTIES
     LIBRARY_OUTPUT_DIRECTORY Timezone
 )
@@ -66,10 +77,15 @@
     LIBRARY_OUTPUT_DIRECTORY GeoLocation
 )
 
+set_target_properties(laphistory PROPERTIES
+    LIBRARY_OUTPUT_DIRECTORY LapHistory
+)
+
 qt5_use_modules(datetime Gui Qml Quick)
 qt5_use_modules(timezone Gui Qml Quick)
 qt5_use_modules(alarmsettings Gui Qml Quick DBus)
 qt5_use_modules(geolocation Gui Qml Quick)
+qt5_use_modules(laphistory Qml)
 
 # Copy qmldir file to build dir for running in QtCreator
 add_custom_target(timezone-qmldir ALL
@@ -92,6 +108,12 @@
     DEPENDS ${QMLFILES}
 )
 
+add_custom_target(laphistory-qmldir ALL
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/modules/LapHistory/qmldir ${CMAKE_CURRENT_BINARY_DIR}/LapHistory
+    DEPENDS ${QMLFILES}
+)
+
+
 # Install plugin file
 install(TARGETS timezone DESTINATION ${MODULE_PATH}/Timezone/)
 install(FILES   modules/Timezone/qmldir DESTINATION ${MODULE_PATH}/Timezone/)
@@ -104,3 +126,6 @@
 
 install(TARGETS geolocation DESTINATION ${MODULE_PATH}/GeoLocation/)
 install(FILES   modules/GeoLocation/qmldir DESTINATION ${MODULE_PATH}/GeoLocation/)
+
+install(TARGETS laphistory DESTINATION ${MODULE_PATH}/LapHistory/)
+install(FILES   modules/LapHistory/qmldir DESTINATION ${MODULE_PATH}/LapHistory/)

=== added directory 'backend/modules/LapHistory'
=== added file 'backend/modules/LapHistory/backend.cpp'
--- backend/modules/LapHistory/backend.cpp	1970-01-01 00:00:00 +0000
+++ backend/modules/LapHistory/backend.cpp	2015-08-16 13:19:14 +0000
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2015 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/>.
+ */
+
+#include <QtQml>
+#include <QtQml/QQmlContext>
+#include "backend.h"
+#include "history.h"
+
+void BackendPlugin::registerTypes(const char *uri)
+{
+    Q_ASSERT(uri == QLatin1String("LapHistory"));
+
+    qmlRegisterType<LapHistory>(uri, 1, 0, "LapHistory");
+}
+
+void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
+{
+    QQmlExtensionPlugin::initializeEngine(engine, uri);
+}

=== added file 'backend/modules/LapHistory/backend.h'
--- backend/modules/LapHistory/backend.h	1970-01-01 00:00:00 +0000
+++ backend/modules/LapHistory/backend.h	2015-08-16 13:19:14 +0000
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2015 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/>.
+ */
+
+#ifndef BACKEND_PLUGIN_H
+#define BACKEND_PLUGIN_H
+
+#include <QtQml/QQmlEngine>
+#include <QtQml/QQmlExtensionPlugin>
+
+class BackendPlugin : public QQmlExtensionPlugin
+{
+    Q_OBJECT
+    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
+
+public:
+    void registerTypes(const char *uri);
+    void initializeEngine(QQmlEngine *engine, const char *uri);
+};
+#endif // BACKEND_PLUGIN_H
+

=== added file 'backend/modules/LapHistory/history.cpp'
--- backend/modules/LapHistory/history.cpp	1970-01-01 00:00:00 +0000
+++ backend/modules/LapHistory/history.cpp	2015-08-16 13:19:14 +0000
@@ -0,0 +1,83 @@
+/*****************************************************************************
+ * Copyright: 2015 Michael Zanetti <michael_zanetti@xxxxxxx>                 *
+ *                                                                           *
+ * This file is part of ubuntu-authenticator                                 *
+ *                                                                           *
+ * This prject is free software: you can redistribute it and/or modify       *
+ * it under the terms of the GNU General Public License as published by      *
+ * the Free Software Foundation, either version 3 of the License, or         *
+ * (at your option) any later version.                                       *
+ *                                                                           *
+ * This project 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/>.     *
+ *                                                                           *
+ ****************************************************************************/
+
+#include "history.h"
+
+#include <QStandardPaths>
+#include <iostream>
+#include <QDebug>
+
+LapHistory::LapHistory(QObject *parent) :
+    QAbstractListModel(parent),
+    m_settings(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/com.ubuntu.clock/com.ubuntu.clock.stopwatch.conf", QSettings::IniFormat)
+{
+    std::cout << "Loading laps" << m_settings.fileName().toStdString() << std::endl;
+}
+
+int LapHistory::rowCount(const QModelIndex &parent) const
+{
+    return m_settings.value("laps").toList().count();
+}
+
+int LapHistory::count() const
+{
+    return m_settings.value("laps").toList().count();
+}
+
+QVariant LapHistory::data(const QModelIndex &index, int role) const
+{
+    switch (role) {
+    case RoleTotalTime:
+        return m_settings.value("laps").toList().at(index.row());
+    case RoleDiffToPrevious: {
+        int previous = 0;
+        if(index.row() != m_settings.value("laps").toList().count() - 1)
+        {
+            previous = data(this->index(index.row() + 1), RoleTotalTime).toInt();
+        }
+        return m_settings.value("laps").toList().at(index.row()).toInt() - previous;
+    }
+    }
+    return QVariant();
+}
+
+QHash<int, QByteArray> LapHistory::roleNames() const
+{
+    QHash< int, QByteArray> roles;
+    roles.insert(RoleTotalTime, "totaltime");
+    roles.insert(RoleDiffToPrevious, "laptime");
+    return roles;
+}
+
+void LapHistory::addLap(int timeDiff)
+{
+    QVariantList laps = m_settings.value("laps").toList();
+    beginInsertRows(QModelIndex(), 0, 0);
+    laps.prepend(timeDiff);
+    m_settings.setValue("laps", laps);
+    endInsertRows();
+}
+
+void LapHistory::clear()
+{
+    beginResetModel();
+    m_settings.setValue("laps", QVariantList());
+    endResetModel();
+}

=== added file 'backend/modules/LapHistory/history.h'
--- backend/modules/LapHistory/history.h	1970-01-01 00:00:00 +0000
+++ backend/modules/LapHistory/history.h	2015-08-16 13:19:14 +0000
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * Copyright: 2015 Michael Zanetti <michael_zanetti@xxxxxxx>                 *
+ *                                                                           *
+ * This file is part of ubuntu-authenticator                                 *
+ *                                                                           *
+ * This prject is free software: you can redistribute it and/or modify       *
+ * it under the terms of the GNU General Public License as published by      *
+ * the Free Software Foundation, either version 3 of the License, or         *
+ * (at your option) any later version.                                       *
+ *                                                                           *
+ * This project 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/>.     *
+ *                                                                           *
+ ****************************************************************************/
+
+#ifndef HISTORY_H
+#define HISTORY_H
+
+#include <QAbstractListModel>
+#include <QSettings>
+
+class LapHistory : public QAbstractListModel
+{
+    Q_OBJECT
+public:
+    enum Role {
+        RoleTotalTime,
+        RoleDiffToPrevious
+    };
+
+    explicit LapHistory(QObject *parent = 0);
+
+    int rowCount(const QModelIndex &parent) const;
+    QVariant data(const QModelIndex &index, int role) const;
+    QHash<int, QByteArray> roleNames() const override;
+
+
+public slots:
+    void addLap(int timeDiff);
+    void clear();
+    int count() const;
+
+private:
+    QSettings m_settings;
+
+};
+
+#endif // HISTORY_H

=== added file 'backend/modules/LapHistory/qmldir'
--- backend/modules/LapHistory/qmldir	1970-01-01 00:00:00 +0000
+++ backend/modules/LapHistory/qmldir	2015-08-16 13:19:14 +0000
@@ -0,0 +1,2 @@
+module LapHistory
+plugin laphistory

=== modified file 'debian/control'
--- debian/control	2015-08-13 18:44:07 +0000
+++ debian/control	2015-08-16 13:19:14 +0000
@@ -10,7 +10,8 @@
                ubuntu-touch-sounds,
                suru-icon-theme | ubuntu-mobile-icons,
                qml-module-qttest,
-	       qml-module-qtsysteminfo,	
+	       qml-module-qtsysteminfo,
+	       qml-module-qt-labs-settings,	
                qtdeclarative5-u1db1.0,
                qtdeclarative5-qtmultimedia-plugin,
                qtdeclarative5-qtpositioning-plugin,


Follow ups