networkmodelitem.cpp 21.5 KB
Newer Older
Jan Grulich's avatar
Jan Grulich committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
    Copyright 2013-2014 Jan Grulich <jgrulich@redhat.com>

    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 <http://www.gnu.org/licenses/>.
*/

#include "networkmodelitem.h"
#include "uiutils.h"

24
#include <NetworkManagerQt/AdslDevice>
Jan Grulich's avatar
Jan Grulich committed
25
#include <NetworkManagerQt/BluetoothDevice>
26 27 28
#include <NetworkManagerQt/BondDevice>
#include <NetworkManagerQt/BridgeDevice>
#include <NetworkManagerQt/InfinibandDevice>
Jan Grulich's avatar
Jan Grulich committed
29 30 31
#include <NetworkManagerQt/Manager>
#include <NetworkManagerQt/ModemDevice>
#include <NetworkManagerQt/Settings>
32 33 34
#if NM_CHECK_VERSION (0, 9, 10)
#include <NetworkManagerQt/TeamDevice>
#endif
Jan Grulich's avatar
Jan Grulich committed
35
#include <NetworkManagerQt/Utils>
36
#include <NetworkManagerQt/VlanDevice>
Jan Grulich's avatar
Jan Grulich committed
37 38
#include <NetworkManagerQt/VpnConnection>
#include <NetworkManagerQt/VpnSetting>
Jan Grulich's avatar
Jan Grulich committed
39
#if !NM_CHECK_VERSION(1, 2, 0)
Jan Grulich's avatar
Jan Grulich committed
40
#include <NetworkManagerQt/WimaxDevice>
Jan Grulich's avatar
Jan Grulich committed
41
#endif
Jan Grulich's avatar
Jan Grulich committed
42 43 44 45 46 47 48 49 50
#include <NetworkManagerQt/WiredDevice>
#include <NetworkManagerQt/WirelessDevice>
#include <NetworkManagerQt/WirelessSetting>

#include <KLocalizedString>

#if WITH_MODEMMANAGER_SUPPORT
#include <ModemManagerQt/manager.h>
#include <ModemManagerQt/modem.h>
Jan Grulich's avatar
Jan Grulich committed
51 52 53
#include <ModemManagerQt/modemdevice.h>
#include <ModemManagerQt/modem3gpp.h>
#include <ModemManagerQt/modemcdma.h>
Jan Grulich's avatar
Jan Grulich committed
54 55 56 57 58 59 60 61
#endif

NetworkModelItem::NetworkModelItem(QObject* parent)
    : QObject(parent)
    , m_connectionState(NetworkManager::ActiveConnection::Deactivated)
    , m_deviceState(NetworkManager::Device::UnknownState)
    , m_duplicate(false)
    , m_mode(NetworkManager::WirelessSetting::Infrastructure)
Jan Grulich's avatar
Jan Grulich committed
62
    , m_securityType(NetworkManager::NoneSecurity)
Jan Grulich's avatar
Jan Grulich committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    , m_signal(0)
    , m_slave(false)
    , m_type(NetworkManager::ConnectionSettings::Unknown)
    , m_vpnState(NetworkManager::VpnConnection::Unknown)
{
}

NetworkModelItem::NetworkModelItem(const NetworkModelItem* item, QObject* parent)
    : QObject(parent)
    , m_connectionPath(item->connectionPath())
    , m_connectionState(NetworkManager::ActiveConnection::Deactivated)
    , m_duplicate(true)
    , m_mode(item->mode())
    , m_name(item->name())
    , m_securityType(item->securityType())
    , m_slave(item->slave())
    , m_ssid(item->ssid())
    , m_timestamp(item->timestamp())
    , m_type(item->type())
    , m_uuid(item->uuid())
    , m_vpnState(NetworkManager::VpnConnection::Unknown)
{
}

NetworkModelItem::~NetworkModelItem()
{
}

QString NetworkModelItem::activeConnectionPath() const
{
    return m_activeConnectionPath;
}

