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