summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-13 20:12:15 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-13 20:12:15 +0100
commit03f91093dcfd8c7adb3b1ddabbf006ca8e0586a1 (patch)
tree8f84eebd41d217aa7ec0618ca4ee126d2e38966c
parent1aa82ab9cfacca1ee9af9f9137caeede55f89230 (diff)
downloadsink-03f91093dcfd8c7adb3b1ddabbf006ca8e0586a1.tar.gz
sink-03f91093dcfd8c7adb3b1ddabbf006ca8e0586a1.zip
Ensure we process the query also if no resource is available.
-rw-r--r--common/clientapi.cpp8
-rw-r--r--common/resultprovider.h8
-rw-r--r--tests/clientapitest.cpp10
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<QAbstractItemModel> Store::loadModel(Query query)
91 91
92 // Query all resources and aggregate results 92 // Query all resources and aggregate results
93 auto resources = getResources(query.resources, ApplicationDomain::getTypeName<DomainType>()); 93 auto resources = getResources(query.resources, ApplicationDomain::getTypeName<DomainType>());
94 if (resources.isEmpty()) {
95 Warning() << "No resources available.";
96 auto resultProvider = Akonadi2::ResultProvider<typename DomainType::Ptr>::Ptr::create();
97 model->setEmitter(resultProvider->emitter());
98 resultProvider->initialResultSetComplete(typename DomainType::Ptr());
99 return model;
100 }
101 auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); 94 auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create();
102 model->setEmitter(aggregatingEmitter); 95 model->setEmitter(aggregatingEmitter);
103 KAsync::iterate(resources) 96 KAsync::iterate(resources)
@@ -114,7 +107,6 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query)
114 future.setFinished(); 107 future.setFinished();
115 } 108 }
116 }).exec(); 109 }).exec();
117 //TODO if the aggregatingEmitter is still empty we're done
118 model->fetchMore(QModelIndex()); 110 model->fetchMore(QModelIndex());
119 111
120 return model; 112 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:
362 362
363 void fetch(const DomainType &parent) Q_DECL_OVERRIDE 363 void fetch(const DomainType &parent) Q_DECL_OVERRIDE
364 { 364 {
365 for (const auto &emitter : mEmitter) { 365 if (mEmitter.isEmpty()) {
366 emitter->fetch(parent); 366 this->initialResultSetComplete(parent);
367 } else {
368 for (const auto &emitter : mEmitter) {
369 emitter->fetch(parent);
370 }
367 } 371 }
368 } 372 }
369 373
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:
103 QCOMPARE(model->rowCount(QModelIndex()), 1); 103 QCOMPARE(model->rowCount(QModelIndex()), 1);
104 } 104 }
105 105
106 void testLoadWithoutResource()
107 {
108 Akonadi2::Query query;
109 query.resources << "nonexisting.resource";
110 query.liveQuery = false;
111
112 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Event>(query);
113 QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
114 }
115
106 //TODO: This test doesn't belong to this testsuite 116 //TODO: This test doesn't belong to this testsuite
107 void resourceManagement() 117 void resourceManagement()
108 { 118 {