mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +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 "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
|
||||
|
|
Loading…
Add table
Reference in a new issue