From 57a88e6c1514b85d25b066059defcd62d2ccd8d6 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 9 Mar 2017 16:14:02 +0100 Subject: Addressbook support --- common/CMakeLists.txt | 2 ++ common/domain/addressbook.cpp | 54 +++++++++++++++++++++++++++++++++ common/domain/addressbook.fbs | 9 ++++++ common/domain/addressbook.h | 51 +++++++++++++++++++++++++++++++ common/domain/applicationdomaintype.cpp | 15 +++++++++ common/domain/applicationdomaintype.h | 12 ++++++++ common/domain/applicationdomaintype_p.h | 8 +++-- common/domain/contact.cpp | 5 ++- common/domain/contact.fbs | 1 + common/domain/contact.h | 3 +- common/domain/domaintypes.h | 1 + common/domainadaptor.h | 5 +-- common/synchronizer.cpp | 11 +++++++ common/synchronizer.h | 2 +- 14 files changed, 169 insertions(+), 10 deletions(-) create mode 100644 common/domain/addressbook.cpp create mode 100644 common/domain/addressbook.fbs create mode 100644 common/domain/addressbook.h (limited to 'common') diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index b5275e0..a10f84f 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -62,6 +62,7 @@ set(command_SRCS domain/propertyregistry.cpp domain/applicationdomaintype.cpp domain/contact.cpp + domain/addressbook.cpp domain/event.cpp domain/mail.cpp domain/folder.cpp @@ -101,6 +102,7 @@ generate_flatbuffers( commands/inspection commands/flush domain/contact + domain/addressbook domain/event domain/mail domain/folder diff --git a/common/domain/addressbook.cpp b/common/domain/addressbook.cpp new file mode 100644 index 0000000..d1a3eaf --- /dev/null +++ b/common/domain/addressbook.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2017 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 "addressbook.h" + +#include +#include + +#include "../propertymapper.h" +#include "../typeindex.h" +#include "entitybuffer.h" +#include "entity_generated.h" + +#include "addressbook_generated.h" + +using namespace Sink::ApplicationDomain; + +void TypeImplementation::configure(TypeIndex &index) +{ + index.addProperty(Addressbook::Parent::name); + index.addProperty(Addressbook::Name::name); +} + +void TypeImplementation::configure(ReadPropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&Buffer::parent); + propertyMapper.addMapping(&Buffer::name); +} + +void TypeImplementation::configure(WritePropertyMapper &propertyMapper) +{ + propertyMapper.addMapping(&BufferBuilder::add_parent); + propertyMapper.addMapping(&BufferBuilder::add_name); +} + +void TypeImplementation::configure(IndexPropertyMapper &) +{ + +} diff --git a/common/domain/addressbook.fbs b/common/domain/addressbook.fbs new file mode 100644 index 0000000..c2bda2b --- /dev/null +++ b/common/domain/addressbook.fbs @@ -0,0 +1,9 @@ +namespace Sink.ApplicationDomain.Buffer; + +table Addressbook { + name:string; + parent:string; +} + +root_type Addressbook; +file_identifier "AKFB"; diff --git a/common/domain/addressbook.h b/common/domain/addressbook.h new file mode 100644 index 0000000..6475073 --- /dev/null +++ b/common/domain/addressbook.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2017 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" + +template +class ReadPropertyMapper; +template +class WritePropertyMapper; +class IndexPropertyMapper; + +class TypeIndex; + +namespace Sink { + +namespace ApplicationDomain { + namespace Buffer { + struct Addressbook; + struct AddressbookBuilder; + } + +template<> +class TypeImplementation { +public: + typedef Sink::ApplicationDomain::Buffer::Addressbook Buffer; + typedef Sink::ApplicationDomain::Buffer::AddressbookBuilder BufferBuilder; + static void configure(TypeIndex &); + static void configure(ReadPropertyMapper &); + static void configure(WritePropertyMapper &); + static void configure(IndexPropertyMapper &indexPropertyMapper); +}; + +} +} diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 99f14a1..1efe052 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -96,6 +96,15 @@ SINK_REGISTER_PROPERTY(Folder, SpecialPurpose); SINK_REGISTER_PROPERTY(Folder, Enabled); SINK_REGISTER_PROPERTY(Folder, Parent); +SINK_REGISTER_PROPERTY(Contact, Uid); +SINK_REGISTER_PROPERTY(Contact, Fn); +SINK_REGISTER_PROPERTY(Contact, Emails); +SINK_REGISTER_PROPERTY(Contact, Vcard); +SINK_REGISTER_PROPERTY(Contact, Addressbook); + +SINK_REGISTER_PROPERTY(Addressbook, Name); +SINK_REGISTER_PROPERTY(Addressbook, Parent); + static const int foo = [] { QMetaType::registerEqualsComparator(); QMetaType::registerDebugStreamOperator(); @@ -368,6 +377,12 @@ QByteArray getTypeName() return "contact"; } +template<> +QByteArray getTypeName() +{ + return "addressbook"; +} + template<> QByteArray getTypeName() { diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 3afef75..209f241 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -312,12 +312,19 @@ struct SINK_EXPORT Entity : public ApplicationDomainType { virtual ~Entity() = default; }; +struct SINK_EXPORT Addressbook : public Entity { + SINK_ENTITY(Addressbook); + SINK_REFERENCE_PROPERTY(Addressbook, Parent, parent); + SINK_PROPERTY(QString, Name, name); +}; + struct SINK_EXPORT Contact : public Entity { SINK_ENTITY(Contact); SINK_PROPERTY(QString, Uid, uid); SINK_PROPERTY(QString, Fn, fn); SINK_PROPERTY(QByteArrayList, Emails, emails); SINK_PROPERTY(QByteArray, Vcard, vcard); + SINK_REFERENCE_PROPERTY(Addressbook, Addressbook, addressbook); }; struct SINK_EXPORT Event : public Entity { @@ -429,6 +436,7 @@ namespace Mail { }; namespace Contact { static constexpr const char *contact = "contact"; + static constexpr const char *addressbook = "addressbook"; static constexpr const char *storage = "contact.storage"; }; }; @@ -453,6 +461,9 @@ QByteArray SINK_EXPORT getTypeName(); template<> QByteArray SINK_EXPORT getTypeName(); +template<> +QByteArray SINK_EXPORT getTypeName(); + template<> QByteArray SINK_EXPORT getTypeName(); @@ -503,6 +514,7 @@ class SINK_EXPORT TypeImplementation; */ #define SINK_REGISTER_TYPES() \ REGISTER_TYPE(Sink::ApplicationDomain::Contact) \ + REGISTER_TYPE(Sink::ApplicationDomain::Addressbook) \ REGISTER_TYPE(Sink::ApplicationDomain::Event) \ REGISTER_TYPE(Sink::ApplicationDomain::Mail) \ REGISTER_TYPE(Sink::ApplicationDomain::Folder) \ diff --git a/common/domain/applicationdomaintype_p.h b/common/domain/applicationdomaintype_p.h index 4b06864..a5a6b1d 100644 --- a/common/domain/applicationdomaintype_p.h +++ b/common/domain/applicationdomaintype_p.h @@ -33,13 +33,15 @@ struct TypeHelper { template R operator()(Args && ... args) const { if (type == Sink::ApplicationDomain::getTypeName()) { - return Func{}(std::forward(args...)); + return Func{}(std::forward(args...)); } else if (type == Sink::ApplicationDomain::getTypeName()) { - return Func{}(std::forward(args...)); + return Func{}(std::forward(args...)); } else if (type == Sink::ApplicationDomain::getTypeName()) { - return Func{}(std::forward(args...)); + return Func{}(std::forward(args...)); } else if (type == Sink::ApplicationDomain::getTypeName()) { return Func{}(std::forward(args...)); + } else if (type == Sink::ApplicationDomain::getTypeName()) { + return Func{}(std::forward(args...)); } else { Q_ASSERT(false); } diff --git a/common/domain/contact.cpp b/common/domain/contact.cpp index ea7cac2..01f9144 100644 --- a/common/domain/contact.cpp +++ b/common/domain/contact.cpp @@ -1,5 +1,6 @@ /* - * Copyright (C) 2017 Sandro Knauß + * Copyright (C) 2017 Sandro Knauß + * Copyright (C) 2017 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 @@ -41,6 +42,7 @@ void TypeImplementation::configure(ReadPropertyMapper &property propertyMapper.addMapping(&Buffer::fn); propertyMapper.addMapping(&Buffer::emails); propertyMapper.addMapping(&Buffer::vcard); + propertyMapper.addMapping(&Buffer::addressbook); } void TypeImplementation::configure(WritePropertyMapper &propertyMapper) @@ -49,6 +51,7 @@ void TypeImplementation::configure(WritePropertyMapper & propertyMapper.addMapping(&BufferBuilder::add_fn); propertyMapper.addMapping(&BufferBuilder::add_emails); propertyMapper.addMapping(&BufferBuilder::add_vcard); + propertyMapper.addMapping(&BufferBuilder::add_addressbook); } void TypeImplementation::configure(IndexPropertyMapper &) diff --git a/common/domain/contact.fbs b/common/domain/contact.fbs index 34fb1d6..7d7f797 100644 --- a/common/domain/contact.fbs +++ b/common/domain/contact.fbs @@ -3,6 +3,7 @@ namespace Sink.ApplicationDomain.Buffer; table Contact { uid:string; fn:string; + addressbook:string; emails: [string]; vcard: string; } diff --git a/common/domain/contact.h b/common/domain/contact.h index c803a9f..976f16e 100644 --- a/common/domain/contact.h +++ b/common/domain/contact.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2017 Sandro Knauß + * Copyright (C) 2017 Sandro Knauß + * Copyright (C) 2017 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 diff --git a/common/domain/domaintypes.h b/common/domain/domaintypes.h index 0abdee7..8e31d48 100644 --- a/common/domain/domaintypes.h +++ b/common/domain/domaintypes.h @@ -1,5 +1,6 @@ #include "contact.h" +#include "addressbook.h" #include "mail.h" #include "folder.h" #include "event.h" diff --git a/common/domainadaptor.h b/common/domainadaptor.h index 0377ef4..66ffb88 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h @@ -26,10 +26,7 @@ #include "domaintypeadaptorfactoryinterface.h" #include "domain/applicationdomaintype.h" -#include "domain/contact.h" -#include "domain/event.h" -#include "domain/mail.h" -#include "domain/folder.h" +#include "domain/domaintypes.h" #include "bufferadaptor.h" #include "entity_generated.h" #include "metadata_generated.h" diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index fcdb5b8..8c0d31d 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -505,6 +505,12 @@ KAsync::Job Synchronizer::replay(const QByteArray &type, const QByteArray } else if (type == ApplicationDomain::getTypeName()) { auto mail = store().readEntity(key); job = replay(mail, operation, oldRemoteId, modifiedProperties); + } else if (type == ApplicationDomain::getTypeName()) { + auto mail = store().readEntity(key); + job = replay(mail, operation, oldRemoteId, modifiedProperties); + } else if (type == ApplicationDomain::getTypeName()) { + auto mail = store().readEntity(key); + job = replay(mail, operation, oldRemoteId, modifiedProperties); } else { SinkErrorCtx(mLogCtx) << "Replayed unknown type: " << type; } @@ -545,6 +551,11 @@ KAsync::Job Synchronizer::replay(const ApplicationDomain::Contact &, return KAsync::null(); } +KAsync::Job Synchronizer::replay(const ApplicationDomain::Addressbook &, Sink::Operation, const QByteArray &, const QList &) +{ + return KAsync::null(); +} + KAsync::Job Synchronizer::replay(const ApplicationDomain::Mail &, Sink::Operation, const QByteArray &, const QList &) { return KAsync::null(); diff --git a/common/synchronizer.h b/common/synchronizer.h index af042cb..45ec9e7 100644 --- a/common/synchronizer.h +++ b/common/synchronizer.h @@ -73,9 +73,9 @@ protected: protected: ///Implement to write back changes to the server virtual KAsync::Job replay(const Sink::ApplicationDomain::Contact &, Sink::Operation, const QByteArray &oldRemoteId, const QList &); + virtual KAsync::Job replay(const Sink::ApplicationDomain::Addressbook &, Sink::Operation, const QByteArray &oldRemoteId, const QList &); virtual KAsync::Job replay(const Sink::ApplicationDomain::Mail &, Sink::Operation, const QByteArray &oldRemoteId, const QList &); virtual KAsync::Job replay(const Sink::ApplicationDomain::Folder &, Sink::Operation, const QByteArray &oldRemoteId, const QList &); - protected: ///Calls the callback to enqueue the command void enqueueCommand(int commandId, const QByteArray &data); -- cgit v1.2.3