From 783004ae580c07f6bea81ad17cdb958f8ad94180 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 24 Jan 2011 17:58:57 +0000 Subject: [PATCH] Some more code clean up --- src/downloadthread.cpp | 27 +++++++++++---------------- src/downloadthread.h | 4 ++-- src/properties/trackersadditiondlg.h | 2 +- src/qtlibtorrent/qbtsession.cpp | 4 ++-- src/qtlibtorrent/qbtsession.h | 4 ++-- src/rss/rssfeed.cpp | 6 +++--- src/rss/rssfolder.cpp | 2 +- src/rss/rssfolder.h | 4 ++-- src/searchengine/engineselectdlg.cpp | 2 +- src/searchengine/engineselectdlg.h | 4 ++-- src/searchengine/searchengine.h | 2 +- 11 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/downloadthread.cpp b/src/downloadthread.cpp index 6ac8c0a2a..a10cae002 100644 --- a/src/downloadthread.cpp +++ b/src/downloadthread.cpp @@ -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)), this, SLOT(ignoreSslErrors(QNetworkReply*,QList))); #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 raw_cookies = RssSettings().getHostNameCookies(host_name); QNetworkCookieJar *cookie_jar = m_networkManager.cookieJar(); QList 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(sender()); +void DownloadThread::checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal) { + QNetworkReply *reply = qobject_cast(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 &errors) { +void DownloadThread::ignoreSslErrors(QNetworkReply* reply, const QList &errors) { Q_UNUSED(errors) // Ignore all SSL errors reply->ignoreSslErrors(); diff --git a/src/downloadthread.h b/src/downloadthread.h index 8fd9781be..887630ca2 100644 --- a/src/downloadthread.h +++ b/src/downloadthread.h @@ -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); diff --git a/src/properties/trackersadditiondlg.h b/src/properties/trackersadditiondlg.h index 56bef79cf..71170a047 100644 --- a/src/properties/trackersadditiondlg.h +++ b/src/properties/trackersadditiondlg.h @@ -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 diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index c68fcebc6..323e1376a 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -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 diff --git a/src/qtlibtorrent/qbtsession.h b/src/qtlibtorrent/qbtsession.h index d8b8efc97..c300d9ed9 100644 --- a/src/qtlibtorrent/qbtsession.h +++ b/src/qtlibtorrent/qbtsession.h @@ -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 BigRatioTimer; // HTTP - QPointer downloader; + DownloadThread* downloader; // File System ScanFoldersModel *m_scanFolders; // Console / Log diff --git a/src/rss/rssfeed.cpp b/src/rss/rssfeed.cpp index 37b56db68..a67519023 100644 --- a/src/rss/rssfeed.cpp +++ b/src/rss/rssfeed.cpp @@ -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 listItem = RssManager::sortNewsList(this->values()); - int excess = nb_articles - max_articles; + const int excess = nb_articles - max_articles; for(int i=0; itake(lastItem->getId()); diff --git a/src/rss/rssfolder.cpp b/src/rss/rssfolder.cpp index 3478d30f4..2eeaa7cc5 100644 --- a/src/rss/rssfolder.cpp +++ b/src/rss/rssfolder.cpp @@ -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))); } diff --git a/src/rss/rssfolder.h b/src/rss/rssfolder.h index 3152b93a6..1bd6eba24 100644 --- a/src/rss/rssfolder.h +++ b/src/rss/rssfolder.h @@ -36,7 +36,7 @@ #include "rssfile.h" class RssArticle; -class downloadThread; +class DownloadThread; class RssFeed; class RssFolder: public RssFile, public QHash { @@ -77,7 +77,7 @@ public slots: private: RssFolder *parent; - downloadThread *downloader; + DownloadThread *downloader; QString name; }; diff --git a/src/searchengine/engineselectdlg.cpp b/src/searchengine/engineselectdlg.cpp index 6ec2e97be..3f5021f3f 100644 --- a/src/searchengine/engineselectdlg.cpp +++ b/src/searchengine/engineselectdlg.cpp @@ -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(); diff --git a/src/searchengine/engineselectdlg.h b/src/searchengine/engineselectdlg.h index 16be96c6e..4141a5091 100644 --- a/src/searchengine/engineselectdlg.h +++ b/src/searchengine/engineselectdlg.h @@ -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: diff --git a/src/searchengine/searchengine.h b/src/searchengine/searchengine.h index 3316979ac..a86b52ad1 100644 --- a/src/searchengine/searchengine.h +++ b/src/searchengine/searchengine.h @@ -41,7 +41,7 @@ #include "searchtab.h" #include "supportedengines.h" -class downloadThread; +class DownloadThread; class QTimer; class SearchEngine; class MainWindow;