# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2017-08-20 06:30:51 # Node ID 43170751e0a777857a92fc89992d8948e6956318 # Parent 70a6380ef381deb06a0303ba81977b1066e52e3c check updates only once a day diff --git a/src/updatecheckdialog.cpp b/src/updatecheckdialog.cpp --- a/src/updatecheckdialog.cpp +++ b/src/updatecheckdialog.cpp @@ -27,9 +27,13 @@ UpdateCheckDialog::UpdateCheckDialog(QWi { ui->setupUi(this); + // by default start from yesterday, so that we check at first run + lastCheck = QDate::currentDate().addDays(-1); + connect(&updateChecker, &UpdateChecker::checkFailed, [this](QString errorMessage) { + lastCheck = QDate::currentDate(); ui->label->setText(QString("Update check failed.\n") + errorMessage); }); @@ -48,6 +52,7 @@ UpdateCheckDialog::UpdateCheckDialog(QWi .arg(newVersion).arg(downloadUrl); } + lastCheck = QDate::currentDate(); ui->label->setText(text); }); } @@ -72,16 +77,21 @@ void UpdateCheckDialog::saveSettings(QSe { settings->beginGroup(SettingGroup_UpdateCheck); settings->setValue(SG_UpdateCheck_Periodic, ui->cbPeriodic->isChecked()); + settings->setValue(SG_UpdateCheck_LastCheck, lastCheck.toString(Qt::ISODate)); settings->endGroup(); } void UpdateCheckDialog::loadSettings(QSettings* settings) { settings->beginGroup(SettingGroup_UpdateCheck); - ui->cbPeriodic->setChecked(settings->value(SG_UpdateCheck_Periodic).toBool()); + ui->cbPeriodic->setChecked(settings->value(SG_UpdateCheck_Periodic, + ui->cbPeriodic->isChecked()).toBool()); + auto lastCheckS = settings->value(SG_UpdateCheck_LastCheck, lastCheck.toString(Qt::ISODate)).toString(); + lastCheck = QDate::fromString(lastCheckS, Qt::ISODate); settings->endGroup(); - if (ui->cbPeriodic->isChecked()) + // start the periodic update if required + if (ui->cbPeriodic->isChecked() && lastCheck < QDate::currentDate()) { updateChecker.checkUpdate(); } diff --git a/src/updatecheckdialog.h b/src/updatecheckdialog.h --- a/src/updatecheckdialog.h +++ b/src/updatecheckdialog.h @@ -21,6 +21,7 @@ #define UPDATECHECKDIALOG_H #include +#include #include #include "updatechecker.h" @@ -44,6 +45,7 @@ public: private: Ui::UpdateCheckDialog *ui; UpdateChecker updateChecker; + QDate lastCheck; void showEvent(QShowEvent *event); void closeEvent(QShowEvent *event); diff --git a/src/updatecheckdialog.ui b/src/updatecheckdialog.ui --- a/src/updatecheckdialog.ui +++ b/src/updatecheckdialog.ui @@ -26,6 +26,9 @@ + + Updates will be checked only once a day at first start of the application + Check updates periodically