diff --git a/src/lib/network/networkproxyfactory.cpp b/src/lib/network/networkproxyfactory.cpp index 9f1794e10..afa66d156 100644 --- a/src/lib/network/networkproxyfactory.cpp +++ b/src/lib/network/networkproxyfactory.cpp @@ -103,6 +103,11 @@ PacManager* NetworkProxyFactory::pacManager() const return m_pacManager; } +NetworkProxyFactory::ProxyPreference NetworkProxyFactory::proxyPreference() const +{ + return m_proxyPreference; +} + QList NetworkProxyFactory::queryProxy(const QNetworkProxyQuery &query) { QList proxyList; diff --git a/src/lib/network/networkproxyfactory.h b/src/lib/network/networkproxyfactory.h index a853508b5..41c37bc73 100644 --- a/src/lib/network/networkproxyfactory.h +++ b/src/lib/network/networkproxyfactory.h @@ -51,7 +51,9 @@ public: ~NetworkProxyFactory(); void loadSettings(); + PacManager* pacManager() const; + ProxyPreference proxyPreference() const; QList queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()); diff --git a/src/plugins/StatusBarIcons/StatusBarIcons.pro b/src/plugins/StatusBarIcons/StatusBarIcons.pro index 5c132167f..fe6415b72 100644 --- a/src/plugins/StatusBarIcons/StatusBarIcons.pro +++ b/src/plugins/StatusBarIcons/StatusBarIcons.pro @@ -5,12 +5,16 @@ TARGET = $$qtLibraryTarget(StatusBarIcons) SOURCES += statusbariconsplugin.cpp \ sbi_iconsmanager.cpp \ sbi_imagesicon.cpp \ - sbi_javascripticon.cpp + sbi_javascripticon.cpp \ + sbi_networkicon.cpp \ + sbi_networkproxy.cpp HEADERS += statusbariconsplugin.h \ sbi_iconsmanager.h \ sbi_imagesicon.h \ - sbi_javascripticon.h + sbi_javascripticon.h \ + sbi_networkicon.h \ + sbi_networkproxy.h RESOURCES += statusbaricons.qrc diff --git a/src/plugins/StatusBarIcons/data/network-offline.png b/src/plugins/StatusBarIcons/data/network-offline.png new file mode 100644 index 000000000..fd50901be Binary files /dev/null and b/src/plugins/StatusBarIcons/data/network-offline.png differ diff --git a/src/plugins/StatusBarIcons/data/network-online.png b/src/plugins/StatusBarIcons/data/network-online.png new file mode 100644 index 000000000..1221e1310 Binary files /dev/null and b/src/plugins/StatusBarIcons/data/network-online.png differ diff --git a/src/plugins/StatusBarIcons/data/network-unknown.png b/src/plugins/StatusBarIcons/data/network-unknown.png new file mode 100644 index 000000000..246c27f89 Binary files /dev/null and b/src/plugins/StatusBarIcons/data/network-unknown.png differ diff --git a/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp b/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp index 6b4523890..80c07a636 100644 --- a/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp +++ b/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp @@ -18,6 +18,7 @@ #include "sbi_iconsmanager.h" #include "sbi_imagesicon.h" #include "sbi_javascripticon.h" +#include "sbi_networkicon.h" #include "qupzilla.h" #include @@ -67,8 +68,6 @@ void SBI_IconsManager::destroyIcons() void SBI_IconsManager::mainWindowCreated(QupZilla* window) { - typedef QWidget SBI_NetworkIcon; - if (m_showImagesIcon) { SBI_ImagesIcon* w = new SBI_ImagesIcon(window, m_settingsPath); window->statusBar()->addPermanentWidget(w); @@ -82,7 +81,7 @@ void SBI_IconsManager::mainWindowCreated(QupZilla* window) } if (m_showNetworkIcon) { - SBI_NetworkIcon* w = new SBI_NetworkIcon; + SBI_NetworkIcon* w = new SBI_NetworkIcon(window, m_settingsPath); window->statusBar()->addPermanentWidget(w); m_windows[window].append(w); } diff --git a/src/plugins/StatusBarIcons/sbi_networkicon.cpp b/src/plugins/StatusBarIcons/sbi_networkicon.cpp new file mode 100644 index 000000000..4f7079c7e --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_networkicon.cpp @@ -0,0 +1,105 @@ +/* ============================================================ +* 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_networkicon.h" +#include "mainapplication.h" +#include "networkmanager.h" +#include "networkproxyfactory.h" +#include "qupzilla.h" + +#include + +SBI_NetworkIcon::SBI_NetworkIcon(QupZilla* window, const QString &settingsPath) + : 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()); +} + +void SBI_NetworkIcon::networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessibility) +{ + switch (accessibility) { + case QNetworkAccessManager::Accessible: + setPixmap(QIcon(":sbi/data/network-online.png").pixmap(16)); + break; + + case QNetworkAccessManager::NotAccessible: + setPixmap(QIcon(":sbi/data/network-offline.png").pixmap(16)); + break; + + default: + setPixmap(QIcon(":sbi/data/network-unknown.png").pixmap(16)); + break; + } + + updateToolTip(); +} + +void SBI_NetworkIcon::updateToolTip() +{ + QString tooltip = tr("Shows network status and manages proxy

Network:
%1

