1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

StatusBarIcons: Update NetworkIcon to work with QNetworkProxy

This should make it work with proxy config in Qt 5.6
This commit is contained in:
David Rosca 2015-08-28 10:58:54 +02:00
parent c04adb2a96
commit adea1139b9
8 changed files with 42 additions and 362 deletions

View File

@ -136,7 +136,6 @@ void SBI_IconsManager::mainWindowCreated(BrowserWindow* window)
m_windows[window].append(w);
}
#if QTWEBENGINE_DISABLED
if (m_showNetworkIcon) {
if (!m_networkManager) {
m_networkManager = new SBI_NetworkManager(m_settingsPath, this);
@ -146,7 +145,6 @@ void SBI_IconsManager::mainWindowCreated(BrowserWindow* window)
window->statusBar()->addPermanentWidget(w);
m_windows[window].append(w);
}
#endif
if (m_showZoomWidget) {
SBI_ZoomWidget* w = new SBI_ZoomWidget(window);

View File

@ -20,8 +20,6 @@
#include "sbi_networkproxy.h"
#include "sbi_networkmanager.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "networkproxyfactory.h"
#include "browserwindow.h"
#include <QMenu>
@ -105,29 +103,19 @@ void SBI_NetworkIcon::updateToolTip()
tooltip = tooltip.arg(tr("Offline"));
}
#if QTWEBENGINE_DISABLED
switch (mApp->networkManager()->proxyFactory()->proxyPreference()) {
case NetworkProxyFactory::SystemProxy:
switch (QNetworkProxy::applicationProxy().type()) {
case QNetworkProxy::DefaultProxy:
tooltip = tooltip.arg(tr("System proxy"));
break;
case NetworkProxyFactory::NoProxy:
case QNetworkProxy::NoProxy:
tooltip = tooltip.arg(tr("No proxy"));
break;
case NetworkProxyFactory::ProxyAutoConfig:
tooltip = tooltip.arg(tr("PAC (Proxy Auto-Config)"));
break;
case NetworkProxyFactory::DefinedProxy:
default:
tooltip = tooltip.arg(tr("User defined"));
break;
default:
qWarning() << "Unknown NetworkProxyFactory::ProxyPreference!";
break;
}
#endif
if (SBINetManager->currentProxy()) {
tooltip.append(QString(" (%1)").arg(SBINetManager->currentProxyName()));

View File

@ -122,16 +122,7 @@ void SBI_NetworkManager::applyCurrentProxy()
return;
}
// Manually modify settings to apply proxy configuration
QSettings settings(DataPaths::currentProfilePath() + "/settings.ini", QSettings::IniFormat);
settings.beginGroup("Web-Proxy");
m_currentProxy->saveToSettings(settings);
settings.endGroup();
settings.sync();
#if QTWEBENGINE_DISABLED
mApp->networkManager()->proxyFactory()->loadSettings();
#endif
m_currentProxy->applyProxy();
}
void SBI_NetworkManager::deleteProxies()

View File

@ -21,10 +21,7 @@
SBI_NetworkProxy::SBI_NetworkProxy()
: m_port(0)
, m_httpsPort(0)
, m_useDifferentProxyForHttps(false)
, m_preference(NetworkProxyFactory::DefinedProxy)
, m_type(QNetworkProxy::HttpProxy)
, m_type(QNetworkProxy::NoProxy)
{
}
@ -32,10 +29,7 @@ bool SBI_NetworkProxy::operator ==(const SBI_NetworkProxy &other) const
{
return m_port == other.m_port && m_hostname == other.m_hostname &&
m_username == other.m_username && m_password == other.m_password &&
m_httpsPort == other.m_httpsPort && m_httpsHostname == other.m_httpsHostname &&
m_httpsUsername == other.m_httpsUsername && m_httpsPassword == other.m_httpsPassword &&
m_useDifferentProxyForHttps == other.m_useDifferentProxyForHttps && m_preference == other.m_preference &&
m_type == other.m_type && m_exceptions == other.m_exceptions;
m_type == other.m_type;
}
quint16 SBI_NetworkProxy::port() const
@ -78,76 +72,6 @@ void SBI_NetworkProxy::setPassword(const QString &password)
m_password = password;
}
quint16 SBI_NetworkProxy::httpsPort() const
{
return m_httpsPort;
}
void SBI_NetworkProxy::setHttpsPort(quint16 port)
{
m_httpsPort = port;
}
QString SBI_NetworkProxy::httpsHostName() const
{
return m_httpsHostname;
}
void SBI_NetworkProxy::setHttpsHostName(const QString &hostName)
{
m_httpsHostname = hostName;
}
QString SBI_NetworkProxy::httpsUserName() const
{
return m_httpsUsername;
}
void SBI_NetworkProxy::setHttpsUserName(const QString &userName)
{
m_httpsUsername = userName;
}
QString SBI_NetworkProxy::httpsPassword() const
{
return m_httpsPassword;
}
void SBI_NetworkProxy::setHttpsPassword(const QString &password)
{
m_httpsPassword = password;
}
QUrl SBI_NetworkProxy::proxyAutoConfigUrl() const
{
return m_pacUrl;
}
void SBI_NetworkProxy::setProxyAutoConfigUrl(const QUrl &url)
{
m_pacUrl = url;
}
bool SBI_NetworkProxy::useDifferentProxyForHttps() const
{
return m_useDifferentProxyForHttps;
}
void SBI_NetworkProxy::setUseDifferentProxyForHttps(bool use)
{
m_useDifferentProxyForHttps = use;
}
NetworkProxyFactory::ProxyPreference SBI_NetworkProxy::preference() const
{
return m_preference;
}
void SBI_NetworkProxy::setPreference(NetworkProxyFactory::ProxyPreference preference)
{
m_preference = preference;
}
QNetworkProxy::ProxyType SBI_NetworkProxy::type() const
{
return m_type;
@ -158,16 +82,6 @@ void SBI_NetworkProxy::setType(QNetworkProxy::ProxyType type)
m_type = type;
}
QStringList SBI_NetworkProxy::exceptions() const
{
return m_exceptions;
}
void SBI_NetworkProxy::setExceptions(const QStringList &exceptions)
{
m_exceptions = exceptions;
}
void SBI_NetworkProxy::loadFromSettings(const QSettings &settings)
{
m_hostname = settings.value("HostName", QString()).toString();
@ -175,16 +89,7 @@ void SBI_NetworkProxy::loadFromSettings(const QSettings &settings)
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", 0).toInt();
m_httpsUsername = settings.value("HttpsUsername", QString()).toString();
m_httpsPassword = settings.value("HttpsPassword", QString()).toString();
m_pacUrl = settings.value("PacUrl", QUrl()).toUrl();
m_useDifferentProxyForHttps = settings.value("UseDifferentProxyForHttps", false).toBool();
m_preference = NetworkProxyFactory::ProxyPreference(settings.value("UseProxy", NetworkProxyFactory::SystemProxy).toInt());
m_type = QNetworkProxy::ProxyType(settings.value("ProxyType", QNetworkProxy::HttpProxy).toInt());
m_exceptions = settings.value("ProxyExceptions", QStringList() << "localhost" << "127.0.0.1").toStringList();
}
void SBI_NetworkProxy::saveToSettings(QSettings &settings) const
@ -194,14 +99,17 @@ void SBI_NetworkProxy::saveToSettings(QSettings &settings) const
settings.setValue("Username", m_username);
settings.setValue("Password", m_password);
settings.setValue("HttpsHostName", m_httpsHostname);
settings.setValue("HttpsPort", m_httpsPort);
settings.setValue("HttpsUsername", m_httpsUsername);
settings.setValue("HttpsPassword", m_httpsPassword);
settings.setValue("PacUrl", m_pacUrl);
settings.setValue("UseDifferentProxyForHttps", m_useDifferentProxyForHttps);
settings.setValue("UseProxy", m_preference);
settings.setValue("ProxyType", m_type);
settings.setValue("ProxyExceptions", m_exceptions);
}
void SBI_NetworkProxy::applyProxy()
{
QNetworkProxy proxy;
proxy.setHostName(m_hostname);
proxy.setPort(m_port);
proxy.setUser(m_username);
proxy.setPassword(m_password);
proxy.setType(m_type);
QNetworkProxy::setApplicationProxy(proxy);
}

