diff options
Diffstat (limited to 'libsowatch/watchserver.cpp')
-rw-r--r-- | libsowatch/watchserver.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp index da7d282..540eeea 100644 --- a/libsowatch/watchserver.cpp +++ b/libsowatch/watchserver.cpp @@ -56,6 +56,17 @@ void WatchServer::addProvider(NotificationProvider *provider) connect(provider, SIGNAL(incomingNotification(Notification*)), SLOT(postNotification(Notification*))); } +void WatchServer::addWatchlet(Watchlet *watchlet) +{ + // A watchlet is best not reparented; just look that the parent is correct + Q_ASSERT(watchlet->_server == this); + _watchlets.append(watchlet); + QString id = watchlet->id(); + if (!_watchletIds.contains(id)) { + _watchletIds[id] = watchlet; + } +} + QList<Notification*> WatchServer::liveNotifications() { QList<Notification*> notifications; @@ -67,17 +78,24 @@ QList<Notification*> WatchServer::liveNotifications() return notifications; } -void WatchServer::runWatchlet(const QString& id) +void WatchServer::runWatchlet(Watchlet *watchlet) { + Q_ASSERT(watchlet->_server == this); if (_currentWatchlet && _currentWatchletActive) { deactivateCurrentWatchlet(); } - _currentWatchlet = _watchlets[id]; + _currentWatchlet = watchlet; if (_watch->isConnected()) { reactivateCurrentWatchlet(); } } +void WatchServer::runWatchlet(const QString& id) +{ + Q_ASSERT(_watchletIds.contains(id)); + runWatchlet(_watchletIds[id]); +} + void WatchServer::closeWatchlet() { if (_currentWatchlet) { @@ -91,15 +109,6 @@ void WatchServer::closeWatchlet() } } -void WatchServer::registerWatchlet(Watchlet *watchlet) -{ - Q_ASSERT(watchlet->_server == this); - QString id = watchlet->id(); - _watchlets[id] = watchlet; - _watchletIds.append(id); -} - - void WatchServer::deactivateCurrentWatchlet() { Q_ASSERT(_currentWatchlet != 0); @@ -123,11 +132,11 @@ void WatchServer::nextWatchlet() { qDebug() << "current watchlet index" << _currentWatchletIndex; _currentWatchletIndex++; - if (_currentWatchletIndex >= _watchletIds.size() || _currentWatchletIndex < 0) { + if (_currentWatchletIndex >= _watchlets.size() || _currentWatchletIndex < 0) { _currentWatchletIndex = -1; closeWatchlet(); } else { - QString watchlet = _watchletIds.at(_currentWatchletIndex); + Watchlet* watchlet = _watchlets.at(_currentWatchletIndex); runWatchlet(watchlet); } } |