1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 17:42:10 +01:00
falkonOfficial/src/lib/network/networkproxyfactory.cpp

116 lines
3.8 KiB
C++
Raw Normal View History

2011-04-27 09:05:54 +02:00
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
2011-04-27 09:05:54 +02:00
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
2011-04-26 19:47:12 +02:00
#include "networkproxyfactory.h"
#include "mainapplication.h"
#include "settings.h"
#include "pac/pacmanager.h"
2011-04-26 19:47:12 +02:00
NetworkProxyFactory::NetworkProxyFactory()
: QNetworkProxyFactory()
, m_pacManager(new PacManager)
, m_proxyPreference(SystemProxy)
2011-04-26 19:47:12 +02:00
{
}
void NetworkProxyFactory::loadSettings()
{
Settings settings;
2011-04-26 19:47:12 +02:00
settings.beginGroup("Web-Proxy");
m_proxyPreference = ProxyPreference(settings.value("UseProxy", SystemProxy).toInt());
m_proxyType = QNetworkProxy::ProxyType(settings.value("ProxyType", QNetworkProxy::HttpProxy).toInt());
m_useDifferentProxyForHttps = settings.value("UseDifferentProxyForHttps", false).toBool();
m_hostName = settings.value("HostName", QString()).toString();
2011-04-26 19:47:12 +02:00
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();
2011-04-26 19:47:12 +02:00
m_proxyExceptions = settings.value("ProxyExceptions", QStringList() << "localhost" << "127.0.0.1").toStringList();
settings.endGroup();
m_pacManager->loadSettings();
}
PacManager* NetworkProxyFactory::pacManager() const
{
return m_pacManager;
2011-04-26 19:47:12 +02:00
}
QList<QNetworkProxy> NetworkProxyFactory::queryProxy(const QNetworkProxyQuery &query)
{
QList<QNetworkProxy> proxyList;
2011-04-26 19:47:12 +02:00
if (m_proxyExceptions.contains(query.url().host(), Qt::CaseInsensitive)) {
proxyList.append(QNetworkProxy::NoProxy);
return proxyList;
}
2011-04-26 19:47:12 +02:00
switch (m_proxyPreference) {
case SystemProxy:
proxyList.append(systemProxyForQuery(query));
break;
2011-04-26 19:47:12 +02:00
case NoProxy:
proxyList.append(QNetworkProxy::NoProxy);
2011-04-26 19:47:12 +02:00
break;
case ProxyAutoConfig:
proxyList.append(m_pacManager->queryProxy(query.url()));
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!");
2011-04-26 19:47:12 +02:00
break;
}
if (!proxyList.contains(QNetworkProxy::NoProxy)) {
proxyList.append(QNetworkProxy::NoProxy);
}
return proxyList;
2011-04-26 19:47:12 +02:00
}