diff options
| author | Robert Meijers <robert@r-meijers.nl> | 2015-09-12 19:58:17 +0200 |
|---|---|---|
| committer | Robert Meijers <robert@r-meijers.nl> | 2015-09-13 18:32:53 +0200 |
| commit | 422e53d6d59252af50da871cfc2b66aaca6cdfe4 (patch) | |
| tree | 57bf3c35744131167114eceea69e4531e8fb8b3a | |
| parent | e5281e2df962fc6b9a6e59d7d106fe0cdc571fb2 (diff) | |
implement sending notification to Pebble Time timeline
Fixes #82
| -rw-r--r-- | daemon/watchconnector.cpp | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index e0ff89a..938c047 100644 --- a/daemon/watchconnector.cpp +++ b/daemon/watchconnector.cpp @@ -598,7 +598,91 @@ void WatchConnector::sendNotification(uint lead, QString sender, QString data, Q } break; case BASALT: { - qCWarning(l) << "Tried sending notification to unsupported watch platform" << lead << sender << data << subject; + int source; + switch (lead) { + case leadEMAIL: + source = 19; + break; + case leadFACEBOOK: + source = 11; + break; + case leadSMS: + source = 45; + break; + case leadTWITTER: + source = 6; + break; + default: + source = 1; + } + + 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 + } + + 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); + + int token = (qrand() % ((int)pow(2, 16) - 2)) + 1; + QByteArray blob; + blob.append(0x01); // command = insert + blob.append(token & 0xFF); blob.append((token >> 8) & 0xFF); // token + blob.append(0x04); //database id = notification + blob.append(itemId.length() & 0xFF); // key length + blob.append(itemId); // key + blob.append(item.length() & 0xFF); blob.append((item.length() >> 8) & 0xFF); // value length + blob.append(item); + + sendMessage(watchBLOB_DB, blob); } break; default: |
