mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
Add "Check for updates" Feature
This patch adds a check for updates feature. It connects to http://subsurface.hohndel.org/updatecheck.html to check for any new versions. It then prompts the user with a download link if an update is available. Signed-off-by: Joseph W. Joshua <joejoshw@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5cec965cb7
commit
ede6a38bcf
6 changed files with 109 additions and 2 deletions
|
@ -37,6 +37,7 @@
|
|||
#include "diveplanner.h"
|
||||
#include "about.h"
|
||||
#include "worldmap-save.h"
|
||||
#include "updatemanager.h"
|
||||
#ifndef NO_PRINTING
|
||||
#include "printdialog.h"
|
||||
#endif
|
||||
|
@ -84,6 +85,8 @@ MainWindow::MainWindow() : QMainWindow(),
|
|||
ui.divePlanner->settingsChanged();
|
||||
ui.divePlannerWidget->settingsChanged();
|
||||
|
||||
updateManager = new UpdateManager(this);
|
||||
|
||||
#ifndef ENABLE_PLANNER
|
||||
// ui.menuLog->removeAction(ui.actionDivePlanner);
|
||||
#endif
|
||||
|
@ -575,6 +578,11 @@ void MainWindow::on_actionAboutSubsurface_triggered()
|
|||
dlg.exec();
|
||||
}
|
||||
|
||||
void MainWindow::on_action_Check_for_Updates_triggered()
|
||||
{
|
||||
updateManager->checkForUpdates();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionUserManual_triggered()
|
||||
{
|
||||
#ifndef NO_USERMANUAL
|
||||
|
|
|
@ -28,6 +28,7 @@ class MainTab;
|
|||
class ProfileGraphicsView;
|
||||
class QWebView;
|
||||
class QSettings;
|
||||
class UpdateManager;
|
||||
|
||||
enum MainWindowTitleFormat {
|
||||
MWTF_DEFAULT,
|
||||
|
@ -121,6 +122,7 @@ slots:
|
|||
void on_actionAboutSubsurface_triggered();
|
||||
void on_actionUserManual_triggered();
|
||||
void on_actionDivePlanner_triggered();
|
||||
void on_action_Check_for_Updates_triggered();
|
||||
|
||||
void current_dive_changed(int divenr);
|
||||
void initialUiSetup();
|
||||
|
@ -171,6 +173,7 @@ private:
|
|||
QString lastUsedDir();
|
||||
void updateLastUsedDir(const QString &s);
|
||||
bool filesAsArguments;
|
||||
UpdateManager *updateManager;
|
||||
};
|
||||
|
||||
MainWindow *mainWindow();
|
||||
|
|
|
@ -601,6 +601,7 @@
|
|||
<string>&Help</string>
|
||||
</property>
|
||||
<addaction name="actionAboutSubsurface"/>
|
||||
<addaction name="action_Check_for_Updates"/>
|
||||
<addaction name="actionUserManual"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuImport">
|
||||
|
@ -910,6 +911,11 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_Check_for_Updates">
|
||||
<property name="text">
|
||||
<string>&Check for Updates</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
67
qt-ui/updatemanager.cpp
Normal file
67
qt-ui/updatemanager.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include "updatemanager.h"
|
||||
#include <QtNetwork>
|
||||
#include <QMessageBox>
|
||||
#include "subsurfacewebservices.h"
|
||||
#include "ssrf-version.h"
|
||||
|
||||
UpdateManager::UpdateManager(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
manager = SubsurfaceWebServices::manager();
|
||||
connect (manager, SIGNAL(finished(QNetworkReply*)), SLOT(requestReceived(QNetworkReply*)));
|
||||
}
|
||||
|
||||
void UpdateManager::checkForUpdates()
|
||||
{
|
||||
QString os;
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
os = "win";
|
||||
#elif defined(Q_OS_MAC)
|
||||
os = "osx";
|
||||
#else
|
||||
os = "unknown";
|
||||
#endif
|
||||
|
||||
QString version = VERSION_STRING;
|
||||
QString url = QString("http://subsurface.hohndel.org/updatecheck.html?os=%1&ver=%2").arg(os, version);
|
||||
manager->get(QNetworkRequest(QUrl(url)));
|
||||
}
|
||||
|
||||
void UpdateManager::requestReceived(QNetworkReply *reply)
|
||||
{
|
||||
QMessageBox msgbox;
|
||||
QString msgTitle = tr("Check for updates.");
|
||||
QString msgText = tr("<h3>Subsurface was unable to check for updates.</h3>");
|
||||
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
//Network Error
|
||||
msgText = msgText + tr("<br/><b>The following error occurred:</b><br/>") + reply->errorString()
|
||||
+ tr("<br/><br/><b>Please check your internet connection.</b>");
|
||||
} else {
|
||||
//No network error
|
||||
QString response(reply->readAll());
|
||||
QString responseBody = response.split("\"").at(1);
|
||||
|
||||
msgbox.setIcon(QMessageBox::Information);
|
||||
|
||||
if (responseBody == "OK") {
|
||||
msgText = tr("You are using the latest version of subsurface.");
|
||||
} else if (responseBody.startsWith("http")) {
|
||||
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")) {
|
||||
msgText = tr("<b>A new version of subsurface is available.</b><br/><br/>%1")
|
||||
.arg(responseBody);
|
||||
} else {
|
||||
msgText = tr("There was an error while trying to check for updates.<br/><br/>%1").arg(responseBody);
|
||||
msgbox.setIcon(QMessageBox::Warning);
|
||||
}
|
||||
}
|
||||
|
||||
msgbox.setWindowTitle(msgTitle);
|
||||
msgbox.setText(msgText);
|
||||
msgbox.setTextFormat(Qt::RichText);
|
||||
msgbox.exec();
|
||||
}
|
21
qt-ui/updatemanager.h
Normal file
21
qt-ui/updatemanager.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef UPDATEMANAGER_H
|
||||
#define UPDATEMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
|
||||
class UpdateManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UpdateManager(QObject *parent = 0);
|
||||
void checkForUpdates();
|
||||
private:
|
||||
QNetworkAccessManager *manager;
|
||||
public slots:
|
||||
void requestReceived(QNetworkReply* reply);
|
||||
};
|
||||
|
||||
#endif // UPDATEMANAGER_H
|
|
@ -76,7 +76,8 @@ HEADERS = \
|
|||
qt-ui/profile/diveprofileitem.h \
|
||||
qt-ui/profile/diveeventitem.h \
|
||||
qt-ui/profile/divetooltipitem.h \
|
||||
qt-ui/profile/ruleritem.h
|
||||
qt-ui/profile/ruleritem.h \
|
||||
qt-ui/updatemanager.h
|
||||
|
||||
android: HEADERS -= \
|
||||
qt-ui/usermanual.h \
|
||||
|
@ -148,7 +149,8 @@ SOURCES = \
|
|||
qt-ui/profile/diveprofileitem.cpp \
|
||||
qt-ui/profile/diveeventitem.cpp \
|
||||
qt-ui/profile/divetooltipitem.cpp \
|
||||
qt-ui/profile/ruleritem.cpp
|
||||
qt-ui/profile/ruleritem.cpp \
|
||||
qt-ui/updatemanager.cpp
|
||||
|
||||
android: SOURCES += android.cpp
|
||||
else: linux*: SOURCES += linux.c
|
||||
|
|
Loading…
Add table
Reference in a new issue