summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-27 10:56:50 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-27 10:56:50 +0200
commited73e44d5ee7aaaeaa5130a08243909f2d45dcce (patch)
treed557d752bbd6244f83122ae5bdf151da89a1affe
parent71fd88a5b5839b228c824e61028787be8e825dad (diff)
downloadsink-ed73e44d5ee7aaaeaa5130a08243909f2d45dcce.tar.gz
sink-ed73e44d5ee7aaaeaa5130a08243909f2d45dcce.zip
Moved the non-generic code back to dummyresource.
The dummy resource could now implement incremental queries.
-rw-r--r--common/facade.h10
-rw-r--r--examples/dummyresource/facade.cpp7
-rw-r--r--examples/dummyresource/facade.h2
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:
148 auto runner = QSharedPointer<QueryRunner>::create(query); 148 auto runner = QSharedPointer<QueryRunner>::create(query);
149 QWeakPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > weakResultProvider = resultProvider; 149 QWeakPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > weakResultProvider = resultProvider;
150 runner->setQuery([this, weakResultProvider, query] (qint64 oldRevision, qint64 newRevision) -> Async::Job<qint64> { 150 runner->setQuery([this, weakResultProvider, query] (qint64 oldRevision, qint64 newRevision) -> Async::Job<qint64> {
151 return Async::start<qint64>([this, weakResultProvider, query](Async::Future<qint64> &future) { 151 return Async::start<qint64>([this, weakResultProvider, query, oldRevision, newRevision](Async::Future<qint64> &future) {
152 auto resultProvider = weakResultProvider.toStrongRef(); 152 auto resultProvider = weakResultProvider.toStrongRef();
153 if (!resultProvider) { 153 if (!resultProvider) {
154 Warning() << "Tried executing query after result provider is already gone"; 154 Warning() << "Tried executing query after result provider is already gone";
@@ -156,11 +156,7 @@ public:
156 future.setFinished(); 156 future.setFinished();
157 return; 157 return;
158 } 158 }
159 //TODO only emit changes and don't replace everything 159 load(query, resultProvider, oldRevision, newRevision).template then<void, qint64>([&future](qint64 queriedRevision) {
160 resultProvider->clear();
161 //rerun query
162 auto addCallback = std::bind(&Akonadi2::ResultProvider<typename DomainType::Ptr>::add, resultProvider, std::placeholders::_1);
163 load(query, addCallback).template then<void, qint64>([resultProvider, &future](qint64 queriedRevision) {
164 //TODO set revision in result provider? 160 //TODO set revision in result provider?
165 //TODO update all existing results with new revision 161 //TODO update all existing results with new revision
166 future.setValue(queriedRevision); 162 future.setValue(queriedRevision);
@@ -214,7 +210,7 @@ protected:
214 return Async::null<void>(); 210 return Async::null<void>();
215 } 211 }
216 212
217 virtual Async::Job<qint64> load(const Akonadi2::Query &query, const std::function<void(const typename DomainType::Ptr &)> &resultCallback) { return Async::null<qint64>(); }; 213 virtual Async::Job<qint64> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) { return Async::null<qint64>(); };
218 214
219protected: 215protected:
220 //TODO use one resource access instance per application => make static 216 //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<Akonadi2::Storage> storage, c
127 }); 127 });
128} 128}
129 129
130Async::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback) 130Async::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision)
131{ 131{
132 return Async::start<qint64>([=](Async::Future<qint64> &future) { 132 return Async::start<qint64>([=](Async::Future<qint64> &future) {
133 //Now that the sync is complete we can execute the query 133 //Now that the sync is complete we can execute the query
@@ -153,6 +153,11 @@ Async::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const
153 }); 153 });
154 } 154 }
155 155
156 // TODO only emit changes and don't replace everything
157 resultProvider->clear();
158 // rerun query
159 auto resultCallback = std::bind(&Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr>::add, resultProvider, std::placeholders::_1);
160
156 if (keys.isEmpty()) { 161 if (keys.isEmpty()) {
157 Log() << "Executing a full scan"; 162 Log() << "Executing a full scan";
158 readValue(storage, QByteArray(), resultCallback, preparedQuery); 163 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<Akonadi2::Application
34public: 34public:
35 DummyResourceFacade(); 35 DummyResourceFacade();
36 virtual ~DummyResourceFacade(); 36 virtual ~DummyResourceFacade();
37 Async::Job<qint64> load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback) Q_DECL_OVERRIDE; 37 Async::Job<qint64> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) Q_DECL_OVERRIDE;
38 38
39private: 39private:
40 void readValue(QSharedPointer<Akonadi2::Storage> storage, const QByteArray &key, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback, std::function<bool(const std::string &key, DummyCalendar::DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local)>); 40 void readValue(QSharedPointer<Akonadi2::Storage> storage, const QByteArray &key, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback, std::function<bool(const std::string &key, DummyCalendar::DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local)>);