Changeset View
Changeset View
Standalone View
Standalone View
kded/notification.cpp
Show First 20 Lines • Show All 366 Lines • ▼ Show 20 Line(s) | |||||
367 | } | 367 | } | ||
368 | 368 | | |||
369 | void Notification::onActiveConnectionStateChanged(NetworkManager::ActiveConnection::State state) | 369 | void Notification::onActiveConnectionStateChanged(NetworkManager::ActiveConnection::State state) | ||
370 | { | 370 | { | ||
371 | NetworkManager::ActiveConnection *ac = qobject_cast<NetworkManager::ActiveConnection*>(sender()); | 371 | NetworkManager::ActiveConnection *ac = qobject_cast<NetworkManager::ActiveConnection*>(sender()); | ||
372 | 372 | | |||
373 | QString eventId, text, iconName; | 373 | QString eventId, text, iconName; | ||
374 | const QString acName = ac->id(); | 374 | const QString acName = ac->id(); | ||
375 | const QString connectionId = ac->path(); | 375 | const QString connectionId = ac->id(); | ||
376 | 376 | | |||
377 | if (state == NetworkManager::ActiveConnection::Activated) { | 377 | if (state == NetworkManager::ActiveConnection::Activated) { | ||
378 | auto foundConnection = std::find_if(m_activeConnectionsBeforeSleep.constBegin(), | 378 | auto foundConnection = std::find_if(m_activeConnectionsBeforeSleep.constBegin(), | ||
379 | m_activeConnectionsBeforeSleep.constEnd(), | 379 | m_activeConnectionsBeforeSleep.constEnd(), | ||
380 | [ac](const QString &uuid) { | 380 | [ac](const QString &uuid) { | ||
381 | return uuid == ac->uuid(); | 381 | return uuid == ac->uuid(); | ||
382 | }); | 382 | }); | ||
383 | 383 | | |||
Show All 37 Lines | 405 | } else if (state == NetworkManager::ActiveConnection::Deactivated) { | |||
421 | default: // silence warning | 421 | default: // silence warning | ||
422 | break; | 422 | break; | ||
423 | } | 423 | } | ||
424 | } else { | 424 | } else { | ||
425 | qCWarning(PLASMA_NM) << "Unhandled active connection state change: " << state; | 425 | qCWarning(PLASMA_NM) << "Unhandled active connection state change: " << state; | ||
426 | return; | 426 | return; | ||
427 | } | 427 | } | ||
428 | 428 | | |||
429 | KNotification *notify = new KNotification(eventId, KNotification::CloseOnTimeout); | 429 | KNotification *notify = m_notifications.value(connectionId); | ||
430 | | ||||
431 | if (!notify) { | ||||
broulik: Avoid double look-up. `QHash` gives you a null value when not existing, so you can do:
```… | |||||
432 | notify = new KNotification(eventId, KNotification::CloseOnTimeout); | ||||
430 | connect(notify, &KNotification::closed, this, &Notification::notificationClosed); | 433 | connect(notify, &KNotification::closed, this, &Notification::notificationClosed); | ||
431 | notify->setProperty("uni", connectionId); | 434 | notify->setProperty("uni", connectionId); | ||
432 | notify->setComponentName(QStringLiteral("networkmanagement")); | 435 | notify->setComponentName(QStringLiteral("networkmanagement")); | ||
436 | m_notifications[connectionId] = notify; | ||||
437 | } | ||||
438 | | ||||
433 | if (!iconName.isEmpty()) { | 439 | if (!iconName.isEmpty()) { | ||
434 | notify->setIconName(iconName); | 440 | notify->setIconName(iconName); | ||
435 | } else { | 441 | } else { | ||
436 | if (state == NetworkManager::ActiveConnection::Activated) { | 442 | if (state == NetworkManager::ActiveConnection::Activated) { | ||
437 | notify->setIconName(QStringLiteral("dialog-information")); | 443 | notify->setIconName(QStringLiteral("dialog-information")); | ||
438 | } else { | 444 | } else { | ||
439 | notify->setIconName(QStringLiteral("dialog-warning")); | 445 | notify->setIconName(QStringLiteral("dialog-warning")); | ||
440 | } | 446 | } | ||
441 | } | 447 | } | ||
442 | notify->setTitle(acName); | 448 | notify->setTitle(acName); | ||
443 | notify->setText(text.toHtmlEscaped()); | 449 | notify->setText(text.toHtmlEscaped()); | ||
444 | m_notifications[connectionId] = notify; | | |||
445 | notify->sendEvent(); | 450 | notify->sendEvent(); | ||
446 | } | 451 | } | ||
447 | 452 | | |||
448 | void Notification::onVpnConnectionStateChanged(NetworkManager::VpnConnection::State state, NetworkManager::VpnConnection::StateChangeReason reason) | 453 | void Notification::onVpnConnectionStateChanged(NetworkManager::VpnConnection::State state, NetworkManager::VpnConnection::StateChangeReason reason) | ||
449 | { | 454 | { | ||
450 | NetworkManager::VpnConnection *vpn = qobject_cast<NetworkManager::VpnConnection*>(sender()); | 455 | NetworkManager::VpnConnection *vpn = qobject_cast<NetworkManager::VpnConnection*>(sender()); | ||
451 | 456 | | |||
452 | QString eventId, text; | 457 | QString eventId, text; | ||
▲ Show 20 Lines • Show All 134 Lines • Show Last 20 Lines |
Avoid double look-up. QHash gives you a null value when not existing, so you can do: