summaryrefslogtreecommitdiffstats
path: root/examples/client/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/client/main.cpp')
-rw-r--r--examples/client/main.cpp87
1 files changed, 73 insertions, 14 deletions
diff --git a/examples/client/main.cpp b/examples/client/main.cpp
index 0a1a725..2aeb328 100644
--- a/examples/client/main.cpp
+++ b/examples/client/main.cpp
@@ -20,21 +20,24 @@
20#include <QApplication> 20#include <QApplication>
21#include <QCommandLineParser> 21#include <QCommandLineParser>
22#include <QCommandLineOption> 22#include <QCommandLineOption>
23#include <QElapsedTimer>
23 24
24#include "common/clientapi.h" 25#include "common/clientapi.h"
25#include "common/resource.h" 26#include "common/resource.h"
26#include "common/listmodelresult.h"
27#include "common/storage.h" 27#include "common/storage.h"
28#include "common/domain/event.h" 28#include "common/domain/event.h"
29#include "common/domain/folder.h"
29#include "common/resourceconfig.h" 30#include "common/resourceconfig.h"
31#include "common/log.h"
30#include "console.h" 32#include "console.h"
31 33
32#include <QWidget> 34#include <QWidget>
33#include <QListView> 35#include <QTreeView>
34#include <QVBoxLayout> 36#include <QVBoxLayout>
35#include <QLabel> 37#include <QLabel>
36#include <QPushButton> 38#include <QPushButton>
37#include <QItemSelectionModel> 39#include <QItemSelectionModel>
40#include <iostream>
38 41
39template <typename T> 42template <typename T>
40class View : public QWidget 43class View : public QWidget
@@ -43,8 +46,8 @@ public:
43 View(QAbstractItemModel *model) 46 View(QAbstractItemModel *model)
44 : QWidget() 47 : QWidget()
45 { 48 {
46 auto listView = new QListView(this); 49 auto modelView = new QTreeView(this);
47 listView->setModel(model); 50 modelView->setModel(model);
48 resize(1000, 1500); 51 resize(1000, 1500);
49 52
50 auto topLayout = new QVBoxLayout(this); 53 auto topLayout = new QVBoxLayout(this);
@@ -61,36 +64,59 @@ public:
61 QObject::connect(syncButton, &QPushButton::pressed, []() { 64 QObject::connect(syncButton, &QPushButton::pressed, []() {
62 Akonadi2::Query query; 65 Akonadi2::Query query;
63 query.resources << "org.kde.dummy.instance1"; 66 query.resources << "org.kde.dummy.instance1";
64 Akonadi2::Store::synchronize(query); 67 query.syncOnDemand = true;
68 Akonadi2::Store::synchronize(query).exec();
65 }); 69 });
66 70
67 auto removeButton = new QPushButton(this); 71 auto removeButton = new QPushButton(this);
68 removeButton->setText("Remove"); 72 removeButton->setText("Remove");
69 QObject::connect(removeButton, &QPushButton::pressed, [listView]() { 73 QObject::connect(removeButton, &QPushButton::pressed, [modelView]() {
70 for (auto index :listView->selectionModel()->selectedIndexes()) { 74 for (auto index : modelView->selectionModel()->selectedIndexes()) {
71 auto object = index.data(DomainObjectRole).value<typename T::Ptr>(); 75 auto object = index.data(Akonadi2::Store::DomainObjectRole).value<typename T::Ptr>();
72 Akonadi2::Store::remove(*object).exec(); 76 Akonadi2::Store::remove(*object).exec();
73 } 77 }
74 }); 78 });
75 79
76 topLayout->addWidget(titleLabel); 80 topLayout->addWidget(titleLabel);
77 topLayout->addWidget(syncButton); 81 topLayout->addWidget(syncButton);
78 topLayout->addWidget(listView, 10); 82 topLayout->addWidget(modelView, 10);
79 83
80 show(); 84 show();
81 } 85 }
82 86
83}; 87};
84 88
89
90class MyApplication : public QApplication
91{
92 QElapsedTimer t;
93public:
94 MyApplication(int& argc, char ** argv) : QApplication(argc, argv) { }
95 virtual ~MyApplication() { }
96
97 virtual bool notify(QObject* receiver, QEvent* event)
98 {
99 t.start();
100 bool ret = QApplication::notify(receiver, event);
101 if(t.elapsed() > 3)
102 qDebug("processing event type %d for object %s took %dms",
103 (int)event->type(), receiver->objectName().toLocal8Bit().data(),
104 (int)t.elapsed());
105 return ret;
106 }
107};
108
85int main(int argc, char *argv[]) 109int main(int argc, char *argv[])
86{ 110{
87 QApplication app(argc, argv); 111 MyApplication app(argc, argv);
88 112
89 QCommandLineParser cliOptions; 113 QCommandLineParser cliOptions;
90 cliOptions.addPositionalArgument(QObject::tr("[resource]"), 114 cliOptions.addPositionalArgument(QObject::tr("[resource]"),
91 QObject::tr("A resource to connect to")); 115 QObject::tr("A resource to connect to"));
92 cliOptions.addOption(QCommandLineOption("clear")); 116 cliOptions.addOption(QCommandLineOption("clear"));
93 cliOptions.addOption(QCommandLineOption("debuglevel")); 117 cliOptions.addOption(QCommandLineOption("debuglevel"));
118 cliOptions.addOption(QCommandLineOption("list"));
119 cliOptions.addOption(QCommandLineOption("count"));
94 cliOptions.addHelpOption(); 120 cliOptions.addHelpOption();
95 cliOptions.process(app); 121 cliOptions.process(app);
96 QStringList resources = cliOptions.positionalArguments(); 122 QStringList resources = cliOptions.positionalArguments();
@@ -122,10 +148,43 @@ int main(int argc, char *argv[])
122 } 148 }
123 query.syncOnDemand = false; 149 query.syncOnDemand = false;
124 query.processAll = false; 150 query.processAll = false;
151 query.requestedProperties << "name";
125 query.liveQuery = true; 152 query.liveQuery = true;
126 153
127 auto model = QSharedPointer<ListModelResult<Akonadi2::ApplicationDomain::Event::Ptr> >::create(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Event>(query), QList<QByteArray>() << "summary" << "uid"); 154 QTime time;
128 auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Event> >::create(model.data()); 155 time.start();
129 156 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query);
130 return app.exec(); 157 qDebug() << "Loaded model in " << time.elapsed() << " ms";
158
159 if (cliOptions.isSet("list")) {
160 query.liveQuery = false;
161 qDebug() << "Listing";
162 QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) {
163 for (int i = start; i <= end; i++) {
164 std::cout << "\tRow " << model->rowCount() << ": " << model->data(model->index(i, 0, index)).toString().toStdString() << std::endl;
165 }
166 });
167 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) {
168 if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) {
169 app.quit();
170 }
171 });
172 if (!model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()) {
173 return app.exec();
174 }
175 } else if (cliOptions.isSet("count")) {
176 query.liveQuery = false;
177 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) {
178 if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) {
179 std::cout << "\tCounted results " << model->rowCount(QModelIndex());
180 app.quit();
181 }
182 });
183 return app.exec();
184 } else {
185 query.liveQuery = true;
186 auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Folder> >::create(model.data());
187 return app.exec();
188 }
189 return 0;
131} 190}