summaryrefslogtreecommitdiff
path: root/daemon/watchconnector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/watchconnector.cpp')
-rw-r--r--daemon/watchconnector.cpp136
1 files changed, 70 insertions, 66 deletions
diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp
index 5f15ee6..4ed8130 100644
--- a/daemon/watchconnector.cpp
+++ b/daemon/watchconnector.cpp
@@ -10,6 +10,7 @@
#include "unpacker.h"
#include "watchconnector.h"
+#include "timelineitem.h"
static const int RECONNECT_TIMEOUT = 500; //ms
static const bool PROTOCOL_DEBUG = false;
@@ -600,7 +601,6 @@ QString WatchConnector::timeStamp()
void WatchConnector::sendNotification(uint lead, QString sender, QString data, QString subject)
{
- qCDebug(l) << _versions.main.version;
if (_versions.main.version < "v3.0") {
QStringList tmp;
tmp.append(sender);
@@ -613,80 +613,71 @@ void WatchConnector::sendNotification(uint lead, QString sender, QString data, Q
sendMessage(watchNOTIFICATION, res);
}
else {
- int source;
+ TimelineAttribute::IconID iconId = TimelineAttribute::IconIDDefaultBell;
+ TimelineAttribute::Color color = TimelineAttribute::ColorRed;
+ QString muteName;
switch (lead) {
- case leadEMAIL:
- source = 19;
- break;
case leadFACEBOOK:
- source = 11;
+ iconId = TimelineAttribute::IconIDFacebook;
+ color = TimelineAttribute::ColorBlue;
+ muteName = "facebook";
break;
- case leadSMS:
- source = 45;
+ case leadHANGOUTS:
+ iconId = TimelineAttribute::IconIDHangout;
+ color = TimelineAttribute::ColorGreen;
+ muteName = "Hangout";
+ break;
+ case leadMISSEDCALL:
+ iconId = TimelineAttribute::IconIDDefaultMissedCall;
+ muteName = "call notifications";
+ break;
+ case leadTELEGRAM:
+ iconId = TimelineAttribute::IconIDTelegram;
+ color = TimelineAttribute::ColorLightBlue;
+ muteName = "Telegram";
break;
case leadTWITTER:
- source = 6;
+ iconId = TimelineAttribute::IconIDTwitter;
+ color = TimelineAttribute::ColorBlue2;
+ muteName = "Twitter";
+ break;
+ case leadWHATSAPP:
+ iconId = TimelineAttribute::IconIDWhatsApp;
+ color = TimelineAttribute::ColorGreen;
+ muteName = "WhatsApp";
break;
+ case leadSMS:
+ muteName = "SMS";
+ iconId = TimelineAttribute::IconIDDefaultBell;
+ break;
+ case leadEMAIL:
default:
- source = 1;
+ muteName = "e mails";
+ iconId = TimelineAttribute::IconIDDefaultBell;
+ break;
}
- int attributesCount = 0;
- QByteArray attributes;
-
- attributesCount++;
- QByteArray senderBytes = sender.left(64).toUtf8();
- attributes.append(0x01); // id = title
- attributes.append(senderBytes.length() & 0xFF); attributes.append(((senderBytes.length() >> 8) & 0xFF)); // length
- attributes.append(senderBytes); // content
-
- attributesCount++;
- QByteArray subjectBytes = (subject.isEmpty() ? data : subject).left(64).toUtf8();
- attributes.append(0x02); // id = subtitle
- attributes.append(subjectBytes.length() & 0xFF); attributes.append((subjectBytes.length() >> 8) & 0xFF); // length
- attributes.append(subjectBytes); //content
-
- if (!data.isEmpty()) {
- attributesCount++;
- QByteArray dataBytes = data.left(512).toUtf8();
- attributes.append(0x03); // id = body
- attributes.append(dataBytes.length() & 0xFF); attributes.append((dataBytes.length() >> 8) & 0xFF); // length
- attributes.append(dataBytes); // content
- }
+ QUuid itemUuid = QUuid::createUuid();
+ TimelineItem timelineItem(itemUuid, TimelineItem::TypeNotification);
+ timelineItem.setFlags(TimelineItem::FlagSingleEvent);
+
+ TimelineAttribute titleAttribute(TimelineAttribute::TypeTitle, sender.left(64).toUtf8());
+ timelineItem.appendAttribute(titleAttribute);
+
+ TimelineAttribute subjectAttribute(TimelineAttribute::TypeSubtitle, subject.left(64).toUtf8());
+ timelineItem.appendAttribute(subjectAttribute);
- attributesCount++;
- attributes.append(0x04); // id = tinyicon
- attributes.append(0x04); attributes.append('\0'); // length
- attributes.append(source); attributes.append('\0'); attributes.append('\0'); attributes.append('\0'); // content
-
-
- QByteArray actions;
- actions.append('\0'); // action id
- actions.append(0x04); // type = dismiss
- actions.append(0x01); // attributes length = 1
- actions.append(0x01); // attribute id = title
- actions.append(0x07); actions.append('\0'); // attribute length
- actions.append("Dismiss"); // attribute content
-
-
- QByteArray itemId = QUuid::createUuid().toRfc4122();
- int time = QDateTime::currentMSecsSinceEpoch() / 1000;
- QByteArray item;
- item.append(itemId); // item id
- item.append(QUuid().toRfc4122()); // parent id
- item.append(time & 0xFF); item.append((time >> 8) & 0xFF); item.append((time >> 16) & 0xFF); item.append((time >> 24) & 0xFF); // timestamp
- item.append('\0'); item.append('\0'); // duration
- item.append(0x01); // type: notification
- item.append('\0'); item.append('\0'); // flags
- item.append(0x01); // layout
-
- int length = attributes.length() + actions.length();
- item.append(length & 0xFF); item.append((length >> 8) & 0xFF); // data length
- item.append(attributesCount); // attributes count
- item.append(0x01); // actions count
- item.append(attributes);
- item.append(actions);
+ TimelineAttribute bodyAttribute(TimelineAttribute::TypeBody, data.toUtf8());
+ timelineItem.appendAttribute(bodyAttribute);
+ TimelineAttribute iconAttribute(TimelineAttribute::TypeTinyIcon, iconId);
+ timelineItem.appendAttribute(iconAttribute);
+
+ TimelineAttribute colorAttribute(TimelineAttribute::TypeColor, color);
+ timelineItem.appendAttribute(colorAttribute);
+
+ QByteArray item = timelineItem.serialize();
+ QByteArray itemId = itemUuid.toRfc4122();
int token = (qrand() % ((int)pow(2, 16) - 2)) + 1;
QByteArray blob;
blob.append(0x01); // command = insert
@@ -696,10 +687,8 @@ void WatchConnector::sendNotification(uint lead, QString sender, QString data, Q
blob.append(itemId); // key
blob.append(item.length() & 0xFF); blob.append((item.length() >> 8) & 0xFF); // value length
blob.append(item);
-
sendMessage(watchBLOB_DB, blob);
}
-
}
void WatchConnector::sendSMSNotification(QString sender, QString data)
@@ -722,6 +711,21 @@ void WatchConnector::sendEmailNotification(QString sender, QString data, QString
sendNotification(leadEMAIL, sender, data, subject);
}
+void WatchConnector::sendWhatsappNotification(QString sender, QString data)
+{
+ sendNotification(leadWHATSAPP, sender, data, "");
+}
+
+void WatchConnector::sendTelegramNotification(QString sender, QString data)
+{
+ sendNotification(leadTELEGRAM, sender, data, "");
+}
+
+void WatchConnector::sendHangoutsNotification(QString sender, QString data)
+{
+ sendNotification(leadHANGOUTS, sender, data, "");
+}
+
void WatchConnector::sendMusicNowPlaying(QString artist, QString album, QString track)
{
QStringList tmp;