From kde-commits Mon Dec 28 19:31:31 2015 From: Aaron Seigo Date: Mon, 28 Dec 2015 19:31:31 +0000 To: kde-commits Subject: [akonadi-next/develop] akonadish: methods to get resourceIds and a compelter built on that Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=145133110419910 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 loadModel(const QStri= ng &type, Akonadi2::Quer return model; } = +QStringList resourceIds(State &state) +{ + QStringList resources; + Akonadi2::Query query; + query.syncOnDemand =3D false; + query.processAll =3D false; + query.liveQuery =3D false; + auto model =3D AkonadishUtils::loadModel("resource", query); + + QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [mod= el, &resources] (const QModelIndex &index, int start, int end) mutable { + for (int i =3D start; i <=3D end; i++) { + auto object =3D model->data(model->index(i, 0, index), Akonadi= 2::Store::DomainObjectBaseRole).value(); + resources << object->identifier(); + } + }); + + QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [mode= l, state](const QModelIndex &, const QModelIndex &, const QVector &rol= es) { + if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { + state.commandFinished(); + } + }); + + state.commandStarted(); + + return resources; +} + +QStringList resourceCompleter(const QStringList &commands, const QString &= fragment, State &state) +{ + QStringList resources =3D resourceIds(state); + if (fragment.isEmpty()) { + return resources; + } + + QStringList filtered; + for (auto resource: resources) { + if (resource.startsWith(fragment)) { + filtered << resource; + } + } + + return filtered; +} + QMap keyValueMapFromArgs(const QStringList &args) { //TODO: this is not the most clever of algorithms. preserved during th= e 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 loadModel(const QString &type, Akonadi2= ::Query query); +QStringList resourceIds(); +QStringList resourceCompleter(const QStringList &, const QString &fragment= , State &state); QMap keyValueMapFromArgs(const QStringList &args); = /**