Commit 85629cc2 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Show notification when connectivity is limited

Plasma-nm already shows a little triangle in the tray when that happens but it can
easily be missed. Show a notification when connectivity becomes limited.

There's a 10 second grace period before showing the notification as NM appears to
briefly mark any connection as limited when connecting to it.
parent 0f417c32
......@@ -6,12 +6,12 @@ if (WITH_MODEMMANAGER_SUPPORT)
set(kded_networkmanagement_SRCS
../libs/debug.cpp
bluetoothmonitor.cpp
connectivitymonitor.cpp
notification.cpp
modemmonitor.cpp
monitor.cpp
passworddialog.cpp
pindialog.cpp
portalmonitor.cpp
secretagent.cpp
service.cpp
)
......@@ -23,10 +23,10 @@ else()
set(kded_networkmanagement_SRCS
../libs/debug.cpp
bluetoothmonitor.cpp
connectivitymonitor.cpp
notification.cpp
monitor.cpp
passworddialog.cpp
portalmonitor.cpp
secretagent.cpp
service.cpp
)
......
/*
* Copyright 2016 Jan Grulich <jgrulich@redhat.com>
* Copyright 2020 Kai Uwe Broulik <kde@broulik.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -19,7 +20,7 @@
*
*/
#include "portalmonitor.h"
#include "connectivitymonitor.h"
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
......@@ -30,59 +31,79 @@
#include <NetworkManagerQt/ActiveConnection>
PortalMonitor::PortalMonitor(QObject *parent)
#include "debug.h"
ConnectivityMonitor::ConnectivityMonitor(QObject *parent)
: QObject(parent)
{
m_limitedConnectivityTimer.setSingleShot(true);
m_limitedConnectivityTimer.setInterval(10000);
connect(&m_limitedConnectivityTimer, &QTimer::timeout, this, &ConnectivityMonitor::showLimitedConnectivityNotification);
checkConnectivity();
connect(NetworkManager::notifier(), &NetworkManager::Notifier::connectivityChanged, this, &PortalMonitor::connectivityChanged);
connect(NetworkManager::notifier(), &NetworkManager::Notifier::connectivityChanged, this, &ConnectivityMonitor::connectivityChanged);
}
PortalMonitor::~PortalMonitor()
ConnectivityMonitor::~ConnectivityMonitor()
{
if (m_notification) {
m_notification->close();
}
}
void PortalMonitor::connectivityChanged(NetworkManager::Connectivity connectivity)
void ConnectivityMonitor::connectivityChanged(NetworkManager::Connectivity connectivity)
{
if (connectivity == NetworkManager::Portal) {
bool updateOnly = true;
NetworkManager::ActiveConnection::Ptr primaryConnection = NetworkManager::primaryConnection();
if (!m_notification) {
updateOnly = false;
m_notification = new KNotification(QStringLiteral("CaptivePortal"), KNotification::Persistent, this);
m_notification->setActions(QStringList{i18n("Log in")});
m_notification->setComponentName(QStringLiteral("networkmanagement"));
m_notification->setText(i18n("You need to log in to this network"));
connect(m_notification, &KNotification::action1Activated, this, [this] () {
QDesktopServices::openUrl(QUrl("http://networkcheck.kde.org"));
});
}
if (m_notification && m_notification->property("nm_connectivity") != connectivity) {
m_notification->close();
m_notification = nullptr;
}
if (primaryConnection) {
m_notification->setTitle(primaryConnection->id());
} else {
m_notification->setTitle(i18n("Network authentication"));
if (connectivity == NetworkManager::Limited) {
qCDebug(PLASMA_NM) << "Network connectivity limited, scheduling notification";
if (!m_limitedConnectivityTimer.isActive()) {
m_limitedConnectivityTimer.start();
}
} else {
m_limitedConnectivityTimer.stop();
if (updateOnly) {
m_notification->update();
} else {
m_notification->sendEvent();
}
if (connectivity == NetworkManager::Portal) {
qCDebug(PLASMA_NM) << "Detected captive portal";
const NetworkManager::ActiveConnection::Ptr primaryConnection = NetworkManager::primaryConnection();
const QString title = primaryConnection ? primaryConnection->id() : i18n("Network authentication");
} else {
if (m_notification) {
m_notification->close();
if (m_notification) {
m_notification->setTitle(title);
m_notification->update();
} else {
m_notification = new KNotification(QStringLiteral("CaptivePortal"), KNotification::Persistent);
m_notification->setActions(QStringList{i18n("Log in")});
m_notification->setComponentName(QStringLiteral("networkmanagement"));
m_notification->setTitle(title);
m_notification->setText(i18n("You need to log in to this network"));
connect(m_notification, &KNotification::action1Activated, this, [this] () {
QDesktopServices::openUrl(QUrl("http://networkcheck.kde.org"));
});
m_notification->sendEvent();
}
}
}
}
void PortalMonitor::checkConnectivity()
void ConnectivityMonitor::showLimitedConnectivityNotification()
{
if (m_notification) {
return;
}
m_notification = new KNotification(QStringLiteral("LimitedConnectivity"));
m_notification->setComponentName(QStringLiteral("networkmanagement"));
m_notification->setTitle(i18n("Limited Connectivity"));
m_notification->setText(i18n("This device appears to be connected to a network but is unable to reach the internet."));
m_notification->sendEvent();
}
void ConnectivityMonitor::checkConnectivity()
{
QDBusPendingReply<uint> pendingReply = NetworkManager::checkConnectivity();
QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingReply);
......
/*
* Copyright 2016 Jan Grulich <jgrulich@redhat.com>
* Copyright 2020 Kai Uwe Broulik <kde@broulik.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -19,28 +20,33 @@
*
*/
#ifndef PLASMA_NM_PORTAL_MONITOR_H
#define PLASMA_NM_PORTAL_MONITOR_H
#ifndef PLASMA_NM_CONNECTIVITY_MONITOR_H
#define PLASMA_NM_CONNECTIVITY_MONITOR_H
#include <NetworkManagerQt/Manager>
#include <KNotification>
#include <QObject>
#include <QPointer>
#include <QTimer>
class PortalMonitor : public QObject
class ConnectivityMonitor : public QObject
{
Q_OBJECT
public:
explicit PortalMonitor(QObject *parent);
~PortalMonitor() override;
explicit ConnectivityMonitor(QObject *parent);
~ConnectivityMonitor() override;
private Q_SLOTS:
void connectivityChanged(NetworkManager::Connectivity connectivity);
void checkConnectivity();
private:
void showLimitedConnectivityNotification();
QPointer<KNotification> m_notification;
QTimer m_limitedConnectivityTimer;
};
#endif // PLASMA_NM_PORTAL_MONITOR_H
#endif // PLASMA_NM_CONNECTIVITY_MONITOR_H
......@@ -467,6 +467,12 @@ Urgency=Low
IconName=dialog-password
Action=Popup
[Event/LimitedConnectivity]
Name=Limited Connectivity
Urgency=Low
IconName=network-limited
Action=Popup
[Event/FailedToCreateHotspot]
Name=Failed to Create Hotspot
Name[ca]=Ha fallat en crear el punt d'accés
......
......@@ -25,10 +25,10 @@
#include <KPluginFactory>
#include "connectivitymonitor.h"
#include "secretagent.h"
#include "notification.h"
#include "monitor.h"
#include "portalmonitor.h"
#include <QDBusMetaType>
#include <QDBusServiceWatcher>
......@@ -44,7 +44,7 @@ class NetworkManagementServicePrivate
SecretAgent *agent = nullptr;
Notification *notification = nullptr;
Monitor *monitor = nullptr;
PortalMonitor *portalMonitor = nullptr;
ConnectivityMonitor *connectivityMonitor = nullptr;
};
NetworkManagementService::NetworkManagementService(QObject * parent, const QVariantList&)
......@@ -75,8 +75,8 @@ void NetworkManagementService::init()
d->monitor = new Monitor(this);
}
if (!d->portalMonitor) {
d->portalMonitor = new PortalMonitor(this);
if (!d->connectivityMonitor) {
d->connectivityMonitor = new ConnectivityMonitor(this);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment