2014-04-02 19:41:39 +00:00
|
|
|
#include "updatemanager.h"
|
2014-07-31 18:20:11 +00:00
|
|
|
#include "usersurvey.h"
|
2014-04-02 19:41:39 +00:00
|
|
|
#include <QtNetwork>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include "subsurfacewebservices.h"
|
|
|
|
#include "ssrf-version.h"
|
|
|
|
|
2014-05-22 18:40:22 +00:00
|
|
|
UpdateManager::UpdateManager(QObject *parent) : QObject(parent)
|
2014-04-02 19:41:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateManager::checkForUpdates()
|
|
|
|
{
|
|
|
|
QString os;
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
os = "win";
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
os = "osx";
|
2014-04-02 19:55:33 +00:00
|
|
|
#elif defined(Q_OS_LINUX)
|
|
|
|
os = "linux";
|
2014-04-02 19:41:39 +00:00
|
|
|
#else
|
|
|
|
os = "unknown";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QString version = VERSION_STRING;
|
|
|
|
QString url = QString("http://subsurface.hohndel.org/updatecheck.html?os=%1&ver=%2").arg(os, version);
|
2014-07-31 18:20:11 +00:00
|
|
|
QNetworkRequest request;
|
|
|
|
request.setUrl(url);
|
|
|
|
request.setRawHeader("Accept", "text/xml");
|
2014-08-08 18:13:05 +00:00
|
|
|
QString userAgent = UserSurvey::getUserAgent();
|
2014-07-31 18:20:11 +00:00
|
|
|
request.setRawHeader("User-Agent", userAgent.toUtf8());
|
|
|
|
connect(SubsurfaceWebServices::manager()->get(request), SIGNAL(finished()), this, SLOT(requestReceived()));
|
2014-04-02 19:41:39 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 20:20:21 +00:00
|
|
|
void UpdateManager::requestReceived()
|
2014-04-02 19:41:39 +00:00
|
|
|
{
|
|
|
|
QMessageBox msgbox;
|
|
|
|
QString msgTitle = tr("Check for updates.");
|
2014-07-09 17:26:43 +00:00
|
|
|
QString msgText = "<h3>" + tr("Subsurface was unable to check for updates.") + "</h3>";
|
2014-04-02 19:41:39 +00:00
|
|
|
|
2014-07-16 20:20:21 +00:00
|
|
|
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
2014-04-02 19:41:39 +00:00
|
|
|
if (reply->error() != QNetworkReply::NoError) {
|
|
|
|
//Network Error
|
2014-07-09 17:26:43 +00:00
|
|
|
msgText = msgText + "<br/><b>" + tr("The following error occurred:") + "</b><br/>" + reply->errorString()
|
|
|
|
+ "<br/><br/><b>" + tr("Please check your internet connection.") + "</b>";
|
2014-04-02 19:41:39 +00:00
|
|
|
} else {
|
|
|
|
//No network error
|
|
|
|
QString response(reply->readAll());
|
2014-08-08 17:39:46 +00:00
|
|
|
QString responseBody;
|
|
|
|
if (response.contains('"'))
|
|
|
|
responseBody = response.split("\"").at(1);
|
|
|
|
else
|
|
|
|
responseBody = response;
|
2014-04-02 19:41:39 +00:00
|
|
|
|
|
|
|
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);
|
2014-07-18 10:57:14 +00:00
|
|
|
msgbox.setWindowIcon(QIcon(":/subsurface-icon"));
|
2014-04-02 19:41:39 +00:00
|
|
|
msgbox.setText(msgText);
|
|
|
|
msgbox.setTextFormat(Qt::RichText);
|
|
|
|
msgbox.exec();
|
|
|
|
}
|