void NetworkModelItem::setActiveConnectionPath(const QString& path)
{
    m_activeConnectionPath = path;
}

QString NetworkModelItem::connectionPath() const
{
    return m_connectionPath;
}

void NetworkModelItem::setConnectionPath(const QString& path)
{
    m_connectionPath = path;
}

NetworkManager::ActiveConnection::State NetworkModelItem::connectionState() const
{
    return m_connectionState;
}

void NetworkModelItem::setConnectionState(NetworkManager::ActiveConnection::State state)
{
    m_connectionState = state;
}

Jan Grulich's avatar
Jan Grulich committed
121
QStringList NetworkModelItem::details() const
Jan Grulich's avatar
Jan Grulich committed
122 123 124 125 126 127 128 129 130
{
    return m_details;
}

QString NetworkModelItem::devicePath() const
{
    return m_devicePath;
}

131 132 133 134 135
QString NetworkModelItem::deviceName() const
{
    return m_deviceName;
}

Jan Grulich's avatar
Jan Grulich committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
void NetworkModelItem::setDeviceName(const QString& name)
{
    m_deviceName = name;
}

void NetworkModelItem::setDevicePath(const QString& path)
{
    m_devicePath = path;
}

QString NetworkModelItem::deviceState() const
{
    return UiUtils::connectionStateToString(m_deviceState);
}

void NetworkModelItem::setDeviceState(const NetworkManager::Device::State state)
{
    m_deviceState = state;
}

bool NetworkModelItem::duplicate() const
{
    return m_duplicate;
}

QString NetworkModelItem::icon() const
{
    switch (m_type) {
        case NetworkManager::ConnectionSettings::Adsl:
Nick Shaforostoff's avatar
Nick Shaforostoff committed
165
            return QStringLiteral("network-mobile-100");
Jan Grulich's avatar
Jan Grulich committed
166 167 168
            break;
        case NetworkManager::ConnectionSettings::Bluetooth:
            if (connectionState() == NetworkManager::ActiveConnection::Activated) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
169
                return QStringLiteral("network-bluetooth-activated");
Jan Grulich's avatar
Jan Grulich committed
170
            } else {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
171
                return QStringLiteral("network-bluetooth");
Jan Grulich's avatar
Jan Grulich committed
172 173 174 175 176 177 178 179 180
            }
            break;
        case NetworkManager::ConnectionSettings::Bond:
            break;
        case NetworkManager::ConnectionSettings::Bridge:
            break;
        case NetworkManager::ConnectionSettings::Cdma:
        case NetworkManager::ConnectionSettings::Gsm:
            if (m_signal == 0 ) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
181
                return QStringLiteral("network-mobile-0");
Jan Grulich's avatar
Jan Grulich committed
182
            } else if (m_signal < 20) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
183
                return QStringLiteral("network-mobile-20");
Jan Grulich's avatar
Jan Grulich committed
184
            } else if (m_signal < 40) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
185
                return QStringLiteral("network-mobile-40");
Jan Grulich's avatar
Jan Grulich committed
186
            } else if (m_signal < 60) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
187
                return QStringLiteral("network-mobile-60");
Jan Grulich's avatar
Jan Grulich committed
188
            } else if (m_signal < 80) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
189
                return QStringLiteral("network-mobile-80");
Jan Grulich's avatar
Jan Grulich committed
190
            } else {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
191
                return QStringLiteral("network-mobile-100");
Jan Grulich's avatar
Jan Grulich committed
192 193 194 195 196 197 198
            }
            break;
        case NetworkManager::ConnectionSettings::Infiniband:
            break;
        case NetworkManager::ConnectionSettings::OLPCMesh:
            break;
        case NetworkManager::ConnectionSettings::Pppoe:
Nick Shaforostoff's avatar
Nick Shaforostoff committed
199
            return QStringLiteral("network-mobile-100");
Jan Grulich's avatar
Jan Grulich committed
200 201 202 203
            break;
        case NetworkManager::ConnectionSettings::Vlan:
            break;
        case NetworkManager::ConnectionSettings::Vpn:
