From bb624c5ec2ab2e13dedcba67fd60e3d2f03216d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Wed, 11 Jan 2017 13:06:55 +0100 Subject: Add Contact as new domain type --- common/CMakeLists.txt | 2 ++ common/domain/applicationdomaintype.cpp | 12 +++++++ common/domain/applicationdomaintype.h | 14 ++++++++ common/domain/contact.cpp | 57 +++++++++++++++++++++++++++++++++ common/domain/contact.fbs | 11 +++++++ common/domain/contact.h | 57 +++++++++++++++++++++++++++++++++ common/domain/domaintypes.h | 1 + 7 files changed, 154 insertions(+) create mode 100644 common/domain/contact.cpp create mode 100644 common/domain/contact.fbs create mode 100644 common/domain/contact.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 934d328..676342d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -61,6 +61,7 @@ set(command_SRCS configstore.cpp resultset.cpp domain/applicationdomaintype.cpp + domain/contact.cpp domain/event.cpp domain/mail.cpp domain/folder.cpp @@ -97,6 +98,7 @@ generate_flatbuffers( commands/revisionreplayed commands/inspection commands/flush + domain/contact domain/event domain/mail domain/folder diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 1647951..6d16a3c 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -206,6 +206,11 @@ Entity::~Entity() } +Contact::~Contact() +{ + +} + Event::~Event() { @@ -324,6 +329,12 @@ SinkResource ImapResource::create(const QByteArray &account) return resource; } +template<> +QByteArray getTypeName() +{ + return "contact"; +} + template<> QByteArray getTypeName() { @@ -377,6 +388,7 @@ QByteArrayList getTypeNames() types << ApplicationDomain::getTypeName(); types << ApplicationDomain::getTypeName(); types << ApplicationDomain::getTypeName(); + types << ApplicationDomain::getTypeName(); } return types; } diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index db7fc8d..e4ed05b 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -328,6 +328,14 @@ struct SINK_EXPORT Entity : public ApplicationDomainType { virtual ~Entity(); }; +struct SINK_EXPORT Contact : public Entity { + SINK_ENTITY(Contact); + SINK_EXTRACTED_PROPERTY(QString, Uid, uid); + SINK_PROPERTY(QString, Fn, fn); + SINK_PROPERTY(QByteArrayList, Emails, emails); + SINK_BLOB_PROPERTY(Vcard, vcard); +}; + struct SINK_EXPORT Event : public Entity { SINK_ENTITY(Event); SINK_PROPERTY(QString, Uid, uid); @@ -458,6 +466,9 @@ namespace Mail { template QByteArray SINK_EXPORT getTypeName(); +template<> +QByteArray SINK_EXPORT getTypeName(); + template<> QByteArray SINK_EXPORT getTypeName(); @@ -507,6 +518,7 @@ class SINK_EXPORT TypeImplementation; * This macro can be used to instantiate templates for all domain types. */ #define SINK_REGISTER_TYPES() \ + REGISTER_TYPE(Sink::ApplicationDomain::Contact); \ REGISTER_TYPE(Sink::ApplicationDomain::Event); \ REGISTER_TYPE(Sink::ApplicationDomain::Mail); \ REGISTER_TYPE(Sink::ApplicationDomain::Folder); \ @@ -521,6 +533,8 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType) Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType::Ptr) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact::Ptr) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Event) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Event::Ptr) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail) diff --git a/common/domain/contact.cpp b/common/domain/contact.cpp new file mode 100644 index 0000000..ea7cac2 --- /dev/null +++ b/common/domain/contact.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2017 Sandro Knauß + * + * 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 "contact.h" + +#include +#include +#include + +#include "../propertymapper.h" +#include "../typeindex.h" +#include "entity_generated.h" + +#include "contact_generated.h" + +using namespace Sink::ApplicationDomain; + +void TypeImplementation::configure(TypeIndex &index) +{ + index.addProperty(Contact::Uid::name); +} + +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&Buffer::uid); + propertyMapper.addMapping(&Buffer::fn); + propertyMapper.addMapping(&Buffer::emails); + propertyMapper.addMapping(&Buffer::vcard); +} + +void TypeImplementation::configure(WritePropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&BufferBuilder::add_uid); + propertyMapper.addMapping(&BufferBuilder::add_fn); + propertyMapper.addMapping(&BufferBuilder::add_emails); + propertyMapper.addMapping(&BufferBuilder::add_vcard); +} + +void TypeImplementation::configure(IndexPropertyMapper &) +{ + +} diff --git a/common/domain/contact.fbs b/common/domain/contact.fbs new file mode 100644 index 0000000..34fb1d6 --- /dev/null +++ b/common/domain/contact.fbs @@ -0,0 +1,11 @@ +namespace Sink.ApplicationDomain.Buffer; + +table Contact { + uid:string; + fn:string; + emails: [string]; + vcard: string; +} + +root_type Contact; +file_identifier "AKFB"; diff --git a/common/domain/contact.h b/common/domain/contact.h new file mode 100644 index 0000000..c803a9f --- /dev/null +++ b/common/domain/contact.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2017 Sandro Knauß + * + * 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" + +class QByteArray; + +template +class ReadPropertyMapper; +template +class WritePropertyMapper; +class IndexPropertyMapper; + +class TypeIndex; + +namespace Sink { +namespace ApplicationDomain { + namespace Buffer { + struct Contact; + struct ContactBuilder; + } + +/** + * Implements all type-specific code such as updating and querying indexes. + * + * These are type specifiy default implementations. Theoretically a resource could implement it's own implementation. + */ +template<> +class TypeImplementation { +public: + typedef Sink::ApplicationDomain::Buffer::Contact Buffer; + typedef Sink::ApplicationDomain::Buffer::ContactBuilder BufferBuilder; + static void configure(TypeIndex &); + static void configure(ReadPropertyMapper &); + static void configure(WritePropertyMapper &); + static void configure(IndexPropertyMapper &indexPropertyMapper); +}; + +} +} diff --git a/common/domain/domaintypes.h b/common/domain/domaintypes.h index 84c5bd5..0abdee7 100644 --- a/common/domain/domaintypes.h +++ b/common/domain/domaintypes.h @@ -1,4 +1,5 @@ +#include "contact.h" #include "mail.h" #include "folder.h" #include "event.h" -- cgit v1.2.3