summaryrefslogtreecommitdiff
path: root/meegohandsetnotification
diff options
context:
space:
mode:
Diffstat (limited to 'meegohandsetnotification')
-rw-r--r--meegohandsetnotification/meegohandsetnotification.pro45
-rw-r--r--meegohandsetnotification/meegohandsetnotificationprovider.cpp51
-rw-r--r--meegohandsetnotification/meegohandsetnotificationprovider.h33
-rw-r--r--meegohandsetnotification/meegohandsetplugin.cpp28
-rw-r--r--meegohandsetnotification/meegohandsetplugin.h24
-rw-r--r--meegohandsetnotification/mnotificationmanagerinterface.cpp14
-rw-r--r--meegohandsetnotification/mnotificationmanagerinterface.h56
-rw-r--r--meegohandsetnotification/watchnotificationsink.cpp72
-rw-r--r--meegohandsetnotification/watchnotificationsink.h41
9 files changed, 364 insertions, 0 deletions
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 <QtDBus/QDBusConnection>
+#include <notificationsystem/metatypedeclarations.h>
+#include <notificationsystem/notificationsinkadaptor.h>
+#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<QList< ::Notification > >();
+ qDBusRegisterMetaType<NotificationGroup>();
+ qDBusRegisterMetaType<QList<NotificationGroup> >();
+ qDBusRegisterMetaType<NotificationParameters>();
+
+ 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 <sowatch.h>
+
+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 <sowatch.h>
+
+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 <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+
+/*
+ * 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<QVariant> argumentList;
+ argumentList << qVariantFromValue(service) << qVariantFromValue(path);
+ return asyncCallWithArgumentList(QLatin1String("registerSink"), argumentList);
+ }
+
+ inline QDBusPendingReply<> unregisterSink(const QString &service, const QString &path)
+ {
+ QList<QVariant> 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 &notification)
+{
+ 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 &parameters)
+{
+ // 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 <QtCore/QMap>
+#include <sowatch.h>
+#include <notificationsystem/notification.h>
+#include <notificationsystem/notificationsink.h>
+#include <notificationsystem/notificationparameters.h>
+
+namespace sowatch {
+ class MeegoHandsetNotificationProvider;
+}
+
+class WatchNotificationSink : public NotificationSink
+{
+ Q_OBJECT
+public:
+ explicit WatchNotificationSink(sowatch::MeegoHandsetNotificationProvider* parent);
+
+ void addNotification(const Notification &notification);
+ void removeNotification(uint notificationId);
+
+ void addGroup(uint groupId, const NotificationParameters &parameters);
+ 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<uint, Notification> _trackedNotifications;
+ uint _counts[maxTypes];
+};
+
+#endif // WATCHNOTIFICATIONSINK_H