From 8d5684292ef92f32487ba32df716a00c4a0841b5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 19 Nov 2015 17:37:39 +0100 Subject: Loading data with the new model for the test client --- common/clientapi.h | 2 +- common/domain/folder.cpp | 1 + common/facade.h | 1 - common/modelresult.h | 6 +++++- examples/client/main.cpp | 7 ++++--- examples/dummyresource/dummystore.h | 2 +- examples/dummyresource/resourcefactory.cpp | 24 ++++++++++++++++++++++++ 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: template static QSharedPointer loadModel(Query query) { - auto model = QSharedPointer >::create(query, QList() << "summary" << "uid"); + auto model = QSharedPointer >::create(query, query.requestedProperties.toList()); auto resultProvider = std::make_shared >(model); //Keep the resultprovider alive for as long as the model lives model->setProperty("resultProvider", QVariant::fromValue(std::shared_ptr(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::index(const QByteArray &identifier, const Buffe const auto parent = bufferAdaptor.getProperty("parent"); Trace() << "indexing " << identifier << " with parent " << parent.toByteArray(); if (parent.isValid()) { + Q_ASSERT(!parent.toByteArray().isEmpty()); Index("folder.index.parent", transaction).add(parent.toByteArray(), identifier); } else { 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: //Incremental updates are always loaded directly, leaving it up to the result to discard the changes if they are not interesting runner->setQuery([this, query, &resultProvider] () -> KAsync::Job { return KAsync::start([this, query, &resultProvider](KAsync::Future &future) { - Trace() << "Executing query "; const qint64 newRevision = executeIncrementalQuery(query, resultProvider); mResourceAccess->sendRevisionReplayedCommand(newRevision); 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: break; } } - beginInsertRows(parent, index, index); + if (mEntities.contains(childId)) { + qWarning() << "Entity already in model " << value->identifier(); + return; + } + beginInsertRows(QModelIndex(), index, index); mEntities.insert(childId, value); mTree[id].insert(index, childId); 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 @@ #include "common/resource.h" #include "common/storage.h" #include "common/domain/event.h" +#include "common/domain/folder.h" #include "common/resourceconfig.h" #include "console.h" @@ -124,10 +125,10 @@ int main(int argc, char *argv[]) query.syncOnDemand = false; query.processAll = false; query.liveQuery = true; - query.requestedProperties << "summary" << "uid"; + query.requestedProperties << "name"; - auto model = Akonadi2::Store::loadModel(query); - auto view = QSharedPointer >::create(model.data()); + auto model = Akonadi2::Store::loadModel(query); + auto view = QSharedPointer >::create(model.data()); return app.exec(); } 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 @@ class DummyStore { public: - //TODO proper singleton static DummyStore &instance() { static DummyStore instance; @@ -32,4 +31,5 @@ public: QMap > events() const; QMap > mails() const; + QMap > folders() const; }; 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 &data, flatbuffers::FlatBufferBuilder &entityFbb) +{ + //Map the source format to the buffer format (which happens to be an exact copy here) + auto name = m_fbb.CreateString(data.value("name").toString().toStdString()); + flatbuffers::Offset parent; + bool hasParent = false; + if (!data.value("parent").toString().isEmpty()) { + hasParent = true; + parent = m_fbb.CreateString(data.value("parent").toString().toStdString()); + } + + auto builder = Akonadi2::ApplicationDomain::Buffer::FolderBuilder(m_fbb); + builder.add_name(name); + if (hasParent) { + builder.add_parent(parent); + } + auto buffer = builder.Finish(); + Akonadi2::ApplicationDomain::Buffer::FinishFolderBuffer(m_fbb, buffer); + Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize()); +} + void DummyResource::synchronize(const QString &bufferType, const QMap > &data, Akonadi2::Storage::Transaction &transaction, std::function &data, flatbuffers::FlatBufferBuilder &entityFbb)> createEntity) { Index uidIndex("index.uid", transaction); @@ -209,6 +230,9 @@ KAsync::Job DummyResource::synchronizeWithSource() synchronize(ENTITY_TYPE_MAIL, DummyStore::instance().mails(), transaction, [this](const QByteArray &ridBuffer, const QMap &data, flatbuffers::FlatBufferBuilder &entityFbb) { createMail(ridBuffer, data, entityFbb); }); + synchronize(ENTITY_TYPE_FOLDER, DummyStore::instance().folders(), transaction, [this](const QByteArray &ridBuffer, const QMap &data, flatbuffers::FlatBufferBuilder &entityFbb) { + createFolder(ridBuffer, data, entityFbb); + }); f.setFinished(); }); 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: private: void createEvent(const QByteArray &rid, const QMap &data, flatbuffers::FlatBufferBuilder &entityFbb); void createMail(const QByteArray &rid, const QMap &data, flatbuffers::FlatBufferBuilder &entityFbb); + void createFolder(const QByteArray &rid, const QMap &data, flatbuffers::FlatBufferBuilder &entityFbb); void synchronize(const QString &bufferType, const QMap > &data, Akonadi2::Storage::Transaction &transaction, std::function &data, flatbuffers::FlatBufferBuilder &entityFbb)> createEntity); }; -- cgit v1.2.3