mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 13:04:23 +00:00
Use new DownloadManager interface
This commit is contained in:
parent
8d438e159c
commit
112a9bcfa2
@ -1844,11 +1844,10 @@ void Session::handleRedirectedToMagnet(const QString &url, const QString &magnet
|
||||
}
|
||||
|
||||
// Add to BitTorrent session the downloaded torrent file
|
||||
void Session::handleDownloadFinished(const QString &url, const QString &filePath)
|
||||
void Session::handleDownloadFinished(const QString &url, const QByteArray &data)
|
||||
{
|
||||
emit downloadFromUrlFinished(url);
|
||||
addTorrent_impl(m_downloadedTorrents.take(url), MagnetUri(), TorrentInfo::loadFromFile(filePath));
|
||||
Utils::Fs::forceRemove(filePath); // remove temporary file
|
||||
addTorrent_impl(m_downloadedTorrents.take(url), MagnetUri(), TorrentInfo::load(data));
|
||||
}
|
||||
|
||||
// Return the torrent handle, given its hash
|
||||
@ -2077,10 +2076,11 @@ bool Session::addTorrent(QString source, const AddTorrentParams ¶ms)
|
||||
return addTorrent_impl(params, magnetUri);
|
||||
}
|
||||
else if (Utils::Misc::isUrl(source)) {
|
||||
Logger::instance()->addMessage(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(source));
|
||||
LogMsg(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(source));
|
||||
// Launch downloader
|
||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true, 10485760 /* 10MB */, true);
|
||||
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QString &)>(&Net::DownloadHandler::downloadFinished)
|
||||
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);
|
||||
|
@ -547,7 +547,7 @@ namespace BitTorrent
|
||||
void generateResumeData(bool final = false);
|
||||
void handleIPFilterParsed(int ruleCount);
|
||||
void handleIPFilterError();
|
||||
void handleDownloadFinished(const QString &url, const QString &filePath);
|
||||
void handleDownloadFinished(const QString &url, const QByteArray &data);
|
||||
void handleDownloadFailed(const QString &url, const QString &reason);
|
||||
void handleRedirectedToMagnet(const QString &url, const QString &magnetUri);
|
||||
|
||||
|
@ -75,9 +75,8 @@ void DNSUpdater::checkPublicIP()
|
||||
{
|
||||
Q_ASSERT(m_state == OK);
|
||||
|
||||
DownloadHandler *handler = DownloadManager::instance()->downloadUrl(
|
||||
"http://checkip.dyndns.org", false, 0, false,
|
||||
"qBittorrent/" QBT_VERSION_2);
|
||||
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);
|
||||
@ -123,9 +122,8 @@ void DNSUpdater::updateDNSService()
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
m_lastIPCheckTime = QDateTime::currentDateTime();
|
||||
DownloadHandler *handler = DownloadManager::instance()->downloadUrl(
|
||||
getUpdateUrl(), false, 0, false,
|
||||
"qBittorrent/" QBT_VERSION_2);
|
||||
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);
|
||||
|
@ -155,11 +155,6 @@ Net::DownloadManager *Net::DownloadManager::instance()
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
Net::DownloadHandler *Net::DownloadManager::downloadUrl(const QString &url, bool saveToFile, qint64 limit, bool handleRedirectToMagnet, const QString &userAgent)
|
||||
{
|
||||
return download(DownloadRequest(url).saveToFile(saveToFile).limit(limit).handleRedirectToMagnet(handleRedirectToMagnet).userAgent(userAgent));
|
||||
}
|
||||
|
||||
Net::DownloadHandler *Net::DownloadManager::download(const DownloadRequest &downloadRequest)
|
||||
{
|
||||
// Process download request
|
||||
|
@ -93,7 +93,6 @@ namespace Net
|
||||
static void freeInstance();
|
||||
static DownloadManager *instance();
|
||||
|
||||
DownloadHandler *downloadUrl(const QString &url, bool saveToFile = false, qint64 limit = 0, bool handleRedirectToMagnet = false, const QString &userAgent = "");
|
||||
DownloadHandler *download(const DownloadRequest &downloadRequest);
|
||||
|
||||
void registerSequentialService(const ServiceID &serviceID);
|
||||
|
@ -118,7 +118,7 @@ void GeoIPManager::manageDatabaseUpdate()
|
||||
|
||||
void GeoIPManager::downloadDatabaseFile()
|
||||
{
|
||||
DownloadHandler *handler = DownloadManager::instance()->downloadUrl(DATABASE_URL);
|
||||
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);
|
||||
|
@ -129,7 +129,7 @@ void Feed::refresh()
|
||||
|
||||
// NOTE: Should we allow manually refreshing for disabled session?
|
||||
|
||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(m_url);
|
||||
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);
|
||||
@ -418,7 +418,8 @@ void Feed::downloadIcon()
|
||||
// XXX: This works for most sites but it is not perfect
|
||||
const QUrl url(m_url);
|
||||
auto iconUrl = QString("%1://%2/favicon.ico").arg(url.scheme(), url.host());
|
||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(iconUrl, true);
|
||||
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);
|
||||
|
@ -170,7 +170,7 @@ void SearchPluginManager::installPlugin(const QString &source)
|
||||
|
||||
if (Utils::Misc::isUrl(source)) {
|
||||
using namespace Net;
|
||||
DownloadHandler *handler = DownloadManager::instance()->downloadUrl(source, true);
|
||||
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);
|
||||
@ -274,7 +274,7 @@ void SearchPluginManager::checkForUpdates()
|
||||
{
|
||||
// Download version file from update server
|
||||
using namespace Net;
|
||||
DownloadHandler *handler = DownloadManager::instance()->downloadUrl(m_updateUrl + "versions.txt");
|
||||
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);
|
||||
|
@ -230,7 +230,9 @@ void AddNewTorrentDialog::show(QString source, const BitTorrent::AddTorrentParam
|
||||
|
||||
if (Utils::Misc::isUrl(source)) {
|
||||
// Launch downloader
|
||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true, 10485760 /* 10MB */, true);
|
||||
// TODO: Don't save loaded torrent to file, just use downloaded data!
|
||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(
|
||||
Net::DownloadRequest(source).limit(10485760 /* 10MB */).handleRedirectToMagnet(true).saveToFile(true));
|
||||
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QString &)>(&Net::DownloadHandler::downloadFinished)
|
||||
, dlg, &AddNewTorrentDialog::handleDownloadFinished);
|
||||
connect(handler, &Net::DownloadHandler::downloadFailed, dlg, &AddNewTorrentDialog::handleDownloadFailed);
|
||||
|
@ -2043,11 +2043,11 @@ void MainWindow::installPython()
|
||||
{
|
||||
setCursor(QCursor(Qt::WaitCursor));
|
||||
// Download python
|
||||
Net::DownloadHandler *handler = nullptr;
|
||||
if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA)
|
||||
handler = Net::DownloadManager::instance()->downloadUrl("https://www.python.org/ftp/python/3.5.2/python-3.5.2.exe", true);
|
||||
else
|
||||
handler = Net::DownloadManager::instance()->downloadUrl("https://www.python.org/ftp/python/3.4.4/python-3.4.4.msi", true);
|
||||
const QString installerURL = ((QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA)
|
||||
? "https://www.python.org/ftp/python/3.5.2/python-3.5.2.exe"
|
||||
: "https://www.python.org/ftp/python/3.4.4/python-3.4.4.msi");
|
||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(
|
||||
Net::DownloadRequest(installerURL).saveToFile(true));
|
||||
|
||||
using Func = void (Net::DownloadHandler::*)(const QString &, const QString &);
|
||||
connect(handler, static_cast<Func>(&Net::DownloadHandler::downloadFinished), this, &MainWindow::pythonDownloadSuccess);
|
||||
|
@ -61,11 +61,10 @@ ProgramUpdater::ProgramUpdater(QObject *parent, bool invokedByUser)
|
||||
|
||||
void ProgramUpdater::checkForUpdates()
|
||||
{
|
||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(
|
||||
RSS_URL, false, 0, false,
|
||||
// Don't change this User-Agent. In case our updater goes haywire,
|
||||
// the filehost can identify it and contact us.
|
||||
"qBittorrent/" QBT_VERSION_2 " ProgramUpdater (www.qbittorrent.org)");
|
||||
// Don't change this User-Agent. In case our updater goes haywire,
|
||||
// the filehost can identify it and contact us.
|
||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(
|
||||
Net::DownloadRequest(RSS_URL).userAgent("qBittorrent/" QBT_VERSION_2 " ProgramUpdater (www.qbittorrent.org)"));
|
||||
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished)
|
||||
, this, &ProgramUpdater::rssDownloadFinished);
|
||||
connect(handler, &Net::DownloadHandler::downloadFailed, this, &ProgramUpdater::rssDownloadFailed);
|
||||
|
@ -25,9 +25,10 @@
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*/
|
||||
|
||||
#include "trackersadditiondialog.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QBuffer>
|
||||
#include <QMessageBox>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
@ -70,25 +71,16 @@ QStringList TrackersAdditionDialog::newTrackers() const
|
||||
void TrackersAdditionDialog::on_uTorrentListButton_clicked()
|
||||
{
|
||||
m_ui->uTorrentListButton->setEnabled(false);
|
||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(m_ui->list_url->text(), true);
|
||||
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QString &)>(&Net::DownloadHandler::downloadFinished)
|
||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->download({m_ui->list_url->text()});
|
||||
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished)
|
||||
, this, &TrackersAdditionDialog::parseUTorrentList);
|
||||
connect(handler, &Net::DownloadHandler::downloadFailed, this, &TrackersAdditionDialog::getTrackerError);
|
||||
// Just to show that it takes times
|
||||
setCursor(Qt::WaitCursor);
|
||||
}
|
||||
|
||||
void TrackersAdditionDialog::parseUTorrentList(const QString &, const QString &path)
|
||||
void TrackersAdditionDialog::parseUTorrentList(const QString &, const QByteArray &data)
|
||||
{
|
||||
QFile listFile(path);
|
||||
if (!listFile.open(QFile::ReadOnly)) {
|
||||
QMessageBox::warning(this, tr("I/O Error"), tr("Error while trying to open the downloaded file."), QMessageBox::Ok);
|
||||
setCursor(Qt::ArrowCursor);
|
||||
m_ui->uTorrentListButton->setEnabled(true);
|
||||
Utils::Fs::forceRemove(path);
|
||||
return;
|
||||
}
|
||||
|
||||
// Load from torrent handle
|
||||
QList<BitTorrent::TrackerEntry> existingTrackers = m_torrent->trackers();
|
||||
// Load from current user list
|
||||
@ -103,19 +95,21 @@ void TrackersAdditionDialog::parseUTorrentList(const QString &, const QString &p
|
||||
if (!m_ui->trackers_list->toPlainText().isEmpty() && !m_ui->trackers_list->toPlainText().endsWith('\n'))
|
||||
m_ui->trackers_list->insertPlainText("\n");
|
||||
int nb = 0;
|
||||
while (!listFile.atEnd()) {
|
||||
const QString line = listFile.readLine().trimmed();
|
||||
QBuffer buffer;
|
||||
buffer.setData(data);
|
||||
buffer.open(QBuffer::ReadOnly);
|
||||
while (!buffer.atEnd()) {
|
||||
const QString line = buffer.readLine().trimmed();
|
||||
if (line.isEmpty()) continue;
|
||||
|
||||
BitTorrent::TrackerEntry newTracker(line);
|
||||
if (!existingTrackers.contains(newTracker)) {
|
||||
m_ui->trackers_list->insertPlainText(line + '\n');
|
||||
++nb;
|
||||
}
|
||||
}
|
||||
// Clean up
|
||||
listFile.close();
|
||||
Utils::Fs::forceRemove(path);
|
||||
//To restore the cursor ...
|
||||
|
||||
// To restore the cursor ...
|
||||
setCursor(Qt::ArrowCursor);
|
||||
m_ui->uTorrentListButton->setEnabled(true);
|
||||
// Display information message if necessary
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void on_uTorrentListButton_clicked();
|
||||
void parseUTorrentList(const QString &, const QString &path);
|
||||
void parseUTorrentList(const QString &, const QByteArray &data);
|
||||
void getTrackerError(const QString &, const QString &error);
|
||||
|
||||
private:
|
||||
|
@ -292,7 +292,8 @@ void PluginSelectDialog::addNewPlugin(QString pluginName)
|
||||
else {
|
||||
// Icon is missing, we must download it
|
||||
using namespace Net;
|
||||
DownloadHandler *handler = DownloadManager::instance()->downloadUrl(plugin->url + "/favicon.ico", true);
|
||||
DownloadHandler *handler = DownloadManager::instance()->download(
|
||||
DownloadRequest(plugin->url + "/favicon.ico").saveToFile(true));
|
||||
connect(handler, static_cast<void (DownloadHandler::*)(const QString &, const QString &)>(&DownloadHandler::downloadFinished)
|
||||
, this, &PluginSelectDialog::iconDownloaded);
|
||||
connect(handler, &DownloadHandler::downloadFailed, this, &PluginSelectDialog::iconDownloadFailed);
|
||||
|
@ -404,7 +404,8 @@ void TrackerFiltersList::trackerWarning(const QString &hash, const QString &trac
|
||||
void TrackerFiltersList::downloadFavicon(const QString& url)
|
||||
{
|
||||
if (!m_downloadTrackerFavicon) return;
|
||||
Net::DownloadHandler *h = Net::DownloadManager::instance()->downloadUrl(url, true);
|
||||
Net::DownloadHandler *h = Net::DownloadManager::instance()->download(
|
||||
Net::DownloadRequest(url).saveToFile(true));
|
||||
using Func = void (Net::DownloadHandler::*)(const QString &, const QString &);
|
||||
connect(h, static_cast<Func>(&Net::DownloadHandler::downloadFinished), this
|
||||
, &TrackerFiltersList::handleFavicoDownload);
|
||||
|
Loading…
x
Reference in New Issue
Block a user