View File

@ -43,53 +43,21 @@ public:
QString password() const;
void setPassword(const QString &password);
quint16 httpsPort() const;
void setHttpsPort(quint16 port);
QString httpsHostName() const;
void setHttpsHostName(const QString &hostName);
QString httpsUserName() const;
void setHttpsUserName(const QString &userName);
QString httpsPassword() const;
void setHttpsPassword(const QString &password);
QUrl proxyAutoConfigUrl() const;
void setProxyAutoConfigUrl(const QUrl &url);
bool useDifferentProxyForHttps() const;
void setUseDifferentProxyForHttps(bool use);
NetworkProxyFactory::ProxyPreference preference() const;
void setPreference(NetworkProxyFactory::ProxyPreference preference);
QNetworkProxy::ProxyType type() const;
void setType(QNetworkProxy::ProxyType type);
QStringList exceptions() const;
void setExceptions(const QStringList &exceptions);
void loadFromSettings(const QSettings &settings);
void saveToSettings(QSettings &settings) const;
void applyProxy();
private:
quint16 m_port;
QString m_hostname;
QString m_username;
QString m_password;
quint16 m_httpsPort;
QString m_httpsHostname;
QString m_httpsUsername;
QString m_httpsPassword;
QUrl m_pacUrl;
bool m_useDifferentProxyForHttps;
NetworkProxyFactory::ProxyPreference m_preference;
QNetworkProxy::ProxyType m_type;
QStringList m_exceptions;
};
#endif // SBI_NETWORKPROXY_H

