From 24c7c2f6f1429103d922ef940c0e17a3d4778059 Mon Sep 17 00:00:00 2001
From: "Javier S. Pedro" <maemo@javispedro.com>
Date: Sun, 5 May 2013 01:44:40 +0200
Subject: ABI change: Watchlet now depends on Watch, not WatchServer

---
 libsowatch/declarativewatchlet.cpp     | 27 ++++++++++++++++-----------
 libsowatch/declarativewatchlet.h       |  5 +++--
 libsowatch/declarativewatchwrapper.cpp |  6 ++----
 libsowatch/declarativewatchwrapper.h   |  3 +--
 libsowatch/graphicswatchlet.cpp        |  4 ++--
 libsowatch/graphicswatchlet.h          |  4 ++--
 libsowatch/watchlet.cpp                | 27 +++++++++++----------------
 libsowatch/watchlet.h                  | 22 +++++++++++-----------
 libsowatch/watchletplugininterface.h   |  4 ++--
 libsowatch/watchserver.cpp             | 24 ++++++++++++++++++++----
 libsowatch/watchserver.h               |  2 ++
 11 files changed, 72 insertions(+), 56 deletions(-)

(limited to 'libsowatch')

diff --git a/libsowatch/declarativewatchlet.cpp b/libsowatch/declarativewatchlet.cpp
index 7e3ac53..ed6ec26 100644
--- a/libsowatch/declarativewatchlet.cpp
+++ b/libsowatch/declarativewatchlet.cpp
@@ -10,8 +10,8 @@ using namespace sowatch;
 
 bool DeclarativeWatchlet::_registered = false;
 
-DeclarativeWatchlet::DeclarativeWatchlet(WatchServer* server, const QString& id) :
-	GraphicsWatchlet(server, id),
+DeclarativeWatchlet::DeclarativeWatchlet(Watch* watch, const QString& id) :
+	GraphicsWatchlet(watch, id),
 	_engine(0),
 	_component(0),
 	_item(0),
@@ -31,27 +31,26 @@ DeclarativeWatchlet::DeclarativeWatchlet(WatchServer* server, const QString& id)
 		_registered = true;
 	}
 
-	// A dynamic property on the WatchServer object is used to share a single
+	// A dynamic property on the Watch object is used to share a single
 	// DeclarativeEngine amongst all DeclarativeWatchlet instances.
-	QVariant serverEngine = server->property("declarativeEngine");
-	if (!serverEngine.isValid()) {
+	QVariant watchEngine = watch->property("declarativeEngine");
+	if (!watchEngine.isValid()) {
 		// Create the shared engine
 		qDebug() << "Starting QDeclarativeEngine";
-		_engine = new QDeclarativeEngine(server);
+		_engine = new QDeclarativeEngine(watch);
 		_engine->addImportPath(SOWATCH_QML_DIR);
 
 		// Set context properties that are shared by all watchlets here
-		_engine->rootContext()->setContextProperty("notifications",
-			const_cast<NotificationsModel*>(server->notifications()));
+		_engine->rootContext()->setContextProperty("notifications", 0);
 
-		server->setProperty("declarativeEngine", QVariant::fromValue(_engine));
+		watch->setProperty("declarativeEngine", QVariant::fromValue(_engine));
 	} else {
-		_engine = serverEngine.value<QDeclarativeEngine*>();
+		_engine = watchEngine.value<QDeclarativeEngine*>();
 	}
 
 	_context = new QDeclarativeContext(_engine, this);
 
-	_wrapper = new DeclarativeWatchWrapper(server, server->watch(), this);
+	_wrapper = new DeclarativeWatchWrapper(watch, this);
 	_context->setContextProperty("watch", _wrapper);
 }
 
@@ -125,6 +124,12 @@ void DeclarativeWatchlet::deactivate()
 	GraphicsWatchlet::deactivate();
 }
 
