diff options
-rw-r--r-- | common/clientapi.h | 2 | ||||
-rw-r--r-- | common/domain/folder.cpp | 1 | ||||
-rw-r--r-- | common/facade.h | 1 | ||||
-rw-r--r-- | common/modelresult.h | 6 | ||||
-rw-r--r-- | examples/client/main.cpp | 7 | ||||
-rw-r--r-- | examples/dummyresource/dummystore.h | 2 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 24 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.h | 1 |
8 files changed, 37 insertions, 7 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index 179bb5c..6b11ad5 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -110,7 +110,7 @@ public: | |||
110 | template <class DomainType> | 110 | template <class DomainType> |
111 | static QSharedPointer<QAbstractItemModel> loadModel(Query query) | 111 | static QSharedPointer<QAbstractItemModel> loadModel(Query query) |
112 | { | 112 | { |
113 | auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr> >::create(query, QList<QByteArray>() << "summary" << "uid"); | 113 | auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr> >::create(query, query.requestedProperties.toList()); |
114 | auto resultProvider = std::make_shared<ModelResultProvider<DomainType, typename DomainType::Ptr> >(model); | 114 | auto resultProvider = std::make_shared<ModelResultProvider<DomainType, typename DomainType::Ptr> >(model); |
115 | //Keep the resultprovider alive for as long as the model lives | 115 | //Keep the resultprovider alive for as long as the model lives |
116 | model->setProperty("resultProvider", QVariant::fromValue(std::shared_ptr<void>(resultProvider))); | 116 | model->setProperty("resultProvider", QVariant::fromValue(std::shared_ptr<void>(resultProvider))); |
diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp index 82f6c1f..989d2c4 100644 --- a/common/domain/folder.cpp +++ b/common/domain/folder.cpp | |||
@@ -60,6 +60,7 @@ void TypeImplementation<Folder>::index(const QByteArray &identifier, const Buffe | |||
60 | const auto parent = bufferAdaptor.getProperty("parent"); | 60 | const auto parent = bufferAdaptor.getProperty("parent"); |
61 | Trace() << "indexing " << identifier << " with parent " << parent.toByteArray(); | 61 | Trace() << "indexing " << identifier << " with parent " << parent.toByteArray(); |
62 | if (parent.isValid()) { | 62 | if (parent.isValid()) { |
63 | Q_ASSERT(!parent.toByteArray().isEmpty()); | ||
63 | Index("folder.index.parent", transaction).add(parent.toByteArray(), identifier); | 64 | Index("folder.index.parent", transaction).add(parent.toByteArray(), identifier); |
64 | } else { | 65 | } else { |
65 | Index("folder.index.parent", transaction).add("toplevel", identifier); | 66 | Index("folder.index.parent", transaction).add("toplevel", identifier); |
diff --git a/common/facade.h b/common/facade.h index f5c05f9..d150d60 100644 --- a/common/facade.h +++ b/common/facade.h | |||
@@ -184,7 +184,6 @@ public: | |||
184 | //Incremental updates are always loaded directly, leaving it up to the result to discard the changes if they are not interesting | 184 | //Incremental updates are always loaded directly, leaving it up to the result to discard the changes if they are not interesting |
185 | runner->setQuery([this, query, &resultProvider] () -> KAsync::Job<void> { | 185 | runner->setQuery([this, query, &resultProvider] () -> KAsync::Job<void> { |
186 | return KAsync::start<void>([this, query, &resultProvider](KAsync::Future<void> &future) { | 186 | return KAsync::start<void>([this, query, &resultProvider](KAsync::Future<void> &future) { |
187 | Trace() << "Executing query "; | ||
188 | const qint64 newRevision = executeIncrementalQuery(query, resultProvider); | 187 | const qint64 newRevision = executeIncrementalQuery(query, resultProvider); |
189 | mResourceAccess->sendRevisionReplayedCommand(newRevision); | 188 | mResourceAccess->sendRevisionReplayedCommand(newRevision); |
190 | future.setFinished(); | 189 | future.setFinished(); |
diff --git a/common/modelresult.h b/common/modelresult.h index 3b45955..1675e60 100644 --- a/common/modelresult.h +++ b/common/modelresult.h | |||
@@ -131,7 +131,11 @@ public: | |||
131 | break; | 131 | break; |
132 | } | 132 | } |
133 | } | 133 | } |
134 | beginInsertRows(parent, index, index); | 134 | if (mEntities.contains(childId)) { |
135 | qWarning() << "Entity already in model " << value->identifier(); | ||
136 | return; | ||
137 | } | ||
138 | beginInsertRows(QModelIndex(), index, index); | ||
135 | mEntities.insert(childId, value); | 139 | mEntities.insert(childId, value); |
136 | mTree[id].insert(index, childId); | 140 | mTree[id].insert(index, childId); |
137 | mParents.insert(childId, id); | 141 | mParents.insert(childId, id); |
diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 75fcf18..794fc58 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "common/resource.h" | 25 | #include "common/resource.h" |
26 | #include "common/storage.h" | 26 | #include "common/storage.h" |
27 | #include "common/domain/event.h" | 27 | #include "common/domain/event.h" |
28 | #include "common/domain/folder.h" | ||
28 | #include "common/resourceconfig.h" | 29 | #include "common/resourceconfig.h" |
29 | #include "console.h" | 30 | #include "console.h" |
30 | 31 | ||
@@ -124,10 +125,10 @@ int main(int argc, char *argv[]) | |||
124 | query.syncOnDemand = false; | 125 | query.syncOnDemand = false; |
125 | query.processAll = false; | 126 | query.processAll = false; |
126 | query.liveQuery = true; | 127 | query.liveQuery = true; |
127 | query.requestedProperties << "summary" << "uid"; | 128 | query.requestedProperties << "name"; |
128 | 129 | ||
129 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Event>(query); | 130 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); |
130 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Event> >::create(model.data()); | 131 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Folder> >::create(model.data()); |
131 | 132 | ||
132 | return app.exec(); | 133 | return app.exec(); |
133 | } | 134 | } |
diff --git a/examples/dummyresource/dummystore.h b/examples/dummyresource/dummystore.h index 4ecd5ea..c730118 100644 --- a/examples/dummyresource/dummystore.h +++ b/examples/dummyresource/dummystore.h | |||
@@ -23,7 +23,6 @@ | |||
23 | class DummyStore | 23 | class DummyStore |
24 | { | 24 | { |
25 | public: | 25 | public: |
26 | //TODO proper singleton | ||
27 | static DummyStore &instance() | 26 | static DummyStore &instance() |
28 | { | 27 | { |
29 | static DummyStore instance; | 28 | static DummyStore instance; |
@@ -32,4 +31,5 @@ public: | |||
32 | 31 | ||
33 | QMap<QString, QMap<QString, QVariant> > events() const; | 32 | QMap<QString, QMap<QString, QVariant> > events() const; |
34 | QMap<QString, QMap<QString, QVariant> > mails() const; | 33 | QMap<QString, QMap<QString, QVariant> > mails() const; |
34 | QMap<QString, QMap<QString, QVariant> > folders() const; | ||
35 | }; | 35 | }; |
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index bed1d71..2a5a3e8 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp | |||
@@ -163,6 +163,27 @@ void DummyResource::createMail(const QByteArray &ridBuffer, const QMap<QString, | |||
163 | Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize()); | 163 | Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize()); |
164 | } | 164 | } |
165 | 165 | ||
166 | void DummyResource::createFolder(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb) | ||
167 | { | ||
168 | //Map the source format to the buffer format (which happens to be an exact copy here) | ||
169 | auto name = m_fbb.CreateString(data.value("name").toString().toStdString()); | ||
170 | flatbuffers::Offset<flatbuffers::String> parent; | ||
171 | bool hasParent = false; | ||
172 | if (!data.value("parent").toString().isEmpty()) { | ||
173 | hasParent = true; | ||
174 | parent = m_fbb.CreateString(data.value("parent").toString().toStdString()); | ||
175 | } | ||
176 | |||
177 | auto builder = Akonadi2::ApplicationDomain::Buffer::FolderBuilder(m_fbb); | ||
178 | builder.add_name(name); | ||
179 | if (hasParent) { | ||
180 | builder.add_parent(parent); | ||
181 | } | ||
182 | auto buffer = builder.Finish(); | ||
183 | Akonadi2::ApplicationDomain::Buffer::FinishFolderBuffer(m_fbb, buffer); | ||
184 | Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize()); | ||
185 | } | ||
186 | |||
166 | void DummyResource::synchronize(const QString &bufferType, const QMap<QString, QMap<QString, QVariant> > &data, Akonadi2::Storage::Transaction &transaction, std::function<void(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb)> createEntity) | 187 | void DummyResource::synchronize(const QString &bufferType, const QMap<QString, QMap<QString, QVariant> > &data, Akonadi2::Storage::Transaction &transaction, std::function<void(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb)> createEntity) |
167 | { | 188 | { |
168 | Index uidIndex("index.uid", transaction); | 189 | Index uidIndex("index.uid", transaction); |
@@ -209,6 +230,9 @@ KAsync::Job<void> DummyResource::synchronizeWithSource() | |||
209 | synchronize(ENTITY_TYPE_MAIL, DummyStore::instance().mails(), transaction, [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb) { | 230 | synchronize(ENTITY_TYPE_MAIL, DummyStore::instance().mails(), transaction, [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb) { |
210 | createMail(ridBuffer, data, entityFbb); | 231 | createMail(ridBuffer, data, entityFbb); |
211 | }); | 232 | }); |
233 | synchronize(ENTITY_TYPE_FOLDER, DummyStore::instance().folders(), transaction, [this](const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb) { | ||
234 | createFolder(ridBuffer, data, entityFbb); | ||
235 | }); | ||
212 | 236 | ||
213 | f.setFinished(); | 237 | f.setFinished(); |
214 | }); | 238 | }); |
diff --git a/examples/dummyresource/resourcefactory.h b/examples/dummyresource/resourcefactory.h index 196d29a..67681ae 100644 --- a/examples/dummyresource/resourcefactory.h +++ b/examples/dummyresource/resourcefactory.h | |||
@@ -38,6 +38,7 @@ public: | |||
38 | private: | 38 | private: |
39 | void createEvent(const QByteArray &rid, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb); | 39 | void createEvent(const QByteArray &rid, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb); |
40 | void createMail(const QByteArray &rid, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb); | 40 | void createMail(const QByteArray &rid, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb); |
41 | void createFolder(const QByteArray &rid, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb); | ||
41 | void synchronize(const QString &bufferType, const QMap<QString, QMap<QString, QVariant> > &data, Akonadi2::Storage::Transaction &transaction, std::function<void(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb)> createEntity); | 42 | void synchronize(const QString &bufferType, const QMap<QString, QMap<QString, QVariant> > &data, Akonadi2::Storage::Transaction &transaction, std::function<void(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb)> createEntity); |
42 | }; | 43 | }; |
43 | 44 | ||