View File

@ -24,10 +24,6 @@ SBI_ProxyWidget::SBI_ProxyWidget(QWidget* parent) :
ui(new Ui::SBI_ProxyWidget)
{
ui->setupUi(this);
useHttpsProxyChanged(false);
connect(ui->useHttpsProxy, SIGNAL(toggled(bool)), this, SLOT(useHttpsProxyChanged(bool)));
}
void SBI_ProxyWidget::clear()
@ -37,16 +33,7 @@ void SBI_ProxyWidget::clear()
ui->proxyUsername->clear();
ui->proxyPassword->clear();
ui->httpsProxyServer->clear();
ui->httpsProxyPort->clear();
ui->httpsProxyUsername->clear();
ui->httpsProxyPassword->clear();
ui->proxyExceptions->clear();
ui->pacUrl->clear();
ui->proxyType->setCurrentIndex(0);
ui->useHttpsProxy->setChecked(false);
ui->noProxy->setChecked(true);
}
@ -59,28 +46,12 @@ SBI_NetworkProxy* SBI_ProxyWidget::getProxy() const
proxy->setUserName(ui->proxyUsername->text());
proxy->setPassword(ui->proxyPassword->text());
proxy->setHttpsHostName(ui->httpsProxyServer->text());
proxy->setHttpsPort(ui->httpsProxyPort->text().toInt());
proxy->setHttpsUserName(ui->httpsProxyUsername->text());
proxy->setHttpsPassword(ui->httpsProxyPassword->text());
proxy->setExceptions(ui->proxyExceptions->text().split(QLatin1Char(','), QString::SkipEmptyParts));
proxy->setProxyAutoConfigUrl(QUrl(ui->pacUrl->text()));
proxy->setUseDifferentProxyForHttps(ui->useHttpsProxy->isChecked());
proxy->setType(ui->proxyType->currentIndex() == 0 ? QNetworkProxy::HttpProxy : QNetworkProxy::Socks5Proxy);
if (ui->noProxy->isChecked()) {
proxy->setPreference(NetworkProxyFactory::NoProxy);
}
else if (ui->systemProxy->isChecked()) {
proxy->setPreference(NetworkProxyFactory::SystemProxy);
}
else if (ui->manualProxy->isChecked()) {
proxy->setPreference(NetworkProxyFactory::DefinedProxy);
}
else if (ui->pacProxy->isChecked()) {
proxy->setPreference(NetworkProxyFactory::ProxyAutoConfig);
proxy->setType(QNetworkProxy::NoProxy);
} else if (ui->systemProxy->isChecked()) {
proxy->setType(QNetworkProxy::DefaultProxy);
} else {
proxy->setType(ui->proxyType->currentIndex() == 0 ? QNetworkProxy::HttpProxy : QNetworkProxy::Socks5Proxy);
}
return proxy;
@ -92,31 +63,25 @@ void SBI_ProxyWidget::setProxy(const SBI_NetworkProxy &proxy)
ui->proxyPort->setText(QString::number(proxy.port()));
ui->proxyUsername->setText(proxy.userName());
ui->proxyPassword->setText(proxy.password());
ui->proxyType->setCurrentIndex(0);
ui->httpsProxyServer->setText(proxy.httpsHostName());
ui->httpsProxyPort->setText(QString::number(proxy.httpsPort()));
ui->httpsProxyUsername->setText(proxy.httpsUserName());
ui->httpsProxyPassword->setText(proxy.httpsPassword());
ui->useHttpsProxy->setChecked(proxy.useDifferentProxyForHttps());
ui->proxyExceptions->setText(proxy.exceptions().join(QLatin1String(",")));
ui->proxyType->setCurrentIndex(proxy.type() == QNetworkProxy::HttpProxy ? 0 : 1);
switch (proxy.preference()) {
case NetworkProxyFactory::NoProxy:
switch (proxy.type()) {
case QNetworkProxy::NoProxy:
ui->noProxy->setChecked(true);
break;
case NetworkProxyFactory::SystemProxy:
case QNetworkProxy::DefaultProxy:
ui->systemProxy->setChecked(true);
break;
case NetworkProxyFactory::DefinedProxy:
case QNetworkProxy::HttpProxy:
ui->manualProxy->setChecked(true);
ui->proxyType->setCurrentIndex(0);
break;
case NetworkProxyFactory::ProxyAutoConfig:
ui->pacProxy->setChecked(true);
case QNetworkProxy::Socks5Proxy:
ui->manualProxy->setChecked(true);
ui->proxyType->setCurrentIndex(1);
break;
default:
@ -124,12 +89,6 @@ void SBI_ProxyWidget::setProxy(const SBI_NetworkProxy &proxy)
}
}
void SBI_ProxyWidget::useHttpsProxyChanged(bool enable)
{
ui->httpsCredentialsLayout_2->setEnabled(enable);
ui->httpsServerLayout_2->setEnabled(enable);
}
SBI_ProxyWidget::~SBI_ProxyWidget()
{
delete ui;

View File

@ -40,9 +40,6 @@ public:
void clear();
private slots:
void useHttpsProxyChanged(bool enable);
private:
Ui::SBI_ProxyWidget* ui;
};

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>558</width>
<height>342</height>
<height>398</height>
</rect>
</property>
<property name="windowTitle">
@ -17,38 +17,10 @@
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="noProxy">
<property name="text">
<string>Do not use proxy</string>
<string>Do &amp;not use proxy</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="useHttpsProxy">
<property name="text">
<string>Use different proxy for https connection</string>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="QLabel" name="label_54">
<property name="text">
<string>&lt;b&gt;Exceptions&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="12" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_27">
<item>
<widget class="QLabel" name="label_40">
<property name="text">
<string>Don't use on:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="proxyExceptions"/>
</item>
</layout>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
@ -140,55 +112,21 @@
</item>
</layout>
</item>
<item row="9" column="0" colspan="2">
<widget class="QRadioButton" name="pacProxy">
<property name="text">
<string>Use script for automatic configuration:</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="systemProxy">
<property name="text">
<string>System proxy configuration</string>
<string>S&amp;ystem proxy configuration</string>
</property>
</widget>
</item>
<item row="10" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_22">
<item>
<widget class="QLineEdit" name="pacUrl">
<property name="placeholderText">
<string>Proxy Auto-Config (.pac) file</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_27">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>50</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<widget class="QRadioButton" name="manualProxy">
<property name="text">
<string>Manual configuration</string>
<string>&amp;Manual configuration</string>
</property>
</widget>
</item>
<item row="13" column="1">
<item row="7" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -201,76 +139,9 @@
</property>
</spacer>
</item>
<item row="7" column="1">
<widget class="QFrame" name="httpsServerLayout_2">
<layout class="QHBoxLayout" name="httpsServerLayout">
<item>
<widget class="QLabel" name="label_55">
<property name="text">
<string>Server:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="httpsProxyServer"/>
</item>
<item>
<widget class="QLabel" name="label_58">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="httpsProxyPort">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="8" column="1">
<item row="6" column="1">
<widget class="QFrame" name="httpsCredentialsLayout_2">
<layout class="QHBoxLayout" name="httpsCredentialsLayout">
<item>
<widget class="QLabel" name="label_38">
<property name="text">
<string>Username:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="httpsProxyUsername"/>
</item>
<item>
<widget class="QLabel" name="label_39">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="httpsProxyPassword"/>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<layout class="QHBoxLayout" name="httpsCredentialsLayout"/>
</widget>
</item>
</layout>