summaryrefslogtreecommitdiff
path: root/saltoqd/contactsmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'saltoqd/contactsmanager.cpp')
-rw-r--r--saltoqd/contactsmanager.cpp92
1 files changed, 70 insertions, 22 deletions
diff --git a/saltoqd/contactsmanager.cpp b/saltoqd/contactsmanager.cpp
index 19e3c84..50b57a5 100644
--- a/saltoqd/contactsmanager.cpp
+++ b/saltoqd/contactsmanager.cpp
@@ -27,6 +27,49 @@ qint64 ContactsManager::getRecordIdForContact(uint contactId)
return contactId;
}
+ContactsManager::NameType ContactsManager::findNameTypeForPhoneNumber(const QString &phoneNumber) const
+{
+ NameType result;
+
+ result.found = false;
+ result.favorite = false;
+
+ if (!phoneNumber.isEmpty()) {
+ const int maxCharacters = QtContactsSqliteExtensions::DefaultMaximumPhoneNumberCharacters;
+ QString normPhoneNumber = QtContactsSqliteExtensions::minimizePhoneNumber(phoneNumber, maxCharacters);
+ QList<QContact> contacts = _contacts->contacts(QContactPhoneNumber::match(normPhoneNumber));
+
+ if (!contacts.isEmpty()) {
+ const QContact& contact = contacts.first();
+ result.found = true;
+ result.name = contact.detail<QContactDisplayLabel>().label();
+ result.favorite = contact.detail<QContactFavorite>().isFavorite();
+
+ for (const QContactPhoneNumber &phone : contact.details<QContactPhoneNumber>()) {
+ if (phone.number() == normPhoneNumber) {
+ result.type = typeForContactPhone(phone);
+ break;
+ }
+ }
+ } else {
+ result.found = false;
+ }
+ }
+
+ if (result.name.isEmpty()) {
+ if (phoneNumber.isEmpty()) {
+ result.name = tr("Unknown");
+ } else {
+ result.name = phoneNumber;
+ }
+ }
+ if (result.type.isEmpty()) {
+ result.type = "Other";
+ }
+
+ return result;
+}
+
void ContactsManager::scheduleRefresh()
{
if (!_refreshTimer->isActive()) {
@@ -60,28 +103,7 @@ void ContactsManager::refresh()
QJsonArray phones;
for (const QContactPhoneNumber &cPhone : contact.details<QContactPhoneNumber>()) {
QJsonObject phone;
- QString type;
- if (!cPhone.subTypes().isEmpty()) {
- if (cPhone.subTypes().first() == QContactPhoneNumber::SubTypeMobile) {
- type = "Mobile";
- }
- }
- if (type.isEmpty() && !cPhone.contexts().isEmpty()) {
- switch (cPhone.contexts().first()) {
- case QContactDetail::ContextHome:
- type = "Home";
- break;
- case QContactDetail::ContextWork:
- type = "Work";
- break;
- default:
- break;
- }
- }
- if (type.isEmpty()) {
- type = "Other";
- }
- phone.insert("Type", type);
+ phone.insert("Type", typeForContactPhone(cPhone));
phone.insert("Number", cPhone.number());
phones.append(phone);
}
@@ -108,3 +130,29 @@ void ContactsManager::refresh()
emit changed();
}
+
+QString ContactsManager::typeForContactPhone(const QContactPhoneNumber &number)
+{
+ QString type;
+ if (!number.subTypes().isEmpty()) {
+ if (number.subTypes().first() == QContactPhoneNumber::SubTypeMobile) {
+ type = "Mobile";
+ }
+ }
+ if (type.isEmpty() && !number.contexts().isEmpty()) {
+ switch (number.contexts().first()) {
+ case QContactDetail::ContextHome:
+ type = "Home";
+ break;
+ case QContactDetail::ContextWork:
+ type = "Work";
+ break;
+ default:
+ break;
+ }
+ }
+ if (type.isEmpty()) {
+ type = "Other";
+ }
+ return type;
+}