mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-23 16:58:06 -06:00
Reduce number of DownloadManager signals
This commit is contained in:
@@ -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