[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [sink/develop] sinksh: Ported sinksh list to synchronous API (which also fixed it)
From:       Christian Mollekopf <chrigi_1 () fastmail ! fm>
Date:       2016-06-30 19:49:32
Message-ID: E1bIhxs-0005c3-Ub () code ! kde ! org
[Download RAW message or body]

Git commit 3db36de42fc986341b0fac8c4cbfe869f0bac356 by Christian Mollekopf.
Committed on 26/06/2016 at 09:27.
Pushed by cmollekopf into branch 'develop'.

Ported sinksh list to synchronous API (which also fixed it)

M  +11   -5    sinksh/sinksh_utils.cpp
M  +11   -0    sinksh/sinksh_utils.h
M  +13   -31   sinksh/syntax_modules/sink_list.cpp

http://commits.kde.org/akonadi-next/3db36de42fc986341b0fac8c4cbfe869f0bac356

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<QAbstractItemModel> loadModel(const QString &type, Sink::Query query)
+QList<QByteArray> requestedProperties(const QString &type)
 {
     if (type == "folder") {
-        query.requestedProperties << "name"
+        return QList<QByteArray>() << "name"
                                   << "parent";
     } else if (type == "mail") {
-        query.requestedProperties << "subject"
+        return QList<QByteArray>() << "subject"
                                   << "folder"
                                   << "date";
     } else if (type == "event") {
-        query.requestedProperties << "summary";
+        return QList<QByteArray>() << "summary";
     } else if (type == "resource") {
-        query.requestedProperties << "type";
+        return QList<QByteArray>() << "type";
     }
+    return QList<QByteArray>();
+}
+
+QSharedPointer<QAbstractItemModel> 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<QAbstractItemModel> loadModel(const QString &type, Sink::Query \
query); +QList<QByteArray> 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<void> modify(const \
                Sink::ApplicationDomain::ApplicationDomainType &type) = 0;
     virtual KAsync::Job<void> remove(const \
                Sink::ApplicationDomain::ApplicationDomainType &type) = 0;
     virtual QSharedPointer<QAbstractItemModel> loadModel(const Sink::Query &query) = \
0; +    virtual QList<Sink::ApplicationDomain::ApplicationDomainType> read(const \
Sink::Query &query) = 0;  };
 
 template <typename T>
@@ -89,5 +91,14 @@ public:
     {
         return Sink::Store::loadModel<T>(query);
     }
+
+    QList<Sink::ApplicationDomain::ApplicationDomainType> read(const Sink::Query \
&query) Q_DECL_OVERRIDE +    {
+        QList<Sink::ApplicationDomain::ApplicationDomainType> list;
+        for (const auto &o : Sink::Store::read<T>(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<Sink::ApplicationDomain::ApplicationDomainType::Ptr>();
                
-            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<int> \
                &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;
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic