mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-03-12 05:11:24 +00:00
Some more code clean up
This commit is contained in:
parent
6ff7c6ed06
commit
783004ae58
@ -44,14 +44,14 @@
|
|||||||
|
|
||||||
/** Download Thread **/
|
/** Download Thread **/
|
||||||
|
|
||||||
downloadThread::downloadThread(QObject* parent) : QObject(parent) {
|
DownloadThread::DownloadThread(QObject* parent) : QObject(parent) {
|
||||||
connect(&m_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(&m_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
|
||||||
}
|
}
|
||||||
|
|
||||||
void downloadThread::processDlFinished(QNetworkReply* reply) {
|
void DownloadThread::processDlFinished(QNetworkReply* reply) {
|
||||||
QString url = reply->url().toString();
|
QString url = reply->url().toString();
|
||||||
qDebug("Download finished: %s", qPrintable(url));
|
qDebug("Download finished: %s", qPrintable(url));
|
||||||
// Check if the request was successful
|
// Check if the request was successful
|
||||||
@ -100,7 +100,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 = m_networkManager.cookieJar();
|
QNetworkCookieJar *cookie_jar = m_networkManager.cookieJar();
|
||||||
QList<QNetworkCookie> cookies;
|
QList<QNetworkCookie> cookies;
|
||||||
@ -117,19 +117,13 @@ void downloadThread::loadCookies(const QString &host_name, QString url) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void downloadThread::downloadTorrentUrl(const QString &url) {
|
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
|
|
||||||
// Process request
|
// Process request
|
||||||
QNetworkReply *reply = downloadUrl(url);
|
QNetworkReply *reply = downloadUrl(url);
|
||||||
connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(checkDownloadSize(qint64,qint64)));
|
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
|
// Update proxy settings
|
||||||
applyProxySettings();
|
applyProxySettings();
|
||||||
#ifndef DISABLE_GUI
|
#ifndef DISABLE_GUI
|
||||||
@ -154,8 +148,9 @@ QNetworkReply* downloadThread::downloadUrl(const QString &url){
|
|||||||
return m_networkManager.get(request);
|
return m_networkManager.get(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
void downloadThread::checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal) {
|
void DownloadThread::checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal) {
|
||||||
QNetworkReply *reply = static_cast<QNetworkReply*>(sender());
|
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
||||||
|
if(!reply) return;
|
||||||
if(bytesTotal > 0) {
|
if(bytesTotal > 0) {
|
||||||
// Total number of bytes is available
|
// Total number of bytes is available
|
||||||
if(bytesTotal > 1048576) {
|
if(bytesTotal > 1048576) {
|
||||||
@ -174,7 +169,7 @@ void downloadThread::checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void downloadThread::applyProxySettings() {
|
void DownloadThread::applyProxySettings() {
|
||||||
QNetworkProxy proxy;
|
QNetworkProxy proxy;
|
||||||
const Preferences pref;
|
const Preferences pref;
|
||||||
if(pref.isProxyEnabled()) {
|
if(pref.isProxyEnabled()) {
|
||||||
@ -202,7 +197,7 @@ void downloadThread::applyProxySettings() {
|
|||||||
m_networkManager.setProxy(proxy);
|
m_networkManager.setProxy(proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString downloadThread::errorCodeToString(QNetworkReply::NetworkError status) {
|
QString DownloadThread::errorCodeToString(QNetworkReply::NetworkError status) {
|
||||||
switch(status){
|
switch(status){
|
||||||
case QNetworkReply::HostNotFoundError:
|
case QNetworkReply::HostNotFoundError:
|
||||||
return tr("The remote host name was not found (invalid hostname)");
|
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
|
#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)
|
Q_UNUSED(errors)
|
||||||
// Ignore all SSL errors
|
// Ignore all SSL errors
|
||||||
reply->ignoreSslErrors();
|
reply->ignoreSslErrors();
|
||||||
|
@ -38,11 +38,11 @@
|
|||||||
|
|
||||||
class QNetworkAccessManager;
|
class QNetworkAccessManager;
|
||||||
|
|
||||||
class downloadThread : public QObject {
|
class DownloadThread : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
downloadThread(QObject* parent = 0);
|
DownloadThread(QObject* parent = 0);
|
||||||
QNetworkReply* downloadUrl(const QString &url);
|
QNetworkReply* downloadUrl(const QString &url);
|
||||||
void downloadTorrentUrl(const QString &url);
|
void downloadTorrentUrl(const QString &url);
|
||||||
//void setProxy(QString IP, int port, QString username, QString password);
|
//void setProxy(QString IP, int port, QString username, QString password);
|
||||||
|
@ -66,7 +66,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void on_uTorrentListButton_clicked() {
|
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(downloadFinished(QString,QString)), this, SLOT(parseUTorrentList(QString,QString)));
|
||||||
connect(d, SIGNAL(downloadFailure(QString,QString)), this, SLOT(getTrackerError(QString,QString)));
|
connect(d, SIGNAL(downloadFailure(QString,QString)), this, SLOT(getTrackerError(QString,QString)));
|
||||||
//Just to show that it takes times
|
//Just to show that it takes times
|
||||||
|
@ -134,7 +134,7 @@ QBtSession::QBtSession()
|
|||||||
connect(&resumeDataTimer, SIGNAL(timeout()), this, SLOT(saveTempFastResumeData()));
|
connect(&resumeDataTimer, SIGNAL(timeout()), this, SLOT(saveTempFastResumeData()));
|
||||||
resumeDataTimer.start(180000); // 3min
|
resumeDataTimer.start(180000); // 3min
|
||||||
// To download from urls
|
// 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(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString)));
|
||||||
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
|
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
|
||||||
appendLabelToSavePath = pref.appendTorrentLabel();
|
appendLabelToSavePath = pref.appendTorrentLabel();
|
||||||
@ -2428,7 +2428,7 @@ void QBtSession::downloadUrlAndSkipDialog(QString url, QString save_path, QStrin
|
|||||||
savepathLabel_fromurl[qurl] = qMakePair(save_path, label);
|
savepathLabel_fromurl[qurl] = qMakePair(save_path, label);
|
||||||
url_skippingDlg << qurl;
|
url_skippingDlg << qurl;
|
||||||
// Launch downloader thread
|
// Launch downloader thread
|
||||||
downloader->downloadUrl(url);
|
downloader->downloadTorrentUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to Bittorrent session the downloaded torrent file
|
// Add to Bittorrent session the downloaded torrent file
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
#define MAX_SAMPLES 20
|
#define MAX_SAMPLES 20
|
||||||
|
|
||||||
class downloadThread;
|
class DownloadThread;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
class FilterParserThread;
|
class FilterParserThread;
|
||||||
class HttpServer;
|
class HttpServer;
|
||||||
@ -224,7 +224,7 @@ private:
|
|||||||
// Ratio
|
// Ratio
|
||||||
QPointer<QTimer> BigRatioTimer;
|
QPointer<QTimer> BigRatioTimer;
|
||||||
// HTTP
|
// HTTP
|
||||||
QPointer<downloadThread> downloader;
|
DownloadThread* downloader;
|
||||||
// File System
|
// File System
|
||||||
ScanFoldersModel *m_scanFolders;
|
ScanFoldersModel *m_scanFolders;
|
||||||
// Console / Log
|
// Console / Log
|
||||||
|
@ -313,11 +313,11 @@ short RssFeed::readDoc(QIODevice* device) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RssFeed::resizeList() {
|
void RssFeed::resizeList() {
|
||||||
unsigned int max_articles = RssSettings().getRSSMaxArticlesPerFeed();
|
const unsigned int max_articles = RssSettings().getRSSMaxArticlesPerFeed();
|
||||||
unsigned int nb_articles = this->size();
|
const unsigned int nb_articles = this->size();
|
||||||
if(nb_articles > max_articles) {
|
if(nb_articles > max_articles) {
|
||||||
QList<RssArticle*> listItem = RssManager::sortNewsList(this->values());
|
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){
|
for(int i=0; i<excess; ++i){
|
||||||
RssArticle *lastItem = listItem.takeLast();
|
RssArticle *lastItem = listItem.takeLast();
|
||||||
delete this->take(lastItem->getId());
|
delete this->take(lastItem->getId());
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
#include "rssfeed.h"
|
#include "rssfeed.h"
|
||||||
|
|
||||||
RssFolder::RssFolder(RssFolder *parent, QString name): parent(parent), name(name) {
|
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(downloadFinished(QString, QString)), this, SLOT(processFinishedDownload(QString, QString)));
|
||||||
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
|
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include "rssfile.h"
|
#include "rssfile.h"
|
||||||
|
|
||||||
class RssArticle;
|
class RssArticle;
|
||||||
class downloadThread;
|
class DownloadThread;
|
||||||
class RssFeed;
|
class RssFeed;
|
||||||
|
|
||||||
class RssFolder: public RssFile, public QHash<QString, RssFile*> {
|
class RssFolder: public RssFile, public QHash<QString, RssFile*> {
|
||||||
@ -77,7 +77,7 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
RssFolder *parent;
|
RssFolder *parent;
|
||||||
downloadThread *downloader;
|
DownloadThread *downloader;
|
||||||
QString name;
|
QString name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ engineSelectDlg::engineSelectDlg(QWidget *parent, SupportedEngines *supported_en
|
|||||||
actionUninstall->setIcon(IconProvider::instance()->getIcon("list-remove"));
|
actionUninstall->setIcon(IconProvider::instance()->getIcon("list-remove"));
|
||||||
connect(actionEnable, SIGNAL(toggled(bool)), this, SLOT(enableSelection(bool)));
|
connect(actionEnable, SIGNAL(toggled(bool)), this, SLOT(enableSelection(bool)));
|
||||||
connect(pluginsTree, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayContextMenu(const QPoint&)));
|
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(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString)));
|
||||||
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
|
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
|
||||||
loadSupportedSearchEngines();
|
loadSupportedSearchEngines();
|
||||||
|
@ -34,14 +34,14 @@
|
|||||||
#include "ui_engineselect.h"
|
#include "ui_engineselect.h"
|
||||||
#include "supportedengines.h"
|
#include "supportedengines.h"
|
||||||
|
|
||||||
class downloadThread;
|
class DownloadThread;
|
||||||
class QDropEvent;
|
class QDropEvent;
|
||||||
|
|
||||||
class engineSelectDlg : public QDialog, public Ui::engineSelect{
|
class engineSelectDlg : public QDialog, public Ui::engineSelect{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
downloadThread *downloader;
|
DownloadThread *downloader;
|
||||||
SupportedEngines *supported_engines;
|
SupportedEngines *supported_engines;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
#include "searchtab.h"
|
#include "searchtab.h"
|
||||||
#include "supportedengines.h"
|
#include "supportedengines.h"
|
||||||
|
|
||||||
class downloadThread;
|
class DownloadThread;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
class SearchEngine;
|
class SearchEngine;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user