From b3ce4470ae2ece0c03c66684ca3d9dd13955786b Mon Sep 17 00:00:00 2001 From: "Jonas M. Gastal" Date: Thu, 22 Dec 2011 17:42:49 -0200 Subject: Removing QHttp class, its tests and its usage in examples. Task-number: QTBUG-22750 Change-Id: I161fad772bfb26797e6ee9d69da925b6747c371f Reviewed-by: Lars Knoll --- examples/network/torrent/trackerclient.cpp | 37 +++++++++++++++++++----------- examples/network/torrent/trackerclient.h | 13 +++++++---- 2 files changed, 32 insertions(+), 18 deletions(-) (limited to 'examples') 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 +#include 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); +} diff --git a/examples/network/torrent/trackerclient.h b/examples/network/torrent/trackerclient.h index 02dd5f91e7..723b3aa4b7 100644 --- a/examples/network/torrent/trackerclient.h +++ b/examples/network/torrent/trackerclient.h @@ -45,7 +45,9 @@ #include #include #include -#include +#include +#include +#include #include "metainfo.h" #include "torrentclient.h" @@ -64,7 +66,7 @@ public: void startSeeding(); signals: - void connectionError(QHttp::Error error); + void connectionError(QNetworkReply::NetworkError error); void failure(const QString &reason); void warning(const QString &message); @@ -80,20 +82,23 @@ protected: private slots: void fetchPeerList(); - void httpRequestDone(bool error); + void httpRequestDone(QNetworkReply *reply); + void provideAuthentication(QNetworkReply *reply, QAuthenticator *auth); private: TorrentClient *torrentDownloader; int requestInterval; int requestIntervalTimer; - QHttp http; + QNetworkAccessManager http; MetaInfo metaInfo; QByteArray trackerId; QList peers; qint64 uploadedBytes; qint64 downloadedBytes; qint64 length; + QString uname; + QString pwd; bool firstTrackerRequest; bool lastTrackerRequest; -- cgit v1.2.3