summaryrefslogtreecommitdiffstats
path: root/akonadish/akonadish_utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'akonadish/akonadish_utils.cpp')
-rw-r--r--akonadish/akonadish_utils.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/akonadish/akonadish_utils.cpp b/akonadish/akonadish_utils.cpp
index ffbdcb3..90847f6 100644
--- a/akonadish/akonadish_utils.cpp
+++ b/akonadish/akonadish_utils.cpp
@@ -70,6 +70,50 @@ QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Akonadi2::Quer
70 return model; 70 return model;
71} 71}
72 72
73QStringList resourceIds(State &state)
74{
75 QStringList resources;
76 Akonadi2::Query query;
77 query.syncOnDemand = false;
78 query.processAll = false;
79 query.liveQuery = false;
80 auto model = AkonadishUtils::loadModel("resource", query);
81
82 QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, &resources] (const QModelIndex &index, int start, int end) mutable {
83 for (int i = start; i <= end; i++) {
84 auto object = model->data(model->index(i, 0, index), Akonadi2::Store::DomainObjectBaseRole).value<Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr>();
85 resources << object->identifier();
86 }
87 });
88
89 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) {
90 if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) {
91 state.commandFinished();
92 }
93 });
94
95 state.commandStarted();
96
97 return resources;
98}
99
100QStringList resourceCompleter(const QStringList &commands, const QString &fragment, State &state)
101{
102 QStringList resources = resourceIds(state);
103 if (fragment.isEmpty()) {
104 return resources;
105 }
106
107 QStringList filtered;
108 for (auto resource: resources) {
109 if (resource.startsWith(fragment)) {
110 filtered << resource;
111 }
112 }
113
114 return filtered;
115}
116
73QMap<QString, QString> keyValueMapFromArgs(const QStringList &args) 117QMap<QString, QString> keyValueMapFromArgs(const QStringList &args)
74{ 118{
75 //TODO: this is not the most clever of algorithms. preserved during the port of commands 119 //TODO: this is not the most clever of algorithms. preserved during the port of commands