From 7a36d1d32561de87cabf5bd6c0665a4f6d10a40b Mon Sep 17 00:00:00 2001 From: Matt Porter Date: Tue, 26 Jun 2018 11:55:17 -0400 Subject: pbap: add PBAP data backed ContactsModel Expose the PBAP phonebook as a QList of Contact QObjects. Each contact has a variable amount of PhoneNumber objects exposed as a list property. PhoneNumber objects carry both the value and type of phone entry (mobile, work, etc.) Bug-AGL: SPEC-1436 Change-Id: Id22f394c13fd842e36c7866342ed7785b243a27b Signed-off-by: Matt Porter --- pbap/pbap.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'pbap/pbap.cpp') diff --git a/pbap/pbap.cpp b/pbap/pbap.cpp index 20024a7..98c05b5 100644 --- a/pbap/pbap.cpp +++ b/pbap/pbap.cpp @@ -45,7 +45,7 @@ int PhoneNumber::stringToEnum(QString key) return (value < 0) ? 0 : value; } -Contact::Contact(QString name, QListnumbers) +Contact::Contact(QString name, QListnumbers) { m_name = name; m_numbers = numbers; @@ -83,6 +83,8 @@ Pbap::Pbap (QUrl &url, QQmlContext *context, QObject * parent) : { m_mloop = new MessageEngine(url); m_context = context; + m_context->setContextProperty("ContactsModel", QVariant::fromValue(m_contacts)); + qmlRegisterUncreatableType("PhoneNumber", 1, 0, "PhoneNumber", "Enum"); m_context->setContextProperty("RecentCallModel", QVariant::fromValue(m_calls)); qmlRegisterUncreatableType("RecentCall", 1, 0, "RecentCall", "Enum"); @@ -149,6 +151,8 @@ void Pbap::updateContacts(QString vcards) { QString name, number, type; + m_contacts.clear(); + QList contacts_vcards = vCard::fromByteArray(vcards.toUtf8()); for (auto vcard : contacts_vcards) { @@ -162,7 +166,7 @@ void Pbap::updateContacts(QString vcards) * properties, so we iterate over all properties and parse * each identified VC_TELEPHONE property in the vCard. */ - QList numbers; + QList numbers; vCardPropertyList properties = vcard.properties(); for (auto property : properties) { if (property.isValid() && (property.name() == VC_TELEPHONE)) { @@ -179,6 +183,9 @@ void Pbap::updateContacts(QString vcards) std::sort(m_contacts.begin(), m_contacts.end(), compareContactPtr); + // Refresh model + m_context->setContextProperty("ContactsModel", QVariant::fromValue(m_contacts)); + refreshCalls(100); } @@ -206,9 +213,8 @@ void Pbap::updateCalls(QString vcards) bool found = false; for (auto contact_obj : m_contacts) { Contact *contact = qobject_cast(contact_obj); - QListnumbers = contact->numbers(); - for (auto number_obj : numbers) { - PhoneNumber *phone_number = qobject_cast(number_obj); + QList numbers = contact->numbers(); + for (auto phone_number : numbers) { if (number.endsWith(phone_number->number())) { name = contact->name(); found = true; -- cgit 1.2.3-korg