summaryrefslogtreecommitdiff
path: root/libsowatch
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2013-05-07 01:37:21 +0200
committerJavier S. Pedro <maemo@javispedro.com>2013-05-07 01:37:21 +0200
commit6003bf81107dd9be51589c074b74c5af82bfc8ab (patch)
tree502193634979c12b45c2a013668d21556e2c7050 /libsowatch
parentae37832316d905889c82706b351b3c037c9e1ab6 (diff)
downloadsowatch-6003bf81107dd9be51589c074b74c5af82bfc8ab.tar.gz
sowatch-6003bf81107dd9be51589c074b74c5af82bfc8ab.zip
testing qml notifications
Diffstat (limited to 'libsowatch')
-rw-r--r--libsowatch/declarativewatchlet.cpp31
-rw-r--r--libsowatch/declarativewatchlet.h3
-rw-r--r--libsowatch/notificationsmodel.cpp4
-rw-r--r--libsowatch/watchlet.cpp12
-rw-r--r--libsowatch/watchlet.h4
-rw-r--r--libsowatch/watchserver.cpp9
6 files changed, 61 insertions, 2 deletions
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>("Notification::Type");
+ qRegisterMetaType<WeatherNotification::WeatherType>("WeatherNotification::WeatherType");
qmlRegisterUncreatableType<DeclarativeWatchWrapper>("com.javispedro.sowatch", 1, 0,
"Watch", "Watch is only available via the 'watch' context property");
qmlRegisterUncreatableType<NotificationsModel>("com.javispedro.sowatch", 1, 0,
"NotificationsModel", "NotificationsModel is only available via the 'notifications' context property");
qmlRegisterUncreatableType<Notification>("com.javispedro.sowatch", 1, 0,
"Notification", "Notification is an abstract class");
+ qmlRegisterUncreatableType<WeatherNotification>("com.javispedro.sowatch", 1, 0,
+ "WeatherNotification", "WeatherNotification is an abstract class");
qmlRegisterType<ConfigKey>();
qmlRegisterType<GConfKey>("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);