Browse Source

Code clean up

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
d198451bb0
  1. 26
      src/downloadthread.cpp
  2. 30
      src/downloadthread.h

26
src/downloadthread.cpp

@ -45,9 +45,9 @@
/** Download Thread **/ /** Download Thread **/
downloadThread::downloadThread(QObject* parent) : QObject(parent) { downloadThread::downloadThread(QObject* parent) : QObject(parent) {
connect(&networkManager, SIGNAL(finished (QNetworkReply*)), this, SLOT(processDlFinished(QNetworkReply*))); connect(&m_networkManager, SIGNAL(finished (QNetworkReply*)), this, SLOT(processDlFinished(QNetworkReply*)));
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
connect(&networkManager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(ignoreSslErrors(QNetworkReply*,QList<QSslError>))); connect(&m_networkManager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(ignoreSslErrors(QNetworkReply*,QList<QSslError>)));
#endif #endif
} }
@ -63,13 +63,13 @@ void downloadThread::processDlFinished(QNetworkReply* reply) {
if(redirection.isValid()) { if(redirection.isValid()) {
// We should redirect // We should redirect
qDebug("Redirecting from %s to %s", qPrintable(url), qPrintable(redirection.toUrl().toString())); qDebug("Redirecting from %s to %s", qPrintable(url), qPrintable(redirection.toUrl().toString()));
redirect_mapping.insert(redirection.toUrl().toString(), url); m_redirectMapping.insert(redirection.toUrl().toString(), url);
downloadUrl(redirection.toUrl().toString()); downloadUrl(redirection.toUrl().toString());
return; return;
} }
// Checking if it was redirecting, restoring initial URL // Checking if it was redirecting, restoring initial URL
if(redirect_mapping.contains(url)) { if(m_redirectMapping.contains(url)) {
url = redirect_mapping.take(url); url = m_redirectMapping.take(url);
} }
// Success // Success
QString filePath; QString filePath;
@ -104,7 +104,7 @@ void downloadThread::processDlFinished(QNetworkReply* reply) {
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
void downloadThread::loadCookies(const QString &host_name, QString url) { void downloadThread::loadCookies(const QString &host_name, QString url) {
const QList<QByteArray> raw_cookies = RssSettings().getHostNameCookies(host_name); const QList<QByteArray> raw_cookies = RssSettings().getHostNameCookies(host_name);
QNetworkCookieJar *cookie_jar = networkManager.cookieJar(); QNetworkCookieJar *cookie_jar = m_networkManager.cookieJar();
QList<QNetworkCookie> cookies; QList<QNetworkCookie> cookies;
qDebug("Loading cookies for host name: %s", qPrintable(host_name)); qDebug("Loading cookies for host name: %s", qPrintable(host_name));
foreach(const QByteArray& raw_cookie, raw_cookies) { foreach(const QByteArray& raw_cookie, raw_cookies) {
@ -115,7 +115,7 @@ void downloadThread::loadCookies(const QString &host_name, QString url) {
} }
} }
cookie_jar->setCookiesFromUrl(cookies, url); cookie_jar->setCookiesFromUrl(cookies, url);
networkManager.setCookieJar(cookie_jar); m_networkManager.setCookieJar(cookie_jar);
} }
#endif #endif
@ -148,12 +148,12 @@ QNetworkReply* downloadThread::downloadUrl(QString url){
// Web server banning // Web server banning
request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5"); request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5");
qDebug("Downloading %s...", request.url().toEncoded().data()); qDebug("Downloading %s...", request.url().toEncoded().data());
qDebug("%d cookies for this URL", networkManager.cookieJar()->cookiesForUrl(url).size()); qDebug("%d cookies for this URL", m_networkManager.cookieJar()->cookiesForUrl(url).size());
for(int i=0; i<networkManager.cookieJar()->cookiesForUrl(url).size(); ++i) { for(int i=0; i<m_networkManager.cookieJar()->cookiesForUrl(url).size(); ++i) {
qDebug("%s=%s", networkManager.cookieJar()->cookiesForUrl(url).at(i).name().data(), networkManager.cookieJar()->cookiesForUrl(url).at(i).value().data()); qDebug("%s=%s", m_networkManager.cookieJar()->cookiesForUrl(url).at(i).name().data(), m_networkManager.cookieJar()->cookiesForUrl(url).at(i).value().data());
qDebug("Domain: %s, Path: %s", qPrintable(networkManager.cookieJar()->cookiesForUrl(url).at(i).domain()), qPrintable(networkManager.cookieJar()->cookiesForUrl(url).at(i).path())); qDebug("Domain: %s, Path: %s", qPrintable(m_networkManager.cookieJar()->cookiesForUrl(url).at(i).domain()), qPrintable(m_networkManager.cookieJar()->cookiesForUrl(url).at(i).path()));
} }
return networkManager.get(request); return m_networkManager.get(request);
} }
void downloadThread::checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal) { void downloadThread::checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal) {
@ -200,7 +200,7 @@ void downloadThread::applyProxySettings() {
} else { } else {
proxy.setType(QNetworkProxy::NoProxy); proxy.setType(QNetworkProxy::NoProxy);
} }
networkManager.setProxy(proxy); m_networkManager.setProxy(proxy);
} }
QString downloadThread::errorCodeToString(QNetworkReply::NetworkError status) { QString downloadThread::errorCodeToString(QNetworkReply::NetworkError status) {

30
src/downloadthread.h

@ -41,33 +41,33 @@ class QNetworkAccessManager;
class downloadThread : public QObject { class downloadThread : public QObject {
Q_OBJECT Q_OBJECT
private: public:
QNetworkAccessManager networkManager; downloadThread(QObject* parent = 0);
QHash<QString, QString> redirect_mapping; QNetworkReply* downloadUrl(QString url);
void downloadTorrentUrl(QString url);
//void setProxy(QString IP, int port, QString username, QString password);
signals: signals:
void downloadFinished(QString url, QString file_path); void downloadFinished(QString url, QString file_path);
void downloadFailure(QString url, QString reason); void downloadFailure(QString url, QString reason);
public: private slots:
downloadThread(QObject* parent); void processDlFinished(QNetworkReply* reply);
QNetworkReply* downloadUrl(QString url); void checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal);
void downloadTorrentUrl(QString url); #ifndef QT_NO_OPENSSL
//void setProxy(QString IP, int port, QString username, QString password); void ignoreSslErrors(QNetworkReply*,QList<QSslError>);
#endif
protected: private:
QString errorCodeToString(QNetworkReply::NetworkError status); QString errorCodeToString(QNetworkReply::NetworkError status);
void applyProxySettings(); void applyProxySettings();
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
void loadCookies(const QString &host_name, QString url); void loadCookies(const QString &host_name, QString url);
#endif #endif
protected slots: private:
void processDlFinished(QNetworkReply* reply); QNetworkAccessManager m_networkManager;
void checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal); QHash<QString, QString> m_redirectMapping;
#ifndef QT_NO_OPENSSL
void ignoreSslErrors(QNetworkReply*,QList<QSslError>);
#endif
}; };

Loading…
Cancel
Save