From 0118cd09f9a2cc956ae0a07b3ba8ad3c95314cab Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 27 Nov 2015 17:44:21 +0100 Subject: list and count options for non-gui operations --- examples/client/main.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 794fc58..c75b3ce 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -68,7 +68,7 @@ public: auto removeButton = new QPushButton(this); removeButton->setText("Remove"); QObject::connect(removeButton, &QPushButton::pressed, [modelView]() { - for (auto index :modelView->selectionModel()->selectedIndexes()) { + for (auto index : modelView->selectionModel()->selectedIndexes()) { auto object = index.data(Akonadi2::Store::DomainObjectRole).value(); Akonadi2::Store::remove(*object).exec(); } @@ -93,6 +93,8 @@ int main(int argc, char *argv[]) QObject::tr("A resource to connect to")); cliOptions.addOption(QCommandLineOption("clear")); cliOptions.addOption(QCommandLineOption("debuglevel")); + cliOptions.addOption(QCommandLineOption("list")); + cliOptions.addOption(QCommandLineOption("count")); cliOptions.addHelpOption(); cliOptions.process(app); QStringList resources = cliOptions.positionalArguments(); @@ -124,11 +126,27 @@ int main(int argc, char *argv[]) } query.syncOnDemand = false; query.processAll = false; - query.liveQuery = true; query.requestedProperties << "name"; auto model = Akonadi2::Store::loadModel(query); - auto view = QSharedPointer >::create(model.data()); - - return app.exec(); + if (cliOptions.isSet("list")) { + query.liveQuery = false; + qDebug() << "Listing"; + QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { + for (int i = start; i <= end; i++) { + qDebug() << model->data(model->index(i, 0, index)).toString(); + } + }); + model->fetchMore(QModelIndex()); + return app.exec(); + } else if (cliOptions.isSet("count")) { + query.liveQuery = false; + model->fetchMore(QModelIndex()); + qDebug() << "Counted results " << model->rowCount(QModelIndex()); + } else { + query.liveQuery = true; + auto view = QSharedPointer >::create(model.data()); + return app.exec(); + } + return 0; } -- cgit v1.2.3