From 4e6b3ce7d1ce97c3e1fb9ae53c5b2be1787acc6b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 11 Nov 2016 13:06:27 +0100 Subject: Prepared new query based synchronization API --- examples/maildirresource/maildirresource.cpp | 54 ++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'examples/maildirresource') 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: SinkLog() << "Synchronized " << count << " mails in " << listingPath << Sink::Log::TraceTime(elapsed) << " " << elapsed/qMax(count, 1) << " [ms/mail]"; } + QList getSyncRequests(const Sink::QueryBase &query) Q_DECL_OVERRIDE + { + QList list; + if (!query.type().isEmpty()) { + //We want to synchronize something specific + list << Synchronizer::SyncRequest{query}; + } else { + //We want to synchronize everything + list << Synchronizer::SyncRequest{Sink::QueryBase(ApplicationDomain::getTypeName())}; + //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. + /* list << Synchronizer::SyncRequest{Flush}; */ + list << Synchronizer::SyncRequest{Sink::QueryBase(ApplicationDomain::getTypeName())}; + } + return list; + } + KAsync::Job synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE { - SinkLog() << " Synchronizing"; - return KAsync::start([this]() { + auto job = KAsync::start([this] { KPIM::Maildir maildir(mMaildirPath, true); if (!maildir.isValid(false)) { return KAsync::error(1, "Maildir path doesn't point to a valid maildir: " + mMaildirPath); } - synchronizeFolders(); - //The next sync needs the folders available - commit(); - for (const auto &folder : listAvailableFolders()) { - synchronizeMails(folder); - //Don't let the transaction grow too much - commit(); - } - SinkLog() << "Done Synchronizing"; return KAsync::null(); }); + + if (query.type() == ApplicationDomain::getTypeName()) { + job = job.syncThen([this] { + synchronizeFolders(); + }); + } else if (query.type() == ApplicationDomain::getTypeName()) { + job = job.syncThen([this, query] { + QStringList folders; + if (query.hasFilter()) { + auto folderFilter = query.getFilter(); + auto localIds = resolveFilter(folderFilter); + auto folderRemoteIds = syncStore().resolveLocalIds(ApplicationDomain::getTypeName(), localIds); + for (const auto &r : folderRemoteIds) { + folders << r; + } + } else { + folders = listAvailableFolders(); + } + for (const auto &folder : folders) { + synchronizeMails(folder); + //Don't let the transaction grow too much + commit(); + } + }); + } + return job; } public: -- cgit v1.2.3