Nick Shaforostoff's avatar
Nick Shaforostoff committed
204
            return QStringLiteral("network-vpn");
Jan Grulich's avatar
Jan Grulich committed
205 206
            break;
        case NetworkManager::ConnectionSettings::Wimax:
207
            if (m_signal == 0 ) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
208
                return QStringLiteral("network-wireless-0");
209
            } else if (m_signal < 20) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
210
                return QStringLiteral("network-wireless-20");
211
            } else if (m_signal < 40) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
212
                return QStringLiteral("network-wireless-40");
213
            } else if (m_signal < 60) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
214
                return QStringLiteral("network-wireless-60");
215
            } else if (m_signal < 80) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
216
                return QStringLiteral("network-wireless-80");
217
            } else {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
218
                return QStringLiteral("network-wireless-100");
219
            }
Jan Grulich's avatar
Jan Grulich committed
220 221 222
            break;
        case NetworkManager::ConnectionSettings::Wired:
            if (connectionState() == NetworkManager::ActiveConnection::Activated) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
223
                return QStringLiteral("network-wired-activated");
Jan Grulich's avatar
Jan Grulich committed
224
            } else {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
225
                return QStringLiteral("network-wired");
Jan Grulich's avatar
Jan Grulich committed
226 227 228 229 230
            }
            break;
        case NetworkManager::ConnectionSettings::Wireless:
            if (m_signal == 0 ) {
                if (m_mode == NetworkManager::WirelessSetting::Adhoc || m_mode == NetworkManager::WirelessSetting::Ap) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
231
                    return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-100") : QStringLiteral("network-wireless-100-locked");
Jan Grulich's avatar
Jan Grulich committed
232
                }
Nick Shaforostoff's avatar
Nick Shaforostoff committed
233
                return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-0") : QStringLiteral("network-wireless-0-locked");
Jan Grulich's avatar
Jan Grulich committed
234
            } else if (m_signal < 20) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
235
                return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-20") : QStringLiteral("network-wireless-20-locked");
Jan Grulich's avatar
Jan Grulich committed
236
            } else if (m_signal < 40) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
237
                return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-40") : QStringLiteral("network-wireless-40-locked");
Jan Grulich's avatar
Jan Grulich committed
238
            } else if (m_signal < 60) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
239
                return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-60") : QStringLiteral("network-wireless-60-locked");
Jan Grulich's avatar
Jan Grulich committed
240
            } else if (m_signal < 80) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
241
                return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-80") : QStringLiteral("network-wireless-80-locked");
Jan Grulich's avatar
Jan Grulich committed
242
            } else {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
243
                return (m_securityType <= NetworkManager::NoneSecurity) ? QStringLiteral("network-wireless-100") : QStringLiteral("network-wireless-100-locked");
Jan Grulich's avatar
Jan Grulich committed
244 245 246 247 248 249
            }
            break;
        default:
            break;
    }

250
    if (connectionState() == NetworkManager::ActiveConnection::Activated) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
251
        return QStringLiteral("network-wired-activated");
252
    } else {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
253
        return QStringLiteral("network-wired");
254
    }
Jan Grulich's avatar
Jan Grulich committed
255 256 257 258 259
}

NetworkModelItem::ItemType NetworkModelItem::itemType() const
{
    if (!m_devicePath.isEmpty() ||
Jan Grulich's avatar
Jan Grulich committed
260 261
        m_type == NetworkManager::ConnectionSettings::Bond ||
        m_type == NetworkManager::ConnectionSettings::Bridge ||
Jan Grulich's avatar
Jan Grulich committed
262
        m_type == NetworkManager::ConnectionSettings::Vlan ||
263
#if NM_CHECK_VERSION(0, 9, 10)
Jan Grulich's avatar
Jan Grulich committed
264 265
        m_type == NetworkManager::ConnectionSettings::Team ||
#endif
266
        (NetworkManager::status() == NetworkManager::Connected && m_type == NetworkManager::ConnectionSettings::Vpn)) {
Jan Grulich's avatar
Jan Grulich committed
267 268
        if (m_connectionPath.isEmpty() && m_type == NetworkManager::ConnectionSettings::Wireless) {
            return NetworkModelItem::AvailableAccessPoint;
269 270
        } else if (m_connectionPath.isEmpty() && m_type == NetworkManager::ConnectionSettings::Wimax) {
            return NetworkModelItem::AvailableNsp;
Jan Grulich's avatar
Jan Grulich committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
        } else {
            return NetworkModelItem::AvailableConnection;
        }
    }
    return NetworkModelItem::UnavailableConnection;
}

