diff --git a/kded/portalmonitor.cpp b/kded/portalmonitor.cpp index 8db521bf..3e8893f6 100644 --- a/kded/portalmonitor.cpp +++ b/kded/portalmonitor.cpp @@ -1,100 +1,96 @@ /* * Copyright 2016 Jan Grulich * * 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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 "portalmonitor.h" #include #include #include #include #include #include PortalMonitor::PortalMonitor(QObject *parent) : QObject(parent) { checkConnectivity(); connect(NetworkManager::notifier(), &NetworkManager::Notifier::connectivityChanged, this, &PortalMonitor::connectivityChanged); } 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(); 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) { m_notification->setTitle(primaryConnection->id()); } else { m_notification->setTitle(i18n("Network authentication")); } if (updateOnly) { m_notification->update(); } else { m_notification->sendEvent(); } } else { if (m_notification) { m_notification->close(); } - m_notification = nullptr; } } void PortalMonitor::checkConnectivity() { QDBusPendingReply pendingReply = NetworkManager::checkConnectivity(); QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingReply); connect(callWatcher, &QDBusPendingCallWatcher::finished, this, [this] (QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; if (reply.isValid()) { connectivityChanged((NetworkManager::Connectivity)reply.value()); } watcher->deleteLater(); }); } diff --git a/kded/portalmonitor.h b/kded/portalmonitor.h index fe6eaab6..1c0a8573 100644 --- a/kded/portalmonitor.h +++ b/kded/portalmonitor.h @@ -1,45 +1,46 @@ /* * Copyright 2016 Jan Grulich * * 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 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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 PLASMA_NM_PORTAL_MONITOR_H #define PLASMA_NM_PORTAL_MONITOR_H #include #include #include +#include class PortalMonitor : public QObject { Q_OBJECT public: explicit PortalMonitor(QObject *parent); ~PortalMonitor() override; private Q_SLOTS: void connectivityChanged(NetworkManager::Connectivity connectivity); void checkConnectivity(); private: - KNotification *m_notification = nullptr; + QPointer m_notification; }; #endif // PLASMA_NM_PORTAL_MONITOR_H