From cdb951e693aac8212715abbdf8728f68205ce203 Mon Sep 17 00:00:00 2001 From: Matt Vogt Date: Mon, 2 Sep 2013 16:08:20 +1000 Subject: [PATCH] [libcontacts] Only aggregate contacts should affect name groups --- src/seasidecache.cpp | 50 +++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index c925b8b..9aa20a5 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -264,9 +264,11 @@ QContactFilter onlineFilter() QContactFilter aggregateFilter() { + static const QString aggregate(QString::fromLatin1("aggregate")); + QContactDetailFilter filter; setDetailType(filter, QContactSyncTarget::FieldSyncTarget); - filter.setValue("aggregate"); + filter.setValue(aggregate); return filter; } @@ -288,6 +290,20 @@ StringPair addressPair(const QContactOnlineAccount &account) return qMakePair(account.value(QContactOnlineAccount__FieldAccountPath), account.accountUri().toLower()); } +bool ignoreContactForNameGroups(const QContact &contact) +{ + static const QString aggregate(QString::fromLatin1("aggregate")); + + // Don't include the self contact in name groups + if (SeasideCache::apiId(contact) == SeasideCache::selfContactId()) { + return true; + } + + // Also ignore non-aggregate contacts + QContactSyncTarget syncTarget = contact.detail(); + return (syncTarget.syncTarget() != aggregate); +} + } SeasideCache *SeasideCache::instancePtr = 0; @@ -1677,9 +1693,11 @@ void SeasideCache::contactsAvailable() // do this even if !roleDataChanged as name groups are affected by other display label changes if (item->nameGroup != oldNameGroup) { - addToContactNameGroup(item->iid, item->nameGroup, &modifiedGroups); - if (!oldNameGroup.isNull()) { - removeFromContactNameGroup(item->iid, oldNameGroup, &modifiedGroups); + if (!ignoreContactForNameGroups(item->contact)) { + addToContactNameGroup(item->iid, item->nameGroup, &modifiedGroups); + if (!oldNameGroup.isNull()) { + removeFromContactNameGroup(item->iid, oldNameGroup, &modifiedGroups); + } } } @@ -2134,12 +2152,14 @@ void SeasideCache::displayLabelOrderChanged() // If the contact's name group is derived from display label, it may have changed const QChar group(determineNameGroup(&*it)); if (group != it->nameGroup) { - if (!it->nameGroup.isNull()) { - removeFromContactNameGroup(it->iid, it->nameGroup, &modifiedGroups); - } + if (!ignoreContactForNameGroups(it->contact)) { + if (!it->nameGroup.isNull()) { + removeFromContactNameGroup(it->iid, it->nameGroup, &modifiedGroups); + } - it->nameGroup = group; - addToContactNameGroup(it->iid, it->nameGroup, &modifiedGroups); + it->nameGroup = group; + addToContactNameGroup(it->iid, it->nameGroup, &modifiedGroups); + } } } @@ -2209,12 +2229,14 @@ void SeasideCache::groupPropertyChanged() // Update the nameGroup for this contact const QChar group(determineNameGroup(&*it)); if (group != it->nameGroup) { - if (!it->nameGroup.isNull()) { - removeFromContactNameGroup(it->iid, it->nameGroup, &modifiedGroups); - } + if (!ignoreContactForNameGroups(it->contact)) { + if (!it->nameGroup.isNull()) { + removeFromContactNameGroup(it->iid, it->nameGroup, &modifiedGroups); + } - it->nameGroup = group; - addToContactNameGroup(it->iid, it->nameGroup, &modifiedGroups); + it->nameGroup = group; + addToContactNameGroup(it->iid, it->nameGroup, &modifiedGroups); + } } }