NetworkManager::WirelessSetting::NetworkMode NetworkModelItem::mode() const
{
    return m_mode;
}

void NetworkModelItem::setMode(const NetworkManager::WirelessSetting::NetworkMode mode)
{
    m_mode = mode;
}

QString NetworkModelItem::name() const
{
    return m_name;
}

void NetworkModelItem::setName(const QString& name)
{
    m_name = name;
}

298 299 300 301 302 303 304 305 306 307
QString NetworkModelItem::nsp() const
{
    return m_nsp;
}

void NetworkModelItem::setNsp(const QString& nsp)
{
    m_nsp = nsp;
}

Jan Grulich's avatar
Jan Grulich committed
308 309 310 311 312
QString NetworkModelItem::originalName() const
{
    if (m_deviceName.isEmpty()) {
        return m_name;
    }
Nick Shaforostoff's avatar
Nick Shaforostoff committed
313
    return m_name % QLatin1String(" (") % m_deviceName % ')';
Jan Grulich's avatar
Jan Grulich committed
314 315 316 317 318 319 320 321 322 323 324
}

QString NetworkModelItem::sectionType() const
{
    if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
        return i18n("Active connections");
    }  else {
        return i18n("Available connections");
    }
}

Jan Grulich's avatar
Jan Grulich committed
325
NetworkManager::WirelessSecurityType NetworkModelItem::securityType() const
Jan Grulich's avatar
Jan Grulich committed
326 327 328 329
{
    return m_securityType;
}

Jan Grulich's avatar
Jan Grulich committed
330
void NetworkModelItem::setSecurityType(NetworkManager::WirelessSecurityType type)
Jan Grulich's avatar
Jan Grulich committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
{
    m_securityType = type;
}

int NetworkModelItem::signal() const
{
    return m_signal;
}

void NetworkModelItem::setSignal(int signal)
{
    m_signal = signal;
}

bool NetworkModelItem::slave() const
{
    return m_slave;
}

void NetworkModelItem::setSlave(bool slave)
{
    m_slave = slave;
}

QString NetworkModelItem::specificPath() const
{
    return m_specificPath;
}

void NetworkModelItem::setSpecificPath(const QString& path)
{
    m_specificPath = path;
}

QString NetworkModelItem::ssid() const
{
    return m_ssid;
}

void NetworkModelItem::setSsid(const QString& ssid)
{
    m_ssid = ssid;
}

NetworkManager::ConnectionSettings::ConnectionType NetworkModelItem::type() const
{
    return m_type;
}

QDateTime NetworkModelItem::timestamp() const
{
    return m_timestamp;
}

void NetworkModelItem::setTimestamp(const QDateTime& date)
{
    m_timestamp = date;
}

void NetworkModelItem::setType(NetworkManager::ConnectionSettings::ConnectionType type)
{
    m_type = type;
}

QString NetworkModelItem::uni() const
{
    if (m_type == NetworkManager::ConnectionSettings::Wireless && m_uuid.isEmpty()) {
        return m_ssid + '%' + m_devicePath;
399 400
    } else if (m_type == NetworkManager::ConnectionSettings::Wimax && m_uuid.isEmpty()) {
        return m_nsp + '%' + m_devicePath;
Jan Grulich's avatar
Jan Grulich committed
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
    } else {
        return m_connectionPath + '%' + m_devicePath;
    }
}

QString NetworkModelItem::uuid() const
{
    return m_uuid;
}

void NetworkModelItem::setUuid(const QString& uuid)
{
    m_uuid = uuid;
}

