summaryrefslogtreecommitdiffstats
path: root/common/domain
diff options
context:
space:
mode:
authorSandro Knauß <sknauss@kde.org>2017-01-11 13:06:55 +0100
committerSandro Knauß <sknauss@kde.org>2017-01-30 10:58:20 +0100
commitbb624c5ec2ab2e13dedcba67fd60e3d2f03216d7 (patch)
treeee27923e8bf1fa51a75599beaff7e005368180e0 /common/domain
parent17d8b00ae32e2b1522c5dce6719566e4fbe3357e (diff)
downloadsink-bb624c5ec2ab2e13dedcba67fd60e3d2f03216d7.tar.gz
sink-bb624c5ec2ab2e13dedcba67fd60e3d2f03216d7.zip
Add Contact as new domain type
Diffstat (limited to 'common/domain')
-rw-r--r--common/domain/applicationdomaintype.cpp12
-rw-r--r--common/domain/applicationdomaintype.h14
-rw-r--r--common/domain/contact.cpp57
-rw-r--r--common/domain/contact.fbs11
-rw-r--r--common/domain/contact.h57
-rw-r--r--common/domain/domaintypes.h1
6 files changed, 152 insertions, 0 deletions
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()
206 206
207} 207}
208 208
209Contact::~Contact()
210{
211
212}
213
209Event::~Event() 214Event::~Event()
210{ 215{
211 216
@@ -325,6 +330,12 @@ SinkResource ImapResource::create(const QByteArray &account)
325} 330}
326 331
327template<> 332template<>
333QByteArray getTypeName<Contact>()
334{
335 return "contact";
336}
337
338template<>
328QByteArray getTypeName<Event>() 339QByteArray getTypeName<Event>()
329{ 340{
330 return "event"; 341 return "event";
@@ -377,6 +388,7 @@ QByteArrayList getTypeNames()
377 types << ApplicationDomain::getTypeName<Folder>(); 388 types << ApplicationDomain::getTypeName<Folder>();
378 types << ApplicationDomain::getTypeName<Event>(); 389 types << ApplicationDomain::getTypeName<Event>();
379 types << ApplicationDomain::getTypeName<Todo>(); 390 types << ApplicationDomain::getTypeName<Todo>();
391 types << ApplicationDomain::getTypeName<Contact>();
380 } 392 }
381 return types; 393 return types;
382} 394}
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 {
328 virtual ~Entity(); 328 virtual ~Entity();
329}; 329};
330 330
331struct SINK_EXPORT Contact : public Entity {
332 SINK_ENTITY(Contact);
333 SINK_EXTRACTED_PROPERTY(QString, Uid, uid);
334 SINK_PROPERTY(QString, Fn, fn);
335 SINK_PROPERTY(QByteArrayList, Emails, emails);
336 SINK_BLOB_PROPERTY(Vcard, vcard);
337};
338
331struct SINK_EXPORT Event : public Entity { 339struct SINK_EXPORT Event : public Entity {
332 SINK_ENTITY(Event); 340 SINK_ENTITY(Event);
333 SINK_PROPERTY(QString, Uid, uid); 341 SINK_PROPERTY(QString, Uid, uid);
@@ -459,6 +467,9 @@ template<class DomainType>
459QByteArray SINK_EXPORT getTypeName(); 467QByteArray SINK_EXPORT getTypeName();
460 468
461template<> 469template<>
470QByteArray SINK_EXPORT getTypeName<Contact>();
471
472template<>
462QByteArray SINK_EXPORT getTypeName<Event>(); 473QByteArray SINK_EXPORT getTypeName<Event>();
463 474
464template<> 475template<>
@@ -507,6 +518,7 @@ class SINK_EXPORT TypeImplementation;
507 * This macro can be used to instantiate templates for all domain types. 518 * This macro can be used to instantiate templates for all domain types.
508 */ 519 */
509#define SINK_REGISTER_TYPES() \ 520#define SINK_REGISTER_TYPES() \
521 REGISTER_TYPE(Sink::ApplicationDomain::Contact); \
510 REGISTER_TYPE(Sink::ApplicationDomain::Event); \ 522 REGISTER_TYPE(Sink::ApplicationDomain::Event); \
511 REGISTER_TYPE(Sink::ApplicationDomain::Mail); \ 523 REGISTER_TYPE(Sink::ApplicationDomain::Mail); \
512 REGISTER_TYPE(Sink::ApplicationDomain::Folder); \ 524 REGISTER_TYPE(Sink::ApplicationDomain::Folder); \
@@ -521,6 +533,8 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType)
521Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType::Ptr) 533Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType::Ptr)
522Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity) 534Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity)
523Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity::Ptr) 535Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity::Ptr)
536Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact)
537Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact::Ptr)
524Q_DECLARE_METATYPE(Sink::ApplicationDomain::Event) 538Q_DECLARE_METATYPE(Sink::ApplicationDomain::Event)
525Q_DECLARE_METATYPE(Sink::ApplicationDomain::Event::Ptr) 539Q_DECLARE_METATYPE(Sink::ApplicationDomain::Event::Ptr)
526Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail) 540Q_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 @@
1/*
2 * Copyright (C) 2017 Sandro Knauß <knauss@kolabsys.com>
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 "contact.h"
20
21#include <QVector>
22#include <QByteArray>
23#include <QString>
24
25#include "../propertymapper.h"
26#include "../typeindex.h"
27#include "entity_generated.h"
28
29#include "contact_generated.h"
30
31using namespace Sink::ApplicationDomain;
32
33void TypeImplementation<Contact>::configure(TypeIndex &index)
34{
35 index.addProperty<QByteArray>(Contact::Uid::name);
36}
37
38void TypeImplementation<Contact>::configure(ReadPropertyMapper<Buffer> &propertyMapper)
39{
40 propertyMapper.addMapping<Contact::Uid, Buffer>(&Buffer::uid);
41 propertyMapper.addMapping<Contact::Fn, Buffer>(&Buffer::fn);
42 propertyMapper.addMapping<Contact::Emails, Buffer>(&Buffer::emails);
43 propertyMapper.addMapping<Contact::Vcard, Buffer>(&Buffer::vcard);
44}
45
46void TypeImplementation<Contact>::configure(WritePropertyMapper<BufferBuilder> &propertyMapper)
47{
48 propertyMapper.addMapping<Contact::Uid>(&BufferBuilder::add_uid);
49 propertyMapper.addMapping<Contact::Fn>(&BufferBuilder::add_fn);
50 propertyMapper.addMapping<Contact::Emails>(&BufferBuilder::add_emails);
51 propertyMapper.addMapping<Contact::Vcard>(&BufferBuilder::add_vcard);
52}
53
54void TypeImplementation<Contact>::configure(IndexPropertyMapper &)
55{
56
57}
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 @@
1namespace Sink.ApplicationDomain.Buffer;
2
3table Contact {
4 uid:string;
5 fn:string;
6 emails: [string];
7 vcard: string;
8}
9
10root_type Contact;
11file_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 @@
1/*
2 * Copyright (C) 2017 Sandro Knauß <knauss@kolabsys.com>
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
23class QByteArray;
24
25template<typename T>
26class ReadPropertyMapper;
27template<typename T>
28class WritePropertyMapper;
29class IndexPropertyMapper;
30
31class TypeIndex;
32
33namespace Sink {
34namespace ApplicationDomain {
35 namespace Buffer {
36 struct Contact;
37 struct ContactBuilder;
38 }
39
40/**
41 * Implements all type-specific code such as updating and querying indexes.
42 *
43 * These are type specifiy default implementations. Theoretically a resource could implement it's own implementation.
44 */
45template<>
46class TypeImplementation<Sink::ApplicationDomain::Contact> {
47public:
48 typedef Sink::ApplicationDomain::Buffer::Contact Buffer;
49 typedef Sink::ApplicationDomain::Buffer::ContactBuilder BufferBuilder;
50 static void configure(TypeIndex &);
51 static void configure(ReadPropertyMapper<Buffer> &);
52 static void configure(WritePropertyMapper<BufferBuilder> &);
53 static void configure(IndexPropertyMapper &indexPropertyMapper);
54};
55
56}
57}
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 @@
1 1
2#include "contact.h"
2#include "mail.h" 3#include "mail.h"
3#include "folder.h" 4#include "folder.h"
4#include "event.h" 5#include "event.h"