From 1f8041dfbc2cb7a35ced4793e10715457ad5cb23 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 24 May 2015 13:35:23 +0200 Subject: A test client showing a model that is populated by a query --- examples/client/main.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 91 insertions(+), 11 deletions(-) (limited to 'examples/client/main.cpp') diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 5cd6141..55ec678 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -19,17 +19,92 @@ #include #include +#include -#include "common/commands.h" -#include "common/resourceaccess.h" +#include "common/clientapi.h" +#include "common/resultprovider.h" +#include "common/resource.h" +#include "common/synclistresult.h" #include "console.h" +#include +#include +#include +#include +#include + +class View : public QWidget +{ +public: + View(QAbstractItemModel *model) + : QWidget() + { + auto listView = new QListView(this); + listView->setModel(model); + resize(1000, 1500); + + auto topLayout = new QVBoxLayout(this); + + auto titleLabel = new QLabel(this); + titleLabel->setText("Demo"); + auto font = titleLabel->font(); + font.setWeight(QFont::Bold); + titleLabel->setFont(font); + titleLabel->setAlignment(Qt::AlignCenter); + + auto syncButton = new QPushButton(this); + syncButton->setText("Synchronize!"); + QObject::connect(syncButton, &QPushButton::pressed, []() { + Akonadi2::Store::synchronize("org.kde.dummy"); + }); + + topLayout->addWidget(titleLabel); + topLayout->addWidget(syncButton); + topLayout->addWidget(listView, 10); + + show(); + } + +}; + +template +class AkonadiListModel : public QStringListModel +{ +public: + AkonadiListModel(const QSharedPointer > &emitter, const QByteArray &property) + :QStringListModel(), + mEmitter(emitter) + { + emitter->onAdded([this, property](const T &value) { + // qDebug() << "VALUE ADDED"; + Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr type(value); + mStringList << type->getProperty(property).toString(); + setStringList(mStringList); + }); + emitter->onInitialResultSetComplete([this]() { + }); + emitter->onComplete([this]() { + // qDebug() << "COMPLETE"; + mEmitter.clear(); + }); + emitter->onClear([this]() { + // qDebug() << "CLEAR"; + mStringList.clear(); + setStringList(mStringList); + }); + } + +private: + QSharedPointer > mEmitter; + QStringList mStringList; +}; + int main(int argc, char *argv[]) { QApplication app(argc, argv); - new Console("Akonadi2 Client"); - Console::main()->log(QString("PID: %1").arg(QCoreApplication::applicationPid())); + Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy", Akonadi2::Storage::ReadWrite); + store.removeFromDisk(); QCommandLineParser cliOptions; cliOptions.addPositionalArgument(QObject::tr("[resource]"), @@ -40,13 +115,18 @@ int main(int argc, char *argv[]) resources << "org.kde.dummy"; } - for (const QString &resource: resources) { - Akonadi2::ResourceAccess *resAccess = new Akonadi2::ResourceAccess(resource.toLatin1()); - QObject::connect(&app, &QCoreApplication::aboutToQuit, - resAccess, &Akonadi2::ResourceAccess::close); - resAccess->sendCommand(Akonadi2::Commands::SynchronizeCommand); - resAccess->open(); - } + //FIXME move to clientapi + Akonadi2::ResourceFactory::load("org.kde.dummy"); + + Akonadi2::Query query; + query.resources << "org.kde.dummy"; + query.syncOnDemand = false; + query.processAll = false; + query.liveQuery = true; + // query.propertyFilter.insert("uid", "testuid"); + + auto model = QSharedPointer >::create(Akonadi2::Store::load(query), "summary"); + auto view = QSharedPointer::create(model.data()); return app.exec(); } -- cgit v1.2.3