diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-20 19:07:07 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-20 19:07:07 +0100 |
commit | bdb01c2c068df326f5a8328ed1492ab1bea388c5 (patch) | |
tree | 25c2ee1b29bc481b6914c244ed9ca194b1415d16 /sinksh/sinksh_utils.h | |
parent | 17e7ee40c9185c0505883853345fd6024c675b1a (diff) | |
download | sink-bdb01c2c068df326f5a8328ed1492ab1bea388c5.tar.gz sink-bdb01c2c068df326f5a8328ed1492ab1bea388c5.zip |
Renamed Akonadi2 to Sink
(except for documentation).
Diffstat (limited to 'sinksh/sinksh_utils.h')
-rw-r--r-- | sinksh/sinksh_utils.h | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/sinksh/sinksh_utils.h b/sinksh/sinksh_utils.h new file mode 100644 index 0000000..457f644 --- /dev/null +++ b/sinksh/sinksh_utils.h | |||
@@ -0,0 +1,88 @@ | |||
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 | #include "state.h" | ||
30 | |||
31 | namespace SinkshUtils | ||
32 | { | ||
33 | |||
34 | class StoreBase; | ||
35 | |||
36 | bool isValidStoreType(const QString &type); | ||
37 | StoreBase &getStore(const QString &type); | ||
38 | QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Sink::Query query); | ||
39 | QStringList resourceIds(); | ||
40 | QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state); | ||
41 | QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state); | ||
42 | QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state); | ||
43 | QMap<QString, QString> keyValueMapFromArgs(const QStringList &args); | ||
44 | |||
45 | /** | ||
46 | * A small abstraction layer to use the sink store with the type available as string. | ||
47 | */ | ||
48 | class StoreBase { | ||
49 | public: | ||
50 | virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() = 0; | ||
51 | virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) = 0; | ||
52 | virtual KAsync::Job<void> create(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; | ||
53 | virtual KAsync::Job<void> modify(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; | ||
54 | virtual KAsync::Job<void> remove(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; | ||
55 | virtual QSharedPointer<QAbstractItemModel> loadModel(const Sink::Query &query) = 0; | ||
56 | }; | ||
57 | |||
58 | template <typename T> | ||
59 | class Store : public StoreBase { | ||
60 | public: | ||
61 | Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() Q_DECL_OVERRIDE { | ||
62 | return T::Ptr::create(); | ||
63 | } | ||
64 | |||
65 | Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) Q_DECL_OVERRIDE { | ||
66 | return T::Ptr::create(resourceInstanceIdentifier, identifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
67 | } | ||
68 | |||
69 | KAsync::Job<void> create(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { | ||
70 | return Sink::Store::create<T>(*static_cast<const T*>(&type)); | ||
71 | } | ||
72 | |||
73 | KAsync::Job<void> modify(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { | ||
74 | return Sink::Store::modify<T>(*static_cast<const T*>(&type)); | ||
75 | } | ||
76 | |||
77 | KAsync::Job<void> remove(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { | ||
78 | return Sink::Store::remove<T>(*static_cast<const T*>(&type)); | ||
79 | } | ||
80 | |||
81 | QSharedPointer<QAbstractItemModel> loadModel(const Sink::Query &query) Q_DECL_OVERRIDE { | ||
82 | return Sink::Store::loadModel<T>(query); | ||
83 | } | ||
84 | }; | ||
85 | |||
86 | |||
87 | } | ||
88 | |||