diff options
-rw-r--r-- | lib/connection.cpp | 13 | ||||
-rw-r--r-- | lib/connection.h | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 50e31d52..d53c308f 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -57,6 +57,7 @@ #include <QtCore/QElapsedTimer> #include <QtCore/QFile> #include <QtCore/QMimeDatabase> +#include <QtCore/QTimer> #include <QtCore/QRegularExpression> #include <QtCore/QStandardPaths> #include <QtCore/QStringBuilder> @@ -506,21 +507,23 @@ void Connection::sync(int timeout) }); } -void Connection::syncLoop(int timeout) +void Connection::syncLoop(int timeout, int msecBetween) { if (d->syncLoopConnection && d->syncTimeout == timeout) { qCInfo(MAIN) << "Attempt to run sync loop but there's one already " "running; nothing will be done"; return; } - std::swap(d->syncTimeout, timeout); + std::swap(d->syncTimeout, timeout); // swap() is for the nice log below if (d->syncLoopConnection) { qCInfo(MAIN) << "Timeout for next syncs changed from" << timeout << "to" << d->syncTimeout; } else { - d->syncLoopConnection = connect(this, &Connection::syncDone, - this, &Connection::syncLoopIteration, - Qt::QueuedConnection); + d->syncLoopConnection = + connect(this, &Connection::syncDone, this, [this, msecBetween] { + QTimer::singleShot(msecBetween, this, + &Connection::syncLoopIteration); + }); syncLoopIteration(); // initial sync to start the loop } } diff --git a/lib/connection.h b/lib/connection.h index d5fa9eac..fb76cf3d 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -544,7 +544,7 @@ public slots: void logout(); void sync(int timeout = -1); - void syncLoop(int timeout = -1); + void syncLoop(int timeout = -1, int msecBetween = 500); void stopSync(); QString nextBatchToken() const; |