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

[StatusBarIcons] NetworkIcon can now also manage proxies.

Closes #787
This commit is contained in:
nowrep 2013-05-28 21:20:13 +02:00
parent c5b7dbb48c
commit 57c4b1c2fc
17 changed files with 1098 additions and 46 deletions

View File

@ -7,15 +7,25 @@ SOURCES += statusbariconsplugin.cpp \
sbi_imagesicon.cpp \
sbi_javascripticon.cpp \
sbi_networkicon.cpp \
sbi_networkproxy.cpp
sbi_networkproxy.cpp \
sbi_proxywidget.cpp \
sbi_networkicondialog.cpp \
sbi_networkmanager.cpp
HEADERS += statusbariconsplugin.h \
sbi_iconsmanager.h \
sbi_imagesicon.h \
sbi_javascripticon.h \
sbi_networkicon.h \
sbi_networkproxy.h
sbi_networkproxy.h \
sbi_proxywidget.h \
sbi_networkicondialog.h \
sbi_networkmanager.h
RESOURCES += statusbaricons.qrc
include(../../plugins.pri)
FORMS += \
sbi_proxywidget.ui \
sbi_networkicondialog.ui

Binary file not shown.

After

Width:  |  Height:  |  Size: 969 B

View File

@ -19,6 +19,7 @@
#include "sbi_imagesicon.h"
#include "sbi_javascripticon.h"
#include "sbi_networkicon.h"
#include "sbi_networkmanager.h"
#include "qupzilla.h"
#include <QDebug>
@ -31,6 +32,7 @@ SBI_IconsManager::SBI_IconsManager(const QString &settingsPath, QObject* parent)
, m_showImagesIcon(false)
, m_showJavaScriptIcon(false)
, m_showNetworkIcon(false)
, m_networkManager(0)
{
loadSettings();
}
@ -81,7 +83,11 @@ void SBI_IconsManager::mainWindowCreated(QupZilla* window)
}
if (m_showNetworkIcon) {
SBI_NetworkIcon* w = new SBI_NetworkIcon(window, m_settingsPath);
if (!m_networkManager) {
m_networkManager = new SBI_NetworkManager(m_settingsPath, this);
}
SBI_NetworkIcon* w = new SBI_NetworkIcon(window);
window->statusBar()->addPermanentWidget(w);
m_windows[window].append(w);
}

View File

@ -22,6 +22,7 @@
#include <QHash>
class QupZilla;
class SBI_NetworkManager;
class SBI_IconsManager : public QObject
{
@ -47,6 +48,7 @@ private:
bool m_showNetworkIcon;
QHash<QupZilla*, QWidgetList> m_windows;
SBI_NetworkManager* m_networkManager;
};
#endif // SBI_ICONSMANAGER_H

View File

@ -16,23 +16,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "sbi_networkicon.h"
#include "sbi_networkicondialog.h"
#include "sbi_networkproxy.h"
#include "sbi_networkmanager.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "networkproxyfactory.h"
#include "qupzilla.h"
#include <QDebug>
#include <QMenu>
SBI_NetworkIcon::SBI_NetworkIcon(QupZilla* window, const QString &settingsPath)
SBI_NetworkIcon::SBI_NetworkIcon(QupZilla* window)
: ClickableLabel(window)
, p_QupZilla(window)
, m_settingsFile(settingsPath + "networkicon.ini")
{
setCursor(Qt::PointingHandCursor);
connect(mApp->networkManager(), SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)), this, SLOT(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)));
networkAccessibleChanged(mApp->networkManager()->networkAccessible());
connect(mApp->networkManager(), SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)), this, SLOT(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)));
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint)));
}
void SBI_NetworkIcon::networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessibility)
@ -54,6 +58,49 @@ void SBI_NetworkIcon::networkAccessibleChanged(QNetworkAccessManager::NetworkAcc
updateToolTip();
}
void SBI_NetworkIcon::showDialog()
{
SBI_NetworkIconDialog dialog(p_QupZilla);
dialog.exec();
}
void SBI_NetworkIcon::showMenu(const QPoint &pos)
{
QFont boldFont = font();
boldFont.setBold(true);
QMenu menu;
menu.addAction(QIcon::fromTheme("preferences-system-network", QIcon(":sbi/data/preferences-network.png")), tr("Proxy configuration"))->setFont(boldFont);
QMenu* proxyMenu = menu.addMenu(tr("Select proxy"));
const QHash<QString, SBI_NetworkProxy*> &proxies = SBINetManager->proxies();
QHashIterator<QString, SBI_NetworkProxy*> it(proxies);
while (it.hasNext()) {
it.next();
QAction* act = proxyMenu->addAction(it.key(), this, SLOT(useProxy()));
act->setData(it.key());
act->setCheckable(true);
act->setChecked(it.value() == SBINetManager->currentProxy());
}
if (proxyMenu->actions().count() == 0) {
proxyMenu->addAction(tr("Empty"))->setEnabled(false);
}
menu.addSeparator();
menu.addAction(tr("Manage proxies"), this, SLOT(showDialog()));
menu.exec(pos);
}
void SBI_NetworkIcon::useProxy()
{
if (QAction* act = qobject_cast<QAction*>(sender())) {
SBINetManager->setCurrentProxy(act->data().toString());
}
}
void SBI_NetworkIcon::updateToolTip()
{
QString tooltip = tr("Shows network status and manages proxy<br/><br/><b>Network:</b><br/>%1<br/><br/><b>Proxy:</b><br/>%2");
@ -94,6 +141,10 @@ void SBI_NetworkIcon::updateToolTip()
break;
}
if (SBINetManager->currentProxy()) {
tooltip.append(QString(" (%1)").arg(SBINetManager->currentProxyName()));
}
setToolTip(tooltip);
}

