summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan-Simon Moeller <jsmoeller@linuxfoundation.org>2019-08-20 11:54:37 +0000
committerGerrit Code Review <gerrit@automotivelinux.org>2019-08-20 11:54:37 +0000
commitb2cfff1cd378b9e822c7cfa53fc0dd94d2e9103f (patch)
treef1a86d1a32682398db1a1e32cac027fc538d233a
parent4617d8b63620de9729a07c5d17e8b3113fbb58a3 (diff)
parent9cae4551c16d66a2139b50830749bfcc770ed17c (diff)
Merge "libqtappfw: bluetooth-map: add support for list_messages + message verbs"
-rw-r--r--map/map.cpp33
-rw-r--r--map/map.h4
-rw-r--r--responsemessage.h5
3 files changed, 42 insertions, 0 deletions
diff --git a/map/map.cpp b/map/map.cpp
index eb3d5e0..38f682a 100644
--- a/map/map.cpp
+++ b/map/map.cpp
@@ -46,6 +46,26 @@ void Map::compose(QString recipient, QString message)
delete tmsg;
}
+void Map::message(QString handle)
+{
+ MapMessage *tmsg = new MapMessage();
+ QJsonObject parameter;
+ parameter.insert("handle", handle);
+ tmsg->createRequest("message", parameter);
+ m_mloop->sendMessage(tmsg);
+ delete tmsg;
+}
+
+void Map::listMessages(QString folder)
+{
+ MapMessage *tmsg = new MapMessage();
+ QJsonObject parameter;
+ parameter.insert("folder", folder);
+ tmsg->createRequest("list_messages", parameter);
+ m_mloop->sendMessage(tmsg);
+ delete tmsg;
+}
+
void Map::onConnected()
{
MapMessage *tmsg = new MapMessage();
@@ -54,6 +74,8 @@ void Map::onConnected()
tmsg->createRequest("subscribe", parameter);
m_mloop->sendMessage(tmsg);
delete tmsg;
+
+ listMessages();
}
void Map::onDisconnected()
@@ -74,6 +96,17 @@ void Map::onMessageReceived(MessageType type, Message *msg)
if (tmsg->isNotificationEvent()) {
emit notificationEvent(tmsg->eventData().toVariantMap());
}
+ } else if (msg->isReply() && type == ResponseRequestMessage) {
+ ResponseMessage *tmsg = qobject_cast<ResponseMessage*>(msg);
+
+ if (tmsg->requestVerb() == "list_messages") {
+ QString folder = tmsg->requestParameters().value("folder").toString();
+ QVariantMap listing = tmsg->replyData().value("messages").toObject().toVariantMap();
+ emit listMessagesResult(folder, listing);
+ } else if (tmsg->requestVerb() == "message") {
+ QString handle = tmsg->requestParameters().value("handle").toString();
+ emit messageResult(handle, tmsg->replyData().toVariantMap());
+ }
}
msg->deleteLater();
diff --git a/map/map.h b/map/map.h
index e712b93..c54a250 100644
--- a/map/map.h
+++ b/map/map.h
@@ -34,9 +34,13 @@ class Map : public QObject
virtual ~Map();
Q_INVOKABLE void compose(QString recipient, QString message);
+ Q_INVOKABLE void message(QString handle);
+ Q_INVOKABLE void listMessages(QString folder = "inbox");
signals:
void notificationEvent(QVariantMap message);
+ void listMessagesResult(QString folder, QVariantMap listing);
+ void messageResult(QString handle, QVariantMap message);
private:
MessageEngine *m_mloop;
diff --git a/responsemessage.h b/responsemessage.h
index fd9406a..dd85150 100644
--- a/responsemessage.h
+++ b/responsemessage.h
@@ -32,6 +32,11 @@ class ResponseMessage : public Message
{
return m_request["verb"].toString();
}
+
+ inline QVariantMap requestParameters() const
+ {
+ return m_request["parameter"].toMap();
+ }
};
#endif // RESPONSEMESSAGE_H