From 03f91093dcfd8c7adb3b1ddabbf006ca8e0586a1 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 13 Dec 2015 20:12:15 +0100 Subject: Ensure we process the query also if no resource is available. --- common/clientapi.cpp | 8 -------- common/resultprovider.h | 8 ++++++-- tests/clientapitest.cpp | 10 ++++++++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 46f7534..25f0f1f 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp @@ -91,13 +91,6 @@ QSharedPointer Store::loadModel(Query query) // Query all resources and aggregate results auto resources = getResources(query.resources, ApplicationDomain::getTypeName()); - if (resources.isEmpty()) { - Warning() << "No resources available."; - auto resultProvider = Akonadi2::ResultProvider::Ptr::create(); - model->setEmitter(resultProvider->emitter()); - resultProvider->initialResultSetComplete(typename DomainType::Ptr()); - return model; - } auto aggregatingEmitter = AggregatingResultEmitter::Ptr::create(); model->setEmitter(aggregatingEmitter); KAsync::iterate(resources) @@ -114,7 +107,6 @@ QSharedPointer Store::loadModel(Query query) future.setFinished(); } }).exec(); - //TODO if the aggregatingEmitter is still empty we're done model->fetchMore(QModelIndex()); return model; diff --git a/common/resultprovider.h b/common/resultprovider.h index d94ad44..08a7d53 100644 --- a/common/resultprovider.h +++ b/common/resultprovider.h @@ -362,8 +362,12 @@ public: void fetch(const DomainType &parent) Q_DECL_OVERRIDE { - for (const auto &emitter : mEmitter) { - emitter->fetch(parent); + if (mEmitter.isEmpty()) { + this->initialResultSetComplete(parent); + } else { + for (const auto &emitter : mEmitter) { + emitter->fetch(parent); + } } } diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 5777e68..3a088f8 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -103,6 +103,16 @@ private Q_SLOTS: QCOMPARE(model->rowCount(QModelIndex()), 1); } + void testLoadWithoutResource() + { + Akonadi2::Query query; + query.resources << "nonexisting.resource"; + query.liveQuery = false; + + auto model = Akonadi2::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + } + //TODO: This test doesn't belong to this testsuite void resourceManagement() { -- cgit v1.2.3