Browse Source

Some more code clean up

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
783004ae58
  1. 27
      src/downloadthread.cpp
  2. 4
      src/downloadthread.h
  3. 2
      src/properties/trackersadditiondlg.h
  4. 4
      src/qtlibtorrent/qbtsession.cpp
  5. 4
      src/qtlibtorrent/qbtsession.h
  6. 6
      src/rss/rssfeed.cpp
  7. 2
      src/rss/rssfolder.cpp
  8. 4
      src/rss/rssfolder.h
  9. 2
      src/searchengine/engineselectdlg.cpp
  10. 4
      src/searchengine/engineselectdlg.h
  11. 2
      src/searchengine/searchengine.h

27
src/downloadthread.cpp

@ -44,14 +44,14 @@ @@ -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) { @@ -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) { @@ -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){ @@ -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) @@ -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() { @@ -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) { @@ -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();

4
src/downloadthread.h

@ -38,11 +38,11 @@ @@ -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);

2
src/properties/trackersadditiondlg.h

@ -66,7 +66,7 @@ public: @@ -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

4
src/qtlibtorrent/qbtsession.cpp

@ -134,7 +134,7 @@ QBtSession::QBtSession() @@ -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 @@ -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

4
src/qtlibtorrent/qbtsession.h

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

6
src/rss/rssfeed.cpp

@ -313,11 +313,11 @@ short RssFeed::readDoc(QIODevice* device) { @@ -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());

2
src/rss/rssfolder.cpp

@ -38,7 +38,7 @@ @@ -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)));
}

4
src/rss/rssfolder.h

@ -36,7 +36,7 @@ @@ -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: @@ -77,7 +77,7 @@ public slots:
private:
RssFolder *parent;
downloadThread *downloader;
DownloadThread *downloader;
QString name;
};

2
src/searchengine/engineselectdlg.cpp

@ -56,7 +56,7 @@ engineSelectDlg::engineSelectDlg(QWidget *parent, SupportedEngines *supported_en @@ -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();

4
src/searchengine/engineselectdlg.h

@ -34,14 +34,14 @@ @@ -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:

2
src/searchengine/searchengine.h

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

Loading…
Cancel
Save