From 25d08af0851b56db664cee7f6463532d7c103d33 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 31 Oct 2015 21:08:39 +0100 Subject: Fixed shutdown and synchronize commands --- common/clientapi.cpp | 23 ++++++++++++++++------- common/clientapi.h | 11 ++++++++--- 2 files changed, 24 insertions(+), 10 deletions(-) (limited to 'common') diff --git a/common/clientapi.cpp b/common/clientapi.cpp index aa3abb4..f99ebb8 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp @@ -69,10 +69,10 @@ QList Store::getResources(const QList &resourceFilter, c return resources; } -void Store::shutdown(const QByteArray &identifier) +KAsync::Job Store::shutdown(const QByteArray &identifier) { Trace() << "shutdown"; - ResourceAccess::connectToServer(identifier).then>([identifier](const QSharedPointer &socket, KAsync::Future &future) { + return ResourceAccess::connectToServer(identifier).then>([identifier](QSharedPointer socket, KAsync::Future &future) { //We can't currently reuse the socket socket->close(); auto resourceAccess = QSharedPointer::create(identifier); @@ -83,15 +83,24 @@ void Store::shutdown(const QByteArray &identifier) }, [](int, const QString &) { //Resource isn't started, nothing to shutdown - }).exec().waitForFinished(); + }) + //FIXME JOBAPI this is only required because we don't care about the return value of connectToServer + .template then([](){}); } -void Store::synchronize(const QByteArray &identifier) +KAsync::Job Store::synchronize(const Akonadi2::Query &query) { Trace() << "synchronize"; - auto resourceAccess = QSharedPointer::create(identifier); - resourceAccess->open(); - resourceAccess->synchronizeResource(true, false).exec().waitForFinished(); + return KAsync::iterate(query.resources) + .template each([query](const QByteArray &resource, KAsync::Future &future) { + auto resourceAccess = QSharedPointer::create(resource); + resourceAccess->open(); + resourceAccess->synchronizeResource(true, false).then([&future]() { + future.setFinished(); + }).exec(); + }) + //FIXME JOBAPI this is only required because we don't care about the return value of each (and each shouldn't even have a return value) + .template then([](){}); } } // namespace Akonadi2 diff --git a/common/clientapi.h b/common/clientapi.h index 4e6db09..9a32188 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -153,10 +153,15 @@ public: }); } - static void shutdown(const QByteArray &resourceIdentifier); + /** + * Shutdown resource. + */ + static KAsync::Job shutdown(const QByteArray &resourceIdentifier); - //TODO do we really want this command? And if yes, shouldn't it take a query to specify what to sync exactly? - static void synchronize(const QByteArray &resourceIdentifier); + /** + * Synchronize data to local cache. + */ + static KAsync::Job synchronize(const Akonadi2::Query &query); }; -- cgit v1.2.3