diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-30 18:49:04 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-30 18:49:04 +0100 |
commit | 412563b7ff18684f9786f4e40b1a4d538f2d5233 (patch) | |
tree | 3190a317306cfb71b0d5d9bc4c0f06b260a92ce6 /common/domain/folder.cpp | |
parent | 790991aa1007d3271d80bc7e77f5b4f86c9bcef0 (diff) | |
parent | 6ad307dd846d07f1b55a1679a8d2eb47525af57d (diff) | |
download | sink-412563b7ff18684f9786f4e40b1a4d538f2d5233.tar.gz sink-412563b7ff18684f9786f4e40b1a4d538f2d5233.zip |
Merge branch 'feature/modelresult' into develop
Diffstat (limited to 'common/domain/folder.cpp')
-rw-r--r-- | common/domain/folder.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
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 | |||
35 | using namespace Akonadi2::ApplicationDomain; | ||
36 | |||
37 | ResultSet 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 | |||
58 | void 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 | |||
70 | void 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 | |||
80 | QSharedPointer<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 | |||
88 | QSharedPointer<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 | } | ||