Changeset View
Changeset View
Standalone View
Standalone View
kded/notification.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | |||||
73 | 73 | | |||
74 | void Notification::stateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason) | 74 | void Notification::stateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason) | ||
75 | { | 75 | { | ||
76 | Q_UNUSED(oldstate) | 76 | Q_UNUSED(oldstate) | ||
77 | 77 | | |||
78 | NetworkManager::Device *device = qobject_cast<NetworkManager::Device*>(sender()); | 78 | NetworkManager::Device *device = qobject_cast<NetworkManager::Device*>(sender()); | ||
79 | if (newstate == NetworkManager::Device::Activated && m_notifications.contains(device->uni())) { | 79 | if (newstate == NetworkManager::Device::Activated && m_notifications.contains(device->uni())) { | ||
80 | KNotification *notify = m_notifications.value(device->uni()); | 80 | KNotification *notify = m_notifications.value(device->uni()); | ||
81 | notify->deleteLater(); | 81 | notify->close(); | ||
82 | m_notifications.remove(device->uni()); | | |||
83 | return; | 82 | return; | ||
84 | } else if (newstate != NetworkManager::Device::Failed) { | 83 | } else if (newstate != NetworkManager::Device::Failed) { | ||
85 | return; | 84 | return; | ||
86 | } | 85 | } | ||
87 | 86 | | |||
88 | const QString identifier = UiUtils::prettyInterfaceName(device->type(), device->interfaceName()); | 87 | const QString identifier = UiUtils::prettyInterfaceName(device->type(), device->interfaceName()); | ||
89 | QString text; | 88 | QString text; | ||
90 | switch (reason) { | 89 | switch (reason) { | ||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Line(s) | 324 | case NetworkManager::Device::Reserved: | |||
326 | return; | 325 | return; | ||
327 | } | 326 | } | ||
328 | 327 | | |||
329 | if (m_notifications.contains(device->uni())) { | 328 | if (m_notifications.contains(device->uni())) { | ||
330 | KNotification *notify = m_notifications.value(device->uni()); | 329 | KNotification *notify = m_notifications.value(device->uni()); | ||
331 | notify->setText(text.toHtmlEscaped()); | 330 | notify->setText(text.toHtmlEscaped()); | ||
332 | notify->update(); | 331 | notify->update(); | ||
333 | } else { | 332 | } else { | ||
334 | KNotification *notify = new KNotification(QStringLiteral("DeviceFailed"), KNotification::CloseOnTimeout, this); | 333 | KNotification *notify = new KNotification(QStringLiteral("DeviceFailed"), KNotification::CloseOnTimeout); | ||
335 | connect(notify, &KNotification::closed, this, &Notification::notificationClosed); | 334 | connect(notify, &KNotification::closed, this, &Notification::notificationClosed); | ||
336 | notify->setProperty("uni", device->uni()); | 335 | notify->setProperty("uni", device->uni()); | ||
337 | notify->setComponentName(QStringLiteral("networkmanagement")); | 336 | notify->setComponentName(QStringLiteral("networkmanagement")); | ||
338 | notify->setIconName(QStringLiteral("dialog-warning")); | 337 | notify->setIconName(QStringLiteral("dialog-warning")); | ||
339 | notify->setTitle(identifier); | 338 | notify->setTitle(identifier); | ||
340 | notify->setText(text.toHtmlEscaped()); | 339 | notify->setText(text.toHtmlEscaped()); | ||
341 | notify->sendEvent(); | | |||
342 | if (notify->id() != -1) { | | |||
343 | m_notifications[device->uni()] = notify; | 340 | m_notifications[device->uni()] = notify; | ||
344 | } | 341 | notify->sendEvent(); | ||
345 | } | 342 | } | ||
346 | } | 343 | } | ||
347 | 344 | | |||
348 | void Notification::addActiveConnection(const QString &path) | 345 | void Notification::addActiveConnection(const QString &path) | ||
349 | { | 346 | { | ||
350 | NetworkManager::ActiveConnection::Ptr ac = NetworkManager::findActiveConnection(path); | 347 | NetworkManager::ActiveConnection::Ptr ac = NetworkManager::findActiveConnection(path); | ||
351 | if (ac && ac->isValid()) { | 348 | if (ac && ac->isValid()) { | ||
352 | addActiveConnection(ac); | 349 | addActiveConnection(ac); | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 405 | } else if (state == NetworkManager::ActiveConnection::Deactivated) { | |||
424 | default: // silence warning | 421 | default: // silence warning | ||
425 | break; | 422 | break; | ||
426 | } | 423 | } | ||
427 | } else { | 424 | } else { | ||
428 | qCWarning(PLASMA_NM) << "Unhandled active connection state change: " << state; | 425 | qCWarning(PLASMA_NM) << "Unhandled active connection state change: " << state; | ||
429 | return; | 426 | return; | ||
430 | } | 427 | } | ||
431 | 428 | | |||
432 | KNotification *notify = new KNotification(eventId, KNotification::CloseOnTimeout, this); | 429 | KNotification *notify = new KNotification(eventId, KNotification::CloseOnTimeout); | ||
433 | connect(notify, &KNotification::closed, this, &Notification::notificationClosed); | 430 | connect(notify, &KNotification::closed, this, &Notification::notificationClosed); | ||
434 | notify->setProperty("uni", connectionId); | 431 | notify->setProperty("uni", connectionId); | ||
435 | notify->setComponentName(QStringLiteral("networkmanagement")); | 432 | notify->setComponentName(QStringLiteral("networkmanagement")); | ||
436 | if (!iconName.isEmpty()) { | 433 | if (!iconName.isEmpty()) { | ||
437 | notify->setIconName(iconName); | 434 | notify->setIconName(iconName); | ||
438 | } else { | 435 | } else { | ||
439 | if (state == NetworkManager::ActiveConnection::Activated) { | 436 | if (state == NetworkManager::ActiveConnection::Activated) { | ||
440 | notify->setIconName(QStringLiteral("dialog-information")); | 437 | notify->setIconName(QStringLiteral("dialog-information")); | ||
441 | } else { | 438 | } else { | ||
442 | notify->setIconName(QStringLiteral("dialog-warning")); | 439 | notify->setIconName(QStringLiteral("dialog-warning")); | ||
443 | } | 440 | } | ||
444 | } | 441 | } | ||
445 | notify->setTitle(acName); | 442 | notify->setTitle(acName); | ||
446 | notify->setText(text.toHtmlEscaped()); | 443 | notify->setText(text.toHtmlEscaped()); | ||
447 | notify->sendEvent(); | | |||
448 | if (notify->id() != -1) { | | |||
449 | m_notifications[connectionId] = notify; | 444 | m_notifications[connectionId] = notify; | ||
450 | } | 445 | notify->sendEvent(); | ||
451 | } | 446 | } | ||
452 | 447 | | |||
453 | void Notification::onVpnConnectionStateChanged(NetworkManager::VpnConnection::State state, NetworkManager::VpnConnection::StateChangeReason reason) | 448 | void Notification::onVpnConnectionStateChanged(NetworkManager::VpnConnection::State state, NetworkManager::VpnConnection::StateChangeReason reason) | ||
454 | { | 449 | { | ||
455 | NetworkManager::VpnConnection *vpn = qobject_cast<NetworkManager::VpnConnection*>(sender()); | 450 | NetworkManager::VpnConnection *vpn = qobject_cast<NetworkManager::VpnConnection*>(sender()); | ||
456 | 451 | | |||
457 | QString eventId, text; | 452 | QString eventId, text; | ||
458 | const QString vpnName = vpn->connection()->name(); | 453 | const QString vpnName = vpn->connection()->name(); | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 498 | case NetworkManager::VpnConnection::ConnectionRemovedReason: | |||
504 | text = i18n("The connection was deleted from settings."); | 499 | text = i18n("The connection was deleted from settings."); | ||
505 | break; | 500 | break; | ||
506 | default: | 501 | default: | ||
507 | case NetworkManager::VpnConnection::UnknownReason: | 502 | case NetworkManager::VpnConnection::UnknownReason: | ||
508 | case NetworkManager::VpnConnection::NoneReason: | 503 | case NetworkManager::VpnConnection::NoneReason: | ||
509 | break; | 504 | break; | ||
510 | } | 505 | } | ||
511 | 506 | | |||
512 | KNotification *notify = new KNotification(eventId, KNotification::CloseOnTimeout, this); | 507 | KNotification *notify = new KNotification(eventId, KNotification::CloseOnTimeout); | ||
513 | connect(notify, &KNotification::closed, this, &Notification::notificationClosed); | 508 | connect(notify, &KNotification::closed, this, &Notification::notificationClosed); | ||
514 | notify->setProperty("uni", connectionId); | 509 | notify->setProperty("uni", connectionId); | ||
515 | notify->setComponentName("networkmanagement"); | 510 | notify->setComponentName("networkmanagement"); | ||
516 | if (state == NetworkManager::VpnConnection::Activated) { | 511 | if (state == NetworkManager::VpnConnection::Activated) { | ||
517 | notify->setIconName(QStringLiteral("dialog-information")); | 512 | notify->setIconName(QStringLiteral("dialog-information")); | ||
518 | } else { | 513 | } else { | ||
519 | notify->setIconName(QStringLiteral("dialog-warning")); | 514 | notify->setIconName(QStringLiteral("dialog-warning")); | ||
520 | } | 515 | } | ||
521 | notify->setTitle(vpnName); | 516 | notify->setTitle(vpnName); | ||
522 | notify->setText(text.toHtmlEscaped()); | 517 | notify->setText(text.toHtmlEscaped()); | ||
523 | notify->sendEvent(); | | |||
524 | if (notify->id() != -1) { | | |||
525 | m_notifications[connectionId] = notify; | 518 | m_notifications[connectionId] = notify; | ||
526 | } | 519 | notify->sendEvent(); | ||
527 | } | 520 | } | ||
528 | 521 | | |||
529 | void Notification::notificationClosed() | 522 | void Notification::notificationClosed() | ||
530 | { | 523 | { | ||
531 | KNotification *notify = qobject_cast<KNotification*>(sender()); | 524 | KNotification *notify = qobject_cast<KNotification*>(sender()); | ||
532 | m_notifications.remove(notify->property("uni").toString()); | 525 | m_notifications.remove(notify->property("uni").toString()); | ||
533 | notify->deleteLater(); | | |||
534 | } | 526 | } | ||
535 | 527 | | |||
536 | void Notification::onPrepareForSleep(bool sleep) | 528 | void Notification::onPrepareForSleep(bool sleep) | ||
537 | { | 529 | { | ||
538 | m_preparingForSleep = sleep; | 530 | m_preparingForSleep = sleep; | ||
539 | 531 | | |||
540 | if (m_checkActiveConnectionOnResumeTimer) { | 532 | if (m_checkActiveConnectionOnResumeTimer) { | ||
541 | m_checkActiveConnectionOnResumeTimer->stop(); | 533 | m_checkActiveConnectionOnResumeTimer->stop(); | ||
Show All 34 Lines | 559 | { | |||
576 | for (const auto &connection : connections) { | 568 | for (const auto &connection : connections) { | ||
577 | if (connection->state() == NetworkManager::ActiveConnection::State::Activated || | 569 | if (connection->state() == NetworkManager::ActiveConnection::State::Activated || | ||
578 | connection->state() == NetworkManager::ActiveConnection::State::Activating) { | 570 | connection->state() == NetworkManager::ActiveConnection::State::Activating) { | ||
579 | // we have an active or activating connection, don't tell the user we're no longer connected | 571 | // we have an active or activating connection, don't tell the user we're no longer connected | ||
580 | return; | 572 | return; | ||
581 | } | 573 | } | ||
582 | } | 574 | } | ||
583 | 575 | | |||
584 | KNotification *notify = new KNotification(QStringLiteral("NoLongerConnected"), KNotification::CloseOnTimeout, this); | 576 | KNotification *notify = new KNotification(QStringLiteral("NoLongerConnected"), KNotification::CloseOnTimeout); | ||
585 | connect(notify, &KNotification::closed, this, &Notification::notificationClosed); | 577 | connect(notify, &KNotification::closed, this, &Notification::notificationClosed); | ||
586 | const QString uni = QStringLiteral("offlineNotification"); | 578 | const QString uni = QStringLiteral("offlineNotification"); | ||
587 | notify->setProperty("uni", uni); | 579 | notify->setProperty("uni", uni); | ||
588 | notify->setComponentName("networkmanagement"); | 580 | notify->setComponentName("networkmanagement"); | ||
589 | notify->setIconName(QStringLiteral("dialog-warning")); | 581 | notify->setIconName(QStringLiteral("dialog-warning")); | ||
590 | notify->setTitle(i18n("No Network Connection")); | 582 | notify->setTitle(i18n("No Network Connection")); | ||
591 | notify->setText(i18n("You are no longer connected to a network.")); | 583 | notify->setText(i18n("You are no longer connected to a network.")); | ||
592 | notify->sendEvent(); | | |||
593 | if (notify->id() != -1) { | | |||
594 | m_notifications[uni] = notify; | 584 | m_notifications[uni] = notify; | ||
595 | } | 585 | notify->sendEvent(); | ||
596 | } | 586 | } |