44#include < QCoreApplication>
55#include < QDir>
66#include < QFileInfo>
7- #include < QTimerEvent>
87#include < dialogmaster.h>
98#include " adminauthorization.h"
109#include " updatebutton.h"
@@ -205,47 +204,24 @@ bool UpdateController::cancelUpdate(int maxDelay)
205204
206205int UpdateController::scheduleUpdate (int delaySeconds, bool repeated, UpdateController::DisplayLevel displayLevel)
207206{
207+ if ((((qint64)delaySeconds) * 1000 ) > INT_MAX) {
208+ qCWarning (logQtAutoUpdater) << " delaySeconds to big to be converted to msecs" ;
209+ return 0 ;
210+ }
208211 Q_D (UpdateController);
209- int id = this ->startTimer (delaySeconds * 1000 , Qt::VeryCoarseTimer);
210- if (id != 0 )
211- d->updateTasks .insert (id, {displayLevel, repeated});
212- return id;
212+ return d->scheduler ->startSchedule (delaySeconds * 1000 , repeated, QVariant::fromValue (displayLevel));
213213}
214214
215215int UpdateController::scheduleUpdate (const QDateTime &when, UpdateController::DisplayLevel displayLevel)
216- {
217- qint64 delta = QDateTime::currentDateTime ().secsTo (when);
218- if (delta > INT_MAX) {
219- qCWarning (logQtAutoUpdater, " Time interval to big, timepoint to far in the future." );
220- return 0 ;
221- } else
222- return this ->scheduleUpdate ((int )delta, false , displayLevel);
223- }
224-
225- void UpdateController::cancelScheduledUpdate (int taskId)
226216{
227217 Q_D (UpdateController);
228- this ->killTimer (taskId);
229- d->updateTasks .remove (taskId);
218+ return d->scheduler ->startSchedule (when, QVariant::fromValue (displayLevel));
230219}
231220
232- void UpdateController::timerEvent (QTimerEvent *event )
221+ void UpdateController::cancelScheduledUpdate ( int taskId )
233222{
234223 Q_D (UpdateController);
235- int tId = event->timerId ();
236- if (d->updateTasks .contains (tId)) {
237- UpdateControllerPrivate::UpdateTask task = d->updateTasks [tId];
238- if (!task.second ) {
239- d->updateTasks .remove (tId);
240- this ->killTimer (tId);
241- }
242- event->accept ();
243-
244- this ->start (task.first );
245- } else {
246- this ->killTimer (tId);
247- event->ignore ();
248- }
224+ d->scheduler ->cancelSchedule (taskId);
249225}
250226
251227void UpdateController::checkUpdatesDone (bool hasUpdates, bool hasError)
@@ -336,13 +312,18 @@ void UpdateController::checkUpdatesDone(bool hasUpdates, bool hasError)
336312 emit runningChanged (false );
337313}
338314
315+ void UpdateController::timerTriggered (int , const QVariant ¶meter)
316+ {
317+ if (parameter.canConvert <DisplayLevel>())
318+ this ->start (parameter.value <DisplayLevel>());
319+ }
320+
339321// -----------------PRIVATE IMPLEMENTATION-----------------
340322
341323UpdateControllerPrivate::UpdateControllerPrivate (UpdateController *q_ptr, QWidget *window) :
342324 UpdateControllerPrivate(q_ptr, QString(), window)
343325{}
344326
345- #include < QDebug>
346327UpdateControllerPrivate::UpdateControllerPrivate (UpdateController *q_ptr, const QString &toolPath, QWidget *window) :
347328 q_ptr(q_ptr),
348329 window(window),
@@ -355,11 +336,13 @@ UpdateControllerPrivate::UpdateControllerPrivate(UpdateController *q_ptr, const
355336 detailedInfo(true ),
356337 checkUpdatesProgress(nullptr ),
357338 wasCanceled(false ),
358- updateTasks( )
339+ scheduler( new SimpleScheduler(q_ptr) )
359340{
360341 QObject::connect (this ->mainUpdater , &Updater::checkUpdatesDone,
361342 q_ptr, &UpdateController::checkUpdatesDone,
362343 Qt::QueuedConnection);
344+ QObject::connect (this ->scheduler , &SimpleScheduler::scheduleTriggered,
345+ q_ptr, &UpdateController::timerTriggered);
363346
364347#ifdef Q_OS_UNIX
365348 // TODO test
0 commit comments