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

Commit

Permalink
Browse files Browse the repository at this point in the history
[libcontacts] Remove existing IsNot relationship during aggregation
If a prior IsNot relationship exists, then remove it if aggregation
causes if to become invalid.
  • Loading branch information
matthewvogt committed Jul 31, 2014
1 parent cfc10ed commit 943b3f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/seasidecache.cpp
Expand Up @@ -82,6 +82,7 @@ Q_GLOBAL_STATIC(CacheConfiguration, cacheConfig)
ML10N::MLocale mLocale;

const QString aggregateRelationshipType = QContactRelationship::Aggregates();
const QString isNotRelationshipType = QString::fromLatin1("IsNot");

const QString syncTargetLocal = QLatin1String("local");
const QString syncTargetWasLocal = QLatin1String("was_local");
Expand Down Expand Up @@ -2980,7 +2981,7 @@ void SeasideCache::aggregateContacts(const QContact &contact1, const QContact &c
void SeasideCache::disaggregateContacts(const QContact &contact1, const QContact &contact2)
{
instancePtr->m_relationshipsToRemove.append(makeRelationship(aggregateRelationshipType, contact1, contact2));
instancePtr->m_relationshipsToSave.append(makeRelationship(QLatin1String("IsNot"), contact1, contact2));
instancePtr->m_relationshipsToSave.append(makeRelationship(isNotRelationshipType, contact1, contact2));

if (contact2.detail<QContactSyncTarget>().syncTarget() == syncTargetWasLocal) {
// restore the local sync target that was changed in a previous link creation operation
Expand Down Expand Up @@ -3052,9 +3053,12 @@ void SeasideCache::completeContactAggregation(const QContactId &contact1Id, cons
// For each constituent of contact2, add a relationship between it and contact1, and remove the
// relationship between it and contact2.
foreach (int id, constituents2) {
QContact c = contactById(apiId(id));
m_relationshipsToSave.append(makeRelationship(aggregateRelationshipType, contactById(contact1Id), c));
m_relationshipsToRemove.append(makeRelationship(aggregateRelationshipType, contactById(contact2Id), c));
const QContactId constituentId(apiId(id));
m_relationshipsToSave.append(makeRelationship(aggregateRelationshipType, contact1Id, constituentId));
m_relationshipsToRemove.append(makeRelationship(aggregateRelationshipType, contact2Id, constituentId));

// If there is an existing IsNot relationship, remove that
m_relationshipsToRemove.append(makeRelationship(isNotRelationshipType, contact1Id, constituentId));
}

if (!m_relationshipsToSave.isEmpty() || !m_relationshipsToRemove.isEmpty())
Expand Down Expand Up @@ -3134,14 +3138,22 @@ int SeasideCache::contactIndex(quint32 iid, FilterType filterType)
return cacheIds.indexOf(iid);
}

QContactRelationship SeasideCache::makeRelationship(const QString &type, const QContact &contact1, const QContact &contact2)
QContactRelationship SeasideCache::makeRelationship(const QString &type, const QContactId &id1, const QContactId &id2)
{
QContact first, second;
first.setId(id1);
second.setId(id2);
QContactRelationship relationship;
relationship.setRelationshipType(type);
relationship.setFirst(contact1);
relationship.setSecond(contact2);
relationship.setFirst(first);
relationship.setSecond(second);
return relationship;
}

QContactRelationship SeasideCache::makeRelationship(const QString &type, const QContact &contact1, const QContact &contact2)
{
return makeRelationship(type, contact1.id(), contact2.id());
}

// Instantiate the contact ID functions for qtcontacts-sqlite
#include <qtcontacts-extensions_impl.h>
1 change: 1 addition & 0 deletions src/seasidecache.h
Expand Up @@ -401,6 +401,7 @@ private slots:

int contactIndex(quint32 iid, FilterType filter);

static QContactRelationship makeRelationship(const QString &type, const QContactId &id1, const QContactId &id2);
static QContactRelationship makeRelationship(const QString &type, const QContact &contact1, const QContact &contact2);

QList<quint32> m_contacts[FilterTypesCount];
Expand Down

0 comments on commit 943b3f1

Please sign in to comment.