summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/dummyresource/facade.cpp43
1 files changed, 38 insertions, 5 deletions
diff --git a/examples/dummyresource/facade.cpp b/examples/dummyresource/facade.cpp
index 5e0bada..9722335 100644
--- a/examples/dummyresource/facade.cpp
+++ b/examples/dummyresource/facade.cpp
@@ -126,8 +126,41 @@ void DummyResourceFacade::readValue(const QSharedPointer<Akonadi2::Storage> &sto
126 }); 126 });
127} 127}
128 128
129//TODO this should return an iterator to the result set so we can lazy load 129/*
130static QVector<QByteArray> getResultSet(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::Storage> &storage) 130 * An iterator to a result set.
131 *
132 * We'll eventually want to lazy load results in next().
133 */
134class ResultSet {
135 public:
136 ResultSet(const QVector<QByteArray> &resultSet)
137 : mResultSet(resultSet),
138 mIt(nullptr)
139 {
140
141 }
142
143 bool next()
144 {
145 if (!mIt) {
146 mIt = mResultSet.constBegin();
147 } else {
148 mIt++;
149 }
150 return mIt != mResultSet.constEnd();
151 }
152
153 QByteArray id()
154 {
155 return *mIt;
156 }
157
158 private:
159 QVector<QByteArray> mResultSet;
160 QVector<QByteArray>::ConstIterator mIt;
161};
162
163static ResultSet getResultSet(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::Storage> &storage)
131{ 164{
132 //Now that the sync is complete we can execute the query 165 //Now that the sync is complete we can execute the query
133 const auto preparedQuery = prepareQuery(query); 166 const auto preparedQuery = prepareQuery(query);
@@ -156,7 +189,7 @@ static QVector<QByteArray> getResultSet(const Akonadi2::Query &query, const QSha
156 }); 189 });
157 } 190 }
158 191
159 return keys; 192 return ResultSet(keys);
160} 193}
161 194
162KAsync::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) 195KAsync::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision)
@@ -176,8 +209,8 @@ KAsync::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, cons
176 // TODO only emit changes and don't replace everything 209 // TODO only emit changes and don't replace everything
177 resultProvider->clear(); 210 resultProvider->clear();
178 auto resultCallback = std::bind(&Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr>::add, resultProvider, std::placeholders::_1); 211 auto resultCallback = std::bind(&Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr>::add, resultProvider, std::placeholders::_1);
179 for (const auto &key : resultSet) { 212 while (resultSet.next()) {
180 readValue(storage, key, [resultCallback](const Akonadi2::ApplicationDomain::Event::Ptr &event) { 213 readValue(storage, resultSet.id(), [resultCallback](const Akonadi2::ApplicationDomain::Event::Ptr &event) {
181 //We create an in-memory copy because the result provider will store the value, and the result we get back is only valid during the callback 214 //We create an in-memory copy because the result provider will store the value, and the result we get back is only valid during the callback
182 resultCallback(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<Akonadi2::ApplicationDomain::Event>(event)); 215 resultCallback(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<Akonadi2::ApplicationDomain::Event>(event));
183 }); 216 });