From e1430017eb60976610f4963cd770116a4a486c2e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 23 Mar 2017 14:02:15 +0100 Subject: New properties --- common/contactpreprocessor.cpp | 6 ++++-- common/domain/applicationdomaintype.cpp | 5 +++++ common/domain/applicationdomaintype.h | 18 +++++++++++++++++- common/domain/contact.fbs | 9 ++++++++- common/domain/propertyregistry.cpp | 18 ++++++++++++++++++ common/domain/propertyregistry.h | 3 +++ common/propertymapper.cpp | 30 ++++++++++++++++++++++++++++++ common/propertymapper.h | 18 ++++++++++++++++++ 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 { contact.setUid(addressee.uid()); contact.setFn(addressee.formattedName()); - QByteArrayList emails; + contact.setFirstname(addressee.givenName()); + contact.setLastname(addressee.familyName()); + QList emails; for (const auto &email : addressee.emails()) { - emails << email.toUtf8(); + emails << Sink::ApplicationDomain::Contact::Email{Sink::ApplicationDomain::Contact::Email::Undefined, email}; } contact.setEmails(emails); } 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); SINK_REGISTER_PROPERTY(Folder, SpecialPurpose); SINK_REGISTER_PROPERTY(Folder, Enabled); SINK_REGISTER_PROPERTY(Folder, Parent); +SINK_REGISTER_PROPERTY(Folder, Count); +SINK_REGISTER_PROPERTY(Folder, FullContentAvailable); SINK_REGISTER_PROPERTY(Contact, Uid); SINK_REGISTER_PROPERTY(Contact, Fn); +SINK_REGISTER_PROPERTY(Contact, Firstname); +SINK_REGISTER_PROPERTY(Contact, Lastname); 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); +SINK_REGISTER_PROPERTY(Addressbook, LastUpdated); static const int foo = [] { QMetaType::registerEqualsComparator(); 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 { SINK_ENTITY(Addressbook); SINK_REFERENCE_PROPERTY(Addressbook, Parent, parent); SINK_PROPERTY(QString, Name, name); + SINK_EXTRACTED_PROPERTY(QDateTime, LastUpdated, lastUpdated); }; struct SINK_EXPORT Contact : public Entity { + struct SINK_EXPORT Email { + enum Type { + Undefined, + Work, + Home + }; + Type type; + QString email; + }; SINK_ENTITY(Contact); SINK_PROPERTY(QString, Uid, uid); SINK_PROPERTY(QString, Fn, fn); - SINK_PROPERTY(QByteArrayList, Emails, emails); + SINK_PROPERTY(QString, Firstname, firstname); + SINK_PROPERTY(QString, Lastname, lastname); + SINK_PROPERTY(QList, Emails, emails); SINK_PROPERTY(QByteArray, Vcard, vcard); SINK_REFERENCE_PROPERTY(Addressbook, Addressbook, addressbook); }; @@ -362,6 +374,9 @@ struct SINK_EXPORT Folder : public Entity { SINK_PROPERTY(QByteArray, Icon, icon); SINK_PROPERTY(QByteArrayList, SpecialPurpose, specialpurpose); SINK_PROPERTY(bool, Enabled, enabled); + SINK_EXTRACTED_PROPERTY(QDateTime, LastUpdated, lastUpdated); + SINK_EXTRACTED_PROPERTY(int, Count, count); + SINK_EXTRACTED_PROPERTY(bool, FullContentAvailable, fullContentAvailable); }; struct SINK_EXPORT Mail : public Entity { @@ -552,6 +567,7 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::ApplicationDomainType::Ptr) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Entity::Ptr) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact::Email) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) 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 @@ namespace Sink.ApplicationDomain.Buffer; +table ContactEmail { + type: int; + email: string; +} + table Contact { uid:string; fn:string; + firstname:string; + lastname:string; addressbook:string; - emails: [string]; + emails: [ContactEmail]; vcard: string; } 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 @@ -63,6 +63,17 @@ QVariant parseString(const QString &s) return QVariant::fromValue(false); } +template <> +QVariant parseString(const QString &s) +{ + bool ok = false; + auto n = s.toInt(&ok); + if (ok) { + return QVariant::fromValue(n); + } + return {}; +} + template <> QVariant parseString>(const QString &s) { @@ -92,6 +103,13 @@ QVariant parseString>(const QStrin return QVariant{}; } +template <> +QVariant parseString>(const QString &s) +{ + Q_ASSERT(false); + return QVariant{}; +} + PropertyRegistry &PropertyRegistry::instance() { 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 @@ -48,6 +48,9 @@ QVariant parseString(const QString &s); template <> QVariant parseString(const QString &s); +template <> +QVariant parseString(const QString &s); + template <> QVariant parseString>(const QString &s); 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 @@ #include "applicationdomaintype.h" #include #include "mail_generated.h" +#include "contact_generated.h" template <> flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) @@ -110,6 +111,21 @@ flatbuffers::uoffset_t variantToProperty +flatbuffers::uoffset_t variantToProperty>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) +{ + if (property.isValid()) { + const auto list = property.value>(); + std::vector> vector; + for (const auto &value : list) { + auto offset = Sink::ApplicationDomain::Buffer::CreateContactEmailDirect(fbb, value.type, value.email.toUtf8().constData()).o; + vector.push_back(offset); + } + return fbb.CreateVector(vector).o; + } + return 0; +} + QString propertyToString(const flatbuffers::String *property) { @@ -216,6 +232,20 @@ QVariant propertyToVariant>(const return QVariant(); } +template <> +QVariant propertyToVariant>(const flatbuffers::Vector> *property) +{ + if (property) { + QList list; + for (auto it = property->begin(); it != property->end();) { + list << Sink::ApplicationDomain::Contact::Email{static_cast(it->type()), propertyToString(it->email())}; + it.operator++(); + } + return QVariant::fromValue(list); + } + return QVariant(); +} + template <> QVariant propertyToVariant(uint8_t 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 { namespace ApplicationDomain { namespace Buffer { struct MailContact; + struct ContactEmail; } } } @@ -54,6 +55,8 @@ template QVariant SINK_EXPORT propertyToVariant(const Sink::ApplicationDomain::Buffer::MailContact *); template QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector> *); +template +QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector> *); /** * The property mapper is a non-typesafe virtual dispatch. @@ -131,6 +134,12 @@ public: addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); } + template + void addMapping(const flatbuffers::Vector> *(Buffer::*f)() const) + { + addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant((buffer->*f)()); }); + } + private: QHash> mReadAccessors; }; @@ -218,6 +227,15 @@ public: }); } + template + void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset>>)) + { + addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { + auto offset = variantToProperty(value, fbb); + return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); }; + }); + } + private: QHash(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors; }; 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: ``` ```no-highlight Mail: - uid [QByteArray]: The message id. + messageId [QByteArray]: The message id. subject [QString]: The subject of the email. folder [MailFolder.id]: The parent folder. date [QDateTime]: The date of the email. @@ -67,6 +67,25 @@ Mail Folder: parent [MailFolder.id]: The parent folder. name [QString]: The user visible name of the folder. icon [QString]: The name of the icon of the folder. + lastUpdated [QDateTime]: time of last successful update. + count [int]: Number of messages available on the server. + fullDataAvailable [bool]: Inidicates whether the local dataset is complete. +``` +```no-highlight +Contact: + uid [QByteArray]: The contact uid. + fn [QString]: The full name. + firstName [QString]: The first name. + lastName [QString]: The last name. + addressbook [Addressbook.id]: The parent addressbook. + emails [Email]: The availale email addresses. +``` +```no-highlight +Addressbook: + parent [Addressbook.id]: The parent addressbook. + name [QString]: The user visible name of the addressbook. + icon [QString]: The name of the icon of the addressbook. + lastUpdated [QDateTime]: time of last successful update. ``` ```no-highlight Sink Resource: -- cgit v1.2.3