summaryrefslogtreecommitdiffstats
path: root/akonadish/akonadish_utils.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-26 19:19:11 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-26 19:19:11 +0100
commit8ef8b8dee60aa0a81fbb2cbba30c00d3b15bb771 (patch)
tree06be3618505d45e6e2886fb614c96689a5555364 /akonadish/akonadish_utils.cpp
parentfc7052f0970465d41dfd67c7e5db080498fd060f (diff)
parent67a19008d078a067ceb3424c00553c33b918970e (diff)
downloadsink-8ef8b8dee60aa0a81fbb2cbba30c00d3b15bb771.tar.gz
sink-8ef8b8dee60aa0a81fbb2cbba30c00d3b15bb771.zip
Merge branch 'feature/new_cli' into develop
Diffstat (limited to 'akonadish/akonadish_utils.cpp')
-rw-r--r--akonadish/akonadish_utils.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/akonadish/akonadish_utils.cpp b/akonadish/akonadish_utils.cpp
new file mode 100644
index 0000000..ffbdcb3
--- /dev/null
+++ b/akonadish/akonadish_utils.cpp
@@ -0,0 +1,86 @@
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#include "akonadish_utils.h"
22
23#include "common/clientapi.h"
24
25namespace AkonadishUtils
26{
27
28bool isValidStoreType(const QString &type)
29{
30 static const QSet<QString> types = QSet<QString>() << "folder" << "mail" << "event" << "resource";
31 return types.contains(type);
32}
33
34StoreBase &getStore(const QString &type)
35{
36 if (type == "folder") {
37 static Store<Akonadi2::ApplicationDomain::Folder> store;
38 return store;
39 } else if (type == "mail") {
40 static Store<Akonadi2::ApplicationDomain::Mail> store;
41 return store;
42 } else if (type == "event") {
43 static Store<Akonadi2::ApplicationDomain::Event> store;
44 return store;
45 } else if (type == "resource") {
46 static Store<Akonadi2::ApplicationDomain::AkonadiResource> store;
47 return store;
48 }
49
50 //TODO: reinstate the warning+assert
51 //Q_ASSERT(false);
52 //qWarning() << "Trying to get a store that doesn't exist, falling back to event";
53 static Store<Akonadi2::ApplicationDomain::Event> store;
54 return store;
55}
56
57QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Akonadi2::Query query)
58{
59 if (type == "folder") {
60 query.requestedProperties << "name" << "parent";
61 } else if (type == "mail") {
62 query.requestedProperties << "subject" << "folder" << "date";
63 } else if (type == "event") {
64 query.requestedProperties << "summary";
65 } else if (type == "resource") {
66 query.requestedProperties << "type";
67 }
68 auto model = getStore(type).loadModel(query);
69 Q_ASSERT(model);
70 return model;
71}
72
73QMap<QString, QString> keyValueMapFromArgs(const QStringList &args)
74{
75 //TODO: this is not the most clever of algorithms. preserved during the port of commands
76 // from akonadi2_client ... we can probably do better, however ;)
77 QMap<QString, QString> map;
78 for (int i = 0; i + 2 <= args.size(); i += 2) {
79 map.insert(args.at(i), args.at(i + 1));
80 }
81
82 return map;
83}
84
85}
86