diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-23 17:33:31 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-23 17:38:15 +0200 |
commit | a62b281d7b7617c6f00b92ff28d742c87e34b12a (patch) | |
tree | 221bfbcbf74dff6c7eb2508f43e86cacc0509cdf | |
parent | 1b78af0030e6b9cae60d32222d86491c281fa565 (diff) | |
download | sink-a62b281d7b7617c6f00b92ff28d742c87e34b12a.tar.gz sink-a62b281d7b7617c6f00b92ff28d742c87e34b12a.zip |
Fixed the client, only optionally delete the db, and avoid constant
model resets.
We can now even start multiple clients.
-rw-r--r-- | examples/client/main.cpp | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 55ec678..127bc08 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp | |||
@@ -19,7 +19,8 @@ | |||
19 | 19 | ||
20 | #include <QApplication> | 20 | #include <QApplication> |
21 | #include <QCommandLineParser> | 21 | #include <QCommandLineParser> |
22 | #include <QStringListModel> | 22 | #include <QCommandLineOption> |
23 | #include <QAbstractListModel> | ||
23 | 24 | ||
24 | #include "common/clientapi.h" | 25 | #include "common/clientapi.h" |
25 | #include "common/resultprovider.h" | 26 | #include "common/resultprovider.h" |
@@ -55,7 +56,7 @@ public: | |||
55 | auto syncButton = new QPushButton(this); | 56 | auto syncButton = new QPushButton(this); |
56 | syncButton->setText("Synchronize!"); | 57 | syncButton->setText("Synchronize!"); |
57 | QObject::connect(syncButton, &QPushButton::pressed, []() { | 58 | QObject::connect(syncButton, &QPushButton::pressed, []() { |
58 | Akonadi2::Store::synchronize("org.kde.dummy"); | 59 | Akonadi2::Store::synchronize("org.kde.dummy.instance1"); |
59 | }); | 60 | }); |
60 | 61 | ||
61 | topLayout->addWidget(titleLabel); | 62 | topLayout->addWidget(titleLabel); |
@@ -68,18 +69,19 @@ public: | |||
68 | }; | 69 | }; |
69 | 70 | ||
70 | template<class T> | 71 | template<class T> |
71 | class AkonadiListModel : public QStringListModel | 72 | class AkonadiListModel : public QAbstractListModel |
72 | { | 73 | { |
73 | public: | 74 | public: |
74 | AkonadiListModel(const QSharedPointer<async::ResultEmitter<T> > &emitter, const QByteArray &property) | 75 | AkonadiListModel(const QSharedPointer<async::ResultEmitter<T> > &emitter, const QByteArray &property) |
75 | :QStringListModel(), | 76 | :QAbstractListModel(), |
76 | mEmitter(emitter) | 77 | mEmitter(emitter) |
77 | { | 78 | { |
78 | emitter->onAdded([this, property](const T &value) { | 79 | emitter->onAdded([this, property](const T &value) { |
79 | // qDebug() << "VALUE ADDED"; | 80 | // qDebug() << "VALUE ADDED"; |
80 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr type(value); | 81 | Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr type(value); |
82 | beginInsertRows(QModelIndex(), mStringList.size(), mStringList.size()); | ||
81 | mStringList << type->getProperty(property).toString(); | 83 | mStringList << type->getProperty(property).toString(); |
82 | setStringList(mStringList); | 84 | endInsertRows(); |
83 | }); | 85 | }); |
84 | emitter->onInitialResultSetComplete([this]() { | 86 | emitter->onInitialResultSetComplete([this]() { |
85 | }); | 87 | }); |
@@ -89,11 +91,29 @@ public: | |||
89 | }); | 91 | }); |
90 | emitter->onClear([this]() { | 92 | emitter->onClear([this]() { |
91 | // qDebug() << "CLEAR"; | 93 | // qDebug() << "CLEAR"; |
94 | beginResetModel(); | ||
92 | mStringList.clear(); | 95 | mStringList.clear(); |
93 | setStringList(mStringList); | 96 | endResetModel(); |
94 | }); | 97 | }); |
95 | } | 98 | } |
96 | 99 | ||
100 | int rowCount(const QModelIndex &parent = QModelIndex()) const | ||
101 | { | ||
102 | return mStringList.size(); | ||
103 | } | ||
104 | |||
105 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const | ||
106 | { | ||
107 | if (index.row() >= mStringList.size()) { | ||
108 | qWarning() << "Out of bounds access"; | ||
109 | return QVariant(); | ||
110 | } | ||
111 | if (role == Qt::DisplayRole) { | ||
112 | return QVariant::fromValue(mStringList.at(index.row())); | ||
113 | } | ||
114 | return QVariant(); | ||
115 | } | ||
116 | |||
97 | private: | 117 | private: |
98 | QSharedPointer<async::ResultEmitter<T> > mEmitter; | 118 | QSharedPointer<async::ResultEmitter<T> > mEmitter; |
99 | QStringList mStringList; | 119 | QStringList mStringList; |
@@ -103,23 +123,32 @@ int main(int argc, char *argv[]) | |||
103 | { | 123 | { |
104 | QApplication app(argc, argv); | 124 | QApplication app(argc, argv); |
105 | 125 | ||
106 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy", Akonadi2::Storage::ReadWrite); | ||
107 | store.removeFromDisk(); | ||
108 | |||
109 | QCommandLineParser cliOptions; | 126 | QCommandLineParser cliOptions; |
110 | cliOptions.addPositionalArgument(QObject::tr("[resource]"), | 127 | cliOptions.addPositionalArgument(QObject::tr("[resource]"), |
111 | QObject::tr("A resource to connect to")); | 128 | QObject::tr("A resource to connect to")); |
129 | cliOptions.addOption(QCommandLineOption("clear")); | ||
130 | cliOptions.addHelpOption(); | ||
112 | cliOptions.process(app); | 131 | cliOptions.process(app); |
113 | QStringList resources = cliOptions.positionalArguments(); | 132 | QStringList resources = cliOptions.positionalArguments(); |
114 | if (resources.isEmpty()) { | 133 | if (resources.isEmpty()) { |
115 | resources << "org.kde.dummy"; | 134 | resources << "org.kde.dummy.instance1"; |
135 | } | ||
136 | |||
137 | if (!cliOptions.value("clear").isEmpty()) { | ||
138 | qDebug() << "Clearing"; | ||
139 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy.instance1", Akonadi2::Storage::ReadWrite); | ||
140 | store.removeFromDisk(); | ||
141 | return 0; | ||
116 | } | 142 | } |
117 | 143 | ||
118 | //FIXME move to clientapi | 144 | //FIXME move to clientapi |
119 | Akonadi2::ResourceFactory::load("org.kde.dummy"); | 145 | Akonadi2::ResourceFactory::load("org.kde.dummy"); |
120 | 146 | ||
147 | //Ensure resource is ready | ||
148 | ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); | ||
149 | |||
121 | Akonadi2::Query query; | 150 | Akonadi2::Query query; |
122 | query.resources << "org.kde.dummy"; | 151 | query.resources << "org.kde.dummy.instance1"; |
123 | query.syncOnDemand = false; | 152 | query.syncOnDemand = false; |
124 | query.processAll = false; | 153 | query.processAll = false; |
125 | query.liveQuery = true; | 154 | query.liveQuery = true; |