QString NetworkModelItem::vpnState() const
{
    return UiUtils::vpnConnectionStateToString(m_vpnState);
}

void NetworkModelItem::setVpnState(NetworkManager::VpnConnection::State state)
{
    m_vpnState = state;
}

426 427 428 429 430 431 432 433 434 435
QString NetworkModelItem::vpnType() const
{
    return m_vpnType;
}

void NetworkModelItem::setVpnType(const QString &type)
{
    m_vpnType = type;
}

Jan Grulich's avatar
Jan Grulich committed
436 437 438 439 440 441 442 443 444 445
bool NetworkModelItem::operator==(const NetworkModelItem* item) const
{
    if (!item->uuid().isEmpty() && !uuid().isEmpty()) {
        if (item->devicePath() == devicePath() && item->uuid() == uuid()) {
            return true;
        }
    } else if (item->type() == NetworkManager::ConnectionSettings::Wireless && type() == NetworkManager::ConnectionSettings::Wireless) {
        if (item->ssid() == ssid() && item->devicePath() == devicePath()) {
            return true;
        }
446 447 448 449
    } else if (item->type() == NetworkManager::ConnectionSettings::Wimax && type() == NetworkManager::ConnectionSettings::Wimax) {
        if (item->nsp() == nsp() && item->devicePath() == devicePath()) {
            return true;
        }
Jan Grulich's avatar
Jan Grulich committed
450 451 452 453 454 455 456
    }

    return false;
}

void NetworkModelItem::updateDetails()
{
Jan Grulich's avatar
Jan Grulich committed
457 458
    m_details.clear();

Jan Grulich's avatar
Jan Grulich committed
459 460 461 462 463 464
    if (itemType() == NetworkModelItem::UnavailableConnection) {
        return;
    }

    NetworkManager::Device::Ptr device = NetworkManager::findNetworkInterface(m_devicePath);

Jan Grulich's avatar
Jan Grulich committed
465 466 467 468 469 470 471 472 473
    // Get IPv[46]Address
    if (device && device->ipV4Config().isValid() && m_connectionState == NetworkManager::ActiveConnection::Activated) {
        if (!device->ipV4Config().addresses().isEmpty()) {
            QHostAddress addr = device->ipV4Config().addresses().first().ip();
            if (!addr.isNull()) {
                m_details << i18n("IPv4 Address") << addr.toString();
            }
        }
    }
Jan Grulich's avatar
Jan Grulich committed
474

Jan Grulich's avatar
Jan Grulich committed
475 476 477 478 479 480
    if (device && device->ipV6Config().isValid() && m_connectionState == NetworkManager::ActiveConnection::Activated) {
        if (!device->ipV6Config().addresses().isEmpty()) {
            QHostAddress addr = device->ipV6Config().addresses().first().ip();
            if (!addr.isNull()) {
                m_details << i18n("IPv6 Address") << addr.toString();
            }
Jan Grulich's avatar
Jan Grulich committed
481
        }
Jan Grulich's avatar
Jan Grulich committed
482 483 484 485 486 487 488 489 490
    }

    if (m_type == NetworkManager::ConnectionSettings::Wired) {
        NetworkManager::WiredDevice::Ptr wiredDevice = device.objectCast<NetworkManager::WiredDevice>();
        if (wiredDevice) {
            if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
                m_details << i18n("Connection speed") << UiUtils::connectionSpeed(wiredDevice->bitRate());
            }
            m_details << i18n("MAC Address") << wiredDevice->permanentHardwareAddress();
Jan Grulich's avatar
Jan Grulich committed
491 492
        }
    } else if (m_type == NetworkManager::ConnectionSettings::Wireless) {
Jan Grulich's avatar
Jan Grulich committed
493 494
        NetworkManager::WirelessDevice::Ptr wirelessDevice = device.objectCast<NetworkManager::WirelessDevice>();
        m_details << i18n("Access point (SSID)") << m_ssid;
495 496 497
        if (m_mode == NetworkManager::WirelessSetting::Infrastructure) {
            m_details << i18n("Signal strength") << QString("%1%").arg(m_signal);
        }
498 499 500
        if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
            m_details << i18n("Security type") << UiUtils::labelFromWirelessSecurity(m_securityType);
        }
