diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-02 13:35:40 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-02 13:35:40 +0200 |
commit | 855a878bcc124f8949586b3656dcc6e545e18dc0 (patch) | |
tree | 6497f1710ba3db8953d204032e5e8c14a239ad33 /examples/imapresource/imapserverproxy.cpp | |
parent | 64a1b21a7b11d640f0ebd37184aeb14a4d9e12db (diff) | |
download | sink-855a878bcc124f8949586b3656dcc6e545e18dc0.tar.gz sink-855a878bcc124f8949586b3656dcc6e545e18dc0.zip |
Always return jobs, not futures.
Otherwise the calls are not composable.
Diffstat (limited to 'examples/imapresource/imapserverproxy.cpp')
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index 58d2772..18b8dcf 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <KIMAP/KIMAP/SelectJob> | 24 | #include <KIMAP/KIMAP/SelectJob> |
25 | #include <KIMAP/KIMAP/AppendJob> | 25 | #include <KIMAP/KIMAP/AppendJob> |
26 | #include <KIMAP/KIMAP/CreateJob> | 26 | #include <KIMAP/KIMAP/CreateJob> |
27 | #include <KIMAP/KIMAP/RenameJob> | ||
27 | #include <KIMAP/KIMAP/DeleteJob> | 28 | #include <KIMAP/KIMAP/DeleteJob> |
28 | #include <KIMAP/KIMAP/StoreJob> | 29 | #include <KIMAP/KIMAP/StoreJob> |
29 | #include <KIMAP/KIMAP/ExpungeJob> | 30 | #include <KIMAP/KIMAP/ExpungeJob> |
@@ -113,6 +114,14 @@ KAsync::Job<void> ImapServerProxy::create(const QString &mailbox) | |||
113 | return runJob(create); | 114 | return runJob(create); |
114 | } | 115 | } |
115 | 116 | ||
117 | KAsync::Job<void> ImapServerProxy::rename(const QString &mailbox, const QString &newMailbox) | ||
118 | { | ||
119 | auto rename = new KIMAP::RenameJob(mSession); | ||
120 | rename->setSourceMailBox(mailbox); | ||
121 | rename->setDestinationMailBox(newMailbox); | ||
122 | return runJob(rename); | ||
123 | } | ||
124 | |||
116 | KAsync::Job<void> ImapServerProxy::remove(const QString &mailbox) | 125 | KAsync::Job<void> ImapServerProxy::remove(const QString &mailbox) |
117 | { | 126 | { |
118 | auto job = new KIMAP::DeleteJob(mSession); | 127 | auto job = new KIMAP::DeleteJob(mSession); |
@@ -216,10 +225,10 @@ KAsync::Job<void> ImapServerProxy::remove(const QString &mailbox, const QByteArr | |||
216 | return select(mailbox).then<void>(store(set, QByteArrayList() << Flags::Deleted)).then<void>(expunge()); | 225 | return select(mailbox).then<void>(store(set, QByteArrayList() << Flags::Deleted)).then<void>(expunge()); |
217 | } | 226 | } |
218 | 227 | ||
219 | KAsync::Future<void> ImapServerProxy::fetchFolders(std::function<void(const QVector<Folder> &)> callback) | 228 | KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const QVector<Folder> &)> callback) |
220 | { | 229 | { |
221 | Trace() << "Fetching folders"; | 230 | Trace() << "Fetching folders"; |
222 | auto job = list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList<KIMAP::MailBoxDescriptor> &mailboxes, const QList<QList<QByteArray> > &flags){ | 231 | return list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList<KIMAP::MailBoxDescriptor> &mailboxes, const QList<QList<QByteArray> > &flags){ |
223 | QVector<Folder> list; | 232 | QVector<Folder> list; |
224 | for (const auto &mailbox : mailboxes) { | 233 | for (const auto &mailbox : mailboxes) { |
225 | Trace() << "Found mailbox: " << mailbox.name; | 234 | Trace() << "Found mailbox: " << mailbox.name; |
@@ -227,13 +236,12 @@ KAsync::Future<void> ImapServerProxy::fetchFolders(std::function<void(const QVec | |||
227 | } | 236 | } |
228 | callback(list); | 237 | callback(list); |
229 | }); | 238 | }); |
230 | return job.exec(); | ||
231 | } | 239 | } |
232 | 240 | ||
233 | KAsync::Future<void> ImapServerProxy::fetchMessages(const Folder &folder, std::function<void(const QVector<Message> &)> callback) | 241 | KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, std::function<void(const QVector<Message> &)> callback) |
234 | { | 242 | { |
235 | Q_ASSERT(!mSeparatorCharacter.isNull()); | 243 | Q_ASSERT(!mSeparatorCharacter.isNull()); |
236 | auto job = select(folder.pathParts.join(mSeparatorCharacter)).then<void, KAsync::Job<void>>([this, callback, folder]() -> KAsync::Job<void> { | 244 | return select(folder.pathParts.join(mSeparatorCharacter)).then<void, KAsync::Job<void>>([this, callback, folder]() -> KAsync::Job<void> { |
237 | return fetchHeaders(folder.pathParts.join(mSeparatorCharacter)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback](const QList<qint64> &uidsToFetch){ | 245 | return fetchHeaders(folder.pathParts.join(mSeparatorCharacter)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback](const QList<qint64> &uidsToFetch){ |
238 | Trace() << "Uids to fetch: " << uidsToFetch; | 246 | Trace() << "Uids to fetch: " << uidsToFetch; |
239 | if (uidsToFetch.isEmpty()) { | 247 | if (uidsToFetch.isEmpty()) { |
@@ -251,5 +259,4 @@ KAsync::Future<void> ImapServerProxy::fetchMessages(const Folder &folder, std::f | |||
251 | }); | 259 | }); |
252 | 260 | ||
253 | }); | 261 | }); |
254 | return job.exec(); | ||
255 | } | 262 | } |