diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-08-29 09:36:36 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-15 16:14:19 +0200 |
commit | 8a0a4de6c51d5ef23ae86655a63536bd8386c575 (patch) | |
tree | 5f192e75c52cb61ed1c68ff53e34b553f802ec12 /examples/imapresource/imapresource.cpp | |
parent | fe6a1094ff67442e05b409bffedd6b3ca017a2c3 (diff) | |
download | sink-8a0a4de6c51d5ef23ae86655a63536bd8386c575.tar.gz sink-8a0a4de6c51d5ef23ae86655a63536bd8386c575.zip |
Made use of KAsync::Job::serialEach
Diffstat (limited to 'examples/imapresource/imapresource.cpp')
-rw-r--r-- | examples/imapresource/imapresource.cpp | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index da87bdb..aad7887 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -261,43 +261,37 @@ public: | |||
261 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE | 261 | KAsync::Job<void> synchronizeWithSource() Q_DECL_OVERRIDE |
262 | { | 262 | { |
263 | SinkLog() << " Synchronizing"; | 263 | SinkLog() << " Synchronizing"; |
264 | return KAsync::start<void>([this](KAsync::Future<void> future) { | 264 | return KAsync::start<void>([this]() { |
265 | SinkTrace() << "Connecting to:" << mServer << mPort; | 265 | SinkTrace() << "Connecting to:" << mServer << mPort; |
266 | SinkTrace() << "as:" << mUser; | 266 | SinkTrace() << "as:" << mUser; |
267 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); | 267 | auto imap = QSharedPointer<ImapServerProxy>::create(mServer, mPort); |
268 | auto loginFuture = imap->login(mUser, mPassword).exec(); | ||
269 | loginFuture.waitForFinished(); | ||
270 | if (loginFuture.errorCode()) { | ||
271 | SinkWarning() << "Login failed."; | ||
272 | future.setError(1, "Login failed"); | ||
273 | return; | ||
274 | } else { | ||
275 | SinkTrace() << "Login was successful"; | ||
276 | } | ||
277 | 268 | ||
278 | QVector<Folder> folderList; | 269 | return imap->login(mUser, mPassword) |
279 | auto folderFuture = imap->fetchFolders([this, &imap, &folderList](const QVector<Folder> &folders) { | 270 | .addToContext(imap) |
280 | synchronizeFolders(folders); | 271 | .onError([](const KAsync::Error &error) { |
281 | commit(); | 272 | SinkWarning() << "Login failed."; |
282 | folderList << folders; | 273 | }) |
283 | 274 | .then<QVector<Folder>>([this, imap]() { | |
284 | }).exec(); | 275 | auto folderList = QSharedPointer<QVector<Folder>>::create(); |
285 | folderFuture.waitForFinished(); | 276 | SinkLog() << "Login was successful"; |
286 | if (folderFuture.errorCode()) { | 277 | return imap->fetchFolders([this, &imap, folderList](const QVector<Folder> &folders) { |
287 | SinkWarning() << "Folder sync failed."; | 278 | synchronizeFolders(folders); |
288 | future.setError(1, "Folder list sync failed"); | 279 | commit(); |
289 | return; | 280 | *folderList << folders; |
290 | } else { | 281 | }) |
291 | SinkTrace() << "Folder sync was successful"; | 282 | .onError([](const KAsync::Error &error) { |
292 | } | 283 | SinkWarning() << "Folder list sync failed."; |
293 | 284 | }) | |
294 | for (const auto &folder : folderList) { | 285 | .syncThen<QVector<Folder>>([folderList]() { |
286 | return *folderList; | ||
287 | }); | ||
288 | }) | ||
289 | .serialEach<void>([this, imap](const Folder &folder) { | ||
295 | if (folder.noselect) { | 290 | if (folder.noselect) { |
296 | continue; | 291 | return KAsync::null<void>(); |
297 | } | 292 | } |
298 | synchronizeFolder(imap, folder).exec().waitForFinished(); | 293 | return synchronizeFolder(imap, folder); |
299 | } | 294 | }); |
300 | future.setFinished(); | ||
301 | }); | 295 | }); |
302 | } | 296 | } |
303 | 297 | ||