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

List:       kde-commits
Subject:    [akonadi-next/develop] akonadish: methods to get resourceIds and a compelter built on that
From:       Aaron Seigo <aseigo () kde ! org>
Date:       2015-12-28 19:31:31
Message-ID: E1aDdVz-0007Os-6j () scm ! kde ! org
[Download RAW message or body]

Git commit 7b380e9677678c0e3bcec981a2466ccb04f4e590 by Aaron Seigo.
Committed on 28/12/2015 at 19:21.
Pushed by aseigo into branch 'develop'.

methods to get resourceIds and a compelter built on that

M  +44   -0    akonadish/akonadish_utils.cpp
M  +4    -0    akonadish/akonadish_utils.h

http://commits.kde.org/akonadi-next/7b380e9677678c0e3bcec981a2466ccb04f4e590

diff --git a/akonadish/akonadish_utils.cpp b/akonadish/akonadish_utils.cpp
index ffbdcb3..90847f6 100644
--- a/akonadish/akonadish_utils.cpp
+++ b/akonadish/akonadish_utils.cpp
@@ -70,6 +70,50 @@ QSharedPointer<QAbstractItemModel> loadModel(const QString &type, \
Akonadi2::Quer  return model;
 }
 
+QStringList resourceIds(State &state)
+{
+    QStringList resources;
+    Akonadi2::Query query;
+    query.syncOnDemand = false;
+    query.processAll = false;
+    query.liveQuery = false;
+    auto model = AkonadishUtils::loadModel("resource", query);
+
+    QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model, \
&resources] (const QModelIndex &index, int start, int end) mutable { +        for \
(int i = start; i <= end; i++) { +            auto object = \
model->data(model->index(i, 0, index), \
Akonadi2::Store::DomainObjectBaseRole).value<Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr>();
 +            resources << object->identifier();
+        }
+    });
+
+    QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, \
state](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { +       \
if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { +            \
state.commandFinished(); +        }
+    });
+
+    state.commandStarted();
+
+    return resources;
+}
+
+QStringList resourceCompleter(const QStringList &commands, const QString &fragment, \
State &state) +{
+    QStringList resources = resourceIds(state);
+    if (fragment.isEmpty()) {
+        return resources;
+    }
+
+    QStringList filtered;
+    for (auto resource: resources) {
+        if (resource.startsWith(fragment)) {
+            filtered << resource;
+        }
+    }
+
+    return filtered;
+}
+
 QMap<QString, QString> keyValueMapFromArgs(const QStringList &args)
 {
     //TODO: this is not the most clever of algorithms. preserved during the port of \
                commands
diff --git a/akonadish/akonadish_utils.h b/akonadish/akonadish_utils.h
index 17b8ec7..5671157 100644
--- a/akonadish/akonadish_utils.h
+++ b/akonadish/akonadish_utils.h
@@ -26,6 +26,8 @@
 #include "common/query.h"
 #include "common/clientapi.h"
 
+#include "state.h"
+
 namespace AkonadishUtils
 {
 
@@ -34,6 +36,8 @@ class StoreBase;
 bool isValidStoreType(const QString &type);
 StoreBase &getStore(const QString &type);
 QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Akonadi2::Query \
query); +QStringList resourceIds();
+QStringList resourceCompleter(const QStringList &, const QString &fragment, State \
&state);  QMap<QString, QString> keyValueMapFromArgs(const QStringList &args);
 
 /**


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

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