summaryrefslogtreecommitdiff
path: root/meegohandsetnotification
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-09-24 20:52:17 +0200
committerJavier S. Pedro <maemo@javispedro.com>2011-09-24 20:52:17 +0200
commita1ec50943454ba4674c8c5e5d5dadcdbd414b111 (patch)
tree163aed51758c98fa6feec35a344aa8b5095c32e5 /meegohandsetnotification
parentcba26597f1c09764d37be0d13863ec5d5c340da0 (diff)
downloadsowatch-a1ec50943454ba4674c8c5e5d5dadcdbd414b111.tar.gz
sowatch-a1ec50943454ba4674c8c5e5d5dadcdbd414b111.zip
Incoming phone calls working!
Diffstat (limited to 'meegohandsetnotification')
-rw-r--r--meegohandsetnotification/meegohandsetnotification.cpp61
-rw-r--r--meegohandsetnotification/meegohandsetnotification.h37
-rw-r--r--meegohandsetnotification/meegohandsetnotification.pro8
-rw-r--r--meegohandsetnotification/meegohandsetnotificationprovider.cpp19
-rw-r--r--meegohandsetnotification/meegohandsetnotificationprovider.h4
-rw-r--r--meegohandsetnotification/watchnotificationsink.cpp67
-rw-r--r--meegohandsetnotification/watchnotificationsink.h15
7 files changed, 126 insertions, 85 deletions
diff --git a/meegohandsetnotification/meegohandsetnotification.cpp b/meegohandsetnotification/meegohandsetnotification.cpp
new file mode 100644
index 0000000..69e2bd5
--- /dev/null
+++ b/meegohandsetnotification/meegohandsetnotification.cpp
@@ -0,0 +1,61 @@
+#include "meegohandsetnotification.h"
+
+MeegoHandsetNotification::MeegoHandsetNotification(const ::Notification& n, QObject *parent) :
+ sowatch::Notification(parent), _n(n)
+{
+}
+
+sowatch::Notification::Type MeegoHandsetNotification::type() const
+{
+ QString eventType = _n.parameters().value("eventType").toString();
+ 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 if (eventType == "x-nokia.messaging.sms")
+ return sowatch::Notification::SmsNotification;
+ else if (eventType == "x-nokia.messaging.mms")
+ return sowatch::Notification::MmsNotification;
+ else
+ return sowatch::Notification::OtherNotification;
+}
+
+uint MeegoHandsetNotification::count() const
+{
+ return _n.parameters().value("count").toUInt();
+}
+
+QDateTime MeegoHandsetNotification::dateTime() const
+{
+ const uint timestamp = _n.parameters().value("timestamp").toUInt();
+ return QDateTime::fromTime_t(timestamp);
+}
+
+QString MeegoHandsetNotification::title() const
+{
+ return _n.parameters().value("summary").toString();
+}
+
+QString MeegoHandsetNotification::body() const
+{
+ return _n.parameters().value("body").toString();
+}
+
+void MeegoHandsetNotification::activate()
+{
+ // TODO Actually do something
+}
+
+void MeegoHandsetNotification::clear()
+{
+ // TODO Actually clear...
+ emit cleared();
+}
+
+void MeegoHandsetNotification::changeTo(const ::Notification &notification)
+{
+ _n = notification;
+ emit changed();
+}
diff --git a/meegohandsetnotification/meegohandsetnotification.h b/meegohandsetnotification/meegohandsetnotification.h
new file mode 100644
index 0000000..fc9d50f
--- /dev/null
+++ b/meegohandsetnotification/meegohandsetnotification.h
@@ -0,0 +1,37 @@
+#ifndef MEEGOHANDSETNOTIFICATION_H
+#define MEEGOHANDSETNOTIFICATION_H
+
+#include <sowatch.h>
+#include <notificationsystem/notification.h>
+#include <notificationsystem/notificationparameters.h>
+
+class WatchNotificationSink;
+
+class MeegoHandsetNotification : public sowatch::Notification
+{
+ Q_OBJECT
+public:
+ explicit MeegoHandsetNotification(const ::Notification& n, QObject *parent = 0);
+
+ Type type() const;
+ uint count() const;
+ QDateTime dateTime() const;
+ QString title() const;
+ QString body() const;
+ void activate();
+ void clear();
+
+signals:
+ void changed();
+ void cleared();
+
+protected:
+ void changeTo(const ::Notification& notification);
+
+protected:
+ ::Notification _n;
+
+friend class WatchNotificationSink;
+};
+
+#endif // MEEGOHANDSETNOTIFICATION_H
diff --git a/meegohandsetnotification/meegohandsetnotification.pro b/meegohandsetnotification/meegohandsetnotification.pro
index 424eb33..e553178 100644
--- a/meegohandsetnotification/meegohandsetnotification.pro
+++ b/meegohandsetnotification/meegohandsetnotification.pro
@@ -13,12 +13,14 @@ QT += dbus
SOURCES += meegohandsetplugin.cpp \
meegohandsetnotificationprovider.cpp \
watchnotificationsink.cpp \
- mnotificationmanagerinterface.cpp
+ mnotificationmanagerinterface.cpp \
+ meegohandsetnotification.cpp
HEADERS += meegohandsetplugin.h \
meegohandsetnotificationprovider.h \
watchnotificationsink.h \
- mnotificationmanagerinterface.h
+ mnotificationmanagerinterface.h \
+ meegohandsetnotification.h
CONFIG += notificationsystem
@@ -43,3 +45,5 @@ unix:!symbian {
+
+
diff --git a/meegohandsetnotification/meegohandsetnotificationprovider.cpp b/meegohandsetnotification/meegohandsetnotificationprovider.cpp
index fc84e46..0297ebb 100644
--- a/meegohandsetnotification/meegohandsetnotificationprovider.cpp
+++ b/meegohandsetnotification/meegohandsetnotificationprovider.cpp
@@ -22,10 +22,8 @@ MeegoHandsetNotificationProvider::MeegoHandsetNotificationProvider(QObject *pare
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)));
+ connect(_sink, SIGNAL(incomingNotification(sowatch::Notification*)),
+ SLOT(newNotification(sowatch::Notification*)));
_manager->registerSink("com.javispedro.sowatch.MeegoHandsetNotificationSink", "/meegohandsetnotificationsink");
}
@@ -35,17 +33,8 @@ 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)
+void MeegoHandsetNotificationProvider::newNotification(Notification* n)
{
- emit unreadCountChanged(type);
+ emit incomingNotification(n);
}
diff --git a/meegohandsetnotification/meegohandsetnotificationprovider.h b/meegohandsetnotification/meegohandsetnotificationprovider.h
index 3cf78d3..f98f226 100644
--- a/meegohandsetnotification/meegohandsetnotificationprovider.h
+++ b/meegohandsetnotification/meegohandsetnotificationprovider.h
@@ -16,14 +16,12 @@ 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);
+ void newNotification(sowatch::Notification *n);
friend class WatchNoficationSink;
};
diff --git a/meegohandsetnotification/watchnotificationsink.cpp b/meegohandsetnotification/watchnotificationsink.cpp
index c80c4ae..cf03c30 100644
--- a/meegohandsetnotification/watchnotificationsink.cpp
+++ b/meegohandsetnotification/watchnotificationsink.cpp
@@ -2,50 +2,33 @@
#include "watchnotificationsink.h"
WatchNotificationSink::WatchNotificationSink(sowatch::MeegoHandsetNotificationProvider *parent) :
- NotificationSink(parent), _parent(parent)
+ NotificationSink(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());
- const uint count = p.value("count").toUInt();
const uint notificationId = notification.notificationId();
if (_trackedNotifications.contains(notificationId)) {
- const NotificationParameters& oldParams = _trackedNotifications[notificationId].parameters();
- _counts[type] -= oldParams.value("count").toUInt();
- }
-
- _counts[type] += count;
- _trackedNotifications[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);
+ MeegoHandsetNotification* n = _trackedNotifications[notificationId];
+ n->changeTo(notification);
+ } else {
+ MeegoHandsetNotification* n = new MeegoHandsetNotification(notification, this);
+ _trackedNotifications[notificationId] = n;
+ emit incomingNotification(static_cast<sowatch::Notification*>(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);
+ if (_trackedNotifications.contains(notificationId)) {
+ MeegoHandsetNotification* n = _trackedNotifications[notificationId];
+ _trackedNotifications.remove(notificationId);
+ n->clear();
+ n->deleteLater();
+ }
}
void WatchNotificationSink::addGroup(uint groupId, const NotificationParameters &parameters)
@@ -59,25 +42,3 @@ 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)
-{
- qDebug() << "incoming " << 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 if (eventType == "x-nokia.messaging.sms")
- return sowatch::Notification::SmsNotification;
- else if (eventType == "x-nokia.messaging.mms")
- return sowatch::Notification::MmsNotification;
- else
- return sowatch::Notification::OtherNotification;
-}
diff --git a/meegohandsetnotification/watchnotificationsink.h b/meegohandsetnotification/watchnotificationsink.h
index dc586a2..9500994 100644
--- a/meegohandsetnotification/watchnotificationsink.h
+++ b/meegohandsetnotification/watchnotificationsink.h
@@ -3,9 +3,8 @@
#include <QtCore/QMap>
#include <sowatch.h>
-#include <notificationsystem/notification.h>
+#include "meegohandsetnotification.h"
#include <notificationsystem/notificationsink.h>
-#include <notificationsystem/notificationparameters.h>
namespace sowatch {
class MeegoHandsetNotificationProvider;
@@ -23,19 +22,11 @@ public:
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);
+ void incomingNotification(sowatch::Notification* notification);
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];
+ QMap<uint, MeegoHandsetNotification*> _trackedNotifications;
};
#endif // WATCHNOTIFICATIONSINK_H