diff --git a/kded/notification.cpp b/kded/notification.cpp index 09e1d449..412efe69 100644 --- a/kded/notification.cpp +++ b/kded/notification.cpp @@ -1,610 +1,594 @@ /* Copyright 2009 Will Stephenson Copyright 2013 by Daniel Nicoletti Copyright 2013 Lukas Tinkl Copyright 2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "debug.h" #include "notification.h" #include #include #include #include #include #include #include #include Notification::Notification(QObject *parent) : QObject(parent) { // devices for (const NetworkManager::Device::Ptr &device : NetworkManager::networkInterfaces()) { addDevice(device); } connect(NetworkManager::notifier(), &NetworkManager::Notifier::deviceAdded, this, &Notification::deviceAdded); // connections for (const NetworkManager::ActiveConnection::Ptr &ac : NetworkManager::activeConnections()) { addActiveConnection(ac); } connect(NetworkManager::notifier(), &NetworkManager::Notifier::activeConnectionAdded, this, QOverload::of(&Notification::addActiveConnection)); QDBusConnection::systemBus().connect(QStringLiteral("org.freedesktop.login1"), QStringLiteral("/org/freedesktop/login1"), QStringLiteral("org.freedesktop.login1.Manager"), QStringLiteral("PrepareForSleep"), this, SLOT(onPrepareForSleep(bool))); } void Notification::deviceAdded(const QString &uni) { NetworkManager::Device::Ptr device = NetworkManager::findNetworkInterface(uni); addDevice(device); } void Notification::addDevice(const NetworkManager::Device::Ptr &device) { connect(device.data(), &NetworkManager::Device::stateChanged, this, &Notification::stateChanged); } void Notification::stateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason) { Q_UNUSED(oldstate) NetworkManager::Device *device = qobject_cast(sender()); if (newstate == NetworkManager::Device::Activated && m_notifications.contains(device->uni())) { KNotification *notify = m_notifications.value(device->uni()); notify->deleteLater(); m_notifications.remove(device->uni()); return; } else if (newstate != NetworkManager::Device::Failed) { return; } const QString identifier = UiUtils::prettyInterfaceName(device->type(), device->interfaceName()); QString text; switch (reason) { case NetworkManager::Device::NoReason: case NetworkManager::Device::UnknownReason: case NetworkManager::Device::NowManagedReason: case NetworkManager::Device::NowUnmanagedReason: return; case NetworkManager::Device::ConfigFailedReason: text = i18nc("@info:status Notification when the device failed due to ConfigFailedReason", "The device could not be configured"); break; case NetworkManager::Device::ConfigUnavailableReason: text = i18nc("@info:status Notification when the device failed due to ConfigUnavailableReason", "IP configuration was unavailable"); break; case NetworkManager::Device::ConfigExpiredReason: text = i18nc("@info:status Notification when the device failed due to ConfigExpiredReason", "IP configuration expired"); break; case NetworkManager::Device::NoSecretsReason: text = i18nc("@info:status Notification when the device failed due to NoSecretsReason", "No secrets were provided"); break; case NetworkManager::Device::AuthSupplicantDisconnectReason: text = i18nc("@info:status Notification when the device failed due to AuthSupplicantDisconnectReason", "Authorization supplicant disconnected"); break; case NetworkManager::Device::AuthSupplicantConfigFailedReason: text = i18nc("@info:status Notification when the device failed due to AuthSupplicantConfigFailedReason", "Authorization supplicant's configuration failed"); break; case NetworkManager::Device::AuthSupplicantFailedReason: text = i18nc("@info:status Notification when the device failed due to AuthSupplicantFailedReason", "Authorization supplicant failed"); break; case NetworkManager::Device::AuthSupplicantTimeoutReason: text = i18nc("@info:status Notification when the device failed due to AuthSupplicantTimeoutReason", "Authorization supplicant timed out"); break; case NetworkManager::Device::PppStartFailedReason: text = i18nc("@info:status Notification when the device failed due to PppStartFailedReason", "PPP failed to start"); break; case NetworkManager::Device::PppDisconnectReason: text = i18nc("@info:status Notification when the device failed due to PppDisconnectReason", "PPP disconnected"); break; case NetworkManager::Device::PppFailedReason: text = i18nc("@info:status Notification when the device failed due to PppFailedReason", "PPP failed"); break; case NetworkManager::Device::DhcpStartFailedReason: text = i18nc("@info:status Notification when the device failed due to DhcpStartFailedReason", "DHCP failed to start"); break; case NetworkManager::Device::DhcpErrorReason: text = i18nc("@info:status Notification when the device failed due to DhcpErrorReason", "A DHCP error occurred"); break; case NetworkManager::Device::DhcpFailedReason: text = i18nc("@info:status Notification when the device failed due to DhcpFailedReason", "DHCP failed "); break; case NetworkManager::Device::SharedStartFailedReason: text = i18nc("@info:status Notification when the device failed due to SharedStartFailedReason", "The shared service failed to start"); break; case NetworkManager::Device::SharedFailedReason: text = i18nc("@info:status Notification when the device failed due to SharedFailedReason", "The shared service failed"); break; case NetworkManager::Device::AutoIpStartFailedReason: text = i18nc("@info:status Notification when the device failed due to AutoIpStartFailedReason", "The auto IP service failed to start"); break; case NetworkManager::Device::AutoIpErrorReason: text = i18nc("@info:status Notification when the device failed due to AutoIpErrorReason", "The auto IP service reported an error"); break; case NetworkManager::Device::AutoIpFailedReason: text = i18nc("@info:status Notification when the device failed due to AutoIpFailedReason", "The auto IP service failed"); break; case NetworkManager::Device::ModemBusyReason: text = i18nc("@info:status Notification when the device failed due to ModemBusyReason", "The modem is busy"); break; case NetworkManager::Device::ModemNoDialToneReason: text = i18nc("@info:status Notification when the device failed due to ModemNoDialToneReason", "The modem has no dial tone"); break; case NetworkManager::Device::ModemNoCarrierReason: text = i18nc("@info:status Notification when the device failed due to ModemNoCarrierReason", "The modem shows no carrier"); break; case NetworkManager::Device::ModemDialTimeoutReason: text = i18nc("@info:status Notification when the device failed due to ModemDialTimeoutReason", "The modem dial timed out"); break; case NetworkManager::Device::ModemDialFailedReason: text = i18nc("@info:status Notification when the device failed due to ModemDialFailedReason", "The modem dial failed"); break; case NetworkManager::Device::ModemInitFailedReason: text = i18nc("@info:status Notification when the device failed due to ModemInitFailedReason", "The modem could not be initialized"); break; case NetworkManager::Device::GsmApnSelectFailedReason: text = i18nc("@info:status Notification when the device failed due to GsmApnSelectFailedReason", "The GSM APN could not be selected"); break; case NetworkManager::Device::GsmNotSearchingReason: text = i18nc("@info:status Notification when the device failed due to GsmNotSearchingReason", "The GSM modem is not searching"); break; case NetworkManager::Device::GsmRegistrationDeniedReason: text = i18nc("@info:status Notification when the device failed due to GsmRegistrationDeniedReason", "GSM network registration was denied"); break; case NetworkManager::Device::GsmRegistrationTimeoutReason: text = i18nc("@info:status Notification when the device failed due to GsmRegistrationTimeoutReason", "GSM network registration timed out"); break; case NetworkManager::Device::GsmRegistrationFailedReason: text = i18nc("@info:status Notification when the device failed due to GsmRegistrationFailedReason", "GSM registration failed"); break; case NetworkManager::Device::GsmPinCheckFailedReason: text = i18nc("@info:status Notification when the device failed due to GsmPinCheckFailedReason", "The GSM PIN check failed"); break; case NetworkManager::Device::FirmwareMissingReason: text = i18nc("@info:status Notification when the device failed due to FirmwareMissingReason", "Device firmware is missing"); break; case NetworkManager::Device::DeviceRemovedReason: text = i18nc("@info:status Notification when the device failed due to DeviceRemovedReason", "The device was removed"); break; case NetworkManager::Device::SleepingReason: text = i18nc("@info:status Notification when the device failed due to SleepingReason", "The networking system is now sleeping"); break; case NetworkManager::Device::ConnectionRemovedReason: text = i18nc("@info:status Notification when the device failed due to ConnectionRemovedReason", "The connection was removed"); break; case NetworkManager::Device::UserRequestedReason: return; case NetworkManager::Device::CarrierReason: text = i18nc("@info:status Notification when the device failed due to CarrierReason", "The cable was disconnected"); break; case NetworkManager::Device::ConnectionAssumedReason: case NetworkManager::Device::SupplicantAvailableReason: return; case NetworkManager::Device::ModemNotFoundReason: text = i18nc("@info:status Notification when the device failed due to ModemNotFoundReason", "The modem could not be found"); break; case NetworkManager::Device::BluetoothFailedReason: text = i18nc("@info:status Notification when the device failed due to BluetoothFailedReason", "The bluetooth connection failed or timed out"); break; case NetworkManager::Device::GsmSimNotInserted: text = i18nc("@info:status Notification when the device failed due to GsmSimNotInserted", "GSM Modem's SIM Card not inserted"); break; case NetworkManager::Device::GsmSimPinRequired: text = i18nc("@info:status Notification when the device failed due to GsmSimPinRequired", "GSM Modem's SIM Pin required"); break; case NetworkManager::Device::GsmSimPukRequired: text = i18nc("@info:status Notification when the device failed due to GsmSimPukRequired", "GSM Modem's SIM Puk required"); break; case NetworkManager::Device::GsmSimWrong: text = i18nc("@info:status Notification when the device failed due to GsmSimWrong", "GSM Modem's SIM wrong"); break; case NetworkManager::Device::InfiniBandMode: text = i18nc("@info:status Notification when the device failed due to InfiniBandMode", "InfiniBand device does not support connected mode"); break; case NetworkManager::Device::DependencyFailed: text = i18nc("@info:status Notification when the device failed due to DependencyFailed", "A dependency of the connection failed"); break; case NetworkManager::Device::Br2684Failed: text = i18nc("@info:status Notification when the device failed due to Br2684Failed", "Problem with the RFC 2684 Ethernet over ADSL bridge"); break; case NetworkManager::Device::ModemManagerUnavailable: text = i18nc("@info:status Notification when the device failed due to ModemManagerUnavailable", "ModemManager not running"); break; case NetworkManager::Device::SsidNotFound: text = i18nc("@info:status Notification when the device failed due to SsidNotFound", "The WiFi network could not be found"); break; case NetworkManager::Device::SecondaryConnectionFailed: text = i18nc("@info:status Notification when the device failed due to SecondaryConnectionFailed", "A secondary connection of the base connection failed"); break; -#if NM_CHECK_VERSION(0, 9, 10) case NetworkManager::Device::DcbFcoeFailed: text = i18nc("@info:status Notification when the device failed due to DcbFcoeFailed", "DCB or FCoE setup failed"); break; case NetworkManager::Device::TeamdControlFailed: text = i18nc("@info:status Notification when the device failed due to TeamdControlFailed", "teamd control failed"); break; case NetworkManager::Device::ModemFailed: text = i18nc("@info:status Notification when the device failed due to ModemFailed", "Modem failed or no longer available"); break; case NetworkManager::Device::ModemAvailable: text = i18nc("@info:status Notification when the device failed due to ModemAvailable", "Modem now ready and available"); break; case NetworkManager::Device::SimPinIncorrect: text = i18nc("@info:status Notification when the device failed due to SimPinIncorrect", "The SIM PIN was incorrect"); break; -#endif -#if NM_CHECK_VERSION(1, 0, 4) case NetworkManager::Device::NewActivation: text = i18nc("@info:status Notification when the device failed due to NewActivation", "A new connection activation was enqueued"); break; case NetworkManager::Device::ParentChanged: text = i18nc("@info:status Notification when the device failed due to ParentChanged", "The device's parent changed"); break; case NetworkManager::Device::ParentManagedChanged: text = i18nc("@info:status Notification when the device failed due to ParentManagedChanged", "The device parent's management changed"); break; -#endif case NetworkManager::Device::Reserved: return; } if (m_notifications.contains(device->uni())) { KNotification *notify = m_notifications.value(device->uni()); notify->setText(text); notify->update(); } else { KNotification *notify = new KNotification(QStringLiteral("DeviceFailed"), KNotification::CloseOnTimeout, this); connect(notify, &KNotification::closed, this, &Notification::notificationClosed); notify->setProperty("uni", device->uni()); notify->setComponentName(QStringLiteral("networkmanagement")); notify->setPixmap(QIcon::fromTheme(QStringLiteral("dialog-warning")).pixmap(KIconLoader::SizeHuge)); notify->setTitle(identifier); notify->setText(text); notify->sendEvent(); if (notify->id() != -1) { m_notifications[device->uni()] = notify; } } } void Notification::addActiveConnection(const QString &path) { NetworkManager::ActiveConnection::Ptr ac = NetworkManager::findActiveConnection(path); if (ac && ac->isValid()) { addActiveConnection(ac); } } void Notification::addActiveConnection(const NetworkManager::ActiveConnection::Ptr &ac) { if (ac->vpn()) { NetworkManager::VpnConnection::Ptr vpnConnection = ac.objectCast(); connect(vpnConnection.data(), &NetworkManager::VpnConnection::stateChanged, this, &Notification::onVpnConnectionStateChanged); -#if NM_CHECK_VERSION(0, 9, 10) } else if (ac->type() != NetworkManager::ConnectionSettings::Bond && ac->type() != NetworkManager::ConnectionSettings::Bridge && ac->type() != NetworkManager::ConnectionSettings::Generic && ac->type() != NetworkManager::ConnectionSettings::Infiniband && ac->type() != NetworkManager::ConnectionSettings::Team && -#if NM_CHECK_VERSION(1, 1, 92) ac->type() != NetworkManager::ConnectionSettings::Vlan && ac->type() != NetworkManager::ConnectionSettings::Tun) { -#else - ac->type() != NetworkManager::ConnectionSettings::Vlan) { -#endif - -#else - } else if (ac->type() != NetworkManager::ConnectionSettings::Bond && - ac->type() != NetworkManager::ConnectionSettings::Bridge && - ac->type() != NetworkManager::ConnectionSettings::Infiniband && - ac->type() != NetworkManager::ConnectionSettings::Vlan) { -#endif connect(ac.data(), &NetworkManager::ActiveConnection::stateChanged, this, &Notification::onActiveConnectionStateChanged); } } void Notification::onActiveConnectionStateChanged(NetworkManager::ActiveConnection::State state) { NetworkManager::ActiveConnection *ac = qobject_cast(sender()); QString eventId, text, iconName; const QString acName = ac->id(); const QString connectionId = ac->path(); if (state == NetworkManager::ActiveConnection::Activated) { auto foundConnection = std::find_if(m_activeConnectionsBeforeSleep.constBegin(), m_activeConnectionsBeforeSleep.constEnd(), [ac](const QString &uuid) { return uuid == ac->uuid(); }); if (foundConnection != m_activeConnectionsBeforeSleep.constEnd()) { qCDebug(PLASMA_NM) << "Not emitting connection activated notification as the connection was active prior to suspend"; return; } eventId = QStringLiteral("ConnectionActivated"); text = i18n("Connection '%1' activated.", acName); switch (ac->type()) { case NetworkManager::ConnectionSettings::Wireless: iconName = QStringLiteral("network-wireless-on"); break; case NetworkManager::ConnectionSettings::Wired: iconName = QStringLiteral("network-wired-activated"); break; default: // silence warning break; } } else if (state == NetworkManager::ActiveConnection::Deactivated) { if (m_preparingForSleep) { qCDebug(PLASMA_NM) << "Not emitting connection deactivated notification as we're about to suspend"; return; } eventId = QStringLiteral("ConnectionDeactivated"); text = i18n("Connection '%1' deactivated.", acName); switch (ac->type()) { case NetworkManager::ConnectionSettings::Wireless: iconName = QStringLiteral("network-wireless-disconnected"); break; case NetworkManager::ConnectionSettings::Wired: iconName = QStringLiteral("network-unavailable"); break; default: // silence warning break; } } else { qCWarning(PLASMA_NM) << "Unhandled active connection state change: " << state; return; } KNotification *notify = new KNotification(eventId, KNotification::CloseOnTimeout, this); connect(notify, &KNotification::closed, this, &Notification::notificationClosed); notify->setProperty("uni", connectionId); notify->setComponentName(QStringLiteral("networkmanagement")); if (!iconName.isEmpty()) { notify->setIconName(iconName); } else { if (state == NetworkManager::ActiveConnection::Activated) { notify->setIconName(QStringLiteral("dialog-information")); } else { notify->setIconName(QStringLiteral("dialog-warning")); } } notify->setTitle(acName); notify->setText(text); notify->sendEvent(); if (notify->id() != -1) { m_notifications[connectionId] = notify; } } void Notification::onVpnConnectionStateChanged(NetworkManager::VpnConnection::State state, NetworkManager::VpnConnection::StateChangeReason reason) { NetworkManager::VpnConnection *vpn = qobject_cast(sender()); QString eventId, text; const QString vpnName = vpn->connection()->name(); const QString connectionId = vpn->path(); if (state == NetworkManager::VpnConnection::Activated) { eventId = QStringLiteral("ConnectionActivated"); text = i18n("VPN connection '%1' activated.", vpnName); } else if (state == NetworkManager::VpnConnection::Failed) { eventId = QStringLiteral("FailedToActivateConnection"); text = i18n("VPN connection '%1' failed.", vpnName); } else if (state == NetworkManager::VpnConnection::Disconnected) { eventId = QStringLiteral("ConnectionDeactivated"); text = i18n("VPN connection '%1' disconnected.", vpnName); } else { qCWarning(PLASMA_NM) << "Unhandled VPN connection state change: " << state; return; } switch (reason) { case NetworkManager::VpnConnection::UserDisconnectedReason: text = i18n("The VPN connection changed state because the user disconnected it."); break; case NetworkManager::VpnConnection::DeviceDisconnectedReason: text = i18n("The VPN connection changed state because the device it was using was disconnected."); break; case NetworkManager::VpnConnection::ServiceStoppedReason: text = i18n("The service providing the VPN connection was stopped."); break; case NetworkManager::VpnConnection::IpConfigInvalidReason: text = i18n("The IP config of the VPN connection was invalid."); break; case NetworkManager::VpnConnection::ConnectTimeoutReason: text = i18n("The connection attempt to the VPN service timed out."); break; case NetworkManager::VpnConnection::ServiceStartTimeoutReason: text = i18n("A timeout occurred while starting the service providing the VPN connection."); break; case NetworkManager::VpnConnection::ServiceStartFailedReason: text = i18n("Starting the service providing the VPN connection failed."); break; case NetworkManager::VpnConnection::NoSecretsReason: text = i18n("Necessary secrets for the VPN connection were not provided."); break; case NetworkManager::VpnConnection::LoginFailedReason: text = i18n("Authentication to the VPN server failed."); break; case NetworkManager::VpnConnection::ConnectionRemovedReason: text = i18n("The connection was deleted from settings."); break; default: case NetworkManager::VpnConnection::UnknownReason: case NetworkManager::VpnConnection::NoneReason: break; } KNotification *notify = new KNotification(eventId, KNotification::CloseOnTimeout, this); connect(notify, &KNotification::closed, this, &Notification::notificationClosed); notify->setProperty("uni", connectionId); notify->setComponentName("networkmanagement"); if (state == NetworkManager::VpnConnection::Activated) { notify->setIconName(QStringLiteral("dialog-information")); } else { notify->setIconName(QStringLiteral("dialog-warning")); } notify->setTitle(vpnName); notify->setText(text); notify->sendEvent(); if (notify->id() != -1) { m_notifications[connectionId] = notify; } } void Notification::notificationClosed() { KNotification *notify = qobject_cast(sender()); m_notifications.remove(notify->property("uni").toString()); notify->deleteLater(); } void Notification::onPrepareForSleep(bool sleep) { m_preparingForSleep = sleep; if (m_checkActiveConnectionOnResumeTimer) { m_checkActiveConnectionOnResumeTimer->stop(); } if (sleep) { // store all active notifications so we don't show a "is connected" notification // on resume if we were connected previously m_activeConnectionsBeforeSleep.clear(); const auto &connections = NetworkManager::activeConnections(); for (const auto &connection : connections) { if (!connection->vpn() && connection->state() == NetworkManager::ActiveConnection::State::Activated) { m_activeConnectionsBeforeSleep << connection->uuid(); } } } else { if (!m_checkActiveConnectionOnResumeTimer) { m_checkActiveConnectionOnResumeTimer = new QTimer(this); m_checkActiveConnectionOnResumeTimer->setInterval(10000); m_checkActiveConnectionOnResumeTimer->setSingleShot(true); connect(m_checkActiveConnectionOnResumeTimer, &QTimer::timeout, this, &Notification::onCheckActiveConnectionOnResume); } m_checkActiveConnectionOnResumeTimer->start(); } } void Notification::onCheckActiveConnectionOnResume() { if (m_activeConnectionsBeforeSleep.isEmpty()) { // if we weren't connected before, don't bother telling us now :) return; } m_activeConnectionsBeforeSleep.clear(); const auto &connections = NetworkManager::activeConnections(); for (const auto &connection : connections) { if (connection->state() == NetworkManager::ActiveConnection::State::Activated || connection->state() == NetworkManager::ActiveConnection::State::Activating) { // we have an active or activating connection, don't tell the user we're no longer connected return; } } KNotification *notify = new KNotification(QStringLiteral("NoLongerConnected"), KNotification::CloseOnTimeout, this); connect(notify, &KNotification::closed, this, &Notification::notificationClosed); const QString uni = QStringLiteral("offlineNotification"); notify->setProperty("uni", uni); notify->setComponentName("networkmanagement"); notify->setIconName(QStringLiteral("dialog-warning")); notify->setTitle(i18n("No Network Connection")); notify->setText(i18n("You are no longer connected to a network.")); notify->sendEvent(); if (notify->id() != -1) { m_notifications[uni] = notify; } } diff --git a/libs/uiutils.cpp b/libs/uiutils.cpp index 85cdc0a0..d613f0a6 100644 --- a/libs/uiutils.cpp +++ b/libs/uiutils.cpp @@ -1,692 +1,684 @@ /* Copyright 2008-2010 Sebastian Kügler Copyright 2013-2014 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 . */ // Own #include "uiutils.h" #include "configuration.h" #include "debug.h" // KDE #include #include #include #include #include #include #include #include #include #include #if WITH_MODEMMANAGER_SUPPORT #include #include #include #include #include #endif // Qt #include #include #include using namespace NetworkManager; UiUtils::SortedConnectionType UiUtils::connectionTypeToSortedType(NetworkManager::ConnectionSettings::ConnectionType type) { switch (type) { case NetworkManager::ConnectionSettings::Unknown: return UiUtils::Unknown; break; case NetworkManager::ConnectionSettings::Adsl: return UiUtils::Adsl; break; case NetworkManager::ConnectionSettings::Bluetooth: return UiUtils::Bluetooth; break; case NetworkManager::ConnectionSettings::Bond: return UiUtils::Bond; break; case NetworkManager::ConnectionSettings::Bridge: return UiUtils::Bridge; break; case NetworkManager::ConnectionSettings::Cdma: return UiUtils::Cdma; break; case NetworkManager::ConnectionSettings::Gsm: return UiUtils::Gsm; break; case NetworkManager::ConnectionSettings::Infiniband: return UiUtils::Infiniband; break; case NetworkManager::ConnectionSettings::OLPCMesh: return UiUtils::OLPCMesh; break; case NetworkManager::ConnectionSettings::Pppoe: return UiUtils::Pppoe; break; case NetworkManager::ConnectionSettings::Team: return UiUtils::Team; break; case NetworkManager::ConnectionSettings::Vlan: return UiUtils::Vlan; break; case NetworkManager::ConnectionSettings::Vpn: return UiUtils::Vpn; break; case NetworkManager::ConnectionSettings::Wired: return UiUtils::Wired; break; case NetworkManager::ConnectionSettings::Wireless: return UiUtils::Wireless; break; default: return UiUtils::Unknown; break; } } bool UiUtils::isConnectionTypeSupported(NetworkManager::ConnectionSettings::ConnectionType type) { -#if NM_CHECK_VERSION(1, 2, 0) if (type == NetworkManager::ConnectionSettings::Generic || type == NetworkManager::ConnectionSettings::Tun) { -#else - if (type == NetworkManager::ConnectionSettings::Generic) { -#endif return false; } bool manageVirtualConnections = Configuration::manageVirtualConnections(); if (type == NetworkManager::ConnectionSettings::Bond || type == NetworkManager::ConnectionSettings::Bridge || type == NetworkManager::ConnectionSettings::Infiniband || type == NetworkManager::ConnectionSettings::Team || type == NetworkManager::ConnectionSettings::Vlan) { return manageVirtualConnections; } return true; } bool UiUtils::isConnectionTypeVirtual(NetworkManager::ConnectionSettings::ConnectionType type) { if (type == NetworkManager::ConnectionSettings::Bond || type == NetworkManager::ConnectionSettings::Bridge || type == NetworkManager::ConnectionSettings::Infiniband || type == NetworkManager::ConnectionSettings::Team || type == NetworkManager::ConnectionSettings::Vlan) { return true; } return false; } QString UiUtils::interfaceTypeLabel(const NetworkManager::Device::Type type, const NetworkManager::Device::Ptr iface) { QString deviceText; switch (type) { case NetworkManager::Device::Wifi: deviceText = i18nc("title of the interface widget in nm's popup", "Wi-Fi"); break; case NetworkManager::Device::Bluetooth: deviceText = i18nc("title of the interface widget in nm's popup", "Bluetooth"); break; case NetworkManager::Device::InfiniBand: deviceText = i18nc("title of the interface widget in nm's popup", "Infiniband"); break; case NetworkManager::Device::Adsl: deviceText = i18nc("title of the interface widget in nm's popup", "ADSL"); break; case NetworkManager::Device::Bond: deviceText = i18nc("title of the interface widget in nm's popup", "Virtual (bond)"); break; case NetworkManager::Device::Bridge: deviceText = i18nc("title of the interface widget in nm's popup", "Virtual (bridge)"); break; case NetworkManager::Device::Vlan: deviceText = i18nc("title of the interface widget in nm's popup", "Virtual (vlan)"); break; -#if NM_CHECK_VERSION(0, 9, 10) case NetworkManager::Device::Team: deviceText = i18nc("title of the interface widget in nm's popup", "Virtual (team)"); break; -#endif case NetworkManager::Device::Modem: { const NetworkManager::ModemDevice::Ptr nmModemIface = iface.objectCast(); if (nmModemIface) { switch(modemSubType(nmModemIface->currentCapabilities())) { case NetworkManager::ModemDevice::Pots: deviceText = i18nc("title of the interface widget in nm's popup", "Serial Modem"); break; case NetworkManager::ModemDevice::GsmUmts: case NetworkManager::ModemDevice::CdmaEvdo: case NetworkManager::ModemDevice::Lte: deviceText = i18nc("title of the interface widget in nm's popup", "Mobile Broadband"); break; case NetworkManager::ModemDevice::NoCapability: qCWarning(PLASMA_NM) << "Unhandled modem sub type: NetworkManager::ModemDevice::NoCapability"; break; } } } break; case NetworkManager::Device::Ethernet: default: deviceText = i18nc("title of the interface widget in nm's popup", "Wired Ethernet"); break; } return deviceText; } QString UiUtils::iconAndTitleForConnectionSettingsType(NetworkManager::ConnectionSettings::ConnectionType type, QString &title) { QString text; QString icon = QStringLiteral("network-wired"); switch (type) { case ConnectionSettings::Adsl: text = i18n("ADSL"); icon = QStringLiteral("network-modem"); break; case ConnectionSettings::Pppoe: text = i18n("DSL"); icon = QStringLiteral("network-modem"); break; case ConnectionSettings::Bluetooth: text = i18n("Bluetooth"); icon = QStringLiteral("network-bluetooth"); break; case ConnectionSettings::Bond: text = i18n("Bond"); break; case ConnectionSettings::Bridge: text = i18n("Bridge"); break; case ConnectionSettings::Gsm: case ConnectionSettings::Cdma: text = i18n("Mobile broadband"); icon = QStringLiteral("smartphone"); break; case ConnectionSettings::Infiniband: text = i18n("Infiniband"); break; case ConnectionSettings::OLPCMesh: text = i18n("Olpc mesh"); break; case ConnectionSettings::Vlan: text = i18n("VLAN"); break; case ConnectionSettings::Vpn: text = i18n("VPN"); icon = QStringLiteral("network-vpn"); break; case ConnectionSettings::Wired: text = i18n("Wired Ethernet"); icon = QStringLiteral("network-wired"); break; case ConnectionSettings::Wireless: text = i18n("Wi-Fi"); icon = QStringLiteral("network-wireless"); break; -#if NM_CHECK_VERSION(0, 9, 10) case ConnectionSettings::Team: text = i18n("Team"); break; -#endif default: text = i18n("Unknown connection type"); break; } title = text; return icon; } QString UiUtils::prettyInterfaceName(NetworkManager::Device::Type type, const QString &interfaceName) { QString ret; switch (type) { case NetworkManager::Device::Wifi: ret = i18n("Wireless Interface (%1)", interfaceName); break; case NetworkManager::Device::Ethernet: ret = i18n("Wired Interface (%1)", interfaceName); break; case NetworkManager::Device::Bluetooth: ret = i18n("Bluetooth (%1)", interfaceName); break; case NetworkManager::Device::Modem: ret = i18n("Modem (%1)", interfaceName); break; case NetworkManager::Device::Adsl: ret = i18n("ADSL (%1)", interfaceName); break; case NetworkManager::Device::Vlan: ret = i18n("VLan (%1)", interfaceName); break; case NetworkManager::Device::Bridge: ret = i18n("Bridge (%1)", interfaceName); break; default: ret = interfaceName; } return ret; } QString UiUtils::connectionStateToString(NetworkManager::Device::State state, const QString &connectionName) { QString stateString; switch (state) { case NetworkManager::Device::UnknownState: stateString = i18nc("description of unknown network interface state", "Unknown"); break; case NetworkManager::Device::Unmanaged: stateString = i18nc("description of unmanaged network interface state", "Unmanaged"); break; case NetworkManager::Device::Unavailable: stateString = i18nc("description of unavailable network interface state", "Unavailable"); break; case NetworkManager::Device::Disconnected: stateString = i18nc("description of unconnected network interface state", "Not connected"); break; case NetworkManager::Device::Preparing: stateString = i18nc("description of preparing to connect network interface state", "Preparing to connect"); break; case NetworkManager::Device::ConfiguringHardware: stateString = i18nc("description of configuring hardware network interface state", "Configuring interface"); break; case NetworkManager::Device::NeedAuth: stateString = i18nc("description of waiting for authentication network interface state", "Waiting for authorization"); break; case NetworkManager::Device::ConfiguringIp: stateString = i18nc("network interface doing dhcp request in most cases", "Setting network address"); break; case NetworkManager::Device::CheckingIp: stateString = i18nc("is other action required to fully connect? captive portals, etc.", "Checking further connectivity"); break; case NetworkManager::Device::WaitingForSecondaries: stateString = i18nc("a secondary connection (e.g. VPN) has to be activated first to continue", "Waiting for a secondary connection"); break; case NetworkManager::Device::Activated: if (connectionName.isEmpty()) { stateString = i18nc("network interface connected state label", "Connected"); } else { stateString = i18nc("network interface connected state label", "Connected to %1", connectionName); } break; case NetworkManager::Device::Deactivating: stateString = i18nc("network interface disconnecting state label", "Deactivating connection"); break; case NetworkManager::Device::Failed: stateString = i18nc("network interface connection failed state label", "Connection Failed"); break; default: stateString = i18nc("interface state", "Error: Invalid state"); } return stateString; } QString UiUtils::vpnConnectionStateToString(VpnConnection::State state) { QString stateString; switch (state) { case VpnConnection::Unknown: stateString = i18nc("The state of the VPN connection is unknown", "Unknown"); break; case VpnConnection::Prepare: stateString = i18nc("The VPN connection is preparing to connect", "Preparing to connect"); break; case VpnConnection::NeedAuth: stateString = i18nc("The VPN connection needs authorization credentials", "Needs authorization"); break; case VpnConnection::Connecting: stateString = i18nc("The VPN connection is being established", "Connecting"); break; case VpnConnection::GettingIpConfig: stateString = i18nc("The VPN connection is getting an IP address", "Setting network address"); break; case VpnConnection::Activated: stateString = i18nc("The VPN connection is active", "Activated"); break; case VpnConnection::Failed: stateString = i18nc("The VPN connection failed", "Failed"); break; case VpnConnection::Disconnected: stateString = i18nc("The VPN connection is disconnected", "Failed"); break; default: stateString = i18nc("interface state", "Error: Invalid state"); } return stateString; } QString UiUtils::operationModeToString(NetworkManager::WirelessDevice::OperationMode mode) { QString modeString; switch (mode) { case NetworkManager::WirelessDevice::WirelessDevice::Unknown: modeString = i18nc("wireless network operation mode", "Unknown"); break; case NetworkManager::WirelessDevice::Adhoc: modeString = i18nc("wireless network operation mode", "Adhoc"); break; case NetworkManager::WirelessDevice::WirelessDevice::Infra: modeString = i18nc("wireless network operation mode", "Infrastructure"); break; case NetworkManager::WirelessDevice::WirelessDevice::ApMode: modeString = i18nc("wireless network operation mode", "Access point"); break; default: modeString = I18N_NOOP("INCORRECT MODE FIX ME"); } return modeString; } QStringList UiUtils::wpaFlagsToStringList(NetworkManager::AccessPoint::WpaFlags flags) { /* for testing purposes flags = NetworkManager::AccessPoint::PairWep40 | NetworkManager::AccessPoint::PairWep104 | NetworkManager::AccessPoint::PairTkip | NetworkManager::AccessPoint::PairCcmp | NetworkManager::AccessPoint::GroupWep40 | NetworkManager::AccessPoint::GroupWep104 | NetworkManager::AccessPoint::GroupTkip | NetworkManager::AccessPoint::GroupCcmp | NetworkManager::AccessPoint::KeyMgmtPsk | NetworkManager::AccessPoint::KeyMgmt8021x; */ QStringList flagList; if (flags.testFlag(NetworkManager::AccessPoint::PairWep40)) flagList.append(i18nc("wireless network cipher", "Pairwise WEP40")); if (flags.testFlag(NetworkManager::AccessPoint::PairWep104)) flagList.append(i18nc("wireless network cipher", "Pairwise WEP104")); if (flags.testFlag(NetworkManager::AccessPoint::PairTkip)) flagList.append(i18nc("wireless network cipher", "Pairwise TKIP")); if (flags.testFlag(NetworkManager::AccessPoint::PairCcmp)) flagList.append(i18nc("wireless network cipher", "Pairwise CCMP")); if (flags.testFlag(NetworkManager::AccessPoint::GroupWep40)) flagList.append(i18nc("wireless network cipher", "Group WEP40")); if (flags.testFlag(NetworkManager::AccessPoint::GroupWep104)) flagList.append(i18nc("wireless network cipher", "Group WEP104")); if (flags.testFlag(NetworkManager::AccessPoint::GroupTkip)) flagList.append(i18nc("wireless network cipher", "Group TKIP")); if (flags.testFlag(NetworkManager::AccessPoint::GroupCcmp)) flagList.append(i18nc("wireless network cipher", "Group CCMP")); if (flags.testFlag(NetworkManager::AccessPoint::KeyMgmtPsk)) flagList.append(i18nc("wireless network cipher", "PSK")); if (flags.testFlag(NetworkManager::AccessPoint::KeyMgmt8021x)) flagList.append(i18nc("wireless network cipher", "802.1x")); return flagList; } QString UiUtils::connectionSpeed(double bitrate) { QString out; if (bitrate < 1000) { out = i18nc("connection speed", "%1 Bit/s", bitrate); } else if (bitrate < 1000000) { out = i18nc("connection speed", "%1 MBit/s", bitrate/1000); } else { out = i18nc("connection speed", "%1 GBit/s", bitrate/1000000); } return out; } QString UiUtils::wirelessBandToString(NetworkManager::WirelessSetting::FrequencyBand band) { switch (band) { case NetworkManager::WirelessSetting::Automatic: return QStringLiteral("automatic"); break; case NetworkManager::WirelessSetting::A: return QStringLiteral("a"); break; case NetworkManager::WirelessSetting::Bg: return QStringLiteral("b/g"); break; } return QString(); } #if WITH_MODEMMANAGER_SUPPORT QString UiUtils::convertAllowedModeToString(ModemManager::Modem::ModemModes modes) { if (modes.testFlag(MM_MODEM_MODE_4G)) { return i18nc("Gsm modes (2G/3G/any)","LTE"); } else if (modes.testFlag(MM_MODEM_MODE_3G)) { return i18nc("Gsm modes (2G/3G/any)","UMTS/HSxPA"); } else if (modes.testFlag(MM_MODEM_MODE_2G)) { return i18nc("Gsm modes (2G/3G/any)","GPRS/EDGE"); } else if (modes.testFlag(MM_MODEM_MODE_CS)) { return i18nc("Gsm modes (2G/3G/any)","GSM"); } else if (modes.testFlag(MM_MODEM_MODE_ANY)) { return i18nc("Gsm modes (2G/3G/any)","Any"); } return i18nc("Gsm modes (2G/3G/any)","Any"); } QString UiUtils::convertAccessTechnologyToString(ModemManager::Modem::AccessTechnologies tech) { if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_LTE)) { return i18nc("Cellular access technology","LTE"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_EVDOB)) { return i18nc("Cellular access technology","CDMA2000 EVDO revision B"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_EVDOA)) { return i18nc("Cellular access technology","CDMA2000 EVDO revision A"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_EVDO0)) { return i18nc("Cellular access technology","CDMA2000 EVDO revision 0"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_1XRTT)) { return i18nc("Cellular access technology","CDMA2000 1xRTT"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_HSPA_PLUS)) { return i18nc("Cellular access technology","HSPA+"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_HSPA)) { return i18nc("Cellular access technology","HSPA"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_HSUPA)) { return i18nc("Cellular access technology","HSUPA"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_HSDPA)) { return i18nc("Cellular access technology","HSDPA"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_UMTS)) { return i18nc("Cellular access technology","UMTS"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_EDGE)) { return i18nc("Cellular access technology","EDGE"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_GPRS)) { return i18nc("Cellular access technology","GPRS"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_GSM_COMPACT)) { return i18nc("Cellular access technology","Compact GSM"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_GSM)) { return i18nc("Cellular access technology","GSM"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_POTS)) { return i18nc("Analog wireline modem","Analog"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN)) { return i18nc("Unknown cellular access technology","Unknown"); } else if (tech.testFlag(MM_MODEM_ACCESS_TECHNOLOGY_ANY)) { return i18nc("Any cellular access technology","Any"); } return i18nc("Unknown cellular access technology","Unknown"); } QString UiUtils::convertLockReasonToString(MMModemLock reason) { switch (reason) { case MM_MODEM_LOCK_NONE: return i18nc("possible SIM lock reason", "Modem is unlocked."); case MM_MODEM_LOCK_SIM_PIN: return i18nc("possible SIM lock reason", "SIM requires the PIN code."); case MM_MODEM_LOCK_SIM_PIN2: return i18nc("possible SIM lock reason", "SIM requires the PIN2 code."); case MM_MODEM_LOCK_SIM_PUK: return i18nc("possible SIM lock reason", "SIM requires the PUK code."); case MM_MODEM_LOCK_SIM_PUK2: return i18nc("possible SIM lock reason", "SIM requires the PUK2 code."); case MM_MODEM_LOCK_PH_SP_PIN: return i18nc("possible SIM lock reason", "Modem requires the service provider PIN code."); case MM_MODEM_LOCK_PH_SP_PUK: return i18nc("possible SIM lock reason", "Modem requires the service provider PUK code."); case MM_MODEM_LOCK_PH_NET_PIN: return i18nc("possible SIM lock reason", "Modem requires the network PIN code."); case MM_MODEM_LOCK_PH_NET_PUK: return i18nc("possible SIM lock reason", "Modem requires the network PUK code."); case MM_MODEM_LOCK_PH_SIM_PIN: return i18nc("possible SIM lock reason", "Modem requires the PIN code."); case MM_MODEM_LOCK_PH_CORP_PIN: return i18nc("possible SIM lock reason", "Modem requires the corporate PIN code."); case MM_MODEM_LOCK_PH_CORP_PUK: return i18nc("possible SIM lock reason", "Modem requires the corporate PUK code."); case MM_MODEM_LOCK_PH_FSIM_PIN: return i18nc("possible SIM lock reason", "Modem requires the PH-FSIM PIN code."); case MM_MODEM_LOCK_PH_FSIM_PUK: return i18nc("possible SIM lock reason", "Modem requires the PH-FSIM PUK code."); case MM_MODEM_LOCK_PH_NETSUB_PIN: return i18nc("possible SIM lock reason", "Modem requires the network subset PIN code."); case MM_MODEM_LOCK_PH_NETSUB_PUK: return i18nc("possible SIM lock reason", "Modem requires the network subset PUK code."); case MM_MODEM_LOCK_UNKNOWN: default: return i18nc("possible SIM lock reason", "Lock reason unknown."); } } #endif NetworkManager::ModemDevice::Capability UiUtils::modemSubType(NetworkManager::ModemDevice::Capabilities modemCaps) { if (modemCaps & NetworkManager::ModemDevice::Lte) { return NetworkManager::ModemDevice::Lte; } else if (modemCaps & NetworkManager::ModemDevice::CdmaEvdo) { return NetworkManager::ModemDevice::CdmaEvdo; } else if (modemCaps & NetworkManager::ModemDevice::GsmUmts) { return NetworkManager::ModemDevice::GsmUmts; } else if (modemCaps & NetworkManager::ModemDevice::Pots) { return NetworkManager::ModemDevice::Pots; } return NetworkManager::ModemDevice::NoCapability; } QString UiUtils::labelFromWirelessSecurity(NetworkManager::WirelessSecurityType type) { QString tip; switch (type) { case NetworkManager::NoneSecurity: tip = i18nc("@label no security", "Insecure"); break; case NetworkManager::StaticWep: tip = i18nc("@label WEP security", "WEP"); break; case NetworkManager::Leap: tip = i18nc("@label LEAP security", "LEAP"); break; case NetworkManager::DynamicWep: tip = i18nc("@label Dynamic WEP security", "Dynamic WEP"); break; case NetworkManager::WpaPsk: tip = i18nc("@label WPA-PSK security", "WPA-PSK"); break; case NetworkManager::WpaEap: tip = i18nc("@label WPA-EAP security", "WPA-EAP"); break; case NetworkManager::Wpa2Psk: tip = i18nc("@label WPA2-PSK security", "WPA2-PSK"); break; case NetworkManager::Wpa2Eap: tip = i18nc("@label WPA2-EAP security", "WPA2-EAP"); break; default: tip = i18nc("@label unknown security", "Unknown security type"); break; } return tip; } QString UiUtils::formatDateRelative(const QDateTime & lastUsed) { QString lastUsedText; if (lastUsed.isValid()) { const QDateTime now = QDateTime::currentDateTime(); if (lastUsed.daysTo(now) == 0 ) { const int secondsAgo = lastUsed.secsTo(now); if (secondsAgo < (60 * 60 )) { const int minutesAgo = secondsAgo / 60; lastUsedText = i18ncp( "Label for last used time for a network connection used in the last hour, as the number of minutes since usage", "One minute ago", "%1 minutes ago", minutesAgo); } else { const int hoursAgo = secondsAgo / (60 * 60); lastUsedText = i18ncp( "Label for last used time for a network connection used in the last day, as the number of hours since usage", "One hour ago", "%1 hours ago", hoursAgo); } } else if (lastUsed.daysTo(now) == 1) { lastUsedText = i18nc("Label for last used time for a network connection used the previous day", "Yesterday"); } else { lastUsedText = QLocale().toString(lastUsed.date(), QLocale::ShortFormat); } } else { lastUsedText = i18nc("Label for last used time for a " "network connection that has never been used", "Never"); } return lastUsedText; } QString UiUtils::formatLastUsedDateRelative(const QDateTime & lastUsed) { QString lastUsedText; if (lastUsed.isValid()) { const QDateTime now = QDateTime::currentDateTime(); if (lastUsed.daysTo(now) == 0 ) { const int secondsAgo = lastUsed.secsTo(now); if (secondsAgo < (60 * 60 )) { const int minutesAgo = secondsAgo / 60; lastUsedText = i18ncp( "Label for last used time for a network connection used in the last hour, as the number of minutes since usage", "Last used one minute ago", "Last used %1 minutes ago", minutesAgo); } else { const int hoursAgo = secondsAgo / (60 * 60); lastUsedText = i18ncp( "Label for last used time for a network connection used in the last day, as the number of hours since usage", "Last used one hour ago", "Last used %1 hours ago", hoursAgo); } } else if (lastUsed.daysTo(now) == 1) { lastUsedText = i18nc("Label for last used time for a network connection used the previous day", "Last used yesterday"); } else { lastUsedText = i18n("Last used on %1", QLocale().toString(lastUsed.date(), QLocale::ShortFormat)); } } else { lastUsedText = i18nc("Label for last used time for a " "network connection that has never been used", "Never used"); } return lastUsedText; }