diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-27 02:26:47 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-15 16:14:19 +0200 |
commit | 26816c21f60450e461a5b6ef4ef740f6070ce278 (patch) | |
tree | 55e8aee03e094abf702438e6cd26233047345e70 /examples/imapresource/imapserverproxy.cpp | |
parent | 9a9bb39f7641a818434cafa0dae0c8aa47124c0b (diff) | |
download | sink-26816c21f60450e461a5b6ef4ef740f6070ce278.tar.gz sink-26816c21f60450e461a5b6ef4ef740f6070ce278.zip |
Ported to the kasync revamp
Diffstat (limited to 'examples/imapresource/imapserverproxy.cpp')
-rw-r--r-- | examples/imapresource/imapserverproxy.cpp | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp index a3d8d16..94367d8 100644 --- a/examples/imapresource/imapserverproxy.cpp +++ b/examples/imapresource/imapserverproxy.cpp | |||
@@ -161,7 +161,7 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString | |||
161 | auto namespaceJob = new KIMAP::NamespaceJob(mSession); | 161 | auto namespaceJob = new KIMAP::NamespaceJob(mSession); |
162 | 162 | ||
163 | //FIXME The ping is only required because the login job doesn't fail after the configured timeout | 163 | //FIXME The ping is only required because the login job doesn't fail after the configured timeout |
164 | return ping().then(runJob(loginJob)).then(runJob(capabilitiesJob)).then<void>([this](){ | 164 | return ping().then(runJob(loginJob)).then(runJob(capabilitiesJob)).syncThen<void>([this](){ |
165 | SinkTrace() << "Supported capabilities: " << mCapabilities; | 165 | SinkTrace() << "Supported capabilities: " << mCapabilities; |
166 | QStringList requiredExtensions = QStringList() << "UIDPLUS" << "NAMESPACE"; | 166 | QStringList requiredExtensions = QStringList() << "UIDPLUS" << "NAMESPACE"; |
167 | for (const auto &requiredExtension : requiredExtensions) { | 167 | for (const auto &requiredExtension : requiredExtensions) { |
@@ -170,7 +170,7 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString | |||
170 | //TODO fail the job | 170 | //TODO fail the job |
171 | } | 171 | } |
172 | } | 172 | } |
173 | }).then(runJob(namespaceJob)).then<void>([this, namespaceJob](){ | 173 | }).then(runJob(namespaceJob)).syncThen<void>([this, namespaceJob] { |
174 | for (const auto &ns :namespaceJob->personalNamespaces()) { | 174 | for (const auto &ns :namespaceJob->personalNamespaces()) { |
175 | mPersonalNamespaces << ns.name; | 175 | mPersonalNamespaces << ns.name; |
176 | mPersonalNamespaceSeparator = ns.separator; | 176 | mPersonalNamespaceSeparator = ns.separator; |
@@ -363,7 +363,7 @@ KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox, | |||
363 | list->append(uids.value(id)); | 363 | list->append(uids.value(id)); |
364 | } | 364 | } |
365 | }) | 365 | }) |
366 | .then<QList<qint64>>([list](){ | 366 | .syncThen<QList<qint64>>([list](){ |
367 | return *list; | 367 | return *list; |
368 | }); | 368 | }); |
369 | } | 369 | } |
@@ -402,35 +402,34 @@ KAsync::Job<void> ImapServerProxy::move(const QString &mailbox, const KIMAP::Ima | |||
402 | 402 | ||
403 | KAsync::Job<QString> ImapServerProxy::createSubfolder(const QString &parentMailbox, const QString &folderName) | 403 | KAsync::Job<QString> ImapServerProxy::createSubfolder(const QString &parentMailbox, const QString &folderName) |
404 | { | 404 | { |
405 | auto folder = QSharedPointer<QString>::create(); | 405 | return KAsync::start<QString>([this, parentMailbox, folderName]() { |
406 | return KAsync::start<void, KAsync::Job<void>>([this, parentMailbox, folderName, folder]() { | ||
407 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); | 406 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); |
407 | auto folder = QSharedPointer<QString>::create(); | ||
408 | if (parentMailbox.isEmpty()) { | 408 | if (parentMailbox.isEmpty()) { |
409 | *folder = mPersonalNamespaces.toList().first() + folderName; | 409 | *folder = mPersonalNamespaces.toList().first() + folderName; |
410 | } else { | 410 | } else { |
411 | *folder = parentMailbox + mPersonalNamespaceSeparator + folderName; | 411 | *folder = parentMailbox + mPersonalNamespaceSeparator + folderName; |
412 | } | 412 | } |
413 | SinkTrace() << "Creating subfolder: " << *folder; | 413 | SinkTrace() << "Creating subfolder: " << *folder; |
414 | return create(*folder); | 414 | return create(*folder) |
415 | }) | 415 | .syncThen<QString>([=]() { |
416 | .then<QString>([=]() { | 416 | return *folder; |
417 | return *folder; | 417 | }); |
418 | }); | 418 | }); |
419 | } | 419 | } |
420 | 420 | ||
421 | KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox, const QString &newName) | 421 | KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox, const QString &newName) |
422 | { | 422 | { |
423 | auto folder = QSharedPointer<QString>::create(); | 423 | return KAsync::start<QString>([this, oldMailbox, newName] { |
424 | return KAsync::start<void, KAsync::Job<void>>([this, oldMailbox, newName, folder]() { | ||
425 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); | 424 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); |
426 | auto parts = oldMailbox.split(mPersonalNamespaceSeparator); | 425 | auto parts = oldMailbox.split(mPersonalNamespaceSeparator); |
427 | parts.removeLast(); | 426 | parts.removeLast(); |
428 | *folder = parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName; | 427 | auto folder = QSharedPointer<QString>::create(parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName); |
429 | SinkTrace() << "Renaming subfolder: " << oldMailbox << *folder; | 428 | SinkTrace() << "Renaming subfolder: " << oldMailbox << *folder; |
430 | return rename(oldMailbox, *folder); | 429 | return rename(oldMailbox, *folder) |
431 | }) | 430 | .syncThen<QString>([=]() { |
432 | .then<QString>([=]() { | 431 | return *folder; |
433 | return *folder; | 432 | }); |
434 | }); | 433 | }); |
435 | } | 434 | } |
436 | 435 | ||
@@ -461,7 +460,7 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, qint64 ui | |||
461 | auto time = QSharedPointer<QTime>::create(); | 460 | auto time = QSharedPointer<QTime>::create(); |
462 | time->start(); | 461 | time->start(); |
463 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); | 462 | Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); |
464 | return select(mailboxFromFolder(folder)).then<void, KAsync::Job<void>, SelectResult>([this, callback, folder, time, progress, uidNext](const SelectResult &selectResult) -> KAsync::Job<void> { | 463 | return select(mailboxFromFolder(folder)).then<void, SelectResult>([this, callback, folder, time, progress, uidNext](const SelectResult &selectResult) -> KAsync::Job<void> { |
465 | 464 | ||
466 | SinkLog() << "UIDNEXT " << selectResult.uidNext << uidNext; | 465 | SinkLog() << "UIDNEXT " << selectResult.uidNext << uidNext; |
467 | if (selectResult.uidNext == (uidNext + 1)) { | 466 | if (selectResult.uidNext == (uidNext + 1)) { |
@@ -469,7 +468,7 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, qint64 ui | |||
469 | return KAsync::null<void>(); | 468 | return KAsync::null<void>(); |
470 | } | 469 | } |
471 | 470 | ||
472 | return fetchHeaders(mailboxFromFolder(folder), (uidNext + 1)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback, time, progress](const QList<qint64> &uidsToFetch){ | 471 | return fetchHeaders(mailboxFromFolder(folder), (uidNext + 1)).then<void, QList<qint64>>([this, callback, time, progress](const QList<qint64> &uidsToFetch){ |
473 | SinkTrace() << "Fetched headers"; | 472 | SinkTrace() << "Fetched headers"; |
474 | SinkTrace() << " Total: " << uidsToFetch.size(); | 473 | SinkTrace() << " Total: " << uidsToFetch.size(); |
475 | SinkTrace() << " Uids to fetch: " << uidsToFetch; | 474 | SinkTrace() << " Uids to fetch: " << uidsToFetch; |