diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-05-24 13:45:28 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-05-24 13:45:28 +0200 |
commit | 12f867fcad903272e1af2285e9eef35060d44923 (patch) | |
tree | 746b5b58e65ddd5d634eaa9de4766f4eadf087e2 | |
parent | a882d614ab4500955adb4aa184776c33a06d6a40 (diff) | |
parent | 1f8041dfbc2cb7a35ced4793e10715457ad5cb23 (diff) | |
download | sink-12f867fcad903272e1af2285e9eef35060d44923.tar.gz sink-12f867fcad903272e1af2285e9eef35060d44923.zip |
Merge branch 'dev/client' into develop
-rw-r--r-- | examples/client/main.cpp | 102 |
1 files changed, 91 insertions, 11 deletions
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 @@ | |||
19 | 19 | ||
20 | #include <QApplication> | 20 | #include <QApplication> |
21 | #include <QCommandLineParser> | 21 | #include <QCommandLineParser> |
22 | #include <QStringListModel> | ||
22 | 23 | ||
23 | #include "common/commands.h" | 24 | #include "common/clientapi.h" |
24 | #include "common/resourceaccess.h" | 25 | #include "common/resultprovider.h" |
26 | #include "common/resource.h" | ||
27 | #include "common/synclistresult.h" | ||
25 | #include "console.h" | 28 | #include "console.h" |
26 | 29 | ||
30 | #include <QWidget> | ||
31 | #include <QListView> | ||
32 | #include <QVBoxLayout> | ||
33 | #include <QLabel> | ||
34 | #include <QPushButton> | ||
35 | |||
36 | class View : public QWidget | ||
37 | { | ||
38 | public: | ||
39 | View(QAbstractItemModel *model) | ||
40 | : QWidget() | ||
41 | { | ||
42 | auto listView = new QListView(this); | ||
43 | listView->setModel(model); | ||
44 | resize(1000, 1500); | ||
45 | |||
46 | auto topLayout = new QVBoxLayout(this); | ||
47 | |||
48 | auto titleLabel = new QLabel(this); | ||
49 | titleLabel->setText("Demo"); | ||
50 | auto font = titleLabel->font(); | ||
51 | font.setWeight(QFont::Bold); | ||
52 | titleLabel->setFont(font); | ||
53 | titleLabel->setAlignment(Qt::AlignCenter); | ||
54 | |||
55 | auto syncButton = new QPushButton(this); | ||
56 | syncButton->setText("Synchronize!"); | ||
57 | QObject::connect(syncButton, &QPushButton::pressed, []() { | ||
58 | Akonadi2::Store::synchronize("org.kde.dummy"); | ||
59 | }); | ||
60 | |||
61 | topLayout->addWidget(titleLabel); | ||
62 | topLayout->addWidget(syncButton); | ||
63 | topLayout->addWidget(listView, 10); | ||
64 | |||
65 | show(); | ||
66 | } | ||
67 | |||
68 | }; | ||
69 | |||
70 | template<class T> | ||
71 | class AkonadiListModel : public QStringListModel | ||
72 | { | ||
73 | public: | ||
74 | AkonadiListModel(const QSharedPointer<async::ResultEmitter<T> > &emitter, const QByteArray &property) | ||
75 | :QStringListModel(), | ||
76 | mEmitter(emitter) | ||
77 | { | ||
78 | emitter->onAdded([this, property](const T &value) { | ||
79 | // qDebug() << "VALUE ADDED"; | ||
80 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr type(value); | ||
81 | mStringList << type->getProperty(property).toString(); | ||
82 | setStringList(mStringList); | ||
83 | }); | ||
84 | emitter->onInitialResultSetComplete([this]() { | ||
85 | }); | ||
86 | emitter->onComplete([this]() { | ||
87 | // qDebug() << "COMPLETE"; | ||
88 | mEmitter.clear(); | ||
89 | }); | ||
90 | emitter->onClear([this]() { | ||
91 | // qDebug() << "CLEAR"; | ||
92 | mStringList.clear(); | ||
93 | setStringList(mStringList); | ||
94 | }); | ||
95 | } | ||
96 | |||
97 | private: | ||
98 | QSharedPointer<async::ResultEmitter<T> > mEmitter; | ||
99 | QStringList mStringList; | ||
100 | }; | ||
101 | |||
27 | int main(int argc, char *argv[]) | 102 | int main(int argc, char *argv[]) |
28 | { | 103 | { |
29 | QApplication app(argc, argv); | 104 | QApplication app(argc, argv); |
30 | 105 | ||
31 | new Console("Akonadi2 Client"); | 106 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy", Akonadi2::Storage::ReadWrite); |
32 | Console::main()->log(QString("PID: %1").arg(QCoreApplication::applicationPid())); | 107 | store.removeFromDisk(); |
33 | 108 | ||
34 | QCommandLineParser cliOptions; | 109 | QCommandLineParser cliOptions; |
35 | cliOptions.addPositionalArgument(QObject::tr("[resource]"), | 110 | cliOptions.addPositionalArgument(QObject::tr("[resource]"), |
@@ -40,13 +115,18 @@ int main(int argc, char *argv[]) | |||
40 | resources << "org.kde.dummy"; | 115 | resources << "org.kde.dummy"; |
41 | } | 116 | } |
42 | 117 | ||
43 | for (const QString &resource: resources) { | 118 | //FIXME move to clientapi |
44 | Akonadi2::ResourceAccess *resAccess = new Akonadi2::ResourceAccess(resource.toLatin1()); | 119 | Akonadi2::ResourceFactory::load("org.kde.dummy"); |
45 | QObject::connect(&app, &QCoreApplication::aboutToQuit, | 120 | |
46 | resAccess, &Akonadi2::ResourceAccess::close); | 121 | Akonadi2::Query query; |
47 | resAccess->sendCommand(Akonadi2::Commands::SynchronizeCommand); | 122 | query.resources << "org.kde.dummy"; |
48 | resAccess->open(); | 123 | query.syncOnDemand = false; |
49 | } | 124 | query.processAll = false; |
125 | query.liveQuery = true; | ||
126 | // query.propertyFilter.insert("uid", "testuid"); | ||
127 | |||
128 | auto model = QSharedPointer<AkonadiListModel<Akonadi2::ApplicationDomain::Event::Ptr> >::create(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Event>(query), "summary"); | ||
129 | auto view = QSharedPointer<View>::create(model.data()); | ||
50 | 130 | ||
51 | return app.exec(); | 131 | return app.exec(); |
52 | } | 132 | } |