From 3db36de42fc986341b0fac8c4cbfe869f0bac356 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 26 Jun 2016 11:27:34 +0200 Subject: Ported sinksh list to synchronous API (which also fixed it) --- sinksh/syntax_modules/sink_list.cpp | 44 +++++++++++-------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) (limited to 'sinksh/syntax_modules') diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index b85de97..b20f3d4 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp @@ -31,6 +31,7 @@ #include "common/log.h" #include "common/storage.h" #include "common/definitions.h" +#include "common/store.h" #include "sinksh_utils.h" #include "state.h" @@ -70,45 +71,26 @@ bool list(const QStringList &args, State &state) query.liveQuery = false; - QTime time; - time.start(); - auto model = SinkshUtils::loadModel(type, query); - if (state.debugLevel() > 0) { - state.printLine(QObject::tr("Folder type %1").arg(type)); - state.printLine(QObject::tr("Loaded model in %1 ms").arg(time.elapsed())); - } + query.requestedProperties = SinkshUtils::requestedProperties(type); - //qDebug() << "Listing"; QStringList line; line << QObject::tr("Resource") << QObject::tr("Identifier"); - for (int i = 0; i < model->columnCount(QModelIndex()); i++) { - line << model->headerData(i, Qt::Horizontal).toString(); + for (const auto &prop: query.requestedProperties) { + line << prop; } state.stageTableLine(line); - QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, state](const QModelIndex &index, int start, int end) { - for (int i = start; i <= end; i++) { - auto object = model->data(model->index(i, 0, index), Sink::Store::DomainObjectBaseRole).value(); - QStringList line; - line << object->resourceInstanceIdentifier(); - line << object->identifier(); - for (int col = 0; col < model->columnCount(QModelIndex()); col++) { - line << model->data(model->index(i, col, index)).toString(); - } - state.stageTableLine(line); - } - }); - - QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector &roles) { - if (roles.contains(Sink::Store::ChildrenFetchedRole)) { - state.flushTable(); - state.commandFinished(); + for (const auto &o : SinkshUtils::getStore(type).read(query)) { + QStringList line; + line << o.resourceInstanceIdentifier(); + line << o.identifier(); + for (const auto &prop: query.requestedProperties) { + line << o.getProperty(prop).toString(); } - }); - - if (!model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()) { - return true; + state.stageTableLine(line); } + state.flushTable(); + state.commandFinished(); return false; } -- cgit v1.2.3