diff options
Diffstat (limited to 'akonadish/akonadish_utils.h')
-rw-r--r-- | akonadish/akonadish_utils.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/akonadish/akonadish_utils.h b/akonadish/akonadish_utils.h new file mode 100644 index 0000000..17b8ec7 --- /dev/null +++ b/akonadish/akonadish_utils.h | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 Aaron Seigo <aseigo@kolabsystems.com> | ||
3 | * Copyright (C) 2015 Christian Mollekopf <mollekopf@kolabsystems.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the | ||
17 | * Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | |||
21 | #pragma once | ||
22 | |||
23 | #include <QAbstractItemModel> | ||
24 | #include <QSharedPointer> | ||
25 | |||
26 | #include "common/query.h" | ||
27 | #include "common/clientapi.h" | ||
28 | |||
29 | namespace AkonadishUtils | ||
30 | { | ||
31 | |||
32 | class StoreBase; | ||
33 | |||
34 | bool isValidStoreType(const QString &type); | ||
35 | StoreBase &getStore(const QString &type); | ||
36 | QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Akonadi2::Query query); | ||
37 | QMap<QString, QString> keyValueMapFromArgs(const QStringList &args); | ||
38 | |||
39 | /** | ||
40 | * A small abstraction layer to use the akonadi store with the type available as string. | ||
41 | */ | ||
42 | class StoreBase { | ||
43 | public: | ||
44 | virtual Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr getObject() = 0; | ||
45 | virtual Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) = 0; | ||
46 | virtual KAsync::Job<void> create(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) = 0; | ||
47 | virtual KAsync::Job<void> modify(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) = 0; | ||
48 | virtual KAsync::Job<void> remove(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) = 0; | ||
49 | virtual QSharedPointer<QAbstractItemModel> loadModel(const Akonadi2::Query &query) = 0; | ||
50 | }; | ||
51 | |||
52 | template <typename T> | ||
53 | class Store : public StoreBase { | ||
54 | public: | ||
55 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr getObject() Q_DECL_OVERRIDE { | ||
56 | return T::Ptr::create(); | ||
57 | } | ||
58 | |||
59 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) Q_DECL_OVERRIDE { | ||
60 | return T::Ptr::create(resourceInstanceIdentifier, identifier, 0, QSharedPointer<Akonadi2::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
61 | } | ||
62 | |||
63 | KAsync::Job<void> create(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { | ||
64 | return Akonadi2::Store::create<T>(*static_cast<const T*>(&type)); | ||
65 | } | ||
66 | |||
67 | KAsync::Job<void> modify(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { | ||
68 | return Akonadi2::Store::modify<T>(*static_cast<const T*>(&type)); | ||
69 | } | ||
70 | |||
71 | KAsync::Job<void> remove(const Akonadi2::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { | ||
72 | return Akonadi2::Store::remove<T>(*static_cast<const T*>(&type)); | ||
73 | } | ||
74 | |||
75 | QSharedPointer<QAbstractItemModel> loadModel(const Akonadi2::Query &query) Q_DECL_OVERRIDE { | ||
76 | return Akonadi2::Store::loadModel<T>(query); | ||
77 | } | ||
78 | }; | ||
79 | |||
80 | |||
81 | } | ||
82 | |||