From 51701e30d710ad016ddf2d306cdd7be122ddf25b Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 11 Aug 2012 15:30:38 +0200 Subject: adding test notification backend --- testnotification/testnotification.cpp | 48 +++++++++++++++++++++++++++ testnotification/testnotification.h | 34 +++++++++++++++++++ testnotification/testnotification.pro | 25 ++++++++++++++ testnotification/testnotificationplugin.cpp | 39 ++++++++++++++++++++++ testnotification/testnotificationplugin.h | 25 ++++++++++++++ testnotification/testnotificationprovider.cpp | 34 +++++++++++++++++++ testnotification/testnotificationprovider.h | 29 ++++++++++++++++ 7 files changed, 234 insertions(+) create mode 100644 testnotification/testnotification.cpp create mode 100644 testnotification/testnotification.h create mode 100644 testnotification/testnotification.pro create mode 100644 testnotification/testnotificationplugin.cpp create mode 100644 testnotification/testnotificationplugin.h create mode 100644 testnotification/testnotificationprovider.cpp create mode 100644 testnotification/testnotificationprovider.h (limited to 'testnotification') diff --git a/testnotification/testnotification.cpp b/testnotification/testnotification.cpp new file mode 100644 index 0000000..fa904b9 --- /dev/null +++ b/testnotification/testnotification.cpp @@ -0,0 +1,48 @@ +#include "testnotification.h" + +using namespace sowatch; + +TestNotification::TestNotification(Type type, const QString &title, const QString &body, QObject *parent) + : Notification(parent), + _type(type), + _time(QDateTime::currentDateTime()), + _title(title), _body(body) +{ +} + +Notification::Type TestNotification::type() const +{ + return _type; +} + +uint TestNotification::count() const +{ + return 1; +} + +QDateTime TestNotification::dateTime() const +{ + return _time; +} + +QString TestNotification::title() const +{ + return _title; +} + +QString TestNotification::body() const +{ + return _body; +} + +void TestNotification::activate() +{ + // Do nothing +} + +void TestNotification::dismiss() +{ + deleteLater(); // We do not want to keep those around. +} + + diff --git a/testnotification/testnotification.h b/testnotification/testnotification.h new file mode 100644 index 0000000..f54623d --- /dev/null +++ b/testnotification/testnotification.h @@ -0,0 +1,34 @@ +#ifndef TESTNOTIFICATION_H +#define TESTNOTIFICATION_H + +#include + +namespace sowatch +{ + +class TestNotification : public Notification +{ + Q_OBJECT + +public: + explicit TestNotification(Type type, const QString& title, const QString& body, QObject *parent = 0); + + Type type() const; + uint count() const; + QDateTime dateTime() const; + QString title() const; + QString body() const; + + void activate(); + void dismiss(); + +private: + Type _type; + QDateTime _time; + QString _title; + QString _body; +}; + +} + +#endif // TESTNOTIFICATION_H diff --git a/testnotification/testnotification.pro b/testnotification/testnotification.pro new file mode 100644 index 0000000..525fdac --- /dev/null +++ b/testnotification/testnotification.pro @@ -0,0 +1,25 @@ +TARGET = testnotification +TEMPLATE = lib +CONFIG += plugin +CONFIG += mobility +MOBILITY += systeminfo + +SOURCES += testnotificationplugin.cpp testnotificationprovider.cpp \ + testnotification.cpp + +HEADERS += testnotificationplugin.h testnotificationprovider.h \ + testnotification.h + +unix: LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch +INCLUDEPATH += $$PWD/../libsowatch +DEPENDPATH += $$PWD/../libsowatch + +unix { + !isEmpty(MEEGO_VERSION_MAJOR)|maemo5 { + QMAKE_RPATHDIR += /opt/sowatch/lib + target.path = /opt/sowatch/lib/notifications + } else { + target.path = /usr/lib/sowatch/notifications + } + INSTALLS += target +} diff --git a/testnotification/testnotificationplugin.cpp b/testnotification/testnotificationplugin.cpp new file mode 100644 index 0000000..7e65851 --- /dev/null +++ b/testnotification/testnotificationplugin.cpp @@ -0,0 +1,39 @@ +#include "testnotificationprovider.h" +#include "testnotificationplugin.h" + +using namespace sowatch; + +static const QLatin1String providerId("testnotification"); + +TestNotificationPlugin::TestNotificationPlugin(QObject *parent) : + QObject(parent) +{ +} + +TestNotificationPlugin::~TestNotificationPlugin() +{ +} + +QStringList TestNotificationPlugin::providers() +{ + QStringList providers; + providers << providerId; + return providers; +} + +NotificationPluginInterface::NotificationProviderInfo TestNotificationPlugin::describeProvider(const QString &driver) +{ + NotificationProviderInfo info; + if (driver != providerId) return info; + info.name = "Test notifications"; + return info; +} + +NotificationProvider* TestNotificationPlugin::getProvider(const QString& id, ConfigKey *settings, QObject *parent) +{ + Q_UNUSED(settings); + if (id != providerId) return 0; + return new TestNotificationProvider(parent); +} + +Q_EXPORT_PLUGIN2(testnotification, TestNotificationPlugin) diff --git a/testnotification/testnotificationplugin.h b/testnotification/testnotificationplugin.h new file mode 100644 index 0000000..03ebb30 --- /dev/null +++ b/testnotification/testnotificationplugin.h @@ -0,0 +1,25 @@ +#ifndef TESTNOTIFICATIONPLUGIN_H +#define TESTNOTIFICATIONPLUGIN_H + +#include + +namespace sowatch +{ + +class TestNotificationPlugin : public QObject, public NotificationPluginInterface +{ + Q_OBJECT + Q_INTERFACES(sowatch::NotificationPluginInterface) + +public: + TestNotificationPlugin(QObject *parent = 0); + ~TestNotificationPlugin(); + + QStringList providers(); + NotificationProviderInfo describeProvider(const QString &driver); + NotificationProvider* getProvider(const QString& driver, ConfigKey *settings, QObject *parent = 0); +}; + +} + +#endif // TESTNOTIFICATIONPLUGIN_H diff --git a/testnotification/testnotificationprovider.cpp b/testnotification/testnotificationprovider.cpp new file mode 100644 index 0000000..960f450 --- /dev/null +++ b/testnotification/testnotificationprovider.cpp @@ -0,0 +1,34 @@ +#include "testnotification.h" +#include "testnotificationprovider.h" + +using namespace sowatch; + +TestNotificationProvider::TestNotificationProvider(QObject *parent) : + NotificationProvider(parent), + _timer(new QTimer(this)) +{ + QTimer::singleShot(15000, this, SLOT(generateInitialNotification())); + connect(_timer, SIGNAL(timeout()), SLOT(generateNotification())); + _timer->setInterval(60000); + _timer->start(); +} + +TestNotificationProvider::~TestNotificationProvider() +{ +} + +void TestNotificationProvider::generateInitialNotification() +{ + TestNotification *n = new TestNotification(Notification::EmailNotification, + "A friend", + "This is a test email notification"); + emit incomingNotification(n); +} + +void TestNotificationProvider::generateNotification() +{ + TestNotification *n = new TestNotification(Notification::ImNotification, + "A friend", + "I will keep talking to you"); + emit incomingNotification(n); +} diff --git a/testnotification/testnotificationprovider.h b/testnotification/testnotificationprovider.h new file mode 100644 index 0000000..9931ea0 --- /dev/null +++ b/testnotification/testnotificationprovider.h @@ -0,0 +1,29 @@ +#ifndef TESTNOTIFICATIONPROVIDER_H +#define TESTNOTIFICATIONPROVIDER_H + +#include + +namespace sowatch +{ + +class TestNotification; + +class TestNotificationProvider : public NotificationProvider +{ + Q_OBJECT + +public: + explicit TestNotificationProvider(QObject *parent = 0); + ~TestNotificationProvider(); + +private slots: + void generateInitialNotification(); + void generateNotification(); + +private: + QTimer *_timer; +}; + +} + +#endif // TESTNOTIFICATIONPROVIDER_H -- cgit v1.2.3