View File

@ -29,20 +29,20 @@ class SBI_NetworkIcon : public ClickableLabel
Q_OBJECT
public:
explicit SBI_NetworkIcon(QupZilla* window, const QString &settingsPath);
explicit SBI_NetworkIcon(QupZilla* window);
private slots:
void networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessibility);
void showDialog();
void showMenu(const QPoint &pos);
void useProxy();
private:
void updateToolTip();
void enterEvent(QEvent* event);
QupZilla* p_QupZilla;
QString m_settingsFile;
QIcon m_icon;
};
#endif // SBI_NETWORKICON_H

View File

@ -0,0 +1,104 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* 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/>.
* ============================================================ */
#include "sbi_networkicondialog.h"
#include "sbi_networkmanager.h"
#include "sbi_networkproxy.h"
#include "ui_sbi_networkicondialog.h"
#include <QInputDialog>
SBI_NetworkIconDialog::SBI_NetworkIconDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::SBI_NetworkIconDialog)
{
ui->setupUi(this);
ui->addButton->setIcon(QIcon::fromTheme("document-new"));
ui->removeButton->setIcon(QIcon::fromTheme("edit-delete"));
const QHash<QString, SBI_NetworkProxy*> &proxies = SBINetManager->proxies();
QHashIterator<QString, SBI_NetworkProxy*> it(proxies);
while (it.hasNext()) {
it.next();
ui->comboBox->addItem(it.key());
}
updateWidgets();
showProxy(ui->comboBox->currentText());
connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addProxy()));
connect(ui->removeButton, SIGNAL(clicked()), this, SLOT(removeProxy()));
connect(ui->comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(showProxy(QString)));
connect(ui->proxyButtonBox, SIGNAL(accepted()), this, SLOT(saveProxy()));
connect(ui->closeButton, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
}
void SBI_NetworkIconDialog::addProxy()
{
const QString &name = QInputDialog::getText(this, tr("Add proxy"), tr("Name of proxy:"));
if (name.isEmpty() || ui->comboBox->findText(name) > -1) {
return;
}
ui->comboBox->addItem(name);
ui->comboBox->setCurrentIndex(ui->comboBox->count() - 1);
updateWidgets();
}
void SBI_NetworkIconDialog::removeProxy()
{
int index = ui->comboBox->currentIndex();
if (index < 0) {
return;
}
SBINetManager->removeProxy(ui->comboBox->currentText());
ui->comboBox->removeItem(index);
updateWidgets();
}
void SBI_NetworkIconDialog::saveProxy()
{
SBINetManager->saveProxy(ui->comboBox->currentText(), ui->proxyWidget->getProxy());
}
void SBI_NetworkIconDialog::showProxy(const QString &name)
{
SBI_NetworkProxy* proxy = SBINetManager->proxies()[name];
ui->proxyWidget->clear();
if (proxy) {
ui->proxyWidget->setProxy(*proxy);
}
}
void SBI_NetworkIconDialog::updateWidgets()
{
ui->removeButton->setEnabled(ui->comboBox->count() > 0);
ui->noProxiesLabel->setVisible(ui->comboBox->count() == 0);
ui->proxyWidget->setVisible(ui->comboBox->count() > 0);
}
SBI_NetworkIconDialog::~SBI_NetworkIconDialog()
{
delete ui;
}

