summaryrefslogtreecommitdiff
path: root/libsowatch
diff options
context:
space:
mode:
Diffstat (limited to 'libsowatch')
-rw-r--r--libsowatch/declarativewatchlet.cpp13
-rw-r--r--libsowatch/declarativewatchlet.h1
-rw-r--r--libsowatch/notificationsmodel.cpp5
-rw-r--r--libsowatch/notificationsmodel.h2
-rw-r--r--libsowatch/watchserver.cpp7
5 files changed, 22 insertions, 6 deletions
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 <QtDeclarative/QtDeclarative>
#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>("Notification::Type");
+ qRegisterMetaType<Notification::Priority>("Notification::Priority");
qRegisterMetaType<WeatherNotification::WeatherType>("WeatherNotification::WeatherType");
+ qRegisterMetaType<WeatherNotification::Unit>("WeatherNotification::Unit");
qmlRegisterUncreatableType<DeclarativeWatchWrapper>("com.javispedro.sowatch", 1, 0,
"Watch", "Watch is only available via the 'watch' context property");
+ qmlRegisterUncreatableType<WatchletsModel>("com.javispedro.sowatch", 1, 0,
+ "Notification", "WatchletsModel is only available via the 'notifications' context property");
+ qmlRegisterUncreatableType<Watchlet>("com.javispedro.sowatch", 1, 0,
+ "Notification", "Watchlet is an abstract class");
qmlRegisterUncreatableType<NotificationsModel>("com.javispedro.sowatch", 1, 0,
"NotificationsModel", "NotificationsModel is only available via the 'notifications' context property");
qmlRegisterUncreatableType<Notification>("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<Notification::Type>(type));
+ return static_cast<QObject*>(getMostRecentByType(static_cast<Notification::Type>(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);