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

[SBI_NetworkIcon] Use QNetworkConfigurationManager to detect online state

This commit is contained in:
nowrep 2013-07-01 17:38:35 +02:00
parent 2554ad9870
commit a4ee2d7497
3 changed files with 16 additions and 25 deletions

View File

@ -26,33 +26,28 @@
#include <QDebug> #include <QDebug>
#include <QMenu> #include <QMenu>
#include <QNetworkConfigurationManager>
SBI_NetworkIcon::SBI_NetworkIcon(QupZilla* window) SBI_NetworkIcon::SBI_NetworkIcon(QupZilla* window)
: ClickableLabel(window) : ClickableLabel(window)
, p_QupZilla(window) , p_QupZilla(window)
, m_networkConfiguration(new QNetworkConfigurationManager(this))
{ {
setCursor(Qt::PointingHandCursor); setCursor(Qt::PointingHandCursor);
networkAccessibleChanged(mApp->networkManager()->networkAccessible()); onlineStateChanged(m_networkConfiguration->isOnline());
connect(mApp->networkManager(), SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)), this, SLOT(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility))); connect(m_networkConfiguration, SIGNAL(onlineStateChanged(bool)), this, SLOT(onlineStateChanged(bool)));
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint))); connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint)));
} }
void SBI_NetworkIcon::networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessibility) void SBI_NetworkIcon::onlineStateChanged(bool online)
{ {
switch (accessibility) { if (online) {
case QNetworkAccessManager::Accessible:
setPixmap(QIcon(":sbi/data/network-online.png").pixmap(16)); setPixmap(QIcon(":sbi/data/network-online.png").pixmap(16));
break; }
else {
case QNetworkAccessManager::NotAccessible:
setPixmap(QIcon(":sbi/data/network-offline.png").pixmap(16)); setPixmap(QIcon(":sbi/data/network-offline.png").pixmap(16));
break;
default:
setPixmap(QIcon(":sbi/data/network-unknown.png").pixmap(16));
break;
} }
updateToolTip(); updateToolTip();
@ -105,18 +100,11 @@ 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"); QString tooltip = tr("Shows network status and manages proxy<br/><br/><b>Network:</b><br/>%1<br/><br/><b>Proxy:</b><br/>%2");
switch (mApp->networkManager()->networkAccessible()) { if (m_networkConfiguration->isOnline()) {
case QNetworkAccessManager::Accessible:
tooltip = tooltip.arg(tr("Connected")); tooltip = tooltip.arg(tr("Connected"));
break; }
else {
case QNetworkAccessManager::NotAccessible:
tooltip = tooltip.arg(tr("Offline")); tooltip = tooltip.arg(tr("Offline"));
break;
default:
tooltip = tooltip.arg(tr("Unknown"));
break;
} }
switch (mApp->networkManager()->proxyFactory()->proxyPreference()) { switch (mApp->networkManager()->proxyFactory()->proxyPreference()) {

View File

@ -22,6 +22,8 @@
#include "clickablelabel.h" #include "clickablelabel.h"
class QNetworkConfigurationManager;
class QupZilla; class QupZilla;
class SBI_NetworkIcon : public ClickableLabel class SBI_NetworkIcon : public ClickableLabel
@ -32,7 +34,7 @@ public:
explicit SBI_NetworkIcon(QupZilla* window); explicit SBI_NetworkIcon(QupZilla* window);
private slots: private slots:
void networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessibility); void onlineStateChanged(bool online);
void showDialog(); void showDialog();
void showMenu(const QPoint &pos); void showMenu(const QPoint &pos);
@ -43,6 +45,7 @@ private:
void enterEvent(QEvent* event); void enterEvent(QEvent* event);
QupZilla* p_QupZilla; QupZilla* p_QupZilla;
QNetworkConfigurationManager* m_networkConfiguration;
}; };
#endif // SBI_NETWORKICON_H #endif // SBI_NETWORKICON_H

View File

@ -35,7 +35,7 @@ PluginSpec StatusBarIconsPlugin::pluginSpec()
spec.name = "StatusBar Icons"; spec.name = "StatusBar Icons";
spec.info = "Icons in statusbar providing various actions"; spec.info = "Icons in statusbar providing various actions";
spec.description = "Adds additional icons to statusbar"; spec.description = "Adds additional icons to statusbar";
spec.version = "0.1.5"; spec.version = "0.1.6";
spec.author = "David Rosca <nowrep@gmail.com>"; spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":sbi/data/icon.png"); spec.icon = QPixmap(":sbi/data/icon.png");
spec.hasSettings = true; spec.hasSettings = true;