From 6003bf81107dd9be51589c074b74c5af82bfc8ab Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Tue, 7 May 2013 01:37:21 +0200 Subject: testing qml notifications --- libsowatch/declarativewatchlet.cpp | 31 ++++++++ libsowatch/declarativewatchlet.h | 3 + libsowatch/notificationsmodel.cpp | 4 +- libsowatch/watchlet.cpp | 12 +++ libsowatch/watchlet.h | 4 + libsowatch/watchserver.cpp | 9 ++- metawatch/metawatch.cpp | 3 +- metawatch/metawatchdigital.cpp | 13 +--- metawatch/metawatchscanner.cpp | 2 +- .../com/javispedro/sowatch/metawatch/MWTitle.qml | 12 +++ metawatch/res/graphics/idle_call.bmp | Bin 134 -> 0 bytes metawatch/res/graphics/idle_mail.bmp | Bin 134 -> 0 bytes metawatch/res/graphics/idle_msg.bmp | Bin 134 -> 0 bytes .../metawatch-digital-notification.qml | 81 +++++++++++++++++++++ metawatchwatchlets/metawatch-digital-watchface.qml | 20 +---- .../metawatchnotificationwatchlet.cpp | 11 +++ metawatchwatchlets/metawatchnotificationwatchlet.h | 20 +++++ metawatchwatchlets/metawatchwatchlets.pro | 8 +- metawatchwatchlets/metawatchwatchletsplugin.cpp | 8 +- 19 files changed, 204 insertions(+), 37 deletions(-) delete mode 100644 metawatch/res/graphics/idle_call.bmp delete mode 100644 metawatch/res/graphics/idle_mail.bmp delete mode 100644 metawatch/res/graphics/idle_msg.bmp create mode 100644 metawatchwatchlets/metawatch-digital-notification.qml create mode 100644 metawatchwatchlets/metawatchnotificationwatchlet.cpp create mode 100644 metawatchwatchlets/metawatchnotificationwatchlet.h diff --git a/libsowatch/declarativewatchlet.cpp b/libsowatch/declarativewatchlet.cpp index bc979b0..6508ce5 100644 --- a/libsowatch/declarativewatchlet.cpp +++ b/libsowatch/declarativewatchlet.cpp @@ -23,12 +23,15 @@ DeclarativeWatchlet::DeclarativeWatchlet(Watch* watch, const QString& id) : if (!_registered) { qRegisterMetaType("Notification::Type"); + qRegisterMetaType("WeatherNotification::WeatherType"); qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, "Watch", "Watch is only available via the 'watch' context property"); qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, "NotificationsModel", "NotificationsModel is only available via the 'notifications' context property"); qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, "Notification", "Notification is an abstract class"); + qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, + "WeatherNotification", "WeatherNotification is an abstract class"); qmlRegisterType(); qmlRegisterType("com.javispedro.sowatch", 1, 0, "GConfKey"); _registered = true; @@ -139,6 +142,34 @@ void DeclarativeWatchlet::setRootObject(QDeclarativeItem *item) scene()->addItem(_item); } +bool DeclarativeWatchlet::handlesNotification(Notification *notification) const +{ + if (_item) { + QVariant arg = QVariant::fromValue(notification); + QVariant result; + if (QMetaObject::invokeMethod(_item, "handlesNotification", + Q_RETURN_ARG(QVariant, result), + Q_ARG(QVariant, arg))) { + return result.toBool(); + } + } + + return false; +} + +void DeclarativeWatchlet::openNotification(Notification *notification) +{ + if (_item) { + QVariant arg = QVariant::fromValue(notification); + QVariant result; + if (!QMetaObject::invokeMethod(_item, "openNotification", + Q_RETURN_ARG(QVariant, result), + Q_ARG(QVariant, arg))) { + qWarning() << "No openNotification method in QML root object"; + } + } +} + void DeclarativeWatchlet::handleComponentStatus(QDeclarativeComponent::Status status) { QObject *obj; diff --git a/libsowatch/declarativewatchlet.h b/libsowatch/declarativewatchlet.h index cf2fd39..dc0fb4a 100644 --- a/libsowatch/declarativewatchlet.h +++ b/libsowatch/declarativewatchlet.h @@ -30,6 +30,9 @@ public: void setNotificationsModel(NotificationsModel *model); + bool handlesNotification(Notification *notification) const; + void openNotification(Notification *notification); + private: void setRootObject(QDeclarativeItem* item); diff --git a/libsowatch/notificationsmodel.cpp b/libsowatch/notificationsmodel.cpp index 259ac93..ce0a2fb 100644 --- a/libsowatch/notificationsmodel.cpp +++ b/libsowatch/notificationsmodel.cpp @@ -96,7 +96,9 @@ int NotificationsModel::fullCountByType(Notification::Type type) const { int count = 0; Q_FOREACH(const Notification *n, _list[type]) { - count += n->count(); + if (n->priority() != Notification::Silent) { + count += n->count(); + } } return count; } diff --git a/libsowatch/watchlet.cpp b/libsowatch/watchlet.cpp index dcd9103..03ede41 100644 --- a/libsowatch/watchlet.cpp +++ b/libsowatch/watchlet.cpp @@ -50,5 +50,17 @@ void Watchlet::deactivate() void Watchlet::setNotificationsModel(NotificationsModel *model) { + Q_UNUSED(model); +} +bool Watchlet::handlesNotification(Notification *notification) const +{ + Q_UNUSED(notification); + return false; +} + +void Watchlet::openNotification(Notification *notification) +{ + Q_UNUSED(notification); + qDebug() << "Watchlet" << _id << "does not override openNotification()"; } diff --git a/libsowatch/watchlet.h b/libsowatch/watchlet.h index 09d2a9c..f32d495 100644 --- a/libsowatch/watchlet.h +++ b/libsowatch/watchlet.h @@ -9,6 +9,7 @@ namespace sowatch class Watch; class WatchServer; +class Notification; class NotificationsModel; class SOWATCH_EXPORT Watchlet : public QObject @@ -34,6 +35,9 @@ public: // Some properties virtual void setNotificationsModel(NotificationsModel *model); + virtual bool handlesNotification(Notification* notification) const; + virtual void openNotification(Notification* notification); + signals: void activeChanged(); void activated(); diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp index 0b7b60f..f79b1c1 100644 --- a/libsowatch/watchserver.cpp +++ b/libsowatch/watchserver.cpp @@ -205,6 +205,10 @@ void WatchServer::nextNotification() deactivateActiveWatchlet(); } _watch->displayNotification(n); + if (_notificationWatchlet) { + activateWatchlet(_notificationWatchlet); + _notificationWatchlet->openNotification(n); + } } else if (_currentWatchlet) { activateCurrentWatchlet(); } else { @@ -335,7 +339,10 @@ void WatchServer::removeNotification(Notification::Type type, Notification *n) void WatchServer::goToIdle() { - Q_ASSERT(!_currentWatchlet && !_activeWatchlet); + Q_ASSERT(!_currentWatchlet); + if (_activeWatchlet) { + deactivateActiveWatchlet(); + } _watch->displayIdleScreen(); if (_idleWatchlet) { activateWatchlet(_idleWatchlet); diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp index 01dec25..782e47f 100644 --- a/metawatch/metawatch.cpp +++ b/metawatch/metawatch.cpp @@ -125,7 +125,8 @@ MetaWatch::MetaWatch(ConfigKey* settings, QObject* parent) : connect(_localDev, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)), SLOT(localDevModeChanged(QBluetoothLocalDevice::HostMode))); // Check to see if we can connect right away - if (_localDev->hostMode() != QBluetoothLocalDevice::HostPoweredOff) { + if (_localDev->isValid() && + _localDev->hostMode() != QBluetoothLocalDevice::HostPoweredOff) { // Do an initial connection attempt after a short delay // (To give time for other plugins to initialize, etc.) scheduleConnect(); diff --git a/metawatch/metawatchdigital.cpp b/metawatch/metawatchdigital.cpp index de55db6..e099f76 100644 --- a/metawatch/metawatchdigital.cpp +++ b/metawatch/metawatchdigital.cpp @@ -48,7 +48,7 @@ QString MetaWatchDigital::model() const void MetaWatchDigital::displayIdleScreen() { - qDebug() << "displaying idle screen"; + qDebug() << "entering idle screen"; MetaWatch::displayIdleScreen(); // Usually, idle screen is kept updated, so we can flip it right away. @@ -57,22 +57,13 @@ void MetaWatchDigital::displayIdleScreen() void MetaWatchDigital::displayNotification(Notification *n) { - qDebug() << "display notification" << n->title() << n->body(); - - // Render the notification and display it before invoking haptic feedback - _currentMode = NotificationMode; - changeMode(_currentMode); - - renderNotification(n); - - // This will trigger haptic feedback, etc. + qDebug() << "entering notification mode"; MetaWatch::displayNotification(n); } void MetaWatchDigital::displayApplication() { qDebug() << "entering application mode"; - MetaWatch::displayApplication(); } diff --git a/metawatch/metawatchscanner.cpp b/metawatch/metawatchscanner.cpp index 0c1d88e..e560195 100644 --- a/metawatch/metawatchscanner.cpp +++ b/metawatch/metawatchscanner.cpp @@ -45,7 +45,7 @@ void MetaWatchScanner::handleDiscoveredService(const QBluetoothServiceInfo &info foundInfo["driver"] = QString("metawatch-digital"); foundInfo["next-watchlet-button"] = QString("A"); foundInfo["idle-watchlet"] = QString("com.javispedro.sowatch.metawatch.watchface"); - foundInfo["notification-watchlet"] = QString("com.javispedro.sowatch.metawatch.notificationwatchlet"); + foundInfo["notification-watchlet"] = QString("com.javispedro.sowatch.metawatch.notification"); emit watchFound(foundInfo); } } diff --git a/metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml b/metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml index b5ad787..d6d4c42 100644 --- a/metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml +++ b/metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml @@ -26,6 +26,17 @@ Rectangle { visible: text != "" } + MWLabel { + id: status + anchors.top: parent.top + anchors.left: parent.left + anchors.leftMargin: 1 + height: 8 + font.family: "MetaWatch Large caps 8pt" + font.pixelSize: 8 + text: "" + } + MWLabel { id: time anchors.right: parent.right @@ -40,6 +51,7 @@ Rectangle { function updateStatusBar() { var now = new Date time.text = Qt.formatDate(now, "ddd") + " " + Qt.formatTime(now) + status.text = notifications.fullCount() > 0 ? "*" : "" } Timer { diff --git a/metawatch/res/graphics/idle_call.bmp b/metawatch/res/graphics/idle_call.bmp deleted file mode 100644 index 2b69eea..0000000 Binary files a/metawatch/res/graphics/idle_call.bmp and /dev/null differ diff --git a/metawatch/res/graphics/idle_mail.bmp b/metawatch/res/graphics/idle_mail.bmp deleted file mode 100644 index 253b5bf..0000000 Binary files a/metawatch/res/graphics/idle_mail.bmp and /dev/null differ diff --git a/metawatch/res/graphics/idle_msg.bmp b/metawatch/res/graphics/idle_msg.bmp deleted file mode 100644 index 0035d4b..0000000 Binary files a/metawatch/res/graphics/idle_msg.bmp and /dev/null differ diff --git a/metawatchwatchlets/metawatch-digital-notification.qml b/metawatchwatchlets/metawatch-digital-notification.qml new file mode 100644 index 0000000..72f7bc9 --- /dev/null +++ b/metawatchwatchlets/metawatch-digital-notification.qml @@ -0,0 +1,81 @@ +import QtQuick 1.0 +import com.javispedro.sowatch 1.0 +import com.javispedro.sowatch.metawatch 1.0 + +MWPage { + id: page + + property QtObject curNotification: null; + + MWTitle { + id: title + } + + Item { + id: container + anchors.top: title.bottom + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + + Item { + id: emailContainer + visible: curNotification.type === Notification.EmailNotification + anchors.fill: parent + + MWLabel { + anchors.centerIn: parent + text: "Email" + } + } + + Item { + id: chatContainer + visible: curNotification.type === Notification.ImNotification + anchors.fill: parent + + MWLabel { + id: chatTitle + text: curNotification.title + } + + Image { + x: 20 + y: chatBubble.y - 8 + source: "bubble_tip.png" + z: 1 + } + + BorderImage { + id: chatBubble + anchors { + top: chatTitle.bottom; left: parent.left; right: parent.right; + leftMargin: 2; topMargin: 8; rightMargin: 2; bottomMargin: 2; + } + border { left: 16; top: 16; right: 16; bottom: 16; } + height: childrenRect.height + 16 + source: "bubble.png" + + MWLabel { + anchors { + top: parent.top; left: parent.left; right: parent.right; + margins: 16 / 2 + } + text: curNotification.body + width: parent.width + wrapMode: Text.Wrap + } + } + } + } + + + + function handlesNotification(notification) { + return false; + } + + function openNotification(notification) { + curNotification = notification; + } +} diff --git a/metawatchwatchlets/metawatch-digital-watchface.qml b/metawatchwatchlets/metawatch-digital-watchface.qml index 23236a6..a030bdb 100644 --- a/metawatchwatchlets/metawatch-digital-watchface.qml +++ b/metawatchwatchlets/metawatch-digital-watchface.qml @@ -5,13 +5,6 @@ import com.javispedro.sowatch.metawatch 1.0 MWPage { id: page - Connections { - target: watch - onActiveChanged: { - console.log("watchface is now " + (watch.active ? "active" : "inactive")) - } - } - Column { Item { id: systemArea @@ -30,6 +23,7 @@ MWPage { Item { width: page.width height: 30 + // TODO Weather stuff. } Image { @@ -107,7 +101,7 @@ MWPage { function updateWeather() { var weather = notifications.getMostRecentByType(Notification.WeatherNotification); if (typeof weather !== "undefined") { - // TODO + // TODO Weather stuff } } @@ -116,16 +110,6 @@ MWPage { updateWeather(); } - Connections { - target: watch - onActiveChanged: { - if (watch.active) { - console.log("watchface active"); - //updateUnreadCounts(); - } - } - } - Connections { target: notifications onModelChanged: update(); diff --git a/metawatchwatchlets/metawatchnotificationwatchlet.cpp b/metawatchwatchlets/metawatchnotificationwatchlet.cpp new file mode 100644 index 0000000..ef9c3d5 --- /dev/null +++ b/metawatchwatchlets/metawatchnotificationwatchlet.cpp @@ -0,0 +1,11 @@ +#include "metawatchnotificationwatchlet.h" + +using namespace sowatch; + +const QLatin1String MetaWatchNotificationWatchlet::myId("com.javispedro.sowatch.metawatch.notification"); + +MetaWatchNotificationWatchlet::MetaWatchNotificationWatchlet(Watch *watch) : + DeclarativeWatchlet(watch, myId) +{ + setSource(QUrl(SOWATCH_QML_DIR "/metawatchwatchlets/" + watch->model() + "-notification.qml")); +} diff --git a/metawatchwatchlets/metawatchnotificationwatchlet.h b/metawatchwatchlets/metawatchnotificationwatchlet.h new file mode 100644 index 0000000..3290b0c --- /dev/null +++ b/metawatchwatchlets/metawatchnotificationwatchlet.h @@ -0,0 +1,20 @@ +#ifndef METAWATCHNOTIFICATIONWATCHLET_H +#define METAWATCHNOTIFICATIONWATCHLET_H + +#include + +namespace sowatch +{ + +class MetaWatchNotificationWatchlet : public DeclarativeWatchlet +{ + Q_OBJECT +public: + explicit MetaWatchNotificationWatchlet(Watch* watch); + + static const QLatin1String myId; +}; + +} + +#endif // METAWATCHNOTIFICATIONWATCHLET_H diff --git a/metawatchwatchlets/metawatchwatchlets.pro b/metawatchwatchlets/metawatchwatchlets.pro index f4393e4..af6dcdb 100644 --- a/metawatchwatchlets/metawatchwatchlets.pro +++ b/metawatchwatchlets/metawatchwatchlets.pro @@ -2,11 +2,13 @@ TARGET = metawatchwatchlets TEMPLATE = lib CONFIG += plugin -SOURCES += metawatchwatchletsplugin.cpp metawatchfacewatchlet.cpp +SOURCES += metawatchwatchletsplugin.cpp \ + metawatchfacewatchlet.cpp metawatchnotificationwatchlet.cpp -HEADERS += metawatchwatchletsplugin.h metawatchfacewatchlet.h +HEADERS += metawatchwatchletsplugin.h \ + metawatchfacewatchlet.h metawatchnotificationwatchlet.h -qml_files.files = metawatch-digital-watchface.qml +qml_files.files = metawatch-digital-watchface.qml metawatch-digital-notification.qml LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch INCLUDEPATH += $$PWD/../libsowatch diff --git a/metawatchwatchlets/metawatchwatchletsplugin.cpp b/metawatchwatchlets/metawatchwatchletsplugin.cpp index 31b66ab..98c1713 100644 --- a/metawatchwatchlets/metawatchwatchletsplugin.cpp +++ b/metawatchwatchlets/metawatchwatchletsplugin.cpp @@ -1,4 +1,5 @@ #include "metawatchfacewatchlet.h" +#include "metawatchnotificationwatchlet.h" #include "metawatchwatchletsplugin.h" using namespace sowatch; @@ -15,7 +16,7 @@ MetaWatchWatchletsPlugin::~MetaWatchWatchletsPlugin() QStringList MetaWatchWatchletsPlugin::watchlets() { QStringList l; - l << MetaWatchFaceWatchlet::myId; + l << MetaWatchFaceWatchlet::myId << MetaWatchNotificationWatchlet::myId; return l; } @@ -25,6 +26,9 @@ WatchletPluginInterface::WatchletInfo MetaWatchWatchletsPlugin::describeWatchlet if (id == MetaWatchFaceWatchlet::myId) { info.name = "MetaWatch Face Watchlet"; info.hidden = true; + } else if (id == MetaWatchNotificationWatchlet::myId) { + info.name = "MetaWatch Notification Watchlet"; + info.hidden = true; } return info; } @@ -34,6 +38,8 @@ Watchlet* MetaWatchWatchletsPlugin::getWatchlet(const QString& id, ConfigKey *se Q_UNUSED(settings); if (id == MetaWatchFaceWatchlet::myId) { return new MetaWatchFaceWatchlet(watch); + } else if (id == MetaWatchNotificationWatchlet::myId) { + return new MetaWatchNotificationWatchlet(watch); } } -- cgit v1.2.3