void Handler::activateConnection(const QString& connection, const QString& device, const QString& specificObject) { NetworkManager::Connection::Ptr con = NetworkManager::findConnection(connection); if (!con) { qCWarning(NM) << "Not possible to activate this connection"; return; } if (con->settings()->connectionType() == NetworkManager::ConnectionSettings::Vpn) { NetworkManager::VpnSetting::Ptr vpnSetting = con->settings()->setting(NetworkManager::Setting::Vpn).staticCast<NetworkManager::VpnSetting>(); if (vpnSetting) { // qCDebug(NM) << "Checking VPN" << con->name() << "type:" << vpnSetting->serviceType(); #if 0 // get the list of supported VPN service types const KService::List services = KServiceTypeTrader::self()->query("PlasmaNetworkManagement/VpnUiPlugin", QString::fromLatin1("[X-NetworkManager-Services]=='%1'").arg(vpnSetting->serviceType())); if (services.isEmpty()) { qCWarning(NM) << "VPN" << vpnSetting->serviceType() << "not found, skipping"; KNotification *notification = new KNotification("MissingVpnPlugin", KNotification::CloseOnTimeout, this); notification->setComponentName("networkmanagement"); notification->setTitle(con->name()); notification->setText(i18n("Missing VPN plugin")); notification->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(KIconLoader::SizeHuge)); notification->sendEvent(); return; } #endif } } #if WITH_MODEMMANAGER_SUPPORT if (con->settings()->connectionType() == NetworkManager::ConnectionSettings::Gsm) { NetworkManager::ModemDevice::Ptr nmModemDevice = NetworkManager::findNetworkInterface(device).objectCast<NetworkManager::ModemDevice>(); if (nmModemDevice) { ModemManager::ModemDevice::Ptr mmModemDevice = ModemManager::findModemDevice(nmModemDevice->udi()); if (mmModemDevice) { ModemManager::Modem::Ptr modem = mmModemDevice->interface(ModemManager::ModemDevice::ModemInterface).objectCast<ModemManager::Modem>(); NetworkManager::GsmSetting::Ptr gsmSetting = con->settings()->setting(NetworkManager::Setting::Gsm).staticCast<NetworkManager::GsmSetting>(); if (gsmSetting && gsmSetting->pinFlags() == NetworkManager::Setting::NotSaved && modem && modem->unlockRequired() > MM_MODEM_LOCK_NONE) { QDBusInterface managerIface("org.kde.plasmanetworkmanagement", "/org/kde/plasmanetworkmanagement", "org.kde.plasmanetworkmanagement", QDBusConnection::sessionBus(), this); managerIface.call("unlockModem", mmModemDevice->uni()); connect(modem.data(), &ModemManager::Modem::unlockRequiredChanged, this, &Handler::unlockRequiredChanged); m_tmpConnectionPath = connection; m_tmpDevicePath = device; m_tmpSpecificPath = specificObject; return; } } } } #endif QDBusPendingReply<QDBusObjectPath> reply = NetworkManager::activateConnection(connection, device, specificObject); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); watcher->setProperty("action", Handler::ActivateConnection); watcher->setProperty("connection", con->name()); connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); }
void PasswordDialog::setupVpnUi(const ConnectionSettings &connectionSettings) { NetworkManager::VpnSetting::Ptr vpnSetting = connectionSettings.setting(Setting::Vpn).dynamicCast<VpnSetting>(); if (!vpnSetting) { qCWarning(PLASMA_NM) << "Missing VPN setting!"; m_hasError = true; m_error = SecretAgent::InternalError; m_errorMessage = QLatin1String("VPN settings are missing"); } else { VpnUiPlugin *vpnUiPlugin; QString error; const QString serviceType = vpnSetting->serviceType(); // qCDebug(PLASMA_NM) << "Agent loading VPN plugin" << serviceType << "from DBUS" << calledFromDBus(); // vpnSetting->printSetting(); vpnUiPlugin = KServiceTypeTrader::createInstanceFromQuery<VpnUiPlugin>(QLatin1String("PlasmaNetworkManagement/VpnUiPlugin"), QString::fromLatin1("[X-NetworkManager-Services]=='%1'").arg(serviceType), this, QVariantList(), &error); if (vpnUiPlugin && error.isEmpty()) { const QString shortName = serviceType.section('.', -1); setWindowTitle(i18n("VPN secrets (%1)", shortName)); vpnWidget = vpnUiPlugin->askUser(vpnSetting, this); QDialogButtonBox * box; if (shortName != QLatin1String("openconnect")) { box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); connect(box, &QDialogButtonBox::accepted, this, &PasswordDialog::accept); } else { box = new QDialogButtonBox(QDialogButtonBox::Cancel, Qt::Horizontal, this); } connect(box, &QDialogButtonBox::rejected, this, &PasswordDialog::reject); QVBoxLayout * layout = new QVBoxLayout(this); layout->addWidget(vpnWidget); layout->addWidget(box); setLayout(layout); } else { qCWarning(PLASMA_NM) << error << ", serviceType == " << serviceType; m_hasError = true; m_error = SecretAgent::InternalError; m_errorMessage = error; } } }
QVariant EditorIdentityModel::data(const QModelIndex& index, int role) const { const QModelIndex sourceIndex = sourceModel()->index(index.row(), 0); const QString connectionName = sourceModel()->data(sourceIndex, NetworkModel::NameRole).toString(); const QString lastUsed = sourceModel()->data(sourceIndex, NetworkModel::LastUsedDateOnlyRole).toString(); const bool isActivated = (NetworkManager::ActiveConnection::State) sourceModel()->data(sourceIndex, NetworkModel::ConnectionStateRole).toInt() == NetworkManager::ActiveConnection::Activated; const bool isActivating = (NetworkManager::ActiveConnection::State) sourceModel()->data(sourceIndex, NetworkModel::ConnectionStateRole).toInt() == NetworkManager::ActiveConnection::Activating; NetworkManager::ConnectionSettings::ConnectionType type = static_cast<NetworkManager::ConnectionSettings::ConnectionType>(sourceModel()->data(sourceIndex, NetworkModel::TypeRole).toInt()); NetworkManager::ConnectionSettings::Ptr settings; NetworkManager::VpnSetting::Ptr vpnSetting ; if (type == NetworkManager::ConnectionSettings::Vpn) { settings = NetworkManager::findConnection(sourceModel()->data(sourceIndex, NetworkModel::ConnectionPathRole).toString())->settings(); if (settings) { vpnSetting = settings->setting(NetworkManager::Setting::Vpn).staticCast<NetworkManager::VpnSetting>(); } } QString tooltip; const QString iconName = UiUtils::iconAndTitleForConnectionSettingsType(type, tooltip); const int column = index.column(); if (role == Qt::DisplayRole) { switch (column) { case 0: if (type == NetworkManager::ConnectionSettings::Infiniband || type == NetworkManager::ConnectionSettings::Bond || type == NetworkManager::ConnectionSettings::Bridge || #if NM_CHECK_VERSION(0, 9, 10) type == NetworkManager::ConnectionSettings::Team || #endif type == NetworkManager::ConnectionSettings::Vlan) { return QString(connectionName + " (" + NetworkManager::ConnectionSettings::typeAsString(type) + ")"); } return connectionName; case 1: if (type == NetworkManager::ConnectionSettings::Vpn && vpnSetting) { return QString("%1 (%2)").arg(tooltip).arg(vpnSetting->serviceType().section('.', -1)); } return tooltip; case 2: return lastUsed; } } else if (role == Qt::DecorationRole) { if (column == 0) { return QIcon::fromTheme(iconName); } } else if (role == Qt::ToolTipRole) { if (column == 0) return tooltip; } else if (role == Qt::FontRole) { if (column == 0 && isActivated) { QFont f; f.setBold(true); return f; } else if (column == 0 && isActivating) { QFont f; f.setItalic(true); return f; } } else { return sourceModel()->data(index, role); } return QVariant(); }