diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2016-02-18 09:13:32 +0100 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2016-02-18 09:13:32 +0100 |
| commit | f4910b3ac84c72a7e17c99895a3b9abb0e9534fe (patch) | |
| tree | 91ae8cfd80dc3d7a2adedee9cab0d407c5c23c84 /rockwork | |
| parent | 7305ce8e080d0a6ee7505fe978a2e601b56a5ce8 (diff) | |
| parent | 8f014f0915c7bdc97573f953aa9a3ae25a5f953a (diff) | |
Merge branch 'rockwork'
Conflicts:
po/de.po
po/en_GB.po
po/eu.po
po/fr.po
po/hu.po
po/it.po
po/pt.po
po/rockwork.mzanetti.pot
po/ru.po
po/template.pot
rockwork/InfoPage.qml
rockwork/Main.qml
rockwork/NotificationsPage.qml
rockworkd/rockworkd.pro
version.pri
Diffstat (limited to 'rockwork')
| -rw-r--r-- | rockwork/InfoPage.qml | 74 | ||||
| -rw-r--r-- | rockwork/Main.qml | 101 | ||||
| -rw-r--r-- | rockwork/NotificationsPage.qml | 88 | ||||
| -rw-r--r-- | rockwork/notificationsourcemodel.cpp | 10 | ||||
| -rw-r--r-- | rockwork/notificationsourcemodel.h | 3 | ||||
| -rw-r--r-- | rockwork/pebbles.cpp | 27 | ||||
| -rw-r--r-- | rockwork/pebbles.h | 6 |
7 files changed, 300 insertions, 9 deletions
diff --git a/rockwork/InfoPage.qml b/rockwork/InfoPage.qml new file mode 100644 index 0000000..1427380 --- /dev/null +++ b/rockwork/InfoPage.qml @@ -0,0 +1,74 @@ +import QtQuick 2.4 +import QtQuick.Layouts 1.1 +import Ubuntu.Components 1.3 +import Ubuntu.Components.ListItems 1.3 + +Page { + title: "About RockWork" + + Flickable { + anchors.fill: parent + contentHeight: contentColumn.height + units.gu(4) + + ColumnLayout { + id: contentColumn + anchors { left: parent.left; top: parent.top; right: parent.right; margins: units.gu(2) } + spacing: units.gu(2) + + RowLayout { + Layout.fillWidth: true + spacing: units.gu(2) + UbuntuShape { + source: Image { + anchors.fill: parent + source: "artwork/rockwork.svg" + } + height: units.gu(6) + width: height + } + + Label { + text: i18n.tr("Version %1").arg(version) + Layout.fillWidth: true + fontSize: "large" + } + } + + ThinDivider {} + + Label { + text: i18n.tr("Legal") + Layout.fillWidth: true + font.bold: true + } + + Label { + text: "This program 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, version 3 of the License.<br>" + + + "This program 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.<br>" + + + "You should have received a copy of the GNU General Public License" + + "along with this program. If not, see <http://www.gnu.org/licenses/>." + Layout.fillWidth: true + wrapMode: Text.WordWrap + } + + Label { + text: i18n.tr("This application is neither affiliated with nor endorsed by Pebble Technology Corp.") + Layout.fillWidth: true + wrapMode: Text.WordWrap + } + Label { + text: i18n.tr("Pebble is a trademark of Pebble Technology Corp.") + Layout.fillWidth: true + wrapMode: Text.WordWrap + } + } + } +} + diff --git a/rockwork/Main.qml b/rockwork/Main.qml new file mode 100644 index 0000000..a4726b9 --- /dev/null +++ b/rockwork/Main.qml @@ -0,0 +1,101 @@ +import QtQuick 2.4 +import QtQuick.Layouts 1.1 +import Ubuntu.Components 1.3 +import RockWork 1.0 + +/*! + \brief MainView with a Label and Button elements. +*/ + +MainView { + applicationName: "rockwork.mzanetti" + + width: units.gu(40) + height: units.gu(70) + + ServiceController { + id: serviceController + serviceName: "rockworkd" + Component.onCompleted: { + if (!serviceController.serviceFileInstalled) { + print("Service file not installed. Installing now.") + serviceController.installServiceFile(); + } + if (!serviceController.serviceRunning) { + print("Service not running. Starting now.") + serviceController.startService(); + } + if (pebbles.version !== version) { + print("Service file version (", version, ") is not equal running service version (", pebbles.version, "). Restarting service.") + serviceController.restartService(); + } + } + } + + Pebbles { + id: pebbles + onCountChanged: loadStack() + onConnectedToServiceChanged: loadStack(); + } + + function loadStack() { + pageStack.clear() + if (!pebbles.connectedToService) { + pageStack.push(loadingComponent) + } else if (pebbles.count == 1) { + pageStack.push(Qt.resolvedUrl("MainMenuPage.qml"), {pebble: pebbles.get(0)}) + } else { + pageStack.push(Qt.resolvedUrl("PebblesPage.qml")) + } + } + + PageStack { + id: pageStack + Component.onCompleted: loadStack(); + } + + Component { + id: loadingComponent + Page { + title: "RockWork" + + Column { + width: parent.width - units.gu(4) + anchors.centerIn: parent + spacing: units.gu(4) + + Rectangle { + id: upgradeIcon + height: units.gu(10) + width: height + radius: width / 2 + color: UbuntuColors.blue + anchors.horizontalCenter: parent.horizontalCenter + Icon { + anchors.fill: parent + anchors.margins: units.gu(1) + name: "preferences-system-updates-symbolic" + color: "white" + } + + RotationAnimation on rotation { + duration: 2000 + loops: Animation.Infinite + from: 0 + to: 360 + running: upgradeIcon.visible + } + visible: true + } + + Label { + width: parent.width + horizontalAlignment: Text.AlignHCenter + fontSize: "large" + text: i18n.tr("Loading...") + } + } + + } + } +} diff --git a/rockwork/NotificationsPage.qml b/rockwork/NotificationsPage.qml new file mode 100644 index 0000000..d3c9ff9 --- /dev/null +++ b/rockwork/NotificationsPage.qml @@ -0,0 +1,88 @@ +import QtQuick 2.4 +import QtQuick.Layouts 1.1 +import Ubuntu.Components 1.3 +import RockWork 1.0 + +Page { + id: root + title: i18n.tr("Notifications") + + property var pebble: null + + ColumnLayout { + anchors.fill: parent + anchors.topMargin: units.gu(1) + + Item { + Layout.fillWidth: true + implicitHeight: infoLabel.height + + Label { + id: infoLabel + anchors { + left: parent.left + right: parent.right + margins: units.gu(2) + } + + wrapMode: Text.WordWrap + text: i18n.tr("Entries here will be added as notifications appear on the phone. Selected notifications will be shown on your Pebble smartwatch.") + } + } + + + ListView { + Layout.fillWidth: true + Layout.fillHeight: true + clip: true + model: root.pebble.notifications + + delegate: ListItem { + ListItemLayout { + title.text: model.name + + UbuntuShape { + SlotsLayout.position: SlotsLayout.Leading; + height: units.gu(5) + width: height + backgroundColor: { + // Add some hacks for known icons + switch (model.icon) { + case "calendar": + return UbuntuColors.orange; + case "settings": + return "grey"; + case "dialog-question-symbolic": + return UbuntuColors.red; + case "alarm-clock": + return UbuntuColors.purple; + case "gpm-battery-050": + return UbuntuColors.green; + } + return "black" + } + source: Image { + height: parent.height + width: parent.width + source: model.icon.indexOf("/") === 0 ? "file://" + model.icon : "" + } + Icon { + anchors.fill: parent + anchors.margins: units.gu(.5) + name: model.icon.indexOf("/") !== 0 ? model.icon : "" + color: "white" + } + } + + Switch { + checked: model.enabled + SlotsLayout.position: SlotsLayout.Trailing; + onClicked: { + root.pebble.setNotificationFilter(model.id, checked) + } + } + } + } + } + } +} diff --git a/rockwork/notificationsourcemodel.cpp b/rockwork/notificationsourcemodel.cpp index cbb75ca..83e87f0 100644 --- a/rockwork/notificationsourcemodel.cpp +++ b/rockwork/notificationsourcemodel.cpp @@ -1,5 +1,8 @@ #include "notificationsourcemodel.h" +#include <QStandardPaths> +#include <QFileInfo> +#include <QDir> #include <QSettings> #include <QDebug> @@ -21,6 +24,8 @@ QVariant NotificationSourceModel::data(const QModelIndex &index, int role) const return item.m_displayName; case RoleEnabled: return item.m_enabled; + case RoleId: + return item.m_id; case RoleIcon: return item.m_icon; } @@ -33,6 +38,7 @@ QHash<int, QByteArray> NotificationSourceModel::roleNames() const roles.insert(RoleName, "name"); roles.insert(RoleEnabled, "enabled"); roles.insert(RoleIcon, "icon"); + roles.insert(RoleId, "id"); return roles; } @@ -59,10 +65,6 @@ void NotificationSourceModel::insert(const QString &sourceId, bool enabled) } } -#include <QStandardPaths> -#include <QFileInfo> -#include <QDir> - NotificationSourceItem NotificationSourceModel::fromDesktopFile(const QString &sourceId) { NotificationSourceItem ret; diff --git a/rockwork/notificationsourcemodel.h b/rockwork/notificationsourcemodel.h index 89fa26f..7349d84 100644 --- a/rockwork/notificationsourcemodel.h +++ b/rockwork/notificationsourcemodel.h @@ -24,7 +24,8 @@ public: enum Roles { RoleName, RoleEnabled, - RoleIcon + RoleIcon, + RoleId }; explicit NotificationSourceModel(QObject *parent = 0); diff --git a/rockwork/pebbles.cpp b/rockwork/pebbles.cpp index e45691e..65eeb6a 100644 --- a/rockwork/pebbles.cpp +++ b/rockwork/pebbles.cpp @@ -16,12 +16,22 @@ Pebbles::Pebbles(QObject *parent): QAbstractListModel(parent) { refresh(); - m_watcher = new QDBusServiceWatcher(ROCKWORK_SERVICE, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration, this); + m_watcher = new QDBusServiceWatcher(ROCKWORK_SERVICE, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); QDBusConnection::sessionBus().connect(ROCKWORK_SERVICE, ROCKWORK_MANAGER_PATH, ROCKWORK_MANAGER_INTERFACE, "PebblesChanged", this, SLOT(refresh())); connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, [this]() { + qDebug() << "service Registered!"; refresh(); QDBusConnection::sessionBus().connect(ROCKWORK_SERVICE, ROCKWORK_MANAGER_PATH, ROCKWORK_MANAGER_INTERFACE, "PebblesChanged", this, SLOT(refresh())); }); + connect(m_watcher, &QDBusServiceWatcher::serviceUnregistered, [this]() { + qDebug() << "service Unregistered!"; + beginResetModel(); + qDeleteAll(m_pebbles); + m_pebbles.clear(); + endResetModel(); + m_connectedToService = false; + emit connectedToServiceChanged(); + }); } int Pebbles::rowCount(const QModelIndex &parent) const @@ -56,6 +66,11 @@ QHash<int, QByteArray> Pebbles::roleNames() const return roles; } +bool Pebbles::connectedToService() +{ + return m_connectedToService; +} + QString Pebbles::version() const { QDBusInterface iface(ROCKWORK_SERVICE, ROCKWORK_MANAGER_PATH, ROCKWORK_MANAGER_INTERFACE); @@ -77,7 +92,10 @@ QString Pebbles::version() const Pebble *Pebbles::get(int index) const { - return m_pebbles.at(index); + if (index >= 0 && index < m_pebbles.count()) { + return m_pebbles.at(index); + } + return nullptr; } int Pebbles::find(const QString &address) const @@ -148,6 +166,11 @@ void Pebbles::refresh() endRemoveRows(); emit countChanged(); } + + if (!m_connectedToService) { + m_connectedToService = true; + emit connectedToServiceChanged(); + } } bool Pebbles::sortPebbles(Pebble *a, Pebble *b) diff --git a/rockwork/pebbles.h b/rockwork/pebbles.h index 0fef3bb..67e4440 100644 --- a/rockwork/pebbles.h +++ b/rockwork/pebbles.h @@ -12,8 +12,8 @@ class QDBusInterface; class Pebbles : public QAbstractListModel { Q_OBJECT + Q_PROPERTY(bool connectedToService READ connectedToService NOTIFY connectedToServiceChanged) Q_PROPERTY(QString version READ version) - Q_PROPERTY(int count READ rowCount NOTIFY countChanged) public: enum Roles { @@ -29,6 +29,7 @@ public: QVariant data(const QModelIndex &index, int role) const override; QHash<int, QByteArray> roleNames() const override; + bool connectedToService(); QString version() const; Q_INVOKABLE Pebble *get(int index) const; @@ -36,6 +37,7 @@ public: signals: + void connectedToServiceChanged(); void countChanged(); private slots: @@ -48,7 +50,7 @@ private: static bool sortPebbles(Pebble *a, Pebble *b); private: - QDBusInterface *m_iface; + bool m_connectedToService = false; QList<Pebble*> m_pebbles; QDBusServiceWatcher *m_watcher; }; |