+void DeclarativeWatchlet::setNotificationsModel(NotificationsModel *model)
+{
+	qDebug() << Q_FUNC_INFO;
+	_context->setContextProperty("notifications", model);
+}
+
 void DeclarativeWatchlet::setRootObject(QDeclarativeItem *item)
 {
 	Q_ASSERT(_item == 0); /* This function should not be called with a current object. */
diff --git a/libsowatch/declarativewatchlet.h b/libsowatch/declarativewatchlet.h
index 28b16a8..6433880 100644
--- a/libsowatch/declarativewatchlet.h
+++ b/libsowatch/declarativewatchlet.h
@@ -17,7 +17,7 @@ class SOWATCH_EXPORT DeclarativeWatchlet : public GraphicsWatchlet
 {
     Q_OBJECT
 public:
-	DeclarativeWatchlet(WatchServer* server, const QString& id);
+	DeclarativeWatchlet(Watch* watch, const QString& id);
 	~DeclarativeWatchlet();
 
 	void setSource(const QUrl& url);
@@ -26,10 +26,11 @@ public:
 	QDeclarativeContext* rootContext();
 	QDeclarativeItem* rootObject();
 
-protected:
 	void activate();
 	void deactivate();
 
+	void setNotificationsModel(NotificationsModel *model);
+
 private:
 	void setRootObject(QDeclarativeItem* item);
 
diff --git a/libsowatch/declarativewatchwrapper.cpp b/libsowatch/declarativewatchwrapper.cpp
index d06ef3b..b5f9bc1 100644
--- a/libsowatch/declarativewatchwrapper.cpp
+++ b/libsowatch/declarativewatchwrapper.cpp
@@ -1,14 +1,12 @@
 #include <QtCore/QDebug>
-#include "watchserver.h"
 #include "watch.h"
 #include "notification.h"
 #include "declarativewatchwrapper.h"
 
 using namespace sowatch;
 
-DeclarativeWatchWrapper::DeclarativeWatchWrapper(WatchServer* server, Watch* watch, QObject* parent) :
-	QObject(parent), _server(server), _watch(watch),
-	_active(false)
+DeclarativeWatchWrapper::DeclarativeWatchWrapper(Watch* watch, QObject* parent) :
+	QObject(parent), _watch(watch), _active(false)
 {
 
 }
diff --git a/libsowatch/declarativewatchwrapper.h b/libsowatch/declarativewatchwrapper.h
index 4cc0bf4..640dc04 100644
--- a/libsowatch/declarativewatchwrapper.h
+++ b/libsowatch/declarativewatchwrapper.h
@@ -19,7 +19,7 @@ class SOWATCH_EXPORT DeclarativeWatchWrapper : public QObject
 	Q_PROPERTY(bool active READ active NOTIFY activeChanged)
 
 public:
-	explicit DeclarativeWatchWrapper(WatchServer *server, Watch *watch, QObject *parent = 0);
+	explicit DeclarativeWatchWrapper(Watch *watch, QObject *parent = 0);
 
 	QString model() const;
 	bool active() const;
@@ -34,7 +34,6 @@ signals:
 	void activeChanged();
 
 private:
-	WatchServer *_server;
 	Watch* _watch;
 	bool _active;
 
diff --git a/libsowatch/graphicswatchlet.cpp b/libsowatch/graphicswatchlet.cpp
index 08441b0..a755c29 100644
--- a/libsowatch/graphicswatchlet.cpp
+++ b/libsowatch/graphicswatchlet.cpp
@@ -7,8 +7,8 @@
 
 using namespace sowatch;
 
-GraphicsWatchlet::GraphicsWatchlet(WatchServer* server, const QString& id)
-    : Watchlet(server, id),
+GraphicsWatchlet::GraphicsWatchlet(Watch* watch, const QString& id)
+    : Watchlet(watch, id),
       _scene(0), _frameTimer(),
       _fullUpdateMode(false), _damaged()
 {
diff --git a/libsowatch/graphicswatchlet.h b/libsowatch/graphicswatchlet.h
index 24413da..808d57c 100644
--- a/libsowatch/graphicswatchlet.h
+++ b/libsowatch/graphicswatchlet.h
@@ -16,7 +16,7 @@ class SOWATCH_EXPORT GraphicsWatchlet : public Watchlet
 	Q_PROPERTY(bool fullUpdateMode READ fullUpdateMode WRITE setFullUpdateMode)
 
 public:
-	explicit GraphicsWatchlet(WatchServer* server, const QString& id);
+	explicit GraphicsWatchlet(Watch* watch, const QString& id);
 	~GraphicsWatchlet();
 
 	QGraphicsScene* scene();
@@ -28,10 +28,10 @@ public:
 	QRectF sceneRect() const;
 	QRect viewportRect() const;
 
-protected:
 	void activate();
 	void deactivate();
 
+protected:
 	static const int frameDelay = 25;
 	static const int busyFrameDelay = 50;
 
diff --git a/libsowatch/watchlet.cpp b/libsowatch/watchlet.cpp
index 555443f..dcd9103 100644
--- a/libsowatch/watchlet.cpp
+++ b/libsowatch/watchlet.cpp
@@ -1,10 +1,10 @@
 #include "watchlet.h"
-#include "watchserver.h"
+#include "watch.h"
 
 using namespace sowatch;
 
-Watchlet::Watchlet(WatchServer *server, const QString& id) :
-	QObject(server), _id(id), _active(false), _server(server)
+Watchlet::Watchlet(Watch *watch, const QString& id) :
+	QObject(watch), _id(id), _active(false), _watch(watch)
 {
 
 }
@@ -14,24 +14,14 @@ Watchlet::~Watchlet()
 
 }
 
-WatchServer* Watchlet::server()
+const Watch* Watchlet::watch() const
 {
-	return _server;
+	return _watch;
 }
 
 Watch* Watchlet::watch()
 {
-	return _server->watch();
-}
-
-const WatchServer* Watchlet::server() const
-{
-	return _server;
-}
-
-const Watch* Watchlet::watch() const
-{
-	return _server->watch();
+	return _watch;
 }
 
 QString Watchlet::id() const
@@ -57,3 +47,8 @@ void Watchlet::deactivate()
 	emit activeChanged();
 	emit deactivated();
 }
+
+void Watchlet::setNotificationsModel(NotificationsModel *model)
+{
+
+}
diff --git a/libsowatch/watchlet.h b/libsowatch/watchlet.h
index 66ec874..09d2a9c 100644
--- a/libsowatch/watchlet.h
+++ b/libsowatch/watchlet.h
@@ -9,6 +9,7 @@ namespace sowatch
 
 class Watch;
 class WatchServer;
+class NotificationsModel;
 
 class SOWATCH_EXPORT Watchlet : public QObject
 {
@@ -17,34 +18,33 @@ class SOWATCH_EXPORT Watchlet : public QObject
 	Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
 
 public:
-	Watchlet(WatchServer *server, const QString& id);
+	Watchlet(Watch *watch, const QString& id);
 	~Watchlet();
 
-	WatchServer* server();
-	Watch* watch();
-
-	const WatchServer* server() const;
 	const Watch* watch() const;
+	Watch* watch();
 
 	QString id() const;
 	bool isActive() const;
 
+	// To be called by the WatchServer
+	virtual void activate();
+	virtual void deactivate();
+
+	// Some properties
+	virtual void setNotificationsModel(NotificationsModel *model);
+
 signals:
 	void activeChanged();
 	void activated();
 	void deactivated();
 
 protected:
-	virtual void activate();
-	virtual void deactivate();
-
 	const QString _id;
 	bool _active;
 
 private:
-	WatchServer* _server;
-
-friend class WatchServer;
+	Watch* _watch;
 };
 
 }
