Commit 520849ae authored by Shashwat Jolly's avatar Shashwat Jolly
Browse files

Use QFutureWatcher in EntriesFetchJob and JournalsFetchJob

Earlier, emitResult() was being called from a different thread than the main UI thread. Now, we are waiting for fetching to be done in the same thread, after which emitResult() is called.
parent 923149c8
Pipeline #33071 passed with stage
in 34 minutes and 4 seconds
......@@ -20,7 +20,13 @@ EntriesFetchJob::EntriesFetchJob(const EteSync *client, const Akonadi::Collectio
void EntriesFetchJob::start()
{
QtConcurrent::run(this, &EntriesFetchJob::fetchEntries);
QFutureWatcher<void> *watcher = new QFutureWatcher<void>(this);
connect(watcher, &QFutureWatcher<int>::finished, this, [this] {
qCDebug(ETESYNC_LOG) << "emitResult from EntriesFetchJob";
emitResult();
});
QFuture<void> fetchEntriesFuture = QtConcurrent::run(this, &EntriesFetchJob::fetchEntries);
watcher->setFuture(fetchEntriesFuture);
}
void EntriesFetchJob::fetchEntries()
......@@ -40,7 +46,7 @@ void EntriesFetchJob::fetchEntries()
CharPtr err(etesync_get_error_message());
setErrorText(QStringFromCharPtr(err));
}
emitResult();
qCDebug(ETESYNC_LOG) << "Entries fetched";
}
EntriesFetchJob::Status EntriesFetchJob::fetchNextBatch()
......
......@@ -27,7 +27,7 @@ namespace EteSyncAPI {
return std::move(mEntries);
}
QString getPrevUid()
QString getPrevUid() const
{
return mPrevUid;
}
......
......@@ -13,7 +13,7 @@ QString QStringFromCharPtr(const CharPtr &str)
if (str.get() == nullptr) {
return QString();
}
QString ret = QString::fromUtf8(str.get());
const QString ret = QString::fromUtf8(str.get());
return ret;
}
......
......@@ -8,6 +8,8 @@
#include <QtConcurrent>
#include "etesync_debug.h"
using namespace EteSyncAPI;
JournalsFetchJob::JournalsFetchJob(EteSync *client, QObject *parent)
......@@ -17,7 +19,13 @@ JournalsFetchJob::JournalsFetchJob(EteSync *client, QObject *parent)
void JournalsFetchJob::start()
{
QtConcurrent::run(this, &JournalsFetchJob::fetchJournals);
QFutureWatcher<void> *watcher = new QFutureWatcher<void>(this);
connect(watcher, &QFutureWatcher<void>::finished, this, [this] {
qCDebug(ETESYNC_LOG) << "emitResult from JournalsFetchJob";
emitResult();
});
QFuture<void> fetchJournalsFuture = QtConcurrent::run(this, &JournalsFetchJob::fetchJournals);
watcher->setFuture(fetchJournalsFuture);
}
void JournalsFetchJob::fetchJournals()
......@@ -29,5 +37,5 @@ void JournalsFetchJob::fetchJournals()
CharPtr err(etesync_get_error_message());
setErrorText(QStringFromCharPtr(err));
}
emitResult();
qCDebug(ETESYNC_LOG) << "Journals fetched";
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment