diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-17 15:29:28 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-17 15:29:28 +0100 |
commit | efc3ca52c338a6b8fca8c523dec86f2c9e84f1c0 (patch) | |
tree | 6d090e5b23ec06dd3f42931cc3995dc19e820d53 | |
parent | f4cba9977d46bd94b19586e31f1bea250f211c0c (diff) | |
download | sink-efc3ca52c338a6b8fca8c523dec86f2c9e84f1c0.tar.gz sink-efc3ca52c338a6b8fca8c523dec86f2c9e84f1c0.zip |
emitNotification function
-rw-r--r-- | common/synchronizer.cpp | 36 | ||||
-rw-r--r-- | common/synchronizer.h | 3 | ||||
-rw-r--r-- | examples/mailtransportresource/mailtransportresource.cpp | 14 |
3 files changed, 19 insertions, 34 deletions
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index c7c0af5..ff13783 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp | |||
@@ -292,6 +292,16 @@ void Synchronizer::flushComplete(const QByteArray &flushId) | |||
292 | } | 292 | } |
293 | } | 293 | } |
294 | 294 | ||
295 | void Synchronizer::emitNotification(Notification::NoticationType type, int code, const QString &message, const QByteArray &id) | ||
296 | { | ||
297 | Sink::Notification n; | ||
298 | n.id = id; | ||
299 | n.type = type; | ||
300 | n.message = message; | ||
301 | n.code = code; | ||
302 | emit notify(n); | ||
303 | } | ||
304 | |||
295 | KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request) | 305 | KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request) |
296 | { | 306 | { |
297 | if (request.options & SyncRequest::RequestFlush) { | 307 | if (request.options & SyncRequest::RequestFlush) { |
@@ -316,13 +326,8 @@ KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request) | |||
316 | }); | 326 | }); |
317 | } else if (request.requestType == Synchronizer::SyncRequest::Synchronization) { | 327 | } else if (request.requestType == Synchronizer::SyncRequest::Synchronization) { |
318 | return KAsync::start([this, request] { | 328 | return KAsync::start([this, request] { |
319 | Sink::Notification n; | ||
320 | n.id = request.requestId; | ||
321 | n.type = Notification::Status; | ||
322 | n.message = "Synchronization has started."; | ||
323 | n.code = ApplicationDomain::BusyStatus; | ||
324 | emit notify(n); | ||
325 | SinkLogCtx(mLogCtx) << "Synchronizing: " << request.query; | 329 | SinkLogCtx(mLogCtx) << "Synchronizing: " << request.query; |
330 | emitNotification(Notification::Status, ApplicationDomain::BusyStatus, "Synchronization has started.", request.requestId); | ||
326 | }).then(synchronizeWithSource(request.query)).then([this] { | 331 | }).then(synchronizeWithSource(request.query)).then([this] { |
327 | //Commit after every request, so implementations only have to commit more if they add a lot of data. | 332 | //Commit after every request, so implementations only have to commit more if they add a lot of data. |
328 | commit(); | 333 | commit(); |
@@ -330,21 +335,11 @@ KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request) | |||
330 | if (error) { | 335 | if (error) { |
331 | //Emit notification with error | 336 | //Emit notification with error |
332 | SinkWarningCtx(mLogCtx) << "Synchronization failed: " << error.errorMessage; | 337 | SinkWarningCtx(mLogCtx) << "Synchronization failed: " << error.errorMessage; |
333 | Sink::Notification n; | 338 | emitNotification(Notification::Status, ApplicationDomain::ErrorStatus, "Synchronization has ended.", request.requestId); |
334 | n.id = request.requestId; | ||
335 | n.type = Notification::Status; | ||
336 | n.message = "Synchronization has ended."; | ||
337 | n.code = ApplicationDomain::ErrorStatus; | ||
338 | emit notify(n); | ||
339 | return KAsync::error(error); | 339 | return KAsync::error(error); |
340 | } else { | 340 | } else { |
341 | SinkLogCtx(mLogCtx) << "Done Synchronizing"; | 341 | SinkLogCtx(mLogCtx) << "Done Synchronizing"; |
342 | Sink::Notification n; | 342 | emitNotification(Notification::Status, ApplicationDomain::ConnectedStatus, "Synchronization has ended.", request.requestId); |
343 | n.id = request.requestId; | ||
344 | n.type = Notification::Status; | ||
345 | n.message = "Synchronization has ended."; | ||
346 | n.code = ApplicationDomain::ConnectedStatus; | ||
347 | emit notify(n); | ||
348 | return KAsync::null(); | 343 | return KAsync::null(); |
349 | } | 344 | } |
350 | }); | 345 | }); |
@@ -354,10 +349,7 @@ KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request) | |||
354 | //FIXME it looks like this is emitted before the replay actually finishes | 349 | //FIXME it looks like this is emitted before the replay actually finishes |
355 | if (request.flushType == Flush::FlushReplayQueue) { | 350 | if (request.flushType == Flush::FlushReplayQueue) { |
356 | SinkTraceCtx(mLogCtx) << "Emitting flush completion: " << request.requestId; | 351 | SinkTraceCtx(mLogCtx) << "Emitting flush completion: " << request.requestId; |
357 | Sink::Notification n; | 352 | emitNotification(Notification::FlushCompletion, 0, "", request.requestId); |
358 | n.type = Sink::Notification::FlushCompletion; | ||
359 | n.id = request.requestId; | ||
360 | emit notify(n); | ||
361 | } else { | 353 | } else { |
362 | flatbuffers::FlatBufferBuilder fbb; | 354 | flatbuffers::FlatBufferBuilder fbb; |
363 | auto flushId = fbb.CreateString(request.requestId.toStdString()); | 355 | auto flushId = fbb.CreateString(request.requestId.toStdString()); |
diff --git a/common/synchronizer.h b/common/synchronizer.h index 45ec9e7..28fe645 100644 --- a/common/synchronizer.h +++ b/common/synchronizer.h | |||
@@ -180,8 +180,11 @@ protected: | |||
180 | */ | 180 | */ |
181 | virtual void mergeIntoQueue(const Synchronizer::SyncRequest &request, QList<Synchronizer::SyncRequest> &queue); | 181 | virtual void mergeIntoQueue(const Synchronizer::SyncRequest &request, QList<Synchronizer::SyncRequest> &queue); |
182 | 182 | ||
183 | void emitNotification(Notification::NoticationType type, int code, const QString &message, const QByteArray &id = QByteArray{}); | ||
184 | |||
183 | protected: | 185 | protected: |
184 | Sink::Log::Context mLogCtx; | 186 | Sink::Log::Context mLogCtx; |
187 | |||
185 | private: | 188 | private: |
186 | void modifyIfChanged(Storage::EntityStore &store, const QByteArray &bufferType, const QByteArray &sinkId, const Sink::ApplicationDomain::ApplicationDomainType &entity); | 189 | void modifyIfChanged(Storage::EntityStore &store, const QByteArray &bufferType, const QByteArray &sinkId, const Sink::ApplicationDomain::ApplicationDomainType &entity); |
187 | KAsync::Job<void> processRequest(const SyncRequest &request); | 190 | KAsync::Job<void> processRequest(const SyncRequest &request); |
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index a6460f1..72fe59d 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp | |||
@@ -81,20 +81,10 @@ public: | |||
81 | } | 81 | } |
82 | if (!MailTransport::sendMessage(msg, settings.server.toUtf8(), settings.username.toUtf8(), settings.password.toUtf8(), settings.cacert.toUtf8(), options)) { | 82 | if (!MailTransport::sendMessage(msg, settings.server.toUtf8(), settings.username.toUtf8(), settings.password.toUtf8(), settings.cacert.toUtf8(), options)) { |
83 | SinkWarning() << "Failed to send message: " << mail; | 83 | SinkWarning() << "Failed to send message: " << mail; |
84 | //Emit failure notification | 84 | emitNotification(Notification::Warning, Notification::TransmissionFailed, "Failed to send message."); |
85 | Sink::Notification n; | ||
86 | n.type = Notification::Warning; | ||
87 | n.message = "Failed to send message."; | ||
88 | n.code = Notification::TransmissionFailed; | ||
89 | emit notify(n); | ||
90 | return KAsync::error("Failed to send the message."); | 85 | return KAsync::error("Failed to send the message."); |
91 | } else { | 86 | } else { |
92 | //Emit success notification | 87 | emitNotification(Notification::Info, Notification::TransmissionSucceeded, "Message successfully sent."); |
93 | Sink::Notification n; | ||
94 | n.type = Notification::Info; | ||
95 | n.message = "Message successfully sent."; | ||
96 | n.code = Notification::TransmissionSucceeded; | ||
97 | emit notify(n); | ||
98 | } | 88 | } |
99 | } | 89 | } |
100 | syncStore().writeValue(mail.identifier(), "sent"); | 90 | syncStore().writeValue(mail.identifier(), "sent"); |