diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-11 13:06:27 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-11 15:26:32 +0100 |
commit | 4e6b3ce7d1ce97c3e1fb9ae53c5b2be1787acc6b (patch) | |
tree | 08d80bbe1cc890f949110a760cba18e8f2b5249b /examples/maildirresource/maildirresource.cpp | |
parent | e5bec3abfe2f2463244d65386dbd1088bf56f5f3 (diff) | |
download | sink-4e6b3ce7d1ce97c3e1fb9ae53c5b2be1787acc6b.tar.gz sink-4e6b3ce7d1ce97c3e1fb9ae53c5b2be1787acc6b.zip |
Prepared new query based synchronization API
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 820ec2f..fc77315 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -330,25 +330,57 @@ public: | |||
330 | SinkLog() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; | 330 | SinkLog() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; |
331 | } | 331 | } |
332 | 332 | ||
333 | QList<Synchronizer::SyncRequest> getSyncRequests(const Sink::QueryBase &query) Q_DECL_OVERRIDE | ||
334 | { | ||
335 | QList<Synchronizer::SyncRequest> list; | ||
336 | if (!query.type().isEmpty()) { | ||
337 | //We want to synchronize something specific | ||
338 | list << Synchronizer::SyncRequest{query}; | ||
339 | } else { | ||
340 | //We want to synchronize everything | ||
341 | list << Synchronizer::SyncRequest{Sink::QueryBase(ApplicationDomain::getTypeName<ApplicationDomain::Folder>())}; | ||
342 | //FIXME we can't process the second synchronization before the pipeline of the first one is processed, otherwise we can't execute a query on the local data. | ||
343 | /* list << Synchronizer::SyncRequest{Flush}; */ | ||
344 | list << Synchronizer::SyncRequest{Sink::QueryBase(ApplicationDomain::getTypeName<ApplicationDomain::Mail>())}; | ||
345 | } | ||
346 | return list; | ||
347 | } | ||
348 | |||
333 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE | 349 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE |
334 | { | 350 | { |
335 | SinkLog() << " Synchronizing"; | 351 | auto job = KAsync::start<void>([this] { |
336 | return KAsync::start<void>([this]() { | ||
337 | KPIM::Maildir maildir(mMaildirPath, true); | 352 | KPIM::Maildir maildir(mMaildirPath, true); |
338 | if (!maildir.isValid(false)) { | 353 | if (!maildir.isValid(false)) { |
339 | return KAsync::error<void>(1, "Maildir path doesn't point to a valid maildir: " + mMaildirPath); | 354 | return KAsync::error<void>(1, "Maildir path doesn't point to a valid maildir: " + mMaildirPath); |
340 | } | 355 | } |
341 | synchronizeFolders(); | ||
342 | //The next sync needs the folders available | ||
343 | commit(); | ||
344 | for (const auto &folder : listAvailableFolders()) { | ||
345 | synchronizeMails(folder); | ||
346 | //Don't let the transaction grow too much | ||
347 | commit(); | ||
348 | } | ||
349 | SinkLog() << "Done Synchronizing"; | ||
350 | return KAsync::null<void>(); | 356 | return KAsync::null<void>(); |
351 | }); | 357 | }); |
358 | |||
359 | if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) { | ||
360 | job = job.syncThen<void>([this] { | ||
361 | synchronizeFolders(); | ||
362 | }); | ||
363 | } else if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Mail>()) { | ||
364 | job = job.syncThen<void>([this, query] { | ||
365 | QStringList folders; | ||
366 | if (query.hasFilter<ApplicationDomain::Mail::Folder>()) { | ||
367 | auto folderFilter = query.getFilter<ApplicationDomain::Mail::Folder>(); | ||
368 | auto localIds = resolveFilter(folderFilter); | ||
369 | auto folderRemoteIds = syncStore().resolveLocalIds(ApplicationDomain::getTypeName<ApplicationDomain::Folder>(), localIds); | ||
370 | for (const auto &r : folderRemoteIds) { | ||
371 | folders << r; | ||
372 | } | ||
373 | } else { | ||
374 | folders = listAvailableFolders(); | ||
375 | } | ||
376 | for (const auto &folder : folders) { | ||
377 | synchronizeMails(folder); | ||
378 | //Don't let the transaction grow too much | ||
379 | commit(); | ||
380 | } | ||
381 | }); | ||
382 | } | ||
383 | return job; | ||
352 | } | 384 | } |
353 | 385 | ||
354 | public: | 386 | public: |