diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/CMakeLists.txt | 3 | ||||
-rw-r--r-- | examples/client/CMakeLists.txt | 8 | ||||
-rw-r--r-- | examples/client/console.cpp | 76 | ||||
-rw-r--r-- | examples/client/console.h | 42 | ||||
-rw-r--r-- | examples/client/main.cpp | 222 | ||||
-rw-r--r-- | examples/imapresource/tests/imapmailsyncbenchmark.cpp | 6 | ||||
-rw-r--r-- | examples/mailtransportresource/tests/mailtransporttest.cpp | 4 |
7 files changed, 5 insertions, 356 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d6f2d90..9d87b1c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt | |||
@@ -1,6 +1,3 @@ | |||
1 | # the client | ||
2 | add_subdirectory(client) | ||
3 | |||
4 | # a simple dummy resource implementation | 1 | # a simple dummy resource implementation |
5 | add_subdirectory(dummyresource) | 2 | add_subdirectory(dummyresource) |
6 | 3 | ||
diff --git a/examples/client/CMakeLists.txt b/examples/client/CMakeLists.txt deleted file mode 100644 index ef00368..0000000 --- a/examples/client/CMakeLists.txt +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | project(sink_client) | ||
2 | |||
3 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) | ||
4 | |||
5 | add_executable(${PROJECT_NAME} main.cpp console.cpp) | ||
6 | target_link_libraries(${PROJECT_NAME} sink) | ||
7 | qt5_use_modules(${PROJECT_NAME} Widgets Network) | ||
8 | install(TARGETS ${PROJECT_NAME} ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) | ||
diff --git a/examples/client/console.cpp b/examples/client/console.cpp deleted file mode 100644 index 8b4f1a5..0000000 --- a/examples/client/console.cpp +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||
8 | * later version accepted by the membership of KDE e.V. (or its | ||
9 | * successor approved by the membership of KDE e.V.), which shall | ||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | * | ||
12 | * This library is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | ||
20 | |||
21 | #include "console.h" | ||
22 | |||
23 | #include <QFontDatabase> | ||
24 | #include <QLabel> | ||
25 | #include <QTextBrowser> | ||
26 | #include <QVBoxLayout> | ||
27 | |||
28 | static Console *s_console = 0; | ||
29 | |||
30 | Console *Console::main() | ||
31 | { | ||
32 | if (!s_console) { | ||
33 | s_console = new Console(QString()); | ||
34 | } | ||
35 | return s_console; | ||
36 | } | ||
37 | |||
38 | Console::Console(const QString &title) | ||
39 | : QWidget(0) | ||
40 | { | ||
41 | if (!s_console) { | ||
42 | s_console = this; | ||
43 | } | ||
44 | |||
45 | resize(1000, 1500); | ||
46 | |||
47 | QVBoxLayout *topLayout = new QVBoxLayout(this); | ||
48 | |||
49 | QLabel *titleLabel = new QLabel(this); | ||
50 | titleLabel->setText(title); | ||
51 | QFont font = titleLabel->font(); | ||
52 | font.setWeight(QFont::Bold); | ||
53 | titleLabel->setFont(font); | ||
54 | titleLabel->setAlignment(Qt::AlignCenter); | ||
55 | |||
56 | QFont consoleFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); | ||
57 | consoleFont.setPointSize(7); | ||
58 | m_textDisplay = new QTextBrowser(this); | ||
59 | m_textDisplay->document()->setDefaultFont(consoleFont); | ||
60 | topLayout->addWidget(titleLabel); | ||
61 | topLayout->addWidget(m_textDisplay, 10); | ||
62 | |||
63 | show(); | ||
64 | m_timestamper.start(); | ||
65 | } | ||
66 | |||
67 | Console::~Console() | ||
68 | { | ||
69 | |||
70 | } | ||
71 | |||
72 | void Console::log(const QString &message) | ||
73 | { | ||
74 | m_textDisplay->append(QString::number(m_timestamper.elapsed()).rightJustified(6) + ": " + message); | ||
75 | } | ||
76 | |||
diff --git a/examples/client/console.h b/examples/client/console.h deleted file mode 100644 index a6fef01..0000000 --- a/examples/client/console.h +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||
8 | * later version accepted by the membership of KDE e.V. (or its | ||
9 | * successor approved by the membership of KDE e.V.), which shall | ||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | * | ||
12 | * This library is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | ||
20 | |||
21 | #pragma once | ||
22 | |||
23 | #include <QTime> | ||
24 | #include <QWidget> | ||
25 | |||
26 | class QTextBrowser; | ||
27 | |||
28 | class Console : public QWidget | ||
29 | { | ||
30 | Q_OBJECT | ||
31 | public: | ||
32 | static Console *main(); | ||
33 | Console(const QString &title); | ||
34 | ~Console(); | ||
35 | |||
36 | void log(const QString &message); | ||
37 | |||
38 | private: | ||
39 | QTextBrowser *m_textDisplay; | ||
40 | QTime m_timestamper; | ||
41 | static Console *s_output; | ||
42 | }; | ||
diff --git a/examples/client/main.cpp b/examples/client/main.cpp deleted file mode 100644 index f4b472f..0000000 --- a/examples/client/main.cpp +++ /dev/null | |||
@@ -1,222 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #include <QApplication> | ||
21 | #include <QCommandLineParser> | ||
22 | #include <QCommandLineOption> | ||
23 | #include <QTime> | ||
24 | |||
25 | #include "common/store.h" | ||
26 | #include "common/log.h" | ||
27 | |||
28 | #include <QWidget> | ||
29 | #include <QTreeView> | ||
30 | #include <QVBoxLayout> | ||
31 | #include <QLabel> | ||
32 | #include <QPushButton> | ||
33 | #include <QItemSelectionModel> | ||
34 | #include <iostream> | ||
35 | |||
36 | /** | ||
37 | * A small abstraction layer to use the sink store with the type available as string. | ||
38 | */ | ||
39 | class StoreBase { | ||
40 | public: | ||
41 | virtual ~StoreBase(){}; | ||
42 | virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() = 0; | ||
43 | virtual Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) = 0; | ||
44 | virtual KAsync::Job<void> create(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; | ||
45 | virtual KAsync::Job<void> modify(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; | ||
46 | virtual KAsync::Job<void> remove(const Sink::ApplicationDomain::ApplicationDomainType &type) = 0; | ||
47 | virtual QSharedPointer<QAbstractItemModel> loadModel(const Sink::Query &query) = 0; | ||
48 | }; | ||
49 | |||
50 | template <typename T> | ||
51 | class Store : public StoreBase { | ||
52 | public: | ||
53 | Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject() Q_DECL_OVERRIDE { | ||
54 | return T::Ptr::create(); | ||
55 | } | ||
56 | |||
57 | Sink::ApplicationDomain::ApplicationDomainType::Ptr getObject(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier = QByteArray()) Q_DECL_OVERRIDE { | ||
58 | return T::Ptr::create(resourceInstanceIdentifier, identifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
59 | } | ||
60 | |||
61 | KAsync::Job<void> create(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { | ||
62 | return Sink::Store::create<T>(*static_cast<const T*>(&type)); | ||
63 | } | ||
64 | |||
65 | KAsync::Job<void> modify(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { | ||
66 | return Sink::Store::modify<T>(*static_cast<const T*>(&type)); | ||
67 | } | ||
68 | |||
69 | KAsync::Job<void> remove(const Sink::ApplicationDomain::ApplicationDomainType &type) Q_DECL_OVERRIDE { | ||
70 | return Sink::Store::remove<T>(*static_cast<const T*>(&type)); | ||
71 | } | ||
72 | |||
73 | QSharedPointer<QAbstractItemModel> loadModel(const Sink::Query &query) Q_DECL_OVERRIDE { | ||
74 | return Sink::Store::loadModel<T>(query); | ||
75 | } | ||
76 | }; | ||
77 | |||
78 | StoreBase& getStore(const QString &type) | ||
79 | { | ||
80 | if (type == "folder") { | ||
81 | static Store<Sink::ApplicationDomain::Folder> store; | ||
82 | return store; | ||
83 | } else if (type == "mail") { | ||
84 | static Store<Sink::ApplicationDomain::Mail> store; | ||
85 | return store; | ||
86 | } else if (type == "event") { | ||
87 | static Store<Sink::ApplicationDomain::Event> store; | ||
88 | return store; | ||
89 | } else if (type == "resource") { | ||
90 | static Store<Sink::ApplicationDomain::SinkResource> store; | ||
91 | return store; | ||
92 | } | ||
93 | Q_ASSERT(false); | ||
94 | qWarning() << "Trying to get a store that doesn't exist, falling back to event"; | ||
95 | static Store<Sink::ApplicationDomain::Event> store; | ||
96 | return store; | ||
97 | } | ||
98 | |||
99 | template <typename T> | ||
100 | class View : public QWidget | ||
101 | { | ||
102 | public: | ||
103 | View(QAbstractItemModel *model) | ||
104 | : QWidget() | ||
105 | { | ||
106 | auto modelView = new QTreeView(this); | ||
107 | modelView->setModel(model); | ||
108 | resize(1000, 1500); | ||
109 | |||
110 | auto topLayout = new QVBoxLayout(this); | ||
111 | |||
112 | auto titleLabel = new QLabel(this); | ||
113 | titleLabel->setText("Demo"); | ||
114 | auto font = titleLabel->font(); | ||
115 | font.setWeight(QFont::Bold); | ||
116 | titleLabel->setFont(font); | ||
117 | titleLabel->setAlignment(Qt::AlignCenter); | ||
118 | |||
119 | auto syncButton = new QPushButton(this); | ||
120 | syncButton->setText("Synchronize!"); | ||
121 | QObject::connect(syncButton, &QPushButton::pressed, []() { | ||
122 | Sink::Query query; | ||
123 | query.resources << "sink.dummy.instance1"; | ||
124 | Sink::Store::synchronize(query).exec(); | ||
125 | }); | ||
126 | |||
127 | auto removeButton = new QPushButton(this); | ||
128 | removeButton->setText("Remove"); | ||
129 | QObject::connect(removeButton, &QPushButton::pressed, [modelView]() { | ||
130 | for (auto index : modelView->selectionModel()->selectedIndexes()) { | ||
131 | auto object = index.data(Sink::Store::DomainObjectRole).value<typename T::Ptr>(); | ||
132 | Sink::Store::remove(*object).exec(); | ||
133 | } | ||
134 | }); | ||
135 | |||
136 | topLayout->addWidget(titleLabel); | ||
137 | topLayout->addWidget(syncButton); | ||
138 | topLayout->addWidget(removeButton); | ||
139 | topLayout->addWidget(modelView, 10); | ||
140 | |||
141 | show(); | ||
142 | } | ||
143 | |||
144 | }; | ||
145 | |||
146 | static QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Sink::Query query) | ||
147 | { | ||
148 | QTime time; | ||
149 | time.start(); | ||
150 | if (type == "folder") { | ||
151 | query.requestedProperties << "name" << "parent"; | ||
152 | } else if (type == "mail") { | ||
153 | query.requestedProperties << "subject" << "folder" << "date"; | ||
154 | } else if (type == "event") { | ||
155 | query.requestedProperties << "summary"; | ||
156 | } else if (type == "resource") { | ||
157 | query.requestedProperties << "type"; | ||
158 | } | ||
159 | auto model = getStore(type).loadModel(query); | ||
160 | qDebug() << "Folder type " << type; | ||
161 | qDebug() << "Loaded model in " << time.elapsed() << " ms"; | ||
162 | Q_ASSERT(model); | ||
163 | return model; | ||
164 | } | ||
165 | |||
166 | QMap<QString, QString> consumeMap(QList<QString> &list) | ||
167 | { | ||
168 | QMap<QString, QString> map; | ||
169 | while(list.size() >= 2) { | ||
170 | map.insert(list.at(0), list.at(1)); | ||
171 | list = list.mid(2); | ||
172 | } | ||
173 | return map; | ||
174 | } | ||
175 | |||
176 | int main(int argc, char *argv[]) | ||
177 | { | ||
178 | QApplication app(argc, argv); | ||
179 | |||
180 | QCommandLineParser cliOptions; | ||
181 | cliOptions.addPositionalArgument(QObject::tr("[type]"), | ||
182 | QObject::tr("A type to work with")); | ||
183 | cliOptions.addPositionalArgument(QObject::tr("[resource]"), | ||
184 | QObject::tr("A resource to connect to")); | ||
185 | cliOptions.addOption(QCommandLineOption("debuglevel", "A debuglevel from 0-6", "debuglevel")); | ||
186 | cliOptions.addHelpOption(); | ||
187 | cliOptions.process(app); | ||
188 | QStringList args = cliOptions.positionalArguments(); | ||
189 | |||
190 | if (cliOptions.isSet("debuglevel")) { | ||
191 | Sink::Log::setDebugOutputLevel(static_cast<Sink::Log::DebugLevel>(cliOptions.value("debuglevel").toInt())); | ||
192 | } | ||
193 | |||
194 | auto type = !args.isEmpty() ? args.takeFirst() : QByteArray(); | ||
195 | auto resources = args; | ||
196 | |||
197 | Sink::Query query; | ||
198 | for (const auto &res : resources) { | ||
199 | query.resources << res.toLatin1(); | ||
200 | } | ||
201 | query.liveQuery = true; | ||
202 | if (type == "folder") { | ||
203 | query.parentProperty = "parent"; | ||
204 | } | ||
205 | auto model = loadModel(type, query); | ||
206 | if (type == "folder") { | ||
207 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { | ||
208 | for (int i = start; i <= end; i++) { | ||
209 | model->fetchMore(model->index(i, 0, index)); | ||
210 | } | ||
211 | }); | ||
212 | auto view = QSharedPointer<View<Sink::ApplicationDomain::Folder> >::create(model.data()); | ||
213 | app.exec(); | ||
214 | } else if (type == "mail") { | ||
215 | auto view = QSharedPointer<View<Sink::ApplicationDomain::Mail> >::create(model.data()); | ||
216 | app.exec(); | ||
217 | } else if (type == "event") { | ||
218 | auto view = QSharedPointer<View<Sink::ApplicationDomain::Event> >::create(model.data()); | ||
219 | app.exec(); | ||
220 | } | ||
221 | return 0; | ||
222 | } | ||
diff --git a/examples/imapresource/tests/imapmailsyncbenchmark.cpp b/examples/imapresource/tests/imapmailsyncbenchmark.cpp index 1cf8861..824b769 100644 --- a/examples/imapresource/tests/imapmailsyncbenchmark.cpp +++ b/examples/imapresource/tests/imapmailsyncbenchmark.cpp | |||
@@ -107,7 +107,7 @@ private slots: | |||
107 | void testSync() | 107 | void testSync() |
108 | { | 108 | { |
109 | Sink::Query query; | 109 | Sink::Query query; |
110 | query.resources << mResourceInstanceIdentifier; | 110 | query.resourceFilter(mResourceInstanceIdentifier); |
111 | query.request<Folder::Name>().request<Folder::SpecialPurpose>(); | 111 | query.request<Folder::Name>().request<Folder::SpecialPurpose>(); |
112 | 112 | ||
113 | QTime time; | 113 | QTime time; |
@@ -117,7 +117,7 @@ private slots: | |||
117 | VERIFYEXEC(Store::synchronize(query)); | 117 | VERIFYEXEC(Store::synchronize(query)); |
118 | SinkLog() << "Sync took: " << Sink::Log::TraceTime(time.elapsed()); | 118 | SinkLog() << "Sync took: " << Sink::Log::TraceTime(time.elapsed()); |
119 | 119 | ||
120 | VERIFYEXEC(ResourceControl::flushMessageQueue(query.resources)); | 120 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); |
121 | SinkLog() << "Total took: " << Sink::Log::TraceTime(time.elapsed()); | 121 | SinkLog() << "Total took: " << Sink::Log::TraceTime(time.elapsed()); |
122 | 122 | ||
123 | time.start(); | 123 | time.start(); |
@@ -125,7 +125,7 @@ private slots: | |||
125 | VERIFYEXEC(Store::synchronize(query)); | 125 | VERIFYEXEC(Store::synchronize(query)); |
126 | SinkLog() << "ReSync took: " << Sink::Log::TraceTime(time.elapsed()); | 126 | SinkLog() << "ReSync took: " << Sink::Log::TraceTime(time.elapsed()); |
127 | 127 | ||
128 | VERIFYEXEC(ResourceControl::flushMessageQueue(query.resources)); | 128 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); |
129 | SinkLog() << "Total resync took: " << Sink::Log::TraceTime(time.elapsed()); | 129 | SinkLog() << "Total resync took: " << Sink::Log::TraceTime(time.elapsed()); |
130 | } | 130 | } |
131 | }; | 131 | }; |
diff --git a/examples/mailtransportresource/tests/mailtransporttest.cpp b/examples/mailtransportresource/tests/mailtransporttest.cpp index fdd591b..e44aa23 100644 --- a/examples/mailtransportresource/tests/mailtransporttest.cpp +++ b/examples/mailtransportresource/tests/mailtransporttest.cpp | |||
@@ -61,10 +61,10 @@ private slots: | |||
61 | 61 | ||
62 | VERIFYEXEC(Store::create(mail)); | 62 | VERIFYEXEC(Store::create(mail)); |
63 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); | 63 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); |
64 | VERIFYEXEC(Store::synchronize(Query::ResourceFilter(mResourceInstanceIdentifier))); | 64 | VERIFYEXEC(Store::synchronize(Query().resourceFilter(mResourceInstanceIdentifier))); |
65 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true))); | 65 | VERIFYEXEC(ResourceControl::inspect<ApplicationDomain::Mail>(ResourceControl::Inspection::ExistenceInspection(mail, true))); |
66 | 66 | ||
67 | auto sentMail = Store::readOne<ApplicationDomain::Mail>(Query::IdentityFilter(mail).request<Mail::Sent>().request<Mail::Subject>()); | 67 | auto sentMail = Store::readOne<ApplicationDomain::Mail>(Query(mail).request<Mail::Sent>().request<Mail::Subject>()); |
68 | QVERIFY(sentMail.getSent()); | 68 | QVERIFY(sentMail.getSent()); |
69 | QVERIFY(!sentMail.getSubject().isEmpty()); | 69 | QVERIFY(!sentMail.getSubject().isEmpty()); |
70 | } | 70 | } |