diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-27 17:44:21 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-27 17:44:21 +0100 |
commit | 0118cd09f9a2cc956ae0a07b3ba8ad3c95314cab (patch) | |
tree | 6623a133e46ea7db362513eac1a728a9658350e6 /examples/client/main.cpp | |
parent | 5b41b26a349967acf2197f9f9228526193fd826e (diff) | |
download | sink-0118cd09f9a2cc956ae0a07b3ba8ad3c95314cab.tar.gz sink-0118cd09f9a2cc956ae0a07b3ba8ad3c95314cab.zip |
list and count options for non-gui operations
Diffstat (limited to 'examples/client/main.cpp')
-rw-r--r-- | examples/client/main.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
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: | |||
68 | auto removeButton = new QPushButton(this); | 68 | auto removeButton = new QPushButton(this); |
69 | removeButton->setText("Remove"); | 69 | removeButton->setText("Remove"); |
70 | QObject::connect(removeButton, &QPushButton::pressed, [modelView]() { | 70 | QObject::connect(removeButton, &QPushButton::pressed, [modelView]() { |
71 | for (auto index :modelView->selectionModel()->selectedIndexes()) { | 71 | for (auto index : modelView->selectionModel()->selectedIndexes()) { |
72 | auto object = index.data(Akonadi2::Store::DomainObjectRole).value<typename T::Ptr>(); | 72 | auto object = index.data(Akonadi2::Store::DomainObjectRole).value<typename T::Ptr>(); |
73 | Akonadi2::Store::remove(*object).exec(); | 73 | Akonadi2::Store::remove(*object).exec(); |
74 | } | 74 | } |
@@ -93,6 +93,8 @@ int main(int argc, char *argv[]) | |||
93 | QObject::tr("A resource to connect to")); | 93 | QObject::tr("A resource to connect to")); |
94 | cliOptions.addOption(QCommandLineOption("clear")); | 94 | cliOptions.addOption(QCommandLineOption("clear")); |
95 | cliOptions.addOption(QCommandLineOption("debuglevel")); | 95 | cliOptions.addOption(QCommandLineOption("debuglevel")); |
96 | cliOptions.addOption(QCommandLineOption("list")); | ||
97 | cliOptions.addOption(QCommandLineOption("count")); | ||
96 | cliOptions.addHelpOption(); | 98 | cliOptions.addHelpOption(); |
97 | cliOptions.process(app); | 99 | cliOptions.process(app); |
98 | QStringList resources = cliOptions.positionalArguments(); | 100 | QStringList resources = cliOptions.positionalArguments(); |
@@ -124,11 +126,27 @@ int main(int argc, char *argv[]) | |||
124 | } | 126 | } |
125 | query.syncOnDemand = false; | 127 | query.syncOnDemand = false; |
126 | query.processAll = false; | 128 | query.processAll = false; |
127 | query.liveQuery = true; | ||
128 | query.requestedProperties << "name"; | 129 | query.requestedProperties << "name"; |
129 | 130 | ||
130 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); | 131 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); |
131 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Folder> >::create(model.data()); | 132 | if (cliOptions.isSet("list")) { |
132 | 133 | query.liveQuery = false; | |
133 | return app.exec(); | 134 | qDebug() << "Listing"; |
135 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { | ||
136 | for (int i = start; i <= end; i++) { | ||
137 | qDebug() << model->data(model->index(i, 0, index)).toString(); | ||
138 | } | ||
139 | }); | ||
140 | model->fetchMore(QModelIndex()); | ||
141 | return app.exec(); | ||
142 | } else if (cliOptions.isSet("count")) { | ||
143 | query.liveQuery = false; | ||
144 | model->fetchMore(QModelIndex()); | ||
145 | qDebug() << "Counted results " << model->rowCount(QModelIndex()); | ||
146 | } else { | ||
147 | query.liveQuery = true; | ||
148 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Folder> >::create(model.data()); | ||
149 | return app.exec(); | ||
150 | } | ||
151 | return 0; | ||
134 | } | 152 | } |