diff options
| author | Javier S. Pedro <maemo@javispedro.com> | 2012-08-10 00:45:24 +0200 | 
|---|---|---|
| committer | Javier S. Pedro <maemo@javispedro.com> | 2012-08-10 00:45:24 +0200 | 
| commit | d194a6112299cfe045c34e5cdb6adbbb81418d09 (patch) | |
| tree | 4973f946b6701c8aea8bed73e5c4c6c978ce8e66 /libsowatch | |
| parent | b1ccb04d7dd2fb20def829be084474ed329d4988 (diff) | |
| download | sowatch-d194a6112299cfe045c34e5cdb6adbbb81418d09.tar.gz sowatch-d194a6112299cfe045c34e5cdb6adbbb81418d09.zip | |
new watchhandler for watchlet/prov lifecycle mgmt
Diffstat (limited to 'libsowatch')
| -rw-r--r-- | libsowatch/notificationprovider.h | 2 | ||||
| -rw-r--r-- | libsowatch/watchserver.cpp | 43 | ||||
| -rw-r--r-- | libsowatch/watchserver.h | 10 | 
3 files changed, 42 insertions, 13 deletions
| diff --git a/libsowatch/notificationprovider.h b/libsowatch/notificationprovider.h index d5449f8..b18b3d6 100644 --- a/libsowatch/notificationprovider.h +++ b/libsowatch/notificationprovider.h @@ -12,7 +12,7 @@ class SOWATCH_EXPORT NotificationProvider : public QObject  {      Q_OBJECT -protected: +public:  	explicit NotificationProvider(QObject *parent = 0);  	virtual ~NotificationProvider(); 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() diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h index 54d3dc1..c1e6ef0 100644 --- a/libsowatch/watchserver.h +++ b/libsowatch/watchserver.h @@ -25,15 +25,19 @@ class SOWATCH_EXPORT WatchServer : public QObject  	Q_PROPERTY(QString nextWatchletButton READ nextWatchletButton WRITE setNextWatchletButton)  public: -	explicit WatchServer(Watch* watch, QObject* parent = 0); +	explicit WatchServer(Watch *watch, QObject *parent = 0);  	Watch* watch();  	QString nextWatchletButton() const;  	void setNextWatchletButton(const QString& value); -	void addWatchlet(Watchlet* watchlet); -	void addProvider(NotificationProvider* provider); +	void addWatchlet(Watchlet *watchlet); +	void insertWatchlet(int position, Watchlet *watchlet); +	void removeWatchlet(const Watchlet *watchlet); + +	void addProvider(NotificationProvider *provider); +	void removeProvider(const NotificationProvider *provider);  	/** Get a list of all current live notifications. */  	QList<Notification*> liveNotifications(); | 
