summaryrefslogtreecommitdiffstats
path: root/common/domain/mail.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/domain/mail.cpp')
-rw-r--r--common/domain/mail.cpp101
1 files changed, 101 insertions, 0 deletions
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
35using namespace Akonadi2::ApplicationDomain;
36
37ResultSet 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
53void 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
62QSharedPointer<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
89QSharedPointer<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}