File indexing completed on 2024-10-13 13:17:35

0001 /*
0002     SPDX-FileCopyrightText: 2013-2018 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #include "networkmodelitem.h"
0007 #include "networkmodel.h"
0008 #include "uiutils.h"
0009 
0010 #include <unordered_map>
0011 
0012 #include <NetworkManagerQt/AdslDevice>
0013 #include <NetworkManagerQt/BluetoothDevice>
0014 #include <NetworkManagerQt/BondDevice>
0015 #include <NetworkManagerQt/BridgeDevice>
0016 #include <NetworkManagerQt/InfinibandDevice>
0017 #include <NetworkManagerQt/Manager>
0018 #include <NetworkManagerQt/ModemDevice>
0019 #include <NetworkManagerQt/Settings>
0020 #include <NetworkManagerQt/TeamDevice>
0021 #include <NetworkManagerQt/VlanDevice>
0022 #include <NetworkManagerQt/VpnSetting>
0023 #include <NetworkManagerQt/WiredDevice>
0024 #include <NetworkManagerQt/WirelessDevice>
0025 #include <NetworkManagerQt/WirelessSetting>
0026 
0027 #include <KLocalizedString>
0028 
0029 #include <ModemManagerQt/Manager>
0030 #include <ModemManagerQt/Modem3Gpp>
0031 #include <ModemManagerQt/Modem>
0032 #include <ModemManagerQt/ModemCdma>
0033 #include <ModemManagerQt/ModemDevice>
0034 
0035 #include <QStringBuilder>
0036 
0037 namespace
0038 {
0039 using ConnectionType = NetworkManager::ConnectionSettings::ConnectionType;
0040 
0041 static const std::unordered_map<ConnectionType, QString> s_connectionTypeToString{
0042     {ConnectionType::Unknown, i18nc("@info:tooltip", "The connection type is Unknown")},
0043     {ConnectionType::Adsl, i18nc("@info:tooltip", "The connection type is ADSL")},
0044     {ConnectionType::Bluetooth, i18nc("@info:tooltip", "The connection type is Bluetooth")},
0045     {ConnectionType::Bridge, i18nc("@info:tooltip", "The connection type is Bridge")},
0046     {ConnectionType::Cdma, i18nc("@info:tooltip", "The connection type is CDMA")},
0047     {ConnectionType::Gsm, i18nc("@info:tooltip", "The connection type is GSM")},
0048     {ConnectionType::Infiniband, i18nc("@info:tooltip", "The connection type is Infiniband")},
0049     {ConnectionType::OLPCMesh, i18nc("@info:tooltip", "The connection type is OLPC Mesh")},
0050     {ConnectionType::Pppoe, i18nc("@info:tooltip", "The connection type is PPOPE")},
0051     {ConnectionType::Vlan, i18nc("@info:tooltip", "The connection type is VLAN")},
0052     {ConnectionType::Vpn, i18nc("@info:tooltip", "The connection type is VPN")},
0053     {ConnectionType::Wimax, i18nc("@info:tooltip", "The connection type is Wimax")},
0054     {ConnectionType::Wired, i18nc("@info:tooltip", "The connection type is Wired")},
0055     {ConnectionType::Wireless, i18nc("@info:tooltip", "The connection type is Wireless")},
0056     {ConnectionType::Team, i18nc("@info:tooltip", "The connection type is Team")},
0057     {ConnectionType::Generic, i18nc("@info:tooltip", "The connection type is Generic")},
0058     {ConnectionType::Tun, i18nc("@info:tooltip", "The connection type is Tunnel")},
0059     {ConnectionType::IpTunnel, i18nc("@info:tooltip", "The connection type is IP Tunnel")},
0060     {ConnectionType::WireGuard, i18nc("@info:tooltip", "The connection type is WireGuard")},
0061 };
0062 }
0063 
0064 NetworkModelItem::NetworkModelItem(QObject *parent)
0065     : QObject(parent)
0066     , m_connectionState(NetworkManager::ActiveConnection::Deactivated)
0067     , m_deviceState(NetworkManager::Device::UnknownState)
0068     , m_detailsValid(false)
0069     , m_delayModelUpdates(false)
0070     , m_duplicate(false)
0071     , m_mode(NetworkManager::WirelessSetting::Infrastructure)
0072     , m_securityType(NetworkManager::NoneSecurity)
0073     , m_signal(0)
0074     , m_slave(false)
0075     , m_type(NetworkManager::ConnectionSettings::Unknown)
0076     , m_vpnState(NetworkManager::VpnConnection::Unknown)
0077     , m_rxBytes(0)
0078     , m_txBytes(0)
0079 {
0080 }
0081 
0082 NetworkModelItem::NetworkModelItem(const NetworkModelItem *item, QObject *parent)
0083     : QObject(parent)
0084     , m_connectionPath(item->connectionPath())
0085     , m_connectionState(NetworkManager::ActiveConnection::Deactivated)
0086     , m_detailsValid(false)
0087     , m_delayModelUpdates(item->delayModelUpdates())
0088     , m_duplicate(true)
0089     , m_mode(item->mode())
0090     , m_name(item->name())
0091     , m_securityType(item->securityType())
0092     , m_slave(item->slave())
0093     , m_ssid(item->ssid())
0094     , m_timestamp(item->timestamp())
0095     , m_type(item->type())
0096     , m_uuid(item->uuid())
0097     , m_vpnState(NetworkManager::VpnConnection::Unknown)
0098     , m_rxBytes(0)
0099     , m_txBytes(0)
0100 {
0101 }
0102 
0103 NetworkModelItem::~NetworkModelItem() = default;
0104 
0105 QString NetworkModelItem::activeConnectionPath() const
0106 {
0107     return m_activeConnectionPath;
0108 }
0109 
0110 void NetworkModelItem::setActiveConnectionPath(const QString &path)
0111 {
0112     m_activeConnectionPath = path;
0113 }
0114 
0115 QString NetworkModelItem::connectionPath() const
0116 {
0117     return m_connectionPath;
0118 }
0119 
0120 void NetworkModelItem::setConnectionPath(const QString &path)
0121 {
0122     if (m_connectionPath != path) {
0123         m_connectionPath = path;
0124         m_changedRoles << NetworkModel::ConnectionPathRole << NetworkModel::UniRole;
0125     }
0126 }
0127 
0128 NetworkManager::ActiveConnection::State NetworkModelItem::connectionState() const
0129 {
0130     return m_connectionState;
0131 }
0132 
0133 void NetworkModelItem::setConnectionState(NetworkManager::ActiveConnection::State state)
0134 {
0135     if (m_connectionState != state) {
0136         m_connectionState = state;
0137         m_changedRoles << NetworkModel::ConnectionStateRole << NetworkModel::SectionRole;
0138         refreshIcon();
0139     }
0140 }
0141 
0142 QStringList NetworkModelItem::details() const
0143 {
0144     if (!m_detailsValid) {
0145         updateDetails();
0146     }
0147     return m_details;
0148 }
0149 
0150 QString NetworkModelItem::devicePath() const
0151 {
0152     return m_devicePath;
0153 }
0154 
0155 QString NetworkModelItem::deviceName() const
0156 {
0157     return m_deviceName;
0158 }
0159 
0160 void NetworkModelItem::setDeviceName(const QString &name)
0161 {
0162     if (m_deviceName != name) {
0163         m_deviceName = name;
0164         m_changedRoles << NetworkModel::DeviceName;
0165     }
0166 }
0167 
0168 void NetworkModelItem::setDevicePath(const QString &path)
0169 {
0170     if (m_devicePath != path) {
0171         m_devicePath = path;
0172         m_changedRoles << NetworkModel::DevicePathRole << NetworkModel::ItemTypeRole << NetworkModel::UniRole;
0173     }
0174 }
0175 
0176 QString NetworkModelItem::deviceState() const
0177 {
0178     return UiUtils::connectionStateToString(m_deviceState);
0179 }
0180 
0181 void NetworkModelItem::setDeviceState(const NetworkManager::Device::State state)
0182 {
0183     if (m_deviceState != state) {
0184         m_deviceState = state;
0185         m_changedRoles << NetworkModel::DeviceStateRole;
0186     }
0187 }
0188 
0189 bool NetworkModelItem::duplicate() const
0190 {
0191     return m_duplicate;
0192 }
0193 
0194 void NetworkModelItem::setIcon(const QString &icon)
0195 {
0196     if (icon != m_icon) {
0197         m_icon = icon;
0198         m_changedRoles << NetworkModel::ConnectionIconRole;
0199     }
0200 }
0201 
0202 void NetworkModelItem::refreshIcon()
0203 {
0204     setIcon(computeIcon());
0205 }
0206 
0207 QString NetworkModelItem::computeIcon() const
0208 {
0209     switch (m_type) {
0210     case NetworkManager::ConnectionSettings::Adsl:
0211         return QStringLiteral("network-mobile-100");
0212         break;
0213     case NetworkManager::ConnectionSettings::Bluetooth:
0214         if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
0215             return QStringLiteral("network-bluetooth-activated");
0216         } else {
0217             return QStringLiteral("network-bluetooth");
0218         }
0219         break;
0220     case NetworkManager::ConnectionSettings::Bond:
0221         break;
0222     case NetworkManager::ConnectionSettings::Bridge:
0223         break;
0224     case NetworkManager::ConnectionSettings::Cdma:
0225     case NetworkManager::ConnectionSettings::Gsm:
0226         if (m_signal == 0) {
0227             return QStringLiteral("network-mobile-0");
0228         } else if (m_signal < 20) {
0229             return QStringLiteral("network-mobile-20");
0230         } else if (m_signal < 40) {
0231             return QStringLiteral("network-mobile-40");
0232         } else if (m_signal < 60) {
0233             return QStringLiteral("network-mobile-60");
0234         } else if (m_signal < 80) {
0235             return QStringLiteral("network-mobile-80");
0236         } else {
0237             return QStringLiteral("network-mobile-100");
0238         }
0239         break;
0240     case NetworkManager::ConnectionSettings::Infiniband:
0241         break;
0242     case NetworkManager::ConnectionSettings::OLPCMesh:
0243         break;
0244     case NetworkManager::ConnectionSettings::Pppoe:
0245         return QStringLiteral("network-mobile-100");
0246         break;
0247     case NetworkManager::ConnectionSettings::Vlan:
0248         break;
0249     case NetworkManager::ConnectionSettings::Vpn:
0250     case NetworkManager::ConnectionSettings::WireGuard:
0251         return QStringLiteral("network-vpn");
0252         break;
0253     case NetworkManager::ConnectionSettings::Wired:
0254         if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
0255             return QStringLiteral("network-wired-activated");
0256         } else {
0257             return QStringLiteral("network-wired");
0258         }
0259         break;
0260     case NetworkManager::ConnectionSettings::Wireless:
0261         if (m_signal == 0) {
0262             if (m_mode == NetworkManager::WirelessSetting::Adhoc || m_mode == NetworkManager::WirelessSetting::Ap) {
0263                 return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-100")
0264                                                                         : QStringLiteral("network-wireless-100-locked");
0265             }
0266             return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-0") : QStringLiteral("network-wireless-0-locked");
0267         } else if (m_signal < 20) {
0268             return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-20") : QStringLiteral("network-wireless-20-locked");
0269         } else if (m_signal < 40) {
0270             return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-40") : QStringLiteral("network-wireless-40-locked");
0271         } else if (m_signal < 60) {
0272             return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-60") : QStringLiteral("network-wireless-60-locked");
0273         } else if (m_signal < 80) {
0274             return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-80") : QStringLiteral("network-wireless-80-locked");
0275         } else {
0276             return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-100") : QStringLiteral("network-wireless-100-locked");
0277         }
0278         break;
0279     default:
0280         break;
0281     }
0282 
0283     if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
0284         return QStringLiteral("network-wired-activated");
0285     } else {
0286         return QStringLiteral("network-wired");
0287     }
0288 }
0289 
0290 NetworkModelItem::ItemType NetworkModelItem::itemType() const
0291 {
0292     if (!m_devicePath.isEmpty() //
0293         || m_type == NetworkManager::ConnectionSettings::Bond //
0294         || m_type == NetworkManager::ConnectionSettings::Bridge //
0295         || m_type == NetworkManager::ConnectionSettings::Vlan //
0296         || m_type == NetworkManager::ConnectionSettings::Team //
0297         || ((NetworkManager::status() == NetworkManager::Connected //
0298              || NetworkManager::status() == NetworkManager::ConnectedLinkLocal //
0299              || NetworkManager::status() == NetworkManager::ConnectedSiteOnly)
0300             && (m_type == NetworkManager::ConnectionSettings::Vpn || m_type == NetworkManager::ConnectionSettings::WireGuard))) {
0301         if (m_connectionPath.isEmpty() && m_type == NetworkManager::ConnectionSettings::Wireless) {
0302             return NetworkModelItem::AvailableAccessPoint;
0303         } else {
0304             return NetworkModelItem::AvailableConnection;
0305         }
0306     }
0307     return NetworkModelItem::UnavailableConnection;
0308 }
0309 
0310 NetworkManager::WirelessSetting::NetworkMode NetworkModelItem::mode() const
0311 {
0312     return m_mode;
0313 }
0314 
0315 void NetworkModelItem::setMode(const NetworkManager::WirelessSetting::NetworkMode mode)
0316 {
0317     if (m_mode != mode) {
0318         m_mode = mode;
0319         refreshIcon();
0320     }
0321 }
0322 
0323 QString NetworkModelItem::name() const
0324 {
0325     return m_name;
0326 }
0327 
0328 void NetworkModelItem::setName(const QString &name)
0329 {
0330     if (m_name != name) {
0331         m_name = name;
0332         m_changedRoles << NetworkModel::ItemUniqueNameRole << NetworkModel::NameRole;
0333     }
0334 }
0335 
0336 QString NetworkModelItem::originalName() const
0337 {
0338     if (m_deviceName.isEmpty()) {
0339         return m_name;
0340     }
0341     return m_name % QLatin1String(" (") % m_deviceName % ')';
0342 }
0343 
0344 QString NetworkModelItem::sectionType() const
0345 {
0346     if (m_connectionState == NetworkManager::ActiveConnection::Deactivated) {
0347         return QStringLiteral("Available connections");
0348     } else {
0349         return {};
0350     }
0351 }
0352 
0353 NetworkManager::WirelessSecurityType NetworkModelItem::securityType() const
0354 {
0355     return m_securityType;
0356 }
0357 
0358 void NetworkModelItem::setSecurityType(NetworkManager::WirelessSecurityType type)
0359 {
0360     if (m_securityType != type) {
0361         m_securityType = type;
0362         m_changedRoles << NetworkModel::SecurityTypeStringRole << NetworkModel::SecurityTypeRole;
0363         refreshIcon();
0364     }
0365 }
0366 
0367 int NetworkModelItem::signal() const
0368 {
0369     return m_signal;
0370 }
0371 
0372 void NetworkModelItem::setSignal(int signal)
0373 {
0374     if (m_signal != signal) {
0375         m_signal = signal;
0376         m_changedRoles << NetworkModel::SignalRole;
0377         refreshIcon();
0378     }
0379 }
0380 
0381 bool NetworkModelItem::slave() const
0382 {
0383     return m_slave;
0384 }
0385 
0386 void NetworkModelItem::setSlave(bool slave)
0387 {
0388     if (m_slave != slave) {
0389         m_slave = slave;
0390         m_changedRoles << NetworkModel::SlaveRole;
0391     }
0392 }
0393 
0394 QString NetworkModelItem::specificPath() const
0395 {
0396     return m_specificPath;
0397 }
0398 
0399 void NetworkModelItem::setSpecificPath(const QString &path)
0400 {
0401     if (m_specificPath != path) {
0402         m_specificPath = path;
0403         m_changedRoles << NetworkModel::SpecificPathRole;
0404     }
0405 }
0406 
0407 QString NetworkModelItem::ssid() const
0408 {
0409     return m_ssid;
0410 }
0411 
0412 void NetworkModelItem::setSsid(const QString &ssid)
0413 {
0414     if (m_ssid != ssid) {
0415         m_ssid = ssid;
0416         m_changedRoles << NetworkModel::SsidRole << NetworkModel::UniRole;
0417     }
0418 }
0419 
0420 NetworkManager::ConnectionSettings::ConnectionType NetworkModelItem::type() const
0421 {
0422     return m_type;
0423 }
0424 
0425 QDateTime NetworkModelItem::timestamp() const
0426 {
0427     return m_timestamp;
0428 }
0429 
0430 void NetworkModelItem::setTimestamp(const QDateTime &date)
0431 {
0432     if (m_timestamp != date) {
0433         m_timestamp = date;
0434         m_changedRoles << NetworkModel::TimeStampRole;
0435     }
0436 }
0437 
0438 void NetworkModelItem::setType(NetworkManager::ConnectionSettings::ConnectionType type)
0439 {
0440     if (m_type == type) {
0441         return;
0442     }
0443 
0444     m_type = type;
0445 
0446     const auto it = s_connectionTypeToString.find(type);
0447     if (it != s_connectionTypeToString.end()) {
0448         m_accessibleDescription = it->second;
0449     } else {
0450         m_accessibleDescription = s_connectionTypeToString.at(NetworkManager::ConnectionSettings::ConnectionType::Unknown);
0451     }
0452 
0453     m_changedRoles << NetworkModel::TypeRole << NetworkModel::ItemTypeRole << NetworkModel::UniRole << Qt::AccessibleDescriptionRole;
0454 
0455     refreshIcon();
0456 }
0457 
0458 QString NetworkModelItem::accessibleDescription() const
0459 {
0460     return m_accessibleDescription;
0461 }
0462 
0463 QString NetworkModelItem::uni() const
0464 {
0465     if (m_type == NetworkManager::ConnectionSettings::Wireless && m_uuid.isEmpty()) {
0466         return m_ssid + '%' + m_devicePath;
0467     } else {
0468         return m_connectionPath + '%' + m_devicePath;
0469     }
0470 }
0471 
0472 QString NetworkModelItem::uuid() const
0473 {
0474     return m_uuid;
0475 }
0476 
0477 void NetworkModelItem::setUuid(const QString &uuid)
0478 {
0479     if (m_uuid != uuid) {
0480         m_uuid = uuid;
0481         m_changedRoles << NetworkModel::UuidRole;
0482     }
0483 }
0484 
0485 QString NetworkModelItem::vpnState() const
0486 {
0487     return UiUtils::vpnConnectionStateToString(m_vpnState);
0488 }
0489 
0490 void NetworkModelItem::setVpnState(NetworkManager::VpnConnection::State state)
0491 {
0492     if (m_vpnState != state) {
0493         m_vpnState = state;
0494         m_changedRoles << NetworkModel::VpnState;
0495     }
0496 }
0497 
0498 QString NetworkModelItem::vpnType() const
0499 {
0500     return m_vpnType;
0501 }
0502 
0503 void NetworkModelItem::setVpnType(const QString &type)
0504 {
0505     if (m_vpnType != type) {
0506         m_vpnType = type;
0507         m_changedRoles << NetworkModel::VpnType;
0508     }
0509 }
0510 
0511 qulonglong NetworkModelItem::rxBytes() const
0512 {
0513     return m_rxBytes;
0514 }
0515 
0516 void NetworkModelItem::setRxBytes(qulonglong bytes)
0517 {
0518     if (m_rxBytes != bytes) {
0519         m_rxBytes = bytes;
0520         m_changedRoles << NetworkModel::RxBytesRole;
0521     }
0522 }
0523 
0524 qulonglong NetworkModelItem::txBytes() const
0525 {
0526     return m_txBytes;
0527 }
0528 
0529 void NetworkModelItem::setTxBytes(qulonglong bytes)
0530 {
0531     if (m_txBytes != bytes) {
0532         m_txBytes = bytes;
0533         m_changedRoles << NetworkModel::TxBytesRole;
0534     }
0535 }
0536 
0537 bool NetworkModelItem::delayModelUpdates() const
0538 {
0539     return m_delayModelUpdates;
0540 }
0541 
0542 void NetworkModelItem::setDelayModelUpdates(bool delay)
0543 {
0544     // special case, does not need m_changedRoles
0545     m_delayModelUpdates = delay;
0546 }
0547 
0548 bool NetworkModelItem::operator==(const NetworkModelItem *item) const
0549 {
0550     if (!item->uuid().isEmpty() && !uuid().isEmpty()) {
0551         if (item->devicePath() == devicePath() && item->uuid() == uuid()) {
0552             return true;
0553         }
0554     } else if (item->type() == NetworkManager::ConnectionSettings::Wireless && type() == NetworkManager::ConnectionSettings::Wireless) {
0555         if (item->ssid() == ssid() && item->devicePath() == devicePath()) {
0556             return true;
0557         }
0558     }
0559 
0560     return false;
0561 }
0562 
0563 void NetworkModelItem::invalidateDetails()
0564 {
0565     m_detailsValid = false;
0566     m_changedRoles << NetworkModel::ConnectionDetailsRole;
0567 }
0568 
0569 void NetworkModelItem::updateDetails() const
0570 {
0571     m_detailsValid = true;
0572     m_details.clear();
0573 
0574     if (itemType() == NetworkModelItem::UnavailableConnection) {
0575         return;
0576     }
0577 
0578     NetworkManager::Device::Ptr device = NetworkManager::findNetworkInterface(m_devicePath);
0579 
0580     // Get IPv[46]Address and related nameservers + IPv[46] default gateway
0581     if (device && device->ipV4Config().isValid() && m_connectionState == NetworkManager::ActiveConnection::Activated) {
0582         if (!device->ipV4Config().addresses().isEmpty()) {
0583             QHostAddress addr = device->ipV4Config().addresses().first().ip();
0584             if (!addr.isNull() && addr.isGlobal()) {
0585                 m_details << i18n("IPv4 Address") << addr.toString();
0586             }
0587         }
0588         if (!device->ipV4Config().gateway().isEmpty()) {
0589             QString addr = device->ipV4Config().gateway();
0590             if (!addr.isNull()) {
0591                 m_details << i18n("IPv4 Default Gateway") << addr;
0592             }
0593         }
0594         if (!device->ipV4Config().nameservers().isEmpty()) {
0595             QHostAddress addr1 = device->ipV4Config().nameservers().first();
0596             QHostAddress addr2 = device->ipV4Config().nameservers().last();
0597             if (!addr1.isNull()) {
0598                 m_details << i18n("IPv4 Primary Nameserver") << addr1.toString();
0599             }
0600             if (!addr2.isNull() && !addr1.isNull()) {
0601                 if (addr2 != addr1) {
0602                     m_details << i18n("IPv4 Secondary Nameserver") << addr2.toString();
0603                 }
0604             }
0605         }
0606     }
0607 
0608     if (device && device->ipV6Config().isValid() && m_connectionState == NetworkManager::ActiveConnection::Activated) {
0609         if (!device->ipV6Config().addresses().isEmpty()) {
0610             QHostAddress addr = device->ipV6Config().addresses().first().ip();
0611             if (!addr.isNull() && addr.isGlobal() && !addr.isUniqueLocalUnicast()) {
0612                 m_details << i18n("IPv6 Address") << addr.toString();
0613             } else if (!addr.isNull() && addr.isGlobal() && addr.isUniqueLocalUnicast()) {
0614                 m_details << i18n("IPv6 ULA Address") << addr.toString();
0615             }
0616         }
0617         if (!device->ipV6Config().gateway().isEmpty()) {
0618             QString addr = device->ipV6Config().gateway();
0619             if (!addr.isNull()) {
0620                 m_details << i18n("IPv6 Default Gateway") << addr;
0621             }
0622         }
0623         if (!device->ipV6Config().nameservers().isEmpty()) {
0624             QHostAddress addr1 = device->ipV6Config().nameservers().first();
0625             QHostAddress addr2 = device->ipV6Config().nameservers().last();
0626             if (!addr1.isNull()) {
0627                 m_details << i18n("IPv6 Primary Nameserver") << addr1.toString();
0628             }
0629             if (!addr2.isNull() && !addr1.isNull()) {
0630                 if (addr2 != addr1) {
0631                     m_details << i18n("IPv6 Secondary Nameserver") << addr2.toString();
0632                 }
0633             }
0634         }
0635     }
0636     if (m_type == NetworkManager::ConnectionSettings::Wired) {
0637         NetworkManager::WiredDevice::Ptr wiredDevice = device.objectCast<NetworkManager::WiredDevice>();
0638         if (wiredDevice) {
0639             if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
0640                 m_details << i18n("Connection speed") << UiUtils::connectionSpeed(wiredDevice->bitRate());
0641             }
0642             m_details << i18n("MAC Address") << wiredDevice->hardwareAddress();
0643         }
0644     } else if (m_type == NetworkManager::ConnectionSettings::Wireless) {
0645         NetworkManager::WirelessDevice::Ptr wirelessDevice = device.objectCast<NetworkManager::WirelessDevice>();
0646         m_details << i18n("Access point (SSID)") << m_ssid;
0647         if (m_mode == NetworkManager::WirelessSetting::Infrastructure) {
0648             m_details << i18n("Signal strength") << QStringLiteral("%1%").arg(m_signal);
0649         }
0650         m_details << i18n("Security type") << UiUtils::labelFromWirelessSecurity(m_securityType);
0651         if (wirelessDevice) {
0652             if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
0653                 m_details << i18n("Connection speed") << UiUtils::connectionSpeed(wirelessDevice->bitRate());
0654             }
0655             const NetworkManager::AccessPoint::Ptr accessPoint = wirelessDevice->findAccessPoint(m_specificPath);
0656             if (accessPoint) {
0657                 m_details << i18n("Frequency") << UiUtils::wirelessFrequencyToString(accessPoint->frequency());
0658                 m_details << i18n("BSSID") << accessPoint->hardwareAddress();
0659             }
0660             m_details << i18n("MAC Address") << wirelessDevice->hardwareAddress();
0661         }
0662     } else if (m_type == NetworkManager::ConnectionSettings::Gsm || m_type == NetworkManager::ConnectionSettings::Cdma) {
0663         NetworkManager::ModemDevice::Ptr modemDevice = device.objectCast<NetworkManager::ModemDevice>();
0664         if (modemDevice) {
0665             ModemManager::ModemDevice::Ptr modem = ModemManager::findModemDevice(modemDevice->udi());
0666             if (modem) {
0667                 ModemManager::Modem::Ptr modemNetwork = modem->interface(ModemManager::ModemDevice::ModemInterface).objectCast<ModemManager::Modem>();
0668 
0669                 if (m_type == NetworkManager::ConnectionSettings::Gsm) {
0670                     ModemManager::Modem3gpp::Ptr gsmNet = modem->interface(ModemManager::ModemDevice::GsmInterface).objectCast<ModemManager::Modem3gpp>();
0671                     if (gsmNet) {
0672                         m_details << i18n("Operator") << gsmNet->operatorName();
0673                     }
0674                 } else {
0675                     ModemManager::ModemCdma::Ptr cdmaNet = modem->interface(ModemManager::ModemDevice::CdmaInterface).objectCast<ModemManager::ModemCdma>();
0676                     m_details << i18n("Network ID") << QStringLiteral("%1").arg(cdmaNet->nid());
0677                 }
0678 
0679                 if (modemNetwork) {
0680                     m_details << i18n("Signal Quality") << QStringLiteral("%1%").arg(modemNetwork->signalQuality().signal);
0681                     m_details << i18n("Access Technology") << UiUtils::convertAccessTechnologyToString(modemNetwork->accessTechnologies());
0682                 }
0683             }
0684         }
0685     } else if (m_type == NetworkManager::ConnectionSettings::Vpn) {
0686         m_details << i18n("VPN plugin") << m_vpnType;
0687 
0688         if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
0689             NetworkManager::ActiveConnection::Ptr active = NetworkManager::findActiveConnection(m_activeConnectionPath);
0690             NetworkManager::VpnConnection::Ptr vpnConnection;
0691 
0692             if (active) {
0693                 vpnConnection = NetworkManager::VpnConnection::Ptr(new NetworkManager::VpnConnection(active->path()), &QObject::deleteLater);
0694             }
0695 
0696             if (vpnConnection && !vpnConnection->banner().isEmpty()) {
0697                 m_details << i18n("Banner") << vpnConnection->banner().simplified();
0698             }
0699         }
0700     } else if (m_type == NetworkManager::ConnectionSettings::Bluetooth) {
0701         NetworkManager::BluetoothDevice::Ptr bluetoothDevice = device.objectCast<NetworkManager::BluetoothDevice>();
0702         if (bluetoothDevice) {
0703             m_details << i18n("Name") << bluetoothDevice->name();
0704             if (bluetoothDevice->bluetoothCapabilities() == NetworkManager::BluetoothDevice::Pan) {
0705                 m_details << i18n("Capabilities") << QStringLiteral("PAN");
0706             } else if (bluetoothDevice->bluetoothCapabilities() == NetworkManager::BluetoothDevice::Dun) {
0707                 m_details << i18n("Capabilities") << QStringLiteral("DUN");
0708             }
0709             m_details << i18n("MAC Address") << bluetoothDevice->hardwareAddress();
0710         }
0711     } else if (m_type == NetworkManager::ConnectionSettings::Infiniband) {
0712         NetworkManager::InfinibandDevice::Ptr infinibandDevice = device.objectCast<NetworkManager::InfinibandDevice>();
0713         m_details << i18n("Type") << i18n("Infiniband");
0714         if (infinibandDevice) {
0715             m_details << i18n("MAC Address") << infinibandDevice->hwAddress();
0716         }
0717     } else if (m_type == NetworkManager::ConnectionSettings::Bond) {
0718         NetworkManager::BondDevice::Ptr bondDevice = device.objectCast<NetworkManager::BondDevice>();
0719         m_details << i18n("Type") << i18n("Bond");
0720         if (bondDevice) {
0721             m_details << i18n("MAC Address") << bondDevice->hwAddress();
0722         }
0723     } else if (m_type == NetworkManager::ConnectionSettings::Bridge) {
0724         NetworkManager::BridgeDevice::Ptr bridgeDevice = device.objectCast<NetworkManager::BridgeDevice>();
0725         m_details << i18n("Type") << i18n("Bridge");
0726         if (bridgeDevice) {
0727             m_details << i18n("MAC Address") << bridgeDevice->hwAddress();
0728         }
0729     } else if (m_type == NetworkManager::ConnectionSettings::Vlan) {
0730         NetworkManager::VlanDevice::Ptr vlanDevice = device.objectCast<NetworkManager::VlanDevice>();
0731         m_details << i18n("Type") << i18n("Vlan");
0732         if (vlanDevice) {
0733             m_details << i18n("Vlan ID") << QString("%1").arg(vlanDevice->vlanId());
0734             m_details << i18n("MAC Address") << vlanDevice->hwAddress();
0735         }
0736     } else if (m_type == NetworkManager::ConnectionSettings::Adsl) {
0737         m_details << i18n("Type") << i18n("Adsl");
0738     } else if (m_type == NetworkManager::ConnectionSettings::Team) {
0739         NetworkManager::TeamDevice::Ptr teamDevice = device.objectCast<NetworkManager::TeamDevice>();
0740         m_details << i18n("Type") << i18n("Team");
0741         if (teamDevice) {
0742             m_details << i18n("MAC Address") << teamDevice->hwAddress();
0743         }
0744     }
0745 
0746     if (device && m_connectionState == NetworkManager::ActiveConnection::Activated) {
0747         m_details << i18n("Device") << device->interfaceName();
0748     }
0749 }