mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
5c8b87b5fd
commit
b76c1846bb
1 changed files with 18 additions and 29 deletions
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue