diff options
Diffstat (limited to 'akonadi2_cli/module.h')
-rw-r--r-- | akonadi2_cli/module.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/akonadi2_cli/module.h b/akonadi2_cli/module.h new file mode 100644 index 0000000..4f426b8 --- /dev/null +++ b/akonadi2_cli/module.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | #include "state.h" | ||
23 | |||
24 | #include <QStringList> | ||
25 | #include <QVector> | ||
26 | |||
27 | class Module | ||
28 | { | ||
29 | public: | ||
30 | struct Syntax | ||
31 | { | ||
32 | Syntax(); | ||
33 | Syntax(const QString &keyword, std::function<bool(const QStringList &, State &)> lambda = std::function<bool(const QStringList &, State &)>(), const QString &helpText = QString(), bool eventDriven = false); | ||
34 | QString keyword; | ||
35 | std::function<bool(const QStringList &, State &)> lambda; | ||
36 | QList<Syntax> children; | ||
37 | QString help; | ||
38 | bool eventDriven; | ||
39 | }; | ||
40 | |||
41 | typedef std::pair<const Syntax *, QStringList> Command; | ||
42 | |||
43 | static void addModule(const Module &module); | ||
44 | static QList<Module> modules(); | ||
45 | static Command match(const QStringList &commands); | ||
46 | static bool run(const QStringList &commands); | ||
47 | static void loadModules(); | ||
48 | static QVector<Syntax>nearestSyntax(const QStringList &words, const QString &fragment); | ||
49 | |||
50 | Module(); | ||
51 | Module::Syntax syntax() const; | ||
52 | void setSyntax(const Syntax &syntax); | ||
53 | |||
54 | private: | ||
55 | Command matches(const QStringList &commands) const; | ||
56 | |||
57 | Syntax m_syntax; | ||
58 | static QList<Module> s_modules; | ||
59 | static State s_state; | ||
60 | }; | ||
61 | |||