Jan Grulich's avatar
Jan Grulich committed
501
        if (wirelessDevice) {
Jan Grulich's avatar
Jan Grulich committed
502 503 504 505
            if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
                m_details << i18n("Connection speed") << UiUtils::connectionSpeed(wirelessDevice->bitRate());
            }
            m_details << i18n("MAC Address") << wirelessDevice->permanentHardwareAddress();
Jan Grulich's avatar
Jan Grulich committed
506
        }
Jan Grulich's avatar
Jan Grulich committed
507 508 509
    } else if (m_type == NetworkManager::ConnectionSettings::Gsm || m_type == NetworkManager::ConnectionSettings::Cdma) {
#if WITH_MODEMMANAGER_SUPPORT
        NetworkManager::ModemDevice::Ptr modemDevice = device.objectCast<NetworkManager::ModemDevice>();
510 511 512 513 514 515 516 517 518 519 520 521 522 523
        if (modemDevice) {
            ModemManager::ModemDevice::Ptr modem = ModemManager::findModemDevice(modemDevice->udi());
            if (modem) {
                ModemManager::Modem::Ptr modemNetwork = modem->interface(ModemManager::ModemDevice::ModemInterface).objectCast<ModemManager::Modem>();

                if (m_type == NetworkManager::ConnectionSettings::Gsm) {
                    ModemManager::Modem3gpp::Ptr gsmNet = modem->interface(ModemManager::ModemDevice::GsmInterface).objectCast<ModemManager::Modem3gpp>();
                    if (gsmNet) {
                        m_details << i18n("Operator") << gsmNet->operatorName();
                    }
                } else {
                    ModemManager::ModemCdma::Ptr cdmaNet = modem->interface(ModemManager::ModemDevice::CdmaInterface).objectCast<ModemManager::ModemCdma>();
                    m_details << i18n("Network ID") << QString("%1").arg(cdmaNet->nid());
                }
Jan Grulich's avatar
Jan Grulich committed
524

525 526 527 528
                if (modemNetwork) {
                    m_details << i18n("Signal Quality") << QString("%1%").arg(modemNetwork->signalQuality().signal);
                    m_details << i18n("Access Technology") << UiUtils::convertAccessTechnologyToString(modemNetwork->accessTechnologies());
                }
529
            }
Jan Grulich's avatar
Jan Grulich committed
530 531
        }
#endif
Jan Grulich's avatar
Jan Grulich committed
532
    } else if (m_type == NetworkManager::ConnectionSettings::Vpn) {
533
        m_details << i18n("VPN plugin") << m_vpnType;
Jan Grulich's avatar
Jan Grulich committed
534

Jan Grulich's avatar
Jan Grulich committed
535 536 537 538 539 540 541 542
        if (m_connectionState == NetworkManager::ActiveConnection::Activated) {
            NetworkManager::ActiveConnection::Ptr active = NetworkManager::findActiveConnection(m_activeConnectionPath);
            NetworkManager::VpnConnection::Ptr vpnConnection;

            if (active) {
                vpnConnection = NetworkManager::VpnConnection::Ptr(new NetworkManager::VpnConnection(active->path()), &QObject::deleteLater);
            }

543
            if (vpnConnection && !vpnConnection->banner().isEmpty()) {
Jan Grulich's avatar
Jan Grulich committed
544 545 546 547
                m_details << i18n("Banner") << vpnConnection->banner().simplified();
            }
        }
    } else if (m_type == NetworkManager::ConnectionSettings::Bluetooth) {
548 549 550 551
        NetworkManager::BluetoothDevice::Ptr bluetoothDevice = device.objectCast<NetworkManager::BluetoothDevice>();
        if (bluetoothDevice) {
            m_details << i18n("Name") << bluetoothDevice->name();
            if (bluetoothDevice->bluetoothCapabilities() == NetworkManager::BluetoothDevice::Pan) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
552
                m_details << i18n("Capabilities") << QStringLiteral("PAN");
553
            } else if (bluetoothDevice->bluetoothCapabilities() == NetworkManager::BluetoothDevice::Dun) {
Nick Shaforostoff's avatar
Nick Shaforostoff committed
554
                m_details << i18n("Capabilities") << QStringLiteral("DUN");
555 556 557 558
            }
            m_details << i18n("MAC Address") << bluetoothDevice->hardwareAddress();

        }
