From 77a98ac21c2520d9fb4bb9c8f70967a8e36dc872 Mon Sep 17 00:00:00 2001
From: "Javier S. Pedro" <maemo@javispedro.com>
Date: Mon, 19 Sep 2011 01:51:04 +0200
Subject: adding notification provider plugins, idle screen

---
 .../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 ++++++++++++
 9 files changed, 364 insertions(+)
 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

(limited to 'meegohandsetnotification')

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
-- 
cgit v1.2.3