summaryrefslogtreecommitdiffstats
path: root/sinksh
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-06-26 11:27:34 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-06-26 11:27:34 +0200
commit3db36de42fc986341b0fac8c4cbfe869f0bac356 (patch)
tree20530c2bff144e835f0e40fc6bacb64d81b10c22 /sinksh
parentd993e357e03549c731d724f199ef55e7bcf7e1b2 (diff)
downloadsink-3db36de42fc986341b0fac8c4cbfe869f0bac356.tar.gz
sink-3db36de42fc986341b0fac8c4cbfe869f0bac356.zip
Ported sinksh list to synchronous API (which also fixed it)
Diffstat (limited to 'sinksh')
-rw-r--r--sinksh/sinksh_utils.cpp16
-rw-r--r--sinksh/sinksh_utils.h11
-rw-r--r--sinksh/syntax_modules/sink_list.cpp44
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)
63 return store; 63 return store;
64} 64}
65 65
66QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Sink::Query query) 66QList<QByteArray> requestedProperties(const QString &type)
67{ 67{
68 if (type == "folder") { 68 if (type == "folder") {
69 query.requestedProperties << "name" 69 return QList<QByteArray>() << "name"
70 << "parent"; 70 << "parent";
71 } else if (type == "mail") { 71 } else if (type == "mail") {
72 query.requestedProperties << "subject" 72 return QList<QByteArray>() << "subject"
73 << "folder" 73 << "folder"
74 << "date"; 74 << "date";
75 } else if (type == "event") { 75 } else if (type == "event") {
76 query.requestedProperties << "summary"; 76 return QList<QByteArray>() << "summary";
77 } else if (type == "resource") { 77 } else if (type == "resource") {
78 query.requestedProperties << "type"; 78 return QList<QByteArray>() << "type";
79 } 79 }
80 return QList<QByteArray>();
81}
82
83QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Sink::Query query)
84{
85 query.requestedProperties = requestedProperties(type);
80 auto model = getStore(type).loadModel(query); 86 auto model = getStore(type).loadModel(query);
81 Q_ASSERT(model); 87 Q_ASSERT(model);
82 return model; 88 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;
35bool isValidStoreType(const QString &type); 35bool isValidStoreType(const QString &type);
36StoreBase &getStore(const QString &type); 36StoreBase &getStore(const QString &type);
37QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Sink::Query query); 37QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Sink::Query query);
38QList<QByteArray> requestedProperties(const QString &type);
38QStringList resourceIds(); 39QStringList resourceIds();
39QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state); 40QStringList resourceCompleter(const QStringList &, const QString &fragment, State &state);
40QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state); 41QStringList resourceOrTypeCompleter(const QStringList &commands, const QString &fragment, State &state);
@@ -54,6 +55,7 @@ public:
54 virtual KAsync::Job<void> modify(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; 55 virtual KAsync::Job<void> modify(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0;
55 virtual KAsync::Job<void> remove(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; 56 virtual KAsync::Job<void> remove(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0;
56 virtual QSharedPointer<QAbstractItemModel> loadModel(const Sink::Query &query) = 0; 57 virtual QSharedPointer<QAbstractItemModel> loadModel(const Sink::Query &query) = 0;
58 virtual QList<Sink::ApplicationDomain::ApplicationDomainType> read(const Sink::Query &query) = 0;
57}; 59};
58 60
59template <typename T> 61template <typename T>
@@ -89,5 +91,14 @@ public:
89 { 91 {
90 return Sink::Store::loadModel<T>(query); 92 return Sink::Store::loadModel<T>(query);
91 } 93 }
94
95 QList<Sink::ApplicationDomain::ApplicationDomainType> read(const Sink::Query &query) Q_DECL_OVERRIDE
96 {
97 QList<Sink::ApplicationDomain::ApplicationDomainType> list;
98 for (const auto &o : Sink::Store::read<T>(query)) {
99 list << o;
100 }
101 return list;
102 }
92}; 103};
93} 104}
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 @@
31#include "common/log.h" 31#include "common/log.h"
32#include "common/storage.h" 32#include "common/storage.h"
33#include "common/definitions.h" 33#include "common/definitions.h"
34#include "common/store.h"
34 35
35#include "sinksh_utils.h" 36#include "sinksh_utils.h"
36#include "state.h" 37#include "state.h"
@@ -70,45 +71,26 @@ bool list(const QStringList &args, State &state)
70 71
71 query.liveQuery = false; 72 query.liveQuery = false;
72 73
73 QTime time; 74 query.requestedProperties = SinkshUtils::requestedProperties(type);
74 time.start();
75 auto model = SinkshUtils::loadModel(type, query);
76 if (state.debugLevel() > 0) {
77 state.printLine(QObject::tr("Folder type %1").arg(type));
78 state.printLine(QObject::tr("Loaded model in %1 ms").arg(time.elapsed()));
79 }
80 75
81 //qDebug() << "Listing";
82 QStringList line; 76 QStringList line;
83 line << QObject::tr("Resource") << QObject::tr("Identifier"); 77 line << QObject::tr("Resource") << QObject::tr("Identifier");
84 for (int i = 0; i < model->columnCount(QModelIndex()); i++) { 78 for (const auto &prop: query.requestedProperties) {
85 line << model->headerData(i, Qt::Horizontal).toString(); 79 line << prop;
86 } 80 }
87 state.stageTableLine(line); 81 state.stageTableLine(line);
88 82
89 QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, state](const QModelIndex &index, int start, int end) { 83 for (const auto &o : SinkshUtils::getStore(type).read(query)) {
90 for (int i = start; i <= end; i++) { 84 QStringList line;
91 auto object = model->data(model->index(i, 0, index), Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>(); 85 line << o.resourceInstanceIdentifier();
92 QStringList line; 86 line << o.identifier();
93 line << object->resourceInstanceIdentifier(); 87 for (const auto &prop: query.requestedProperties) {
94 line << object->identifier(); 88 line << o.getProperty(prop).toString();
95 for (int col = 0; col < model->columnCount(QModelIndex()); col++) {
96 line << model->data(model->index(i, col, index)).toString();
97 }
98 state.stageTableLine(line);
99 }
100 });
101
102 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) {
103 if (roles.contains(Sink::Store::ChildrenFetchedRole)) {
104 state.flushTable();
105 state.commandFinished();
106 } 89 }
107 }); 90 state.stageTableLine(line);
108
109 if (!model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()) {
110 return true;
111 } 91 }
92 state.flushTable();
93 state.commandFinished();
112 94
113 return false; 95 return false;
114} 96}