View File

@ -0,0 +1,51 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* 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/>.
* ============================================================ */
#ifndef SBI_NETWORKICONDIALOG_H
#define SBI_NETWORKICONDIALOG_H
#include <QDialog>
namespace Ui
{
class SBI_NetworkIconDialog;
}
class SBI_NetworkIcon;
class SBI_NetworkIconDialog : public QDialog
{
Q_OBJECT
public:
explicit SBI_NetworkIconDialog(QWidget* parent = 0);
~SBI_NetworkIconDialog();
private slots:
void addProxy();
void removeProxy();
void saveProxy();
void showProxy(const QString &name);
private:
void updateWidgets();
Ui::SBI_NetworkIconDialog* ui;
};
#endif // SBI_NETWORKICONDIALOG_H

View File

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SBI_NetworkIconDialog</class>
<widget class="QWidget" name="SBI_NetworkIconDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>520</width>
<height>390</height>
</rect>
</property>
<property name="windowTitle">
<string>Proxy Manager</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Select proxy: </string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox"/>
</item>
<item>
<widget class="QToolButton" name="addButton">
<property name="toolTip">
<string>Add proxy</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="removeButton">
<property name="toolTip">
<string>Remove proxy</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="proxyBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="noProxiesLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>No proxies. You can add proxy by clicking on &lt;b&gt;Add&lt;/b&gt; button.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="SBI_ProxyWidget" name="proxyWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QDialogButtonBox" name="proxyButtonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Save</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>All changes must be saved with &lt;b&gt;Save&lt;/b&gt; button.</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="closeButton">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SBI_ProxyWidget</class>
<extends>QWidget</extends>
<header>sbi_proxywidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,130 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* 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/>.
* ============================================================ */
#include "sbi_networkmanager.h"
#include "sbi_networkproxy.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include <QSettings>
SBI_NetworkManager* SBI_NetworkManager::s_instance = 0;
SBI_NetworkManager::SBI_NetworkManager(const QString &settingsPath, QObject* parent)
: QObject(parent)
, m_settingsFile(settingsPath + "networkicon.ini")
, m_currentProxy(0)
{
s_instance = this;
loadSettings();
}
SBI_NetworkManager* SBI_NetworkManager::instance()
{
return s_instance;
}
void SBI_NetworkManager::loadSettings()
{
QSettings settings(m_settingsFile, QSettings::IniFormat);
foreach (const QString &group, settings.childGroups()) {
SBI_NetworkProxy* proxy = new SBI_NetworkProxy;
settings.beginGroup(group);
proxy->loadFromSettings(settings);
settings.endGroup();
m_proxies[group] = proxy;
}
const QString &currentName = settings.value("CurrentProxy", QString()).toString();
m_currentProxy = m_proxies.contains(currentName) ? m_proxies[currentName] : 0;
applyCurrentProxy();
}
QString SBI_NetworkManager::currentProxyName() const
{
return m_proxies.key(m_currentProxy);
}
SBI_NetworkProxy* SBI_NetworkManager::currentProxy() const
{
return m_currentProxy;
}
void SBI_NetworkManager::setCurrentProxy(const QString &name)
{
QSettings settings(m_settingsFile, QSettings::IniFormat);
settings.setValue("CurrentProxy", name);
m_currentProxy = m_proxies.contains(name) ? m_proxies[name] : 0;
applyCurrentProxy();
}
void SBI_NetworkManager::saveProxy(const QString &name, SBI_NetworkProxy* proxy)
{
QSettings settings(m_settingsFile, QSettings::IniFormat);
settings.beginGroup(name);
proxy->saveToSettings(settings);
settings.endGroup();
m_proxies[name] = proxy;
}
void SBI_NetworkManager::removeProxy(const QString &name)
{
QSettings settings(m_settingsFile, QSettings::IniFormat);
settings.beginGroup(name);
settings.remove(QString()); // Removes all keys in current group
settings.endGroup();
m_proxies.remove(name);
}
QHash<QString, SBI_NetworkProxy*> SBI_NetworkManager::proxies() const
{
return m_proxies;
}
void SBI_NetworkManager::applyCurrentProxy()
{
if (!m_currentProxy) {
return;
}
// Manually modify settings to apply proxy configuration
QSettings settings(mApp->currentProfilePath() + "settings.ini", QSettings::IniFormat);
settings.beginGroup("Web-Proxy");
m_currentProxy->saveToSettings(settings);
settings.endGroup();
mApp->networkManager()->proxyFactory()->loadSettings();
}
void SBI_NetworkManager::deleteProxies()
{
qDeleteAll(m_proxies);
m_proxies.clear();
}
SBI_NetworkManager::~SBI_NetworkManager()
{
deleteProxies();
}

