diff options
-rw-r--r-- | akonadish/akonadish_utils.cpp | 44 | ||||
-rw-r--r-- | akonadish/akonadish_utils.h | 4 |
2 files changed, 48 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 | ||
73 | QStringList 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 | |||
100 | QStringList 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 | |||
73 | QMap<QString, QString> keyValueMapFromArgs(const QStringList &args) | 117 | QMap<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 |
diff --git a/akonadish/akonadish_utils.h b/akonadish/akonadish_utils.h index 17b8ec7..5671157 100644 --- a/akonadish/akonadish_utils.h +++ b/akonadish/akonadish_utils.h | |||
@@ -26,6 +26,8 @@ | |||
26 | #include "common/query.h" | 26 | #include "common/query.h" |
27 | #include "common/clientapi.h" | 27 | #include "common/clientapi.h" |
28 | 28 | ||
29 | #include "state.h" | ||
30 | |||
29 | namespace AkonadishUtils | 31 | namespace AkonadishUtils |
30 | { | 32 | { |
31 | 33 | ||
@@ -34,6 +36,8 @@ class StoreBase; | |||
34 | bool isValidStoreType(const QString &type); | 36 | bool isValidStoreType(const QString &type); |
35 | StoreBase &getStore(const QString &type); | 37 | StoreBase &getStore(const QString &type); |
36 | QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Akonadi2::Query query); | 38 | QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Akonadi2::Query query); |
39 | QStringList resourceIds(); | ||
40 | QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state); | ||
37 | QMap<QString, QString> keyValueMapFromArgs(const QStringList &args); | 41 | QMap<QString, QString> keyValueMapFromArgs(const QStringList &args); |
38 | 42 | ||
39 | /** | 43 | /** |