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/sinksh_utils.cpp | 16 +++++++++----- sinksh/sinksh_utils.h | 11 ++++++++++ sinksh/syntax_modules/sink_list.cpp | 44 +++++++++++-------------------------- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp index 151ea2f..091eb38 100644 --- a/sinksh/sinksh_utils.cpp +++ b/sinksh/sinksh_utils.cpp @@ -63,20 +63,26 @@ StoreBase &getStore(const QString &type) return store; } -QSharedPointer loadModel(const QString &type, Sink::Query query) +QList requestedProperties(const QString &type) { if (type == "folder") { - query.requestedProperties << "name" + return QList() << "name" << "parent"; } else if (type == "mail") { - query.requestedProperties << "subject" + return QList() << "subject" << "folder" << "date"; } else if (type == "event") { - query.requestedProperties << "summary"; + return QList() << "summary"; } else if (type == "resource") { - query.requestedProperties << "type"; + return QList() << "type"; } + return QList(); +} + +QSharedPointer loadModel(const QString &type, Sink::Query query) +{ + query.requestedProperties = requestedProperties(type); auto model = getStore(type).loadModel(query); Q_ASSERT(model); return model; diff --git a/sinksh/sinksh_utils.h b/sinksh/sinksh_utils.h index 5f470ff..b5b6f3c 100644 --- a/sinksh/sinksh_utils.h +++ b/sinksh/sinksh_utils.h @@ -35,6 +35,7 @@ class StoreBase; bool isValidStoreType(const QString &type); StoreBase &getStore(const QString &type); QSharedPointer loadModel(const QString &type, Sink::Query query); +QList requestedProperties(const QString &type); QStringList resourceIds(); QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state); QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state); @@ -54,6 +55,7 @@ public: virtual KAsync::Job modify(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; virtual KAsync::Job remove(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; virtual QSharedPointer loadModel(const Sink::Query &query) = 0; + virtual QList read(const Sink::Query &query) = 0; }; template @@ -89,5 +91,14 @@ public: { return Sink::Store::loadModel(query); } + + QList read(const Sink::Query &query) Q_DECL_OVERRIDE + { + QList list; + for (const auto &o : Sink::Store::read(query)) { + list << o; + } + return list; + } }; } 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