tahoma2d/toonz/sources/toonzqt/updatechecker.cpp
Shinya Kitaoka 7be7e612c4 Fix a version text (Rewrite update check) (#290)
* Rewrite update check

Before release, the update URL will need to be changed to an official
one.

* remove syntax macros: CASE, __OR, and DEFAULT

* define VC_EXTRALEAN

* modify the URL of opentoonz-version.txt

* fix a type of updateUrl

* remove meanless comments
2016-05-16 14:16:01 +09:00

36 lines
1.1 KiB
C++

#include "./toonzqt/updatechecker.h"
#include <QNetworkReply>
UpdateChecker::UpdateChecker(QUrl const& updateUrl)
: manager_(new QNetworkAccessManager(this), &QNetworkAccessManager::deleteLater)
{
connect(manager_.data(), SIGNAL(finished(QNetworkReply*)),
this, SLOT(httpRequestFinished(QNetworkReply*)));
manager_->get(QNetworkRequest(updateUrl));
}
void UpdateChecker::httpRequestFinished(QNetworkReply *pReply)
{
QSharedPointer<QNetworkReply> reply(pReply, &QNetworkReply::deleteLater);
// If there was an error, don't bother doing the check
if (reply->error() != QNetworkReply::NoError) {
emit done(true);
return;
}
// Convert the response from a QByteArray into a QString
QString candidateVersion = QString(reply->readAll()).trimmed();
// 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;
}
// Completed with no errors
m_latestVersion = candidateVersion;
emit done(false);
}