mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 21:03:30 -07:00
Move Utils::Misc::isUrl() function
All usage of this function gets to call Net::DownloadManager eventually.
This commit is contained in:
parent
6759446639
commit
2b903fc3d1
10 changed files with 20 additions and 18 deletions
|
@ -2094,7 +2094,7 @@ bool Session::addTorrent(const QString &source, const AddTorrentParams ¶ms)
|
||||||
{
|
{
|
||||||
// `source`: .torrent file path/url or magnet uri
|
// `source`: .torrent file path/url or magnet uri
|
||||||
|
|
||||||
if (Utils::Misc::isUrl(source)) {
|
if (Net::DownloadManager::hasSupportedScheme(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));
|
||||||
// Launch downloader
|
// Launch downloader
|
||||||
Net::DownloadHandler *handler =
|
Net::DownloadHandler *handler =
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
|
|
||||||
#include "downloadmanager.h"
|
#include "downloadmanager.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QNetworkCookie>
|
#include <QNetworkCookie>
|
||||||
|
@ -210,6 +212,15 @@ bool Net::DownloadManager::deleteCookie(const QNetworkCookie &cookie)
|
||||||
return static_cast<NetworkCookieJar *>(m_networkManager.cookieJar())->deleteCookie(cookie);
|
return static_cast<NetworkCookieJar *>(m_networkManager.cookieJar())->deleteCookie(cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Net::DownloadManager::hasSupportedScheme(const QString &url)
|
||||||
|
{
|
||||||
|
const QStringList schemes = instance()->m_networkManager.supportedSchemes();
|
||||||
|
return std::any_of(schemes.cbegin(), schemes.cend(), [&url](const QString &scheme)
|
||||||
|
{
|
||||||
|
return url.startsWith((scheme + QLatin1Char(':')), Qt::CaseInsensitive);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void Net::DownloadManager::applyProxySettings()
|
void Net::DownloadManager::applyProxySettings()
|
||||||
{
|
{
|
||||||
auto proxyManager = ProxyConfigurationManager::instance();
|
auto proxyManager = ProxyConfigurationManager::instance();
|
||||||
|
|
|
@ -103,6 +103,8 @@ namespace Net
|
||||||
void setAllCookies(const QList<QNetworkCookie> &cookieList);
|
void setAllCookies(const QList<QNetworkCookie> &cookieList);
|
||||||
bool deleteCookie(const QNetworkCookie &cookie);
|
bool deleteCookie(const QNetworkCookie &cookie);
|
||||||
|
|
||||||
|
static bool hasSupportedScheme(const QString &url);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
#ifndef QT_NO_OPENSSL
|
#ifndef QT_NO_OPENSSL
|
||||||
void ignoreSslErrors(QNetworkReply *, const QList<QSslError> &);
|
void ignoreSslErrors(QNetworkReply *, const QList<QSslError> &);
|
||||||
|
|
|
@ -50,7 +50,6 @@
|
||||||
#include "base/utils/bytearray.h"
|
#include "base/utils/bytearray.h"
|
||||||
#include "base/utils/foreignapps.h"
|
#include "base/utils/foreignapps.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/utils/misc.h"
|
|
||||||
#include "searchdownloadhandler.h"
|
#include "searchdownloadhandler.h"
|
||||||
#include "searchhandler.h"
|
#include "searchhandler.h"
|
||||||
|
|
||||||
|
@ -198,7 +197,7 @@ void SearchPluginManager::installPlugin(const QString &source)
|
||||||
{
|
{
|
||||||
clearPythonCache(engineLocation());
|
clearPythonCache(engineLocation());
|
||||||
|
|
||||||
if (Utils::Misc::isUrl(source)) {
|
if (Net::DownloadManager::hasSupportedScheme(source)) {
|
||||||
using namespace Net;
|
using namespace Net;
|
||||||
DownloadHandler *handler = DownloadManager::instance()->download(DownloadRequest(source).saveToFile(true));
|
DownloadHandler *handler = DownloadManager::instance()->download(DownloadRequest(source).saveToFile(true));
|
||||||
connect(handler, static_cast<void (DownloadHandler::*)(const QString &, const QString &)>(&DownloadHandler::downloadFinished)
|
connect(handler, static_cast<void (DownloadHandler::*)(const QString &, const QString &)>(&DownloadHandler::downloadFinished)
|
||||||
|
|
|
@ -414,14 +414,6 @@ QList<bool> Utils::Misc::boolListfromStringList(const QStringList &l)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::Misc::isUrl(const QString &s)
|
|
||||||
{
|
|
||||||
static const QRegularExpression reURLScheme(
|
|
||||||
"http[s]?|ftp", QRegularExpression::CaseInsensitiveOption);
|
|
||||||
|
|
||||||
return reURLScheme.match(QUrl(s).scheme()).hasMatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Utils::Misc::parseHtmlLinks(const QString &rawText)
|
QString Utils::Misc::parseHtmlLinks(const QString &rawText)
|
||||||
{
|
{
|
||||||
QString result = rawText;
|
QString result = rawText;
|
||||||
|
|
|
@ -71,7 +71,6 @@ namespace Utils
|
||||||
};
|
};
|
||||||
|
|
||||||
QString parseHtmlLinks(const QString &rawText);
|
QString parseHtmlLinks(const QString &rawText);
|
||||||
bool isUrl(const QString &s);
|
|
||||||
|
|
||||||
void shutdownComputer(const ShutdownDialogAction &action);
|
void shutdownComputer(const ShutdownDialogAction &action);
|
||||||
|
|
||||||
|
|
|
@ -231,7 +231,7 @@ void AddNewTorrentDialog::show(const QString &source, const BitTorrent::AddTorre
|
||||||
{
|
{
|
||||||
AddNewTorrentDialog *dlg = new AddNewTorrentDialog(inParams, parent);
|
AddNewTorrentDialog *dlg = new AddNewTorrentDialog(inParams, parent);
|
||||||
|
|
||||||
if (Utils::Misc::isUrl(source)) {
|
if (Net::DownloadManager::hasSupportedScheme(source)) {
|
||||||
// Launch downloader
|
// Launch downloader
|
||||||
// TODO: Don't save loaded torrent to file, just use downloaded data!
|
// TODO: Don't save loaded torrent to file, just use downloaded data!
|
||||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(
|
Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
#include "base/bittorrent/torrenthandle.h"
|
#include "base/bittorrent/torrenthandle.h"
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/logger.h"
|
#include "base/logger.h"
|
||||||
|
#include "base/net/downloadmanager.h"
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
#include "base/rss/rss_folder.h"
|
#include "base/rss/rss_folder.h"
|
||||||
#include "base/rss/rss_session.h"
|
#include "base/rss/rss_session.h"
|
||||||
|
@ -1295,7 +1296,7 @@ void MainWindow::dropEvent(QDropEvent *event)
|
||||||
for (const QString &file : asConst(files)) {
|
for (const QString &file : asConst(files)) {
|
||||||
const bool isTorrentLink = (file.startsWith("magnet:", Qt::CaseInsensitive)
|
const bool isTorrentLink = (file.startsWith("magnet:", Qt::CaseInsensitive)
|
||||||
|| file.endsWith(C_TORRENT_FILE_EXTENSION, Qt::CaseInsensitive)
|
|| file.endsWith(C_TORRENT_FILE_EXTENSION, Qt::CaseInsensitive)
|
||||||
|| Utils::Misc::isUrl(file));
|
|| Net::DownloadManager::hasSupportedScheme(file));
|
||||||
if (isTorrentLink)
|
if (isTorrentLink)
|
||||||
torrentFiles << file;
|
torrentFiles << file;
|
||||||
else
|
else
|
||||||
|
|
|
@ -48,7 +48,6 @@
|
||||||
#include "base/rss/rss_feed.h"
|
#include "base/rss/rss_feed.h"
|
||||||
#include "base/rss/rss_folder.h"
|
#include "base/rss/rss_folder.h"
|
||||||
#include "base/rss/rss_session.h"
|
#include "base/rss/rss_session.h"
|
||||||
#include "base/utils/misc.h"
|
|
||||||
#include "addnewtorrentdialog.h"
|
#include "addnewtorrentdialog.h"
|
||||||
#include "articlelistwidget.h"
|
#include "articlelistwidget.h"
|
||||||
#include "autoexpandabledialog.h"
|
#include "autoexpandabledialog.h"
|
||||||
|
@ -249,7 +248,7 @@ void RSSWidget::on_newFeedButton_clicked()
|
||||||
{
|
{
|
||||||
// Ask for feed URL
|
// Ask for feed URL
|
||||||
const QString clipText = qApp->clipboard()->text();
|
const QString clipText = qApp->clipboard()->text();
|
||||||
const QString defaultURL = (Utils::Misc::isUrl(clipText) ? clipText : "http://");
|
const QString defaultURL = Net::DownloadManager::hasSupportedScheme(clipText) ? clipText : "http://";
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
QString newURL = AutoExpandableDialog::getText(
|
QString newURL = AutoExpandableDialog::getText(
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
#include "base/net/downloadhandler.h"
|
#include "base/net/downloadhandler.h"
|
||||||
#include "base/net/downloadmanager.h"
|
#include "base/net/downloadmanager.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/utils/misc.h"
|
|
||||||
#include "autoexpandabledialog.h"
|
#include "autoexpandabledialog.h"
|
||||||
#include "guiiconprovider.h"
|
#include "guiiconprovider.h"
|
||||||
#include "pluginsourcedialog.h"
|
#include "pluginsourcedialog.h"
|
||||||
|
@ -337,7 +336,7 @@ void PluginSelectDialog::askForPluginUrl()
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
QString clipTxt = qApp->clipboard()->text();
|
QString clipTxt = qApp->clipboard()->text();
|
||||||
QString defaultUrl = "http://";
|
QString defaultUrl = "http://";
|
||||||
if (Utils::Misc::isUrl(clipTxt) && clipTxt.endsWith(".py"))
|
if (Net::DownloadManager::hasSupportedScheme(clipTxt) && clipTxt.endsWith(".py"))
|
||||||
defaultUrl = clipTxt;
|
defaultUrl = clipTxt;
|
||||||
QString url = AutoExpandableDialog::getText(
|
QString url = AutoExpandableDialog::getText(
|
||||||
this, tr("New search engine plugin URL"),
|
this, tr("New search engine plugin URL"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue