mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 21:20:19 +00:00
d818dc1a84
In some strings that won't be possible as the translation needs to be aware of line breaks, etc. But for these strings it seems like the right thing to do. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
68 lines
2 KiB
C++
68 lines
2 KiB
C++
#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";
|
|
#elif defined(Q_OS_LINUX)
|
|
os = "linux";
|
|
#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 = "<h3>" + tr("Subsurface was unable to check for updates.") + "</h3>";
|
|
|
|
|
|
if (reply->error() != QNetworkReply::NoError) {
|
|
//Network Error
|
|
msgText = msgText + "<br/><b>" + tr("The following error occurred:") + "</b><br/>" + reply->errorString()
|
|
+ "<br/><br/><b>" + tr("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();
|
|
}
|