summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/contactpreprocessor.cpp6
-rw-r--r--common/domain/applicationdomaintype.cpp5
-rw-r--r--common/domain/applicationdomaintype.h18
-rw-r--r--common/domain/contact.fbs9
-rw-r--r--common/domain/propertyregistry.cpp18
-rw-r--r--common/domain/propertyregistry.h3
-rw-r--r--common/propertymapper.cpp30
-rw-r--r--common/propertymapper.h18
-rw-r--r--docs/applicationdomaintypes.md21
9 files changed, 123 insertions, 5 deletions
diff --git a/common/contactpreprocessor.cpp b/common/contactpreprocessor.cpp
index 0f2ca17..ac2c3bc 100644
--- a/common/contactpreprocessor.cpp
+++ b/common/contactpreprocessor.cpp
@@ -28,9 +28,11 @@ void updatedProperties(Sink::ApplicationDomain::Contact &contact, const KContact
28{ 28{
29 contact.setUid(addressee.uid()); 29 contact.setUid(addressee.uid());
30 contact.setFn(addressee.formattedName()); 30 contact.setFn(addressee.formattedName());
31 QByteArrayList emails; 31 contact.setFirstname(addressee.givenName());
32 contact.setLastname(addressee.familyName());
33 QList<Sink::ApplicationDomain::Contact::Email> emails;
32 for (const auto &email : addressee.emails()) { 34 for (const auto &email : addressee.emails()) {
33 emails << email.toUtf8(); 35 emails << Sink::ApplicationDomain::Contact::Email{Sink::ApplicationDomain::Contact::Email::Undefined, email};
34 } 36 }
35 contact.setEmails(emails); 37 contact.setEmails(emails);
36} 38}
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp
index 413fb7c..c9cef3f 100644
--- a/common/domain/applicationdomaintype.cpp
+++ b/common/domain/applicationdomaintype.cpp
@@ -95,15 +95,20 @@ SINK_REGISTER_PROPERTY(Folder, Icon);
95SINK_REGISTER_PROPERTY(Folder, SpecialPurpose); 95SINK_REGISTER_PROPERTY(Folder, SpecialPurpose);
96SINK_REGISTER_PROPERTY(Folder, Enabled); 96SINK_REGISTER_PROPERTY(Folder, Enabled);
97SINK_REGISTER_PROPERTY(Folder, Parent); 97SINK_REGISTER_PROPERTY(Folder, Parent);
98SINK_REGISTER_PROPERTY(Folder, Count);
99SINK_REGISTER_PROPERTY(Folder, FullContentAvailable);
98 100
99SINK_REGISTER_PROPERTY(Contact, Uid); 101SINK_REGISTER_PROPERTY(Contact, Uid);
100SINK_REGISTER_PROPERTY(Contact, Fn); 102SINK_REGISTER_PROPERTY(Contact, Fn);
103SINK_REGISTER_PROPERTY(Contact, Firstname);
104SINK_REGISTER_PROPERTY(Contact, Lastname);
101SINK_REGISTER_PROPERTY(Contact, Emails); 105SINK_REGISTER_PROPERTY(Contact, Emails);
102SINK_REGISTER_PROPERTY(Contact, Vcard); 106SINK_REGISTER_PROPERTY(Contact, Vcard);
103SINK_REGISTER_PROPERTY(Contact, Addressbook); 107SINK_REGISTER_PROPERTY(Contact, Addressbook);
104 108
105SINK_REGISTER_PROPERTY(Addressbook, Name); 109SINK_REGISTER_PROPERTY(Addressbook, Name);
106SINK_REGISTER_PROPERTY(Addressbook, Parent); 110SINK_REGISTER_PROPERTY(Addressbook, Parent);
111SINK_REGISTER_PROPERTY(Addressbook, LastUpdated);
107 112
108static const int foo = [] { 113static const int foo = [] {
109 QMetaType::registerEqualsComparator<Reference>(); 114 QMetaType::registerEqualsComparator<Reference>();
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index ae8e6bc..74b747d 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -328,13 +328,25 @@ struct SINK_EXPORT Addressbook : public Entity {
328 SINK_ENTITY(Addressbook); 328 SINK_ENTITY(Addressbook);
329 SINK_REFERENCE_PROPERTY(Addressbook, Parent, parent); 329 SINK_REFERENCE_PROPERTY(Addressbook, Parent, parent);
330 SINK_PROPERTY(QString, Name, name); 330 SINK_PROPERTY(QString, Name, name);
331 SINK_EXTRACTED_PROPERTY(QDateTime, LastUpdated, lastUpdated);
331}; 332};
332 333
333struct SINK_EXPORT Contact : public Entity { 334struct SINK_EXPORT Contact : public Entity {
335 struct SINK_EXPORT Email {
336 enum Type {
337 Undefined,
338 Work,
339 Home
340 };
341 Type type;
342 QString email;
343 };
334 SINK_ENTITY(Contact); 344 SINK_ENTITY(Contact);
335 SINK_PROPERTY(QString, Uid, uid); 345 SINK_PROPERTY(QString, Uid, uid);
336 SINK_PROPERTY(QString, Fn, fn); 346 SINK_PROPERTY(QString, Fn, fn);
337 SINK_PROPERTY(QByteArrayList, Emails, emails); 347 SINK_PROPERTY(QString, Firstname, firstname);
348 SINK_PROPERTY(QString, Lastname, lastname);
349 SINK_PROPERTY(QList<Email>, Emails, emails);
338 SINK_PROPERTY(QByteArray, Vcard, vcard); 350 SINK_PROPERTY(QByteArray, Vcard, vcard);
339 SINK_REFERENCE_PROPERTY(Addressbook, Addressbook, addressbook); 351 SINK_REFERENCE_PROPERTY(Addressbook, Addressbook, addressbook);
340}; 352};
@@ -362,6 +374,9 @@ struct SINK_EXPORT Folder : public Entity {
362 SINK_PROPERTY(QByteArray, Icon, icon); 374 SINK_PROPERTY(QByteArray, Icon, icon);
363 SINK_PROPERTY(QByteArrayList, SpecialPurpose, specialpurpose); 375 SINK_PROPERTY(QByteArrayList, SpecialPurpose, specialpurpose);
364 SINK_PROPERTY(bool, Enabled, enabled); 376 SINK_PROPERTY(bool, Enabled, enabled);
377 SINK_EXTRACTED_PROPERTY(QDateTime, LastUpdated, lastUpdated);
378 SINK_EXTRACTED_PROPERTY(int, Count, count);
379 SINK_EXTRACTED_PROPERTY(bool, FullContentAvailable, fullContentAvailable);
365}; 380};
366 381
367struct SINK_EXPORT Mail : public Entity { 382struct SINK_EXPORT Mail : public Entity {
@@ -552,6 +567,7 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType::Ptr)
552Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity) 567Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity)
553Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity::Ptr) 568Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity::Ptr)
554Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact) 569Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact)
570Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact::Email)
555Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) 571Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error)
556Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) 572Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress)
557Q_DECLARE_METATYPE(Sink::ApplicationDomain::BLOB) 573Q_DECLARE_METATYPE(Sink::ApplicationDomain::BLOB)
diff --git a/common/domain/contact.fbs b/common/domain/contact.fbs
index 7d7f797..d941d5a 100644
--- a/common/domain/contact.fbs
+++ b/common/domain/contact.fbs
@@ -1,10 +1,17 @@
1namespace Sink.ApplicationDomain.Buffer; 1namespace Sink.ApplicationDomain.Buffer;
2 2
3table ContactEmail {
4 type: int;
5 email: string;
6}
7
3table Contact { 8table Contact {
4 uid:string; 9 uid:string;
5 fn:string; 10 fn:string;
11 firstname:string;
12 lastname:string;
6 addressbook:string; 13 addressbook:string;
7 emails: [string]; 14 emails: [ContactEmail];
8 vcard: string; 15 vcard: string;
9} 16}
10 17
diff --git a/common/domain/propertyregistry.cpp b/common/domain/propertyregistry.cpp
index 2208193..7b9b61a 100644
--- a/common/domain/propertyregistry.cpp
+++ b/common/domain/propertyregistry.cpp
@@ -64,6 +64,17 @@ QVariant parseString<bool>(const QString &s)
64} 64}
65 65
66template <> 66template <>
67QVariant parseString<int>(const QString &s)
68{
69 bool ok = false;
70 auto n = s.toInt(&ok);
71 if (ok) {
72 return QVariant::fromValue(n);
73 }
74 return {};
75}
76
77template <>
67QVariant parseString<QList<QByteArray>>(const QString &s) 78QVariant parseString<QList<QByteArray>>(const QString &s)
68{ 79{
69 auto list = s.split(','); 80 auto list = s.split(',');
@@ -92,6 +103,13 @@ QVariant parseString<QList<Sink::ApplicationDomain::Mail::Contact>>(const QStrin
92 return QVariant{}; 103 return QVariant{};
93} 104}
94 105
106template <>
107QVariant parseString<QList<Sink::ApplicationDomain::Contact::Email>>(const QString &s)
108{
109 Q_ASSERT(false);
110 return QVariant{};
111}
112
95PropertyRegistry &PropertyRegistry::instance() 113PropertyRegistry &PropertyRegistry::instance()
96{ 114{
97 static PropertyRegistry instance; 115 static PropertyRegistry instance;
diff --git a/common/domain/propertyregistry.h b/common/domain/propertyregistry.h
index 16df23b..758c10d 100644
--- a/common/domain/propertyregistry.h
+++ b/common/domain/propertyregistry.h
@@ -49,6 +49,9 @@ template <>
49QVariant parseString<bool>(const QString &s); 49QVariant parseString<bool>(const QString &s);
50 50
51template <> 51template <>
52QVariant parseString<int>(const QString &s);
53
54template <>
52QVariant parseString<QList<QByteArray>>(const QString &s); 55QVariant parseString<QList<QByteArray>>(const QString &s);
53 56
54template <> 57template <>
diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp
index 4d45644..c72cf31 100644
--- a/common/propertymapper.cpp
+++ b/common/propertymapper.cpp
@@ -22,6 +22,7 @@
22#include "applicationdomaintype.h" 22#include "applicationdomaintype.h"
23#include <QDateTime> 23#include <QDateTime>
24#include "mail_generated.h" 24#include "mail_generated.h"
25#include "contact_generated.h"
25 26
26template <> 27template <>
27flatbuffers::uoffset_t variantToProperty<QString>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) 28flatbuffers::uoffset_t variantToProperty<QString>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb)
@@ -110,6 +111,21 @@ flatbuffers::uoffset_t variantToProperty<QList<Sink::ApplicationDomain::Mail::Co
110 return 0; 111 return 0;
111} 112}
112 113
114template <>
115flatbuffers::uoffset_t variantToProperty<QList<Sink::ApplicationDomain::Contact::Email>>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb)
116{
117 if (property.isValid()) {
118 const auto list = property.value<QList<Sink::ApplicationDomain::Contact::Email>>();
119 std::vector<flatbuffers::Offset<Sink::ApplicationDomain::Buffer::ContactEmail>> vector;
120 for (const auto &value : list) {
121 auto offset = Sink::ApplicationDomain::Buffer::CreateContactEmailDirect(fbb, value.type, value.email.toUtf8().constData()).o;
122 vector.push_back(offset);
123 }
124 return fbb.CreateVector(vector).o;
125 }
126 return 0;
127}
128
113 129
114QString propertyToString(const flatbuffers::String *property) 130QString propertyToString(const flatbuffers::String *property)
115{ 131{
@@ -217,6 +233,20 @@ QVariant propertyToVariant<QList<Sink::ApplicationDomain::Mail::Contact>>(const
217} 233}
218 234
219template <> 235template <>
236QVariant propertyToVariant<QList<Sink::ApplicationDomain::Contact::Email>>(const flatbuffers::Vector<flatbuffers::Offset<Sink::ApplicationDomain::Buffer::ContactEmail>> *property)
237{
238 if (property) {
239 QList<Sink::ApplicationDomain::Contact::Email> list;
240 for (auto it = property->begin(); it != property->end();) {
241 list << Sink::ApplicationDomain::Contact::Email{static_cast<Sink::ApplicationDomain::Contact::Email::Type>(it->type()), propertyToString(it->email())};
242 it.operator++();
243 }
244 return QVariant::fromValue(list);
245 }
246 return QVariant();
247}
248
249template <>
220QVariant propertyToVariant<bool>(uint8_t property) 250QVariant propertyToVariant<bool>(uint8_t property)
221{ 251{
222 return static_cast<bool>(property); 252 return static_cast<bool>(property);
diff --git a/common/propertymapper.h b/common/propertymapper.h
index 70491a1..9ea0b73 100644
--- a/common/propertymapper.h
+++ b/common/propertymapper.h
@@ -29,6 +29,7 @@ namespace Sink {
29namespace ApplicationDomain { 29namespace ApplicationDomain {
30namespace Buffer { 30namespace Buffer {
31 struct MailContact; 31 struct MailContact;
32 struct ContactEmail;
32} 33}
33} 34}
34} 35}
@@ -54,6 +55,8 @@ template <typename T>
54QVariant SINK_EXPORT propertyToVariant(const Sink::ApplicationDomain::Buffer::MailContact *); 55QVariant SINK_EXPORT propertyToVariant(const Sink::ApplicationDomain::Buffer::MailContact *);
55template <typename T> 56template <typename T>
56QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<flatbuffers::Offset<Sink::ApplicationDomain::Buffer::MailContact>> *); 57QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<flatbuffers::Offset<Sink::ApplicationDomain::Buffer::MailContact>> *);
58template <typename T>
59QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<flatbuffers::Offset<Sink::ApplicationDomain::Buffer::ContactEmail>> *);
57 60
58/** 61/**
59 * The property mapper is a non-typesafe virtual dispatch. 62 * The property mapper is a non-typesafe virtual dispatch.
@@ -131,6 +134,12 @@ public:
131 addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<typename T::Type>((buffer->*f)()); }); 134 addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<typename T::Type>((buffer->*f)()); });
132 } 135 }
133 136
137 template <typename T, typename Buffer>
138 void addMapping(const flatbuffers::Vector<flatbuffers::Offset<Sink::ApplicationDomain::Buffer::ContactEmail>> *(Buffer::*f)() const)
139 {
140 addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<typename T::Type>((buffer->*f)()); });
141 }
142
134private: 143private:
135 QHash<QByteArray, std::function<QVariant(BufferType const *)>> mReadAccessors; 144 QHash<QByteArray, std::function<QVariant(BufferType const *)>> mReadAccessors;
136}; 145};
@@ -218,6 +227,15 @@ public:
218 }); 227 });
219 } 228 }
220 229
230 template <typename T>
231 void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Sink::ApplicationDomain::Buffer::ContactEmail>>>))
232 {
233 addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> {
234 auto offset = variantToProperty<typename T::Type>(value, fbb);
235 return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); };
236 });
237 }
238
221private: 239private:
222 QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors; 240 QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors;
223}; 241};
diff --git a/docs/applicationdomaintypes.md b/docs/applicationdomaintypes.md
index 09fec9f..48fe17c 100644
--- a/docs/applicationdomaintypes.md
+++ b/docs/applicationdomaintypes.md
@@ -56,7 +56,7 @@ Event:
56``` 56```
57```no-highlight 57```no-highlight
58Mail: 58Mail:
59 uid [QByteArray]: The message id. 59 messageId [QByteArray]: The message id.
60 subject [QString]: The subject of the email. 60 subject [QString]: The subject of the email.
61 folder [MailFolder.id]: The parent folder. 61 folder [MailFolder.id]: The parent folder.
62 date [QDateTime]: The date of the email. 62 date [QDateTime]: The date of the email.
@@ -67,6 +67,25 @@ Mail Folder:
67 parent [MailFolder.id]: The parent folder. 67 parent [MailFolder.id]: The parent folder.
68 name [QString]: The user visible name of the folder. 68 name [QString]: The user visible name of the folder.
69 icon [QString]: The name of the icon of the folder. 69 icon [QString]: The name of the icon of the folder.
70 lastUpdated [QDateTime]: time of last successful update.
71 count [int]: Number of messages available on the server.
72 fullDataAvailable [bool]: Inidicates whether the local dataset is complete.
73```
74```no-highlight
75Contact:
76 uid [QByteArray]: The contact uid.
77 fn [QString]: The full name.
78 firstName [QString]: The first name.
79 lastName [QString]: The last name.
80 addressbook [Addressbook.id]: The parent addressbook.
81 emails [Email]: The availale email addresses.
82```
83```no-highlight
84Addressbook:
85 parent [Addressbook.id]: The parent addressbook.
86 name [QString]: The user visible name of the addressbook.
87 icon [QString]: The name of the icon of the addressbook.
88 lastUpdated [QDateTime]: time of last successful update.
70``` 89```
71```no-highlight 90```no-highlight
72Sink Resource: 91Sink Resource: