diff options
Diffstat (limited to 'akonadish/akonadish_utils.cpp')
-rw-r--r-- | akonadish/akonadish_utils.cpp | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/akonadish/akonadish_utils.cpp b/akonadish/akonadish_utils.cpp index 90847f6..070d788 100644 --- a/akonadish/akonadish_utils.cpp +++ b/akonadish/akonadish_utils.cpp | |||
@@ -25,10 +25,11 @@ | |||
25 | namespace AkonadishUtils | 25 | namespace AkonadishUtils |
26 | { | 26 | { |
27 | 27 | ||
28 | static QStringList s_types = QStringList() << "resource" << "folder" << "mail" << "event"; | ||
29 | |||
28 | bool isValidStoreType(const QString &type) | 30 | bool 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 | ||
34 | StoreBase &getStore(const QString &type) | 35 | StoreBase &getStore(const QString &type) |
@@ -97,23 +98,42 @@ QStringList resourceIds(State &state) | |||
97 | return resources; | 98 | return resources; |
98 | } | 99 | } |
99 | 100 | ||
100 | QStringList resourceCompleter(const QStringList &commands, const QString &fragment, State &state) | 101 | QStringList filtered(const QStringList &list, const QString &fragment) |
101 | { | 102 | { |
102 | QStringList resources = resourceIds(state); | ||
103 | if (fragment.isEmpty()) { | 103 | if (fragment.isEmpty()) { |
104 | return resources; | 104 | return list; |
105 | } | 105 | } |
106 | 106 | ||
107 | QStringList filtered; | 107 | QStringList filtered; |
108 | for (auto resource: resources) { | 108 | for (auto item: list) { |
109 | if (resource.startsWith(fragment)) { | 109 | if (item.startsWith(fragment)) { |
110 | filtered << resource; | 110 | filtered << item; |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | return filtered; | 114 | return filtered; |
115 | } | 115 | } |
116 | 116 | ||
117 | QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state) | ||
118 | { | ||
119 | return filtered(resourceIds(state), fragment); | ||
120 | } | ||
121 | |||
122 | QStringList 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 | |||
132 | QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state) | ||
133 | { | ||
134 | return filtered(s_types, fragment); | ||
135 | } | ||
136 | |||
117 | QMap<QString, QString> keyValueMapFromArgs(const QStringList &args) | 137 | QMap<QString, QString> keyValueMapFromArgs(const QStringList &args) |
118 | { | 138 | { |
119 | //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 |