summaryrefslogtreecommitdiffstats
path: root/sinksh/sinksh_utils.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-20 19:07:07 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-20 19:07:07 +0100
commitbdb01c2c068df326f5a8328ed1492ab1bea388c5 (patch)
tree25c2ee1b29bc481b6914c244ed9ca194b1415d16 /sinksh/sinksh_utils.h
parent17e7ee40c9185c0505883853345fd6024c675b1a (diff)
downloadsink-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.h88
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
31namespace SinkshUtils
32{
33
34class StoreBase;
35
36bool isValidStoreType(const QString &type);
37StoreBase &getStore(const QString &type);
38QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Sink::Query query);
39QStringList resourceIds();
40QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state);
41QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state);
42QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state);
43QMap<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 */
48class StoreBase {
49public:
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
58template <typename T>
59class Store : public StoreBase {
60public:
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