diff options
-rw-r--r-- | common/contactpreprocessor.cpp | 6 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 5 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.h | 18 | ||||
-rw-r--r-- | common/domain/contact.fbs | 9 | ||||
-rw-r--r-- | common/domain/propertyregistry.cpp | 18 | ||||
-rw-r--r-- | common/domain/propertyregistry.h | 3 | ||||
-rw-r--r-- | common/propertymapper.cpp | 30 | ||||
-rw-r--r-- | common/propertymapper.h | 18 | ||||
-rw-r--r-- | docs/applicationdomaintypes.md | 21 |
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); | |||
95 | SINK_REGISTER_PROPERTY(Folder, SpecialPurpose); | 95 | SINK_REGISTER_PROPERTY(Folder, SpecialPurpose); |
96 | SINK_REGISTER_PROPERTY(Folder, Enabled); | 96 | SINK_REGISTER_PROPERTY(Folder, Enabled); |
97 | SINK_REGISTER_PROPERTY(Folder, Parent); | 97 | SINK_REGISTER_PROPERTY(Folder, Parent); |
98 | SINK_REGISTER_PROPERTY(Folder, Count); | ||
99 | SINK_REGISTER_PROPERTY(Folder, FullContentAvailable); | ||
98 | 100 | ||
99 | SINK_REGISTER_PROPERTY(Contact, Uid); | 101 | SINK_REGISTER_PROPERTY(Contact, Uid); |
100 | SINK_REGISTER_PROPERTY(Contact, Fn); | 102 | SINK_REGISTER_PROPERTY(Contact, Fn); |
103 | SINK_REGISTER_PROPERTY(Contact, Firstname); | ||
104 | SINK_REGISTER_PROPERTY(Contact, Lastname); | ||
101 | SINK_REGISTER_PROPERTY(Contact, Emails); | 105 | SINK_REGISTER_PROPERTY(Contact, Emails); |
102 | SINK_REGISTER_PROPERTY(Contact, Vcard); | 106 | SINK_REGISTER_PROPERTY(Contact, Vcard); |
103 | SINK_REGISTER_PROPERTY(Contact, Addressbook); | 107 | SINK_REGISTER_PROPERTY(Contact, Addressbook); |
104 | 108 | ||
105 | SINK_REGISTER_PROPERTY(Addressbook, Name); | 109 | SINK_REGISTER_PROPERTY(Addressbook, Name); |
106 | SINK_REGISTER_PROPERTY(Addressbook, Parent); | 110 | SINK_REGISTER_PROPERTY(Addressbook, Parent); |
111 | SINK_REGISTER_PROPERTY(Addressbook, LastUpdated); | ||
107 | 112 | ||
108 | static const int foo = [] { | 113 | static 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 | ||
333 | struct SINK_EXPORT Contact : public Entity { | 334 | struct 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 | ||
367 | struct SINK_EXPORT Mail : public Entity { | 382 | struct SINK_EXPORT Mail : public Entity { |
@@ -552,6 +567,7 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType::Ptr) | |||
552 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity) | 567 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity) |
553 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity::Ptr) | 568 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity::Ptr) |
554 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact) | 569 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact) |
570 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact::Email) | ||
555 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) | 571 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) |
556 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) | 572 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) |
557 | Q_DECLARE_METATYPE(Sink::ApplicationDomain::BLOB) | 573 | Q_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 @@ | |||
1 | namespace Sink.ApplicationDomain.Buffer; | 1 | namespace Sink.ApplicationDomain.Buffer; |
2 | 2 | ||
3 | table ContactEmail { | ||
4 | type: int; | ||
5 | email: string; | ||
6 | } | ||
7 | |||
3 | table Contact { | 8 | table 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 | ||
66 | template <> | 66 | template <> |
67 | QVariant 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 | |||
77 | template <> | ||
67 | QVariant parseString<QList<QByteArray>>(const QString &s) | 78 | QVariant 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 | ||
106 | template <> | ||
107 | QVariant parseString<QList<Sink::ApplicationDomain::Contact::Email>>(const QString &s) | ||
108 | { | ||
109 | Q_ASSERT(false); | ||
110 | return QVariant{}; | ||
111 | } | ||
112 | |||
95 | PropertyRegistry &PropertyRegistry::instance() | 113 | PropertyRegistry &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 <> | |||
49 | QVariant parseString<bool>(const QString &s); | 49 | QVariant parseString<bool>(const QString &s); |
50 | 50 | ||
51 | template <> | 51 | template <> |
52 | QVariant parseString<int>(const QString &s); | ||
53 | |||
54 | template <> | ||
52 | QVariant parseString<QList<QByteArray>>(const QString &s); | 55 | QVariant parseString<QList<QByteArray>>(const QString &s); |
53 | 56 | ||
54 | template <> | 57 | template <> |
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 | ||
26 | template <> | 27 | template <> |
27 | flatbuffers::uoffset_t variantToProperty<QString>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) | 28 | flatbuffers::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 | ||
114 | template <> | ||
115 | flatbuffers::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 | ||
114 | QString propertyToString(const flatbuffers::String *property) | 130 | QString propertyToString(const flatbuffers::String *property) |
115 | { | 131 | { |
@@ -217,6 +233,20 @@ QVariant propertyToVariant<QList<Sink::ApplicationDomain::Mail::Contact>>(const | |||
217 | } | 233 | } |
218 | 234 | ||
219 | template <> | 235 | template <> |
236 | QVariant 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 | |||
249 | template <> | ||
220 | QVariant propertyToVariant<bool>(uint8_t property) | 250 | QVariant 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 { | |||
29 | namespace ApplicationDomain { | 29 | namespace ApplicationDomain { |
30 | namespace Buffer { | 30 | namespace Buffer { |
31 | struct MailContact; | 31 | struct MailContact; |
32 | struct ContactEmail; | ||
32 | } | 33 | } |
33 | } | 34 | } |
34 | } | 35 | } |
@@ -54,6 +55,8 @@ template <typename T> | |||
54 | QVariant SINK_EXPORT propertyToVariant(const Sink::ApplicationDomain::Buffer::MailContact *); | 55 | QVariant SINK_EXPORT propertyToVariant(const Sink::ApplicationDomain::Buffer::MailContact *); |
55 | template <typename T> | 56 | template <typename T> |
56 | QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<flatbuffers::Offset<Sink::ApplicationDomain::Buffer::MailContact>> *); | 57 | QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<flatbuffers::Offset<Sink::ApplicationDomain::Buffer::MailContact>> *); |
58 | template <typename T> | ||
59 | QVariant 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 | |||
134 | private: | 143 | private: |
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 | |||
221 | private: | 239 | private: |
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 |
58 | Mail: | 58 | Mail: |
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 | ||
75 | Contact: | ||
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 | ||
84 | Addressbook: | ||
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 |
72 | Sink Resource: | 91 | Sink Resource: |