Changeset View
Changeset View
Standalone View
Standalone View
kcm/kcm.cpp
Show All 19 Lines | |||||
20 | 20 | | |||
21 | #include "kcm.h" | 21 | #include "kcm.h" | ||
22 | 22 | | |||
23 | #include "debug.h" | 23 | #include "debug.h" | ||
24 | #include "connectioneditordialog.h" | 24 | #include "connectioneditordialog.h" | ||
25 | #include "mobileconnectionwizard.h" | 25 | #include "mobileconnectionwizard.h" | ||
26 | #include "uiutils.h" | 26 | #include "uiutils.h" | ||
27 | #include "vpnuiplugin.h" | 27 | #include "vpnuiplugin.h" | ||
28 | #include "settings/wireguardinterfacewidget.h" | ||||
28 | 29 | | |||
29 | // KDE | 30 | // KDE | ||
30 | #include <KMessageBox> | 31 | #include <KMessageBox> | ||
31 | #include <KPluginFactory> | 32 | #include <KPluginFactory> | ||
32 | #include <KSharedConfig> | 33 | #include <KSharedConfig> | ||
33 | #include <kdeclarative/kdeclarative.h> | 34 | #include <kdeclarative/kdeclarative.h> | ||
34 | #include <KService> | 35 | #include <KService> | ||
35 | #include <KServiceTypeTrader> | 36 | #include <KServiceTypeTrader> | ||
36 | 37 | | |||
37 | #include <NetworkManagerQt/ActiveConnection> | 38 | #include <NetworkManagerQt/ActiveConnection> | ||
38 | #include <NetworkManagerQt/Connection> | 39 | #include <NetworkManagerQt/Connection> | ||
39 | #include <NetworkManagerQt/ConnectionSettings> | 40 | #include <NetworkManagerQt/ConnectionSettings> | ||
40 | #include <NetworkManagerQt/GsmSetting> | 41 | #include <NetworkManagerQt/GsmSetting> | ||
41 | #include <NetworkManagerQt/Ipv4Setting> | 42 | #include <NetworkManagerQt/Ipv4Setting> | ||
43 | #include <NetworkManagerQt/Ipv6Setting> | ||||
42 | #include <NetworkManagerQt/Settings> | 44 | #include <NetworkManagerQt/Settings> | ||
43 | #include <NetworkManagerQt/Utils> | 45 | #include <NetworkManagerQt/Utils> | ||
44 | #include <NetworkManagerQt/VpnSetting> | 46 | #include <NetworkManagerQt/VpnSetting> | ||
45 | #include <NetworkManagerQt/WiredSetting> | 47 | #include <NetworkManagerQt/WiredSetting> | ||
46 | #include <NetworkManagerQt/WirelessSetting> | 48 | #include <NetworkManagerQt/WirelessSetting> | ||
47 | #include <NetworkManagerQt/WirelessDevice> | 49 | #include <NetworkManagerQt/WirelessDevice> | ||
50 | #include <NetworkManagerQt/WireguardSetting> | ||||
48 | 51 | | |||
49 | // Qt | 52 | // Qt | ||
50 | #include <QFileDialog> | 53 | #include <QFileDialog> | ||
51 | #include <QMenu> | 54 | #include <QMenu> | ||
52 | #include <QVBoxLayout> | 55 | #include <QVBoxLayout> | ||
53 | #include <QTimer> | 56 | #include <QTimer> | ||
54 | #include <QQmlContext> | 57 | #include <QQmlContext> | ||
55 | #include <QQmlEngine> | 58 | #include <QQmlEngine> | ||
▲ Show 20 Lines • Show All 196 Lines • ▼ Show 20 Line(s) | 251 | if (connectionSettings && connectionSettings->uuid() == m_createdConnectionUuid) { | |||
252 | m_createdConnectionUuid.clear(); | 255 | m_createdConnectionUuid.clear(); | ||
253 | } | 256 | } | ||
254 | } | 257 | } | ||
255 | } | 258 | } | ||
256 | 259 | | |||
257 | void KCMNetworkmanagement::onRequestCreateConnection(int connectionType, const QString &vpnType, const QString &specificType, bool shared) | 260 | void KCMNetworkmanagement::onRequestCreateConnection(int connectionType, const QString &vpnType, const QString &specificType, bool shared) | ||
258 | { | 261 | { | ||
259 | NetworkManager::ConnectionSettings::ConnectionType type = static_cast<NetworkManager::ConnectionSettings::ConnectionType>(connectionType); | 262 | NetworkManager::ConnectionSettings::ConnectionType type = static_cast<NetworkManager::ConnectionSettings::ConnectionType>(connectionType); | ||
260 | 263 | | |||
jgrulich: Please remove. | |||||
261 | if (type == NetworkManager::ConnectionSettings::Vpn && vpnType == "imported") { | 264 | if (type == NetworkManager::ConnectionSettings::Vpn && vpnType == "imported") { | ||
262 | importVpn(); | 265 | importVpn(); | ||
263 | } else if (type == NetworkManager::ConnectionSettings::Gsm) { // launch the mobile broadband wizard, both gsm/cdma | 266 | } else if (type == NetworkManager::ConnectionSettings::Gsm) { // launch the mobile broadband wizard, both gsm/cdma | ||
264 | #if WITH_MODEMMANAGER_SUPPORT | 267 | #if WITH_MODEMMANAGER_SUPPORT | ||
265 | QPointer<MobileConnectionWizard> wizard = new MobileConnectionWizard(NetworkManager::ConnectionSettings::Unknown, this); | 268 | QPointer<MobileConnectionWizard> wizard = new MobileConnectionWizard(NetworkManager::ConnectionSettings::Unknown, this); | ||
266 | connect(wizard.data(), &MobileConnectionWizard::accepted, | 269 | connect(wizard.data(), &MobileConnectionWizard::accepted, | ||
267 | [wizard, this] () { | 270 | [wizard, this] () { | ||
268 | if (wizard->getError() == MobileProviders::Success) { | 271 | if (wizard->getError() == MobileProviders::Success) { | ||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | 332 | if (type == NetworkManager::ConnectionSettings::Wireless) { | |||
344 | } | 347 | } | ||
345 | } | 348 | } | ||
346 | 349 | | |||
347 | NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast<NetworkManager::Ipv4Setting>(); | 350 | NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast<NetworkManager::Ipv4Setting>(); | ||
348 | ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Shared); | 351 | ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Shared); | ||
349 | connectionSettings->setAutoconnect(false); | 352 | connectionSettings->setAutoconnect(false); | ||
350 | } | 353 | } | ||
351 | } | 354 | } | ||
355 | if (type == NetworkManager::ConnectionSettings::WireGuard) { | ||||
356 | NetworkManager::WireGuardSetting::Ptr wireguardSetting = connectionSettings->setting(NetworkManager::Setting::WireGuard).dynamicCast<NetworkManager::WireGuardSetting>(); | ||||
357 | NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast<NetworkManager::Ipv4Setting>(); | ||||
358 | NetworkManager::Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast<NetworkManager::Ipv6Setting>(); | ||||
359 | connectionSettings->setAutoconnect(false); | ||||
360 | ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Disabled); | ||||
361 | ipv6Setting->setMethod(NetworkManager::Ipv6Setting::Ignored); | ||||
362 | } | ||||
352 | // Generate new UUID | 363 | // Generate new UUID | ||
353 | connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); | 364 | connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); | ||
354 | addConnection(connectionSettings); | 365 | addConnection(connectionSettings); | ||
355 | } | 366 | } | ||
356 | } | 367 | } | ||
357 | 368 | | |||
358 | void KCMNetworkmanagement::onRequestExportConnection(const QString &connectionPath) | 369 | void KCMNetworkmanagement::onRequestExportConnection(const QString &connectionPath) | ||
359 | { | 370 | { | ||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Line(s) | 494 | { | |||
496 | 507 | | |||
497 | if (!filename.isEmpty()) { | 508 | if (!filename.isEmpty()) { | ||
498 | const KService::List services = KServiceTypeTrader::self()->query("PlasmaNetworkManagement/VpnUiPlugin"); | 509 | const KService::List services = KServiceTypeTrader::self()->query("PlasmaNetworkManagement/VpnUiPlugin"); | ||
499 | 510 | | |||
500 | QFileInfo fi(filename); | 511 | QFileInfo fi(filename); | ||
501 | const QString ext = QStringLiteral("*.") % fi.suffix(); | 512 | const QString ext = QStringLiteral("*.") % fi.suffix(); | ||
502 | qCDebug(PLASMA_NM) << "Importing VPN connection " << filename << "extension:" << ext; | 513 | qCDebug(PLASMA_NM) << "Importing VPN connection " << filename << "extension:" << ext; | ||
503 | 514 | | |||
515 | // Handle WireGuard separately because it is different than all the other VPNs | ||||
516 | if (WireGuardInterfaceWidget::supportedFileExtensions().contains(ext)) { | ||||
517 | NMVariantMapMap connection = WireGuardInterfaceWidget::importConnectionSettings(filename); | ||||
518 | NetworkManager::ConnectionSettings connectionSettings; | ||||
519 | connectionSettings.fromMap(connection); | ||||
520 | connectionSettings.setUuid(NetworkManager::ConnectionSettings::createNewUuid()); | ||||
521 | | ||||
522 | // qCDebug(PLASMA_NM) << "Converted connection:" << connectionSettings; | ||||
523 | | ||||
524 | m_handler->addConnection(connectionSettings.toMap()); | ||||
525 | // qCDebug(PLASMA_NM) << "Adding imported connection under id:" << conId; | ||||
526 | | ||||
527 | if (connection.isEmpty()) { // the "positive" part will arrive with connectionAdded | ||||
jgrulich: ```
if (!connection.isEmpty()) {
return;
}
``` | |||||
528 | // TODO display success | ||||
529 | } else { | ||||
530 | return; // get out if the import produced at least some output | ||||
531 | } | ||||
532 | } | ||||
504 | for (const KService::Ptr &service : services) { | 533 | for (const KService::Ptr &service : services) { | ||
505 | VpnUiPlugin * vpnPlugin = service->createInstance<VpnUiPlugin>(this); | 534 | VpnUiPlugin * vpnPlugin = service->createInstance<VpnUiPlugin>(this); | ||
506 | if (vpnPlugin && vpnPlugin->supportedFileExtensions().contains(ext)) { | 535 | if (vpnPlugin && vpnPlugin->supportedFileExtensions().contains(ext)) { | ||
507 | qCDebug(PLASMA_NM) << "Found VPN plugin" << service->name() << ", type:" << service->property("X-NetworkManager-Services", QVariant::String).toString(); | 536 | qCDebug(PLASMA_NM) << "Found VPN plugin" << service->name() << ", type:" << service->property("X-NetworkManager-Services", QVariant::String).toString(); | ||
508 | 537 | | |||
509 | NMVariantMapMap connection = vpnPlugin->importConnectionSettings(filename); | 538 | NMVariantMapMap connection = vpnPlugin->importConnectionSettings(filename); | ||
510 | 539 | | |||
511 | // qCDebug(PLASMA_NM) << "Raw connection:" << connection; | 540 | // qCDebug(PLASMA_NM) << "Raw connection:" << connection; | ||
Show All 38 Lines |
Please remove.