diff --git a/libsowatch/watchletplugininterface.h b/libsowatch/watchletplugininterface.h
index cccf86f..5e99605 100644
--- a/libsowatch/watchletplugininterface.h
+++ b/libsowatch/watchletplugininterface.h
@@ -12,7 +12,7 @@ namespace sowatch
 
 class ConfigKey;
 class Watchlet;
-class WatchServer;
+class Watch;
 
 class SOWATCH_EXPORT WatchletPluginInterface
 {
@@ -27,7 +27,7 @@ public:
 
 	virtual QStringList watchlets() = 0;
 	virtual WatchletInfo describeWatchlet(const QString& id) = 0;
-	virtual Watchlet* getWatchlet(const QString& id, ConfigKey *settings, WatchServer *server) = 0;
+	virtual Watchlet* getWatchlet(const QString& id, ConfigKey *settings, Watch *watch) = 0;
 };
 
 }
diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp
index 3d9db24..d3328df 100644
--- a/libsowatch/watchserver.cpp
+++ b/libsowatch/watchserver.cpp
@@ -65,11 +65,13 @@ void WatchServer::addWatchlet(Watchlet *watchlet)
 void WatchServer::insertWatchlet(int position, Watchlet *watchlet)
 {
 	Q_ASSERT(watchlet);
-	Q_ASSERT(watchlet->_server == this);
+	Q_ASSERT(watchlet->watch() == _watch);
 
 	const QString id = watchlet->id();
 	Q_ASSERT(!_watchletIds.contains(id));
 
+	setWatchletProperties(watchlet);
+
 	_watchlets.insert(position, watchlet);
 	_watchletIds[id] = watchlet;
 }
