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