diff options
Diffstat (limited to 'akonadish/akonadish_utils.cpp')
-rw-r--r-- | akonadish/akonadish_utils.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/akonadish/akonadish_utils.cpp b/akonadish/akonadish_utils.cpp new file mode 100644 index 0000000..bfb72ca --- /dev/null +++ b/akonadish/akonadish_utils.cpp | |||
@@ -0,0 +1,74 @@ | |||
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 | |||
25 | namespace AkonadishUtils | ||
26 | { | ||
27 | |||
28 | bool isValidStoreType(const QString &type) | ||
29 | { | ||
30 | static const QSet<QString> types = QSet<QString>() << "folder" << "mail" << "event" << "resource"; | ||
31 | return types.contains(type); | ||
32 | } | ||
33 | |||
34 | StoreBase &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 | |||
57 | QSharedPointer<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 | |||
73 | } | ||
74 | |||