Mercurial > hg > svapp
comparison framework/VersionTester.cpp @ 263:3c236d31cccd qt5
Get this one building with Qt5
author | Chris Cannam |
---|---|
date | Mon, 11 Mar 2013 14:48:49 +0000 |
parents | 8aace2d9f1c2 |
children | 8cb01cd2441d |
comparison
equal
deleted
inserted
replaced
262:8a603a0840c8 | 263:3c236d31cccd |
---|---|
21 #include "VersionTester.h" | 21 #include "VersionTester.h" |
22 #include "base/Debug.h" | 22 #include "base/Debug.h" |
23 | 23 |
24 #include <iostream> | 24 #include <iostream> |
25 | 25 |
26 #include <QHttp> | 26 #include <QNetworkAccessManager> |
27 | |
28 static QNetworkAccessManager nm; | |
27 | 29 |
28 VersionTester::VersionTester(QString hostname, QString versionFilePath, | 30 VersionTester::VersionTester(QString hostname, QString versionFilePath, |
29 QString myVersion) : | 31 QString myVersion) : |
30 m_httpFailed(false), | 32 m_myVersion(myVersion), |
31 m_myVersion(myVersion) | 33 m_reply(0), |
34 m_httpFailed(false) | |
32 { | 35 { |
33 QHttp *http = new QHttp(); | 36 QUrl url(QString("http://%1/%2").arg(hostname).arg(versionFilePath)); |
34 connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), | 37 std::cerr << "VersionTester: URL is " << url << std::endl; |
35 this, SLOT(httpResponseHeaderReceived(const QHttpResponseHeader &))); | 38 m_reply = nm.get(QNetworkRequest(url)); |
36 connect(http, SIGNAL(done(bool)), | 39 connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), |
37 this, SLOT(httpDone(bool))); | 40 this, SLOT(error(QNetworkReply::NetworkError))); |
38 http->setHost(hostname); | 41 connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); |
39 http->get(versionFilePath); | |
40 } | 42 } |
41 | 43 |
42 VersionTester::~VersionTester() | 44 VersionTester::~VersionTester() |
43 { | 45 { |
46 if (m_reply) { | |
47 m_reply->abort(); | |
48 m_reply->deleteLater(); | |
49 } | |
44 } | 50 } |
45 | 51 |
46 bool | 52 bool |
47 VersionTester::isVersionNewerThan(QString a, QString b) | 53 VersionTester::isVersionNewerThan(QString a, QString b) |
48 { | 54 { |
67 } | 73 } |
68 return false; | 74 return false; |
69 } | 75 } |
70 | 76 |
71 void | 77 void |
72 VersionTester::httpResponseHeaderReceived(const QHttpResponseHeader &h) | 78 VersionTester::error(QNetworkReply::NetworkError) |
73 { | 79 { |
74 if (h.statusCode() / 100 != 2) m_httpFailed = true; | 80 std::cerr << "VersionTester: error: " << m_reply->errorString() << std::endl; |
81 m_httpFailed = true; | |
75 } | 82 } |
76 | 83 |
77 void | 84 void |
78 VersionTester::httpDone(bool error) | 85 VersionTester::finished() |
79 { | 86 { |
80 QHttp *http = const_cast<QHttp *>(dynamic_cast<const QHttp *>(sender())); | 87 m_reply->deleteLater(); |
81 if (!http) return; | 88 if (m_httpFailed) return; |
82 http->deleteLater(); | |
83 if (error || m_httpFailed) return; | |
84 | 89 |
85 QByteArray responseData = http->readAll(); | 90 int status = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); |
91 if (status / 100 != 2) { | |
92 std::cerr << "VersionTester: error: http status = " << status << std::endl; | |
93 return; | |
94 } | |
95 | |
96 QByteArray responseData = m_reply->readAll(); | |
86 QString str = QString::fromUtf8(responseData.data()); | 97 QString str = QString::fromUtf8(responseData.data()); |
87 QStringList lines = str.split('\n', QString::SkipEmptyParts); | 98 QStringList lines = str.split('\n', QString::SkipEmptyParts); |
88 if (lines.empty()) return; | 99 if (lines.empty()) return; |
89 | 100 |
90 QString latestVersion = lines[0]; | 101 QString latestVersion = lines[0]; |