From 24c7c2f6f1429103d922ef940c0e17a3d4778059 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" 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 ++ metawatch/metawatch.pro | 9 ++++++-- metawatch/metawatchdigital.cpp | 2 +- metawatch/metawatchdigitalfacewatchlet.cpp | 8 +++++++ metawatch/metawatchdigitalfacewatchlet.h | 18 +++++++++++++++ metawatch/qml/metawatch-digital-watchface.qml | 7 ++++++ notificationswatchlet/notificationswatchlet.cpp | 6 ++--- notificationswatchlet/notificationswatchlet.h | 2 +- .../notificationswatchletplugin.cpp | 4 ++-- .../notificationswatchletplugin.h | 2 +- sowatchd/watchhandler.cpp | 2 +- 21 files changed, 121 insertions(+), 67 deletions(-) create mode 100644 metawatch/metawatchdigitalfacewatchlet.cpp create mode 100644 metawatch/metawatchdigitalfacewatchlet.h create mode 100644 metawatch/qml/metawatch-digital-watchface.qml 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(server->notifications())); + _engine->rootContext()->setContextProperty("notifications", 0); - server->setProperty("declarativeEngine", QVariant::fromValue(_engine)); + watch->setProperty("declarativeEngine", QVariant::fromValue(_engine)); } else { - _engine = serverEngine.value(); + _engine = watchEngine.value(); } _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 -#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)); - 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)); + _watchlets.removeAll(const_cast(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(); diff --git a/metawatch/metawatch.pro b/metawatch/metawatch.pro index 536ccee..1437b71 100644 --- a/metawatch/metawatch.pro +++ b/metawatch/metawatch.pro @@ -18,7 +18,8 @@ SOURCES += metawatchplugin.cpp \ metawatchanalog.cpp \ metawatchscanner.cpp \ metawatchdigitalsimulator.cpp \ - metawatchdigitalsimulatorform.cpp + metawatchdigitalsimulatorform.cpp \ + metawatchdigitalfacewatchlet.cpp HEADERS += metawatchplugin.h \ metawatchpaintengine.h \ @@ -27,7 +28,8 @@ HEADERS += metawatchplugin.h \ metawatchanalog.h \ metawatchscanner.h \ metawatchdigitalsimulator.h \ - metawatchdigitalsimulatorform.h + metawatchdigitalsimulatorform.h \ + metawatchdigitalfacewatchlet.h FORMS += \ metawatchdigitalsimulatorform.ui @@ -51,3 +53,6 @@ DEPENDPATH += $$PWD/../libsowatch qml_files.path = /usr/share/sowatch/qml } INSTALLS += target res_files qml_files + +OTHER_FILES += \ + qml/metawatch-digital-watchface.qml diff --git a/metawatch/metawatchdigital.cpp b/metawatch/metawatchdigital.cpp index 147fd79..9145336 100644 --- a/metawatch/metawatchdigital.cpp +++ b/metawatch/metawatchdigital.cpp @@ -339,7 +339,7 @@ void MetaWatchDigital::handleWatchConnected() // Grab all of the buttons that are of interest to us // We do not grab the F button, as it triggers the LED. grabButton(IdleMode, BtnA); // Required for app-switch - // TODO: Grabbing these buttons seems to break everything + // TODO: Grabbing these buttons seems to break everything since gen2 firmware. //grabButton(IdleMode, BtnB); // What does this do? //grabButton(IdleMode, BtnE); // Music mode is currently not supported grabButton(ApplicationMode, BtnA); diff --git a/metawatch/metawatchdigitalfacewatchlet.cpp b/metawatch/metawatchdigitalfacewatchlet.cpp new file mode 100644 index 0000000..08d8ac4 --- /dev/null +++ b/metawatch/metawatchdigitalfacewatchlet.cpp @@ -0,0 +1,8 @@ +#include "metawatchdigitalfacewatchlet.h" + +using namespace sowatch; + +MetaWatchDigitalFaceWatchlet::MetaWatchDigitalFaceWatchlet(Watch *watch) : + DeclarativeWatchlet(watch, "crap") +{ +} diff --git a/metawatch/metawatchdigitalfacewatchlet.h b/metawatch/metawatchdigitalfacewatchlet.h new file mode 100644 index 0000000..b4b92ca --- /dev/null +++ b/metawatch/metawatchdigitalfacewatchlet.h @@ -0,0 +1,18 @@ +#ifndef METAWATCHDIGITALFACEWATCHLET_H +#define METAWATCHDIGITALFACEWATCHLET_H + +#include + +namespace sowatch +{ + +class MetaWatchDigitalFaceWatchlet : public DeclarativeWatchlet +{ + Q_OBJECT +public: + explicit MetaWatchDigitalFaceWatchlet(Watch* watch); +}; + +} + +#endif // METAWATCHDIGITALFACEWATCHLET_H diff --git a/metawatch/qml/metawatch-digital-watchface.qml b/metawatch/qml/metawatch-digital-watchface.qml new file mode 100644 index 0000000..d2abbf0 --- /dev/null +++ b/metawatch/qml/metawatch-digital-watchface.qml @@ -0,0 +1,7 @@ +// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5 +import QtQuick 1.1 + +Rectangle { + width: 100 + height: 62 +} diff --git a/notificationswatchlet/notificationswatchlet.cpp b/notificationswatchlet/notificationswatchlet.cpp index 89e61ca..b587fb5 100644 --- a/notificationswatchlet/notificationswatchlet.cpp +++ b/notificationswatchlet/notificationswatchlet.cpp @@ -2,9 +2,9 @@ using namespace sowatch; -NotificationsWatchlet::NotificationsWatchlet(WatchServer* server) : - DeclarativeWatchlet(server, "com.javispedro.sowatch.notifications") +NotificationsWatchlet::NotificationsWatchlet(Watch* watch) : + DeclarativeWatchlet(watch, "com.javispedro.sowatch.notifications") { - setSource(QUrl(SOWATCH_QML_DIR "/notificationswatchlet/" + server->watch()->model() + ".qml")); + setSource(QUrl(SOWATCH_QML_DIR "/notificationswatchlet/" + watch->model() + ".qml")); } diff --git a/notificationswatchlet/notificationswatchlet.h b/notificationswatchlet/notificationswatchlet.h index fe49f97..78df1f6 100644 --- a/notificationswatchlet/notificationswatchlet.h +++ b/notificationswatchlet/notificationswatchlet.h @@ -10,7 +10,7 @@ class NotificationsWatchlet : public DeclarativeWatchlet { Q_OBJECT public: - explicit NotificationsWatchlet(WatchServer* server); + explicit NotificationsWatchlet(Watch* watch); }; } diff --git a/notificationswatchlet/notificationswatchletplugin.cpp b/notificationswatchlet/notificationswatchletplugin.cpp index d5ba173..4b26a14 100644 --- a/notificationswatchlet/notificationswatchletplugin.cpp +++ b/notificationswatchlet/notificationswatchletplugin.cpp @@ -28,11 +28,11 @@ WatchletPluginInterface::WatchletInfo NotificationsWatchletPlugin::describeWatch return info; } -Watchlet* NotificationsWatchletPlugin::getWatchlet(const QString& driver, ConfigKey *settings, WatchServer *server) +Watchlet* NotificationsWatchletPlugin::getWatchlet(const QString& driver, ConfigKey *settings, Watch *watch) { Q_UNUSED(driver); Q_UNUSED(settings); - return new NotificationsWatchlet(server); + return new NotificationsWatchlet(watch); } Q_EXPORT_PLUGIN2(notificationswatchlet, NotificationsWatchletPlugin) diff --git a/notificationswatchlet/notificationswatchletplugin.h b/notificationswatchlet/notificationswatchletplugin.h index 7efbc1c..472af5c 100644 --- a/notificationswatchlet/notificationswatchletplugin.h +++ b/notificationswatchlet/notificationswatchletplugin.h @@ -17,7 +17,7 @@ public: QStringList watchlets(); WatchletInfo describeWatchlet(const QString &id); - Watchlet* getWatchlet(const QString& id, ConfigKey *settings, WatchServer* server); + Watchlet* getWatchlet(const QString& id, ConfigKey *settings, Watch* watch); }; } diff --git a/sowatchd/watchhandler.cpp b/sowatchd/watchhandler.cpp index 89d3d95..bde68b4 100644 --- a/sowatchd/watchhandler.cpp +++ b/sowatchd/watchhandler.cpp @@ -82,7 +82,7 @@ Watchlet* WatchHandler::createWatchlet(const QString &id) } ConfigKey *subconfig = _config->getSubkey(id); - Watchlet* watchlet = plugin->getWatchlet(id, subconfig, _server); + Watchlet* watchlet = plugin->getWatchlet(id, subconfig, _watch); delete subconfig; return watchlet; -- cgit v1.2.3