From e146895c7620f924a5541931e4ebc52206843176 Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Thu, 27 Dec 2018 18:33:53 -0800 Subject: libqtappfw: pbap: add VC_PHOTO support to contacts Provide photo support for a contacts vCard data Bug-AGL: SPEC-2088 Change-Id: Ia193a26acb4c829c09f3e57944b8e3d0e550de19 Signed-off-by: Matt Ranostay --- pbap/pbap.cpp | 32 ++++++++++++++++++++++++++------ pbap/pbap.h | 6 +++++- 2 files changed, 31 insertions(+), 7 deletions(-) (limited to 'pbap') diff --git a/pbap/pbap.cpp b/pbap/pbap.cpp index 71dc7cb..df1c622 100644 --- a/pbap/pbap.cpp +++ b/pbap/pbap.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include @@ -45,9 +46,10 @@ int PhoneNumber::stringToEnum(QString key) return (value < 0) ? 0 : value; } -Contact::Contact(QString name, QListnumbers) +Contact::Contact(QString name, QString photo, QListnumbers) { m_name = name; + m_photo = photo; m_numbers = numbers; } @@ -167,18 +169,36 @@ void Pbap::updateContacts(QString vcards) * each identified VC_TELEPHONE property in the vCard. */ QList numbers; + QString photo; vCardPropertyList properties = vcard.properties(); for (auto property : properties) { - if (property.isValid() && (property.name() == VC_TELEPHONE)) { - QStringList values = property.values(); + 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 - type = params.at(0).value(); + // 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); } } - m_contacts.append(new Contact(name, numbers)); + if (!numbers.isEmpty()) + m_contacts.append(new Contact(name, photo, numbers)); } std::sort(m_contacts.begin(), m_contacts.end(), compareContactPtr); diff --git a/pbap/pbap.h b/pbap/pbap.h index 8249400..15cf2d4 100644 --- a/pbap/pbap.h +++ b/pbap/pbap.h @@ -64,14 +64,16 @@ class Contact : public QObject Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) + Q_PROPERTY(QString photo READ photo NOTIFY photoChanged) Q_PROPERTY(QQmlListPropertynumbers READ numbersList NOTIFY numbersListChanged) public: - explicit Contact(QString name, QListnumbers); + explicit Contact(QString name, QString photo, QListnumbers); virtual ~Contact(); bool operator<(Contact& c) {return ((this->m_name < c.m_name));}; QString name() {return m_name;}; + QString photo() {return m_photo;}; QListnumbers() {return m_numbers;}; QQmlListPropertynumbersList() { return QQmlListProperty(this, 0, &Contact::countNumbers, &Contact::atNumbers); @@ -87,10 +89,12 @@ class Contact : public QObject signals: void nameChanged(); + void photoChanged(); void numbersListChanged(); private: QString m_name; + QString m_photo; QListm_numbers; }; -- cgit 1.2.3-korg