From f1c7c2beaf0385f8720f09b9fab0bac0cd614e2e Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sun, 11 Feb 2018 10:24:55 +0100 Subject: [PATCH] Remove NetworkProxyFactory --- src/lib/CMakeLists.txt | 1 - src/lib/network/networkproxyfactory.cpp | 171 ------------------ src/lib/network/networkproxyfactory.h | 75 -------- src/lib/preferences/preferences.cpp | 1 - src/plugins/StatusBarIcons/sbi_networkproxy.h | 3 +- 5 files changed, 1 insertion(+), 250 deletions(-) delete mode 100644 src/lib/network/networkproxyfactory.cpp delete mode 100644 src/lib/network/networkproxyfactory.h diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 343c113bc..9082b99e8 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -130,7 +130,6 @@ set(SRCS ${SRCS} navigation/siteicon.cpp navigation/websearchbar.cpp network/networkmanager.cpp - network/networkproxyfactory.cpp network/networkurlinterceptor.cpp network/schemehandlers/extensionschemehandler.cpp network/schemehandlers/falkonschemehandler.cpp diff --git a/src/lib/network/networkproxyfactory.cpp b/src/lib/network/networkproxyfactory.cpp deleted file mode 100644 index aa5d23a26..000000000 --- a/src/lib/network/networkproxyfactory.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* ============================================================ -* Falkon - Qt web browser -* Copyright (C) 2010-2014 David Rosca -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#include "networkproxyfactory.h" -#include "mainapplication.h" -#include "settings.h" - -WildcardMatcher::WildcardMatcher(const QString &pattern) - : m_regExp(0) -{ - setPattern(pattern); -} - -WildcardMatcher::~WildcardMatcher() -{ - delete m_regExp; -} - -void WildcardMatcher::setPattern(const QString &pattern) -{ - m_pattern = pattern; - - if (m_pattern.contains(QLatin1Char('?')) || m_pattern.contains(QLatin1Char('*'))) { - QString regexp = m_pattern; - regexp.replace(QLatin1Char('.'), QLatin1String("\\.")) - .replace(QLatin1Char('*'), QLatin1String(".*")) - .replace(QLatin1Char('?'), QLatin1Char('.')); - regexp = QString("^.*%1.*$").arg(regexp); - - m_regExp = new QzRegExp(regexp, Qt::CaseInsensitive); - } -} - -QString WildcardMatcher::pattern() const -{ - return m_pattern; -} - -bool WildcardMatcher::match(const QString &str) const -{ - if (!m_regExp) { - return str.contains(m_pattern, Qt::CaseInsensitive); - } - - return m_regExp->indexIn(str) > -1; -} - -NetworkProxyFactory::NetworkProxyFactory() - : QNetworkProxyFactory() - , m_proxyPreference(SystemProxy) - , m_proxyType(QNetworkProxy::NoProxy) - , m_port(0) - , m_httpsPort(0) - , m_useDifferentProxyForHttps(false) -{ -} - -void NetworkProxyFactory::loadSettings() -{ - Settings settings; - settings.beginGroup("Web-Proxy"); - m_proxyPreference = ProxyPreference(settings.value("UseProxy", SystemProxy).toInt()); - m_proxyType = QNetworkProxy::ProxyType(settings.value("ProxyType", QNetworkProxy::NoProxy).toInt()); - m_useDifferentProxyForHttps = settings.value("UseDifferentProxyForHttps", false).toBool(); - - m_hostName = settings.value("HostName", QString()).toString(); - m_port = settings.value("Port", 8080).toInt(); - m_username = settings.value("Username", QString()).toString(); - m_password = settings.value("Password", QString()).toString(); - - m_httpsHostName = settings.value("HttpsHostName", QString()).toString(); - m_httpsPort = settings.value("HttpsPort", 8080).toInt(); - m_httpsUsername = settings.value("HttpsUsername", QString()).toString(); - m_httpsPassword = settings.value("HttpsPassword", QString()).toString(); - - QStringList exceptions = settings.value("ProxyExceptions", QStringList() << "localhost" << "127.0.0.1").toStringList(); - settings.endGroup(); - - qDeleteAll(m_proxyExceptions); - m_proxyExceptions.clear(); - - foreach (const QString &exception, exceptions) { - m_proxyExceptions.append(new WildcardMatcher(exception.trimmed())); - } -} - -NetworkProxyFactory::ProxyPreference NetworkProxyFactory::proxyPreference() const -{ - return m_proxyPreference; -} - -QList NetworkProxyFactory::queryProxy(const QNetworkProxyQuery &query) -{ - QList proxyList; - - if (m_proxyPreference == NoProxy) { - proxyList.append(QNetworkProxy::NoProxy); - return proxyList; - } - - const QString urlHost = query.url().host(); - foreach (WildcardMatcher* m, m_proxyExceptions) { - if (m->match(urlHost)) { - proxyList.append(QNetworkProxy::NoProxy); - return proxyList; - } - } - - switch (m_proxyPreference) { - case SystemProxy: - proxyList.append(systemProxyForQuery(query)); - break; - - case ProxyAutoConfig: - qWarning() << "PAC Not Implemented!"; - break; - - case DefinedProxy: { - QNetworkProxy proxy(m_proxyType); - - if (m_useDifferentProxyForHttps && query.protocolTag() == QLatin1String("https")) { - proxy.setHostName(m_httpsHostName); - proxy.setPort(m_httpsPort); - proxy.setUser(m_httpsUsername); - proxy.setPassword(m_httpsPassword); - } - else { - proxy.setHostName(m_hostName); - proxy.setPort(m_port); - proxy.setUser(m_username); - proxy.setPassword(m_password); - } - - if (proxy.hostName().isEmpty()) { - proxy = QNetworkProxy::NoProxy; - } - - proxyList.append(proxy); - break; - } - - default: - qWarning("NetworkProxyFactory::queryProxy Unknown proxy type!"); - break; - } - - if (!proxyList.contains(QNetworkProxy::NoProxy)) { - proxyList.append(QNetworkProxy::NoProxy); - } - - return proxyList; -} - -NetworkProxyFactory::~NetworkProxyFactory() -{ - qDeleteAll(m_proxyExceptions); -} diff --git a/src/lib/network/networkproxyfactory.h b/src/lib/network/networkproxyfactory.h deleted file mode 100644 index 471a50180..000000000 --- a/src/lib/network/networkproxyfactory.h +++ /dev/null @@ -1,75 +0,0 @@ -/* ============================================================ -* Falkon - Qt web browser -* Copyright (C) 2010-2014 David Rosca -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#ifndef NETWORKPROXYFACTORY_H -#define NETWORKPROXYFACTORY_H - -#include -#include - -#include "qzcommon.h" -#include "qzregexp.h" - -class WildcardMatcher -{ -public: - explicit WildcardMatcher(const QString &pattern = QString()); - ~WildcardMatcher(); - - void setPattern(const QString &pattern); - QString pattern() const; - - bool match(const QString &str) const; - -private: - QString m_pattern; - QzRegExp* m_regExp; -}; - -class FALKON_EXPORT NetworkProxyFactory : public QNetworkProxyFactory -{ -public: - enum ProxyPreference { SystemProxy, NoProxy, ProxyAutoConfig, DefinedProxy }; - - explicit NetworkProxyFactory(); - ~NetworkProxyFactory(); - - void loadSettings(); - - ProxyPreference proxyPreference() const; - - QList queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()); - -private: - ProxyPreference m_proxyPreference; - QNetworkProxy::ProxyType m_proxyType; - - QString m_hostName; - quint16 m_port; - QString m_username; - QString m_password; - - QString m_httpsHostName; - quint16 m_httpsPort; - QString m_httpsUsername; - QString m_httpsPassword; - - QList m_proxyExceptions; - bool m_useDifferentProxyForHttps; -}; - -#endif // NETWORKPROXYFACTORY_H diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index ef8d13f26..f21bd41ce 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -29,7 +29,6 @@ #include "pluginproxy.h" #include "pluginsmanager.h" #include "jsoptions.h" -#include "networkproxyfactory.h" #include "networkmanager.h" #include "desktopnotificationsfactory.h" #include "desktopnotification.h" diff --git a/src/plugins/StatusBarIcons/sbi_networkproxy.h b/src/plugins/StatusBarIcons/sbi_networkproxy.h index 0125acb8b..5e290e707 100644 --- a/src/plugins/StatusBarIcons/sbi_networkproxy.h +++ b/src/plugins/StatusBarIcons/sbi_networkproxy.h @@ -19,8 +19,7 @@ #define SBI_NETWORKPROXY_H #include - -#include "networkproxyfactory.h" +#include class QSettings;