Some more code clean up

This commit is contained in:
Christophe Dumez 2011-01-24 17:58:57 +00:00
parent 6ff7c6ed06
commit 783004ae58
11 changed files with 28 additions and 33 deletions

View File

@ -44,14 +44,14 @@
/** Download Thread **/
downloadThread::downloadThread(QObject* parent) : QObject(parent) {
DownloadThread::DownloadThread(QObject* parent) : QObject(parent) {
connect(&m_networkManager, SIGNAL(finished (QNetworkReply*)), this, SLOT(processDlFinished(QNetworkReply*)));
#ifndef QT_NO_OPENSSL
connect(&m_networkManager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(ignoreSslErrors(QNetworkReply*,QList<QSslError>)));
#endif
}
void downloadThread::processDlFinished(QNetworkReply* reply) {
void DownloadThread::processDlFinished(QNetworkReply* reply) {
QString url = reply->url().toString();
qDebug("Download finished: %s", qPrintable(url));
// Check if the request was successful
@ -100,7 +100,7 @@ void downloadThread::processDlFinished(QNetworkReply* reply) {
}
#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);
QNetworkCookieJar *cookie_jar = m_networkManager.cookieJar();
QList<QNetworkCookie> cookies;
@ -117,19 +117,13 @@ void downloadThread::loadCookies(const QString &host_name, QString url) {
}
#endif
void downloadThread::downloadTorrentUrl(const QString &url) {
#ifndef DISABLE_GUI
// Load cookies
QString host_name = QUrl::fromEncoded(url.toLocal8Bit()).host();
if(!host_name.isEmpty())
loadCookies(host_name, url);
#endif
void DownloadThread::downloadTorrentUrl(const QString &url) {
// Process request
QNetworkReply *reply = downloadUrl(url);
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(checkDownloadSize(qint64,qint64)));
}
QNetworkReply* downloadThread::downloadUrl(const QString &url){
QNetworkReply* DownloadThread::downloadUrl(const QString &url){
// Update proxy settings
applyProxySettings();
#ifndef DISABLE_GUI
@ -154,8 +148,9 @@ QNetworkReply* downloadThread::downloadUrl(const QString &url){
return m_networkManager.get(request);
}
void downloadThread::checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal) {
QNetworkReply *reply = static_cast<QNetworkReply*>(sender());
void DownloadThread::checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal) {
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
if(!reply) return;
if(bytesTotal > 0) {
// Total number of bytes is available
if(bytesTotal > 1048576) {
@ -174,7 +169,7 @@ void downloadThread::checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal)
}
}
void downloadThread::applyProxySettings() {
void DownloadThread::applyProxySettings() {
QNetworkProxy proxy;
const Preferences pref;
if(pref.isProxyEnabled()) {
@ -202,7 +197,7 @@ void downloadThread::applyProxySettings() {
m_networkManager.setProxy(proxy);
}
QString downloadThread::errorCodeToString(QNetworkReply::NetworkError status) {
QString DownloadThread::errorCodeToString(QNetworkReply::NetworkError status) {
switch(status){
case QNetworkReply::HostNotFoundError:
return tr("The remote host name was not found (invalid hostname)");
@ -252,7 +247,7 @@ QString downloadThread::errorCodeToString(QNetworkReply::NetworkError status) {
}
#ifndef QT_NO_OPENSSL
void downloadThread::ignoreSslErrors(QNetworkReply* reply, const QList<QSslError> &errors) {
void DownloadThread::ignoreSslErrors(QNetworkReply* reply, const QList<QSslError> &errors) {
Q_UNUSED(errors)
// Ignore all SSL errors
reply->ignoreSslErrors();

View File

@ -38,11 +38,11 @@
class QNetworkAccessManager;
class downloadThread : public QObject {
class DownloadThread : public QObject {
Q_OBJECT
public:
downloadThread(QObject* parent = 0);
DownloadThread(QObject* parent = 0);
QNetworkReply* downloadUrl(const QString &url);
void downloadTorrentUrl(const QString &url);
//void setProxy(QString IP, int port, QString username, QString password);

View File

@ -66,7 +66,7 @@ public:
public slots:
void on_uTorrentListButton_clicked() {
downloadThread *d = new downloadThread(this);
DownloadThread *d = new DownloadThread(this);
connect(d, SIGNAL(downloadFinished(QString,QString)), this, SLOT(parseUTorrentList(QString,QString)));
connect(d, SIGNAL(downloadFailure(QString,QString)), this, SLOT(getTrackerError(QString,QString)));
//Just to show that it takes times

View File

@ -134,7 +134,7 @@ QBtSession::QBtSession()
connect(&resumeDataTimer, SIGNAL(timeout()), this, SLOT(saveTempFastResumeData()));
resumeDataTimer.start(180000); // 3min
// To download from urls
downloader = new downloadThread(this);
downloader = new DownloadThread(this);
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString)));
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
appendLabelToSavePath = pref.appendTorrentLabel();
@ -2428,7 +2428,7 @@ void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QStrin
savepathLabel_fromurl[qurl] = qMakePair(save_path, label);
url_skippingDlg << qurl;
// Launch downloader thread
downloader->downloadUrl(url);
downloader->downloadTorrentUrl(url);
}
// Add to Bittorrent session the downloaded torrent file

View File

@ -53,7 +53,7 @@
#define MAX_SAMPLES 20
class downloadThread;
class DownloadThread;
class QTimer;
class FilterParserThread;
class HttpServer;
@ -224,7 +224,7 @@ private:
// Ratio
QPointer<QTimer> BigRatioTimer;
// HTTP
QPointer<downloadThread> downloader;
DownloadThread* downloader;
// File System
ScanFoldersModel *m_scanFolders;
// Console / Log

View File

@ -313,11 +313,11 @@ short RssFeed::readDoc(QIODevice* device) {
}
void RssFeed::resizeList() {
unsigned int max_articles = RssSettings().getRSSMaxArticlesPerFeed();
unsigned int nb_articles = this->size();
const unsigned int max_articles = RssSettings().getRSSMaxArticlesPerFeed();
const unsigned int nb_articles = this->size();
if(nb_articles > max_articles) {
QList<RssArticle*> listItem = RssManager::sortNewsList(this->values());
int excess = nb_articles - max_articles;
const int excess = nb_articles - max_articles;
for(int i=0; i<excess; ++i){
RssArticle *lastItem = listItem.takeLast();
delete this->take(lastItem->getId());

View File

@ -38,7 +38,7 @@
#include "rssfeed.h"
RssFolder::RssFolder(RssFolder *parent, QString name): parent(parent), name(name) {
downloader = new downloadThread(this);
downloader = new DownloadThread(this);
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processFinishedDownload(QString, QString)));
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
}

View File

@ -36,7 +36,7 @@
#include "rssfile.h"
class RssArticle;
class downloadThread;
class DownloadThread;
class RssFeed;
class RssFolder: public RssFile, public QHash<QString, RssFile*> {
@ -77,7 +77,7 @@ public slots:
private:
RssFolder *parent;
downloadThread *downloader;
DownloadThread *downloader;
QString name;
};

View File

@ -56,7 +56,7 @@ engineSelectDlg::engineSelectDlg(QWidget *parent, SupportedEngines *supported_en
actionUninstall->setIcon(IconProvider::instance()->getIcon("list-remove"));
connect(actionEnable, SIGNAL(toggled(bool)), this, SLOT(enableSelection(bool)));
connect(pluginsTree, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayContextMenu(const QPoint&)));
downloader = new downloadThread(this);
downloader = new DownloadThread(this);
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString)));
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
loadSupportedSearchEngines();

View File

@ -34,14 +34,14 @@
#include "ui_engineselect.h"
#include "supportedengines.h"
class downloadThread;
class DownloadThread;
class QDropEvent;
class engineSelectDlg : public QDialog, public Ui::engineSelect{
Q_OBJECT
private:
downloadThread *downloader;
DownloadThread *downloader;
SupportedEngines *supported_engines;
public:

View File

@ -41,7 +41,7 @@
#include "searchtab.h"
#include "supportedengines.h"
class downloadThread;
class DownloadThread;
class QTimer;
class SearchEngine;
class MainWindow;