From 57c4b1c2fc426baea81e09d9b068158285ff0f4c Mon Sep 17 00:00:00 2001 From: nowrep Date: Tue, 28 May 2013 21:20:13 +0200 Subject: [PATCH] [StatusBarIcons] NetworkIcon can now also manage proxies. Closes #787 --- src/plugins/StatusBarIcons/StatusBarIcons.pro | 14 +- .../data/preferences-network.png | Bin 0 -> 969 bytes .../StatusBarIcons/sbi_iconsmanager.cpp | 8 +- src/plugins/StatusBarIcons/sbi_iconsmanager.h | 2 + .../StatusBarIcons/sbi_networkicon.cpp | 59 +++- src/plugins/StatusBarIcons/sbi_networkicon.h | 10 +- .../StatusBarIcons/sbi_networkicondialog.cpp | 104 +++++++ .../StatusBarIcons/sbi_networkicondialog.h | 51 ++++ .../StatusBarIcons/sbi_networkicondialog.ui | 132 +++++++++ .../StatusBarIcons/sbi_networkmanager.cpp | 130 ++++++++ .../StatusBarIcons/sbi_networkmanager.h | 59 ++++ .../StatusBarIcons/sbi_networkproxy.cpp | 113 +++++-- src/plugins/StatusBarIcons/sbi_networkproxy.h | 32 +- .../StatusBarIcons/sbi_proxywidget.cpp | 116 ++++++++ src/plugins/StatusBarIcons/sbi_proxywidget.h | 33 +++ src/plugins/StatusBarIcons/sbi_proxywidget.ui | 280 ++++++++++++++++++ src/plugins/StatusBarIcons/statusbaricons.qrc | 1 + 17 files changed, 1098 insertions(+), 46 deletions(-) create mode 100644 src/plugins/StatusBarIcons/data/preferences-network.png create mode 100644 src/plugins/StatusBarIcons/sbi_networkicondialog.cpp create mode 100644 src/plugins/StatusBarIcons/sbi_networkicondialog.h create mode 100644 src/plugins/StatusBarIcons/sbi_networkicondialog.ui create mode 100644 src/plugins/StatusBarIcons/sbi_networkmanager.cpp create mode 100644 src/plugins/StatusBarIcons/sbi_networkmanager.h create mode 100644 src/plugins/StatusBarIcons/sbi_proxywidget.cpp create mode 100644 src/plugins/StatusBarIcons/sbi_proxywidget.h create mode 100644 src/plugins/StatusBarIcons/sbi_proxywidget.ui diff --git a/src/plugins/StatusBarIcons/StatusBarIcons.pro b/src/plugins/StatusBarIcons/StatusBarIcons.pro index fe6415b72..ff7fa54ce 100644 --- a/src/plugins/StatusBarIcons/StatusBarIcons.pro +++ b/src/plugins/StatusBarIcons/StatusBarIcons.pro @@ -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 diff --git a/src/plugins/StatusBarIcons/data/preferences-network.png b/src/plugins/StatusBarIcons/data/preferences-network.png new file mode 100644 index 0000000000000000000000000000000000000000..b6d0546f3b4ab1e3dd3de3b9445375485d5e0901 GIT binary patch literal 969 zcmV;)12+7LP)jG7n^jT#RI6AvQ)031wAQ^UcJgCRm_BqAKBST#mNQ?)?TN(^alm7nzPdweY0T!!NZ+Seuvl4Iqm(UDUM^iL7p#}EnG*{DfqzNQ>}|b_p*NQkF~VExaWzRQ zZ{x4oY)^-onh8-%L@2M6y6jx>OW*|n4dA(hpS>TBo4YDe6TKnHaxBWCG_VbWSDFgE z-Mx`F_eUw~lCmc84gLAYdp*b-W0reM&y zy^eg|O0F(j{W2Wi*Ac6ay=%z;iTW57B|rdPl>?1F=g$vNbv;rM`2OlRb}&soXW>{C z`TOYX#Q?DAD~0rH)Lf6MUnU@Yjx^k3`mZ^HL6hIEk8^7_N37#@^py(bibqfrSWb08 zD5ZGh$&cq{YQv^v(?;r35e{!#Pa*yQA726Qp)FZ%tm3Om!qjf*u6s${U3&HUh2F9M*x23O-QLsFb9!`i^wiMM(0~vk r1?&KJ0bM{G_yd>##(+EOK861Q>-m4jvEEc|00000NkvXXu0mjf=hnyk literal 0 HcmV?d00001 diff --git a/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp b/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp index 80c07a636..21c581dd7 100644 --- a/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp +++ b/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp @@ -19,6 +19,7 @@ #include "sbi_imagesicon.h" #include "sbi_javascripticon.h" #include "sbi_networkicon.h" +#include "sbi_networkmanager.h" #include "qupzilla.h" #include @@ -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); } diff --git a/src/plugins/StatusBarIcons/sbi_iconsmanager.h b/src/plugins/StatusBarIcons/sbi_iconsmanager.h index 364b0d989..c34e0d978 100644 --- a/src/plugins/StatusBarIcons/sbi_iconsmanager.h +++ b/src/plugins/StatusBarIcons/sbi_iconsmanager.h @@ -22,6 +22,7 @@ #include class QupZilla; +class SBI_NetworkManager; class SBI_IconsManager : public QObject { @@ -47,6 +48,7 @@ private: bool m_showNetworkIcon; QHash m_windows; + SBI_NetworkManager* m_networkManager; }; #endif // SBI_ICONSMANAGER_H diff --git a/src/plugins/StatusBarIcons/sbi_networkicon.cpp b/src/plugins/StatusBarIcons/sbi_networkicon.cpp index 4f7079c7e..c3a317e6e 100644 --- a/src/plugins/StatusBarIcons/sbi_networkicon.cpp +++ b/src/plugins/StatusBarIcons/sbi_networkicon.cpp @@ -16,23 +16,27 @@ * along with this program. If not, see . * ============================================================ */ #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 +#include -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 &proxies = SBINetManager->proxies(); + + QHashIterator 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(sender())) { + SBINetManager->setCurrentProxy(act->data().toString()); + } +} + void SBI_NetworkIcon::updateToolTip() { QString tooltip = tr("Shows network status and manages proxy

