diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2018-12-27 18:33:53 -0800 |
---|---|---|
committer | Matt Ranostay <matt.ranostay@konsulko.com> | 2018-12-27 19:27:43 -0800 |
commit | e146895c7620f924a5541931e4ebc52206843176 (patch) | |
tree | 33bd6c495ada8c60cc43431f11c8598e7aa682d8 | |
parent | cdfb8ce39e99616d84742c337213fc4bfebd1ad4 (diff) |
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 <matt.ranostay@konsulko.com>
-rw-r--r-- | pbap/pbap.cpp | 32 | ||||
-rw-r--r-- | pbap/pbap.h | 6 |
2 files changed, 31 insertions, 7 deletions
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 <QMetaEnum> +#include <QMimeDatabase> #include <QtQml/QQmlEngine> #include <vcard/vcard.h> @@ -45,9 +46,10 @@ int PhoneNumber::stringToEnum(QString key) return (value < 0) ? 0 : value; } -Contact::Contact(QString name, QList<PhoneNumber *>numbers) +Contact::Contact(QString name, QString photo, QList<PhoneNumber *>numbers) { 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<PhoneNumber *> 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(QQmlListProperty<PhoneNumber>numbers READ numbersList NOTIFY numbersListChanged) public: - explicit Contact(QString name, QList<PhoneNumber *>numbers); + explicit Contact(QString name, QString photo, QList<PhoneNumber *>numbers); virtual ~Contact(); bool operator<(Contact& c) {return ((this->m_name < c.m_name));}; QString name() {return m_name;}; + QString photo() {return m_photo;}; QList<PhoneNumber *>numbers() {return m_numbers;}; QQmlListProperty<PhoneNumber>numbersList() { return QQmlListProperty<PhoneNumber>(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; QList<PhoneNumber *>m_numbers; }; |