diff options
Diffstat (limited to 'common/domain')
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 12 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.h | 14 | ||||
-rw-r--r-- | common/domain/mail.cpp | 101 | ||||
-rw-r--r-- | common/domain/mail.fbs | 14 | ||||
-rw-r--r-- | common/domain/mail.h | 60 |
5 files changed, 199 insertions, 2 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 47ff0c3..3cc075b 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -40,6 +40,18 @@ QByteArray getTypeName<AkonadiResource>() | |||
40 | return "akonadiresource"; | 40 | return "akonadiresource"; |
41 | } | 41 | } |
42 | 42 | ||
43 | template<> | ||
44 | QByteArray getTypeName<Mail>() | ||
45 | { | ||
46 | return "mail"; | ||
47 | } | ||
48 | |||
49 | template<> | ||
50 | QByteArray getTypeName<Folder>() | ||
51 | { | ||
52 | return "folder"; | ||
53 | } | ||
54 | |||
43 | } | 55 | } |
44 | } | 56 | } |
45 | 57 | ||
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 29bebcf..e0a6de0 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -112,10 +112,14 @@ struct Calendar : public ApplicationDomainType { | |||
112 | using ApplicationDomainType::ApplicationDomainType; | 112 | using ApplicationDomainType::ApplicationDomainType; |
113 | }; | 113 | }; |
114 | 114 | ||
115 | class Mail : public ApplicationDomainType { | 115 | struct Mail : public ApplicationDomainType { |
116 | typedef QSharedPointer<Mail> Ptr; | ||
117 | using ApplicationDomainType::ApplicationDomainType; | ||
116 | }; | 118 | }; |
117 | 119 | ||
118 | class Folder : public ApplicationDomainType { | 120 | struct Folder : public ApplicationDomainType { |
121 | typedef QSharedPointer<Folder> Ptr; | ||
122 | using ApplicationDomainType::ApplicationDomainType; | ||
119 | }; | 123 | }; |
120 | 124 | ||
121 | /** | 125 | /** |
@@ -146,6 +150,12 @@ QByteArray getTypeName<Todo>(); | |||
146 | template<> | 150 | template<> |
147 | QByteArray getTypeName<AkonadiResource>(); | 151 | QByteArray getTypeName<AkonadiResource>(); |
148 | 152 | ||
153 | template<> | ||
154 | QByteArray getTypeName<Mail>(); | ||
155 | |||
156 | template<> | ||
157 | QByteArray getTypeName<Folder>(); | ||
158 | |||
149 | /** | 159 | /** |
150 | * Type implementation. | 160 | * Type implementation. |
151 | * | 161 | * |
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp new file mode 100644 index 0000000..c52bfe0 --- /dev/null +++ b/common/domain/mail.cpp | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
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 "mail.h" | ||
20 | |||
21 | #include <QVector> | ||
22 | #include <QByteArray> | ||
23 | #include <QString> | ||
24 | |||
25 | #include "../resultset.h" | ||
26 | #include "../index.h" | ||
27 | #include "../storage.h" | ||
28 | #include "../log.h" | ||
29 | #include "../propertymapper.h" | ||
30 | #include "../query.h" | ||
31 | #include "../definitions.h" | ||
32 | |||
33 | #include "mail_generated.h" | ||
34 | |||
35 | using namespace Akonadi2::ApplicationDomain; | ||
36 | |||
37 | ResultSet TypeImplementation<Mail>::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, Akonadi2::Storage::Transaction &transaction) | ||
38 | { | ||
39 | QVector<QByteArray> keys; | ||
40 | if (query.propertyFilter.contains("uid")) { | ||
41 | Index uidIndex("mail.index.uid", transaction); | ||
42 | uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { | ||
43 | keys << value; | ||
44 | }, | ||
45 | [](const Index::Error &error) { | ||
46 | Warning() << "Error in uid index: " << error.message; | ||
47 | }); | ||
48 | appliedFilters << "uid"; | ||
49 | } | ||
50 | return ResultSet(keys); | ||
51 | } | ||
52 | |||
53 | void TypeImplementation<Mail>::index(const Mail &type, Akonadi2::Storage::Transaction &transaction) | ||
54 | { | ||
55 | const auto uid = type.getProperty("uid"); | ||
56 | if (uid.isValid()) { | ||
57 | Index uidIndex("mail.index.uid", transaction); | ||
58 | uidIndex.add(uid.toByteArray(), type.identifier()); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplementation<Mail>::initializeReadPropertyMapper() | ||
63 | { | ||
64 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); | ||
65 | propertyMapper->addMapping("uid", [](Buffer const *buffer) -> QVariant { | ||
66 | return propertyToVariant<QString>(buffer->uid()); | ||
67 | }); | ||
68 | propertyMapper->addMapping("sender", [](Buffer const *buffer) -> QVariant { | ||
69 | return propertyToVariant<QString>(buffer->sender()); | ||
70 | }); | ||
71 | propertyMapper->addMapping("senderName", [](Buffer const *buffer) -> QVariant { | ||
72 | return propertyToVariant<QString>(buffer->senderName()); | ||
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 | return propertyMapper; | ||
87 | } | ||
88 | |||
89 | QSharedPointer<WritePropertyMapper<TypeImplementation<Mail>::BufferBuilder> > TypeImplementation<Mail>::initializeWritePropertyMapper() | ||
90 | { | ||
91 | auto propertyMapper = QSharedPointer<WritePropertyMapper<BufferBuilder> >::create(); | ||
92 | // propertyMapper->addMapping("summary", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | ||
93 | // auto offset = variantToProperty<QString>(value, fbb); | ||
94 | // return [offset](BufferBuilder &builder) { builder.add_summary(offset); }; | ||
95 | // }); | ||
96 | propertyMapper->addMapping("uid", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | ||
97 | auto offset = variantToProperty<QString>(value, fbb); | ||
98 | return [offset](BufferBuilder &builder) { builder.add_uid(offset); }; | ||
99 | }); | ||
100 | return propertyMapper; | ||
101 | } | ||
diff --git a/common/domain/mail.fbs b/common/domain/mail.fbs new file mode 100644 index 0000000..654f49c --- /dev/null +++ b/common/domain/mail.fbs | |||
@@ -0,0 +1,14 @@ | |||
1 | namespace Akonadi2.ApplicationDomain.Buffer; | ||
2 | |||
3 | table Mail { | ||
4 | uid:string; | ||
5 | sender:string; | ||
6 | senderName:string; | ||
7 | subject:string; | ||
8 | date:string; | ||
9 | unread:bool = false; | ||
10 | important:bool = false; | ||
11 | } | ||
12 | |||
13 | root_type Mail; | ||
14 | file_identifier "AKFB"; | ||
diff --git a/common/domain/mail.h b/common/domain/mail.h new file mode 100644 index 0000000..b58ce44 --- /dev/null +++ b/common/domain/mail.h | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
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 | |||
23 | #include "storage.h" | ||
24 | |||
25 | class ResultSet; | ||
26 | class QByteArray; | ||
27 | |||
28 | template<typename T> | ||
29 | class ReadPropertyMapper; | ||
30 | template<typename T> | ||
31 | class WritePropertyMapper; | ||
32 | |||
33 | namespace Akonadi2 { | ||
34 | class Query; | ||
35 | |||
36 | namespace ApplicationDomain { | ||
37 | namespace Buffer { | ||
38 | struct Mail; | ||
39 | struct MailBuilder; | ||
40 | } | ||
41 | |||
42 | template<> | ||
43 | class TypeImplementation<Akonadi2::ApplicationDomain::Mail> { | ||
44 | public: | ||
45 | typedef Akonadi2::ApplicationDomain::Buffer::Mail Buffer; | ||
46 | typedef Akonadi2::ApplicationDomain::Buffer::MailBuilder BufferBuilder; | ||
47 | static QSet<QByteArray> indexedProperties(); | ||
48 | /** | ||
49 | * Returns the potential result set based on the indexes. | ||
50 | * | ||
51 | * An empty result set indicates that a full scan is required. | ||
52 | */ | ||
53 | static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, Akonadi2::Storage::Transaction &transaction); | ||
54 | static void index(const Mail &type, Akonadi2::Storage::Transaction &transaction); | ||
55 | static QSharedPointer<ReadPropertyMapper<Buffer> > initializeReadPropertyMapper(); | ||
56 | static QSharedPointer<WritePropertyMapper<BufferBuilder> > initializeWritePropertyMapper(); | ||
57 | }; | ||
58 | |||
59 | } | ||
60 | } | ||