View File

@ -0,0 +1,59 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2013 David Rosca <nowrep@gmail.com>
*
* 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/>.
* ============================================================ */
#ifndef SBI_NETWORKMANAGER_H
#define SBI_NETWORKMANAGER_H
#include <QObject>
#include <QHash>
class SBI_NetworkProxy;
class SBI_NetworkManager : public QObject
{
Q_OBJECT
public:
explicit SBI_NetworkManager(const QString &settingsPath, QObject* parent = 0);
~SBI_NetworkManager();
static SBI_NetworkManager* instance();
void loadSettings();
QString currentProxyName() const;
SBI_NetworkProxy* currentProxy() const;
void setCurrentProxy(const QString &name);
void saveProxy(const QString &name, SBI_NetworkProxy* proxy);
void removeProxy(const QString &name);
QHash<QString, SBI_NetworkProxy*> proxies() const;
private:
void applyCurrentProxy();
void deleteProxies();
QString m_settingsFile;
QHash<QString, SBI_NetworkProxy*> m_proxies;
SBI_NetworkProxy* m_currentProxy;
static SBI_NetworkManager* s_instance;
};
#define SBINetManager SBI_NetworkManager::instance()
#endif // SBI_NETWORKMANAGER_H

View File

@ -23,9 +23,21 @@ SBI_NetworkProxy::SBI_NetworkProxy()
: m_port(0)
, m_httpsPort(0)
, m_useDifferentProxyForHttps(false)
, m_preference(NetworkProxyFactory::DefinedProxy)
, m_type(QNetworkProxy::HttpProxy)
{
}
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;
}
quint16 SBI_NetworkProxy::port() const
{
return m_port;
@ -66,11 +78,6 @@ void SBI_NetworkProxy::setPassword(const QString &password)
m_password = password;
}
bool SBI_NetworkProxy::useDifferentProxyForHttps() const
{
return m_useDifferentProxyForHttps;
}
quint16 SBI_NetworkProxy::httpsPort() const
{
return m_httpsPort;
@ -111,32 +118,80 @@ void SBI_NetworkProxy::setHttpsPassword(const QString &password)
m_httpsPassword = password;
}
void SBI_NetworkProxy::loadFromSettings(QSettings* settings)
bool SBI_NetworkProxy::useDifferentProxyForHttps() const
{
m_hostname = settings->value("HostName", QString()).toString();
m_port = settings->value("Port", 0).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", 0).toInt();
m_httpsUsername = settings->value("HttpsUsername", QString()).toString();
m_httpsPassword = settings->value("HttpsPassword", QString()).toString();
m_useDifferentProxyForHttps = settings->value("UseDifferentProxyForHttps", false).toBool();
return m_useDifferentProxyForHttps;
}
void SBI_NetworkProxy::saveToSettings(QSettings* settings)
void SBI_NetworkProxy::setUseDifferentProxyForHttps(bool use)
{
settings->setValue("HostName", m_hostname);
settings->setValue("Port", m_port);
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("UseDifferentProxyForHttps", m_useDifferentProxyForHttps);
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;
}
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();
m_port = settings.value("Port", 0).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", 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
{
settings.setValue("HostName", m_hostname);
settings.setValue("Port", m_port);
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);
}

View File

@ -18,7 +18,9 @@
#ifndef SBI_NETWORKPROXY_H
#define SBI_NETWORKPROXY_H
#include <QString>
#include <QUrl>
#include "networkproxyfactory.h"
class QSettings;
@ -27,6 +29,8 @@ class SBI_NetworkProxy
public:
explicit SBI_NetworkProxy();
bool operator==(const SBI_NetworkProxy &other) const;
quint16 port() const;
void setPort(quint16 port);
@ -39,8 +43,6 @@ public:
QString password() const;
void setPassword(const QString &password);
bool useDifferentProxyForHttps() const;
quint16 httpsPort() const;
void setHttpsPort(quint16 port);
@ -53,8 +55,23 @@ public:
QString httpsPassword() const;
void setHttpsPassword(const QString &password);
void loadFromSettings(QSettings* settings);
void saveToSettings(QSettings* settings);
QUrl proxyAutoConfigUrl() const;
void setProxyAutoConfigUrl();
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;
private:
quint16 m_port;
@ -67,7 +84,12 @@ private:
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

