1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include "Windows/updatecheck.h"
UpdateCheck::UpdateCheck(QWidget *parent) : QDialog(parent)
{
QHBoxLayout *hLayout = new QHBoxLayout();
statusLabel = new QLabel();
statusLabel->setOpenExternalLinks(true);
statusLabel->setTextFormat(Qt::RichText);
hLayout->addWidget(statusLabel);
setLayout(hLayout);
setWindowTitle(tr("Update check"));
timer.setSingleShot(true);
timer.setInterval(5000);
manualCheckErrorText = tr("Please check that you are connected to the internet then try again.<br/>"
"If the problem persists, you can check manually at <a href='zegrapher.com'>zegrapher.com</a><br/>"
"Current version: ") + SOFTWARE_VERSION_STR;
connect(&manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
connect(&timer, SIGNAL(timeout()), this, SLOT(timedOut()));
}
void UpdateCheck::timedOut()
{
statusLabel->setText(tr("Failed to lookup the latest version.<br/>") + manualCheckErrorText);
}
void UpdateCheck::silentCheckForUpdate()
{
statusLabel->setText(tr("Looking for a possible update, please wait..."));
QNetworkRequest request(QUrl("https://zegrapher.com/latest"));
timer.start();
manager.get(request);
}
void UpdateCheck::checkForUpdate()
{
statusLabel->setText(tr("Looking for a possible update, please wait..."));
QNetworkRequest request(QUrl("https://zegrapher.com/latest"));
timer.start();
manager.get(request);
QDialog::exec();
}
void UpdateCheck::downloadFinished(QNetworkReply *reply)
{
timer.stop();
if(reply->error() != QNetworkReply::NoError)
{
statusLabel->setText(tr("Failed to lookup the latest version.<br/>") + manualCheckErrorText);
reply->deleteLater();
return;
}
bool ok = false;
QTextStream reader(reply);
double latestVersion = reader.readAll().toDouble(&ok);
if(!ok)
{
statusLabel->setText(tr("Error while reading latest version file...") + manualCheckErrorText);
}
else
{
if(latestVersion > SOFTWARE_VERSION)
{
statusLabel->setText(tr("A new version is available!<br/>"
"To download it, visit <a href=https://zegrapher.com>zegrapher.com</a><br/><br/>"
"<u>Note:</u> You can enable/disable the automatic update check in the settings"));
QDialog::exec();
}
else
{
statusLabel->setText(tr("You have the latest version."));
}
}
reply->deleteLater();
}
UpdateCheck::~UpdateCheck()
{
}
|