summaryrefslogtreecommitdiffstats
path: root/examples/network/torrent/trackerclient.cpp
diff options
context:
space:
mode:
authorJonas M. Gastal <jgastal@profusion.mobi>2011-12-22 17:42:49 -0200
committerQt by Nokia <qt-info@nokia.com>2012-01-06 23:07:26 +0100
commitb3ce4470ae2ece0c03c66684ca3d9dd13955786b (patch)
tree9e4ef3ec338cb3731bd1df66e0df4c0448a6574b /examples/network/torrent/trackerclient.cpp
parent7dca461620ee6d8cce3a74acf2e1530d4497bff9 (diff)
Removing QHttp class, its tests and its usage in examples.
Task-number: QTBUG-22750 Change-Id: I161fad772bfb26797e6ee9d69da925b6747c371f Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'examples/network/torrent/trackerclient.cpp')
-rw-r--r--examples/network/torrent/trackerclient.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/examples/network/torrent/trackerclient.cpp b/examples/network/torrent/trackerclient.cpp
index c8525e983f..43c60ac9bd 100644
--- a/examples/network/torrent/trackerclient.cpp
+++ b/examples/network/torrent/trackerclient.cpp
@@ -45,6 +45,7 @@
#include "trackerclient.h"
#include <QtCore>
+#include <QNetworkRequest>
TrackerClient::TrackerClient(TorrentClient *downloader, QObject *parent)
: QObject(parent), torrentDownloader(downloader)
@@ -56,7 +57,7 @@ TrackerClient::TrackerClient(TorrentClient *downloader, QObject *parent)
lastTrackerRequest = false;
firstSeeding = true;
- connect(&http, SIGNAL(done(bool)), this, SLOT(httpRequestDone(bool)));
+ connect(&http, SIGNAL(finished(QNetworkReply*)), this, SLOT(httpRequestDone(QNetworkReply*)));
}
void TrackerClient::start(const MetaInfo &info)
@@ -82,15 +83,13 @@ void TrackerClient::startSeeding()
void TrackerClient::stop()
{
lastTrackerRequest = true;
- http.abort();
fetchPeerList();
}
void TrackerClient::timerEvent(QTimerEvent *event)
{
if (event->timerId() == requestIntervalTimer) {
- if (http.state() == QHttp::Unconnected)
- fetchPeerList();
+ fetchPeerList();
} else {
QObject::timerEvent(event);
}
@@ -148,32 +147,35 @@ void TrackerClient::fetchPeerList()
if (!trackerId.isEmpty())
query += "&trackerid=" + trackerId;
- http.setHost(url.host(), url.port() == -1 ? 80 : url.port());
- if (!url.userName().isEmpty())
- http.setUser(url.userName(), url.password());
- http.get(query);
+ QNetworkRequest req(url);
+ if (!url.userName().isEmpty()) {
+ uname = url.userName();
+ pwd = url.password();
+ connect(&http, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(provideAuthentication(QNetworkReply*,QAuthenticator*)));
+ }
+ http.get(req);
}
-void TrackerClient::httpRequestDone(bool error)
+void TrackerClient::httpRequestDone(QNetworkReply *reply)
{
+ reply->deleteLater();
if (lastTrackerRequest) {
emit stopped();
return;
}
- if (error) {
- emit connectionError(http.error());
+ if (reply->error() != QNetworkReply::NoError) {
+ emit connectionError(reply->error());
return;
}
- QByteArray response = http.readAll();
- http.abort();
+ QByteArray response = reply->readAll();
+ reply->abort();
BencodeParser parser;
if (!parser.parse(response)) {
qWarning("Error parsing bencode response from tracker: %s",
qPrintable(parser.errorString()));
- http.abort();
return;
}
@@ -234,3 +236,10 @@ void TrackerClient::httpRequestDone(bool error)
emit peerListUpdated(peers);
}
}
+
+void TrackerClient::provideAuthentication(QNetworkReply *reply, QAuthenticator *auth)
+{
+ Q_UNUSED(reply);
+ auth->setUser(uname);
+ auth->setPassword(pwd);
+}