diff options
author | Tomaz Canabrava <tomaz.canabrava@gmail.com> | 2016-08-10 16:40:14 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-08-27 11:40:44 -0700 |
commit | b76c1846bbfda4b802795a682398c82361103e3c (patch) | |
tree | 5b076394d3c4e79bfe1f16d541ae1447ba588065 /desktop-widgets | |
parent | 5c8b87b5fdd73310447589771e68ea387aedfa6c (diff) | |
download | subsurface-b76c1846bbfda4b802795a682398c82361103e3c.tar.gz |
Settings update: Simplify Update Manager
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/updatemanager.cpp | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/desktop-widgets/updatemanager.cpp b/desktop-widgets/updatemanager.cpp index b09d12439..b56580113 100644 --- a/desktop-widgets/updatemanager.cpp +++ b/desktop-widgets/updatemanager.cpp @@ -8,32 +8,24 @@ #include "core/version.h" #include "desktop-widgets/mainwindow.h" #include "core/cloudstorage.h" +#include "core/subsurface-qt/SettingsObjectWrapper.h" UpdateManager::UpdateManager(QObject *parent) : QObject(parent), isAutomaticCheck(false) { - // is this the first time this version was run? - QSettings settings; - settings.beginGroup("UpdateManager"); - if (settings.contains("DontCheckForUpdates") && settings.value("DontCheckForUpdates") == "TRUE") + auto update_settings = SettingsObjectWrapper::instance()->update_manager_settings; + + if (update_settings->dontCheckForUpdates()) return; - if (settings.contains("LastVersionUsed")) { - // we have checked at least once before - if (settings.value("LastVersionUsed").toString() != subsurface_git_version()) { - // we have just updated - wait two weeks before you check again - settings.setValue("LastVersionUsed", QString(subsurface_git_version())); - settings.setValue("NextCheck", QDateTime::currentDateTime().addDays(14).toString(Qt::ISODate)); - } else { - // is it time to check again? - QString nextCheckString = settings.value("NextCheck").toString(); - QDateTime nextCheck = QDateTime::fromString(nextCheckString, Qt::ISODate); - if (nextCheck > QDateTime::currentDateTime()) - return; - } - } - settings.setValue("LastVersionUsed", QString(subsurface_git_version())); - settings.setValue("NextCheck", QDateTime::currentDateTime().addDays(14).toString(Qt::ISODate)); + + if (update_settings->lastVersionUsed() == subsurface_git_version() && + update_settings->nextCheck() > QDate::currentDate()) + return; + + update_settings->setLastVersionUsed(subsurface_git_version()); + update_settings->setNextCheck(QDate::currentDate().addDays(14)); + checkForUpdates(true); } @@ -117,23 +109,20 @@ void UpdateManager::requestReceived() msgbox.exec(); } if (isAutomaticCheck) { - QSettings settings; - settings.beginGroup("UpdateManager"); - if (!settings.contains("DontCheckForUpdates")) { + auto update_settings = SettingsObjectWrapper::instance()->update_manager_settings; + if (!update_settings->dontCheckForUpdates()) { + // we allow an opt out of future checks QMessageBox response(MainWindow::instance()); - QString message = tr("Subsurface is checking every two weeks if a new version is available. If you don't want Subsurface to continue checking, please click Decline."); + QString message = tr("Subsurface is checking every two weeks if a new version is available. " + "\n If you don't want Subsurface to continue checking, please click Decline."); response.addButton(tr("Decline"), QMessageBox::RejectRole); response.addButton(tr("Accept"), QMessageBox::AcceptRole); response.setText(message); response.setWindowTitle(tr("Automatic check for updates")); response.setIcon(QMessageBox::Question); response.setWindowModality(Qt::WindowModal); - int ret = response.exec(); - if (ret == QMessageBox::Accepted) - settings.setValue("DontCheckForUpdates", "FALSE"); - else - settings.setValue("DontCheckForUpdates", "TRUE"); + update_settings->setDontCheckForUpdates(response.exec() != QMessageBox::Accepted); } } #endif |