Browse Source

Use new DownloadManager interface

adaptive-webui-19844
Vladimir Golovnev (Glassez) 7 years ago
parent
commit
112a9bcfa2
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 12
      src/base/bittorrent/session.cpp
  2. 2
      src/base/bittorrent/session.h
  3. 10
      src/base/net/dnsupdater.cpp
  4. 5
      src/base/net/downloadmanager.cpp
  5. 1
      src/base/net/downloadmanager.h
  6. 2
      src/base/net/geoipmanager.cpp
  7. 5
      src/base/rss/rss_feed.cpp
  8. 4
      src/base/search/searchpluginmanager.cpp
  9. 4
      src/gui/addnewtorrentdialog.cpp
  10. 10
      src/gui/mainwindow.cpp
  11. 5
      src/gui/programupdater.cpp
  12. 30
      src/gui/properties/trackersadditiondialog.cpp
  13. 2
      src/gui/properties/trackersadditiondialog.h
  14. 3
      src/gui/search/pluginselectdialog.cpp
  15. 3
      src/gui/transferlistfilterswidget.cpp

12
src/base/bittorrent/session.cpp

@ -1844,11 +1844,10 @@ void Session::handleRedirectedToMagnet(const QString &url, const QString &magnet @@ -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 &params) @@ -2077,10 +2076,11 @@ bool Session::addTorrent(QString source, const AddTorrentParams &params)
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);

2
src/base/bittorrent/session.h

@ -547,7 +547,7 @@ namespace BitTorrent @@ -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);

10
src/base/net/dnsupdater.cpp

@ -75,9 +75,8 @@ void DNSUpdater::checkPublicIP() @@ -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() @@ -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);

5
src/base/net/downloadmanager.cpp

@ -155,11 +155,6 @@ Net::DownloadManager *Net::DownloadManager::instance() @@ -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

1
src/base/net/downloadmanager.h

@ -93,7 +93,6 @@ namespace Net @@ -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);

2
src/base/net/geoipmanager.cpp

@ -118,7 +118,7 @@ void GeoIPManager::manageDatabaseUpdate() @@ -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);

5
src/base/rss/rss_feed.cpp

@ -129,7 +129,7 @@ void Feed::refresh() @@ -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() @@ -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);

4
src/base/search/searchpluginmanager.cpp

@ -170,7 +170,7 @@ void SearchPluginManager::installPlugin(const QString &source) @@ -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() @@ -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);

4
src/gui/addnewtorrentdialog.cpp

@ -230,7 +230,9 @@ void AddNewTorrentDialog::show(QString source, const BitTorrent::AddTorrentParam @@ -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);

10
src/gui/mainwindow.cpp

@ -2043,11 +2043,11 @@ void MainWindow::installPython() @@ -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);

5
src/gui/programupdater.cpp

@ -61,11 +61,10 @@ ProgramUpdater::ProgramUpdater(QObject *parent, bool invokedByUser) @@ -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)");
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);

30
src/gui/properties/trackersadditiondialog.cpp

@ -25,9 +25,10 @@ @@ -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 @@ -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,18 +95,20 @@ void TrackersAdditionDialog::parseUTorrentList(const QString &, const QString &p @@ -103,18 +95,20 @@ 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 ...
setCursor(Qt::ArrowCursor);
m_ui->uTorrentListButton->setEnabled(true);

2
src/gui/properties/trackersadditiondialog.h

@ -57,7 +57,7 @@ public: @@ -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:

3
src/gui/search/pluginselectdialog.cpp

@ -292,7 +292,8 @@ void PluginSelectDialog::addNewPlugin(QString pluginName) @@ -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);

3
src/gui/transferlistfilterswidget.cpp

@ -404,7 +404,8 @@ void TrackerFiltersList::trackerWarning(const QString &hash, const QString &trac @@ -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…
Cancel
Save