From ed73e44d5ee7aaaeaa5130a08243909f2d45dcce Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 27 Apr 2015 10:56:50 +0200 Subject: Moved the non-generic code back to dummyresource. The dummy resource could now implement incremental queries. --- common/facade.h | 10 +++------- examples/dummyresource/facade.cpp | 7 ++++++- examples/dummyresource/facade.h | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/common/facade.h b/common/facade.h index b6ae4a6..541d1ce 100644 --- a/common/facade.h +++ b/common/facade.h @@ -148,7 +148,7 @@ public: auto runner = QSharedPointer::create(query); QWeakPointer > weakResultProvider = resultProvider; runner->setQuery([this, weakResultProvider, query] (qint64 oldRevision, qint64 newRevision) -> Async::Job { - return Async::start([this, weakResultProvider, query](Async::Future &future) { + return Async::start([this, weakResultProvider, query, oldRevision, newRevision](Async::Future &future) { auto resultProvider = weakResultProvider.toStrongRef(); if (!resultProvider) { Warning() << "Tried executing query after result provider is already gone"; @@ -156,11 +156,7 @@ public: future.setFinished(); return; } - //TODO only emit changes and don't replace everything - resultProvider->clear(); - //rerun query - auto addCallback = std::bind(&Akonadi2::ResultProvider::add, resultProvider, std::placeholders::_1); - load(query, addCallback).template then([resultProvider, &future](qint64 queriedRevision) { + load(query, resultProvider, oldRevision, newRevision).template then([&future](qint64 queriedRevision) { //TODO set revision in result provider? //TODO update all existing results with new revision future.setValue(queriedRevision); @@ -214,7 +210,7 @@ protected: return Async::null(); } - virtual Async::Job load(const Akonadi2::Query &query, const std::function &resultCallback) { return Async::null(); }; + virtual Async::Job load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider, qint64 oldRevision, qint64 newRevision) { return Async::null(); }; protected: //TODO use one resource access instance per application => make static diff --git a/examples/dummyresource/facade.cpp b/examples/dummyresource/facade.cpp index 37f75ae..c1e7a64 100644 --- a/examples/dummyresource/facade.cpp +++ b/examples/dummyresource/facade.cpp @@ -127,7 +127,7 @@ void DummyResourceFacade::readValue(QSharedPointer storage, c }); } -Async::Job DummyResourceFacade::load(const Akonadi2::Query &query, const std::function &resultCallback) +Async::Job DummyResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider, qint64 oldRevision, qint64 newRevision) { return Async::start([=](Async::Future &future) { //Now that the sync is complete we can execute the query @@ -153,6 +153,11 @@ Async::Job DummyResourceFacade::load(const Akonadi2::Query &query, const }); } + // TODO only emit changes and don't replace everything + resultProvider->clear(); + // rerun query + auto resultCallback = std::bind(&Akonadi2::ResultProvider::add, resultProvider, std::placeholders::_1); + if (keys.isEmpty()) { Log() << "Executing a full scan"; readValue(storage, QByteArray(), resultCallback, preparedQuery); diff --git a/examples/dummyresource/facade.h b/examples/dummyresource/facade.h index 2fd2fa9..d0af487 100644 --- a/examples/dummyresource/facade.h +++ b/examples/dummyresource/facade.h @@ -34,7 +34,7 @@ class DummyResourceFacade : public Akonadi2::GenericFacade load(const Akonadi2::Query &query, const std::function &resultCallback) Q_DECL_OVERRIDE; + Async::Job load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider, qint64 oldRevision, qint64 newRevision) Q_DECL_OVERRIDE; private: void readValue(QSharedPointer storage, const QByteArray &key, const std::function &resultCallback, std::function); -- cgit v1.2.3