diff options
-rw-r--r-- | akonadish/akonadish_utils.cpp | 36 | ||||
-rw-r--r-- | akonadish/akonadish_utils.h | 2 | ||||
-rw-r--r-- | akonadish/syntax_modules/akonadi_count.cpp | 2 | ||||
-rw-r--r-- | akonadish/syntax_modules/akonadi_list.cpp | 7 | ||||
-rw-r--r-- | akonadish/syntax_modules/akonadi_modify.cpp | 2 |
5 files changed, 35 insertions, 14 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 |
diff --git a/akonadish/akonadish_utils.h b/akonadish/akonadish_utils.h index 5671157..5dd24f1 100644 --- a/akonadish/akonadish_utils.h +++ b/akonadish/akonadish_utils.h | |||
@@ -38,6 +38,8 @@ StoreBase &getStore(const QString &type); | |||
38 | QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Akonadi2::Query query); | 38 | QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Akonadi2::Query query); |
39 | QStringList resourceIds(); | 39 | QStringList resourceIds(); |
40 | QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state); | 40 | QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state); |
41 | QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state); | ||
42 | QStringList typeCompleter(const QStringList &commands, const QString &fragment, State &state); | ||
41 | QMap<QString, QString> keyValueMapFromArgs(const QStringList &args); | 43 | QMap<QString, QString> keyValueMapFromArgs(const QStringList &args); |
42 | 44 | ||
43 | /** | 45 | /** |
diff --git a/akonadish/syntax_modules/akonadi_count.cpp b/akonadish/syntax_modules/akonadi_count.cpp index fa3f1fb..5acdcdd 100644 --- a/akonadish/syntax_modules/akonadi_count.cpp +++ b/akonadish/syntax_modules/akonadi_count.cpp | |||
@@ -75,7 +75,7 @@ bool count(const QStringList &args, State &state) | |||
75 | Syntax::List syntax() | 75 | Syntax::List syntax() |
76 | { | 76 | { |
77 | Syntax count("count", QObject::tr("Returns the number of items of a given type in a resource. Usage: count <type> <resource>"), &AkonadiCount::count, Syntax::EventDriven); | 77 | Syntax count("count", QObject::tr("Returns the number of items of a given type in a resource. Usage: count <type> <resource>"), &AkonadiCount::count, Syntax::EventDriven); |
78 | count.completer = &AkonadishUtils::resourceCompleter; | 78 | count.completer = &AkonadishUtils::typeCompleter; |
79 | 79 | ||
80 | return Syntax::List() << count; | 80 | return Syntax::List() << count; |
81 | } | 81 | } |
diff --git a/akonadish/syntax_modules/akonadi_list.cpp b/akonadish/syntax_modules/akonadi_list.cpp index 18f15e7..82f13b5 100644 --- a/akonadish/syntax_modules/akonadi_list.cpp +++ b/akonadish/syntax_modules/akonadi_list.cpp | |||
@@ -106,10 +106,9 @@ bool list(const QStringList &args, State &state) | |||
106 | 106 | ||
107 | Syntax::List syntax() | 107 | Syntax::List syntax() |
108 | { | 108 | { |
109 | Syntax::List syntax; | 109 | Syntax list("list", QObject::tr("List all resources, or the contents of one or more resources"), &AkonadiList::list, Syntax::EventDriven); |
110 | syntax << Syntax("list", QObject::tr("List all resources, or the contents of one or more resources"), &AkonadiList::list, Syntax::EventDriven); | 110 | list.completer = &AkonadishUtils::resourceOrTypeCompleter; |
111 | 111 | return Syntax::List() << list; | |
112 | return syntax; | ||
113 | } | 112 | } |
114 | 113 | ||
115 | REGISTER_SYNTAX(AkonadiList) | 114 | REGISTER_SYNTAX(AkonadiList) |
diff --git a/akonadish/syntax_modules/akonadi_modify.cpp b/akonadish/syntax_modules/akonadi_modify.cpp index 8ab873a..76a7f5e 100644 --- a/akonadish/syntax_modules/akonadi_modify.cpp +++ b/akonadish/syntax_modules/akonadi_modify.cpp | |||
@@ -109,7 +109,7 @@ Syntax::List syntax() | |||
109 | { | 109 | { |
110 | Syntax modify("modify", QObject::tr("Modify items in a resource"), &AkonadiModify::modify); | 110 | Syntax modify("modify", QObject::tr("Modify items in a resource"), &AkonadiModify::modify); |
111 | Syntax resource("resource", QObject::tr("Modify a resource"), &AkonadiModify::resource);//, Syntax::EventDriven); | 111 | Syntax resource("resource", QObject::tr("Modify a resource"), &AkonadiModify::resource);//, Syntax::EventDriven); |
112 | resource.completer = &AkonadishUtils::resourceCompleter; | 112 | resource.completer = &AkonadishUtils::resourceOrTypeCompleter; |
113 | modify.children << resource; | 113 | modify.children << resource; |
114 | 114 | ||
115 | return Syntax::List() << modify; | 115 | return Syntax::List() << modify; |