diff options
Diffstat (limited to 'tests/hawd/modules/list.cpp')
-rw-r--r-- | tests/hawd/modules/list.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/hawd/modules/list.cpp b/tests/hawd/modules/list.cpp new file mode 100644 index 0000000..3310217 --- /dev/null +++ b/tests/hawd/modules/list.cpp | |||
@@ -0,0 +1,79 @@ | |||
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 | #include "list.h" | ||
21 | |||
22 | #include "../datasetdefinition.h" | ||
23 | |||
24 | #include <QDebug> | ||
25 | #include <QDir> | ||
26 | #include <QObject> | ||
27 | |||
28 | #include <iostream> | ||
29 | |||
30 | namespace HAWD | ||
31 | { | ||
32 | |||
33 | List::List() | ||
34 | : Module() | ||
35 | { | ||
36 | Syntax top("list", &List::list); | ||
37 | //top.children << Syntax("create", &List::create); | ||
38 | setSyntax(top); | ||
39 | } | ||
40 | |||
41 | bool List::list(const QStringList &commands, State &state) | ||
42 | { | ||
43 | QDir project(state.projectPath()); | ||
44 | |||
45 | if (commands.isEmpty()) { | ||
46 | project.setFilter(QDir::Files | QDir::Readable | QDir::NoDotAndDotDot | QDir::NoSymLinks); | ||
47 | const QStringList entryList = project.entryList(); | ||
48 | |||
49 | if (entryList.isEmpty()) { | ||
50 | std::cout << QObject::tr("No data sets in this project").toStdString() << std::endl; | ||
51 | } else { | ||
52 | std::cout << QObject::tr("Data sets in this project:").toStdString() << std::endl; | ||
53 | for (const QString &file: project.entryList()) { | ||
54 | std::cout << '\t' << file.toStdString() << std::endl; | ||
55 | } | ||
56 | } | ||
57 | } else { | ||
58 | for (const QString &file: commands) { | ||
59 | DatasetDefinition dataset(project.absoluteFilePath(file)); | ||
60 | if (dataset.isValid()) { | ||
61 | DatasetDefinition dataset(project.absoluteFilePath(file)); | ||
62 | std::cout << '\t' << QObject::tr("Dataset: %1").arg(dataset.name()).toStdString() << std::endl; | ||
63 | QHashIterator<QString, DataDefinition> it(dataset.columns()); | ||
64 | while (it.hasNext()) { | ||
65 | it.next(); | ||
66 | std::cout << "\t\t" << it.value().typeString().toStdString() << ' ' << it.key().toStdString() << std::endl; | ||
67 | } | ||
68 | |||
69 | } else { | ||
70 | std::cout << QObject::tr("Invalid or non-existent dataset definition at %1").arg(project.absoluteFilePath(file)).toStdString() << std::endl; | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | return true; | ||
76 | } | ||
77 | |||
78 | } // namespace HAWD | ||
79 | |||