Commit 1ffef126 authored by Jan Grulich's avatar Jan Grulich
Browse files

Captive portal notification improvements

Summary:
Do not duplicate captive portal notifications and close them when we are no longer
behind captive portal.

BUG: 411846
BUG: 411847

Reviewers: ngraham, broulik, #plasma

Reviewed By: ngraham

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26042
parent e5bc1e04
......@@ -40,26 +40,49 @@ PortalMonitor::PortalMonitor(QObject *parent)
PortalMonitor::~PortalMonitor()
{
if (m_notification) {
m_notification->close();
}
}
void PortalMonitor::connectivityChanged(NetworkManager::Connectivity connectivity)
{
if (connectivity == NetworkManager::Portal) {
bool updateOnly = true;
NetworkManager::ActiveConnection::Ptr primaryConnection = NetworkManager::primaryConnection();
KNotification *notification = new KNotification(QStringLiteral("CaptivePortal"), KNotification::Persistent, this);
notification->setActions(QStringList{i18n("Log in")});
notification->setComponentName(QStringLiteral("networkmanagement"));
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"));
});
connect(m_notification, &KNotification::closed, this, [this] () {
m_notification = nullptr;
});
}
if (primaryConnection) {
notification->setTitle(primaryConnection->id());
m_notification->setTitle(primaryConnection->id());
} else {
notification->setTitle(i18n("Network authentication"));
m_notification->setTitle(i18n("Network authentication"));
}
if (updateOnly) {
m_notification->update();
} else {
m_notification->sendEvent();
}
} else {
if (m_notification) {
m_notification->close();
}
notification->setText(i18n("You need to log in to this network"));
notification->sendEvent();
connect(notification, &KNotification::action1Activated, this, [notification] () {
QDesktopServices::openUrl(QUrl("http://networkcheck.kde.org"));
notification->close();
});
m_notification = nullptr;
}
}
......
......@@ -24,6 +24,7 @@
#include <NetworkManagerQt/Manager>
#include <KNotification>
#include <QObject>
class PortalMonitor : public QObject
......@@ -36,6 +37,9 @@ public:
private Q_SLOTS:
void connectivityChanged(NetworkManager::Connectivity connectivity);
void checkConnectivity();
private:
KNotification *m_notification = nullptr;
};
#endif // PLASMA_NM_PORTAL_MONITOR_H
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