summaryrefslogtreecommitdiffstats
path: root/common/domain
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-09 16:14:02 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-09 16:14:02 +0100
commit57a88e6c1514b85d25b066059defcd62d2ccd8d6 (patch)
treead41c8e9e4e6b59329e84c2151f24ba5a22eca64 /common/domain
parent45aaa4a4b2a0718d6e23dd5ac8a5c594d774e949 (diff)
downloadsink-57a88e6c1514b85d25b066059defcd62d2ccd8d6.tar.gz
sink-57a88e6c1514b85d25b066059defcd62d2ccd8d6.zip
Addressbook support
Diffstat (limited to 'common/domain')
-rw-r--r--common/domain/addressbook.cpp54
-rw-r--r--common/domain/addressbook.fbs9
-rw-r--r--common/domain/addressbook.h51
-rw-r--r--common/domain/applicationdomaintype.cpp15
-rw-r--r--common/domain/applicationdomaintype.h12
-rw-r--r--common/domain/applicationdomaintype_p.h8
-rw-r--r--common/domain/contact.cpp5
-rw-r--r--common/domain/contact.fbs1
-rw-r--r--common/domain/contact.h3
-rw-r--r--common/domain/domaintypes.h1
10 files changed, 154 insertions, 5 deletions
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 @@
1/*
2 * Copyright (C) 2017 Christian Mollekopf <chrigi_1@fastaddressbook.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19#include "addressbook.h"
20
21#include <QByteArray>
22#include <QString>
23
24#include "../propertymapper.h"
25#include "../typeindex.h"
26#include "entitybuffer.h"
27#include "entity_generated.h"
28
29#include "addressbook_generated.h"
30
31using namespace Sink::ApplicationDomain;
32
33void TypeImplementation<Addressbook>::configure(TypeIndex &index)
34{
35 index.addProperty<QByteArray>(Addressbook::Parent::name);
36 index.addProperty<QString>(Addressbook::Name::name);
37}
38
39void TypeImplementation<Addressbook>::configure(ReadPropertyMapper<Buffer> &propertyMapper)
40{
41 propertyMapper.addMapping<Addressbook::Parent, Buffer>(&Buffer::parent);
42 propertyMapper.addMapping<Addressbook::Name, Buffer>(&Buffer::name);
43}
44
45void TypeImplementation<Addressbook>::configure(WritePropertyMapper<BufferBuilder> &propertyMapper)
46{
47 propertyMapper.addMapping<Addressbook::Parent>(&BufferBuilder::add_parent);
48 propertyMapper.addMapping<Addressbook::Name>(&BufferBuilder::add_name);
49}
50
51void TypeImplementation<Addressbook>::configure(IndexPropertyMapper &)
52{
53
54}
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 @@
1namespace Sink.ApplicationDomain.Buffer;
2
3table Addressbook {
4 name:string;
5 parent:string;
6}
7
8root_type Addressbook;
9file_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 @@
1/*
2 * Copyright (C) 2017 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19#pragma once
20
21#include "applicationdomaintype.h"
22
23template<typename T>
24class ReadPropertyMapper;
25template<typename T>
26class WritePropertyMapper;
27class IndexPropertyMapper;
28
29class TypeIndex;
30
31namespace Sink {
32
33namespace ApplicationDomain {
34 namespace Buffer {
35 struct Addressbook;
36 struct AddressbookBuilder;
37 }
38
39template<>
40class TypeImplementation<Sink::ApplicationDomain::Addressbook> {
41public:
42 typedef Sink::ApplicationDomain::Buffer::Addressbook Buffer;
43 typedef Sink::ApplicationDomain::Buffer::AddressbookBuilder BufferBuilder;
44 static void configure(TypeIndex &);
45 static void configure(ReadPropertyMapper<Buffer> &);
46 static void configure(WritePropertyMapper<BufferBuilder> &);
47 static void configure(IndexPropertyMapper &indexPropertyMapper);
48};
49
50}
51}
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);
96SINK_REGISTER_PROPERTY(Folder, Enabled); 96SINK_REGISTER_PROPERTY(Folder, Enabled);
97SINK_REGISTER_PROPERTY(Folder, Parent); 97SINK_REGISTER_PROPERTY(Folder, Parent);
98 98
99SINK_REGISTER_PROPERTY(Contact, Uid);
100SINK_REGISTER_PROPERTY(Contact, Fn);
101SINK_REGISTER_PROPERTY(Contact, Emails);
102SINK_REGISTER_PROPERTY(Contact, Vcard);
103SINK_REGISTER_PROPERTY(Contact, Addressbook);
104
105SINK_REGISTER_PROPERTY(Addressbook, Name);
106SINK_REGISTER_PROPERTY(Addressbook, Parent);
107
99static const int foo = [] { 108static const int foo = [] {
100 QMetaType::registerEqualsComparator<Reference>(); 109 QMetaType::registerEqualsComparator<Reference>();
101 QMetaType::registerDebugStreamOperator<Reference>(); 110 QMetaType::registerDebugStreamOperator<Reference>();
@@ -369,6 +378,12 @@ QByteArray getTypeName<Contact>()
369} 378}
370 379
371template<> 380template<>
381QByteArray getTypeName<Addressbook>()
382{
383 return "addressbook";
384}
385
386template<>
372QByteArray getTypeName<Event>() 387QByteArray getTypeName<Event>()
373{ 388{
374 return "event"; 389 return "event";
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 {
312 virtual ~Entity() = default; 312 virtual ~Entity() = default;
313}; 313};
314 314
315struct SINK_EXPORT Addressbook : public Entity {
316 SINK_ENTITY(Addressbook);
317 SINK_REFERENCE_PROPERTY(Addressbook, Parent, parent);
318 SINK_PROPERTY(QString, Name, name);
319};
320
315struct SINK_EXPORT Contact : public Entity { 321struct SINK_EXPORT Contact : public Entity {
316 SINK_ENTITY(Contact); 322 SINK_ENTITY(Contact);
317 SINK_PROPERTY(QString, Uid, uid); 323 SINK_PROPERTY(QString, Uid, uid);
318 SINK_PROPERTY(QString, Fn, fn); 324 SINK_PROPERTY(QString, Fn, fn);
319 SINK_PROPERTY(QByteArrayList, Emails, emails); 325 SINK_PROPERTY(QByteArrayList, Emails, emails);
320 SINK_PROPERTY(QByteArray, Vcard, vcard); 326 SINK_PROPERTY(QByteArray, Vcard, vcard);
327 SINK_REFERENCE_PROPERTY(Addressbook, Addressbook, addressbook);
321}; 328};
322 329
323struct SINK_EXPORT Event : public Entity { 330struct SINK_EXPORT Event : public Entity {
@@ -429,6 +436,7 @@ namespace Mail {
429}; 436};
430namespace Contact { 437namespace Contact {
431 static constexpr const char *contact = "contact"; 438 static constexpr const char *contact = "contact";
439 static constexpr const char *addressbook = "addressbook";
432 static constexpr const char *storage = "contact.storage"; 440 static constexpr const char *storage = "contact.storage";
433}; 441};
434}; 442};
@@ -454,6 +462,9 @@ template<>
454QByteArray SINK_EXPORT getTypeName<Contact>(); 462QByteArray SINK_EXPORT getTypeName<Contact>();
455 463
456template<> 464template<>
465QByteArray SINK_EXPORT getTypeName<Addressbook>();
466
467template<>
457QByteArray SINK_EXPORT getTypeName<Event>(); 468QByteArray SINK_EXPORT getTypeName<Event>();
458 469
459template<> 470template<>
@@ -503,6 +514,7 @@ class SINK_EXPORT TypeImplementation;
503 */ 514 */
504#define SINK_REGISTER_TYPES() \ 515#define SINK_REGISTER_TYPES() \
505 REGISTER_TYPE(Sink::ApplicationDomain::Contact) \ 516 REGISTER_TYPE(Sink::ApplicationDomain::Contact) \
517 REGISTER_TYPE(Sink::ApplicationDomain::Addressbook) \
506 REGISTER_TYPE(Sink::ApplicationDomain::Event) \ 518 REGISTER_TYPE(Sink::ApplicationDomain::Event) \
507 REGISTER_TYPE(Sink::ApplicationDomain::Mail) \ 519 REGISTER_TYPE(Sink::ApplicationDomain::Mail) \
508 REGISTER_TYPE(Sink::ApplicationDomain::Folder) \ 520 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 {
33 template <typename R, typename ...Args> 33 template <typename R, typename ...Args>
34 R operator()(Args && ... args) const { 34 R operator()(Args && ... args) const {
35 if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Folder>()) { 35 if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Folder>()) {
36 return Func<Sink::ApplicationDomain::Folder>{}(std::forward<Args...>(args...)); 36 return Func<Sink::ApplicationDomain::Folder>{}(std::forward<Args...>(args...));
37 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Mail>()) { 37 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Mail>()) {
38 return Func<Sink::ApplicationDomain::Mail>{}(std::forward<Args...>(args...)); 38 return Func<Sink::ApplicationDomain::Mail>{}(std::forward<Args...>(args...));
39 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Event>()) { 39 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Event>()) {
40 return Func<Sink::ApplicationDomain::Event>{}(std::forward<Args...>(args...)); 40 return Func<Sink::ApplicationDomain::Event>{}(std::forward<Args...>(args...));
41 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Contact>()) { 41 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Contact>()) {
42 return Func<Sink::ApplicationDomain::Contact>{}(std::forward<Args...>(args...)); 42 return Func<Sink::ApplicationDomain::Contact>{}(std::forward<Args...>(args...));
43 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Addressbook>()) {
44 return Func<Sink::ApplicationDomain::Addressbook>{}(std::forward<Args...>(args...));
43 } else { 45 } else {
44 Q_ASSERT(false); 46 Q_ASSERT(false);
45 } 47 }
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 @@
1/* 1/*
2 * Copyright (C) 2017 Sandro Knauß <knauss@kolabsys.com> 2 * Copyright (C) 2017 Sandro Knauß <knauss@kolabsys.com>
3 * Copyright (C) 2017 Christian Mollekopf <mollekopf@kolabsys.com>
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -41,6 +42,7 @@ void TypeImplementation<Contact>::configure(ReadPropertyMapper<Buffer> &property
41 propertyMapper.addMapping<Contact::Fn, Buffer>(&Buffer::fn); 42 propertyMapper.addMapping<Contact::Fn, Buffer>(&Buffer::fn);
42 propertyMapper.addMapping<Contact::Emails, Buffer>(&Buffer::emails); 43 propertyMapper.addMapping<Contact::Emails, Buffer>(&Buffer::emails);
43 propertyMapper.addMapping<Contact::Vcard, Buffer>(&Buffer::vcard); 44 propertyMapper.addMapping<Contact::Vcard, Buffer>(&Buffer::vcard);
45 propertyMapper.addMapping<Contact::Addressbook, Buffer>(&Buffer::addressbook);
44} 46}
45 47
46void TypeImplementation<Contact>::configure(WritePropertyMapper<BufferBuilder> &propertyMapper) 48void TypeImplementation<Contact>::configure(WritePropertyMapper<BufferBuilder> &propertyMapper)
@@ -49,6 +51,7 @@ void TypeImplementation<Contact>::configure(WritePropertyMapper<BufferBuilder> &
49 propertyMapper.addMapping<Contact::Fn>(&BufferBuilder::add_fn); 51 propertyMapper.addMapping<Contact::Fn>(&BufferBuilder::add_fn);
50 propertyMapper.addMapping<Contact::Emails>(&BufferBuilder::add_emails); 52 propertyMapper.addMapping<Contact::Emails>(&BufferBuilder::add_emails);
51 propertyMapper.addMapping<Contact::Vcard>(&BufferBuilder::add_vcard); 53 propertyMapper.addMapping<Contact::Vcard>(&BufferBuilder::add_vcard);
54 propertyMapper.addMapping<Contact::Addressbook>(&BufferBuilder::add_addressbook);
52} 55}
53 56
54void TypeImplementation<Contact>::configure(IndexPropertyMapper &) 57void TypeImplementation<Contact>::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;
3table Contact { 3table Contact {
4 uid:string; 4 uid:string;
5 fn:string; 5 fn:string;
6 addressbook:string;
6 emails: [string]; 7 emails: [string];
7 vcard: string; 8 vcard: string;
8} 9}
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 @@
1/* 1/*
2 * Copyright (C) 2017 Sandro Knauß <knauss@kolabsys.com> 2 * Copyright (C) 2017 Sandro Knauß <knauss@kolabsys.com>
3 * Copyright (C) 2017 Christian Mollekopf <mollekopf@kolabsys.com>
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 6 * 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 @@
1 1
2#include "contact.h" 2#include "contact.h"
3#include "addressbook.h"
3#include "mail.h" 4#include "mail.h"
4#include "folder.h" 5#include "folder.h"
5#include "event.h" 6#include "event.h"