Proxy:
%2"); + + switch (mApp->networkManager()->networkAccessible()) { + case QNetworkAccessManager::Accessible: + tooltip = tooltip.arg(tr("Connected")); + break; + + case QNetworkAccessManager::NotAccessible: + tooltip = tooltip.arg(tr("Offline")); + break; + + default: + tooltip = tooltip.arg(tr("Unknown")); + break; + } + + switch (mApp->networkManager()->proxyFactory()->proxyPreference()) { + case NetworkProxyFactory::SystemProxy: + tooltip = tooltip.arg("System proxy"); + break; + + case NetworkProxyFactory::NoProxy: + tooltip = tooltip.arg("No proxy"); + break; + + case NetworkProxyFactory::ProxyAutoConfig: + tooltip = tooltip.arg("PAC (Proxy Auto-Config)"); + break; + + case NetworkProxyFactory::DefinedProxy: + tooltip = tooltip.arg("User defined"); + break; + + default: + qWarning() << "Unknown NetworkProxyFactory::ProxyPreference!"; + break; + } + + setToolTip(tooltip); +} + +void SBI_NetworkIcon::enterEvent(QEvent* event) +{ + updateToolTip(); + + ClickableLabel::enterEvent(event); +} diff --git a/src/plugins/StatusBarIcons/sbi_networkicon.h b/src/plugins/StatusBarIcons/sbi_networkicon.h new file mode 100644 index 000000000..2a82b26e7 --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_networkicon.h @@ -0,0 +1,48 @@ +/* ============================================================ +* 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_NETWORKICON_H +#define SBI_NETWORKICON_H + +#include + +#include "clickablelabel.h" + +class QupZilla; + +class SBI_NetworkIcon : public ClickableLabel +{ + Q_OBJECT + +public: + explicit SBI_NetworkIcon(QupZilla* window, const QString &settingsPath); + +private slots: + void networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessibility); + +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_networkproxy.cpp b/src/plugins/StatusBarIcons/sbi_networkproxy.cpp new file mode 100644 index 000000000..546a20622 --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_networkproxy.cpp @@ -0,0 +1,142 @@ +/* ============================================================ +* 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_networkproxy.h" + +#include + +SBI_NetworkProxy::SBI_NetworkProxy() + : m_port(0) + , m_httpsPort(0) + , m_useDifferentProxyForHttps(false) +{ +} + +quint16 SBI_NetworkProxy::port() const +{ + return m_port; +} + +void SBI_NetworkProxy::setPort(quint16 port) +{ + m_port = port; +} + +QString SBI_NetworkProxy::hostName() const +{ + return m_hostname; +} + +void SBI_NetworkProxy::setHostName(const QString &hostName) +{ + m_hostname = hostName; +} + +QString SBI_NetworkProxy::userName() const +{ + return m_username; +} + +void SBI_NetworkProxy::setUserName(const QString &userName) +{ + m_username = userName; +} + +QString SBI_NetworkProxy::password() const +{ + return m_password; +} + +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; +} + +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; +} + +void SBI_NetworkProxy::loadFromSettings(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_useDifferentProxyForHttps = settings->value("UseDifferentProxyForHttps", false).toBool(); +} + +void SBI_NetworkProxy::saveToSettings(QSettings* settings) +{ + 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); +} diff --git a/src/plugins/StatusBarIcons/sbi_networkproxy.h b/src/plugins/StatusBarIcons/sbi_networkproxy.h new file mode 100644 index 000000000..42b7f9ba1 --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_networkproxy.h @@ -0,0 +1,73 @@ +/* ============================================================ +* 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_NETWORKPROXY_H +#define SBI_NETWORKPROXY_H + +#include + +class QSettings; + +class SBI_NetworkProxy +{ +public: + explicit SBI_NetworkProxy(); + + quint16 port() const; + void setPort(quint16 port); + + QString hostName() const; + void setHostName(const QString &hostName); + + QString userName() const; + void setUserName(const QString &userName); + + QString password() const; + void setPassword(const QString &password); + + bool useDifferentProxyForHttps() const; + + 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); + + void loadFromSettings(QSettings* settings); + void saveToSettings(QSettings* settings); + +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; + + bool m_useDifferentProxyForHttps; +}; + +#endif // SBI_NETWORKPROXY_H diff --git a/src/plugins/StatusBarIcons/statusbaricons.qrc b/src/plugins/StatusBarIcons/statusbaricons.qrc index 8572f4abc..7c27a16c2 100644 --- a/src/plugins/StatusBarIcons/statusbaricons.qrc +++ b/src/plugins/StatusBarIcons/statusbaricons.qrc @@ -3,5 +3,8 @@ data/icon.png data/images.png data/javascript.png + data/network-offline.png + data/network-online.png + data/network-unknown.png diff --git a/src/plugins/StatusBarIcons/translations/empty.ts b/src/plugins/StatusBarIcons/translations/empty.ts index 8b55ec7cd..2a0a9e16e 100644 --- a/src/plugins/StatusBarIcons/translations/empty.ts +++ b/src/plugins/StatusBarIcons/translations/empty.ts @@ -67,4 +67,27 @@ + + SBI_NetworkIcon + + + Shows network status and manages proxy<br/><br/><b>Network:</b><br/>%1<br/><br/><b>Proxy:</b><br/>%2 + + + + + Connected + + + + + Offline + + + + + Unknown + + +