diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-01 11:14:30 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-01 11:14:30 +0100 |
commit | bbdd4b86328f03b5a466dcff5c7179775c03ab2f (patch) | |
tree | 54e64bf742d8ba750c2946509f88a014c7b7e460 /examples/client/main.cpp | |
parent | 44edbee0f0b2fcf13e2ee388a90a8dd1f84a329e (diff) | |
download | sink-bbdd4b86328f03b5a466dcff5c7179775c03ab2f.tar.gz sink-bbdd4b86328f03b5a466dcff5c7179775c03ab2f.zip |
Example client: sync and trees
Diffstat (limited to 'examples/client/main.cpp')
-rw-r--r-- | examples/client/main.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 2aeb328..ac40fcb 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp | |||
@@ -40,6 +40,18 @@ | |||
40 | #include <iostream> | 40 | #include <iostream> |
41 | 41 | ||
42 | template <typename T> | 42 | template <typename T> |
43 | QString format(const T &object) | ||
44 | { | ||
45 | QString output; | ||
46 | output.append(object->identifier()); | ||
47 | output.append(QStringLiteral("\t")); | ||
48 | output.append(object->getProperty("name").toString()); | ||
49 | output.append(QStringLiteral("\t")); | ||
50 | output.append(object->getProperty("parent").toString()); | ||
51 | return output; | ||
52 | } | ||
53 | |||
54 | template <typename T> | ||
43 | class View : public QWidget | 55 | class View : public QWidget |
44 | { | 56 | { |
45 | public: | 57 | public: |
@@ -117,6 +129,7 @@ int main(int argc, char *argv[]) | |||
117 | cliOptions.addOption(QCommandLineOption("debuglevel")); | 129 | cliOptions.addOption(QCommandLineOption("debuglevel")); |
118 | cliOptions.addOption(QCommandLineOption("list")); | 130 | cliOptions.addOption(QCommandLineOption("list")); |
119 | cliOptions.addOption(QCommandLineOption("count")); | 131 | cliOptions.addOption(QCommandLineOption("count")); |
132 | cliOptions.addOption(QCommandLineOption("synchronize")); | ||
120 | cliOptions.addHelpOption(); | 133 | cliOptions.addHelpOption(); |
121 | cliOptions.process(app); | 134 | cliOptions.process(app); |
122 | QStringList resources = cliOptions.positionalArguments(); | 135 | QStringList resources = cliOptions.positionalArguments(); |
@@ -153,15 +166,16 @@ int main(int argc, char *argv[]) | |||
153 | 166 | ||
154 | QTime time; | 167 | QTime time; |
155 | time.start(); | 168 | time.start(); |
156 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); | ||
157 | qDebug() << "Loaded model in " << time.elapsed() << " ms"; | ||
158 | 169 | ||
159 | if (cliOptions.isSet("list")) { | 170 | if (cliOptions.isSet("list")) { |
160 | query.liveQuery = false; | 171 | query.liveQuery = false; |
172 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); | ||
173 | qDebug() << "Loaded model in " << time.elapsed() << " ms"; | ||
161 | qDebug() << "Listing"; | 174 | qDebug() << "Listing"; |
162 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { | 175 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { |
163 | for (int i = start; i <= end; i++) { | 176 | for (int i = start; i <= end; i++) { |
164 | std::cout << "\tRow " << model->rowCount() << ": " << model->data(model->index(i, 0, index)).toString().toStdString() << std::endl; | 177 | QString output = format<Akonadi2::ApplicationDomain::Folder::Ptr>(model->data(model->index(i, 0, index), Akonadi2::Store::DomainObjectRole).value<Akonadi2::ApplicationDomain::Folder::Ptr>()); |
178 | std::cout << "\tRow " << model->rowCount() << ": " << output.toStdString() << std::endl; | ||
165 | } | 179 | } |
166 | }); | 180 | }); |
167 | QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { | 181 | QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { |
@@ -174,6 +188,8 @@ int main(int argc, char *argv[]) | |||
174 | } | 188 | } |
175 | } else if (cliOptions.isSet("count")) { | 189 | } else if (cliOptions.isSet("count")) { |
176 | query.liveQuery = false; | 190 | query.liveQuery = false; |
191 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); | ||
192 | qDebug() << "Loaded model in " << time.elapsed() << " ms"; | ||
177 | QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { | 193 | QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { |
178 | if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { | 194 | if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { |
179 | std::cout << "\tCounted results " << model->rowCount(QModelIndex()); | 195 | std::cout << "\tCounted results " << model->rowCount(QModelIndex()); |
@@ -181,8 +197,23 @@ int main(int argc, char *argv[]) | |||
181 | } | 197 | } |
182 | }); | 198 | }); |
183 | return app.exec(); | 199 | return app.exec(); |
200 | } else if (cliOptions.isSet("synchronize")) { | ||
201 | query.syncOnDemand = true; | ||
202 | query.processAll = true; | ||
203 | Akonadi2::Store::synchronize(query).then<void>([&app]() { | ||
204 | app.quit(); | ||
205 | }).exec(); | ||
206 | app.exec(); | ||
184 | } else { | 207 | } else { |
208 | query.parentProperty = "parent"; | ||
185 | query.liveQuery = true; | 209 | query.liveQuery = true; |
210 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); | ||
211 | qDebug() << "Loaded model in " << time.elapsed() << " ms"; | ||
212 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { | ||
213 | for (int i = start; i <= end; i++) { | ||
214 | model->fetchMore(model->index(i, 0, index)); | ||
215 | } | ||
216 | }); | ||
186 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Folder> >::create(model.data()); | 217 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Folder> >::create(model.data()); |
187 | return app.exec(); | 218 | return app.exec(); |
188 | } | 219 | } |