From 9f6e0fbfd8cf23104eba5a78f89a69fab1a417f5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 9 Nov 2015 16:04:46 +0100 Subject: Added a folder type --- common/domain/applicationdomaintype.h | 2 + common/domain/dummy.fbs | 7 ++++ common/domain/folder.cpp | 71 +++++++++++++++++++++++++++++++++++ common/domain/folder.fbs | 9 +++++ common/domain/folder.h | 56 +++++++++++++++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 common/domain/dummy.fbs create mode 100644 common/domain/folder.cpp create mode 100644 common/domain/folder.fbs create mode 100644 common/domain/folder.h (limited to 'common/domain') diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 5514d26..b4cf8c4 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -160,3 +160,5 @@ Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Event) Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Event::Ptr) Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail) Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail::Ptr) +Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Folder) +Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Folder::Ptr) diff --git a/common/domain/dummy.fbs b/common/domain/dummy.fbs new file mode 100644 index 0000000..8816b09 --- /dev/null +++ b/common/domain/dummy.fbs @@ -0,0 +1,7 @@ +namespace Akonadi2.ApplicationDomain.Buffer; + +table Dummy { +} + +root_type Dummy; +file_identifier "AKFB"; diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp new file mode 100644 index 0000000..50f73c2 --- /dev/null +++ b/common/domain/folder.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2015 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#include "folder.h" + +#include +#include +#include + +#include "../resultset.h" +#include "../index.h" +#include "../storage.h" +#include "../log.h" +#include "../propertymapper.h" +#include "../query.h" +#include "../definitions.h" + +#include "folder_generated.h" + +using namespace Akonadi2::ApplicationDomain; + +ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) +{ + QVector keys; + return ResultSet(keys); +} + +void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +{ +} + +void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) +{ +} + +QSharedPointer::Buffer> > TypeImplementation::initializeReadPropertyMapper() +{ + auto propertyMapper = QSharedPointer >::create(); + propertyMapper->addMapping("parent", &Buffer::parent); + propertyMapper->addMapping("name", &Buffer::name); + return propertyMapper; +} + +QSharedPointer::BufferBuilder> > TypeImplementation::initializeWritePropertyMapper() +{ + auto propertyMapper = QSharedPointer >::create(); + propertyMapper->addMapping("parent", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { + auto offset = variantToProperty(value, fbb); + return [offset](BufferBuilder &builder) { builder.add_parent(offset); }; + }); + propertyMapper->addMapping("name", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { + auto offset = variantToProperty(value, fbb); + return [offset](BufferBuilder &builder) { builder.add_name(offset); }; + }); + return propertyMapper; +} diff --git a/common/domain/folder.fbs b/common/domain/folder.fbs new file mode 100644 index 0000000..3476d58 --- /dev/null +++ b/common/domain/folder.fbs @@ -0,0 +1,9 @@ +namespace Akonadi2.ApplicationDomain.Buffer; + +table Folder { + name:string; + parent:string; +} + +root_type Folder; +file_identifier "AKFB"; diff --git a/common/domain/folder.h b/common/domain/folder.h new file mode 100644 index 0000000..545836f --- /dev/null +++ b/common/domain/folder.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2015 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#pragma once + +#include "applicationdomaintype.h" + +#include "storage.h" + +class ResultSet; +class QByteArray; + +template +class ReadPropertyMapper; +template +class WritePropertyMapper; + +namespace Akonadi2 { + class Query; + +namespace ApplicationDomain { + namespace Buffer { + struct Folder; + struct FolderBuilder; + } + +template<> +class TypeImplementation { +public: + typedef Akonadi2::ApplicationDomain::Buffer::Folder Buffer; + typedef Akonadi2::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; + static QSet indexedProperties(); + static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction); + static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); + static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction); + static QSharedPointer > initializeReadPropertyMapper(); + static QSharedPointer > initializeWritePropertyMapper(); +}; + +} +} -- cgit v1.2.3 From fa1f58e8a83c6dc524ee0540f450065014e1a825 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 10 Nov 2015 11:48:00 +0100 Subject: Cleanups --- common/domain/applicationdomaintype.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'common/domain') diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 1b5d870..c9a8bba 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -60,10 +60,13 @@ ApplicationDomainType& ApplicationDomainType::operator=(const ApplicationDomainT return *this; } -ApplicationDomainType::~ApplicationDomainType() {} +ApplicationDomainType::~ApplicationDomainType() +{ +} QVariant ApplicationDomainType::getProperty(const QByteArray &key) const { + Q_ASSERT(mAdaptor); if (!mAdaptor->availableProperties().contains(key)) { Warning() << "No such property available " << key; } @@ -72,7 +75,9 @@ QVariant ApplicationDomainType::getProperty(const QByteArray &key) const void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) { - mChangeSet.insert(key, value); mAdaptor->setProperty(key, value); + Q_ASSERT(mAdaptor); + mChangeSet.insert(key, value); + mAdaptor->setProperty(key, value); } QByteArrayList ApplicationDomainType::changedProperties() const -- cgit v1.2.3 From d4b10a3de396eebc6c815093e9e1725ece270e9e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 15 Nov 2015 11:09:31 +0100 Subject: Working folder tree query --- common/domain/folder.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'common/domain') diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp index 50f73c2..82f6c1f 100644 --- a/common/domain/folder.cpp +++ b/common/domain/folder.cpp @@ -37,15 +37,43 @@ using namespace Akonadi2::ApplicationDomain; ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) { QVector keys; + if (query.propertyFilter.contains("parent")) { + Index index("folder.index.parent", transaction); + auto lookupKey = query.propertyFilter.value("parent").toByteArray(); + if (lookupKey.isEmpty()) { + lookupKey = "toplevel"; + } + index.lookup(lookupKey, [&](const QByteArray &value) { + keys << value; + }, + [](const Index::Error &error) { + Warning() << "Error in uid index: " << error.message; + }); + appliedFilters << "parent"; + } + Trace() << "Index lookup found " << keys.size() << " keys."; return ResultSet(keys); } void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) { + const auto parent = bufferAdaptor.getProperty("parent"); + Trace() << "indexing " << identifier << " with parent " << parent.toByteArray(); + if (parent.isValid()) { + Index("folder.index.parent", transaction).add(parent.toByteArray(), identifier); + } else { + Index("folder.index.parent", transaction).add("toplevel", identifier); + } } void TypeImplementation::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction) { + const auto parent = bufferAdaptor.getProperty("parent"); + if (parent.isValid()) { + Index("folder.index.parent", transaction).remove(parent.toByteArray(), identifier); + } else { + Index("folder.index.parent", transaction).remove("toplevel", identifier); + } } QSharedPointer::Buffer> > TypeImplementation::initializeReadPropertyMapper() -- cgit v1.2.3 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/domain/folder.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'common/domain') 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); -- cgit v1.2.3 From 94a2cd6ec21bf0466a9a50d6e4a0a956ed47bc82 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 19 Nov 2015 23:23:56 +0100 Subject: Move implementations to the cpp file. I finally figured out how to do that with cpp files. It requires instantiating the code with all expected classes, but that's not a big problem since we know all types. This will hopefully greatly reduce the compiletimes... --- common/domain/applicationdomaintype.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'common/domain') diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index b4cf8c4..227ab4d 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -162,3 +162,5 @@ Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail) Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail::Ptr) Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Folder) Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Folder::Ptr) +Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::AkonadiResource) +Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::AkonadiResource::Ptr) -- cgit v1.2.3 From bf839f1a38518fd9302f4742ddeac16e891ac408 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 30 Nov 2015 10:32:14 +0100 Subject: Debug output --- common/domain/event.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'common/domain') diff --git a/common/domain/event.cpp b/common/domain/event.cpp index 87e13bc..42c13e2 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp @@ -47,6 +47,7 @@ ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, }); appliedFilters << "uid"; } + Trace() << "Index lookup found " << keys.size() << " keys."; return ResultSet(keys); } -- cgit v1.2.3