tahoma2d/toonz/sources/toonzqt/updatechecker.cpp

37 lines
1.1 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "./toonzqt/updatechecker.h"
#include <QNetworkReply>
UpdateChecker::UpdateChecker(QUrl const& updateUrl)
2016-06-15 18:43:10 +12:00
: manager_(new QNetworkAccessManager(this),
&QNetworkAccessManager::deleteLater) {
connect(manager_.data(), SIGNAL(finished(QNetworkReply*)), this,
SLOT(httpRequestFinished(QNetworkReply*)));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
manager_->get(QNetworkRequest(updateUrl));
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
void UpdateChecker::httpRequestFinished(QNetworkReply* pReply) {
QSharedPointer<QNetworkReply> reply(pReply, &QNetworkReply::deleteLater);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// If there was an error, don't bother doing the check
if (reply->error() != QNetworkReply::NoError) {
emit done(true);
return;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Convert the response from a QByteArray into a QString
QString candidateVersion = QString(reply->readAll()).trimmed();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// TODO: Verify that the response was valid by ensuring we have a single line
// in the format x.x[.x]*
if (candidateVersion.indexOf(".") < 0) {
// There was some invalid response, so we'll ignore the check for now
emit done(true);
return;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Completed with no errors
m_latestVersion = candidateVersion;
emit done(false);
2016-03-19 06:57:51 +13:00
}