22 #include "base/Debug.h" 26 #include <QNetworkAccessManager> 31 m_myVersion(myVersion),
34 m_nm(new QNetworkAccessManager)
36 QUrl url(QString(
"http://%1/%2").arg(hostname).arg(versionFilePath));
37 SVDEBUG <<
"VersionTester: URL is " << url << endl;
39 connect(
m_reply, SIGNAL(
error(QNetworkReply::NetworkError)),
40 this, SLOT(
error(QNetworkReply::NetworkError)));
57 QStringList alist = a.split(re, QString::SkipEmptyParts);
58 QStringList blist = b.split(re, QString::SkipEmptyParts);
59 int ae = alist.size();
60 int be = blist.size();
61 int e = std::max(ae, be);
62 for (
int i = 0; i < e; ++i) {
65 an = alist[i].toInt();
66 if (an == 0 && alist[i] !=
"0") {
71 bn = blist[i].toInt();
72 if (bn == 0 && blist[i] !=
"0") {
76 if (an < bn)
return false;
77 if (an > bn)
return true;
85 SVDEBUG <<
"VersionTester: error: " <<
m_reply->errorString() << endl;
98 int status = r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
99 if (status / 100 != 2) {
100 SVDEBUG <<
"VersionTester: error: http status = " << status << endl;
104 QByteArray responseData = r->readAll();
105 QString str = QString::fromUtf8(responseData.data());
106 QStringList lines = str.split(
'\n', QString::SkipEmptyParts);
107 if (lines.empty())
return;
109 QString latestVersion = lines[0];
110 SVDEBUG <<
"Comparing current version \"" <<
m_myVersion <<
"\" with latest version \"" << latestVersion <<
"\"" << endl;
112 SVDEBUG <<
"Latest version \"" << latestVersion <<
"\" is newer than current version \"" <<
m_myVersion <<
"\"" << endl;
static bool isVersionNewerThan(QString, QString)
void newerVersionAvailable(QString)
void error(QNetworkReply::NetworkError)
QNetworkAccessManager * m_nm
VersionTester(QString hostname, QString versionFilePath, QString myVersion)