diff options
Diffstat (limited to 'sinksh/syntax_modules')
-rw-r--r-- | sinksh/syntax_modules/sink_clear.cpp | 2 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_remove.cpp | 2 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_stat.cpp | 29 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_sync.cpp | 2 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_trace.cpp | 87 |
5 files changed, 95 insertions, 27 deletions
diff --git a/sinksh/syntax_modules/sink_clear.cpp b/sinksh/syntax_modules/sink_clear.cpp index 72d9a14..1537ecd 100644 --- a/sinksh/syntax_modules/sink_clear.cpp +++ b/sinksh/syntax_modules/sink_clear.cpp | |||
@@ -50,7 +50,7 @@ bool clear(const QStringList &args, State &state) | |||
50 | 50 | ||
51 | Syntax::List syntax() | 51 | Syntax::List syntax() |
52 | { | 52 | { |
53 | Syntax clear("clear", QObject::tr("Clears the local cache of one or more resources (be careful!)"), &SinkClear::clear); | 53 | Syntax clear("clear", QObject::tr("Clears the local cache of one or more resources (be careful!)"), &SinkClear::clear, Syntax::NotInteractive); |
54 | clear.completer = &SinkshUtils::resourceCompleter; | 54 | clear.completer = &SinkshUtils::resourceCompleter; |
55 | 55 | ||
56 | return Syntax::List() << clear; | 56 | return Syntax::List() << clear; |
diff --git a/sinksh/syntax_modules/sink_remove.cpp b/sinksh/syntax_modules/sink_remove.cpp index b374824..d474518 100644 --- a/sinksh/syntax_modules/sink_remove.cpp +++ b/sinksh/syntax_modules/sink_remove.cpp | |||
@@ -98,7 +98,7 @@ bool resource(const QStringList &args, State &state) | |||
98 | Syntax::List syntax() | 98 | Syntax::List syntax() |
99 | { | 99 | { |
100 | Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); | 100 | Syntax remove("remove", QObject::tr("Remove items in a resource"), &SinkRemove::remove); |
101 | Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource);//, Syntax::EventDriven); | 101 | Syntax resource("resource", QObject::tr("Removes a resource"), &SinkRemove::resource, Syntax::NotInteractive); |
102 | resource.completer = &SinkshUtils::resourceCompleter; | 102 | resource.completer = &SinkshUtils::resourceCompleter; |
103 | remove.children << resource; | 103 | remove.children << resource; |
104 | 104 | ||
diff --git a/sinksh/syntax_modules/sink_stat.cpp b/sinksh/syntax_modules/sink_stat.cpp index 06586d9..9f0fe44 100644 --- a/sinksh/syntax_modules/sink_stat.cpp +++ b/sinksh/syntax_modules/sink_stat.cpp | |||
@@ -70,30 +70,11 @@ bool statAllResources(State &state) | |||
70 | { | 70 | { |
71 | Sink::Query query; | 71 | Sink::Query query; |
72 | query.liveQuery = false; | 72 | query.liveQuery = false; |
73 | auto model = SinkshUtils::loadModel("resource", query); | 73 | QStringList resources; |
74 | 74 | for (const auto &r : SinkshUtils::getStore("resource").read(query)) { | |
75 | //SUUUPER ugly, but can't think of a better way with 2 glasses of wine in me on Christmas day | 75 | resources << r.identifier(); |
76 | static QStringList resources; | ||
77 | resources.clear(); | ||
78 | |||
79 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) mutable { | ||
80 | for (int i = start; i <= end; i++) { | ||
81 | auto object = model->data(model->index(i, 0, index), Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>(); | ||
82 | resources << object->identifier(); | ||
83 | } | ||
84 | }); | ||
85 | |||
86 | QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { | ||
87 | if (roles.contains(Sink::Store::ChildrenFetchedRole)) { | ||
88 | statResources(resources, state); | ||
89 | state.commandFinished(); | ||
90 | } | ||
91 | }); | ||
92 | |||
93 | if (!model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()) { | ||
94 | return true; | ||
95 | } | 76 | } |
96 | 77 | statResources(resources, state); | |
97 | return false; | 78 | return false; |
98 | } | 79 | } |
99 | 80 | ||
@@ -109,7 +90,7 @@ bool stat(const QStringList &args, State &state) | |||
109 | 90 | ||
110 | Syntax::List syntax() | 91 | Syntax::List syntax() |
111 | { | 92 | { |
112 | Syntax state("stat", QObject::tr("Shows database usage for the resources requested"), &SinkStat::stat, Syntax::EventDriven); | 93 | Syntax state("stat", QObject::tr("Shows database usage for the resources requested"), &SinkStat::stat, Syntax::NotInteractive); |
113 | state.completer = &SinkshUtils::resourceCompleter; | 94 | state.completer = &SinkshUtils::resourceCompleter; |
114 | 95 | ||
115 | return Syntax::List() << state; | 96 | return Syntax::List() << state; |
diff --git a/sinksh/syntax_modules/sink_sync.cpp b/sinksh/syntax_modules/sink_sync.cpp index 3006202..208b869 100644 --- a/sinksh/syntax_modules/sink_sync.cpp +++ b/sinksh/syntax_modules/sink_sync.cpp | |||
@@ -56,7 +56,7 @@ bool sync(const QStringList &args, State &state) | |||
56 | 56 | ||
57 | Syntax::List syntax() | 57 | Syntax::List syntax() |
58 | { | 58 | { |
59 | Syntax sync("sync", QObject::tr("Syncronizes all resources that are listed; and empty list triggers a syncronizaton on all resources"), &SinkSync::sync, Syntax::EventDriven ); | 59 | Syntax sync("sync", QObject::tr("Syncronizes all resources that are listed; and empty list triggers a syncronizaton on all resources"), &SinkSync::sync, Syntax::EventDriven); |
60 | sync.completer = &SinkshUtils::resourceCompleter; | 60 | sync.completer = &SinkshUtils::resourceCompleter; |
61 | 61 | ||
62 | return Syntax::List() << sync; | 62 | return Syntax::List() << sync; |
diff --git a/sinksh/syntax_modules/sink_trace.cpp b/sinksh/syntax_modules/sink_trace.cpp new file mode 100644 index 0000000..8bd52a0 --- /dev/null +++ b/sinksh/syntax_modules/sink_trace.cpp | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
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 <QDebug> | ||
21 | #include <QObject> // tr() | ||
22 | #include <QTimer> | ||
23 | |||
24 | #include "common/resource.h" | ||
25 | #include "common/storage.h" | ||
26 | #include "common/resourceconfig.h" | ||
27 | #include "common/log.h" | ||
28 | #include "common/storage.h" | ||
29 | #include "common/definitions.h" | ||
30 | |||
31 | #include "sinksh_utils.h" | ||
32 | #include "state.h" | ||
33 | #include "syntaxtree.h" | ||
34 | #include "iostream" | ||
35 | |||
36 | namespace SinkTrace | ||
37 | { | ||
38 | |||
39 | bool traceOff(const QStringList &args, State &state) | ||
40 | { | ||
41 | Sink::Log::setDebugOutputLevel(Sink::Log::Log); | ||
42 | std::cout << "Turned trace off." << std::endl; | ||
43 | return true; | ||
44 | } | ||
45 | |||
46 | bool traceOn(const QStringList &args, State &state) | ||
47 | { | ||
48 | Sink::Log::setDebugOutputLevel(Sink::Log::Trace); | ||
49 | if (args.isEmpty() || (args.size() == 1 && args.first() == "*")) { | ||
50 | Sink::Log::setDebugOutputFilter(Sink::Log::Area, QByteArrayList()); | ||
51 | std::cout << "Set trace filter to: *" << std::endl; | ||
52 | } else { | ||
53 | QByteArrayList filter; | ||
54 | for (const auto &arg : args) { | ||
55 | filter << arg.toLatin1(); | ||
56 | } | ||
57 | Sink::Log::setDebugOutputFilter(Sink::Log::Area, filter); | ||
58 | std::cout << "Set trace filter to: " << filter.join(", ").toStdString() << std::endl; | ||
59 | } | ||
60 | return true; | ||
61 | } | ||
62 | |||
63 | bool trace(const QStringList &args, State &state) | ||
64 | { | ||
65 | return traceOn(args, state); | ||
66 | } | ||
67 | |||
68 | |||
69 | Syntax::List syntax() | ||
70 | { | ||
71 | Syntax trace("trace", QObject::tr("Control trace debug output."), &SinkTrace::trace, Syntax::NotInteractive); | ||
72 | trace.completer = &SinkshUtils::debugareaCompleter; | ||
73 | |||
74 | Syntax traceOff("off", QObject::tr("Turns off trace output."), &SinkTrace::traceOff, Syntax::NotInteractive); | ||
75 | traceOff.completer = &SinkshUtils::debugareaCompleter; | ||
76 | trace.children << traceOff; | ||
77 | |||
78 | Syntax traceOn("on", QObject::tr("Turns on trace output."), &SinkTrace::traceOn, Syntax::NotInteractive); | ||
79 | traceOn.completer = &SinkshUtils::debugareaCompleter; | ||
80 | trace.children << traceOn; | ||
81 | |||
82 | return Syntax::List() << trace; | ||
83 | } | ||
84 | |||
85 | REGISTER_SYNTAX(SinkTrace) | ||
86 | |||
87 | } | ||