diff options
author | Javier <dev.git@javispedro.com> | 2014-11-23 19:53:30 +0100 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2014-11-23 19:53:30 +0100 |
commit | 9949c02b0f814ad94a27864a5c39689f090299b6 (patch) | |
tree | 90e2893d5aafc14a020754eaf72a2df99e373efb /notificationconn.cc | |
parent | 5244f7909e04b23fbd5706dc6bcadafba21f7600 (diff) | |
download | sapd-9949c02b0f814ad94a27864a5c39689f090299b6.tar.gz sapd-9949c02b0f814ad94a27864a5c39689f090299b6.zip |
port to sailfish with qt 5.2
Diffstat (limited to 'notificationconn.cc')
-rw-r--r-- | notificationconn.cc | 61 |
1 files changed, 50 insertions, 11 deletions
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); } |