1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +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 <QMenu>
#include <QNetworkConfigurationManager>
SBI_NetworkIcon::SBI_NetworkIcon(QupZilla* window)
: ClickableLabel(window)
, p_QupZilla(window)
, m_networkConfiguration(new QNetworkConfigurationManager(this))
{
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)));
}
void SBI_NetworkIcon::networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessibility)
void SBI_NetworkIcon::onlineStateChanged(bool online)
{
switch (accessibility) {
case QNetworkAccessManager::Accessible:
if (online) {
setPixmap(QIcon(":sbi/data/network-online.png").pixmap(16));
break;
case QNetworkAccessManager::NotAccessible:
}
else {
setPixmap(QIcon(":sbi/data/network-offline.png").pixmap(16));
break;
default:
setPixmap(QIcon(":sbi/data/network-unknown.png").pixmap(16));
break;
}
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");
switch (mApp->networkManager()->networkAccessible()) {
case QNetworkAccessManager::Accessible:
if (m_networkConfiguration->isOnline()) {
tooltip = tooltip.arg(tr("Connected"));
break;
case QNetworkAccessManager::NotAccessible:
}
else {
tooltip = tooltip.arg(tr("Offline"));
break;
default:
tooltip = tooltip.arg(tr("Unknown"));
break;
}
switch (mApp->networkManager()->proxyFactory()->proxyPreference()) {

View File

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

View File

@ -35,7 +35,7 @@ PluginSpec StatusBarIconsPlugin::pluginSpec()
spec.name = "StatusBar Icons";
spec.info = "Icons in statusbar providing various actions";
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.icon = QPixmap(":sbi/data/icon.png");
spec.hasSettings = true;