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 ++++++++--- examples/client/main.cpp | 4 +++- tests/dummyresourcetest.cpp | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) 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); }; diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 52f3607..0a1a725 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -59,7 +59,9 @@ public: auto syncButton = new QPushButton(this); syncButton->setText("Synchronize!"); QObject::connect(syncButton, &QPushButton::pressed, []() { - Akonadi2::Store::synchronize("org.kde.dummy.instance1"); + Akonadi2::Query query; + query.resources << "org.kde.dummy.instance1"; + Akonadi2::Store::synchronize(query); }); auto removeButton = new QPushButton(this); diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index ae71912..d027266 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -31,7 +31,7 @@ private Q_SLOTS: void cleanup() { - Akonadi2::Store::shutdown("org.kde.dummy.instance1"); + Akonadi2::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); DummyResource::removeFromDisk("org.kde.dummy.instance1"); auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); -- cgit v1.2.3