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

Commit

Permalink
Merge branch 'jb45633' into 'master'
Browse files Browse the repository at this point in the history
[libcontacts] Emit saveContactComplete() when appropriate. Contributes to JB#45633

See merge request mer-core/libcontacts!13
  • Loading branch information
blam committed Jun 3, 2019
2 parents 706f707 + c9279bd commit 346cbb2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/seasidecache.cpp
Expand Up @@ -2660,6 +2660,17 @@ void SeasideCache::appendContacts(const QList<QContact> &contacts, FilterType fi
}
}

void SeasideCache::notifySaveContactComplete(int constituentId, int aggregateId)
{
for (int i = 0; i < FilterTypesCount; ++i) {
const QList<ListModel *> &models = m_models[i];
for (int j = 0; j < models.count(); ++j) {
ListModel *model = models.at(j);
model->saveContactComplete(constituentId, aggregateId);
}
}
}

void SeasideCache::requestStateChanged(QContactAbstractRequest::State state)
{
if (state != QContactAbstractRequest::FinishedState)
Expand Down Expand Up @@ -2800,6 +2811,37 @@ void SeasideCache::requestStateChanged(QContactAbstractRequest::State state)
}
m_populating = false;
}
} else if (request == &m_saveRequest) {
for (int i = 0; i < m_saveRequest.contacts().size(); ++i) {
const QContact c = m_saveRequest.contacts().at(i);
if (m_saveRequest.errorMap().value(i) != QContactManager::NoError) {
notifySaveContactComplete(-1, -1);
} else if (c.detail<QContactSyncTarget>().syncTarget() == QStringLiteral("aggregate")) {
// In case an aggregate is saved rather than a local constituent,
// no need to look up the aggregate via a relationship fetch request.
notifySaveContactComplete(-1, internalId(c));
} else {
// Get the aggregate associated with this contact.
QContactRelationshipFetchRequest *rfr = new QContactRelationshipFetchRequest(this);
rfr->setManager(m_saveRequest.manager());
rfr->setRelationshipType(QContactRelationship::Aggregates());
rfr->setSecond(c);
connect(rfr, &QContactAbstractRequest::stateChanged, this, [this, c, rfr] {
if (rfr->state() == QContactAbstractRequest::FinishedState) {
rfr->deleteLater();
if (rfr->relationships().size()) {
const quint32 constituentId = internalId(apiId(rfr->relationships().at(0).second()));
const quint32 aggregateId = internalId(apiId(rfr->relationships().at(0).first()));
this->notifySaveContactComplete(constituentId, aggregateId);
} else {
// error: cannot retrieve aggregate for newly created constituent.
this->notifySaveContactComplete(internalId(c), -1);
}
}
});
rfr->start();
}
}
}

// See if there are any more requests to dispatch
Expand Down
4 changes: 4 additions & 0 deletions src/seasidecache.h
Expand Up @@ -234,6 +234,8 @@ class CONTACTCACHE_EXPORT SeasideCache : public QObject
virtual void updateGroupProperty() = 0;

virtual void updateSectionBucketIndexCache() = 0;

virtual void saveContactComplete(int localId, int aggregateId) = 0;
};

struct ResolveListener
Expand Down Expand Up @@ -407,6 +409,8 @@ private slots:

int contactIndex(quint32 iid, FilterType filter);

void notifySaveContactComplete(int constituentId, int aggregateId);

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

Expand Down

0 comments on commit 346cbb2

Please sign in to comment.