summaryrefslogtreecommitdiff
path: root/saltoqd
diff options
context:
space:
mode:
Diffstat (limited to 'saltoqd')
-rw-r--r--saltoqd/cardmanager.cpp17
-rw-r--r--saltoqd/cardmanager.h1
-rw-r--r--saltoqd/notificationmonitor.cpp20
3 files changed, 33 insertions, 5 deletions
diff --git a/saltoqd/cardmanager.cpp b/saltoqd/cardmanager.cpp
index 7465cc4..ab3a0bc 100644
--- a/saltoqd/cardmanager.cpp
+++ b/saltoqd/cardmanager.cpp
@@ -274,28 +274,37 @@ void CardManager::uninstallDeck(CardDeck *deck)
disconnect(deck, 0, this, 0);
}
+QString CardManager::escapeString(const QString &s)
+{
+ QString e(s);
+ e.replace('\\', "\\\\");
+ e.replace('\n', "\\n");
+ e.replace('"', "\\\"");
+ return e;
+}
+
QString CardManager::generateCardDescription(const QString &verb, Card *card) const
{
QString desc = verb + " { ";
desc += QString("id = \"%1\", ").arg(card->id());
desc += QString("version = 2, cardevents = \"true\", ");
if (!card->header().isEmpty()) {
- desc += QString("header = \"%1\", ").arg(card->header());
+ desc += QString("header = \"%1\", ").arg(escapeString(card->header()));
}
if (!card->title().isEmpty()) {
- desc += QString("title = \"%1\", ").arg(card->title());
+ desc += QString("title = \"%1\", ").arg(escapeString(card->title()));
}
if (card->dateTime().isValid()) {
desc += QString("time = \"%1\", ").arg(card->dateTime().toMSecsSinceEpoch());
}
if (!card->info().isEmpty()) {
- desc += QString("info = \"%1\", ").arg(card->info());
+ desc += QString("info = \"%1\", ").arg(escapeString(card->info()));
}
if (!card->isVibrate()) {
desc += QString("suppressvibe = \"true\", ");
}
if (!card->text().isEmpty()) {
- desc += QString("detail = { \"%1\" }").arg(card->text());
+ desc += QString("detail = { \"%1\" }").arg(escapeString(card->text()));
}
desc += QString("}\n");
return desc;
diff --git a/saltoqd/cardmanager.h b/saltoqd/cardmanager.h
index 5162a3b..e4ffc2a 100644
--- a/saltoqd/cardmanager.h
+++ b/saltoqd/cardmanager.h
@@ -132,6 +132,7 @@ public slots:
void uninstallDeck(CardDeck *deck);
private:
+ static QString escapeString(const QString &s);
QString generateCardDescription(const QString &verb, Card * card) const;
QByteArray packMessage(CardDeck *deck, const QString &msg) const;
QPair<CardDeck *, QString> unpackMessage(const QByteArray &data) const;
diff --git a/saltoqd/notificationmonitor.cpp b/saltoqd/notificationmonitor.cpp
index 900b742..107e165 100644
--- a/saltoqd/notificationmonitor.cpp
+++ b/saltoqd/notificationmonitor.cpp
@@ -268,7 +268,21 @@ void NotificationMonitor::processIncomingNotification(quint32 id, const QVariant
qDebug() << "Incoming notification" << id << content;
MonitoredNotification *n = _notifs.value(id, 0);
if (n) {
- // TODO emit changed signals for individual fields
+ QString s = content["summary"].toString();
+ if (n->_summary != s) {
+ n->_summary = s;
+ emit n->summaryChanged();
+ }
+ s = content["body"].toString();
+ if (n->_body != s) {
+ n->_body = s;
+ emit n->bodyChanged();
+ }
+ QDateTime dt = content["timestamp"].toDateTime();
+ if (dt.isValid() && n->_timestamp != dt) {
+ n->_timestamp = dt;
+ emit n->timestampChanged();
+ }
} else {
n = new MonitoredNotification(this);
n->_id = id;
@@ -277,6 +291,10 @@ void NotificationMonitor::processIncomingNotification(quint32 id, const QVariant
n->_body = content["body"].toString();
n->_timestamp = content["timestamp"].toDateTime();
+ if (!n->_timestamp.isValid()) {
+ n->_timestamp = QDateTime::currentDateTime();
+ }
+
_notifs.insert(id, n);
emit notification(n);