Code clean up

This commit is contained in:
Christophe Dumez 2010-12-02 17:27:01 +00:00
parent ebf252ce86
commit d198451bb0
2 changed files with 30 additions and 30 deletions

View file

@ -45,9 +45,9 @@
/** Download Thread **/
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
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
}
@ -63,13 +63,13 @@ void downloadThread::processDlFinished(QNetworkReply* reply) {
if(redirection.isValid()) {
// We should redirect
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());
return;
}
// Checking if it was redirecting, restoring initial URL
if(redirect_mapping.contains(url)) {
url = redirect_mapping.take(url);
if(m_redirectMapping.contains(url)) {
url = m_redirectMapping.take(url);
}
// Success
QString filePath;
@ -104,7 +104,7 @@ void downloadThread::processDlFinished(QNetworkReply* reply) {
#ifndef DISABLE_GUI
void downloadThread::loadCookies(const QString &host_name, QString url) {
const QList<QByteArray> raw_cookies = RssSettings().getHostNameCookies(host_name);
QNetworkCookieJar *cookie_jar = networkManager.cookieJar();
QNetworkCookieJar *cookie_jar = m_networkManager.cookieJar();
QList<QNetworkCookie> cookies;
qDebug("Loading cookies for host name: %s", qPrintable(host_name));
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);
networkManager.setCookieJar(cookie_jar);
m_networkManager.setCookieJar(cookie_jar);
}
#endif
@ -148,12 +148,12 @@ QNetworkReply* downloadThread::downloadUrl(QString url){
// 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");
qDebug("Downloading %s...", request.url().toEncoded().data());
qDebug("%d cookies for this URL", networkManager.cookieJar()->cookiesForUrl(url).size());
for(int i=0; i<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("Domain: %s, Path: %s", qPrintable(networkManager.cookieJar()->cookiesForUrl(url).at(i).domain()), qPrintable(networkManager.cookieJar()->cookiesForUrl(url).at(i).path()));
qDebug("%d cookies for this URL", m_networkManager.cookieJar()->cookiesForUrl(url).size());
for(int i=0; i<m_networkManager.cookieJar()->cookiesForUrl(url).size(); ++i) {
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(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) {
@ -200,7 +200,7 @@ void downloadThread::applyProxySettings() {
} else {
proxy.setType(QNetworkProxy::NoProxy);
}
networkManager.setProxy(proxy);
m_networkManager.setProxy(proxy);
}
QString downloadThread::errorCodeToString(QNetworkReply::NetworkError status) {

View file

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