diff options
Diffstat (limited to 'common/domain/event.cpp')
-rw-r--r-- | common/domain/event.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/common/domain/event.cpp b/common/domain/event.cpp new file mode 100644 index 0000000..86100b7 --- /dev/null +++ b/common/domain/event.cpp | |||
@@ -0,0 +1,53 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 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 "event.h" | ||
20 | |||
21 | #include <QVector> | ||
22 | #include <QByteArray> | ||
23 | |||
24 | #include "../resultset.h" | ||
25 | #include "../index.h" | ||
26 | #include "../storage.h" | ||
27 | #include "../log.h" | ||
28 | |||
29 | using namespace Akonadi2::ApplicationDomain; | ||
30 | |||
31 | ResultSet EventImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier) | ||
32 | { | ||
33 | QVector<QByteArray> keys; | ||
34 | if (query.propertyFilter.contains("uid")) { | ||
35 | Index uidIndex(Akonadi2::Store::storageLocation(), resourceInstanceIdentifier + "index.uid", Akonadi2::Storage::ReadOnly); | ||
36 | uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { | ||
37 | keys << value; | ||
38 | }, | ||
39 | [](const Index::Error &error) { | ||
40 | Warning() << "Error in index: " << error.message; | ||
41 | }); | ||
42 | } | ||
43 | return ResultSet(keys); | ||
44 | } | ||
45 | |||
46 | void EventImplementation::index(const Event &type) | ||
47 | { | ||
48 | Index uidIndex(Akonadi2::Store::storageLocation(), type.resourceInstanceIdentifier() + "index.uid", Akonadi2::Storage::ReadWrite); | ||
49 | const auto uid = type.getProperty("uid"); | ||
50 | if (uid.isValid()) { | ||
51 | uidIndex.add(uid.toByteArray(), type.identifier()); | ||
52 | } | ||
53 | } | ||