From 77a98ac21c2520d9fb4bb9c8f70967a8e36dc872 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Mon, 19 Sep 2011 01:51:04 +0200 Subject: adding notification provider plugins, idle screen --- libsowatch/watchserver.cpp | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'libsowatch/watchserver.cpp') diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp index 5ee8a90..8d00088 100644 --- a/libsowatch/watchserver.cpp +++ b/libsowatch/watchserver.cpp @@ -1,7 +1,11 @@ +#include + +#include "notificationprovider.h" #include "watch.h" #include "watchlet.h" #include "watchserver.h" + using namespace sowatch; WatchServer::WatchServer(Watch* watch, QObject* parent) : @@ -16,12 +20,22 @@ Watch* WatchServer::watch() return _watch; } +void WatchServer::addProvider(NotificationProvider *provider) +{ + provider->setParent(this); + + connect(provider, SIGNAL(notification(Notification)), SLOT(notificationEmitted(Notification))); + connect(provider, SIGNAL(unreadCountChanged(Notification::Type)), SLOT(unreadCountUpdated(Notification::Type))); + + _providers.append(provider); +} + void WatchServer::runWatchlet(const QString& id) { if (_currentWatchlet) { closeWatchlet(); } - _currentWatchlet = watchlets[id]; + _currentWatchlet = _watchlets[id]; if (_watch->isConnected()) { _currentWatchlet->activate(); } @@ -36,15 +50,10 @@ void WatchServer::closeWatchlet() _currentWatchlet = 0; } -void WatchServer::notification(const Notification &n) -{ - Q_UNUSED(n); -} - void WatchServer::registerWatchlet(Watchlet *watchlet) { Q_ASSERT(watchlet->_server == this); - watchlets[watchlet->id()] = watchlet; + _watchlets[watchlet->id()] = watchlet; } void WatchServer::watchConnected() @@ -60,3 +69,19 @@ void WatchServer::watchDisconnected() _currentWatchlet->deactivate(); } } + +void WatchServer::notificationEmitted(const Notification ¬ification) +{ + // TODO app loses button focus... + _watch->showNotification(notification); +} + +void WatchServer::unreadCountUpdated(Notification::Type type) +{ + uint count = 0; + foreach(NotificationProvider* provider, _providers) + { + count += provider->getCount(type); + } + _watch->updateNotificationCount(type, count); +} -- cgit v1.2.3