Commit 23c5e97d authored by Krzysztof Nowicki's avatar Krzysztof Nowicki Committed by Laurent Montel
Browse files

Factor out collection sync state handing into dedicated methods

This is a preparatory change for moving the collection sync state from
the resource config file into the Akonadi database itself.
parent 8316db61
...@@ -319,7 +319,7 @@ void EwsResource::connectionError() ...@@ -319,7 +319,7 @@ void EwsResource::connectionError()
void EwsResource::retrieveItems(const Collection &collection) void EwsResource::retrieveItems(const Collection &collection)
{ {
QString rid = collection.remoteId(); QString rid = collection.remoteId();
auto job = new EwsFetchItemsJob(collection, mEwsClient, mSyncState.value(rid), mItemsToCheck.value(rid), mTagStore, this); auto job = new EwsFetchItemsJob(collection, mEwsClient, getCollectionSyncState(collection), mItemsToCheck.value(rid), mTagStore, this);
job->setQueuedUpdates(mQueuedUpdates.value(collection.remoteId())); job->setQueuedUpdates(mQueuedUpdates.value(collection.remoteId()));
mQueuedUpdates.remove(collection.remoteId()); mQueuedUpdates.remove(collection.remoteId());
connect(job, &EwsFetchItemsJob::result, this, &EwsResource::itemFetchJobFinished); connect(job, &EwsFetchItemsJob::result, this, &EwsResource::itemFetchJobFinished);
...@@ -442,13 +442,15 @@ void EwsResource::itemFetchJobFinished(KJob *job) ...@@ -442,13 +442,15 @@ void EwsResource::itemFetchJobFinished(KJob *job)
cancelTask(i18nc("@info:status", "Failed to retrieve items - internal error")); cancelTask(i18nc("@info:status", "Failed to retrieve items - internal error"));
return; return;
} }
auto col = fetchJob->collection();
if (job->error()) { if (job->error()) {
qCWarningNC(EWSRES_LOG) << QStringLiteral("Item fetch error:") << job->errorString(); qCWarningNC(EWSRES_LOG) << QStringLiteral("Item fetch error:") << job->errorString();
if (mSyncState.contains(fetchJob->collection().remoteId())) { const auto syncState = getCollectionSyncState(fetchJob->collection());
if (!syncState.isEmpty()) {
qCDebugNC(EWSRES_LOG) << QStringLiteral("Retrying with empty state."); qCDebugNC(EWSRES_LOG) << QStringLiteral("Retrying with empty state.");
// Retry with a clear sync state. // Retry with a clear sync state.
mSyncState.remove(fetchJob->collection().remoteId()); saveCollectionSyncState(col, QString());
retrieveItems(fetchJob->collection()); retrieveItems(col);
} else { } else {
qCDebugNC(EWSRES_LOG) << QStringLiteral("Clean sync failed."); qCDebugNC(EWSRES_LOG) << QStringLiteral("Clean sync failed.");
// No more hope // No more hope
...@@ -456,7 +458,7 @@ void EwsResource::itemFetchJobFinished(KJob *job) ...@@ -456,7 +458,7 @@ void EwsResource::itemFetchJobFinished(KJob *job)
return; return;
} }
} else { } else {
mSyncState[fetchJob->collection().remoteId()] = fetchJob->syncState(); saveCollectionSyncState(col, fetchJob->syncState());
itemsRetrievedIncremental(fetchJob->changedItems(), fetchJob->deletedItems()); itemsRetrievedIncremental(fetchJob->changedItems(), fetchJob->deletedItems());
} }
saveState(); saveState();
...@@ -1380,4 +1382,14 @@ void EwsResource::connectStatusSignals(Job *job) ...@@ -1380,4 +1382,14 @@ void EwsResource::connectStatusSignals(Job *job)
}); });
} }
QString EwsResource::getCollectionSyncState(const Akonadi::Collection &col) const
{
return mSyncState.value(col.remoteId());
}
void EwsResource::saveCollectionSyncState(Akonadi::Collection &col, const QString &state)
{
mSyncState[col.remoteId()] = state;
}
AKONADI_RESOURCE_MAIN(EwsResource) AKONADI_RESOURCE_MAIN(EwsResource)
...@@ -141,6 +141,9 @@ private: ...@@ -141,6 +141,9 @@ private:
void reauthNotificationDismissed(bool accepted); void reauthNotificationDismissed(bool accepted);
void reauthenticate(); void reauthenticate();
QString getCollectionSyncState(const Akonadi::Collection &col) const;
void saveCollectionSyncState(Akonadi::Collection &col, const QString &state);
template<class Job> template<class Job>
void connectStatusSignals(Job *job); void connectStatusSignals(Job *job);
......
Supports Markdown
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