Network:
%1

Proxy:
%2"); @@ -94,6 +141,10 @@ void SBI_NetworkIcon::updateToolTip() break; } + if (SBINetManager->currentProxy()) { + tooltip.append(QString(" (%1)").arg(SBINetManager->currentProxyName())); + } + setToolTip(tooltip); } diff --git a/src/plugins/StatusBarIcons/sbi_networkicon.h b/src/plugins/StatusBarIcons/sbi_networkicon.h index 2a82b26e7..82e0c7a0f 100644 --- a/src/plugins/StatusBarIcons/sbi_networkicon.h +++ b/src/plugins/StatusBarIcons/sbi_networkicon.h @@ -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 diff --git a/src/plugins/StatusBarIcons/sbi_networkicondialog.cpp b/src/plugins/StatusBarIcons/sbi_networkicondialog.cpp new file mode 100644 index 000000000..aac6c3a21 --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_networkicondialog.cpp @@ -0,0 +1,104 @@ +/* ============================================================ +* StatusBarIcons - Extra icons in statusbar for QupZilla +* Copyright (C) 2013 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 "sbi_networkicondialog.h" +#include "sbi_networkmanager.h" +#include "sbi_networkproxy.h" +#include "ui_sbi_networkicondialog.h" + +#include + +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 &proxies = SBINetManager->proxies(); + + QHashIterator 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; +} diff --git a/src/plugins/StatusBarIcons/sbi_networkicondialog.h b/src/plugins/StatusBarIcons/sbi_networkicondialog.h new file mode 100644 index 000000000..3686385f3 --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_networkicondialog.h @@ -0,0 +1,51 @@ +/* ============================================================ +* StatusBarIcons - Extra icons in statusbar for QupZilla +* Copyright (C) 2013 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 SBI_NETWORKICONDIALOG_H +#define SBI_NETWORKICONDIALOG_H + +#include + +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 diff --git a/src/plugins/StatusBarIcons/sbi_networkicondialog.ui b/src/plugins/StatusBarIcons/sbi_networkicondialog.ui new file mode 100644 index 000000000..d7cadc604 --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_networkicondialog.ui @@ -0,0 +1,132 @@ + + + SBI_NetworkIconDialog + + + + 0 + 0 + 520 + 390 + + + + Proxy Manager + + + + + + + + + 0 + 0 + + + + Select proxy: + + + + + + + + + + Add proxy + + + + + + + Remove proxy + + + + + + + + + + 0 + 0 + + + + + + + + 0 + 0 + + + + No proxies. You can add proxy by clicking on <b>Add</b> button. + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + + + + + + + 0 + 0 + + + + QDialogButtonBox::Save + + + + + + + All changes must be saved with <b>Save</b> button. + + + + + + + + + + + + QDialogButtonBox::Close + + + + + + + + SBI_ProxyWidget + QWidget +
sbi_proxywidget.h
+ 1 +
+
+ + +
diff --git a/src/plugins/StatusBarIcons/sbi_networkmanager.cpp b/src/plugins/StatusBarIcons/sbi_networkmanager.cpp new file mode 100644 index 000000000..7d4f1e8c3 --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_networkmanager.cpp @@ -0,0 +1,130 @@ +/* ============================================================ +* StatusBarIcons - Extra icons in statusbar for QupZilla +* Copyright (C) 2013 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 "sbi_networkmanager.h" +#include "sbi_networkproxy.h" +#include "mainapplication.h" +#include "networkmanager.h" + +#include + +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 ¤tName = 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 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(); +} diff --git a/src/plugins/StatusBarIcons/sbi_networkmanager.h b/src/plugins/StatusBarIcons/sbi_networkmanager.h new file mode 100644 index 000000000..b8078b90a --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_networkmanager.h @@ -0,0 +1,59 @@ +/* ============================================================ +* StatusBarIcons - Extra icons in statusbar for QupZilla +* Copyright (C) 2013 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 SBI_NETWORKMANAGER_H +#define SBI_NETWORKMANAGER_H + +#include +#include + +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 proxies() const; + +private: + void applyCurrentProxy(); + void deleteProxies(); + + QString m_settingsFile; + QHash m_proxies; + SBI_NetworkProxy* m_currentProxy; + + static SBI_NetworkManager* s_instance; +}; + +#define SBINetManager SBI_NetworkManager::instance() + +#endif // SBI_NETWORKMANAGER_H diff --git a/src/plugins/StatusBarIcons/sbi_networkproxy.cpp b/src/plugins/StatusBarIcons/sbi_networkproxy.cpp index 546a20622..681834f25 100644 --- a/src/plugins/StatusBarIcons/sbi_networkproxy.cpp +++ b/src/plugins/StatusBarIcons/sbi_networkproxy.cpp @@ -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); } diff --git a/src/plugins/StatusBarIcons/sbi_networkproxy.h b/src/plugins/StatusBarIcons/sbi_networkproxy.h index 42b7f9ba1..0e076e3e8 100644 --- a/src/plugins/StatusBarIcons/sbi_networkproxy.h +++ b/src/plugins/StatusBarIcons/sbi_networkproxy.h @@ -18,7 +18,9 @@ #ifndef SBI_NETWORKPROXY_H #define SBI_NETWORKPROXY_H -#include +#include + +#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 diff --git a/src/plugins/StatusBarIcons/sbi_proxywidget.cpp b/src/plugins/StatusBarIcons/sbi_proxywidget.cpp new file mode 100644 index 000000000..f36da116e --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_proxywidget.cpp @@ -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; +} diff --git a/src/plugins/StatusBarIcons/sbi_proxywidget.h b/src/plugins/StatusBarIcons/sbi_proxywidget.h new file mode 100644 index 000000000..a28ee6405 --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_proxywidget.h @@ -0,0 +1,33 @@ +#ifndef SBI_PROXYWIDGET_H +#define SBI_PROXYWIDGET_H + +#include + +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 diff --git a/src/plugins/StatusBarIcons/sbi_proxywidget.ui b/src/plugins/StatusBarIcons/sbi_proxywidget.ui new file mode 100644 index 000000000..d31e0018b --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_proxywidget.ui @@ -0,0 +1,280 @@ + + + SBI_ProxyWidget + + + + 0 + 0 + 558 + 342 + + + + Form + + + + + + Do not use proxy + + + + + + + Use different proxy for https connection + + + + + + + <b>Exceptions</b> + + + + + + + + + Don't use on: + + + + + + + + + + + + + + + HTTP + + + + + SOCKS5 + + + + + + + + + + + Port: + + + + + + + + 50 + 16777215 + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + + + Username: + + + + + + + + + + Password: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Use script for automatic configuration: + + + + + + + System proxy configuration + + + + + + + + + Proxy Auto-Config (.pac) file + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 50 + 20 + + + + + + + + + + Manual configuration + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Server: + + + + + + + + + + Port: + + + + + + + + 50 + 16777215 + + + + + + + + + + + + + + Username: + + + + + + + + + + Password: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + diff --git a/src/plugins/StatusBarIcons/statusbaricons.qrc b/src/plugins/StatusBarIcons/statusbaricons.qrc index 7c27a16c2..f77d2bedd 100644 --- a/src/plugins/StatusBarIcons/statusbaricons.qrc +++ b/src/plugins/StatusBarIcons/statusbaricons.qrc @@ -6,5 +6,6 @@ data/network-offline.png data/network-online.png data/network-unknown.png + data/preferences-network.png