From ce2fd2666f084eebe443598f6f3740a02913091e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 11 Jul 2016 08:25:30 +0200 Subject: Read resources synchronously --- sinksh/syntax_modules/sink_stat.cpp | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) (limited to 'sinksh/syntax_modules/sink_stat.cpp') 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) { Sink::Query query; query.liveQuery = false; - auto model = SinkshUtils::loadModel("resource", query); - - //SUUUPER ugly, but can't think of a better way with 2 glasses of wine in me on Christmas day - static QStringList resources; - resources.clear(); - - QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) mutable { - for (int i = start; i <= end; i++) { - auto object = model->data(model->index(i, 0, index), Sink::Store::DomainObjectBaseRole).value(); - resources << object->identifier(); - } - }); - - QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector &roles) { - if (roles.contains(Sink::Store::ChildrenFetchedRole)) { - statResources(resources, state); - state.commandFinished(); - } - }); - - if (!model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()) { - return true; + QStringList resources; + for (const auto &r : SinkshUtils::getStore("resource").read(query)) { + resources << r.identifier(); } - + statResources(resources, state); return false; } @@ -109,7 +90,7 @@ bool stat(const QStringList &args, State &state) Syntax::List syntax() { - Syntax state("stat", QObject::tr("Shows database usage for the resources requested"), &SinkStat::stat, Syntax::EventDriven); + Syntax state("stat", QObject::tr("Shows database usage for the resources requested"), &SinkStat::stat, Syntax::NotInteractive); state.completer = &SinkshUtils::resourceCompleter; return Syntax::List() << state; -- cgit v1.2.3