diff options
-rw-r--r-- | common/domain/event.cpp | 8 | ||||
-rw-r--r-- | common/domain/mail.cpp | 32 | ||||
-rw-r--r-- | common/propertymapper.h | 16 |
3 files changed, 26 insertions, 30 deletions
diff --git a/common/domain/event.cpp b/common/domain/event.cpp index e107441..38872f9 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp | |||
@@ -62,12 +62,8 @@ void TypeImplementation<Event>::index(const Event &type, Akonadi2::Storage::Tran | |||
62 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Event>::Buffer> > TypeImplementation<Event>::initializeReadPropertyMapper() | 62 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Event>::Buffer> > TypeImplementation<Event>::initializeReadPropertyMapper() |
63 | { | 63 | { |
64 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); | 64 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); |
65 | propertyMapper->addMapping("summary", [](Buffer const *buffer) -> QVariant { | 65 | propertyMapper->addMapping<QString, Buffer>("summary", &Buffer::summary); |
66 | return propertyToVariant<QString>(buffer->summary()); | 66 | propertyMapper->addMapping<QString, Buffer>("uid", &Buffer::uid); |
67 | }); | ||
68 | propertyMapper->addMapping("uid", [](Buffer const *buffer) -> QVariant { | ||
69 | return propertyToVariant<QString>(buffer->uid()); | ||
70 | }); | ||
71 | return propertyMapper; | 67 | return propertyMapper; |
72 | } | 68 | } |
73 | 69 | ||
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp index 230ef31..d40dde9 100644 --- a/common/domain/mail.cpp +++ b/common/domain/mail.cpp | |||
@@ -62,30 +62,14 @@ void TypeImplementation<Mail>::index(const Mail &type, Akonadi2::Storage::Transa | |||
62 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplementation<Mail>::initializeReadPropertyMapper() | 62 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplementation<Mail>::initializeReadPropertyMapper() |
63 | { | 63 | { |
64 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); | 64 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); |
65 | propertyMapper->addMapping("uid", [](Buffer const *buffer) -> QVariant { | 65 | propertyMapper->addMapping<QString, Buffer>("uid", &Buffer::uid); |
66 | return propertyToVariant<QString>(buffer->uid()); | 66 | propertyMapper->addMapping<QString, Buffer>("sender", &Buffer::sender); |
67 | }); | 67 | propertyMapper->addMapping<QString, Buffer>("senderName", &Buffer::senderName); |
68 | propertyMapper->addMapping("sender", [](Buffer const *buffer) -> QVariant { | 68 | propertyMapper->addMapping<QString, Buffer>("subject", &Buffer::subject); |
69 | return propertyToVariant<QString>(buffer->sender()); | 69 | propertyMapper->addMapping<QString, Buffer>("date", &Buffer::date); |
70 | }); | 70 | propertyMapper->addMapping<bool, Buffer>("unread", &Buffer::unread); |
71 | propertyMapper->addMapping("senderName", [](Buffer const *buffer) -> QVariant { | 71 | propertyMapper->addMapping<bool, Buffer>("important", &Buffer::important); |
72 | return propertyToVariant<QString>(buffer->senderName()); | 72 | propertyMapper->addMapping<QString, Buffer>("folder", &Buffer::folder); |
73 | }); | ||
74 | propertyMapper->addMapping("subject", [](Buffer const *buffer) -> QVariant { | ||
75 | return propertyToVariant<QString>(buffer->subject()); | ||
76 | }); | ||
77 | propertyMapper->addMapping("date", [](Buffer const *buffer) -> QVariant { | ||
78 | return propertyToVariant<QString>(buffer->date()); | ||
79 | }); | ||
80 | propertyMapper->addMapping("unread", [](Buffer const *buffer) -> QVariant { | ||
81 | return propertyToVariant<bool>(buffer->unread()); | ||
82 | }); | ||
83 | propertyMapper->addMapping("important", [](Buffer const *buffer) -> QVariant { | ||
84 | return propertyToVariant<bool>(buffer->important()); | ||
85 | }); | ||
86 | propertyMapper->addMapping("folder", [](Buffer const *buffer) -> QVariant { | ||
87 | return propertyToVariant<QString>(buffer->folder()); | ||
88 | }); | ||
89 | return propertyMapper; | 73 | return propertyMapper; |
90 | } | 74 | } |
91 | 75 | ||
diff --git a/common/propertymapper.h b/common/propertymapper.h index 72468e2..87c7485 100644 --- a/common/propertymapper.h +++ b/common/propertymapper.h | |||
@@ -63,6 +63,22 @@ public: | |||
63 | void addMapping(const QByteArray &property, const std::function<QVariant(BufferType const *)> &mapping) { | 63 | void addMapping(const QByteArray &property, const std::function<QVariant(BufferType const *)> &mapping) { |
64 | mReadAccessors.insert(property, mapping); | 64 | mReadAccessors.insert(property, mapping); |
65 | } | 65 | } |
66 | |||
67 | template <typename T, typename Buffer> | ||
68 | void addMapping(const QByteArray &name, const flatbuffers::String *(Buffer::*f)() const) | ||
69 | { | ||
70 | addMapping(name, [f](Buffer const *buffer) -> QVariant { | ||
71 | return propertyToVariant<T>((buffer->*f)()); | ||
72 | }); | ||
73 | } | ||
74 | |||
75 | template <typename T, typename Buffer> | ||
76 | void addMapping(const QByteArray &name, uint8_t (Buffer::*f)() const) | ||
77 | { | ||
78 | addMapping(name, [f](Buffer const *buffer) -> QVariant { | ||
79 | return propertyToVariant<T>((buffer->*f)()); | ||
80 | }); | ||
81 | } | ||
66 | private: | 82 | private: |
67 | QHash<QByteArray, std::function<QVariant(BufferType const *)> > mReadAccessors; | 83 | QHash<QByteArray, std::function<QVariant(BufferType const *)> > mReadAccessors; |
68 | }; | 84 | }; |