mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 13:18:06 -06:00
Reduce number of DownloadManager signals
This commit is contained in:
@@ -1542,22 +1542,21 @@ void Session::processShareLimits()
|
||||
}
|
||||
}
|
||||
|
||||
void Session::handleDownloadFailed(const QString &url, const QString &reason)
|
||||
{
|
||||
emit downloadFromUrlFailed(url, reason);
|
||||
}
|
||||
|
||||
void Session::handleRedirectedToMagnet(const QString &url, const QString &magnetUri)
|
||||
{
|
||||
addTorrent_impl(CreateTorrentParams(m_downloadedTorrents.take(url)), MagnetUri(magnetUri));
|
||||
}
|
||||
|
||||
// Add to BitTorrent session the downloaded torrent file
|
||||
void Session::handleDownloadFinished(const QString &url, const QByteArray &data)
|
||||
void Session::handleDownloadFinished(const Net::DownloadResult &result)
|
||||
{
|
||||
emit downloadFromUrlFinished(url);
|
||||
addTorrent_impl(CreateTorrentParams(m_downloadedTorrents.take(url))
|
||||
, MagnetUri(), TorrentInfo::load(data));
|
||||
switch (result.status) {
|
||||
case Net::DownloadStatus::Success:
|
||||
emit downloadFromUrlFinished(result.url);
|
||||
addTorrent_impl(CreateTorrentParams(m_downloadedTorrents.take(result.url))
|
||||
, MagnetUri(), TorrentInfo::load(result.data));
|
||||
break;
|
||||
case Net::DownloadStatus::RedirectedToMagnet:
|
||||
addTorrent_impl(CreateTorrentParams(m_downloadedTorrents.take(result.url)), MagnetUri(result.magnet));
|
||||
break;
|
||||
default:
|
||||
emit downloadFromUrlFailed(result.url, result.errorString);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the torrent handle, given its hash
|
||||
@@ -1796,11 +1795,8 @@ bool Session::addTorrent(const QString &source, const AddTorrentParams ¶ms)
|
||||
LogMsg(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(source));
|
||||
// Launch downloader
|
||||
const Net::DownloadHandler *handler =
|
||||
Net::DownloadManager::instance()->download(Net::DownloadRequest(source).limit(10485760 /* 10MB */).handleRedirectToMagnet(true));
|
||||
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished)
|
||||
, this, &Session::handleDownloadFinished);
|
||||
connect(handler, &Net::DownloadHandler::downloadFailed, this, &Session::handleDownloadFailed);
|
||||
connect(handler, &Net::DownloadHandler::redirectedToMagnet, this, &Session::handleRedirectedToMagnet);
|
||||
Net::DownloadManager::instance()->download(Net::DownloadRequest(source).limit(10485760 /* 10MB */));
|
||||
connect(handler, &Net::DownloadHandler::finished, this, &Session::handleDownloadFinished);
|
||||
m_downloadedTorrents[handler->url()] = params;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -118,6 +118,11 @@ enum TorrentExportFolder
|
||||
Finished
|
||||
};
|
||||
|
||||
namespace Net
|
||||
{
|
||||
struct DownloadResult;
|
||||
}
|
||||
|
||||
namespace BitTorrent
|
||||
{
|
||||
class InfoHash;
|
||||
@@ -537,9 +542,7 @@ namespace BitTorrent
|
||||
void generateResumeData(bool final = false);
|
||||
void handleIPFilterParsed(int ruleCount);
|
||||
void handleIPFilterError();
|
||||
void handleDownloadFinished(const QString &url, const QByteArray &data);
|
||||
void handleDownloadFailed(const QString &url, const QString &reason);
|
||||
void handleRedirectedToMagnet(const QString &url, const QString &magnetUri);
|
||||
void handleDownloadFinished(const Net::DownloadResult &result);
|
||||
|
||||
// Session reconfiguration triggers
|
||||
void networkOnlineStateChanged(bool online);
|
||||
|
||||
@@ -76,19 +76,20 @@ void DNSUpdater::checkPublicIP()
|
||||
|
||||
DownloadHandler *handler = DownloadManager::instance()->download(
|
||||
DownloadRequest("http://checkip.dyndns.org").userAgent("qBittorrent/" QBT_VERSION_2));
|
||||
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished)
|
||||
, this, &DNSUpdater::ipRequestFinished);
|
||||
connect(handler, &Net::DownloadHandler::downloadFailed, this, &DNSUpdater::ipRequestFailed);
|
||||
connect(handler, &DownloadHandler::finished, this, &DNSUpdater::ipRequestFinished);
|
||||
|
||||
m_lastIPCheckTime = QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
void DNSUpdater::ipRequestFinished(const QString &url, const QByteArray &data)
|
||||
void DNSUpdater::ipRequestFinished(const DownloadResult &result)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
if (result.status != DownloadStatus::Success) {
|
||||
qWarning() << "IP request failed:" << result.errorString;
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse response
|
||||
const QRegularExpressionMatch ipRegexMatch = QRegularExpression("Current IP Address:\\s+([^<]+)</body>").match(data);
|
||||
const QRegularExpressionMatch ipRegexMatch = QRegularExpression("Current IP Address:\\s+([^<]+)</body>").match(result.data);
|
||||
if (ipRegexMatch.hasMatch()) {
|
||||
QString ipStr = ipRegexMatch.captured(1);
|
||||
qDebug() << Q_FUNC_INFO << "Regular expression captured the following IP:" << ipStr;
|
||||
@@ -110,12 +111,6 @@ void DNSUpdater::ipRequestFinished(const QString &url, const QByteArray &data)
|
||||
}
|
||||
}
|
||||
|
||||
void DNSUpdater::ipRequestFailed(const QString &url, const QString &error)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
qWarning() << "IP request failed:" << error;
|
||||
}
|
||||
|
||||
void DNSUpdater::updateDNSService()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
@@ -123,9 +118,7 @@ void DNSUpdater::updateDNSService()
|
||||
m_lastIPCheckTime = QDateTime::currentDateTime();
|
||||
DownloadHandler *handler = DownloadManager::instance()->download(
|
||||
DownloadRequest(getUpdateUrl()).userAgent("qBittorrent/" QBT_VERSION_2));
|
||||
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished)
|
||||
, this, &DNSUpdater::ipUpdateFinished);
|
||||
connect(handler, &Net::DownloadHandler::downloadFailed, this, &DNSUpdater::ipUpdateFailed);
|
||||
connect(handler, &DownloadHandler::finished, this, &DNSUpdater::ipUpdateFinished);
|
||||
}
|
||||
|
||||
QString DNSUpdater::getUpdateUrl() const
|
||||
@@ -164,17 +157,12 @@ QString DNSUpdater::getUpdateUrl() const
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
void DNSUpdater::ipUpdateFinished(const QString &url, const QByteArray &data)
|
||||
void DNSUpdater::ipUpdateFinished(const DownloadResult &result)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
// Parse reply
|
||||
processIPUpdateReply(data);
|
||||
}
|
||||
|
||||
void DNSUpdater::ipUpdateFailed(const QString &url, const QString &error)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
qWarning() << "IP update failed:" << error;
|
||||
if (result.status == DownloadStatus::Success)
|
||||
processIPUpdateReply(result.data);
|
||||
else
|
||||
qWarning() << "IP update failed:" << result.errorString;
|
||||
}
|
||||
|
||||
void DNSUpdater::processIPUpdateReply(const QString &reply)
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
|
||||
namespace Net
|
||||
{
|
||||
struct DownloadResult;
|
||||
|
||||
// Based on http://www.dyndns.com/developers/specs/
|
||||
class DNSUpdater : public QObject
|
||||
{
|
||||
@@ -54,11 +56,9 @@ namespace Net
|
||||
|
||||
private slots:
|
||||
void checkPublicIP();
|
||||
void ipRequestFinished(const QString &url, const QByteArray &data);
|
||||
void ipRequestFailed(const QString &url, const QString &error);
|
||||
void ipRequestFinished(const DownloadResult &result);
|
||||
void updateDNSService();
|
||||
void ipUpdateFinished(const QString &url, const QByteArray &data);
|
||||
void ipUpdateFailed(const QString &url, const QString &error);
|
||||
void ipUpdateFinished(const DownloadResult &result);
|
||||
|
||||
private:
|
||||
enum State
|
||||
|
||||
@@ -69,6 +69,8 @@ Net::DownloadHandler::DownloadHandler(QNetworkReply *reply, DownloadManager *man
|
||||
{
|
||||
if (reply)
|
||||
assignNetworkReply(reply);
|
||||
m_result.url = url();
|
||||
m_result.status = DownloadStatus::Success;
|
||||
}
|
||||
|
||||
Net::DownloadHandler::~DownloadHandler()
|
||||
@@ -103,8 +105,8 @@ void Net::DownloadHandler::processFinishedDownload()
|
||||
if (m_reply->error() != QNetworkReply::NoError) {
|
||||
// Failure
|
||||
qDebug("Download failure (%s), reason: %s", qUtf8Printable(url), qUtf8Printable(errorCodeToString(m_reply->error())));
|
||||
emit downloadFailed(m_downloadRequest.url(), errorCodeToString(m_reply->error()));
|
||||
this->deleteLater();
|
||||
setError(errorCodeToString(m_reply->error()));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -117,49 +119,43 @@ void Net::DownloadHandler::processFinishedDownload()
|
||||
}
|
||||
|
||||
// Success
|
||||
const QByteArray replyData = (m_reply->rawHeader("Content-Encoding") == "gzip")
|
||||
m_result.data = (m_reply->rawHeader("Content-Encoding") == "gzip")
|
||||
? Utils::Gzip::decompress(m_reply->readAll())
|
||||
: m_reply->readAll();
|
||||
|
||||
if (m_downloadRequest.saveToFile()) {
|
||||
QString filePath;
|
||||
if (saveToFile(replyData, filePath))
|
||||
emit downloadFinished(m_downloadRequest.url(), filePath);
|
||||
if (saveToFile(m_result.data, filePath))
|
||||
m_result.filePath = filePath;
|
||||
else
|
||||
emit downloadFailed(m_downloadRequest.url(), tr("I/O Error"));
|
||||
}
|
||||
else {
|
||||
emit downloadFinished(m_downloadRequest.url(), replyData);
|
||||
setError(tr("I/O Error"));
|
||||
}
|
||||
|
||||
this->deleteLater();
|
||||
finish();
|
||||
}
|
||||
|
||||
void Net::DownloadHandler::checkDownloadSize(const qint64 bytesReceived, const qint64 bytesTotal)
|
||||
{
|
||||
QString msg = tr("The file size is %1. It exceeds the download limit of %2.");
|
||||
|
||||
if (bytesTotal > 0) {
|
||||
if ((bytesTotal > 0) && (bytesTotal <= m_downloadRequest.limit())) {
|
||||
// Total number of bytes is available
|
||||
if (bytesTotal > m_downloadRequest.limit()) {
|
||||
m_reply->abort();
|
||||
emit downloadFailed(m_downloadRequest.url(), msg.arg(Utils::Misc::friendlyUnit(bytesTotal), Utils::Misc::friendlyUnit(m_downloadRequest.limit())));
|
||||
}
|
||||
else {
|
||||
disconnect(m_reply, &QNetworkReply::downloadProgress, this, &Net::DownloadHandler::checkDownloadSize);
|
||||
}
|
||||
disconnect(m_reply, &QNetworkReply::downloadProgress, this, &Net::DownloadHandler::checkDownloadSize);
|
||||
return;
|
||||
}
|
||||
else if (bytesReceived > m_downloadRequest.limit()) {
|
||||
|
||||
if ((bytesTotal > m_downloadRequest.limit()) || (bytesReceived > m_downloadRequest.limit())) {
|
||||
m_reply->abort();
|
||||
emit downloadFailed(m_downloadRequest.url(), msg.arg(Utils::Misc::friendlyUnit(bytesReceived), Utils::Misc::friendlyUnit(m_downloadRequest.limit())));
|
||||
setError(tr("The file size is %1. It exceeds the download limit of %2.")
|
||||
.arg(Utils::Misc::friendlyUnit(bytesTotal)
|
||||
, Utils::Misc::friendlyUnit(m_downloadRequest.limit())));
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
void Net::DownloadHandler::handleRedirection(const QUrl &newUrl)
|
||||
{
|
||||
if (m_redirectionCounter >= MAX_REDIRECTIONS) {
|
||||
emit downloadFailed(url(), tr("Exceeded max redirections (%1)").arg(MAX_REDIRECTIONS));
|
||||
this->deleteLater();
|
||||
setError(tr("Exceeded max redirections (%1)").arg(MAX_REDIRECTIONS));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -172,38 +168,35 @@ void Net::DownloadHandler::handleRedirection(const QUrl &newUrl)
|
||||
if (newUrlString.startsWith("magnet:", Qt::CaseInsensitive)) {
|
||||
qDebug("Magnet redirect detected.");
|
||||
m_reply->abort();
|
||||
if (m_downloadRequest.handleRedirectToMagnet())
|
||||
emit redirectedToMagnet(m_downloadRequest.url(), newUrlString);
|
||||
else
|
||||
emit downloadFailed(m_downloadRequest.url(), tr("Unexpected redirect to magnet URI."));
|
||||
m_result.status = DownloadStatus::RedirectedToMagnet;
|
||||
m_result.magnet = newUrlString;
|
||||
|
||||
this->deleteLater();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
DownloadHandler *redirected = m_manager->download(DownloadRequest(m_downloadRequest).url(newUrlString));
|
||||
redirected->m_redirectionCounter = (m_redirectionCounter + 1);
|
||||
connect(redirected, &DownloadHandler::destroyed, this, &DownloadHandler::deleteLater);
|
||||
connect(redirected, &DownloadHandler::downloadFailed, this, [this](const QString &, const QString &reason)
|
||||
connect(redirected, &DownloadHandler::finished, this, [this](const DownloadResult &result)
|
||||
{
|
||||
emit downloadFailed(url(), reason);
|
||||
});
|
||||
connect(redirected, &DownloadHandler::redirectedToMagnet, this, [this](const QString &, const QString &magnetUri)
|
||||
{
|
||||
emit redirectedToMagnet(url(), magnetUri);
|
||||
});
|
||||
connect(redirected, static_cast<void (DownloadHandler::*)(const QString &, const QString &)>(&DownloadHandler::downloadFinished)
|
||||
, this, [this](const QString &, const QString &fileName)
|
||||
{
|
||||
emit downloadFinished(url(), fileName);
|
||||
});
|
||||
connect(redirected, static_cast<void (DownloadHandler::*)(const QString &, const QByteArray &)>(&DownloadHandler::downloadFinished)
|
||||
, this, [this](const QString &, const QByteArray &data)
|
||||
{
|
||||
emit downloadFinished(url(), data);
|
||||
m_result = result;
|
||||
m_result.url = url();
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
void Net::DownloadHandler::setError(const QString &error)
|
||||
{
|
||||
m_result.errorString = error;
|
||||
m_result.status = DownloadStatus::Failed;
|
||||
}
|
||||
|
||||
void Net::DownloadHandler::finish()
|
||||
{
|
||||
emit finished(m_result);
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
QString Net::DownloadHandler::errorCodeToString(const QNetworkReply::NetworkError status)
|
||||
{
|
||||
switch (status) {
|
||||
|
||||
@@ -56,10 +56,7 @@ namespace Net
|
||||
QString url() const;
|
||||
|
||||
signals:
|
||||
void downloadFinished(const QString &url, const QByteArray &data);
|
||||
void downloadFinished(const QString &url, const QString &filePath);
|
||||
void downloadFailed(const QString &url, const QString &reason);
|
||||
void redirectedToMagnet(const QString &url, const QString &magnetUri);
|
||||
void finished(const DownloadResult &result);
|
||||
|
||||
private slots:
|
||||
void processFinishedDownload();
|
||||
@@ -68,6 +65,8 @@ namespace Net
|
||||
private:
|
||||
void assignNetworkReply(QNetworkReply *reply);
|
||||
void handleRedirection(const QUrl &newUrl);
|
||||
void setError(const QString &error);
|
||||
void finish();
|
||||
|
||||
static QString errorCodeToString(QNetworkReply::NetworkError status);
|
||||
|
||||
@@ -75,6 +74,7 @@ namespace Net
|
||||
DownloadManager *m_manager;
|
||||
const DownloadRequest m_downloadRequest;
|
||||
short m_redirectionCounter = 0;
|
||||
DownloadResult m_result;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -328,17 +328,6 @@ Net::DownloadRequest &Net::DownloadRequest::saveToFile(const bool value)
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Net::DownloadRequest::handleRedirectToMagnet() const
|
||||
{
|
||||
return m_handleRedirectToMagnet;
|
||||
}
|
||||
|
||||
Net::DownloadRequest &Net::DownloadRequest::handleRedirectToMagnet(const bool value)
|
||||
{
|
||||
m_handleRedirectToMagnet = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Net::ServiceID Net::ServiceID::fromURL(const QUrl &url)
|
||||
{
|
||||
return {url.host(), url.port(80)};
|
||||
|
||||
@@ -64,15 +64,28 @@ namespace Net
|
||||
bool saveToFile() const;
|
||||
DownloadRequest &saveToFile(bool value);
|
||||
|
||||
bool handleRedirectToMagnet() const;
|
||||
DownloadRequest &handleRedirectToMagnet(bool value);
|
||||
|
||||
private:
|
||||
QString m_url;
|
||||
QString m_userAgent;
|
||||
qint64 m_limit = 0;
|
||||
bool m_saveToFile = false;
|
||||
bool m_handleRedirectToMagnet = false;
|
||||
};
|
||||
|
||||
enum class DownloadStatus
|
||||
{
|
||||
Success,
|
||||
RedirectedToMagnet,
|
||||
Failed
|
||||
};
|
||||
|
||||
struct DownloadResult
|
||||
{
|
||||
QString url;
|
||||
DownloadStatus status;
|
||||
QString errorString;
|
||||
QByteArray data;
|
||||
QString filePath;
|
||||
QString magnet;
|
||||
};
|
||||
|
||||
struct ServiceID
|
||||
|
||||
@@ -119,9 +119,7 @@ void GeoIPManager::manageDatabaseUpdate()
|
||||
void GeoIPManager::downloadDatabaseFile()
|
||||
{
|
||||
const DownloadHandler *handler = DownloadManager::instance()->download({DATABASE_URL});
|
||||
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished)
|
||||
, this, &GeoIPManager::downloadFinished);
|
||||
connect(handler, &Net::DownloadHandler::downloadFailed, this, &GeoIPManager::downloadFailed);
|
||||
connect(handler, &DownloadHandler::finished, this, &GeoIPManager::downloadFinished);
|
||||
}
|
||||
|
||||
QString GeoIPManager::lookup(const QHostAddress &hostAddr) const
|
||||
@@ -413,14 +411,17 @@ void GeoIPManager::configure()
|
||||
}
|
||||
}
|
||||
|
||||
void GeoIPManager::downloadFinished(const QString &url, QByteArray data)
|
||||
void GeoIPManager::downloadFinished(const DownloadResult &result)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
if (result.status != DownloadStatus::Success) {
|
||||
LogMsg(tr("Couldn't download GeoIP database file. Reason: %1").arg(result.errorString), Log::WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
bool ok = false;
|
||||
data = Utils::Gzip::decompress(data, &ok);
|
||||
const QByteArray data = Utils::Gzip::decompress(result.data, &ok);
|
||||
if (!ok) {
|
||||
Logger::instance()->addMessage(tr("Could not decompress GeoIP database file."), Log::WARNING);
|
||||
LogMsg(tr("Could not decompress GeoIP database file."), Log::WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -431,7 +432,7 @@ void GeoIPManager::downloadFinished(const QString &url, QByteArray data)
|
||||
if (m_geoIPDatabase)
|
||||
delete m_geoIPDatabase;
|
||||
m_geoIPDatabase = geoIPDatabase;
|
||||
Logger::instance()->addMessage(tr("GeoIP database loaded. Type: %1. Build time: %2.")
|
||||
LogMsg(tr("GeoIP database loaded. Type: %1. Build time: %2.")
|
||||
.arg(m_geoIPDatabase->type(), m_geoIPDatabase->buildEpoch().toString()),
|
||||
Log::INFO);
|
||||
const QString targetPath = Utils::Fs::expandPathAbs(
|
||||
@@ -439,25 +440,16 @@ void GeoIPManager::downloadFinished(const QString &url, QByteArray data)
|
||||
if (!QDir(targetPath).exists())
|
||||
QDir().mkpath(targetPath);
|
||||
QFile targetFile(QString("%1/%2").arg(targetPath, GEOIP_FILENAME));
|
||||
if (!targetFile.open(QFile::WriteOnly) || (targetFile.write(data) == -1)) {
|
||||
Logger::instance()->addMessage(
|
||||
tr("Couldn't save downloaded GeoIP database file."), Log::WARNING);
|
||||
}
|
||||
else {
|
||||
Logger::instance()->addMessage(tr("Successfully updated GeoIP database."), Log::INFO);
|
||||
}
|
||||
if (!targetFile.open(QFile::WriteOnly) || (targetFile.write(data) == -1))
|
||||
LogMsg(tr("Couldn't save downloaded GeoIP database file."), Log::WARNING);
|
||||
else
|
||||
LogMsg(tr("Successfully updated GeoIP database."), Log::INFO);
|
||||
}
|
||||
else {
|
||||
delete geoIPDatabase;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Logger::instance()->addMessage(tr("Couldn't load GeoIP database. Reason: %1").arg(error), Log::WARNING);
|
||||
LogMsg(tr("Couldn't load GeoIP database. Reason: %1").arg(error), Log::WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
void GeoIPManager::downloadFailed(const QString &url, const QString &reason)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
Logger::instance()->addMessage(tr("Couldn't download GeoIP database file. Reason: %1").arg(reason), Log::WARNING);
|
||||
}
|
||||
|
||||
@@ -40,9 +40,12 @@ class GeoIPDatabase;
|
||||
|
||||
namespace Net
|
||||
{
|
||||
struct DownloadResult;
|
||||
|
||||
class GeoIPManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(GeoIPManager)
|
||||
|
||||
public:
|
||||
static void initInstance();
|
||||
@@ -55,12 +58,11 @@ namespace Net
|
||||
|
||||
private slots:
|
||||
void configure();
|
||||
void downloadFinished(const QString &url, QByteArray data);
|
||||
void downloadFailed(const QString &url, const QString &reason);
|
||||
void downloadFinished(const DownloadResult &result);
|
||||
|
||||
private:
|
||||
GeoIPManager();
|
||||
~GeoIPManager();
|
||||
~GeoIPManager() override;
|
||||
|
||||
void loadDatabase();
|
||||
void manageDatabaseUpdate();
|
||||
|
||||
@@ -131,10 +131,7 @@ void Feed::refresh()
|
||||
// NOTE: Should we allow manually refreshing for disabled session?
|
||||
|
||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(m_url);
|
||||
connect(handler
|
||||
, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished)
|
||||
, this, &Feed::handleDownloadFinished);
|
||||
connect(handler, &Net::DownloadHandler::downloadFailed, this, &Feed::handleDownloadFailed);
|
||||
connect(handler, &Net::DownloadHandler::finished, this, &Feed::handleDownloadFinished);
|
||||
|
||||
m_isLoading = true;
|
||||
emit stateChanged(this);
|
||||
@@ -182,12 +179,12 @@ void Feed::handleMaxArticlesPerFeedChanged(const int n)
|
||||
// We don't need store articles here
|
||||
}
|
||||
|
||||
void Feed::handleIconDownloadFinished(const QString &url, const QString &filePath)
|
||||
void Feed::handleIconDownloadFinished(const Net::DownloadResult &result)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
|
||||
m_iconPath = Utils::Fs::fromNativePath(filePath);
|
||||
emit iconLoaded(this);
|
||||
if (result.status == Net::DownloadStatus::Success) {
|
||||
m_iconPath = Utils::Fs::fromNativePath(result.filePath);
|
||||
emit iconLoaded(this);
|
||||
}
|
||||
}
|
||||
|
||||
bool Feed::hasError() const
|
||||
@@ -195,22 +192,22 @@ bool Feed::hasError() const
|
||||
return m_hasError;
|
||||
}
|
||||
|
||||
void Feed::handleDownloadFinished(const QString &url, const QByteArray &data)
|
||||
void Feed::handleDownloadFinished(const Net::DownloadResult &result)
|
||||
{
|
||||
qDebug() << "Successfully downloaded RSS feed at" << url;
|
||||
// Parse the download RSS
|
||||
m_parser->parse(data);
|
||||
}
|
||||
if (result.status == Net::DownloadStatus::Success) {
|
||||
qDebug() << "Successfully downloaded RSS feed at" << result.url;
|
||||
// Parse the download RSS
|
||||
m_parser->parse(result.data);
|
||||
}
|
||||
else {
|
||||
m_isLoading = false;
|
||||
m_hasError = true;
|
||||
|
||||
void Feed::handleDownloadFailed(const QString &url, const QString &error)
|
||||
{
|
||||
m_isLoading = false;
|
||||
m_hasError = true;
|
||||
LogMsg(tr("Failed to download RSS feed at '%1'. Reason: %2")
|
||||
.arg(result.url, result.errorString), Log::WARNING);
|
||||
|
||||
LogMsg(tr("Failed to download RSS feed at '%1'. Reason: %2").arg(url, error)
|
||||
, Log::WARNING);
|
||||
|
||||
emit stateChanged(this);
|
||||
emit stateChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Feed::handleParsingFinished(const RSS::Private::ParsingResult &result)
|
||||
@@ -404,9 +401,7 @@ void Feed::downloadIcon()
|
||||
const auto iconUrl = QString("%1://%2/favicon.ico").arg(url.scheme(), url.host());
|
||||
const Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(
|
||||
Net::DownloadRequest(iconUrl).saveToFile(true));
|
||||
connect(handler
|
||||
, static_cast<void (Net::DownloadHandler::*)(const QString &, const QString &)>(&Net::DownloadHandler::downloadFinished)
|
||||
, this, &Feed::handleIconDownloadFinished);
|
||||
connect(handler, &Net::DownloadHandler::finished, this, &Feed::handleIconDownloadFinished);
|
||||
}
|
||||
|
||||
int Feed::updateArticles(const QList<QVariantHash> &loadedArticles)
|
||||
|
||||
@@ -39,6 +39,11 @@
|
||||
|
||||
class AsyncFileStorage;
|
||||
|
||||
namespace Net
|
||||
{
|
||||
struct DownloadResult;
|
||||
}
|
||||
|
||||
namespace RSS
|
||||
{
|
||||
class Article;
|
||||
@@ -85,9 +90,8 @@ namespace RSS
|
||||
private slots:
|
||||
void handleSessionProcessingEnabledChanged(bool enabled);
|
||||
void handleMaxArticlesPerFeedChanged(int n);
|
||||
void handleIconDownloadFinished(const QString &url, const QString &filePath);
|
||||
void handleDownloadFinished(const QString &url, const QByteArray &data);
|
||||
void handleDownloadFailed(const QString &url, const QString &error);
|
||||
void handleIconDownloadFinished(const Net::DownloadResult &result);
|
||||
void handleDownloadFinished(const Net::DownloadResult &result);
|
||||
void handleParsingFinished(const Private::ParsingResult &result);
|
||||
void handleArticleRead(Article *article);
|
||||
|
||||
|
||||
@@ -200,9 +200,7 @@ void SearchPluginManager::installPlugin(const QString &source)
|
||||
if (Net::DownloadManager::hasSupportedScheme(source)) {
|
||||
using namespace Net;
|
||||
DownloadHandler *handler = DownloadManager::instance()->download(DownloadRequest(source).saveToFile(true));
|
||||
connect(handler, static_cast<void (DownloadHandler::*)(const QString &, const QString &)>(&DownloadHandler::downloadFinished)
|
||||
, this, &SearchPluginManager::pluginDownloaded);
|
||||
connect(handler, &DownloadHandler::downloadFailed, this, &SearchPluginManager::pluginDownloadFailed);
|
||||
connect(handler, &Net::DownloadHandler::finished, this, &SearchPluginManager::pluginDownloadFinished);
|
||||
}
|
||||
else {
|
||||
QString path = source;
|
||||
@@ -305,9 +303,7 @@ void SearchPluginManager::checkForUpdates()
|
||||
// Download version file from update server
|
||||
using namespace Net;
|
||||
DownloadHandler *handler = DownloadManager::instance()->download({m_updateUrl + "versions.txt"});
|
||||
connect(handler, static_cast<void (DownloadHandler::*)(const QString &, const QByteArray &)>(&DownloadHandler::downloadFinished)
|
||||
, this, &SearchPluginManager::versionInfoDownloaded);
|
||||
connect(handler, &DownloadHandler::downloadFailed, this, &SearchPluginManager::versionInfoDownloadFailed);
|
||||
connect(handler, &Net::DownloadHandler::finished, this, &SearchPluginManager::versionInfoDownloadFinished);
|
||||
}
|
||||
|
||||
SearchDownloadHandler *SearchPluginManager::downloadTorrent(const QString &siteUrl, const QString &url)
|
||||
@@ -364,36 +360,32 @@ QString SearchPluginManager::engineLocation()
|
||||
return location;
|
||||
}
|
||||
|
||||
void SearchPluginManager::versionInfoDownloaded(const QString &url, const QByteArray &data)
|
||||
void SearchPluginManager::versionInfoDownloadFinished(const Net::DownloadResult &result)
|
||||
{
|
||||
Q_UNUSED(url)
|
||||
parseVersionInfo(data);
|
||||
}
|
||||
|
||||
void SearchPluginManager::versionInfoDownloadFailed(const QString &url, const QString &reason)
|
||||
{
|
||||
Q_UNUSED(url)
|
||||
emit checkForUpdatesFailed(tr("Update server is temporarily unavailable. %1").arg(reason));
|
||||
}
|
||||
|
||||
void SearchPluginManager::pluginDownloaded(const QString &url, QString filePath)
|
||||
{
|
||||
filePath = Utils::Fs::fromNativePath(filePath);
|
||||
|
||||
QString pluginName = Utils::Fs::fileName(url);
|
||||
pluginName.chop(pluginName.size() - pluginName.lastIndexOf('.')); // Remove extension
|
||||
installPlugin_impl(pluginName, filePath);
|
||||
Utils::Fs::forceRemove(filePath);
|
||||
}
|
||||
|
||||
void SearchPluginManager::pluginDownloadFailed(const QString &url, const QString &reason)
|
||||
{
|
||||
QString pluginName = url.split('/').last();
|
||||
pluginName.replace(".py", "", Qt::CaseInsensitive);
|
||||
if (pluginInfo(pluginName))
|
||||
emit pluginUpdateFailed(pluginName, tr("Failed to download the plugin file. %1").arg(reason));
|
||||
if (result.status == Net::DownloadStatus::Success)
|
||||
parseVersionInfo(result.data);
|
||||
else
|
||||
emit pluginInstallationFailed(pluginName, tr("Failed to download the plugin file. %1").arg(reason));
|
||||
emit checkForUpdatesFailed(tr("Update server is temporarily unavailable. %1").arg(result.errorString));
|
||||
}
|
||||
|
||||
void SearchPluginManager::pluginDownloadFinished(const Net::DownloadResult &result)
|
||||
{
|
||||
if (result.status == Net::DownloadStatus::Success) {
|
||||
const QString filePath = Utils::Fs::fromNativePath(result.filePath);
|
||||
|
||||
QString pluginName = Utils::Fs::fileName(result.url);
|
||||
pluginName.chop(pluginName.size() - pluginName.lastIndexOf('.')); // Remove extension
|
||||
installPlugin_impl(pluginName, filePath);
|
||||
Utils::Fs::forceRemove(filePath);
|
||||
}
|
||||
else {
|
||||
QString pluginName = result.url.split('/').last();
|
||||
pluginName.replace(".py", "", Qt::CaseInsensitive);
|
||||
if (pluginInfo(pluginName))
|
||||
emit pluginUpdateFailed(pluginName, tr("Failed to download the plugin file. %1").arg(result.errorString));
|
||||
else
|
||||
emit pluginInstallationFailed(pluginName, tr("Failed to download the plugin file. %1").arg(result.errorString));
|
||||
}
|
||||
}
|
||||
|
||||
// Update nova.py search plugin if necessary
|
||||
|
||||
@@ -38,6 +38,11 @@
|
||||
using PluginVersion = Utils::Version<unsigned short, 2>;
|
||||
Q_DECLARE_METATYPE(PluginVersion)
|
||||
|
||||
namespace Net
|
||||
{
|
||||
struct DownloadResult;
|
||||
}
|
||||
|
||||
struct PluginInfo
|
||||
{
|
||||
QString name;
|
||||
@@ -104,10 +109,8 @@ private:
|
||||
void installPlugin_impl(const QString &name, const QString &path);
|
||||
bool isUpdateNeeded(const QString &pluginName, PluginVersion newVersion) const;
|
||||
|
||||
void versionInfoDownloaded(const QString &url, const QByteArray &data);
|
||||
void versionInfoDownloadFailed(const QString &url, const QString &reason);
|
||||
void pluginDownloaded(const QString &url, QString filePath);
|
||||
void pluginDownloadFailed(const QString &url, const QString &reason);
|
||||
void versionInfoDownloadFinished(const Net::DownloadResult &result);
|
||||
void pluginDownloadFinished(const Net::DownloadResult &result);
|
||||
|
||||
static QString pluginPath(const QString &name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user