Changeset View
Changeset View
Standalone View
Standalone View
kded/portalmonitor.cpp
Show All 34 Lines | |||||
35 | { | 35 | { | ||
36 | checkConnectivity(); | 36 | checkConnectivity(); | ||
37 | 37 | | |||
38 | connect(NetworkManager::notifier(), &NetworkManager::Notifier::connectivityChanged, this, &PortalMonitor::connectivityChanged); | 38 | connect(NetworkManager::notifier(), &NetworkManager::Notifier::connectivityChanged, this, &PortalMonitor::connectivityChanged); | ||
39 | } | 39 | } | ||
40 | 40 | | |||
41 | PortalMonitor::~PortalMonitor() | 41 | PortalMonitor::~PortalMonitor() | ||
42 | { | 42 | { | ||
43 | if (m_notification) { | ||||
44 | m_notification->close(); | ||||
45 | } | ||||
43 | } | 46 | } | ||
44 | 47 | | |||
45 | void PortalMonitor::connectivityChanged(NetworkManager::Connectivity connectivity) | 48 | void PortalMonitor::connectivityChanged(NetworkManager::Connectivity connectivity) | ||
46 | { | 49 | { | ||
47 | if (connectivity == NetworkManager::Portal) { | 50 | if (connectivity == NetworkManager::Portal) { | ||
51 | bool updateOnly = true; | ||||
48 | NetworkManager::ActiveConnection::Ptr primaryConnection = NetworkManager::primaryConnection(); | 52 | NetworkManager::ActiveConnection::Ptr primaryConnection = NetworkManager::primaryConnection(); | ||
49 | KNotification *notification = new KNotification(QStringLiteral("CaptivePortal"), KNotification::Persistent, this); | 53 | | ||
50 | notification->setActions(QStringList{i18n("Log in")}); | 54 | if (!m_notification) { | ||
51 | notification->setComponentName(QStringLiteral("networkmanagement")); | 55 | updateOnly = false; | ||
56 | m_notification = new KNotification(QStringLiteral("CaptivePortal"), KNotification::Persistent, this); | ||||
57 | m_notification->setActions(QStringList{i18n("Log in")}); | ||||
58 | m_notification->setComponentName(QStringLiteral("networkmanagement")); | ||||
59 | m_notification->setText(i18n("You need to log in to this network")); | ||||
60 | | ||||
61 | connect(m_notification, &KNotification::action1Activated, this, [this] () { | ||||
62 | QDesktopServices::openUrl(QUrl("http://networkcheck.kde.org")); | ||||
63 | }); | ||||
64 | connect(m_notification, &KNotification::closed, this, [this] () { | ||||
65 | m_notification = nullptr; | ||||
66 | }); | ||||
67 | } | ||||
68 | | ||||
52 | if (primaryConnection) { | 69 | if (primaryConnection) { | ||
53 | notification->setTitle(primaryConnection->id()); | 70 | m_notification->setTitle(primaryConnection->id()); | ||
54 | } else { | 71 | } else { | ||
55 | notification->setTitle(i18n("Network authentication")); | 72 | m_notification->setTitle(i18n("Network authentication")); | ||
56 | } | 73 | } | ||
57 | notification->setText(i18n("You need to log in to this network")); | 74 | | ||
58 | notification->sendEvent(); | 75 | if (updateOnly) { | ||
59 | connect(notification, &KNotification::action1Activated, this, [notification] () { | 76 | m_notification->update(); | ||
60 | QDesktopServices::openUrl(QUrl("http://networkcheck.kde.org")); | 77 | } else { | ||
61 | notification->close(); | 78 | m_notification->sendEvent(); | ||
62 | }); | 79 | } | ||
80 | | ||||
81 | } else { | ||||
82 | if (m_notification) { | ||||
83 | m_notification->close(); | ||||
84 | } | ||||
85 | m_notification = nullptr; | ||||
63 | } | 86 | } | ||
64 | } | 87 | } | ||
65 | 88 | | |||
66 | void PortalMonitor::checkConnectivity() | 89 | void PortalMonitor::checkConnectivity() | ||
67 | { | 90 | { | ||
68 | QDBusPendingReply<uint> pendingReply = NetworkManager::checkConnectivity(); | 91 | QDBusPendingReply<uint> pendingReply = NetworkManager::checkConnectivity(); | ||
69 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingReply); | 92 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingReply); | ||
70 | connect(callWatcher, &QDBusPendingCallWatcher::finished, this, [this] (QDBusPendingCallWatcher *watcher) { | 93 | connect(callWatcher, &QDBusPendingCallWatcher::finished, this, [this] (QDBusPendingCallWatcher *watcher) { | ||
71 | QDBusPendingReply<uint> reply = *watcher; | 94 | QDBusPendingReply<uint> reply = *watcher; | ||
72 | if (reply.isValid()) { | 95 | if (reply.isValid()) { | ||
73 | connectivityChanged((NetworkManager::Connectivity)reply.value()); | 96 | connectivityChanged((NetworkManager::Connectivity)reply.value()); | ||
74 | } | 97 | } | ||
75 | watcher->deleteLater(); | 98 | watcher->deleteLater(); | ||
76 | }); | 99 | }); | ||
77 | } | 100 | } |