summaryrefslogtreecommitdiffstats
path: root/akonadish/akonadish_utils.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-28 22:51:43 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-28 22:51:43 +0100
commit1998b8d35478205118cea5cc215c682b235434f1 (patch)
tree7a0f04f8b52843d9cbdb622d476a90604c48ff7a /akonadish/akonadish_utils.cpp
parentac0e1de3a3895b0e62231364499a2c3327fd74f0 (diff)
parentcc5363fe4b0cd4ea95ac98d9d37f2028fe226145 (diff)
downloadsink-1998b8d35478205118cea5cc215c682b235434f1.tar.gz
sink-1998b8d35478205118cea5cc215c682b235434f1.zip
Merge branch 'develop' of git://anongit.kde.org/akonadi-next into develop
Diffstat (limited to 'akonadish/akonadish_utils.cpp')
-rw-r--r--akonadish/akonadish_utils.cpp68
1 files changed, 66 insertions, 2 deletions
diff --git a/akonadish/akonadish_utils.cpp b/akonadish/akonadish_utils.cpp
index ffbdcb3..070d788 100644
--- a/akonadish/akonadish_utils.cpp
+++ b/akonadish/akonadish_utils.cpp
@@ -25,10 +25,11 @@
25namespace AkonadishUtils 25namespace AkonadishUtils
26{ 26{
27 27
28static QStringList s_types = QStringList() << "resource" << "folder" << "mail" << "event";
29
28bool isValidStoreType(const QString &type) 30bool isValidStoreType(const QString &type)
29{ 31{
30 static const QSet<QString> types = QSet<QString>() << "folder" << "mail" << "event" << "resource"; 32 return s_types.contains(type);
31 return types.contains(type);
32} 33}
33 34
34StoreBase &getStore(const QString &type) 35StoreBase &getStore(const QString &type)
@@ -70,6 +71,69 @@ QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Akonadi2::Quer
70 return model; 71 return model;
71} 72}
72 73
74QStringList resourceIds(State &state)
75{
76 QStringList resources;
77 Akonadi2::Query query;
78 query.syncOnDemand = false;
79 query.processAll = false;
80 query.liveQuery = false;
81 auto model = AkonadishUtils::loadModel("resource", query);
82
83 QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, &resources] (const QModelIndex &index, int start, int end) mutable {
84 for (int i = start; i <= end; i++) {
85 auto object = model->data(model->index(i, 0, index), Akonadi2::Store::DomainObjectBaseRole).value<Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr>();
86 resources << object->identifier();
87 }
88 });
89
90 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) {
91 if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) {
92 state.commandFinished();
93 }
94 });
95
96 state.commandStarted();
97
98 return resources;
99}
100
101QStringList filtered(const QStringList &list, const QString &fragment)
102{
103 if (fragment.isEmpty()) {
104 return list;
105 }
106
107 QStringList filtered;
108 for (auto item: list) {
109 if (item.startsWith(fragment)) {
110 filtered << item;
111 }
112 }
113
114 return filtered;
115}
116
117QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state)
118{
119 return filtered(resourceIds(state), fragment);
120}
121
122QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state)
123{
124 static QStringList types = QStringList() << "resource" << "folder" << "mail" << "event";
125 if (commands.count() == 1) {
126 return filtered(s_types, fragment);
127 }
128
129 return filtered(resourceIds(state), fragment);
130}
131
132QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state)
133{
134 return filtered(s_types, fragment);
135}
136
73QMap<QString, QString> keyValueMapFromArgs(const QStringList &args) 137QMap<QString, QString> keyValueMapFromArgs(const QStringList &args)
74{ 138{
75 //TODO: this is not the most clever of algorithms. preserved during the port of commands 139 //TODO: this is not the most clever of algorithms. preserved during the port of commands