diff options
-rw-r--r-- | common/changereplay.h | 2 | ||||
-rw-r--r-- | common/synchronizer.cpp | 19 | ||||
-rw-r--r-- | common/synchronizer.h | 2 | ||||
-rw-r--r-- | examples/imapresource/imapresource.cpp | 21 |
4 files changed, 24 insertions, 20 deletions
diff --git a/common/changereplay.h b/common/changereplay.h index c509735..22e26a5 100644 --- a/common/changereplay.h +++ b/common/changereplay.h | |||
@@ -54,7 +54,7 @@ public slots: | |||
54 | protected: | 54 | protected: |
55 | virtual KAsync::Job<void> replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) = 0; | 55 | virtual KAsync::Job<void> replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) = 0; |
56 | virtual bool canReplay(const QByteArray &type, const QByteArray &key, const QByteArray &value) = 0; | 56 | virtual bool canReplay(const QByteArray &type, const QByteArray &key, const QByteArray &value) = 0; |
57 | virtual void reportProgress(int progress, int total){}; | 57 | virtual void reportProgress(int progress, int total, const QByteArrayList &applicableEntities = {}){}; |
58 | Sink::Storage::DataStore mStorage; | 58 | Sink::Storage::DataStore mStorage; |
59 | KAsync::Job<void> replayNextRevision(); | 59 | KAsync::Job<void> replayNextRevision(); |
60 | 60 | ||
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index b9decbd..3ef7eb7 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp | |||
@@ -315,11 +315,17 @@ void Synchronizer::emitProgressNotification(Notification::NoticationType type, i | |||
315 | emit notify(n); | 315 | emit notify(n); |
316 | } | 316 | } |
317 | 317 | ||
318 | void Synchronizer::reportProgress(int progress, int total) | 318 | void Synchronizer::reportProgress(int progress, int total, const QByteArrayList &entities) |
319 | { | 319 | { |
320 | if (progress > 0 && total > 0) { | 320 | if (progress > 0 && total > 0) { |
321 | SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total; | 321 | SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total << mCurrentRequest.requestId << mCurrentRequest.applicableEntities; |
322 | emitProgressNotification(Notification::Progress, progress, total, mCurrentRequest.requestId, mCurrentRequest.applicableEntities); | 322 | const auto applicableEntities = [&] { |
323 | if (entities.isEmpty()) { | ||
324 | return mCurrentRequest.applicableEntities; | ||
325 | } | ||
326 | return entities; | ||
327 | }(); | ||
328 | emitProgressNotification(Notification::Progress, progress, total, mCurrentRequest.requestId, applicableEntities); | ||
323 | } | 329 | } |
324 | } | 330 | } |
325 | 331 | ||
@@ -371,6 +377,7 @@ KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request) | |||
371 | } else if (request.requestType == Synchronizer::SyncRequest::Synchronization) { | 377 | } else if (request.requestType == Synchronizer::SyncRequest::Synchronization) { |
372 | return KAsync::start([this, request] { | 378 | return KAsync::start([this, request] { |
373 | SinkLogCtx(mLogCtx) << "Synchronizing: " << request.query; | 379 | SinkLogCtx(mLogCtx) << "Synchronizing: " << request.query; |
380 | setBusy(true, "Synchronization has started.", request.requestId); | ||
374 | emitNotification(Notification::Info, ApplicationDomain::SyncInProgress, {}, {}, request.applicableEntities); | 381 | emitNotification(Notification::Info, ApplicationDomain::SyncInProgress, {}, {}, request.applicableEntities); |
375 | }).then(synchronizeWithSource(request.query)).then([this] { | 382 | }).then(synchronizeWithSource(request.query)).then([this] { |
376 | //Commit after every request, so implementations only have to commit more if they add a lot of data. | 383 | //Commit after every request, so implementations only have to commit more if they add a lot of data. |
@@ -408,6 +415,7 @@ KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request) | |||
408 | return KAsync::null(); | 415 | return KAsync::null(); |
409 | } else { | 416 | } else { |
410 | return KAsync::start([this, request] { | 417 | return KAsync::start([this, request] { |
418 | setBusy(true, "ChangeReplay has started.", request.requestId); | ||
411 | SinkLogCtx(mLogCtx) << "Replaying changes."; | 419 | SinkLogCtx(mLogCtx) << "Replaying changes."; |
412 | }) | 420 | }) |
413 | .then(replayNextRevision()) | 421 | .then(replayNextRevision()) |
@@ -479,11 +487,6 @@ KAsync::Job<void> Synchronizer::processSyncQueue() | |||
479 | mMessageQueue->startTransaction(); | 487 | mMessageQueue->startTransaction(); |
480 | mEntityStore->startTransaction(Sink::Storage::DataStore::ReadOnly); | 488 | mEntityStore->startTransaction(Sink::Storage::DataStore::ReadOnly); |
481 | mSyncInProgress = true; | 489 | mSyncInProgress = true; |
482 | if (request.requestType == Synchronizer::SyncRequest::Synchronization) { | ||
483 | setBusy(true, "Synchronization has started.", request.requestId); | ||
484 | } else if (request.requestType == Synchronizer::SyncRequest::ChangeReplay) { | ||
485 | setBusy(true, "ChangeReplay has started.", request.requestId); | ||
486 | } | ||
487 | mCurrentRequest = request; | 490 | mCurrentRequest = request; |
488 | }) | 491 | }) |
489 | .then(processRequest(request)) | 492 | .then(processRequest(request)) |
diff --git a/common/synchronizer.h b/common/synchronizer.h index 935c139..cc082be 100644 --- a/common/synchronizer.h +++ b/common/synchronizer.h | |||
@@ -197,7 +197,7 @@ protected: | |||
197 | /** | 197 | /** |
198 | * Report progress for current task | 198 | * Report progress for current task |
199 | */ | 199 | */ |
200 | virtual void reportProgress(int progress, int total) Q_DECL_OVERRIDE; | 200 | virtual void reportProgress(int progress, int total, const QByteArrayList &entities = {}) Q_DECL_OVERRIDE; |
201 | 201 | ||
202 | protected: | 202 | protected: |
203 | Sink::Log::Context mLogCtx; | 203 | Sink::Log::Context mLogCtx; |
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 94ca27a..533dea3 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -184,14 +184,12 @@ public: | |||
184 | return flags; | 184 | return flags; |
185 | } | 185 | } |
186 | 186 | ||
187 | void synchronizeMails(const QByteArray &folderRid, const Message &message) | 187 | void synchronizeMails(const QByteArray &folderRid, const QByteArray &folderLocalId, const Message &message) |
188 | { | 188 | { |
189 | auto time = QSharedPointer<QTime>::create(); | 189 | auto time = QSharedPointer<QTime>::create(); |
190 | time->start(); | 190 | time->start(); |
191 | SinkTraceCtx(mLogCtx) << "Importing new mail." << folderRid; | 191 | SinkTraceCtx(mLogCtx) << "Importing new mail." << folderRid; |
192 | 192 | ||
193 | const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, folderRid); | ||
194 | |||
195 | const auto remoteId = assembleMailRid(folderLocalId, message.uid); | 193 | const auto remoteId = assembleMailRid(folderLocalId, message.uid); |
196 | 194 | ||
197 | Q_ASSERT(message.msg); | 195 | Q_ASSERT(message.msg); |
@@ -315,14 +313,15 @@ public: | |||
315 | SinkTraceCtx(mLogCtx) << "Uids to fetch: " << filteredAndSorted; | 313 | SinkTraceCtx(mLogCtx) << "Uids to fetch: " << filteredAndSorted; |
316 | 314 | ||
317 | bool headersOnly = false; | 315 | bool headersOnly = false; |
316 | const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, folderRemoteId); | ||
318 | return imap->fetchMessages(folder, filteredAndSorted, headersOnly, [=](const Message &m) { | 317 | return imap->fetchMessages(folder, filteredAndSorted, headersOnly, [=](const Message &m) { |
319 | if (*maxUid < m.uid) { | 318 | if (*maxUid < m.uid) { |
320 | *maxUid = m.uid; | 319 | *maxUid = m.uid; |
321 | } | 320 | } |
322 | synchronizeMails(folderRemoteId, m); | 321 | synchronizeMails(folderRemoteId, folderLocalId, m); |
323 | }, | 322 | }, |
324 | [this, maxUid, folder](int progress, int total) { | 323 | [=](int progress, int total) { |
325 | reportProgress(progress, total); | 324 | reportProgress(progress, total, QByteArrayList{} << folderLocalId); |
326 | //commit every 10 messages | 325 | //commit every 10 messages |
327 | if ((progress % 10) == 0) { | 326 | if ((progress % 10) == 0) { |
328 | commit(); | 327 | commit(); |
@@ -359,11 +358,12 @@ public: | |||
359 | SinkLogCtx(mLogCtx) << "Fetching headers for: " << toFetch; | 358 | SinkLogCtx(mLogCtx) << "Fetching headers for: " << toFetch; |
360 | 359 | ||
361 | bool headersOnly = true; | 360 | bool headersOnly = true; |
361 | const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, folderRemoteId); | ||
362 | return imap->fetchMessages(folder, toFetch, headersOnly, [=](const Message &m) { | 362 | return imap->fetchMessages(folder, toFetch, headersOnly, [=](const Message &m) { |
363 | synchronizeMails(folderRemoteId, m); | 363 | synchronizeMails(folderRemoteId, folderLocalId, m); |
364 | }, | 364 | }, |
365 | [=](int progress, int total) { | 365 | [=](int progress, int total) { |
366 | reportProgress(progress, total); | 366 | reportProgress(progress, total, QByteArrayList{} << folderLocalId); |
367 | //commit every 100 messages | 367 | //commit every 100 messages |
368 | if ((progress % 100) == 0) { | 368 | if ((progress % 100) == 0) { |
369 | commit(); | 369 | commit(); |
@@ -567,11 +567,12 @@ public: | |||
567 | } | 567 | } |
568 | SinkLog() << "Fetching messages: " << toFetch << folderRemoteId; | 568 | SinkLog() << "Fetching messages: " << toFetch << folderRemoteId; |
569 | bool headersOnly = false; | 569 | bool headersOnly = false; |
570 | const auto folderLocalId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, folderRemoteId); | ||
570 | return imap->fetchMessages(Folder{folderRemoteId}, toFetch, headersOnly, [=](const Message &m) { | 571 | return imap->fetchMessages(Folder{folderRemoteId}, toFetch, headersOnly, [=](const Message &m) { |
571 | synchronizeMails(folderRemoteId, m); | 572 | synchronizeMails(folderRemoteId, folderLocalId, m); |
572 | }, | 573 | }, |
573 | [=](int progress, int total) { | 574 | [=](int progress, int total) { |
574 | reportProgress(progress, total); | 575 | reportProgress(progress, total, QByteArrayList{} << folderLocalId); |
575 | //commit every 100 messages | 576 | //commit every 100 messages |
576 | if ((progress % 100) == 0) { | 577 | if ((progress % 100) == 0) { |
577 | commit(); | 578 | commit(); |