summaryrefslogtreecommitdiff
path: root/libsowatch/watchserver.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2012-08-10 00:45:24 +0200
committerJavier S. Pedro <maemo@javispedro.com>2012-08-10 00:45:24 +0200
commitd194a6112299cfe045c34e5cdb6adbbb81418d09 (patch)
tree4973f946b6701c8aea8bed73e5c4c6c978ce8e66 /libsowatch/watchserver.cpp
parentb1ccb04d7dd2fb20def829be084474ed329d4988 (diff)
downloadsowatch-d194a6112299cfe045c34e5cdb6adbbb81418d09.tar.gz
sowatch-d194a6112299cfe045c34e5cdb6adbbb81418d09.zip
new watchhandler for watchlet/prov lifecycle mgmt
Diffstat (limited to 'libsowatch/watchserver.cpp')
-rw-r--r--libsowatch/watchserver.cpp43
1 files changed, 34 insertions, 9 deletions
diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp
index d5db9da..2cadc98 100644
--- a/libsowatch/watchserver.cpp
+++ b/libsowatch/watchserver.cpp
@@ -50,21 +50,46 @@ void WatchServer::setNextWatchletButton(const QString& value)
}
}
-void WatchServer::addProvider(NotificationProvider *provider)
+void WatchServer::addWatchlet(Watchlet *watchlet)
{
- provider->setParent(this);
- connect(provider, SIGNAL(incomingNotification(Notification*)), SLOT(postNotification(Notification*)));
+ insertWatchlet(_watchlets.size(), watchlet);
}
-void WatchServer::addWatchlet(Watchlet *watchlet)
+void WatchServer::insertWatchlet(int position, Watchlet *watchlet)
+{
+ const QString id = watchlet->id();
+ Q_ASSERT(watchlet->_server == this);
+ Q_ASSERT(!_watchletIds.contains(id));
+
+ _watchlets.insert(position, watchlet);
+ _watchletIds[id] = watchlet;
+}
+
+void WatchServer::removeWatchlet(const Watchlet *watchlet)
{
- // A watchlet is best not reparented; just look that the parent is correct
+ const QString id = watchlet->id();
+
Q_ASSERT(watchlet->_server == this);
- _watchlets.append(watchlet);
- QString id = watchlet->id();
- if (!_watchletIds.contains(id)) {
- _watchletIds[id] = watchlet;
+ Q_ASSERT(_watchletIds.contains(id));
+
+ if (_currentWatchlet == watchlet) {
+ closeWatchlet();
}
+
+ _watchlets.removeAll(const_cast<Watchlet*>(watchlet));
+ _watchletIds.remove(id);
+}
+
+void WatchServer::addProvider(NotificationProvider *provider)
+{
+ connect(provider, SIGNAL(incomingNotification(Notification*)),
+ this, SLOT(postNotification(Notification*)));
+}
+
+void WatchServer::removeProvider(const NotificationProvider *provider)
+{
+ disconnect(provider, SIGNAL(incomingNotification(Notification*)),
+ this, SLOT(postNotification(Notification*)));
}
QList<Notification*> WatchServer::liveNotifications()