From 855a878bcc124f8949586b3656dcc6e545e18dc0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 2 Jun 2016 13:35:40 +0200 Subject: Always return jobs, not futures. Otherwise the calls are not composable. --- examples/imapresource/imapresource.cpp | 5 +++-- examples/imapresource/imapserverproxy.cpp | 19 +++++++++++++------ examples/imapresource/imapserverproxy.h | 5 +++-- examples/imapresource/tests/imapserverproxytest.cpp | 9 ++------- 4 files changed, 21 insertions(+), 17 deletions(-) (limited to 'examples/imapresource') diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 5e5aae6..2bb28e7 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp @@ -54,6 +54,7 @@ #define DEBUG_AREA "resource.imap" using namespace Imap; +using namespace Sink; class MailPropertyExtractor : public Sink::Preprocessor { @@ -273,7 +274,7 @@ public: commitSync(); folderList << folders; - }); + }).exec(); folderFuture.waitForFinished(); if (folderFuture.errorCode()) { Warning() << "Folder sync failed."; @@ -293,7 +294,7 @@ public: synchronizeMails(folder.normalizedPath(), messages); commit(); commitSync(); - }); + }).exec(); messagesFuture.waitForFinished(); if (messagesFuture.errorCode()) { future.setError(1, "Folder sync failed: " + folder.normalizedPath()); 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 @@ #include #include #include +#include #include #include #include @@ -113,6 +114,14 @@ KAsync::Job ImapServerProxy::create(const QString &mailbox) return runJob(create); } +KAsync::Job ImapServerProxy::rename(const QString &mailbox, const QString &newMailbox) +{ + auto rename = new KIMAP::RenameJob(mSession); + rename->setSourceMailBox(mailbox); + rename->setDestinationMailBox(newMailbox); + return runJob(rename); +} + KAsync::Job ImapServerProxy::remove(const QString &mailbox) { auto job = new KIMAP::DeleteJob(mSession); @@ -216,10 +225,10 @@ KAsync::Job ImapServerProxy::remove(const QString &mailbox, const QByteArr return select(mailbox).then(store(set, QByteArrayList() << Flags::Deleted)).then(expunge()); } -KAsync::Future ImapServerProxy::fetchFolders(std::function &)> callback) +KAsync::Job ImapServerProxy::fetchFolders(std::function &)> callback) { Trace() << "Fetching folders"; - auto job = list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList &mailboxes, const QList > &flags){ + return list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList &mailboxes, const QList > &flags){ QVector list; for (const auto &mailbox : mailboxes) { Trace() << "Found mailbox: " << mailbox.name; @@ -227,13 +236,12 @@ KAsync::Future ImapServerProxy::fetchFolders(std::function ImapServerProxy::fetchMessages(const Folder &folder, std::function &)> callback) +KAsync::Job ImapServerProxy::fetchMessages(const Folder &folder, std::function &)> callback) { Q_ASSERT(!mSeparatorCharacter.isNull()); - auto job = select(folder.pathParts.join(mSeparatorCharacter)).then>([this, callback, folder]() -> KAsync::Job { + return select(folder.pathParts.join(mSeparatorCharacter)).then>([this, callback, folder]() -> KAsync::Job { return fetchHeaders(folder.pathParts.join(mSeparatorCharacter)).then, QList>([this, callback](const QList &uidsToFetch){ Trace() << "Uids to fetch: " << uidsToFetch; if (uidsToFetch.isEmpty()) { @@ -251,5 +259,4 @@ KAsync::Future ImapServerProxy::fetchMessages(const Folder &folder, std::f }); }); - return job.exec(); } diff --git a/examples/imapresource/imapserverproxy.h b/examples/imapresource/imapserverproxy.h index a5a1296..cf315df 100644 --- a/examples/imapresource/imapserverproxy.h +++ b/examples/imapresource/imapserverproxy.h @@ -69,6 +69,7 @@ public: KAsync::Job append(const QString &mailbox, const QByteArray &content, const QList &flags = QList(), const QDateTime &internalDate = QDateTime()); KAsync::Job store(const KIMAP::ImapSet &set, const QList &flags); KAsync::Job create(const QString &mailbox); + KAsync::Job rename(const QString &mailbox, const QString &newMailbox); KAsync::Job remove(const QString &mailbox); KAsync::Job expunge(); @@ -87,8 +88,8 @@ public: KAsync::Job> fetchHeaders(const QString &mailbox); KAsync::Job remove(const QString &mailbox, const QByteArray &imapSet); - KAsync::Future fetchFolders(std::function &)> callback); - KAsync::Future fetchMessages(const Folder &folder, std::function &)> callback); + KAsync::Job fetchFolders(std::function &)> callback); + KAsync::Job fetchMessages(const Folder &folder, std::function &)> callback); }; } diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp index b30cc33..3761dac 100644 --- a/examples/imapresource/tests/imapserverproxytest.cpp +++ b/examples/imapresource/tests/imapserverproxytest.cpp @@ -80,18 +80,13 @@ private slots: { ImapServerProxy imap("localhost", 993); VERIFYEXEC(imap.login("doe", "doe")); - auto future = imap.fetchFolders([](const QVector &){}); - future.waitForFinished(); - QVERIFY(!future.errorCode()); + VERIFYEXEC(imap.fetchFolders([](const QVector &){})); } void testFetchFoldersFailure() { ImapServerProxy imap("foobar", 993); - auto future = imap.fetchFolders([](const QVector &){}); - auto future2 = future; - future2.waitForFinished(); - QVERIFY(future2.errorCode()); + VERIFYEXEC_FAIL(imap.fetchFolders([](const QVector &){})); } void testFetchMail() -- cgit v1.2.3