summaryrefslogtreecommitdiffstats
path: root/pbap
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2019-05-15 22:39:55 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2019-05-16 14:22:35 +0000
commitfa307bc84a2aaaebaf9cff5fa26c2ccf9448d4ab (patch)
tree27291af07f9ad8a3277b234f488290df6e6e5382 /pbap
parentb95b16f5fe5671de805403b8067367e5de3044bc (diff)
libqtappfw: pbap: switch to vcard processing done in binding
agl-service-bluetooth-pbap now outputs JSON data of processed vCard information, and now libvcard is no longer needed. Bug-AGL: SPEC-2392 Change-Id: Ice1ec6e1a22687f4839fd3e8a286d279d8a4f586 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'pbap')
-rw-r--r--pbap/pbap.cpp111
-rw-r--r--pbap/pbap.h4
2 files changed, 39 insertions, 76 deletions
diff --git a/pbap/pbap.cpp b/pbap/pbap.cpp
index df1c622..bdd2bd9 100644
--- a/pbap/pbap.cpp
+++ b/pbap/pbap.cpp
@@ -18,8 +18,6 @@
#include <QMimeDatabase>
#include <QtQml/QQmlEngine>
-#include <vcard/vcard.h>
-
#include "message.h"
#include "messageengine.h"
#include "pbap.h"
@@ -149,56 +147,32 @@ bool compareContactPtr(QObject *a, QObject *b)
return (*contactA < *contactB);
}
-void Pbap::updateContacts(QString vcards)
+void Pbap::updateContacts(QJsonArray vcards)
{
- QString name, number, type;
-
m_contacts.clear();
- QList<vCard> contacts_vcards = vCard::fromByteArray(vcards.toUtf8());
-
- for (auto vcard : contacts_vcards) {
- vCardProperty name_prop = vcard.property(VC_FORMATTED_NAME);
- QStringList values = name_prop.values();
- name = values.at(vCardProperty::DefaultValue);
- if (name.isEmpty() || name.startsWith('#'))
- continue;
- /*
- * libvcard has no member function to return a list of named
- * properties, so we iterate over all properties and parse
- * each identified VC_TELEPHONE property in the vCard.
- */
+ for (auto vcard : vcards) {
+ QJsonObject entry = vcard.toObject();
+ QString image;
+
+ QString name = entry.value("fn").toString();
QList<PhoneNumber *> numbers;
- QString photo;
- vCardPropertyList properties = vcard.properties();
- for (auto property : properties) {
- QStringList values;
-
- if (!property.isValid())
- continue;
-
- values = property.values();
-
- if (property.name() == VC_TELEPHONE) {
- number = values.at(0);
- // Telephone entry can be empty
- if (number.isEmpty())
- continue;
- vCardParamList params = property.params();
- // The first parameter is always the phone number type, but is optional
- if (params.length())
- type = params.at(0).value();
- else
- type = "";
- numbers.append(new PhoneNumber(number, type));
- } else if (property.name() == VC_PHOTO) {
- QMimeDatabase db;
- QMimeType type = db.mimeTypeForData(QByteArray::fromBase64(values.at(0).toLocal8Bit()));
- photo = "data:" + type.name() + ";base64," + values.at(0);
- }
+
+ for (auto number: entry.value("telephone").toArray()) {
+ QString type = number.toObject().keys().at(0);
+ QString tel = number.toObject().value(type).toString();
+ numbers.append(new PhoneNumber(tel, type));
+ }
+
+ if (entry.contains("photo")) {
+ QJsonObject photo = entry.value("photo").toObject();
+ QString mimetype = photo.value("mimetype").toString();
+ QString mimedata = photo.value("data").toString();
+ image = "data:" + mimetype + ";base64," + mimedata;
}
+
if (!numbers.isEmpty())
- m_contacts.append(new Contact(name, photo, numbers));
+ m_contacts.append(new Contact(name, image, numbers));
}
std::sort(m_contacts.begin(), m_contacts.end(), compareContactPtr);
@@ -209,25 +183,16 @@ void Pbap::updateContacts(QString vcards)
refreshCalls(100);
}
-#define VC_DATETIME "X-IRMC-CALL-DATETIME"
-
-void Pbap::updateCalls(QString vcards)
+void Pbap::updateCalls(QJsonArray vcards)
{
QString name, number, datetime, type;
m_calls.clear();
- QList<vCard> history_vcards = vCard::fromByteArray(vcards.toUtf8());
-
- for (auto vcard : history_vcards) {
- vCardProperty number_prop = vcard.property(VC_TELEPHONE);
- if (number_prop.isValid()) {
- QStringList values = number_prop.values();
- number = values.at(0);
- }
- vCardProperty name_prop = vcard.property(VC_FORMATTED_NAME);
- QStringList values = name_prop.values();
- name = values.at(0);
+ for (auto vcard : vcards) {
+ QJsonObject entry = vcard.toObject();
+ name = entry.value("fn").toString();
+ number = entry.value("telephone").toString();
// For calls with an empty name, fetch the name from contacts
if (name.isEmpty()) {
bool found = false;
@@ -247,18 +212,16 @@ void Pbap::updateCalls(QString vcards)
if (!found)
name = number;
}
- vCardProperty datetime_prop = vcard.property(VC_DATETIME);
- if (datetime_prop.isValid()) {
- vCardParamList params = datetime_prop.params();
- QStringList values = datetime_prop.values();
- type = params.at(0).value();
- datetime = values.at(0);
- // Convert the PBAP date/time to ISO 8601 format
- datetime.insert(4, '-');
- datetime.insert(7, '-');
- datetime.insert(13, ':');
- datetime.insert(16, ':');
- }
+
+ type = entry.value("type").toString();
+ datetime = entry.value("timestamp").toString();
+
+ // Convert the PBAP date/time to ISO 8601 format
+ datetime.insert(4, '-');
+ datetime.insert(7, '-');
+ datetime.insert(13, ':');
+ datetime.insert(16, ':');
+
m_calls.append(new RecentCall(name, number, datetime, type));
}
@@ -323,9 +286,9 @@ void Pbap::onMessageReceived(MessageType type, Message *msg)
ResponseMessage *tmsg = qobject_cast<ResponseMessage*>(msg);
if (tmsg->requestVerb() == "contacts") {
- updateContacts(tmsg->replyData().value("vcards").toString());
+ updateContacts(tmsg->replyData().value("vcards").toArray());
} else if (tmsg->requestVerb() == "history") {
- updateCalls(tmsg->replyData().value("vcards").toString());
+ updateCalls(tmsg->replyData().value("vcards").toArray());
} else if (tmsg->requestVerb() == "search") {
sendSearchResults(tmsg->replyData().value("results").toArray());
}
diff --git a/pbap/pbap.h b/pbap/pbap.h
index 15cf2d4..4d49521 100644
--- a/pbap/pbap.h
+++ b/pbap/pbap.h
@@ -159,8 +159,8 @@ class Pbap : public QObject
QQmlContext *m_context;
QList<QObject *>m_contacts;
QList<QObject *>m_calls;
- void updateContacts(QString);
- void updateCalls(QString);
+ void updateContacts(QJsonArray);
+ void updateCalls(QJsonArray);
void sendSearchResults(QJsonArray);
// slots