From 77a98ac21c2520d9fb4bb9c8f70967a8e36dc872 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Mon, 19 Sep 2011 01:51:04 +0200 Subject: adding notification provider plugins, idle screen --- libsowatch/declarativewatchlet.h | 6 +- libsowatch/declarativewatchwrapper.h | 6 +- libsowatch/graphicswatchlet.h | 6 +- libsowatch/libsowatch.pro | 8 +- libsowatch/notification.h | 10 ++- libsowatch/notificationplugininterface.h | 17 ++-- libsowatch/notificationprovider.cpp | 13 +++ libsowatch/notificationprovider.h | 29 +++++++ libsowatch/sowatch.h | 13 ++- libsowatch/testdeclarativewatchlet.h | 6 +- libsowatch/testwatchlet.h | 6 +- libsowatch/watch.h | 6 +- libsowatch/watchlet.h | 6 +- libsowatch/watchpaintengine.h | 6 +- libsowatch/watchplugininterface.h | 6 +- libsowatch/watchserver.cpp | 39 +++++++-- libsowatch/watchserver.h | 22 ++--- libsowatch/watchsimulator.h | 6 +- .../meegohandsetnotification.pro | 45 ++++++++++ .../meegohandsetnotificationprovider.cpp | 51 ++++++++++++ .../meegohandsetnotificationprovider.h | 33 ++++++++ meegohandsetnotification/meegohandsetplugin.cpp | 28 +++++++ meegohandsetnotification/meegohandsetplugin.h | 24 ++++++ .../mnotificationmanagerinterface.cpp | 14 ++++ .../mnotificationmanagerinterface.h | 56 +++++++++++++ meegohandsetnotification/watchnotificationsink.cpp | 72 ++++++++++++++++ meegohandsetnotification/watchnotificationsink.h | 41 +++++++++ metawatch/metawatch.cpp | 92 +++++++++++++++++---- metawatch/metawatch.h | 5 ++ metawatch/metawatch.pro | 14 +++- metawatch/metawatch_16pt_11pxl.ttf | Bin 0 -> 14576 bytes metawatch/metawatch_8pt_5pxl_CAPS.ttf | Bin 0 -> 12408 bytes metawatch/metawatch_8pt_7pxl_CAPS.ttf | Bin 0 -> 15212 bytes metawatch/metawatchplugin.cpp | 14 ++++ metawatch/metawatchplugin.h | 4 + metawatch/uires.qrc | 13 ++- metawatch/weather_cloudy.bmp | Bin 0 -> 158 bytes metawatch/weather_rain.bmp | Bin 0 -> 158 bytes metawatch/weather_snow.bmp | Bin 0 -> 158 bytes metawatch/weather_sunny.bmp | Bin 0 -> 158 bytes metawatch/weather_thunderstorm.bmp | Bin 0 -> 158 bytes metawatch/weather_wind.bmp | Bin 0 -> 158 bytes sowatch.pro | 14 ++++ sowatch.pro.user | 28 ++++--- sowatchd/daemon.cpp | 71 ++++++++++++++-- sowatchd/daemon.h | 9 +- 46 files changed, 736 insertions(+), 103 deletions(-) create mode 100644 libsowatch/notificationprovider.cpp create mode 100644 libsowatch/notificationprovider.h create mode 100644 meegohandsetnotification/meegohandsetnotification.pro create mode 100644 meegohandsetnotification/meegohandsetnotificationprovider.cpp create mode 100644 meegohandsetnotification/meegohandsetnotificationprovider.h create mode 100644 meegohandsetnotification/meegohandsetplugin.cpp create mode 100644 meegohandsetnotification/meegohandsetplugin.h create mode 100644 meegohandsetnotification/mnotificationmanagerinterface.cpp create mode 100644 meegohandsetnotification/mnotificationmanagerinterface.h create mode 100644 meegohandsetnotification/watchnotificationsink.cpp create mode 100644 meegohandsetnotification/watchnotificationsink.h create mode 100644 metawatch/metawatch_16pt_11pxl.ttf create mode 100644 metawatch/metawatch_8pt_5pxl_CAPS.ttf create mode 100644 metawatch/metawatch_8pt_7pxl_CAPS.ttf create mode 100644 metawatch/weather_cloudy.bmp create mode 100644 metawatch/weather_rain.bmp create mode 100644 metawatch/weather_snow.bmp create mode 100644 metawatch/weather_sunny.bmp create mode 100644 metawatch/weather_thunderstorm.bmp create mode 100644 metawatch/weather_wind.bmp diff --git a/libsowatch/declarativewatchlet.h b/libsowatch/declarativewatchlet.h index ea31a33..2cc4655 100644 --- a/libsowatch/declarativewatchlet.h +++ b/libsowatch/declarativewatchlet.h @@ -1,5 +1,5 @@ -#ifndef DECLARATIVEWATCHLET_H -#define DECLARATIVEWATCHLET_H +#ifndef SOWATCH_DECLARATIVEWATCHLET_H +#define SOWATCH_DECLARATIVEWATCHLET_H #include #include @@ -37,4 +37,4 @@ protected: } -#endif // DECLARATIVEWATCHLET_H +#endif // SOWATCH_DECLARATIVEWATCHLET_H diff --git a/libsowatch/declarativewatchwrapper.h b/libsowatch/declarativewatchwrapper.h index 5f78e75..42746ec 100644 --- a/libsowatch/declarativewatchwrapper.h +++ b/libsowatch/declarativewatchwrapper.h @@ -1,5 +1,5 @@ -#ifndef DECLARATIVEWATCHWRAPPER_H -#define DECLARATIVEWATCHWRAPPER_H +#ifndef SOWATCH_DECLARATIVEWATCHWRAPPER_H +#define SOWATCH_DECLARATIVEWATCHWRAPPER_H #include @@ -41,4 +41,4 @@ friend class DeclarativeWatchlet; QML_DECLARE_TYPE(sowatch::DeclarativeWatchWrapper) -#endif // DECLARATIVEWATCHWRAPPER_H +#endif // SOWATCH_DECLARATIVEWATCHWRAPPER_H diff --git a/libsowatch/graphicswatchlet.h b/libsowatch/graphicswatchlet.h index d2cbb37..37752a9 100644 --- a/libsowatch/graphicswatchlet.h +++ b/libsowatch/graphicswatchlet.h @@ -1,5 +1,5 @@ -#ifndef GRAPHICSWATCHLET_H -#define GRAPHICSWATCHLET_H +#ifndef SOWATCH_GRAPHICSWATCHLET_H +#define SOWATCH_GRAPHICSWATCHLET_H #include #include @@ -29,4 +29,4 @@ protected slots: } -#endif // GRAPHICSWATCHLET_H +#endif // SOWATCH_GRAPHICSWATCHLET_H diff --git a/libsowatch/libsowatch.pro b/libsowatch/libsowatch.pro index 38d3389..aefdadd 100644 --- a/libsowatch/libsowatch.pro +++ b/libsowatch/libsowatch.pro @@ -26,7 +26,8 @@ SOURCES += \ declarativewatchlet.cpp \ watchplugininterface.cpp \ notification.cpp \ - notificationplugininterface.cpp + notificationplugininterface.cpp \ + notificationprovider.cpp HEADERS +=\ watchsimulator.h \ @@ -43,7 +44,8 @@ HEADERS +=\ sowatch_global.h \ watchplugininterface.h \ notification.h \ - notificationplugininterface.h + notificationplugininterface.h \ + notificationprovider.h install_headers.files = $$HEADERS @@ -84,4 +86,6 @@ unix:!symbian { + + diff --git a/libsowatch/notification.h b/libsowatch/notification.h index 7f463bf..80d7996 100644 --- a/libsowatch/notification.h +++ b/libsowatch/notification.h @@ -1,5 +1,5 @@ -#ifndef NOTIFICATION_H -#define NOTIFICATION_H +#ifndef SOWATCH_NOTIFICATION_H +#define SOWATCH_NOTIFICATION_H #include #include @@ -13,10 +13,12 @@ class SOWATCH_EXPORT Notification public: enum Type { OtherNotification = 0, - EmailNotification, CallNotification, + EmailNotification, + MissedCallNotification, SmsNotification, ImNotification, + CalendarNotification, TypeCount }; @@ -37,4 +39,4 @@ protected: } -#endif // NOTIFICATION_H +#endif // SOWATCH_NOTIFICATION_H diff --git a/libsowatch/notificationplugininterface.h b/libsowatch/notificationplugininterface.h index 1a312a1..b6c16f7 100644 --- a/libsowatch/notificationplugininterface.h +++ b/libsowatch/notificationplugininterface.h @@ -1,29 +1,28 @@ -#ifndef NOTIFICATIONPLUGININTERFACE_H -#define NOTIFICATIONPLUGININTERFACE_H +#ifndef SOWATCH_NOTIFICATIONPLUGININTERFACE_H +#define SOWATCH_NOTIFICATIONPLUGININTERFACE_H #include +#include +#include #include "sowatch_global.h" -#include "notification.h" namespace sowatch { class Notification; +class NotificationProvider; class SOWATCH_EXPORT NotificationPluginInterface { public: virtual ~NotificationPluginInterface(); - int getCount(Notification::Type type); - -signals: - void incomingNotification(const Notification& n); - void unreadCountChanged(Notification::Type type); + virtual QStringList providers() = 0; + virtual NotificationProvider* getProvider(const QString& driver, QSettings& settings, QObject *parent = 0) = 0; }; } Q_DECLARE_INTERFACE(sowatch::NotificationPluginInterface, "com.javispedro.sowatch.NotificationPluginInterface") -#endif // NOTIFICATIONPLUGININTERFACE_H +#endif // SOWATCH_NOTIFICATIONPLUGININTERFACE_H diff --git a/libsowatch/notificationprovider.cpp b/libsowatch/notificationprovider.cpp new file mode 100644 index 0000000..abc8bfc --- /dev/null +++ b/libsowatch/notificationprovider.cpp @@ -0,0 +1,13 @@ +#include "notificationprovider.h" + +using namespace sowatch; + +NotificationProvider::NotificationProvider(QObject *parent) : + QObject(parent) +{ +} + +NotificationProvider::~NotificationProvider() +{ + +} diff --git a/libsowatch/notificationprovider.h b/libsowatch/notificationprovider.h new file mode 100644 index 0000000..6f31581 --- /dev/null +++ b/libsowatch/notificationprovider.h @@ -0,0 +1,29 @@ +#ifndef SOWATCH_NOTIFICATIONPROVIDER_H +#define SOWATCH_NOTIFICATIONPROVIDER_H + +#include +#include "notification.h" + +namespace sowatch +{ + +class NotificationProvider : public QObject +{ + Q_OBJECT + +protected: + explicit NotificationProvider(QObject *parent = 0); + virtual ~NotificationProvider(); + +public: + virtual int getCount(Notification::Type type) = 0; + +signals: + void notification(const Notification& n); + void unreadCountChanged(Notification::Type type); + +}; + +} + +#endif // SOWATCH_NOTIFICATIONPROVIDER_H diff --git a/libsowatch/sowatch.h b/libsowatch/sowatch.h index 8c56954..e294ece 100644 --- a/libsowatch/sowatch.h +++ b/libsowatch/sowatch.h @@ -2,13 +2,18 @@ #define SOWATCH_H #include "sowatch_global.h" + #include "watch.h" -#include "watchlet.h" -#include "graphicswatchlet.h" -#include "declarativewatchlet.h" -#include "notification.h" #include "watchserver.h" #include "watchsimulator.h" #include "watchplugininterface.h" +#include "notification.h" +#include "notificationprovider.h" +#include "notificationplugininterface.h" + +#include "watchlet.h" +#include "graphicswatchlet.h" +#include "declarativewatchlet.h" + #endif // SOWATCH_H diff --git a/libsowatch/testdeclarativewatchlet.h b/libsowatch/testdeclarativewatchlet.h index b7b6dcd..a200663 100644 --- a/libsowatch/testdeclarativewatchlet.h +++ b/libsowatch/testdeclarativewatchlet.h @@ -1,5 +1,5 @@ -#ifndef TESTDECLARATIVEWATCHLET_H -#define TESTDECLARATIVEWATCHLET_H +#ifndef SOWATCH_TESTDECLARATIVEWATCHLET_H +#define SOWATCH_TESTDECLARATIVEWATCHLET_H #include "declarativewatchlet.h" @@ -16,4 +16,4 @@ public: } -#endif // TESTDECLARATIVEWATCHLET_H +#endif // SOWATCH_TESTDECLARATIVEWATCHLET_H diff --git a/libsowatch/testwatchlet.h b/libsowatch/testwatchlet.h index caa68da..6556724 100644 --- a/libsowatch/testwatchlet.h +++ b/libsowatch/testwatchlet.h @@ -1,5 +1,5 @@ -#ifndef TESTWATCHLET_H -#define TESTWATCHLET_H +#ifndef SOWATCH_TESTWATCHLET_H +#define SOWATCH_TESTWATCHLET_H #include #include "watchlet.h" @@ -26,4 +26,4 @@ private: } -#endif // TESTWATCHLET_H +#endif // SOWATCH_TESTWATCHLET_H diff --git a/libsowatch/watch.h b/libsowatch/watch.h index 056bfe0..fff4c15 100644 --- a/libsowatch/watch.h +++ b/libsowatch/watch.h @@ -1,5 +1,5 @@ -#ifndef WATCH_H -#define WATCH_H +#ifndef SOWATCH_WATCH_H +#define SOWATCH_WATCH_H #include #include @@ -45,4 +45,4 @@ public slots: } -#endif // WATCH_H +#endif // SOWATCH_WATCH_H diff --git a/libsowatch/watchlet.h b/libsowatch/watchlet.h index 06e43a0..7f3413d 100644 --- a/libsowatch/watchlet.h +++ b/libsowatch/watchlet.h @@ -1,5 +1,5 @@ -#ifndef WATCHLET_H -#define WATCHLET_H +#ifndef SOWATCH_WATCHLET_H +#define SOWATCH_WATCHLET_H #include #include "sowatch_global.h" @@ -45,4 +45,4 @@ friend class WatchServer; } -#endif // WATCHLET_H +#endif // SOWATCH_WATCHLET_H diff --git a/libsowatch/watchpaintengine.h b/libsowatch/watchpaintengine.h index 14d8f61..74d4e09 100644 --- a/libsowatch/watchpaintengine.h +++ b/libsowatch/watchpaintengine.h @@ -1,5 +1,5 @@ -#ifndef WATCHPAINTENGINE_H -#define WATCHPAINTENGINE_H +#ifndef SOWATCH_WATCHPAINTENGINE_H +#define SOWATCH_WATCHPAINTENGINE_H #include @@ -56,4 +56,4 @@ protected: } -#endif // WATCHPAINTENGINE_H +#endif // SOWATCH_WATCHPAINTENGINE_H diff --git a/libsowatch/watchplugininterface.h b/libsowatch/watchplugininterface.h index e360dea..c027c47 100644 --- a/libsowatch/watchplugininterface.h +++ b/libsowatch/watchplugininterface.h @@ -1,5 +1,5 @@ -#ifndef WATCHPLUGININTERFACE_H -#define WATCHPLUGININTERFACE_H +#ifndef SOWATCH_WATCHPLUGININTERFACE_H +#define SOWATCH_WATCHPLUGININTERFACE_H #include #include @@ -24,4 +24,4 @@ public: Q_DECLARE_INTERFACE(sowatch::WatchPluginInterface, "com.javispedro.sowatch.WatchPluginInterface") -#endif // WATCHPLUGININTERFACE_H +#endif // SOWATCH_WATCHPLUGININTERFACE_H diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp index 5ee8a90..8d00088 100644 --- a/libsowatch/watchserver.cpp +++ b/libsowatch/watchserver.cpp @@ -1,7 +1,11 @@ +#include + +#include "notificationprovider.h" #include "watch.h" #include "watchlet.h" #include "watchserver.h" + using namespace sowatch; WatchServer::WatchServer(Watch* watch, QObject* parent) : @@ -16,12 +20,22 @@ Watch* WatchServer::watch() return _watch; } +void WatchServer::addProvider(NotificationProvider *provider) +{ + provider->setParent(this); + + connect(provider, SIGNAL(notification(Notification)), SLOT(notificationEmitted(Notification))); + connect(provider, SIGNAL(unreadCountChanged(Notification::Type)), SLOT(unreadCountUpdated(Notification::Type))); + + _providers.append(provider); +} + void WatchServer::runWatchlet(const QString& id) { if (_currentWatchlet) { closeWatchlet(); } - _currentWatchlet = watchlets[id]; + _currentWatchlet = _watchlets[id]; if (_watch->isConnected()) { _currentWatchlet->activate(); } @@ -36,15 +50,10 @@ void WatchServer::closeWatchlet() _currentWatchlet = 0; } -void WatchServer::notification(const Notification &n) -{ - Q_UNUSED(n); -} - void WatchServer::registerWatchlet(Watchlet *watchlet) { Q_ASSERT(watchlet->_server == this); - watchlets[watchlet->id()] = watchlet; + _watchlets[watchlet->id()] = watchlet; } void WatchServer::watchConnected() @@ -60,3 +69,19 @@ void WatchServer::watchDisconnected() _currentWatchlet->deactivate(); } } + +void WatchServer::notificationEmitted(const Notification ¬ification) +{ + // TODO app loses button focus... + _watch->showNotification(notification); +} + +void WatchServer::unreadCountUpdated(Notification::Type type) +{ + uint count = 0; + foreach(NotificationProvider* provider, _providers) + { + count += provider->getCount(type); + } + _watch->updateNotificationCount(type, count); +} diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h index f8bed67..0ca1f4f 100644 --- a/libsowatch/watchserver.h +++ b/libsowatch/watchserver.h @@ -1,17 +1,19 @@ -#ifndef WATCHSERVER_H -#define WATCHSERVER_H +#ifndef SOWATCH_WATCHSERVER_H +#define SOWATCH_WATCHSERVER_H #include #include +#include #include "sowatch_global.h" +#include "notification.h" namespace sowatch { class Watch; class Watchlet; -class Notification; +class NotificationProvider; class SOWATCH_EXPORT WatchServer : public QObject { @@ -23,29 +25,29 @@ public: Watch* watch(); + void addProvider(NotificationProvider* provider); + void runWatchlet(const QString& id); void closeWatchlet(); -signals: - -public slots: - void notification(const Notification& n); - protected: Watch* _watch; Watchlet* _currentWatchlet; - QMap watchlets; + QMap _watchlets; + QList _providers; void registerWatchlet(Watchlet *watchlet); protected slots: void watchConnected(); void watchDisconnected(); + void notificationEmitted(const Notification& notification); + void unreadCountUpdated(Notification::Type type); friend class Watchlet; }; } -#endif // WATCHSERVER_H +#endif // SOWATCH_WATCHSERVER_H diff --git a/libsowatch/watchsimulator.h b/libsowatch/watchsimulator.h index aa8586d..c9d69ba 100644 --- a/libsowatch/watchsimulator.h +++ b/libsowatch/watchsimulator.h @@ -1,5 +1,5 @@ -#ifndef WATCHSIMULATOR_H -#define WATCHSIMULATOR_H +#ifndef SOWATCH_WATCHSIMULATOR_H +#define SOWATCH_WATCHSIMULATOR_H #include @@ -17,4 +17,4 @@ public: } -#endif // WATCHSIMULATOR_H +#endif // SOWATCH_WATCHSIMULATOR_H diff --git a/meegohandsetnotification/meegohandsetnotification.pro b/meegohandsetnotification/meegohandsetnotification.pro new file mode 100644 index 0000000..424eb33 --- /dev/null +++ b/meegohandsetnotification/meegohandsetnotification.pro @@ -0,0 +1,45 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2011-09-18T18:48:13 +# +#------------------------------------------------- + + +TARGET = meegohandsetnotification +TEMPLATE = lib +# CONFIG += plugin # Stupid Qt creator doesn't want to deploy plugins +QT += dbus + +SOURCES += meegohandsetplugin.cpp \ + meegohandsetnotificationprovider.cpp \ + watchnotificationsink.cpp \ + mnotificationmanagerinterface.cpp + +HEADERS += meegohandsetplugin.h \ + meegohandsetnotificationprovider.h \ + watchnotificationsink.h \ + mnotificationmanagerinterface.h + +CONFIG += notificationsystem + +unix: LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch + +INCLUDEPATH += $$PWD/../libsowatch +DEPENDPATH += $$PWD/../libsowatch + +unix:!symbian { + maemo5 { + target.path = /opt/sowatch/notifications + } else { + target.path = /usr/lib/sowatch/notifications + } + INSTALLS += target +} + + + + + + + + diff --git a/meegohandsetnotification/meegohandsetnotificationprovider.cpp b/meegohandsetnotification/meegohandsetnotificationprovider.cpp new file mode 100644 index 0000000..fc84e46 --- /dev/null +++ b/meegohandsetnotification/meegohandsetnotificationprovider.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include "watchnotificationsink.h" +#include "mnotificationmanagerinterface.h" +#include "meegohandsetnotificationprovider.h" + +using namespace sowatch; + +MeegoHandsetNotificationProvider::MeegoHandsetNotificationProvider(QObject *parent) : + sowatch::NotificationProvider(parent), + _manager(new MNotificationManagerInterface("com.meego.core.MNotificationManager", "/notificationsinkmanager", QDBusConnection::sessionBus(), this)), + _sink(new WatchNotificationSink(this)) +{ + qDBusRegisterMetaType< ::Notification >(); // Avoid a name collision with sowatch::Notification + qDBusRegisterMetaType >(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType >(); + qDBusRegisterMetaType(); + + new NotificationSinkAdaptor(_sink); + QDBusConnection::sessionBus().registerService("com.javispedro.sowatch.MeegoHandsetNotificationSink"); + QDBusConnection::sessionBus().registerObject("/meegohandsetnotificationsink", _sink); + + connect(_sink, SIGNAL(incomingNotification(sowatch::Notification)), + SLOT(sinkNotification(sowatch::Notification))); + connect(_sink, SIGNAL(countsChanged(sowatch::Notification::Type)), + SLOT(sinkUnreadCountChanged(sowatch::Notification::Type))); + + _manager->registerSink("com.javispedro.sowatch.MeegoHandsetNotificationSink", "/meegohandsetnotificationsink"); +} + +MeegoHandsetNotificationProvider::~MeegoHandsetNotificationProvider() +{ + +} + +int MeegoHandsetNotificationProvider::getCount(sowatch::Notification::Type type) +{ + return _sink->getCount(type); +} + +void MeegoHandsetNotificationProvider::sinkNotification(const Notification &n) +{ + emit notification(n); +} + +void MeegoHandsetNotificationProvider::sinkUnreadCountChanged(Notification::Type type) +{ + emit unreadCountChanged(type); +} diff --git a/meegohandsetnotification/meegohandsetnotificationprovider.h b/meegohandsetnotification/meegohandsetnotificationprovider.h new file mode 100644 index 0000000..3cf78d3 --- /dev/null +++ b/meegohandsetnotification/meegohandsetnotificationprovider.h @@ -0,0 +1,33 @@ +#ifndef MEEGOHANDSETNOTIFICATIONPROVIDER_H +#define MEEGOHANDSETNOTIFICATIONPROVIDER_H + +#include + +class MNotificationManagerInterface; +class WatchNotificationSink; + +namespace sowatch +{ + +class MeegoHandsetNotificationProvider : public NotificationProvider +{ + Q_OBJECT +public: + explicit MeegoHandsetNotificationProvider(QObject *parent = 0); + ~MeegoHandsetNotificationProvider(); + + int getCount(Notification::Type type); +protected: + MNotificationManagerInterface* _manager; + WatchNotificationSink* _sink; + +protected slots: + void sinkNotification(const sowatch::Notification &n); + void sinkUnreadCountChanged(sowatch::Notification::Type type); + +friend class WatchNoficationSink; +}; + +} + +#endif // MEEGOHANDSETNOTIFICATIONPROVIDER_H diff --git a/meegohandsetnotification/meegohandsetplugin.cpp b/meegohandsetnotification/meegohandsetplugin.cpp new file mode 100644 index 0000000..bac41aa --- /dev/null +++ b/meegohandsetnotification/meegohandsetplugin.cpp @@ -0,0 +1,28 @@ +#include "meegohandsetplugin.h" +#include "meegohandsetnotificationprovider.h" + +using namespace sowatch; + +MeegoHandsetPlugin::MeegoHandsetPlugin() +{ +} + +MeegoHandsetPlugin::~MeegoHandsetPlugin() +{ +} + +QStringList MeegoHandsetPlugin::providers() +{ + QStringList providers; + providers << "meegohandset"; + return providers; +} + +NotificationProvider* MeegoHandsetPlugin::getProvider(const QString& driver, QSettings& settings, QObject *parent) +{ + Q_UNUSED(driver); + Q_UNUSED(settings); + return new MeegoHandsetNotificationProvider(parent); +} + +Q_EXPORT_PLUGIN2(meegohandsetnotification, MeegoHandsetPlugin) diff --git a/meegohandsetnotification/meegohandsetplugin.h b/meegohandsetnotification/meegohandsetplugin.h new file mode 100644 index 0000000..616fb9b --- /dev/null +++ b/meegohandsetnotification/meegohandsetplugin.h @@ -0,0 +1,24 @@ +#ifndef MEEGOHANDSETPLUGIN_H +#define MEEGOHANDSETPLUGIN_H + +#include + +namespace sowatch +{ + +class MeegoHandsetPlugin : public QObject, public NotificationPluginInterface +{ + Q_OBJECT + Q_INTERFACES(sowatch::NotificationPluginInterface) + +public: + MeegoHandsetPlugin(); + ~MeegoHandsetPlugin(); + + QStringList providers(); + NotificationProvider* getProvider(const QString& driver, QSettings& settings, QObject *parent = 0); +}; + +} + +#endif // MEEGOHANDSETPLUGIN_H diff --git a/meegohandsetnotification/mnotificationmanagerinterface.cpp b/meegohandsetnotification/mnotificationmanagerinterface.cpp new file mode 100644 index 0000000..91adbb4 --- /dev/null +++ b/meegohandsetnotification/mnotificationmanagerinterface.cpp @@ -0,0 +1,14 @@ +#include "mnotificationmanagerinterface.h" + +/* + * Implementation of interface class MNotificationManagerInterface + */ + +MNotificationManagerInterface::MNotificationManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +MNotificationManagerInterface::~MNotificationManagerInterface() +{ +} diff --git a/meegohandsetnotification/mnotificationmanagerinterface.h b/meegohandsetnotification/mnotificationmanagerinterface.h new file mode 100644 index 0000000..d5761c9 --- /dev/null +++ b/meegohandsetnotification/mnotificationmanagerinterface.h @@ -0,0 +1,56 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -N -p - dbusinterfacenotificationsink.xml + * + * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef QDBUSXML2CPP_PROXY_1316370481 +#define QDBUSXML2CPP_PROXY_1316370481 + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface com.meego.core.MNotificationManager + */ +class MNotificationManagerInterface: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "com.meego.core.MNotificationManager"; } + +public: + MNotificationManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~MNotificationManagerInterface(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> registerSink(const QString &service, const QString &path) + { + QList argumentList; + argumentList << qVariantFromValue(service) << qVariantFromValue(path); + return asyncCallWithArgumentList(QLatin1String("registerSink"), argumentList); + } + + inline QDBusPendingReply<> unregisterSink(const QString &service, const QString &path) + { + QList argumentList; + argumentList << qVariantFromValue(service) << qVariantFromValue(path); + return asyncCallWithArgumentList(QLatin1String("unregisterSink"), argumentList); + } + +Q_SIGNALS: // SIGNALS +}; + +#endif diff --git a/meegohandsetnotification/watchnotificationsink.cpp b/meegohandsetnotification/watchnotificationsink.cpp new file mode 100644 index 0000000..0d97562 --- /dev/null +++ b/meegohandsetnotification/watchnotificationsink.cpp @@ -0,0 +1,72 @@ +#include "meegohandsetnotificationprovider.h" +#include "watchnotificationsink.h" + +WatchNotificationSink::WatchNotificationSink(sowatch::MeegoHandsetNotificationProvider *parent) : + NotificationSink(parent), _parent(parent) +{ + for (uint i = 0; i < maxTypes; i++) { + _counts[i] = 0; + } +} + +void WatchNotificationSink::addNotification(const Notification ¬ification) +{ + const NotificationParameters& p = notification.parameters(); + sowatch::Notification::Type type = notificationTypeFromEventType(p.value("eventType").toString()); + uint count = p.value("count").toUInt(); + + _counts[type] += count; + _trackedNotifications[notification.notificationId()] = notification; + + emit countsChanged(type); + + QDateTime dt = QDateTime::fromTime_t(p.value("timestamp").toUInt()); + QDateTime tenSecondsAgo = QDateTime::currentDateTimeUtc().addSecs(-10); + if (dt >= tenSecondsAgo) { + // If the notification happened recently, show it. + sowatch::Notification n(type, dt, p.value("summary").toString(), p.value("body").toString()); + emit incomingNotification(n); + } +} + +void WatchNotificationSink::removeNotification(uint notificationId) +{ + Notification notification = _trackedNotifications[notificationId]; + const NotificationParameters& p = notification.parameters(); + sowatch::Notification::Type type = notificationTypeFromEventType(p.value("eventType").toString()); + uint count = p.value("count").toUInt(); + + _counts[type] -= count; + _trackedNotifications.remove(notificationId); + + emit countsChanged(type); +} + +void WatchNotificationSink::addGroup(uint groupId, const NotificationParameters ¶meters) +{ + // We do not care about notification groups + Q_UNUSED(groupId); + Q_UNUSED(parameters); +} + +void WatchNotificationSink::removeGroup(uint groupId) +{ + Q_UNUSED(groupId); +} + +int WatchNotificationSink::getCount(sowatch::Notification::Type type) +{ + return _counts[type]; +} + +sowatch::Notification::Type WatchNotificationSink::notificationTypeFromEventType(const QString& eventType) +{ + if (eventType == "email.arrived") + return sowatch::Notification::EmailNotification; + else if (eventType == "x-nokia.call.missed") + return sowatch::Notification::MissedCallNotification; + else if (eventType == "x-nokia.messaging.im") + return sowatch::Notification::ImNotification; + else + return sowatch::Notification::OtherNotification; +} diff --git a/meegohandsetnotification/watchnotificationsink.h b/meegohandsetnotification/watchnotificationsink.h new file mode 100644 index 0000000..dc586a2 --- /dev/null +++ b/meegohandsetnotification/watchnotificationsink.h @@ -0,0 +1,41 @@ +#ifndef WATCHNOTIFICATIONSINK_H +#define WATCHNOTIFICATIONSINK_H + +#include +#include +#include +#include +#include + +namespace sowatch { + class MeegoHandsetNotificationProvider; +} + +class WatchNotificationSink : public NotificationSink +{ + Q_OBJECT +public: + explicit WatchNotificationSink(sowatch::MeegoHandsetNotificationProvider* parent); + + void addNotification(const Notification ¬ification); + void removeNotification(uint notificationId); + + void addGroup(uint groupId, const NotificationParameters ¶meters); + void removeGroup(uint groupId); + + int getCount(sowatch::Notification::Type type); + +signals: + void incomingNotification(const sowatch::Notification& notification); + void countsChanged(sowatch::Notification::Type type); + +protected: + static const uint maxTypes = sowatch::Notification::TypeCount; + static sowatch::Notification::Type notificationTypeFromEventType(const QString& eventType); + + sowatch::MeegoHandsetNotificationProvider* _parent; + QMap _trackedNotifications; + uint _counts[maxTypes]; +}; + +#endif // WATCHNOTIFICATIONSINK_H diff --git a/metawatch/metawatch.cpp b/metawatch/metawatch.cpp index 08b9890..e6a28f4 100644 --- a/metawatch/metawatch.cpp +++ b/metawatch/metawatch.cpp @@ -85,7 +85,8 @@ MetaWatch::MetaWatch(const QBluetoothAddress& address, QObject *parent) : _connectAlignedTimer(new QSystemAlignedTimer(this)), _sendTimer(new QTimer(this)), _currentMode(IdleMode), - _paintMode(IdleMode) + _paintMode(IdleMode), + _nMails(0), _nCalls(0), _nIms(0), _nSms(0) { QImage baseImage(screenWidth, screenHeight, QImage::Format_MonoLSB); baseImage.setColor(0, QColor(Qt::white).rgb()); @@ -191,8 +192,25 @@ void MetaWatch::setDateTime(const QDateTime &dateTime) void MetaWatch::updateNotificationCount(Notification::Type type, int count) { - Q_UNUSED(type); - Q_UNUSED(count); // TODO + switch (type) { + case Notification::MissedCallNotification: + _nCalls = count; + break; + case Notification::EmailNotification: + _nMails = count; + break; + case Notification::ImNotification: + _nIms = count; + break; + case Notification::SmsNotification: + _nSms = count; + break; + default: + // Ignore + break; + } + + renderIdleCounts(); } void MetaWatch::vibrate(bool on) @@ -202,7 +220,7 @@ void MetaWatch::vibrate(bool on) void MetaWatch::showNotification(const Notification &n) { - Q_UNUSED(n); // TODO + qDebug() << "It's time for a notification" << n.title(); } MetaWatch::Mode MetaWatch::currentMode() const @@ -248,20 +266,64 @@ void MetaWatch::clear(Mode mode, bool black) void MetaWatch::renderIdleScreen() { _paintMode = IdleMode; + + QFont smallFont("MetaWatch Small caps 8pt", 6); + QImage idle_mail(QString(":/metawatch/graphics/idle_gmail.bmp")); + QImage idle_call(QString(":/metawatch/graphics/idle_call.bmp")); + QImage idle_sms(QString(":/metawatch/graphics/idle_sms.bmp")); QPainter p(this); + p.fillRect(0, 0, screenWidth, screenHeight, Qt::white); + p.setPen(QPen(Qt::black, 1.0, Qt::DashLine)); - p.drawLine(0, systemAreaHeight + 2, screenWidth, systemAreaHeight + 2); - p.drawLine(0, systemAreaHeight * 2 + 3, screenWidth, systemAreaHeight * 2 + 3); - p.setPen(Qt::black); - p.drawText(1, systemAreaHeight + 16, "Space Weather!"); - QImage idle_mail(QString(":/metawatch/idle_gmail.bmp")); - QImage idle_call(QString(":/metawatch/idle_call.bmp")); - QImage idle_sms(QString(":/metawatch/idle_sms.bmp")); - p.drawImage(4, systemAreaHeight * 2 + 6, idle_mail); - p.drawImage(32 + 4, systemAreaHeight * 2 + 6, idle_call); - p.drawImage(32 * 2 + 4, systemAreaHeight * 2 + 6, idle_sms); - p.drawText(14, 93, "Too many!"); + p.drawLine(1, systemAreaHeight + 2, screenWidth - 2, systemAreaHeight + 2); + p.drawLine(1, systemAreaHeight * 2 + 3, screenWidth - 2, systemAreaHeight * 2 + 3); + + p.drawImage(3, systemAreaHeight * 2 + 6, idle_mail); + p.drawImage(32 + 3, systemAreaHeight * 2 + 6, idle_call); + p.drawImage(32 * 2 + 3, systemAreaHeight * 2 + 6, idle_sms); + + p.end(); + renderIdleWeather(); + renderIdleCounts(); + _paintMode = _currentMode; +} + +void MetaWatch::renderIdleWeather() +{ + _paintMode = IdleMode; + QFont smallFont("MetaWatch Small caps 8pt", 6); + QImage rain(QString(":/metawatch/graphics/weather_rain.bmp")); + QPainter p(this); + + p.setFont(smallFont); + p.drawText(46, systemAreaHeight + 14, "Rain"); + p.drawImage(screenWidth - 26, systemAreaHeight + 6, rain); + + _paintMode = _currentMode; +} + +void MetaWatch::renderIdleCounts() +{ + _paintMode = IdleMode; + QFont medFont("MetaWatch Large caps 8pt", 6); + QString s; + QPainter p(this); + QTextOption opt(Qt::AlignCenter); + const int y = systemAreaHeight * 2 + 25; + const int w = 24; + const int h = screenHeight - (y + 1); + const int mails = _nMails; + const int calls = _nCalls; + const int sms = _nSms + _nIms; + + qDebug() << "unread counts" << mails << calls << sms; + + p.setFont(medFont); + p.fillRect(QRect(0, y, screenWidth, h), Qt::white); + p.drawText(QRect(4, y, w, h), s.sprintf("%d", mails), opt); + p.drawText(QRect(32 + 4, y, w, h), s.sprintf("%d", calls), opt); + p.drawText(QRect(32 * 2 + 4, y, w, h), s.sprintf("%d", sms), opt); } quint16 MetaWatch::calcCrc(const QByteArray &data, int size) diff --git a/metawatch/metawatch.h b/metawatch/metawatch.h index 68e24c3..d15054f 100644 --- a/metawatch/metawatch.h +++ b/metawatch/metawatch.h @@ -88,6 +88,8 @@ public: void update(Mode mode, const QList& rects = QList()); void renderIdleScreen(); + void renderIdleWeather(); + void renderIdleCounts(); protected: mutable MetaWatchPaintEngine* _paintEngine; @@ -120,6 +122,9 @@ protected: Mode _paintMode; quint8 _buttonState; + // Notifications: Unread count + uint _nMails, _nCalls, _nIms, _nSms; + static const quint8 bitRevTable[16]; static const quint16 crcTable[256]; quint16 calcCrc(const QByteArray& data, int size); diff --git a/metawatch/metawatch.pro b/metawatch/metawatch.pro index f4b86f8..9a661ba 100644 --- a/metawatch/metawatch.pro +++ b/metawatch/metawatch.pro @@ -32,7 +32,16 @@ RESOURCES += \ OTHER_FILES += \ idle_sms.bmp \ idle_gmail.bmp \ - idle_call.bmp + idle_call.bmp \ + weather_wind.bmp \ + weather_thunderstorm.bmp \ + weather_sunny.bmp \ + weather_snow.bmp \ + weather_rain.bmp \ + weather_cloudy.bmp \ + metawatch_16pt_11pxl.ttf \ + metawatch_8pt_7pxl_CAPS.ttf \ + metawatch_8pt_5pxl_CAPS.ttf win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/release/ -lsowatch else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/debug/ -lsowatch @@ -47,7 +56,7 @@ symbian { TARGET.UID3 = 0xE4DC26B0 TARGET.CAPABILITY = TARGET.EPOCALLOWDLLDATA = 1 - addFiles.sources = metawatch.dll + addFiles.sources = metawatchdriver.dll addFiles.path = !:/sys/bin DEPLOYMENT += addFiles } @@ -60,3 +69,4 @@ unix:!symbian { } INSTALLS += target } + diff --git a/metawatch/metawatch_16pt_11pxl.ttf b/metawatch/metawatch_16pt_11pxl.ttf new file mode 100644 index 0000000..9aeb8b3 Binary files /dev/null and b/metawatch/metawatch_16pt_11pxl.ttf differ diff --git a/metawatch/metawatch_8pt_5pxl_CAPS.ttf b/metawatch/metawatch_8pt_5pxl_CAPS.ttf new file mode 100644 index 0000000..a6b8f30 Binary files /dev/null and b/metawatch/metawatch_8pt_5pxl_CAPS.ttf differ diff --git a/metawatch/metawatch_8pt_7pxl_CAPS.ttf b/metawatch/metawatch_8pt_7pxl_CAPS.ttf new file mode 100644 index 0000000..72eda9e Binary files /dev/null and b/metawatch/metawatch_8pt_7pxl_CAPS.ttf differ diff --git a/metawatch/metawatchplugin.cpp b/metawatch/metawatchplugin.cpp index e56d6db..751cff9 100644 --- a/metawatch/metawatchplugin.cpp +++ b/metawatch/metawatchplugin.cpp @@ -1,3 +1,4 @@ +#include #include #include "metawatch.h" #include "metawatchsimulator.h" @@ -6,6 +7,19 @@ using namespace sowatch; QTM_USE_NAMESPACE +bool MetaWatchPlugin::fontsLoaded = false; + +MetaWatchPlugin::MetaWatchPlugin() +{ + if (!fontsLoaded) { + QFontDatabase::addApplicationFont(":/metawatch/fonts/metawatch_16pt_11pxl.ttf"); + QFontDatabase::addApplicationFont(":/metawatch/fonts/metawatch_8pt_7pxl_CAPS.ttf"); + QFontDatabase::addApplicationFont(":/metawatch/fonts/metawatch_8pt_5pxl_CAPS.ttf"); + // "MetaWatch Large 16pt", "MetaWatch Large caps 8pt", "MetaWatch Small caps 8pt" + fontsLoaded = true; + } +} + MetaWatchPlugin::~MetaWatchPlugin() { diff --git a/metawatch/metawatchplugin.h b/metawatch/metawatchplugin.h index 9662ec0..57b1029 100644 --- a/metawatch/metawatchplugin.h +++ b/metawatch/metawatchplugin.h @@ -11,10 +11,14 @@ class MetaWatchPlugin : public QObject, public WatchPluginInterface { Q_INTERFACES(sowatch::WatchPluginInterface) public: + MetaWatchPlugin(); ~MetaWatchPlugin(); virtual QStringList drivers(); virtual Watch* getWatch(const QString& driver, QSettings& settings, QObject *parent = 0); + +protected: + static bool fontsLoaded; }; } diff --git a/metawatch/uires.qrc b/metawatch/uires.qrc index 4be7fc8..24d70fb 100644 --- a/metawatch/uires.qrc +++ b/metawatch/uires.qrc @@ -1,7 +1,18 @@ - + idle_call.bmp idle_gmail.bmp idle_sms.bmp + weather_cloudy.bmp + weather_rain.bmp + weather_snow.bmp + weather_sunny.bmp + weather_thunderstorm.bmp + weather_wind.bmp + + + metawatch_8pt_5pxl_CAPS.ttf + metawatch_8pt_7pxl_CAPS.ttf + metawatch_16pt_11pxl.ttf diff --git a/metawatch/weather_cloudy.bmp b/metawatch/weather_cloudy.bmp new file mode 100644 index 0000000..506c24a Binary files /dev/null and b/metawatch/weather_cloudy.bmp differ diff --git a/metawatch/weather_rain.bmp b/metawatch/weather_rain.bmp new file mode 100644 index 0000000..fc12c6e Binary files /dev/null and b/metawatch/weather_rain.bmp differ diff --git a/metawatch/weather_snow.bmp b/metawatch/weather_snow.bmp new file mode 100644 index 0000000..d328105 Binary files /dev/null and b/metawatch/weather_snow.bmp differ diff --git a/metawatch/weather_sunny.bmp b/metawatch/weather_sunny.bmp new file mode 100644 index 0000000..df9f774 Binary files /dev/null and b/metawatch/weather_sunny.bmp differ diff --git a/metawatch/weather_thunderstorm.bmp b/metawatch/weather_thunderstorm.bmp new file mode 100644 index 0000000..f101610 Binary files /dev/null and b/metawatch/weather_thunderstorm.bmp differ diff --git a/metawatch/weather_wind.bmp b/metawatch/weather_wind.bmp new file mode 100644 index 0000000..59bd81b Binary files /dev/null and b/metawatch/weather_wind.bmp differ diff --git a/sowatch.pro b/sowatch.pro index 9689ea3..38f2a8c 100644 --- a/sowatch.pro +++ b/sowatch.pro @@ -3,6 +3,19 @@ SUBDIRS = libsowatch \ metawatch \ sowatchd +!isEmpty(MEEGO_VERSION_MAJOR) { + SUBDIRS += meegohandsetnotification +} + +unix:!symbian { + maemo5 { + target.path = /opt/sowatch/notifications + } else { + target.path = /usr/lib/sowatch/notifications + } + INSTALLS += target +} + OTHER_FILES += \ qtc_packaging/debian_harmattan/rules \ qtc_packaging/debian_harmattan/README \ @@ -22,3 +35,4 @@ OTHER_FILES += \ + diff --git a/sowatch.pro.user b/sowatch.pro.user index 7f97a16..852a8a1 100644 --- a/sowatch.pro.user +++ b/sowatch.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -227,7 +227,7 @@ - 2011-09-18T04:20:07 + 2011-09-18T16:45:58 2011-09-17T20:53:24 @@ -408,11 +408,11 @@ Harmattan Harmattan Qt4ProjectManager.Target.HarmattanDeviceTarget - 0 + 1 0 1 - Qt4ProjectManager.ToolChain.Maemo:/home/javier/opt/QtSDK/Madde/targets/harmattan-nokia-meego-api/bin/gcc.arm-linux-generic-elf-32bit./home/javier/opt/QtSDK/pythongdb/gdb + Qt4ProjectManager.ToolChain.Maemo:/home/javier/opt/QtSDK/Madde/targets/harmattan-platform-api/bin/gcc.arm-linux-generic-elf-32bit./home/javier/opt/QtSDK/pythongdb/gdb qmake @@ -453,16 +453,16 @@ 2 false - MeeGo 1.2 Harmattan API (Qt SDK) Release - + Harmattan Platform API (Qt SDK) Release + Harmattan Release Qt4ProjectManager.Qt4BuildConfiguration 0 /mnt/Fuentes/Javier/Maemo/qt/sowatch-build-harmattan-release - 10 + 12 true - Qt4ProjectManager.ToolChain.Maemo:/home/javier/opt/QtSDK/Madde/targets/harmattan-nokia-meego-api/bin/gcc.arm-linux-generic-elf-32bit./home/javier/opt/QtSDK/pythongdb/gdb + Qt4ProjectManager.ToolChain.Maemo:/home/javier/opt/QtSDK/Madde/targets/harmattan-platform-api/bin/gcc.arm-linux-generic-elf-32bit./home/javier/opt/QtSDK/pythongdb/gdb qmake @@ -503,12 +503,12 @@ 2 false - MeeGo 1.2 Harmattan API (Qt SDK) Debug - + Harmattan Platform API (Qt SDK) Debug + Harmattan Debug Qt4ProjectManager.Qt4BuildConfiguration 2 /mnt/Fuentes/Javier/Maemo/qt/sowatch-build-harmattan-debug - 10 + 12 true 2 @@ -529,16 +529,20 @@ MaemoUploadAndInstallDpkgPackageStep + /mnt/Fuentes/Javier/Maemo/qt/sowatch-build-harmattan-debug/sowatch_0.1.1_armel.deb /mnt/Fuentes/Javier/Maemo/qt/sowatch-build-harmattan-release/sowatch_0.1.1_armel.deb harm + harm + - 2011-09-18T04:49:50 + 2011-09-19T01:23:25 + 2011-09-18T05:14:20 3 diff --git a/sowatchd/daemon.cpp b/sowatchd/daemon.cpp index a2d7b5a..3d9c05c 100644 --- a/sowatchd/daemon.cpp +++ b/sowatchd/daemon.cpp @@ -11,14 +11,18 @@ Daemon::Daemon(QObject *parent) : QObject(parent) { loadDrivers(); - loadWatches(); - loadWatchlets(); + loadProviders(); + initWatches(); } void Daemon::loadDrivers() { QDir dir(SOWATCH_DRIVERS_DIR); foreach (QString file, dir.entryList(QDir::Files)) { +#if defined(Q_OS_UNIX) + // Temporary workaround for QtC deploy plugin issues + if (!file.endsWith(".so")) continue; +#endif QPluginLoader loader(dir.absoluteFilePath(file)); QObject *pluginObj = loader.instance(); if (pluginObj) { @@ -28,16 +32,50 @@ void Daemon::loadDrivers() foreach (const QString& driver, drivers) { _drivers[driver] = plugin; } + } else { + qWarning() << "Invalid plugin" << file; + loader.unload(); } } else { qWarning() << "Invalid plugin" << file; + loader.unload(); } } qDebug() << "loaded drivers" << _drivers.keys(); } -void Daemon::loadWatches() +void Daemon::loadProviders() +{ + QDir dir(SOWATCH_NOTIFICATIONS_DIR); + foreach (QString file, dir.entryList(QDir::Files)) { +#if defined(Q_OS_UNIX) + // Temporary workaround for QtC deploy plugin issues + if (!file.endsWith(".so")) continue; +#endif + QPluginLoader loader(dir.absoluteFilePath(file)); + QObject *pluginObj = loader.instance(); + if (pluginObj) { + NotificationPluginInterface *plugin = qobject_cast(pluginObj); + if (plugin) { + QStringList providers = plugin->providers(); + foreach (const QString& provider, providers) { + _providers[provider] = plugin; + } + } else { + qWarning() << "Invalid plugin" << file; + loader.unload(); + } + } else { + qWarning() << "Invalid plugin" << file; + loader.unload(); + } + } + + qDebug() << "loaded providers" << _providers; +} + +void Daemon::initWatches() { QSettings settings; int size = settings.beginReadArray("watches"); @@ -49,7 +87,7 @@ void Daemon::loadWatches() if (plugin) { Watch *watch = plugin->getWatch(driver, settings, this); if (watch) { - _watches.append(watch); + initWatch(watch, settings); } else { qWarning() << "Driver" << driver << "refused to getWatch"; } @@ -59,7 +97,30 @@ void Daemon::loadWatches() } settings.endArray(); - qDebug() << "handling" << _watches.size() << "watches"; + qDebug() << "handling" << _servers.size() << "watches"; +} + +void Daemon::initWatch(Watch* watch, QSettings& settings) +{ + int size; + + // Create the server + WatchServer* server = new WatchServer(watch, this); + _servers.append(server); + + // Initialize providers + size = settings.beginReadArray("notifications"); + for (int i = 0; i < size; i++) { + settings.setArrayIndex(i); + QString id = settings.value("provider").toString().toLower(); + NotificationPluginInterface *plugin = _providers[id]; + if (plugin) { + NotificationProvider *provider = plugin->getProvider(id, settings, server); + server->addProvider(provider); + } + } + + settings.endArray(); } void Daemon::loadWatchlets() diff --git a/sowatchd/daemon.h b/sowatchd/daemon.h index 9346a41..607e887 100644 --- a/sowatchd/daemon.h +++ b/sowatchd/daemon.h @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -18,11 +19,15 @@ public: protected: QMap _drivers; - QList _watches; + QMap _providers; + QList _servers; void loadDrivers(); - void loadWatches(); + void loadProviders(); void loadWatchlets(); + + void initWatches(); + void initWatch(Watch* watch, QSettings& settings); }; } -- cgit v1.2.3