summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/commands/notification.fbs2
-rw-r--r--common/listener.cpp2
-rw-r--r--common/notification.h2
-rw-r--r--common/resourceaccess.cpp2
-rw-r--r--common/synchronizer.cpp18
-rw-r--r--common/synchronizer.h10
-rw-r--r--examples/imapresource/imapresource.cpp4
7 files changed, 36 insertions, 4 deletions
diff --git a/common/commands/notification.fbs b/common/commands/notification.fbs
index 517111c..7ced666 100644
--- a/common/commands/notification.fbs
+++ b/common/commands/notification.fbs
@@ -5,6 +5,8 @@ table Notification {
5 identifier: string; //An identifier that links back to the something related to the notification (e.g. a command id) 5 identifier: string; //An identifier that links back to the something related to the notification (e.g. a command id)
6 message: string; 6 message: string;
7 code: int = 0; //See notification.h 7 code: int = 0; //See notification.h
8 progress: int = 0; //See notification.h
9 total: int = 0; //See notification.h
8 entities: [string]; //A list of entities this applies to 10 entities: [string]; //A list of entities this applies to
9} 11}
10 12
diff --git a/common/listener.cpp b/common/listener.cpp
index 983e438..ec2bedb 100644
--- a/common/listener.cpp
+++ b/common/listener.cpp
@@ -420,6 +420,8 @@ void Listener::notify(const Sink::Notification &notification)
420 builder.add_identifier(idString); 420 builder.add_identifier(idString);
421 builder.add_message(messageString); 421 builder.add_message(messageString);
422 builder.add_entities(entities); 422 builder.add_entities(entities);
423 builder.add_progress(notification.progress);
424 builder.add_total(notification.total);
423 auto command = builder.Finish(); 425 auto command = builder.Finish();
424 Sink::Commands::FinishNotificationBuffer(m_fbb, command); 426 Sink::Commands::FinishNotificationBuffer(m_fbb, command);
425 for (Client &client : m_connections) { 427 for (Client &client : m_connections) {
diff --git a/common/notification.h b/common/notification.h
index f5379fd..30e240c 100644
--- a/common/notification.h
+++ b/common/notification.h
@@ -56,6 +56,8 @@ public:
56 QString message; 56 QString message;
57 //A return code. Zero typically indicates success. 57 //A return code. Zero typically indicates success.
58 int code = 0; 58 int code = 0;
59 int progress = 0;
60 int total = 0;
59 QByteArray resource; 61 QByteArray resource;
60}; 62};
61} 63}
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp
index ad8cae9..cf8b2e0 100644
--- a/common/resourceaccess.cpp
+++ b/common/resourceaccess.cpp
@@ -547,6 +547,8 @@ static Sink::Notification getNotification(const Sink::Commands::Notification *bu
547 } 547 }
548 n.type = buffer->type(); 548 n.type = buffer->type();
549 n.code = buffer->code(); 549 n.code = buffer->code();
550 n.progress = buffer->progress();
551 n.total = buffer->total();
550 n.entities = BufferUtils::fromVector(*buffer->entities()); 552 n.entities = BufferUtils::fromVector(*buffer->entities());
551 return n; 553 return n;
552} 554}
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp
index 3e7bd30..58e5e7a 100644
--- a/common/synchronizer.cpp
+++ b/common/synchronizer.cpp
@@ -304,9 +304,21 @@ void Synchronizer::emitNotification(Notification::NoticationType type, int code,
304 emit notify(n); 304 emit notify(n);
305} 305}
306 306
307void Synchronizer::emitProgressNotification(Notification::NoticationType type, int progress, int total, const QByteArray &id, const QByteArrayList &entities)
308{
309 Sink::Notification n;
310 n.id = id;
311 n.type = type;
312 n.progress = progress;
313 n.total = total;
314 n.entities = entities;
315 emit notify(n);
316}
317
307void Synchronizer::reportProgress(int progress, int total) 318void Synchronizer::reportProgress(int progress, int total)
308{ 319{
309 SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total; 320 SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total;
321 emitProgressNotification(Notification::Progress, progress, total, mCurrentRequest.requestId, mCurrentRequest.applicableEntities);
310} 322}
311 323
312void Synchronizer::setStatusFromResult(const KAsync::Error &error, const QString &s, const QByteArray &requestId) 324void Synchronizer::setStatusFromResult(const KAsync::Error &error, const QString &s, const QByteArray &requestId)
@@ -465,13 +477,15 @@ KAsync::Job<void> Synchronizer::processSyncQueue()
465 if (request.requestType == Synchronizer::SyncRequest::Synchronization) { 477 if (request.requestType == Synchronizer::SyncRequest::Synchronization) {
466 setBusy(true, "Synchronization has started.", request.requestId); 478 setBusy(true, "Synchronization has started.", request.requestId);
467 } else if (request.requestType == Synchronizer::SyncRequest::ChangeReplay) { 479 } else if (request.requestType == Synchronizer::SyncRequest::ChangeReplay) {
468 setBusy(true, "ChangeReplay has started.", "changereplay"); 480 setBusy(true, "ChangeReplay has started.", request.requestId);
469 } 481 }
482 mCurrentRequest = request;
470 }) 483 })
471 .then(processRequest(request)) 484 .then(processRequest(request))
472 .then<void>([this, request](const KAsync::Error &error) { 485 .then<void>([this, request](const KAsync::Error &error) {
473 SinkTraceCtx(mLogCtx) << "Sync request processed"; 486 SinkTraceCtx(mLogCtx) << "Sync request processed";
474 setBusy(false, {}, request.requestId); 487 setBusy(false, {}, request.requestId);
488 mCurrentRequest = {};
475 mEntityStore->abortTransaction(); 489 mEntityStore->abortTransaction();
476 mSyncTransaction.abort(); 490 mSyncTransaction.abort();
477 mMessageQueue->commit(); 491 mMessageQueue->commit();
@@ -516,7 +530,7 @@ void Synchronizer::revisionChanged()
516 return; 530 return;
517 } 531 }
518 } 532 }
519 mSyncRequestQueue << Synchronizer::SyncRequest{Synchronizer::SyncRequest::ChangeReplay}; 533 mSyncRequestQueue << Synchronizer::SyncRequest{Synchronizer::SyncRequest::ChangeReplay, "changereplay"};
520 processSyncQueue().exec(); 534 processSyncQueue().exec();
521} 535}
522 536
diff --git a/common/synchronizer.h b/common/synchronizer.h
index b1ee122..bb24c2b 100644
--- a/common/synchronizer.h
+++ b/common/synchronizer.h
@@ -131,6 +131,8 @@ protected:
131 RequestFlush 131 RequestFlush
132 }; 132 };
133 133
134 SyncRequest() = default;
135
134 SyncRequest(const Sink::QueryBase &q, const QByteArray &requestId_ = QByteArray(), RequestOptions o = NoOptions) 136 SyncRequest(const Sink::QueryBase &q, const QByteArray &requestId_ = QByteArray(), RequestOptions o = NoOptions)
135 : requestId(requestId_), 137 : requestId(requestId_),
136 requestType(Synchronization), 138 requestType(Synchronization),
@@ -145,6 +147,12 @@ protected:
145 { 147 {
146 } 148 }
147 149
150 SyncRequest(RequestType type, const QByteArray &requestId_)
151 : requestId(requestId_),
152 requestType(type)
153 {
154 }
155
148 SyncRequest(RequestType type, int flushType_, const QByteArray &requestId_) 156 SyncRequest(RequestType type, int flushType_, const QByteArray &requestId_)
149 : flushType(flushType_), 157 : flushType(flushType_),
150 requestId(requestId_), 158 requestId(requestId_),
@@ -184,6 +192,7 @@ protected:
184 virtual void mergeIntoQueue(const Synchronizer::SyncRequest &request, QList<Synchronizer::SyncRequest> &queue); 192 virtual void mergeIntoQueue(const Synchronizer::SyncRequest &request, QList<Synchronizer::SyncRequest> &queue);
185 193
186 void emitNotification(Notification::NoticationType type, int code, const QString &message, const QByteArray &id = QByteArray{}, const QByteArrayList &entiteis = QByteArrayList{}); 194 void emitNotification(Notification::NoticationType type, int code, const QString &message, const QByteArray &id = QByteArray{}, const QByteArrayList &entiteis = QByteArrayList{});
195 void emitProgressNotification(Notification::NoticationType type, int progress, int total, const QByteArray &id, const QByteArrayList &entities);
187 196
188 /** 197 /**
189 * Report progress for current task 198 * Report progress for current task
@@ -211,6 +220,7 @@ private:
211 Sink::Storage::DataStore::Transaction mSyncTransaction; 220 Sink::Storage::DataStore::Transaction mSyncTransaction;
212 std::function<void(int commandId, const QByteArray &data)> mEnqueue; 221 std::function<void(int commandId, const QByteArray &data)> mEnqueue;
213 QList<SyncRequest> mSyncRequestQueue; 222 QList<SyncRequest> mSyncRequestQueue;
223 SyncRequest mCurrentRequest;
214 MessageQueue *mMessageQueue; 224 MessageQueue *mMessageQueue;
215 bool mSyncInProgress; 225 bool mSyncInProgress;
216 QMultiHash<QByteArray, SyncRequest> mPendingSyncRequests; 226 QMultiHash<QByteArray, SyncRequest> mPendingSyncRequests;
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp
index 8e6d2b1..5aa18dd 100644
--- a/examples/imapresource/imapresource.cpp
+++ b/examples/imapresource/imapresource.cpp
@@ -324,7 +324,7 @@ public:
324 synchronizeMails(folderRemoteId, m); 324 synchronizeMails(folderRemoteId, m);
325 }, 325 },
326 [this, maxUid, folder](int progress, int total) { 326 [this, maxUid, folder](int progress, int total) {
327 SinkLog() << "Progress: " << progress << " out of " << total; 327 reportProgress(progress, total);
328 //commit every 10 messages 328 //commit every 10 messages
329 if ((progress % 10) == 0) { 329 if ((progress % 10) == 0) {
330 commit(); 330 commit();
@@ -365,7 +365,7 @@ public:
365 synchronizeMails(folderRemoteId, m); 365 synchronizeMails(folderRemoteId, m);
366 }, 366 },
367 [=](int progress, int total) { 367 [=](int progress, int total) {
368 SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total; 368 reportProgress(progress, total);
369 //commit every 100 messages 369 //commit every 100 messages
370 if ((progress % 100) == 0) { 370 if ((progress % 100) == 0) {
371 commit(); 371 commit();