Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #45 from matthewvogt/removal-notification
Browse files Browse the repository at this point in the history
libcontacts] Ensure contacts are not in name groups on cache removal
  • Loading branch information
matthewvogt committed Oct 11, 2013
2 parents 7f336b3 + b0d72c2 commit 8cce9b4
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/seasidecache.cpp
Expand Up @@ -883,11 +883,9 @@ void SeasideCache::removeContactData(quint32 iid, FilterType filter)

if (filter == FilterAll) {
const QString group(nameGroup(existingItem(iid)));
if (!group.isNull()) {
QSet<QString> modifiedNameGroups;
removeFromContactNameGroup(iid, group, &modifiedNameGroups);
notifyNameGroupsChanged(modifiedNameGroups);
}
QSet<QString> modifiedNameGroups;
removeFromContactNameGroup(iid, group, &modifiedNameGroups);
notifyNameGroupsChanged(modifiedNameGroups);
}

for (int i = 0; i < models.count(); ++i)
Expand Down Expand Up @@ -1383,15 +1381,30 @@ bool SeasideCache::event(QEvent *event)
} else {
m_updatesPending = false;

const QHash<ContactIdType,int> expiredContacts = m_expiredContacts;
QList<quint32> removeIds;

QHash<ContactIdType, int>::const_iterator it = m_expiredContacts.constBegin(), end = m_expiredContacts.constEnd();
for ( ; it != end; ++it) {
if (it.value() < 0) {
quint32 iid = internalId(it.key());
removeIds.append(iid);
}
}
m_expiredContacts.clear();

typedef QHash<ContactIdType,int>::const_iterator iterator;
for (iterator it = expiredContacts.begin(); it != expiredContacts.end(); ++it) {
if (*it >= 0)
continue;
QSet<QString> modifiedGroups;

// Before removal, ensure none of these contacts are in name groups
foreach (quint32 iid, removeIds) {
if (CacheItem *item = existingItem(iid)) {
removeFromContactNameGroup(item->iid, item->nameGroup, &modifiedGroups);
}
}

notifyNameGroupsChanged(modifiedGroups);

quint32 iid = internalId(it.key());
// Remove the contacts from the cache
foreach (quint32 iid, removeIds) {
QHash<quint32, CacheItem>::iterator cacheItem = m_people.find(iid);
if (cacheItem != m_people.end()) {
delete cacheItem->itemData;
Expand Down Expand Up @@ -1788,9 +1801,7 @@ void SeasideCache::contactsAvailable()
if (item->nameGroup != oldNameGroup) {
if (!ignoreContactForNameGroups(item->contact)) {
addToContactNameGroup(item->iid, item->nameGroup, &modifiedGroups);
if (!oldNameGroup.isNull()) {
removeFromContactNameGroup(item->iid, oldNameGroup, &modifiedGroups);
}
removeFromContactNameGroup(item->iid, oldNameGroup, &modifiedGroups);
}
}

Expand Down Expand Up @@ -2253,9 +2264,7 @@ void SeasideCache::displayLabelOrderChanged()
const QString group(determineNameGroup(&*it));
if (group != it->nameGroup) {
if (!ignoreContactForNameGroups(it->contact)) {
if (!it->nameGroup.isNull()) {
removeFromContactNameGroup(it->iid, it->nameGroup, &modifiedGroups);
}
removeFromContactNameGroup(it->iid, it->nameGroup, &modifiedGroups);

it->nameGroup = group;
addToContactNameGroup(it->iid, it->nameGroup, &modifiedGroups);
Expand Down Expand Up @@ -2330,9 +2339,7 @@ void SeasideCache::groupPropertyChanged()
const QString group(determineNameGroup(&*it));
if (group != it->nameGroup) {
if (!ignoreContactForNameGroups(it->contact)) {
if (!it->nameGroup.isNull()) {
removeFromContactNameGroup(it->iid, it->nameGroup, &modifiedGroups);
}
removeFromContactNameGroup(it->iid, it->nameGroup, &modifiedGroups);

it->nameGroup = group;
addToContactNameGroup(it->iid, it->nameGroup, &modifiedGroups);
Expand Down

0 comments on commit 8cce9b4

Please sign in to comment.