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/CMakeLists.txt | 3 ++ 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 +++++++++++++++++++++++ common/domainadaptor.h | 1 + examples/dummyresource/domainadaptor.cpp | 6 +++ examples/dummyresource/domainadaptor.h | 12 ++++- examples/dummyresource/facade.cpp | 22 +++------ examples/dummyresource/facade.h | 6 +-- examples/dummyresource/resourcefactory.cpp | 2 + 12 files changed, 173 insertions(+), 24 deletions(-) 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 diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index b4a4703..f24ec46 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -36,6 +36,7 @@ set(command_SRCS domain/applicationdomaintype.cpp domain/event.cpp domain/mail.cpp + domain/folder.cpp ${storage_SRCS}) add_library(${PROJECT_NAME} SHARED ${command_SRCS}) @@ -55,6 +56,8 @@ generate_flatbuffers( commands/revisionreplayed domain/event domain/mail + domain/folder + domain/dummy entity metadata queuedcommand 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(); +}; + +} +} diff --git a/common/domainadaptor.h b/common/domainadaptor.h index b14fbcd..620a658 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h @@ -26,6 +26,7 @@ #include "domain/applicationdomaintype.h" #include "domain/event.h" #include "domain/mail.h" +#include "domain/folder.h" #include "bufferadaptor.h" #include "entity_generated.h" #include "metadata_generated.h" diff --git a/examples/dummyresource/domainadaptor.cpp b/examples/dummyresource/domainadaptor.cpp index d08a783..74b170d 100644 --- a/examples/dummyresource/domainadaptor.cpp +++ b/examples/dummyresource/domainadaptor.cpp @@ -51,3 +51,9 @@ DummyMailAdaptorFactory::DummyMailAdaptorFactory() } +DummyFolderAdaptorFactory::DummyFolderAdaptorFactory() + : DomainTypeAdaptorFactory() +{ + +} + diff --git a/examples/dummyresource/domainadaptor.h b/examples/dummyresource/domainadaptor.h index add3e8e..e5856f8 100644 --- a/examples/dummyresource/domainadaptor.h +++ b/examples/dummyresource/domainadaptor.h @@ -21,6 +21,8 @@ #include "common/domainadaptor.h" #include "event_generated.h" #include "mail_generated.h" +#include "folder_generated.h" +#include "dummy_generated.h" #include "dummycalendar_generated.h" #include "entity_generated.h" @@ -31,10 +33,16 @@ public: virtual ~DummyEventAdaptorFactory() {}; }; -//TODO replace the resource specific event class by a mail class or a dummy class if no resource type is required. -class DummyMailAdaptorFactory : public DomainTypeAdaptorFactory +class DummyMailAdaptorFactory : public DomainTypeAdaptorFactory { public: DummyMailAdaptorFactory(); virtual ~DummyMailAdaptorFactory() {}; }; + +class DummyFolderAdaptorFactory : public DomainTypeAdaptorFactory +{ +public: + DummyFolderAdaptorFactory(); + virtual ~DummyFolderAdaptorFactory() {}; +}; diff --git a/examples/dummyresource/facade.cpp b/examples/dummyresource/facade.cpp index 5a9d722..f337bdc 100644 --- a/examples/dummyresource/facade.cpp +++ b/examples/dummyresource/facade.cpp @@ -30,6 +30,7 @@ DummyResourceFacade::~DummyResourceFacade() { } + DummyResourceMailFacade::DummyResourceMailFacade(const QByteArray &instanceIdentifier) : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create()) { @@ -39,25 +40,12 @@ DummyResourceMailFacade::~DummyResourceMailFacade() { } -static void addFolder(const QSharedPointer > &resultProvider, QByteArray uid, QString name, QString icon) + +DummyResourceFolderFacade::DummyResourceFolderFacade(const QByteArray &instanceIdentifier) + : Akonadi2::GenericFacade(instanceIdentifier, QSharedPointer::create()) { - auto folder = Akonadi2::ApplicationDomain::Folder::Ptr::create(); - folder->setProperty("name", name); - folder->setProperty("uid", uid); - resultProvider->add(folder); } -KAsync::Job load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider) +DummyResourceFolderFacade::~DummyResourceFolderFacade() { - //Dummy implementation for a fixed set of folders - addFolder(resultProvider, "inbox", "INBOX", "mail-folder-inbox"); - addFolder(resultProvider, "sent", "Sent", "mail-folder-sent"); - addFolder(resultProvider, "trash", "Trash", "user-trash"); - addFolder(resultProvider, "drafts", "Drafts", "document-edit"); - addFolder(resultProvider, "1", "dragons", "folder"); - addFolder(resultProvider, "1", "super mega long tailed dragons", "folder"); - resultProvider->initialResultSetComplete(); - resultProvider->complete(); - return KAsync::null(); } - diff --git a/examples/dummyresource/facade.h b/examples/dummyresource/facade.h index 948116b..b00e1d7 100644 --- a/examples/dummyresource/facade.h +++ b/examples/dummyresource/facade.h @@ -36,13 +36,9 @@ public: virtual ~DummyResourceMailFacade(); }; -class DummyResourceFolderFacade : public Akonadi2::StoreFacade +class DummyResourceFolderFacade : public Akonadi2::GenericFacade { public: DummyResourceFolderFacade(const QByteArray &instanceIdentifier); virtual ~DummyResourceFolderFacade(); - virtual KAsync::Job create(const Akonadi2::ApplicationDomain::Folder &domainObject) { return KAsync::null(); }; - virtual KAsync::Job modify(const Akonadi2::ApplicationDomain::Folder &domainObject) { return KAsync::null(); }; - virtual KAsync::Job remove(const Akonadi2::ApplicationDomain::Folder &domainObject) { return KAsync::null(); }; - virtual KAsync::Job load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider); }; diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index 397ca5f..edb3b42 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -40,6 +40,7 @@ //This is the resources entity type, and not the domain type #define ENTITY_TYPE_EVENT "event" #define ENTITY_TYPE_MAIL "mail" +#define ENTITY_TYPE_FOLDER "folder" /** * Index types: @@ -228,5 +229,6 @@ void DummyResourceFactory::registerFacades(Akonadi2::FacadeFactory &factory) { factory.registerFacade(PLUGIN_NAME); factory.registerFacade(PLUGIN_NAME); + factory.registerFacade(PLUGIN_NAME); } -- cgit v1.2.3