Jan Grulich's avatar
Jan Grulich committed
559
#if !NM_CHECK_VERSION(1, 2, 0)
Jan Grulich's avatar
Jan Grulich committed
560
    } else if (m_type == NetworkManager::ConnectionSettings::Wimax) {
561 562 563 564
        NetworkManager::WimaxDevice::Ptr wimaxDevice = device.objectCast<NetworkManager::WimaxDevice>();
        if (wimaxDevice) {
            NetworkManager::WimaxNsp::Ptr wimaxNsp = wimaxDevice->findNsp(m_specificPath);
            m_details << i18n("NSP Name") << m_nsp;
565
            m_details << i18n("Signal Strength") << QString("%1%").arg(m_signal);
566 567 568 569 570 571
            if (wimaxNsp) {
                m_details << i18n("Network Type");
            }
            m_details << i18n("Bsid") << wimaxDevice->bsid();
            m_details << i18n("MAC Address") << wimaxDevice->hardwareAddress();
        }
Jan Grulich's avatar
Jan Grulich committed
572
#endif
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
    } else if (m_type == NetworkManager::ConnectionSettings::Infiniband) {
        NetworkManager::InfinibandDevice::Ptr infinibandDevice = device.objectCast<NetworkManager::InfinibandDevice>();
        m_details << i18n("Type") << i18n("Infiniband");
        if (infinibandDevice) {
            m_details << i18n("MAC Address") << infinibandDevice->hwAddress();
        }
    } else if (m_type == NetworkManager::ConnectionSettings::Bond) {
        NetworkManager::BondDevice::Ptr bondDevice = device.objectCast<NetworkManager::BondDevice>();
        m_details << i18n("Type") << i18n("Bond");
        if (bondDevice) {
            m_details << i18n("MAC Address") << bondDevice->hwAddress();
        }
    } else if (m_type == NetworkManager::ConnectionSettings::Bridge) {
        NetworkManager::BridgeDevice::Ptr bridgeDevice = device.objectCast<NetworkManager::BridgeDevice>();
        m_details << i18n("Type") << i18n("Bridge");
        if (bridgeDevice) {
            m_details << i18n("MAC Address") << bridgeDevice->hwAddress();
        }
    } else if (m_type == NetworkManager::ConnectionSettings::Vlan) {
        NetworkManager::VlanDevice::Ptr vlanDevice = device.objectCast<NetworkManager::VlanDevice>();
        m_details << i18n("Type") << i18n("Vlan");
        if (vlanDevice) {
595
            m_details << i18n("Vlan ID") << QString("%1").arg(vlanDevice->vlanId());
596 597 598 599 600 601 602 603 604 605 606 607
            m_details << i18n("MAC Address") << vlanDevice->hwAddress();
        }
    } else if (m_type == NetworkManager::ConnectionSettings::Adsl) {
        m_details << i18n("Type") << i18n("Adsl");
    }
#if NM_CHECK_VERSION (0, 9, 10)
      else if (m_type == NetworkManager::ConnectionSettings::Team) {
        NetworkManager::TeamDevice::Ptr teamDevice = device.objectCast<NetworkManager::TeamDevice>();
        m_details << i18n("Type") << i18n("Team");
        if (teamDevice) {
            m_details << i18n("MAC Address") << teamDevice->hwAddress();
        }
Jan Grulich's avatar
Jan Grulich committed
608
    }
609
#endif
Jan Grulich's avatar
Jan Grulich committed
610
}