summaryrefslogtreecommitdiffstats
path: root/common/synchronizer.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-24 22:15:18 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-24 22:15:18 +0100
commit9ea268a6d0f4054c31b2729ecd6cfcc9d07a2d6a (patch)
tree41fef7daac9e5ae64d61452a3f38c82243d29fdd /common/synchronizer.cpp
parent84d70933c0cd0987d5fee5a78f413fec82bb1288 (diff)
downloadsink-9ea268a6d0f4054c31b2729ecd6cfcc9d07a2d6a.tar.gz
sink-9ea268a6d0f4054c31b2729ecd6cfcc9d07a2d6a.zip
Implemented notification support in the model.
This will allow us to fold things like progress and sync status directly into the model. Usecases are mail download progress and folder sync progress. Ideally we would also solve the resource/account state through this.
Diffstat (limited to 'common/synchronizer.cpp')
-rw-r--r--common/synchronizer.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp
index 4ed6e3a..ec896ed 100644
--- a/common/synchronizer.cpp
+++ b/common/synchronizer.cpp
@@ -292,13 +292,14 @@ void Synchronizer::flushComplete(const QByteArray &flushId)
292 } 292 }
293} 293}
294 294
295void Synchronizer::emitNotification(Notification::NoticationType type, int code, const QString &message, const QByteArray &id) 295void Synchronizer::emitNotification(Notification::NoticationType type, int code, const QString &message, const QByteArray &id, const QByteArrayList &entities)
296{ 296{
297 Sink::Notification n; 297 Sink::Notification n;
298 n.id = id; 298 n.id = id;
299 n.type = type; 299 n.type = type;
300 n.message = message; 300 n.message = message;
301 n.code = code; 301 n.code = code;
302 n.entities = entities;
302 emit notify(n); 303 emit notify(n);
303} 304}
304 305
@@ -328,6 +329,7 @@ KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request)
328 return KAsync::start([this, request] { 329 return KAsync::start([this, request] {
329 SinkLogCtx(mLogCtx) << "Synchronizing: " << request.query; 330 SinkLogCtx(mLogCtx) << "Synchronizing: " << request.query;
330 emitNotification(Notification::Status, ApplicationDomain::BusyStatus, "Synchronization has started.", request.requestId); 331 emitNotification(Notification::Status, ApplicationDomain::BusyStatus, "Synchronization has started.", request.requestId);
332 emitNotification(Notification::Info, ApplicationDomain::SyncInProgress, {}, {}, request.query.ids());
331 }).then(synchronizeWithSource(request.query)).then([this] { 333 }).then(synchronizeWithSource(request.query)).then([this] {
332 //Commit after every request, so implementations only have to commit more if they add a lot of data. 334 //Commit after every request, so implementations only have to commit more if they add a lot of data.
333 commit(); 335 commit();
@@ -335,10 +337,12 @@ KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request)
335 if (error) { 337 if (error) {
336 //Emit notification with error 338 //Emit notification with error
337 SinkWarningCtx(mLogCtx) << "Synchronization failed: " << error.errorMessage; 339 SinkWarningCtx(mLogCtx) << "Synchronization failed: " << error.errorMessage;
340 emitNotification(Notification::Warning, ApplicationDomain::SyncError, {}, {}, request.query.ids());
338 emitNotification(Notification::Status, ApplicationDomain::ErrorStatus, "Synchronization has ended.", request.requestId); 341 emitNotification(Notification::Status, ApplicationDomain::ErrorStatus, "Synchronization has ended.", request.requestId);
339 return KAsync::error(error); 342 return KAsync::error(error);
340 } else { 343 } else {
341 SinkLogCtx(mLogCtx) << "Done Synchronizing"; 344 SinkLogCtx(mLogCtx) << "Done Synchronizing";
345 emitNotification(Notification::Info, ApplicationDomain::SyncSuccess, {}, {}, request.query.ids());
342 emitNotification(Notification::Status, ApplicationDomain::ConnectedStatus, "Synchronization has ended.", request.requestId); 346 emitNotification(Notification::Status, ApplicationDomain::ConnectedStatus, "Synchronization has ended.", request.requestId);
343 return KAsync::null(); 347 return KAsync::null();
344 } 348 }