From 3ca9235ddb93b52730099164a0dc387f7a301280 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 12 May 2013 03:49:38 +0200 Subject: weather rendering in metawatchwatchlets --- libsowatch/declarativewatchlet.cpp | 13 +++++++++++++ libsowatch/declarativewatchlet.h | 1 + libsowatch/notificationsmodel.cpp | 5 +++-- libsowatch/notificationsmodel.h | 2 +- libsowatch/watchserver.cpp | 7 ++++--- 5 files changed, 22 insertions(+), 6 deletions(-) (limited to 'libsowatch') diff --git a/libsowatch/declarativewatchlet.cpp b/libsowatch/declarativewatchlet.cpp index c223b8d..4683dcb 100644 --- a/libsowatch/declarativewatchlet.cpp +++ b/libsowatch/declarativewatchlet.cpp @@ -2,6 +2,7 @@ #include #include "watchserver.h" #include "watch.h" +#include "watchletsmodel.h" #include "notificationsmodel.h" #include "gconfkey.h" #include "declarativewatchwrapper.h" @@ -24,9 +25,15 @@ DeclarativeWatchlet::DeclarativeWatchlet(Watch* watch, const QString& id) : if (!_registered) { qRegisterMetaType("Notification::Type"); + qRegisterMetaType("Notification::Priority"); qRegisterMetaType("WeatherNotification::WeatherType"); + qRegisterMetaType("WeatherNotification::Unit"); qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, "Watch", "Watch is only available via the 'watch' context property"); + qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, + "Notification", "WatchletsModel is only available via the 'notifications' context property"); + qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, + "Notification", "Watchlet is an abstract class"); qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, "NotificationsModel", "NotificationsModel is only available via the 'notifications' context property"); qmlRegisterUncreatableType("com.javispedro.sowatch", 1, 0, @@ -48,6 +55,7 @@ DeclarativeWatchlet::DeclarativeWatchlet(Watch* watch, const QString& id) : _engine->addImportPath(SOWATCH_QML_DIR); // Set context properties that are shared by all watchlets here + _engine->rootContext()->setContextProperty("watchlets", 0); _engine->rootContext()->setContextProperty("notifications", 0); watch->setProperty("declarativeEngine", QVariant::fromValue(_engine)); @@ -126,6 +134,11 @@ void DeclarativeWatchlet::deactivate() GraphicsWatchlet::deactivate(); } +void DeclarativeWatchlet::setWatchletsModel(WatchletsModel *model) +{ + _context->setContextProperty("watchlets", model); +} + void DeclarativeWatchlet::setNotificationsModel(NotificationsModel *model) { _context->setContextProperty("notifications", model); diff --git a/libsowatch/declarativewatchlet.h b/libsowatch/declarativewatchlet.h index dc0fb4a..93e9a8e 100644 --- a/libsowatch/declarativewatchlet.h +++ b/libsowatch/declarativewatchlet.h @@ -28,6 +28,7 @@ public: void activate(); void deactivate(); + void setWatchletsModel(WatchletsModel *model); void setNotificationsModel(NotificationsModel *model); bool handlesNotification(Notification *notification) const; diff --git a/libsowatch/notificationsmodel.cpp b/libsowatch/notificationsmodel.cpp index ce0a2fb..86adabc 100644 --- a/libsowatch/notificationsmodel.cpp +++ b/libsowatch/notificationsmodel.cpp @@ -112,6 +112,7 @@ int NotificationsModel::fullCountByType(int type) const Notification* NotificationsModel::getMostRecentByType(Notification::Type type) const { if (!_list[type].empty()) { + qDebug() << "Returning most recent" << _list[type].first(); // TODO Actually get the most recent (sort by date) return _list[type].first(); } else { @@ -119,10 +120,10 @@ Notification* NotificationsModel::getMostRecentByType(Notification::Type type) c } } -Notification* NotificationsModel::getMostRecentByType(int type) const +QObject* NotificationsModel::getMostRecentByType(int type) const { Q_ASSERT(type >= 0 && type < Notification::TypeCount); - return getMostRecentByType(static_cast(type)); + return static_cast(getMostRecentByType(static_cast(type))); } Notification::Type NotificationsModel::getTypeOfDeletedNotification(Notification *n) const diff --git a/libsowatch/notificationsmodel.h b/libsowatch/notificationsmodel.h index d88693f..ffd8ab7 100644 --- a/libsowatch/notificationsmodel.h +++ b/libsowatch/notificationsmodel.h @@ -33,7 +33,7 @@ public: Q_INVOKABLE int fullCountByType(int type) const; // See QTBUG-26415 Q_INVOKABLE Notification* getMostRecentByType(Notification::Type type) const; - Q_INVOKABLE Notification* getMostRecentByType(int type) const; + Q_INVOKABLE QObject* getMostRecentByType(int type) const; // QML version Notification::Type getTypeOfDeletedNotification(Notification *n) const; diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp index 06a8189..eaea040 100644 --- a/libsowatch/watchserver.cpp +++ b/libsowatch/watchserver.cpp @@ -187,11 +187,12 @@ void WatchServer::postNotification(Notification *notification) void WatchServer::nextNotification() { if (!_watch->isConnected()) return; + if (_activeWatchlet) { + // Deactive active watchlet, if any. + deactivateActiveWatchlet(); + } if (!_pendingNotifications.empty()) { Notification *n = _pendingNotifications.head(); - if (_activeWatchlet) { - deactivateActiveWatchlet(); - } _watch->displayNotification(n); if (_notificationWatchlet) { activateWatchlet(_notificationWatchlet); -- cgit v1.2.3