comparison framework/VersionTester.cpp @ 287:8cb01cd2441d sv_v2.1

Delete things
author Chris Cannam
date Thu, 16 May 2013 14:05:02 +0100
parents 3c236d31cccd
children 068235cf5bf7
comparison
equal deleted inserted replaced
286:489bb1ba1202 287:8cb01cd2441d
23 23
24 #include <iostream> 24 #include <iostream>
25 25
26 #include <QNetworkAccessManager> 26 #include <QNetworkAccessManager>
27 27
28 static QNetworkAccessManager nm;
29 28
30 VersionTester::VersionTester(QString hostname, QString versionFilePath, 29 VersionTester::VersionTester(QString hostname, QString versionFilePath,
31 QString myVersion) : 30 QString myVersion) :
32 m_myVersion(myVersion), 31 m_myVersion(myVersion),
33 m_reply(0), 32 m_reply(0),
34 m_httpFailed(false) 33 m_httpFailed(false),
34 m_nm(new QNetworkAccessManager)
35 { 35 {
36 QUrl url(QString("http://%1/%2").arg(hostname).arg(versionFilePath)); 36 QUrl url(QString("http://%1/%2").arg(hostname).arg(versionFilePath));
37 std::cerr << "VersionTester: URL is " << url << std::endl; 37 std::cerr << "VersionTester: URL is " << url << std::endl;
38 m_reply = nm.get(QNetworkRequest(url)); 38 m_reply = m_nm->get(QNetworkRequest(url));
39 connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), 39 connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)),
40 this, SLOT(error(QNetworkReply::NetworkError))); 40 this, SLOT(error(QNetworkReply::NetworkError)));
41 connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); 41 connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
42 } 42 }
43 43
45 { 45 {
46 if (m_reply) { 46 if (m_reply) {
47 m_reply->abort(); 47 m_reply->abort();
48 m_reply->deleteLater(); 48 m_reply->deleteLater();
49 } 49 }
50 delete m_nm;
50 } 51 }
51 52
52 bool 53 bool
53 VersionTester::isVersionNewerThan(QString a, QString b) 54 VersionTester::isVersionNewerThan(QString a, QString b)
54 { 55 {
82 } 83 }
83 84
84 void 85 void
85 VersionTester::finished() 86 VersionTester::finished()
86 { 87 {
87 m_reply->deleteLater(); 88 QNetworkReply *r = m_reply;
89 m_reply = 0;
90
91 r->deleteLater();
88 if (m_httpFailed) return; 92 if (m_httpFailed) return;
89 93
90 int status = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); 94 int status = r->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
91 if (status / 100 != 2) { 95 if (status / 100 != 2) {
92 std::cerr << "VersionTester: error: http status = " << status << std::endl; 96 std::cerr << "VersionTester: error: http status = " << status << std::endl;
93 return; 97 return;
94 } 98 }
95 99
96 QByteArray responseData = m_reply->readAll(); 100 QByteArray responseData = r->readAll();
97 QString str = QString::fromUtf8(responseData.data()); 101 QString str = QString::fromUtf8(responseData.data());
98 QStringList lines = str.split('\n', QString::SkipEmptyParts); 102 QStringList lines = str.split('\n', QString::SkipEmptyParts);
99 if (lines.empty()) return; 103 if (lines.empty()) return;
100 104
101 QString latestVersion = lines[0]; 105 QString latestVersion = lines[0];