@ -0,0 +1,116 @@
#include "sbi_proxywidget.h"
#include "sbi_networkproxy.h"
#include "ui_sbi_proxywidget.h"
SBI_ProxyWidget::SBI_ProxyWidget(QWidget* parent) :
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()
{
ui->proxyServer->clear();
ui->proxyPort->clear();
ui->proxyUsername->clear();
ui->proxyPassword->clear();
ui->httpsProxyServer->clear();
ui->httpsProxyPort->clear();
ui->httpsProxyUsername->clear();
ui->httpsProxyPassword->clear();
ui->useHttpsProxy->setChecked(false);
ui->proxyExceptions->clear();
ui->proxyType->setCurrentIndex(0);
ui->noProxy->setChecked(true);
}
SBI_NetworkProxy* SBI_ProxyWidget::getProxy() const
{
SBI_NetworkProxy* proxy = new SBI_NetworkProxy;
proxy->setHostName(ui->proxyServer->text());
proxy->setPort(ui->proxyPort->text().toInt());
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->setUseDifferentProxyForHttps(ui->useHttpsProxy->isChecked());
proxy->setExceptions(ui->proxyExceptions->text().split(QLatin1Char(',')));
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::NoProxy);
}
else if (ui->manualProxy->isChecked()) {
proxy->setPreference(NetworkProxyFactory::NoProxy);
}
else if (ui->pacProxy->isChecked()) {
proxy->setPreference(NetworkProxyFactory::NoProxy);
}
return proxy;
}
void SBI_ProxyWidget::setProxy(const SBI_NetworkProxy &proxy)
{
ui->proxyServer->setText(proxy.hostName());
ui->proxyPort->setText(QString::number(proxy.port()));
ui->proxyUsername->setText(proxy.userName());
ui->proxyPassword->setText(proxy.password());
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:
ui->noProxy->setChecked(true);
break;
case NetworkProxyFactory::SystemProxy:
ui->systemProxy->setChecked(true);
break;
case NetworkProxyFactory::DefinedProxy:
ui->manualProxy->setChecked(true);
break;
case NetworkProxyFactory::ProxyAutoConfig:
ui->pacProxy->setChecked(true);
break;
default:
break;
}
}
void SBI_ProxyWidget::useHttpsProxyChanged(bool enable)
{
ui->httpsCredentialsLayout_2->setEnabled(enable);
ui->httpsServerLayout_2->setEnabled(enable);
}
SBI_ProxyWidget::~SBI_ProxyWidget()
{
delete ui;
}

View File

@ -0,0 +1,33 @@
#ifndef SBI_PROXYWIDGET_H
#define SBI_PROXYWIDGET_H
#include <QWidget>
namespace Ui
{
class SBI_ProxyWidget;
}
class SBI_NetworkProxy;
class SBI_ProxyWidget : public QWidget
{
Q_OBJECT
public:
explicit SBI_ProxyWidget(QWidget* parent = 0);
~SBI_ProxyWidget();
SBI_NetworkProxy* getProxy() const;
void setProxy(const SBI_NetworkProxy &proxy);
void clear();
private slots:
void useHttpsProxyChanged(bool enable);
private:
Ui::SBI_ProxyWidget* ui;
};
#endif // SBI_PROXYWIDGET_H

View File

@ -0,0 +1,280 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SBI_ProxyWidget</class>
<widget class="QWidget" name="SBI_ProxyWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>558</width>
<height>342</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="noProxy">
<property name="text">
<string>Do 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>
<widget class="QComboBox" name="proxyType">
<item>
<property name="text">
<string>HTTP</string>
</property>
</item>
<item>
<property name="text">
<string>SOCKS5</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLineEdit" name="proxyServer"/>
</item>
<item>
<widget class="QLabel" name="label_37">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="proxyPort">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_24">
<item>
<widget class="QLabel" name="label_56">
<property name="text">
<string>Username:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="httpsProxyUsername"/>
</item>
<item>
<widget class="QLabel" name="label_57">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="httpsProxyPassword"/>
</item>
<item>
<spacer name="horizontalSpacer_28">
<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>
</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>
</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>
</property>
</widget>
</item>
<item row="13" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</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">
<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="proxyUsername"/>
</item>
<item>
<widget class="QLabel" name="label_39">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="proxyPassword"/>
</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>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -6,5 +6,6 @@
<file>data/network-offline.png</file>
<file>data/network-online.png</file>
<file>data/network-unknown.png</file>
<file>data/preferences-network.png</file>
</qresource>
</RCC>