From 9949c02b0f814ad94a27864a5c39689f090299b6 Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 23 Nov 2014 19:53:30 +0100 Subject: port to sailfish with qt 5.2 --- notificationconn.cc | 61 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 11 deletions(-) (limited to 'notificationconn.cc') diff --git a/notificationconn.cc b/notificationconn.cc index fde3303..231427e 100644 --- a/notificationconn.cc +++ b/notificationconn.cc @@ -6,6 +6,10 @@ #include "endianhelpers.h" #include "notificationconn.h" +#if SAILFISH +#include "sailfish/notificationmonitor.h" +#endif + NotificationConn::Notification::Notification() : type(NotificationPopup), sequenceNumber(0), urgent(false), applicationId(0), category(0), @@ -44,7 +48,7 @@ QByteArray NotificationConn::packNotification(const Notification &n) if (!n.body.isEmpty()) attributeCount++; if (!n.thumbnail.isEmpty()) attributeCount++; if (!n.applicationName.isEmpty()) attributeCount++; - //TODO if (n.openInHost) attributeCount++; + // TODO if (n.openInHost) attributeCount++; //if (n.openInWatch) attributeCount++; if (n.notificationId != -1) attributeCount++; @@ -94,12 +98,27 @@ QByteArray NotificationConn::packNotification(const Notification &n) return data; } +void NotificationConn::sendNotification(const Notification &n) +{ + QByteArray packet = packNotification(n); + packet.prepend('\0'); + + qDebug() << packet.toHex(); + + _socket->send(packet); +} + void NotificationConn::handleConnected() { - qDebug() << "Manager socket now connected!"; + qDebug() << "NotificationManager socket now connected!"; +#if SAILFISH + NotificationMonitor *monitor = NotificationMonitor::instance(); + connect(monitor, SIGNAL(incomingNotification(QString,QIcon,QString,int,QString,QDateTime)), + this, SLOT(handleIncomingNotification(QString,QIcon,QString,int,QString,QDateTime))); +#else QTimer::singleShot(2000, this, SLOT(performTest())); - +#endif } void NotificationConn::handleMessageReceived() @@ -112,12 +131,37 @@ void NotificationConn::handleMessageReceived() // TODO Seems that we receive the notification ID that we should act upon. } +void NotificationConn::handleIncomingNotification(const QString &sender, const QIcon &icon, const QString &summary, int count, const QString &body, const QDateTime &dateTime) +{ + short applicationId = _knownSenders.value(sender, 0); + if (!applicationId) { + applicationId = _knownSenders.size() + 1; + _knownSenders.insert(sender, applicationId); + } + + Notification n; + n.sequenceNumber = ++_lastSeqNumber; + n.type = NotificationPopup; + n.time = dateTime; + n.title = summary; + n.packageName = sender; + n.applicationName = sender; + n.body = body; + n.sender = 0; + n.count = 0; // TODO figure this out + n.category = 0; + n.applicationId = applicationId; + n.notificationId = ++_lastNotifId; + + sendNotification(n); +} + void NotificationConn::performTest() { qDebug() << "Performing notif test"; Notification n; - n.sequenceNumber = 1; + n.sequenceNumber = ++_lastSeqNumber; n.type = NotificationPopup; n.time = QDateTime::currentDateTime(); n.title = "A title"; @@ -128,12 +172,7 @@ void NotificationConn::performTest() n.count = 13; n.category = 0; n.applicationId = 0xc2d7; - n.notificationId = 1; + n.notificationId = ++_lastNotifId; - QByteArray packet = packNotification(n); - packet.prepend('\0'); - - qDebug() << packet.toHex(); - - _socket->send(packet); + sendNotification(n); } -- cgit v1.2.3