summaryrefslogtreecommitdiffstats
path: root/common/domain
diff options
context:
space:
mode:
Diffstat (limited to 'common/domain')
-rw-r--r--common/domain/applicationdomaintype.cpp9
-rw-r--r--common/domain/applicationdomaintype.h4
-rw-r--r--common/domain/dummy.fbs7
-rw-r--r--common/domain/event.cpp1
-rw-r--r--common/domain/folder.cpp100
-rw-r--r--common/domain/folder.fbs9
-rw-r--r--common/domain/folder.h56
7 files changed, 184 insertions, 2 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp
index 1b5d870..c9a8bba 100644
--- a/common/domain/applicationdomaintype.cpp
+++ b/common/domain/applicationdomaintype.cpp
@@ -60,10 +60,13 @@ ApplicationDomainType& ApplicationDomainType::operator=(const ApplicationDomainT
60 return *this; 60 return *this;
61} 61}
62 62
63ApplicationDomainType::~ApplicationDomainType() {} 63ApplicationDomainType::~ApplicationDomainType()
64{
65}
64 66
65QVariant ApplicationDomainType::getProperty(const QByteArray &key) const 67QVariant ApplicationDomainType::getProperty(const QByteArray &key) const
66{ 68{
69 Q_ASSERT(mAdaptor);
67 if (!mAdaptor->availableProperties().contains(key)) { 70 if (!mAdaptor->availableProperties().contains(key)) {
68 Warning() << "No such property available " << key; 71 Warning() << "No such property available " << key;
69 } 72 }
@@ -72,7 +75,9 @@ QVariant ApplicationDomainType::getProperty(const QByteArray &key) const
72 75
73void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) 76void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value)
74{ 77{
75 mChangeSet.insert(key, value); mAdaptor->setProperty(key, value); 78 Q_ASSERT(mAdaptor);
79 mChangeSet.insert(key, value);
80 mAdaptor->setProperty(key, value);
76} 81}
77 82
78QByteArrayList ApplicationDomainType::changedProperties() const 83QByteArrayList ApplicationDomainType::changedProperties() const
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index 5514d26..227ab4d 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -160,3 +160,7 @@ Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Event)
160Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Event::Ptr) 160Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Event::Ptr)
161Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail) 161Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail)
162Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail::Ptr) 162Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Mail::Ptr)
163Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Folder)
164Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::Folder::Ptr)
165Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::AkonadiResource)
166Q_DECLARE_METATYPE(Akonadi2::ApplicationDomain::AkonadiResource::Ptr)
diff --git a/common/domain/dummy.fbs b/common/domain/dummy.fbs
new file mode 100644
index 0000000..8816b09
--- /dev/null
+++ b/common/domain/dummy.fbs
@@ -0,0 +1,7 @@
1namespace Akonadi2.ApplicationDomain.Buffer;
2
3table Dummy {
4}
5
6root_type Dummy;
7file_identifier "AKFB";
diff --git a/common/domain/event.cpp b/common/domain/event.cpp
index 87e13bc..42c13e2 100644
--- a/common/domain/event.cpp
+++ b/common/domain/event.cpp
@@ -47,6 +47,7 @@ ResultSet TypeImplementation<Event>::queryIndexes(const Akonadi2::Query &query,
47 }); 47 });
48 appliedFilters << "uid"; 48 appliedFilters << "uid";
49 } 49 }
50 Trace() << "Index lookup found " << keys.size() << " keys.";
50 return ResultSet(keys); 51 return ResultSet(keys);
51} 52}
52 53
diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp
new file mode 100644
index 0000000..989d2c4
--- /dev/null
+++ b/common/domain/folder.cpp
@@ -0,0 +1,100 @@
1/*
2 * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastfolder.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 "folder.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 "folder_generated.h"
34
35using namespace Akonadi2::ApplicationDomain;
36
37ResultSet TypeImplementation<Folder>::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("parent")) {
41 Index index("folder.index.parent", transaction);
42 auto lookupKey = query.propertyFilter.value("parent").toByteArray();
43 if (lookupKey.isEmpty()) {
44 lookupKey = "toplevel";
45 }
46 index.lookup(lookupKey, [&](const QByteArray &value) {
47 keys << value;
48 },
49 [](const Index::Error &error) {
50 Warning() << "Error in uid index: " << error.message;
51 });
52 appliedFilters << "parent";
53 }
54 Trace() << "Index lookup found " << keys.size() << " keys.";
55 return ResultSet(keys);
56}
57
58void TypeImplementation<Folder>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction)
59{
60 const auto parent = bufferAdaptor.getProperty("parent");
61 Trace() << "indexing " << identifier << " with parent " << parent.toByteArray();
62 if (parent.isValid()) {
63 Q_ASSERT(!parent.toByteArray().isEmpty());
64 Index("folder.index.parent", transaction).add(parent.toByteArray(), identifier);
65 } else {
66 Index("folder.index.parent", transaction).add("toplevel", identifier);
67 }
68}
69
70void TypeImplementation<Folder>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction)
71{
72 const auto parent = bufferAdaptor.getProperty("parent");
73 if (parent.isValid()) {
74 Index("folder.index.parent", transaction).remove(parent.toByteArray(), identifier);
75 } else {
76 Index("folder.index.parent", transaction).remove("toplevel", identifier);
77 }
78}
79
80QSharedPointer<ReadPropertyMapper<TypeImplementation<Folder>::Buffer> > TypeImplementation<Folder>::initializeReadPropertyMapper()
81{
82 auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create();
83 propertyMapper->addMapping<QString, Buffer>("parent", &Buffer::parent);
84 propertyMapper->addMapping<QString, Buffer>("name", &Buffer::name);
85 return propertyMapper;
86}
87
88QSharedPointer<WritePropertyMapper<TypeImplementation<Folder>::BufferBuilder> > TypeImplementation<Folder>::initializeWritePropertyMapper()
89{
90 auto propertyMapper = QSharedPointer<WritePropertyMapper<BufferBuilder> >::create();
91 propertyMapper->addMapping("parent", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> {
92 auto offset = variantToProperty<QString>(value, fbb);
93 return [offset](BufferBuilder &builder) { builder.add_parent(offset); };
94 });
95 propertyMapper->addMapping("name", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> {
96 auto offset = variantToProperty<QString>(value, fbb);
97 return [offset](BufferBuilder &builder) { builder.add_name(offset); };
98 });
99 return propertyMapper;
100}
diff --git a/common/domain/folder.fbs b/common/domain/folder.fbs
new file mode 100644
index 0000000..3476d58
--- /dev/null
+++ b/common/domain/folder.fbs
@@ -0,0 +1,9 @@
1namespace Akonadi2.ApplicationDomain.Buffer;
2
3table Folder {
4 name:string;
5 parent:string;
6}
7
8root_type Folder;
9file_identifier "AKFB";
diff --git a/common/domain/folder.h b/common/domain/folder.h
new file mode 100644
index 0000000..545836f
--- /dev/null
+++ b/common/domain/folder.h
@@ -0,0 +1,56 @@
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
25class ResultSet;
26class QByteArray;
27
28template<typename T>
29class ReadPropertyMapper;
30template<typename T>
31class WritePropertyMapper;
32
33namespace Akonadi2 {
34 class Query;
35
36namespace ApplicationDomain {
37 namespace Buffer {
38 struct Folder;
39 struct FolderBuilder;
40 }
41
42template<>
43class TypeImplementation<Akonadi2::ApplicationDomain::Folder> {
44public:
45 typedef Akonadi2::ApplicationDomain::Buffer::Folder Buffer;
46 typedef Akonadi2::ApplicationDomain::Buffer::FolderBuilder BufferBuilder;
47 static QSet<QByteArray> indexedProperties();
48 static ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, Akonadi2::Storage::Transaction &transaction);
49 static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction);
50 static void removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Akonadi2::Storage::Transaction &transaction);
51 static QSharedPointer<ReadPropertyMapper<Buffer> > initializeReadPropertyMapper();
52 static QSharedPointer<WritePropertyMapper<BufferBuilder> > initializeWritePropertyMapper();
53};
54
55}
56}