summaryrefslogtreecommitdiffstats
path: root/qt-ui/updatemanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/updatemanager.cpp')
-rw-r--r--qt-ui/updatemanager.cpp59
1 files changed, 51 insertions, 8 deletions
diff --git a/qt-ui/updatemanager.cpp b/qt-ui/updatemanager.cpp
index 6a02578b5..b6e8dc47a 100644
--- a/qt-ui/updatemanager.cpp
+++ b/qt-ui/updatemanager.cpp
@@ -2,14 +2,31 @@
#include "usersurvey.h"
#include <QtNetwork>
#include <QMessageBox>
+#include <QDateTime>
#include "subsurfacewebservices.h"
#include "ssrf-version.h"
+#include "mainwindow.h"
UpdateManager::UpdateManager(QObject *parent) : QObject(parent)
{
+ // is this the first time this version was run?
+ QSettings settings;
+ settings.beginGroup("UpdateManager");
+ if (settings.contains("LastVersionUsed") && settings.value("LastVersionUsed").toString() == GIT_VERSION_STRING) {
+ // this is the version we've been using
+ QString nextCheckString = settings.value("NextCheck").toString();
+ QDateTime nextCheck = QDateTime::fromString(nextCheckString, Qt::ISODate);
+ if (nextCheck > QDateTime::currentDateTime())
+ return;
+ }
+ settings.setValue("LastVersionUsed", QString(GIT_VERSION_STRING));
+ if (settings.contains("DontCheckForUpdates") && settings.value("DontCheckForUpdates") == "TRUE")
+ return;
+ checkForUpdates(true);
+ settings.setValue("NextCheck", QDateTime::currentDateTime().addDays(14).toString(Qt::ISODate));
}
-void UpdateManager::checkForUpdates()
+void UpdateManager::checkForUpdates(bool automatic)
{
QString os;
@@ -22,7 +39,8 @@ void UpdateManager::checkForUpdates()
#else
os = "unknown";
#endif
-
+ qDebug() << "checking for update";
+ isAutomaticCheck = automatic;
QString version = CANONICAL_VERSION_STRING;
QString url = QString("http://subsurface-divelog.org/updatecheck.html?os=%1&version=%2").arg(os, version);
QNetworkRequest request;
@@ -35,6 +53,7 @@ void UpdateManager::checkForUpdates()
void UpdateManager::requestReceived()
{
+ bool haveNewVersion = false;
QMessageBox msgbox;
QString msgTitle = tr("Check for updates.");
QString msgText = "<h3>" + tr("Subsurface was unable to check for updates.") + "</h3>";
@@ -58,11 +77,13 @@ void UpdateManager::requestReceived()
if (responseBody == "OK") {
msgText = tr("You are using the latest version of Subsurface.");
} else if (responseBody.startsWith("http")) {
+ haveNewVersion = true;
msgText = tr("A new version of Subsurface is available.<br/>Click on:<br/><a href=\"%1\">%1</a><br/> to download it.")
.arg(responseBody);
} else if (responseBody.startsWith("Latest version")) {
// the webservice backend doesn't localize - but it's easy enough to just replace the
// strings that it is likely to send back
+ haveNewVersion = true;
responseBody.replace("Latest version is ", "");
responseBody.replace(". please check with your OS vendor for updates.", "");
msgText = QString("<b>") + tr("A new version of Subsurface is available.") + QString("</b><br/><br/>") +
@@ -71,16 +92,38 @@ void UpdateManager::requestReceived()
} else {
// the webservice backend doesn't localize - but it's easy enough to just replace the
// strings that it is likely to send back
+ haveNewVersion = true;
if (responseBody.contains("Newest release version is "))
responseBody.replace("Newest release version is ", tr("Newest release version is "));
msgText = tr("The server returned the following information:").append("<br/><br/>").append(responseBody);
msgbox.setIcon(QMessageBox::Warning);
}
}
-
- msgbox.setWindowTitle(msgTitle);
- msgbox.setWindowIcon(QIcon(":/subsurface-icon"));
- msgbox.setText(msgText);
- msgbox.setTextFormat(Qt::RichText);
- msgbox.exec();
+ if (haveNewVersion || !isAutomaticCheck) {
+ msgbox.setWindowTitle(msgTitle);
+ msgbox.setWindowIcon(QIcon(":/subsurface-icon"));
+ msgbox.setText(msgText);
+ msgbox.setTextFormat(Qt::RichText);
+ msgbox.exec();
+ }
+ if (isAutomaticCheck) {
+ QSettings settings;
+ settings.beginGroup("UpdateManager");
+ if (!settings.contains("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.");
+ 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");
+ }
+ }
}