From f2f26869ed6efc4faf173b9a5cd5d2f15cec1e06 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 10 Dec 2015 16:40:27 +0100 Subject: Deal with no available resources --- common/clientapi.cpp | 10 +++++++++- common/modelresult.cpp | 6 +++++- tests/querytest.cpp | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 061d920..644d60c 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp @@ -90,7 +90,15 @@ QSharedPointer Store::loadModel(Query query) //* The result provider needs to live for as long as results are provided (until the last thread exits). // Query all resources and aggregate results - KAsync::iterate(getResources(query.resources, ApplicationDomain::getTypeName())) + 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; + } + KAsync::iterate(resources) .template each([query, model](const QByteArray &resource, KAsync::Future &future) { auto facade = FacadeFactory::instance().getFacade(resourceName(resource), resource); if (facade) { diff --git a/common/modelresult.cpp b/common/modelresult.cpp index d2a7e88..d18dba1 100644 --- a/common/modelresult.cpp +++ b/common/modelresult.cpp @@ -203,7 +203,11 @@ void ModelResult::fetchEntities(const QModelIndex &parent) const auto id = getIdentifier(parent); mEntityChildrenFetched.insert(id); Trace() << "Loading child entities"; - loadEntities(parent.data(DomainObjectRole).template value()); + if (loadEntities) { + loadEntities(parent.data(DomainObjectRole).template value()); + } else { + Warning() << "No way to fetch entities"; + } } template diff --git a/tests/querytest.cpp b/tests/querytest.cpp index f0f0766..1192b87 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -43,6 +43,22 @@ private Q_SLOTS: qDebug(); } + void testNoResources() + { + //Test + Akonadi2::Query query; + query.resources << "foobar"; + query.syncOnDemand = false; + query.processAll = false; + query.liveQuery = true; + + //We fetch before the data is available and rely on the live query mechanism to deliver the actual data + auto model = Akonadi2::Store::loadModel(query); + QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()); + QCOMPARE(model->rowCount(), 0); + } + + void testSingle() { //Setup -- cgit v1.2.3