summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sinksh/CMakeLists.txt1
-rw-r--r--sinksh/syntax_modules/sink_show.cpp105
2 files changed, 0 insertions, 106 deletions
diff --git a/sinksh/CMakeLists.txt b/sinksh/CMakeLists.txt
index 359dbf0..2a81df0 100644
--- a/sinksh/CMakeLists.txt
+++ b/sinksh/CMakeLists.txt
@@ -14,7 +14,6 @@ set(sink_cli_SRCS
14 syntax_modules/sink_remove.cpp 14 syntax_modules/sink_remove.cpp
15 syntax_modules/sink_stat.cpp 15 syntax_modules/sink_stat.cpp
16 syntax_modules/sink_sync.cpp 16 syntax_modules/sink_sync.cpp
17 syntax_modules/sink_show.cpp
18 syntax_modules/sink_trace.cpp 17 syntax_modules/sink_trace.cpp
19 syntax_modules/sink_inspect.cpp 18 syntax_modules/sink_inspect.cpp
20 syntax_modules/sink_drop.cpp 19 syntax_modules/sink_drop.cpp
diff --git a/sinksh/syntax_modules/sink_show.cpp b/sinksh/syntax_modules/sink_show.cpp
deleted file mode 100644
index 7a4166f..0000000
--- a/sinksh/syntax_modules/sink_show.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
3 * Copyright (C) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <QDebug>
22#include <QObject> // tr()
23#include <QModelIndex>
24#include <QTime>
25
26#include "common/storage.h"
27
28#include "sinksh_utils.h"
29#include "state.h"
30#include "syntaxtree.h"
31
32namespace SinkShow
33{
34
35bool show(const QStringList &args, State &state)
36{
37 if (args.isEmpty()) {
38 state.printError(QObject::tr("Options: $type --resource $resource --id $id"));
39 return false;
40 }
41
42 auto options = SyntaxTree::parseOptions(args);
43
44 auto type = options.positionalArguments.isEmpty() ? QString{} : options.positionalArguments.first();
45 auto resource = options.options.value("resource");
46 auto id = options.options.value("id");
47
48 if (id.isEmpty() || resource.isEmpty() || !SinkshUtils::isValidStoreType(type)) {
49 state.printError(QObject::tr("Invalid command syntax. Supply type and resource at least."));
50 return false;
51 }
52
53 Sink::Query query;
54 query.resourceFilter(resource.first().toLatin1());
55 query.filter(id.first().toLatin1());
56
57 QTime time;
58 time.start();
59 auto model = SinkshUtils::loadModel(type, query);
60 if (state.debugLevel() > 0) {
61 state.printLine(QObject::tr("Folder type %1").arg(type));
62 state.printLine(QObject::tr("Loaded model in %1 ms").arg(time.elapsed()));
63 }
64
65 QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, state](const QModelIndex &index, int start, int end) {
66 for (int i = start; i <= end; i++) {
67 auto object = model->data(model->index(i, 0, index), Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>();
68 state.printLine("Resource: " + object->resourceInstanceIdentifier(), 1);
69 state.printLine("Identifier: " + object->identifier(), 1);
70 state.stageTableLine(QStringList()
71 << QObject::tr("Property:")
72 << QObject::tr("Value:"));
73
74 for (const auto &property : object->availableProperties()) {
75 state.stageTableLine(QStringList()
76 << property
77 << object->getProperty(property).toString());
78 }
79 state.flushTable();
80 }
81 });
82
83 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) {
84 if (roles.contains(Sink::Store::ChildrenFetchedRole)) {
85 state.commandFinished();
86 }
87 });
88
89 if (!model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()) {
90 return true;
91 }
92
93 return false;
94}
95
96Syntax::List syntax()
97{
98 Syntax show("show", QObject::tr("Show all properties of an entity."), &SinkShow::show, Syntax::EventDriven);
99 show.completer = &SinkshUtils::resourceOrTypeCompleter;
100 return Syntax::List() << show;
101}
102
103REGISTER_SYNTAX(SinkShow)
104
105}