From: Flavio Date: Mon, 28 Jan 2013 09:32:02 +0000 (+0100) Subject: Fix retry X-Git-Tag: 2.0~21 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=850603e0b4cc538e5e5b9d656f3dcc955a3920ea;p=minitube Fix retry --- diff --git a/src/networkaccess.cpp b/src/networkaccess.cpp index e779de8..4ed98b7 100644 --- a/src/networkaccess.cpp +++ b/src/networkaccess.cpp @@ -14,8 +14,11 @@ const QString USER_AGENT = QString(Constants::NAME) const QString USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"; -NetworkReply::NetworkReply(QNetworkReply *networkReply) : QObject(networkReply) { - this->networkReply = networkReply; +NetworkReply::NetworkReply(QNetworkReply *networkReply) : + QObject(networkReply), + networkReply(networkReply), + retryCount(0) { + setupReply(); readTimeoutTimer = new QTimer(this); @@ -48,7 +51,7 @@ void NetworkReply::finished() { setupReply(); readTimeoutTimer->start(); return; - } else qWarning("Redirection not supported"); + } else qWarning() << "Redirection not supported" << networkReply->url().toEncoded(); } if (receivers(SIGNAL(data(QByteArray))) > 0) @@ -92,10 +95,16 @@ void NetworkReply::readTimeout() { return; } + if (retryCount > 3) { + emit error(networkReply); + return; + } QNetworkReply *retryReply = The::http()->request(networkReply->url(), networkReply->operation()); setParent(retryReply); networkReply = retryReply; setupReply(); + retryCount++; + readTimeoutTimer->start(); } /* --- NetworkAccess --- */ diff --git a/src/networkaccess.h b/src/networkaccess.h index c9a5c18..a595ac7 100644 --- a/src/networkaccess.h +++ b/src/networkaccess.h @@ -14,22 +14,24 @@ class NetworkReply : public QObject { public: NetworkReply(QNetworkReply* networkReply); - -public slots: - void finished(); - void requestError(QNetworkReply::NetworkError); - void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); - void readTimeout(); + QNetworkReply* getNetworkReply() { return networkReply; } signals: void data(QByteArray); void error(QNetworkReply*); void finished(QNetworkReply*); +private slots: + void finished(); + void requestError(QNetworkReply::NetworkError); + void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); + void readTimeout(); + private: void setupReply(); QNetworkReply *networkReply; QTimer *readTimeoutTimer; + int retryCount; };