mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-03 06:02:29 -06:00
Move Utils::Misc::isUrl() function
All usage of this function gets to call Net::DownloadManager eventually.
This commit is contained in:
@@ -2094,7 +2094,7 @@ bool Session::addTorrent(const QString &source, const AddTorrentParams ¶ms)
|
||||
{
|
||||
// `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));
|
||||
// Launch downloader
|
||||
Net::DownloadHandler *handler =
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
|
||||
#include "downloadmanager.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QNetworkCookie>
|
||||
@@ -210,6 +212,15 @@ bool Net::DownloadManager::deleteCookie(const QNetworkCookie &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()
|
||||
{
|
||||
auto proxyManager = ProxyConfigurationManager::instance();
|
||||
|
||||
@@ -103,6 +103,8 @@ namespace Net
|
||||
void setAllCookies(const QList<QNetworkCookie> &cookieList);
|
||||
bool deleteCookie(const QNetworkCookie &cookie);
|
||||
|
||||
static bool hasSupportedScheme(const QString &url);
|
||||
|
||||
private slots:
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void ignoreSslErrors(QNetworkReply *, const QList<QSslError> &);
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
#include "base/utils/bytearray.h"
|
||||
#include "base/utils/foreignapps.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "searchdownloadhandler.h"
|
||||
#include "searchhandler.h"
|
||||
|
||||
@@ -198,7 +197,7 @@ void SearchPluginManager::installPlugin(const QString &source)
|
||||
{
|
||||
clearPythonCache(engineLocation());
|
||||
|
||||
if (Utils::Misc::isUrl(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)
|
||||
|
||||
@@ -414,14 +414,6 @@ QList<bool> Utils::Misc::boolListfromStringList(const QStringList &l)
|
||||
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 result = rawText;
|
||||
|
||||
@@ -71,7 +71,6 @@ namespace Utils
|
||||
};
|
||||
|
||||
QString parseHtmlLinks(const QString &rawText);
|
||||
bool isUrl(const QString &s);
|
||||
|
||||
void shutdownComputer(const ShutdownDialogAction &action);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user