|
|
@ -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(); |
|
|
|