@@ -79,7 +81,7 @@ void WatchServer::moveWatchlet(const Watchlet *watchlet, int to)
 	const QString id = watchlet->id();
 	int index = _watchlets.indexOf(const_cast<Watchlet*>(watchlet));
 
-	Q_ASSERT(watchlet->_server == this);
+	Q_ASSERT(watchlet->watch() == _watch);
 	Q_ASSERT(_watchletIds.contains(id));
 	Q_ASSERT(index >= 0);
 
@@ -90,13 +92,15 @@ void WatchServer::removeWatchlet(const Watchlet *watchlet)
 {
 	const QString id = watchlet->id();
 
-	Q_ASSERT(watchlet->_server == this);
+	Q_ASSERT(watchlet->watch() == _watch);
 	Q_ASSERT(_watchletIds.contains(id));
 
 	if (_currentWatchlet == watchlet) {
 		closeWatchlet();
 	}
 
+	unsetWatchletProperties(const_cast<Watchlet*>(watchlet));
+
 	_watchlets.removeAll(const_cast<Watchlet*>(watchlet));
 	_watchletIds.remove(id);
 }
@@ -177,7 +181,7 @@ void WatchServer::nextNotification()
 
 void WatchServer::runWatchlet(Watchlet *watchlet)
 {
-	Q_ASSERT(watchlet->_server == this);
+	Q_ASSERT(watchlet->watch() == _watch);
 	if (_currentWatchlet && _currentWatchletActive) {
 		deactivateCurrentWatchlet();
 	}
@@ -278,6 +282,18 @@ void WatchServer::removeNotification(Notification::Type type, Notification *n)
 	disconnect(n, 0, this, 0);
 }
 
+void WatchServer::setWatchletProperties(Watchlet *watchlet)
+{
+	Q_ASSERT(watchlet->watch() == _watch);
+	watchlet->setNotificationsModel(_notifications);
+}
+
+void WatchServer::unsetWatchletProperties(Watchlet *watchlet)
+{
+	Q_ASSERT(watchlet->watch() == _watch);
+	watchlet->setNotificationsModel(0);
+}
+
 void WatchServer::goToIdle()
 {
 	Q_ASSERT(!_currentWatchletActive);
diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h
index 67fcb81..fb1b4e7 100644
--- a/libsowatch/watchserver.h
+++ b/libsowatch/watchserver.h
@@ -96,6 +96,8 @@ private:
 	/** Remove a notification of a certain type. */
 	void removeNotification(Notification::Type type, Notification* n);
 
+	void setWatchletProperties(Watchlet *watchlet);
+	void unsetWatchletProperties(Watchlet *watchlet);
 	void deactivateCurrentWatchlet();
 	void reactivateCurrentWatchlet();
 	void goToIdle();
-- 
cgit v1.2.3