summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-01 20:49:24 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-01 20:49:24 -0800
commit864c4ce94d58d6b1bad5fa77b75cb1a9311ab889 (patch)
treec8737b0f7379467c70fbf51b182ff3498396f5f8
parent4ce3c1e8b89cd7b8178ee8f360f6a431d3d381e6 (diff)
downloadsubsurface-864c4ce94d58d6b1bad5fa77b75cb1a9311ab889.tar.gz
Automatic update check with an opt out
Store the last version used, the next time we can check, and the decision if the user does or does not want these checks in the settings. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/mainwindow.cpp2
-rw-r--r--qt-ui/updatemanager.cpp59
-rw-r--r--qt-ui/updatemanager.h5
3 files changed, 56 insertions, 10 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index c578cb3d1..3ce038ba0 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -64,7 +64,6 @@ MainWindow::MainWindow() : QMainWindow(),
actionPreviousDive(0),
helpView(0),
state(VIEWALL),
- updateManager(0),
survey(0)
{
Q_ASSERT_X(m_Instance == NULL, "MainWindow", "MainWindow recreated!");
@@ -136,6 +135,7 @@ MainWindow::MainWindow() : QMainWindow(),
QLayoutItem *p = ui.gridLayout->takeAt(0);
ui.gridLayout->addWidget(toolBar, 0, 0);
ui.gridLayout->addItem(p, 0, 1);
+ updateManager = new UpdateManager(this);
}
MainWindow::~MainWindow()
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");
+ }
+ }
}
diff --git a/qt-ui/updatemanager.h b/qt-ui/updatemanager.h
index 98b84021d..4e95d740f 100644
--- a/qt-ui/updatemanager.h
+++ b/qt-ui/updatemanager.h
@@ -10,11 +10,14 @@ class UpdateManager : public QObject {
Q_OBJECT
public:
explicit UpdateManager(QObject *parent = 0);
- void checkForUpdates();
+ void checkForUpdates(bool automatic = false);
public
slots:
void requestReceived();
+
+private:
+ bool isAutomaticCheck;
};
#endif // UPDATEMANAGER_H