Settings update: Simplify Update Manager

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2016-08-10 16:40:14 -03:00 committed by Dirk Hohndel
parent 5c8b87b5fd
commit b76c1846bb

View file

@ -8,32 +8,24 @@
#include "core/version.h" #include "core/version.h"
#include "desktop-widgets/mainwindow.h" #include "desktop-widgets/mainwindow.h"
#include "core/cloudstorage.h" #include "core/cloudstorage.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h"
UpdateManager::UpdateManager(QObject *parent) : UpdateManager::UpdateManager(QObject *parent) :
QObject(parent), QObject(parent),
isAutomaticCheck(false) isAutomaticCheck(false)
{ {
// is this the first time this version was run? auto update_settings = SettingsObjectWrapper::instance()->update_manager_settings;
QSettings settings;
settings.beginGroup("UpdateManager"); if (update_settings->dontCheckForUpdates())
if (settings.contains("DontCheckForUpdates") && settings.value("DontCheckForUpdates") == "TRUE")
return; return;
if (settings.contains("LastVersionUsed")) {
// we have checked at least once before if (update_settings->lastVersionUsed() == subsurface_git_version() &&
if (settings.value("LastVersionUsed").toString() != subsurface_git_version()) { update_settings->nextCheck() > QDate::currentDate())
// we have just updated - wait two weeks before you check again return;
settings.setValue("LastVersionUsed", QString(subsurface_git_version()));
settings.setValue("NextCheck", QDateTime::currentDateTime().addDays(14).toString(Qt::ISODate)); update_settings->setLastVersionUsed(subsurface_git_version());
} else { update_settings->setNextCheck(QDate::currentDate().addDays(14));
// 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));
checkForUpdates(true); checkForUpdates(true);
} }
@ -117,23 +109,20 @@ void UpdateManager::requestReceived()
msgbox.exec(); msgbox.exec();
} }
if (isAutomaticCheck) { if (isAutomaticCheck) {
QSettings settings; auto update_settings = SettingsObjectWrapper::instance()->update_manager_settings;
settings.beginGroup("UpdateManager"); if (!update_settings->dontCheckForUpdates()) {
if (!settings.contains("DontCheckForUpdates")) {
// we allow an opt out of future checks // we allow an opt out of future checks
QMessageBox response(MainWindow::instance()); 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("Decline"), QMessageBox::RejectRole);
response.addButton(tr("Accept"), QMessageBox::AcceptRole); response.addButton(tr("Accept"), QMessageBox::AcceptRole);
response.setText(message); response.setText(message);
response.setWindowTitle(tr("Automatic check for updates")); response.setWindowTitle(tr("Automatic check for updates"));
response.setIcon(QMessageBox::Question); response.setIcon(QMessageBox::Question);
response.setWindowModality(Qt::WindowModal); response.setWindowModality(Qt::WindowModal);
int ret = response.exec(); update_settings->setDontCheckForUpdates(response.exec() != QMessageBox::Accepted);
if (ret == QMessageBox::Accepted)
settings.setValue("DontCheckForUpdates", "FALSE");
else
settings.setValue("DontCheckForUpdates", "TRUE");
} }
} }
#endif #endif