summaryrefslogtreecommitdiffstats
path: root/examples/client
diff options
context:
space:
mode:
Diffstat (limited to 'examples/client')
-rw-r--r--examples/client/main.cpp59
1 files changed, 34 insertions, 25 deletions
diff --git a/examples/client/main.cpp b/examples/client/main.cpp
index 5470e17..7bbac56 100644
--- a/examples/client/main.cpp
+++ b/examples/client/main.cpp
@@ -123,9 +123,13 @@ static QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Akonadi
123 } else if (type == "event") { 123 } else if (type == "event") {
124 query.requestedProperties << "summary"; 124 query.requestedProperties << "summary";
125 model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Event>(query); 125 model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Event>(query);
126 } else if (type == "resource") {
127 query.requestedProperties << "identifier" << "type";
128 model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::AkonadiResource>(query);
126 } 129 }
127 qDebug() << "Folder type " << type; 130 qDebug() << "Folder type " << type;
128 qDebug() << "Loaded model in " << time.elapsed() << " ms"; 131 qDebug() << "Loaded model in " << time.elapsed() << " ms";
132 Q_ASSERT(model);
129 return model; 133 return model;
130} 134}
131 135
@@ -134,41 +138,30 @@ int main(int argc, char *argv[])
134 MyApplication app(argc, argv); 138 MyApplication app(argc, argv);
135 139
136 QCommandLineParser cliOptions; 140 QCommandLineParser cliOptions;
137 cliOptions.addPositionalArgument(QObject::tr("[resource]"), 141 cliOptions.addPositionalArgument(QObject::tr("[command]"),
138 QObject::tr("A resource to connect to")); 142 QObject::tr("A command"));
139 cliOptions.addPositionalArgument(QObject::tr("[type]"), 143 cliOptions.addPositionalArgument(QObject::tr("[type]"),
140 QObject::tr("A type to work with")); 144 QObject::tr("A type to work with"));
145 cliOptions.addPositionalArgument(QObject::tr("[resource]"),
146 QObject::tr("A resource to connect to"));
141 cliOptions.addOption(QCommandLineOption("clear")); 147 cliOptions.addOption(QCommandLineOption("clear"));
142 cliOptions.addOption(QCommandLineOption("debuglevel")); 148 cliOptions.addOption(QCommandLineOption("debuglevel"));
143 // cliOptions.addOption(QCommandLineOption("type", "type to list", "type"));
144 cliOptions.addOption(QCommandLineOption("list"));
145 cliOptions.addOption(QCommandLineOption("count"));
146 cliOptions.addOption(QCommandLineOption("synchronize"));
147 cliOptions.addHelpOption(); 149 cliOptions.addHelpOption();
148 cliOptions.process(app); 150 cliOptions.process(app);
149 QStringList args = cliOptions.positionalArguments(); 151 QStringList args = cliOptions.positionalArguments();
150 auto type = args.takeLast(); 152 auto command = args.takeFirst();
153 auto type = !args.isEmpty() ? args.takeFirst() : QByteArray();
151 auto resources = args; 154 auto resources = args;
152 if (resources.isEmpty()) {
153 resources << "org.kde.dummy.instance1";
154 }
155 155
156 if (cliOptions.isSet("clear")) {
157 qDebug() << "Clearing";
158 for (const auto &resource : resources) {
159 Akonadi2::Store::removeFromDisk(resource.toLatin1());
160 }
161 return 0;
162 }
163 if (cliOptions.isSet("debuglevel")) { 156 if (cliOptions.isSet("debuglevel")) {
164 Akonadi2::Log::setDebugOutputLevel(static_cast<Akonadi2::Log::DebugLevel>(cliOptions.value("debuglevel").toInt())); 157 Akonadi2::Log::setDebugOutputLevel(static_cast<Akonadi2::Log::DebugLevel>(cliOptions.value("debuglevel").toInt()));
165 } 158 }
166 159
167 //Ensure resource is ready 160 //Ensure resource is ready
168 for (const auto &resource : resources) { 161 // for (const auto &resource : resources) {
169 Akonadi2::ResourceFactory::load(Akonadi2::Store::resourceName(resource.toLatin1())); 162 // Akonadi2::ResourceFactory::load(Akonadi2::Store::resourceName(resource.toLatin1()));
170 ResourceConfig::addResource(resource.toLatin1(), Akonadi2::Store::resourceName(resource.toLatin1())); 163 // ResourceConfig::addResource(resource.toLatin1(), Akonadi2::Store::resourceName(resource.toLatin1()));
171 } 164 // }
172 165
173 Akonadi2::Query query; 166 Akonadi2::Query query;
174 for (const auto &res : resources) { 167 for (const auto &res : resources) {
@@ -180,7 +173,7 @@ int main(int argc, char *argv[])
180 173
181 qDebug() << "Type: " << type; 174 qDebug() << "Type: " << type;
182 175
183 if (cliOptions.isSet("list")) { 176 if (command == "list") {
184 query.liveQuery = false; 177 query.liveQuery = false;
185 auto model = loadModel(type, query); 178 auto model = loadModel(type, query);
186 qDebug() << "Listing"; 179 qDebug() << "Listing";
@@ -192,6 +185,7 @@ int main(int argc, char *argv[])
192 QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { 185 QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) {
193 for (int i = start; i <= end; i++) { 186 for (int i = start; i <= end; i++) {
194 std::cout << "\tRow " << model->rowCount() << ":\t "; 187 std::cout << "\tRow " << model->rowCount() << ":\t ";
188 std::cout << "\t" << model->data(model->index(i, 0, index), Akonadi2::Store::DomainObjectBaseRole).value<Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr>()->identifier().toStdString();
195 for (int col = 0; col < model->columnCount(QModelIndex()); col++) { 189 for (int col = 0; col < model->columnCount(QModelIndex()); col++) {
196 std::cout << "\t" << model->data(model->index(i, col, index)).toString().toStdString(); 190 std::cout << "\t" << model->data(model->index(i, col, index)).toString().toStdString();
197 } 191 }
@@ -206,7 +200,7 @@ int main(int argc, char *argv[])
206 if (!model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()) { 200 if (!model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()) {
207 return app.exec(); 201 return app.exec();
208 } 202 }
209 } else if (cliOptions.isSet("count")) { 203 } else if (command == "count") {
210 query.liveQuery = false; 204 query.liveQuery = false;
211 auto model = loadModel(type, query); 205 auto model = loadModel(type, query);
212 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { 206 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) {
@@ -216,14 +210,14 @@ int main(int argc, char *argv[])
216 } 210 }
217 }); 211 });
218 return app.exec(); 212 return app.exec();
219 } else if (cliOptions.isSet("synchronize")) { 213 } else if (command == "synchronize") {
220 query.syncOnDemand = true; 214 query.syncOnDemand = true;
221 query.processAll = true; 215 query.processAll = true;
222 Akonadi2::Store::synchronize(query).then<void>([&app]() { 216 Akonadi2::Store::synchronize(query).then<void>([&app]() {
223 app.quit(); 217 app.quit();
224 }).exec(); 218 }).exec();
225 app.exec(); 219 app.exec();
226 } else { 220 } else if (command == "show") {
227 query.liveQuery = true; 221 query.liveQuery = true;
228 if (type == "folder") { 222 if (type == "folder") {
229 query.parentProperty = "parent"; 223 query.parentProperty = "parent";
@@ -244,6 +238,21 @@ int main(int argc, char *argv[])
244 auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Event> >::create(model.data()); 238 auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Event> >::create(model.data());
245 app.exec(); 239 app.exec();
246 } 240 }
241 } else if (command == "clear") {
242 qDebug() << "Clearing";
243 for (const auto &resource : resources) {
244 Akonadi2::Store::removeFromDisk(resource.toLatin1());
245 }
246 } else if (command == "create") {
247 if (type == "resource") {
248 Akonadi2::ApplicationDomain::AkonadiResource resource;
249 resource.setProperty("identifier", resources.at(0));
250 resource.setProperty("type", resources.at(1));
251 Akonadi2::Store::create<Akonadi2::ApplicationDomain::AkonadiResource>(resource).exec().waitForFinished();
252 qDebug() << "Created resource " << resources;
253 }
254 } else {
255 qWarning() << "Unknown command " << command;
247 } 256 }
248 return 0; 257 return 0;
249} 258}