Commit 943b3f1d authored by mvogt's avatar mvogt

[libcontacts] Remove existing IsNot relationship during aggregation

If a prior IsNot relationship exists, then remove it if aggregation
causes if to become invalid.
parent cfc10ed5
...@@ -82,6 +82,7 @@ Q_GLOBAL_STATIC(CacheConfiguration, cacheConfig) ...@@ -82,6 +82,7 @@ Q_GLOBAL_STATIC(CacheConfiguration, cacheConfig)
ML10N::MLocale mLocale; ML10N::MLocale mLocale;
const QString aggregateRelationshipType = QContactRelationship::Aggregates(); const QString aggregateRelationshipType = QContactRelationship::Aggregates();
const QString isNotRelationshipType = QString::fromLatin1("IsNot");
const QString syncTargetLocal = QLatin1String("local"); const QString syncTargetLocal = QLatin1String("local");
const QString syncTargetWasLocal = QLatin1String("was_local"); const QString syncTargetWasLocal = QLatin1String("was_local");
...@@ -2980,7 +2981,7 @@ void SeasideCache::aggregateContacts(const QContact &contact1, const QContact &c ...@@ -2980,7 +2981,7 @@ void SeasideCache::aggregateContacts(const QContact &contact1, const QContact &c
void SeasideCache::disaggregateContacts(const QContact &contact1, const QContact &contact2) void SeasideCache::disaggregateContacts(const QContact &contact1, const QContact &contact2)
{ {
instancePtr->m_relationshipsToRemove.append(makeRelationship(aggregateRelationshipType, contact1, 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) { if (contact2.detail<QContactSyncTarget>().syncTarget() == syncTargetWasLocal) {
// restore the local sync target that was changed in a previous link creation operation // restore the local sync target that was changed in a previous link creation operation
...@@ -3052,9 +3053,12 @@ void SeasideCache::completeContactAggregation(const QContactId &contact1Id, cons ...@@ -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 // For each constituent of contact2, add a relationship between it and contact1, and remove the
// relationship between it and contact2. // relationship between it and contact2.
foreach (int id, constituents2) { foreach (int id, constituents2) {
QContact c = contactById(apiId(id)); const QContactId constituentId(apiId(id));
m_relationshipsToSave.append(makeRelationship(aggregateRelationshipType, contactById(contact1Id), c)); m_relationshipsToSave.append(makeRelationship(aggregateRelationshipType, contact1Id, constituentId));
m_relationshipsToRemove.append(makeRelationship(aggregateRelationshipType, contactById(contact2Id), c)); 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()) if (!m_relationshipsToSave.isEmpty() || !m_relationshipsToRemove.isEmpty())
...@@ -3134,14 +3138,22 @@ int SeasideCache::contactIndex(quint32 iid, FilterType filterType) ...@@ -3134,14 +3138,22 @@ int SeasideCache::contactIndex(quint32 iid, FilterType filterType)
return cacheIds.indexOf(iid); 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; QContactRelationship relationship;
relationship.setRelationshipType(type); relationship.setRelationshipType(type);
relationship.setFirst(contact1); relationship.setFirst(first);
relationship.setSecond(contact2); relationship.setSecond(second);
return relationship; 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 // Instantiate the contact ID functions for qtcontacts-sqlite
#include <qtcontacts-extensions_impl.h> #include <qtcontacts-extensions_impl.h>
...@@ -401,6 +401,7 @@ private: ...@@ -401,6 +401,7 @@ private:
int contactIndex(quint32 iid, FilterType filter); 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); static QContactRelationship makeRelationship(const QString &type, const QContact &contact1, const QContact &contact2);
QList<quint32> m_contacts[FilterTypesCount]; QList<quint32> m_contacts[FilterTypesCount];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment