mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 21:14:33 +00:00
Cleanup code
Also remove redundant code, it is already handled correctly in subsequent function calls.
This commit is contained in:
parent
19d6de795c
commit
6759446639
@ -2090,12 +2090,9 @@ TorrentStatusReport Session::torrentStatusReport() const
|
|||||||
return m_torrentStatusReport;
|
return m_torrentStatusReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
// source - .torrent file path/url or magnet uri
|
bool Session::addTorrent(const QString &source, const AddTorrentParams ¶ms)
|
||||||
bool Session::addTorrent(QString source, const AddTorrentParams ¶ms)
|
|
||||||
{
|
{
|
||||||
MagnetUri magnetUri(source);
|
// `source`: .torrent file path/url or magnet uri
|
||||||
if (magnetUri.isValid())
|
|
||||||
return addTorrent_impl(CreateTorrentParams(params), magnetUri);
|
|
||||||
|
|
||||||
if (Utils::Misc::isUrl(source)) {
|
if (Utils::Misc::isUrl(source)) {
|
||||||
LogMsg(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));
|
||||||
@ -2110,6 +2107,10 @@ bool Session::addTorrent(QString source, const AddTorrentParams ¶ms)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MagnetUri magnetUri {source};
|
||||||
|
if (magnetUri.isValid())
|
||||||
|
return addTorrent_impl(CreateTorrentParams(params), magnetUri);
|
||||||
|
|
||||||
TorrentFileGuard guard(source);
|
TorrentFileGuard guard(source);
|
||||||
if (addTorrent_impl(CreateTorrentParams(params)
|
if (addTorrent_impl(CreateTorrentParams(params)
|
||||||
, MagnetUri(), TorrentInfo::loadFromFile(source))) {
|
, MagnetUri(), TorrentInfo::loadFromFile(source))) {
|
||||||
|
@ -469,7 +469,7 @@ namespace BitTorrent
|
|||||||
void banIP(const QString &ip);
|
void banIP(const QString &ip);
|
||||||
|
|
||||||
bool isKnownTorrent(const InfoHash &hash) const;
|
bool isKnownTorrent(const InfoHash &hash) const;
|
||||||
bool addTorrent(QString source, const AddTorrentParams ¶ms = AddTorrentParams());
|
bool addTorrent(const QString &source, const AddTorrentParams ¶ms = AddTorrentParams());
|
||||||
bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams ¶ms = AddTorrentParams());
|
bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams ¶ms = AddTorrentParams());
|
||||||
bool deleteTorrent(const QString &hash, bool deleteLocalFiles = false);
|
bool deleteTorrent(const QString &hash, bool deleteLocalFiles = false);
|
||||||
bool loadMetadata(const MagnetUri &magnetUri);
|
bool loadMetadata(const MagnetUri &magnetUri);
|
||||||
|
@ -227,7 +227,7 @@ void AddNewTorrentDialog::saveState()
|
|||||||
settings()->storeValue(KEY_EXPANDED, m_ui->toolButtonAdvanced->isChecked());
|
settings()->storeValue(KEY_EXPANDED, m_ui->toolButtonAdvanced->isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddNewTorrentDialog::show(QString source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent)
|
void AddNewTorrentDialog::show(const QString &source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent)
|
||||||
{
|
{
|
||||||
AddNewTorrentDialog *dlg = new AddNewTorrentDialog(inParams, parent);
|
AddNewTorrentDialog *dlg = new AddNewTorrentDialog(inParams, parent);
|
||||||
|
|
||||||
@ -240,27 +240,27 @@ void AddNewTorrentDialog::show(QString source, const BitTorrent::AddTorrentParam
|
|||||||
, dlg, &AddNewTorrentDialog::handleDownloadFinished);
|
, dlg, &AddNewTorrentDialog::handleDownloadFinished);
|
||||||
connect(handler, &Net::DownloadHandler::downloadFailed, dlg, &AddNewTorrentDialog::handleDownloadFailed);
|
connect(handler, &Net::DownloadHandler::downloadFailed, dlg, &AddNewTorrentDialog::handleDownloadFailed);
|
||||||
connect(handler, &Net::DownloadHandler::redirectedToMagnet, dlg, &AddNewTorrentDialog::handleRedirectedToMagnet);
|
connect(handler, &Net::DownloadHandler::redirectedToMagnet, dlg, &AddNewTorrentDialog::handleRedirectedToMagnet);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BitTorrent::MagnetUri magnetUri(source);
|
||||||
|
const bool isLoaded = magnetUri.isValid()
|
||||||
|
? dlg->loadMagnet(magnetUri)
|
||||||
|
: dlg->loadTorrent(source);
|
||||||
|
|
||||||
|
if (isLoaded) {
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
dlg->exec();
|
||||||
|
#else
|
||||||
|
dlg->open();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bool ok = false;
|
delete dlg;
|
||||||
BitTorrent::MagnetUri magnetUri(source);
|
|
||||||
if (magnetUri.isValid())
|
|
||||||
ok = dlg->loadMagnet(magnetUri);
|
|
||||||
else
|
|
||||||
ok = dlg->loadTorrent(source);
|
|
||||||
|
|
||||||
if (ok)
|
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
dlg->exec();
|
|
||||||
#else
|
|
||||||
dlg->open();
|
|
||||||
#endif
|
|
||||||
else
|
|
||||||
delete dlg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddNewTorrentDialog::show(QString source, QWidget *parent)
|
void AddNewTorrentDialog::show(const QString &source, QWidget *parent)
|
||||||
{
|
{
|
||||||
show(source, BitTorrent::AddTorrentParams(), parent);
|
show(source, BitTorrent::AddTorrentParams(), parent);
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ public:
|
|||||||
static int savePathHistoryLength();
|
static int savePathHistoryLength();
|
||||||
static void setSavePathHistoryLength(int value);
|
static void setSavePathHistoryLength(int value);
|
||||||
|
|
||||||
static void show(QString source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent);
|
static void show(const QString &source, const BitTorrent::AddTorrentParams &inParams, QWidget *parent);
|
||||||
static void show(QString source, QWidget *parent);
|
static void show(const QString &source, QWidget *parent);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showAdvancedSettings(bool show);
|
void showAdvancedSettings(bool show);
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QRegularExpression>
|
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
@ -1628,11 +1627,7 @@ void MainWindow::showNotificationBaloon(QString title, QString msg) const
|
|||||||
void MainWindow::downloadFromURLList(const QStringList &urlList)
|
void MainWindow::downloadFromURLList(const QStringList &urlList)
|
||||||
{
|
{
|
||||||
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
|
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
|
||||||
for (QString url : urlList) {
|
for (const QString &url : urlList) {
|
||||||
if (((url.size() == 40) && !url.contains(QRegularExpression("[^0-9A-Fa-f]")))
|
|
||||||
|| ((url.size() == 32) && !url.contains(QRegularExpression("[^2-7A-Za-z]"))))
|
|
||||||
url = "magnet:?xt=urn:btih:" + url;
|
|
||||||
|
|
||||||
if (useTorrentAdditionDialog)
|
if (useTorrentAdditionDialog)
|
||||||
AddNewTorrentDialog::show(url, this);
|
AddNewTorrentDialog::show(url, this);
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user