summaryrefslogtreecommitdiffstats
path: root/pbap
diff options
context:
space:
mode:
authorMatt Porter <mporter@konsulko.com>2018-06-26 11:55:17 -0400
committerMatt Porter <mporter@konsulko.com>2018-06-26 12:05:20 -0400
commit7a36d1d32561de87cabf5bd6c0665a4f6d10a40b (patch)
tree9f17db84bcd2072dbf8605fd36650c0255885584 /pbap
parentbc9d7b82208767b92cb975e4a2c3dc43983fb6f9 (diff)
pbap: add PBAP data backed ContactsModelflounder_5.99.1flounder/5.99.15.99.1
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 <mporter@konsulko.com>
Diffstat (limited to 'pbap')
-rw-r--r--pbap/pbap.cpp16
-rw-r--r--pbap/pbap.h22
2 files changed, 28 insertions, 10 deletions
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, QList<QObject *>numbers)
+Contact::Contact(QString name, QList<PhoneNumber *>numbers)
{
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>("PhoneNumber", 1, 0, "PhoneNumber", "Enum");
m_context->setContextProperty("RecentCallModel", QVariant::fromValue(m_calls));
qmlRegisterUncreatableType<RecentCall>("RecentCall", 1, 0, "RecentCall", "Enum");
@@ -149,6 +151,8 @@ void Pbap::updateContacts(QString vcards)
{
QString name, number, type;
+ m_contacts.clear();
+
QList<vCard> 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<QObject *> numbers;
+ QList<PhoneNumber *> 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 *>(contact_obj);
- QList<QObject *>numbers = contact->numbers();
- for (auto number_obj : numbers) {
- PhoneNumber *phone_number = qobject_cast<PhoneNumber *>(number_obj);
+ QList<PhoneNumber *> numbers = contact->numbers();
+ for (auto phone_number : numbers) {
if (number.endsWith(phone_number->number())) {
name = contact->name();
found = true;
diff --git a/pbap/pbap.h b/pbap/pbap.h
index 4b1bd43..8249400 100644
--- a/pbap/pbap.h
+++ b/pbap/pbap.h
@@ -21,6 +21,7 @@
#include <QObject>
#include <QJsonArray>
#include <QtQml/QQmlContext>
+#include <QtQml/QQmlListProperty>
#include "messageengine.h"
@@ -63,23 +64,34 @@ class Contact : public QObject
Q_OBJECT
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
- Q_PROPERTY(QList<QObject *>numbers READ numbers NOTIFY numbersChanged)
+ Q_PROPERTY(QQmlListProperty<PhoneNumber>numbers READ numbersList NOTIFY numbersListChanged)
public:
- explicit Contact(QString name, QList<QObject *>numbers);
+ explicit Contact(QString name, QList<PhoneNumber *>numbers);
virtual ~Contact();
bool operator<(Contact& c) {return ((this->m_name < c.m_name));};
QString name() {return m_name;};
- QList<QObject *>numbers() {return m_numbers;};
+ QList<PhoneNumber *>numbers() {return m_numbers;};
+ QQmlListProperty<PhoneNumber>numbersList() {
+ return QQmlListProperty<PhoneNumber>(this, 0, &Contact::countNumbers, &Contact::atNumbers);
+ }
+ static int countNumbers(QQmlListProperty<PhoneNumber> *property) {
+ Contact *contact = qobject_cast<Contact *>(property->object);
+ return contact->m_numbers.size();
+ }
+ static PhoneNumber *atNumbers(QQmlListProperty<PhoneNumber> *property, int index) {
+ Contact *contact = qobject_cast<Contact *>(property->object);
+ return contact->m_numbers[index];
+ }
signals:
void nameChanged();
- void numbersChanged();
+ void numbersListChanged();
private:
QString m_name;
- QList<QObject *>m_numbers;
+ QList<PhoneNumber *>m_numbers;
};
class RecentCall : public QObject