File indexing completed on 2024-07-14 05:24:11

0001 /*
0002     SPDX-FileCopyrightText: 2013-2016 Jan Grulich <jgrulich@redhat.com>
0003     SPDX-FileCopyrightText: 2013, 2014 Lukas Tinkl <ltinkl@redhat.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include "connectioneditorbase.h"
0009 
0010 #include "plasma_nm_editor.h"
0011 #include "settings/bondwidget.h"
0012 #include "settings/bridgewidget.h"
0013 #include "settings/btwidget.h"
0014 #include "settings/cdmawidget.h"
0015 #include "settings/connectionwidget.h"
0016 #include "settings/gsmwidget.h"
0017 #include "settings/infinibandwidget.h"
0018 #include "settings/ipv4widget.h"
0019 #include "settings/ipv6widget.h"
0020 #include "settings/pppoewidget.h"
0021 #include "settings/pppwidget.h"
0022 #include "settings/teamwidget.h"
0023 #include "settings/vlanwidget.h"
0024 #include "settings/wificonnectionwidget.h"
0025 #include "settings/wifisecurity.h"
0026 #include "settings/wiredconnectionwidget.h"
0027 #include "settings/wiredsecurity.h"
0028 #include "settings/wireguardinterfacewidget.h"
0029 #include "uiutils.h"
0030 #include "vpnuiplugin.h"
0031 
0032 #include <NetworkManagerQt/ActiveConnection>
0033 #include <NetworkManagerQt/AdslSetting>
0034 #include <NetworkManagerQt/CdmaSetting>
0035 #include <NetworkManagerQt/Connection>
0036 #include <NetworkManagerQt/GenericTypes>
0037 #include <NetworkManagerQt/GsmSetting>
0038 #include <NetworkManagerQt/PppoeSetting>
0039 #include <NetworkManagerQt/Settings>
0040 #include <NetworkManagerQt/Utils>
0041 #include <NetworkManagerQt/VpnSetting>
0042 #include <NetworkManagerQt/WirelessDevice>
0043 #include <NetworkManagerQt/WirelessSecuritySetting>
0044 #include <NetworkManagerQt/WirelessSetting>
0045 
0046 #include <KLocalizedString>
0047 #include <KNotification>
0048 #include <KUser>
0049 
0050 ConnectionEditorBase::ConnectionEditorBase(const NetworkManager::ConnectionSettings::Ptr &connection, QWidget *parent, Qt::WindowFlags f)
0051     : QWidget(parent, f)
0052     , m_initialized(false)
0053     , m_valid(false)
0054     , m_pendingReplies(0)
0055     , m_connection(connection)
0056 {
0057 }
0058 
0059 ConnectionEditorBase::ConnectionEditorBase(QWidget *parent, Qt::WindowFlags f)
0060     : QWidget(parent, f)
0061 {
0062 }
0063 
0064 ConnectionEditorBase::~ConnectionEditorBase()
0065 {
0066     m_connection.clear();
0067 }
0068 
0069 void ConnectionEditorBase::setConnection(const NetworkManager::ConnectionSettings::Ptr &connection)
0070 {
0071     // Set connection settings
0072     m_connection.clear();
0073     m_connection = connection;
0074     m_initialized = false;
0075     m_wifiSecurity = nullptr;
0076 
0077     // Reset UI setting widgets
0078     delete m_connectionWidget;
0079     m_connectionWidget = nullptr;
0080     qDeleteAll(m_settingWidgets);
0081     m_settingWidgets.clear();
0082 
0083     initialize();
0084 }
0085 
0086 NMVariantMapMap ConnectionEditorBase::setting() const
0087 {
0088     NMVariantMapMap settings = m_connectionWidget->setting();
0089 
0090     for (SettingWidget *widget : m_settingWidgets) {
0091         const QString type = widget->type();
0092         if (type != NetworkManager::Setting::typeAsString(NetworkManager::Setting::Security8021x)
0093             && type != NetworkManager::Setting::typeAsString(NetworkManager::Setting::WirelessSecurity)) {
0094             settings.insert(type, widget->setting());
0095         }
0096 
0097         // add 802.1x security if needed
0098         QVariantMap security8021x;
0099         if (type == NetworkManager::Setting::typeAsString(NetworkManager::Setting::WirelessSecurity)) {
0100             auto wifiSecurity = static_cast<WifiSecurity *>(widget);
0101             if (wifiSecurity->enabled()) {
0102                 settings.insert(type, wifiSecurity->setting());
0103             }
0104             if (wifiSecurity->enabled8021x()) {
0105                 security8021x = static_cast<WifiSecurity *>(widget)->setting8021x();
0106                 settings.insert(NetworkManager::Setting::typeAsString(NetworkManager::Setting::Security8021x), security8021x);
0107             }
0108         } else if (type == NetworkManager::Setting::typeAsString(NetworkManager::Setting::Security8021x)) {
0109             auto wiredSecurity = static_cast<WiredSecurity *>(widget);
0110             if (wiredSecurity->enabled8021x()) {
0111                 security8021x = static_cast<WiredSecurity *>(widget)->setting();
0112                 settings.insert(NetworkManager::Setting::typeAsString(NetworkManager::Setting::Security8021x), security8021x);
0113             }
0114         }
0115     }
0116 
0117     // Set properties which are not returned from setting widgets
0118     NetworkManager::ConnectionSettings::Ptr connectionSettings =
0119         NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(m_connection->connectionType()));
0120 
0121     connectionSettings->fromMap(settings);
0122     connectionSettings->setId(connectionName());
0123     if (connectionSettings->connectionType() == NetworkManager::ConnectionSettings::WireGuard)
0124         connectionSettings->setInterfaceName(connectionName());
0125     connectionSettings->setUuid(m_connection->uuid());
0126 
0127     if (connectionSettings->connectionType() == NetworkManager::ConnectionSettings::Wireless) {
0128         NetworkManager::WirelessSecuritySetting::Ptr securitySetting =
0129             connectionSettings->setting(NetworkManager::Setting::WirelessSecurity).staticCast<NetworkManager::WirelessSecuritySetting>();
0130         NetworkManager::WirelessSetting::Ptr wirelessSetting =
0131             connectionSettings->setting(NetworkManager::Setting::Wireless).staticCast<NetworkManager::WirelessSetting>();
0132 
0133         if (securitySetting && wirelessSetting) {
0134             if (securitySetting->keyMgmt() != NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting::Unknown) {
0135                 wirelessSetting->setSecurity(QStringLiteral("802-11-wireless-security"));
0136             }
0137 
0138             if (securitySetting->keyMgmt() == NetworkManager::WirelessSecuritySetting::SAE
0139                 && wirelessSetting->mode() == NetworkManager::WirelessSetting::Adhoc) {
0140                 // Ad-Hoc settings as specified by the supplicant
0141                 // Proto
0142                 QList<NetworkManager::WirelessSecuritySetting::WpaProtocolVersion> protoVersions = securitySetting->proto();
0143                 protoVersions << NetworkManager::WirelessSecuritySetting::Rsn;
0144                 securitySetting->setProto(protoVersions);
0145                 // Pairwise
0146                 QList<NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities> pairwiseEncrypts = securitySetting->pairwise();
0147                 pairwiseEncrypts << NetworkManager::WirelessSecuritySetting::Ccmp;
0148                 securitySetting->setPairwise(pairwiseEncrypts);
0149                 // Group
0150                 QList<NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities> groupEncrypts = securitySetting->group();
0151                 groupEncrypts << NetworkManager::WirelessSecuritySetting::Ccmp;
0152                 securitySetting->setGroup(groupEncrypts);
0153             }
0154         }
0155     }
0156     return connectionSettings->toMap();
0157 }
0158 
0159 bool ConnectionEditorBase::isInitialized() const
0160 {
0161     return m_initialized;
0162 }
0163 
0164 bool ConnectionEditorBase::isValid() const
0165 {
0166     return m_valid;
0167 }
0168 
0169 void ConnectionEditorBase::addConnectionWidget(ConnectionWidget *widget, const QString &text)
0170 {
0171     m_connectionWidget = widget;
0172 
0173     connect(widget, &ConnectionWidget::settingChanged, this, &ConnectionEditorBase::settingChanged);
0174 
0175     addWidget(widget, text);
0176 }
0177 
0178 void ConnectionEditorBase::addSettingWidget(SettingWidget *widget, const QString &text)
0179 {
0180     m_settingWidgets << widget;
0181 
0182     connect(widget, &SettingWidget::settingChanged, this, &ConnectionEditorBase::settingChanged);
0183 
0184     addWidget(widget, text);
0185 }
0186 
0187 void ConnectionEditorBase::initialize()
0188 {
0189     const bool emptyConnection = m_connection->id().isEmpty();
0190     const NetworkManager::ConnectionSettings::ConnectionType type = m_connection->connectionType();
0191 
0192     if (emptyConnection) {
0193         UiUtils::setConnectionDefaultPermissions(m_connection);
0194     }
0195 
0196     // General configuration common to all connection types
0197     auto connectionWidget = new ConnectionWidget(m_connection);
0198     addConnectionWidget(connectionWidget, i18nc("General", "General configuration"));
0199     connect(connectionWidget, &ConnectionWidget::allUsersChanged, this, &ConnectionEditorBase::onAllUsersChanged);
0200 
0201     // Add the rest of widgets
0202     QString serviceType;
0203     if (type == NetworkManager::ConnectionSettings::Wired) {
0204         auto wiredWidget = new WiredConnectionWidget(m_connection->setting(NetworkManager::Setting::Wired), this);
0205         addSettingWidget(wiredWidget, i18n("Wired"));
0206         auto wiredSecurity =
0207             new WiredSecurity(m_connection->setting(NetworkManager::Setting::Security8021x).staticCast<NetworkManager::Security8021xSetting>(), this);
0208         addSettingWidget(wiredSecurity, i18n("802.1x Security"));
0209     } else if (type == NetworkManager::ConnectionSettings::Wireless) {
0210         auto wifiWidget = new WifiConnectionWidget(m_connection->setting(NetworkManager::Setting::Wireless), this);
0211         addSettingWidget(wifiWidget, i18n("Wi-Fi"));
0212         auto wifiSecurity = new WifiSecurity(m_connection->setting(NetworkManager::Setting::WirelessSecurity),
0213                                              m_connection->setting(NetworkManager::Setting::Security8021x).staticCast<NetworkManager::Security8021xSetting>(),
0214                                              this);
0215         addSettingWidget(wifiSecurity, i18n("Wi-Fi Security"));
0216         connect(wifiWidget, QOverload<const QString &>::of(&WifiConnectionWidget::ssidChanged), wifiSecurity, &WifiSecurity::onSsidChanged);
0217         m_wifiSecurity = wifiSecurity;
0218     } else if (type == NetworkManager::ConnectionSettings::Pppoe) { // DSL
0219         auto pppoeWidget = new PppoeWidget(m_connection->setting(NetworkManager::Setting::Pppoe), this);
0220         addSettingWidget(pppoeWidget, i18n("DSL"));
0221         auto wiredWidget = new WiredConnectionWidget(m_connection->setting(NetworkManager::Setting::Wired), this);
0222         addSettingWidget(wiredWidget, i18n("Wired"));
0223     } else if (type == NetworkManager::ConnectionSettings::Gsm) { // GSM
0224         auto gsmWidget = new GsmWidget(m_connection->setting(NetworkManager::Setting::Gsm), this);
0225         addSettingWidget(gsmWidget, i18n("Mobile Broadband (%1)", m_connection->typeAsString(m_connection->connectionType())));
0226     } else if (type == NetworkManager::ConnectionSettings::Cdma) { // CDMA
0227         auto cdmaWidget = new CdmaWidget(m_connection->setting(NetworkManager::Setting::Cdma), this);
0228         addSettingWidget(cdmaWidget, i18n("Mobile Broadband (%1)", m_connection->typeAsString(m_connection->connectionType())));
0229     } else if (type == NetworkManager::ConnectionSettings::Bluetooth) { // Bluetooth
0230         auto btWidget = new BtWidget(m_connection->setting(NetworkManager::Setting::Bluetooth), this);
0231         addSettingWidget(btWidget, i18n("Bluetooth"));
0232         NetworkManager::BluetoothSetting::Ptr btSetting =
0233             m_connection->setting(NetworkManager::Setting::Bluetooth).staticCast<NetworkManager::BluetoothSetting>();
0234         if (btSetting->profileType() == NetworkManager::BluetoothSetting::Dun) {
0235             auto gsmWidget = new GsmWidget(m_connection->setting(NetworkManager::Setting::Gsm), this);
0236             addSettingWidget(gsmWidget, i18n("GSM"));
0237             auto pppWidget = new PPPWidget(m_connection->setting(NetworkManager::Setting::Ppp), this);
0238             addSettingWidget(pppWidget, i18n("PPP"));
0239         }
0240     } else if (type == NetworkManager::ConnectionSettings::Infiniband) { // Infiniband
0241         auto infinibandWidget = new InfinibandWidget(m_connection->setting(NetworkManager::Setting::Infiniband), this);
0242         addSettingWidget(infinibandWidget, i18n("Infiniband"));
0243     } else if (type == NetworkManager::ConnectionSettings::Bond) { // Bond
0244         auto bondWidget = new BondWidget(m_connection->uuid(), m_connection->id(), m_connection->setting(NetworkManager::Setting::Bond), this);
0245         addSettingWidget(bondWidget, i18n("Bond"));
0246     } else if (type == NetworkManager::ConnectionSettings::Bridge) { // Bridge
0247         auto bridgeWidget = new BridgeWidget(m_connection->uuid(), m_connection->id(), m_connection->setting(NetworkManager::Setting::Bridge), this);
0248         addSettingWidget(bridgeWidget, i18n("Bridge"));
0249     } else if (type == NetworkManager::ConnectionSettings::Vlan) { // Vlan
0250         auto vlanWidget = new VlanWidget(m_connection->setting(NetworkManager::Setting::Vlan), this);
0251         addSettingWidget(vlanWidget, i18n("Vlan"));
0252     } else if (type == NetworkManager::ConnectionSettings::Team) { // Team
0253         auto teamWidget = new TeamWidget(m_connection->uuid(), m_connection->id(), m_connection->setting(NetworkManager::Setting::Team), this);
0254         addSettingWidget(teamWidget, i18n("Team"));
0255     } else if (type == NetworkManager::ConnectionSettings::WireGuard) { // WireGuard
0256         auto wireGuardInterfaceWidget = new WireGuardInterfaceWidget(m_connection->setting(NetworkManager::Setting::WireGuard), this);
0257         addSettingWidget(wireGuardInterfaceWidget, i18n("WireGuard Interface"));
0258     } else if (type == NetworkManager::ConnectionSettings::Vpn) { // VPN
0259         NetworkManager::VpnSetting::Ptr vpnSetting = m_connection->setting(NetworkManager::Setting::Vpn).staticCast<NetworkManager::VpnSetting>();
0260         if (!vpnSetting) {
0261             qCWarning(PLASMA_NM_EDITOR_LOG) << "Missing VPN setting!";
0262         } else {
0263             serviceType = vpnSetting->serviceType();
0264 
0265             const auto result = VpnUiPlugin::loadPluginForType(this, serviceType);
0266 
0267             if (result) {
0268                 const QString shortName = serviceType.section('.', -1);
0269                 SettingWidget *vpnWidget = result.plugin->widget(vpnSetting, this);
0270                 addSettingWidget(vpnWidget, i18n("VPN (%1)", shortName));
0271             } else {
0272                 qCWarning(PLASMA_NM_EDITOR_LOG) << "Could not instantiate VPN UI plugin" << result.errorText;
0273             }
0274         }
0275     }
0276 
0277     // PPP widget
0278     if (type == NetworkManager::ConnectionSettings::Pppoe || type == NetworkManager::ConnectionSettings::Cdma
0279         || type == NetworkManager::ConnectionSettings::Gsm) {
0280         auto pppWidget = new PPPWidget(m_connection->setting(NetworkManager::Setting::Ppp), this);
0281         addSettingWidget(pppWidget, i18n("PPP"));
0282     }
0283 
0284     // IPv4 widget
0285     if (!m_connection->isSlave()) {
0286         auto ipv4Widget = new IPv4Widget(m_connection->setting(NetworkManager::Setting::Ipv4), this);
0287         addSettingWidget(ipv4Widget, i18n("IPv4"));
0288     }
0289 
0290     // IPv6 widget
0291     if ((type == NetworkManager::ConnectionSettings::Wired //
0292          || type == NetworkManager::ConnectionSettings::Wireless //
0293          || type == NetworkManager::ConnectionSettings::Infiniband //
0294          || type == NetworkManager::ConnectionSettings::Team //
0295          || type == NetworkManager::ConnectionSettings::Cdma //
0296          || type == NetworkManager::ConnectionSettings::Gsm //
0297          || type == NetworkManager::ConnectionSettings::Bond //
0298          || type == NetworkManager::ConnectionSettings::Bridge //
0299          || type == NetworkManager::ConnectionSettings::Vlan //
0300          || type == NetworkManager::ConnectionSettings::WireGuard //
0301          || (type == NetworkManager::ConnectionSettings::Vpn && serviceType == QLatin1String("org.freedesktop.NetworkManager.openvpn")))
0302         && !m_connection->isSlave()) {
0303         auto ipv6Widget = new IPv6Widget(m_connection->setting(NetworkManager::Setting::Ipv6), this);
0304         addSettingWidget(ipv6Widget, i18n("IPv6"));
0305     }
0306 
0307     // Re-check validation
0308     bool valid = true;
0309     for (SettingWidget *widget : std::as_const(m_settingWidgets)) {
0310         valid = valid && widget->isValid();
0311         connect(widget, &SettingWidget::validChanged, this, &ConnectionEditorBase::validChanged);
0312     }
0313 
0314     m_valid = valid;
0315     Q_EMIT validityChanged(valid);
0316 
0317     KAcceleratorManager::manage(this);
0318 
0319     // If the connection is not empty (not new) we want to load its secrets
0320     if (!emptyConnection) {
0321         NetworkManager::Connection::Ptr connection = NetworkManager::findConnectionByUuid(m_connection->uuid());
0322         if (connection) {
0323             QStringList requiredSecrets;
0324             QString settingName;
0325             QVariantMap setting;
0326             QDBusPendingReply<NMVariantMapMap> reply;
0327 
0328             if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Adsl) {
0329                 NetworkManager::AdslSetting::Ptr adslSetting =
0330                     connection->settings()->setting(NetworkManager::Setting::Adsl).staticCast<NetworkManager::AdslSetting>();
0331                 if (adslSetting && !adslSetting->needSecrets().isEmpty()) {
0332                     requiredSecrets = adslSetting->needSecrets();
0333                     setting = adslSetting->toMap();
0334                     settingName = QStringLiteral("adsl");
0335                 }
0336             } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Bluetooth) {
0337                 NetworkManager::GsmSetting::Ptr gsmSetting =
0338                     connection->settings()->setting(NetworkManager::Setting::Gsm).staticCast<NetworkManager::GsmSetting>();
0339                 if (gsmSetting && !gsmSetting->needSecrets().isEmpty()) {
0340                     requiredSecrets = gsmSetting->needSecrets();
0341                     setting = gsmSetting->toMap();
0342                     settingName = QStringLiteral("gsm");
0343                 }
0344             } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Cdma) {
0345                 NetworkManager::CdmaSetting::Ptr cdmaSetting =
0346                     connection->settings()->setting(NetworkManager::Setting::Cdma).staticCast<NetworkManager::CdmaSetting>();
0347                 if (cdmaSetting && !cdmaSetting->needSecrets().isEmpty()) {
0348                     requiredSecrets = cdmaSetting->needSecrets();
0349                     setting = cdmaSetting->toMap();
0350                     settingName = QStringLiteral("cdma");
0351                 }
0352             } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Gsm) {
0353                 NetworkManager::GsmSetting::Ptr gsmSetting =
0354                     connection->settings()->setting(NetworkManager::Setting::Gsm).staticCast<NetworkManager::GsmSetting>();
0355                 if (gsmSetting && !gsmSetting->needSecrets().isEmpty()) {
0356                     requiredSecrets = gsmSetting->needSecrets();
0357                     setting = gsmSetting->toMap();
0358                     settingName = QStringLiteral("gsm");
0359                 }
0360             } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Pppoe) {
0361                 NetworkManager::PppoeSetting::Ptr pppoeSetting =
0362                     connection->settings()->setting(NetworkManager::Setting::Pppoe).staticCast<NetworkManager::PppoeSetting>();
0363                 if (pppoeSetting && !pppoeSetting->needSecrets().isEmpty()) {
0364                     requiredSecrets = pppoeSetting->needSecrets();
0365                     setting = pppoeSetting->toMap();
0366                     settingName = QStringLiteral("pppoe");
0367                 }
0368             } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Wired) {
0369                 NetworkManager::Security8021xSetting::Ptr securitySetting =
0370                     connection->settings()->setting(NetworkManager::Setting::Security8021x).staticCast<NetworkManager::Security8021xSetting>();
0371                 if (securitySetting && !securitySetting->needSecrets().isEmpty()) {
0372                     requiredSecrets = securitySetting->needSecrets();
0373                     setting = securitySetting->toMap();
0374                     settingName = QStringLiteral("802-1x");
0375                 }
0376             } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::WireGuard) {
0377                 NetworkManager::WireGuardSetting::Ptr securitySetting =
0378                     connection->settings()->setting(NetworkManager::Setting::WireGuard).staticCast<NetworkManager::WireGuardSetting>();
0379                 if (securitySetting && !securitySetting->needSecrets().isEmpty()) {
0380                     requiredSecrets = securitySetting->needSecrets();
0381                     setting = securitySetting->toMap();
0382                     settingName = QStringLiteral("wireguard");
0383                 }
0384             } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Wireless) {
0385                 NetworkManager::WirelessSecuritySetting::Ptr wifiSecuritySetting =
0386                     connection->settings()->setting(NetworkManager::Setting::WirelessSecurity).staticCast<NetworkManager::WirelessSecuritySetting>();
0387                 if (wifiSecuritySetting
0388                     && (wifiSecuritySetting->keyMgmt() == NetworkManager::WirelessSecuritySetting::WpaEap
0389                         || wifiSecuritySetting->keyMgmt() == NetworkManager::WirelessSecuritySetting::WpaEapSuiteB192
0390                         || (wifiSecuritySetting->keyMgmt() == NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting::Ieee8021x
0391                             && wifiSecuritySetting->authAlg() != NetworkManager::WirelessSecuritySetting::Leap))) {
0392                     NetworkManager::Security8021xSetting::Ptr securitySetting =
0393                         connection->settings()->setting(NetworkManager::Setting::Security8021x).staticCast<NetworkManager::Security8021xSetting>();
0394                     if (securitySetting && !securitySetting->needSecrets().isEmpty()) {
0395                         requiredSecrets = securitySetting->needSecrets();
0396                         setting = securitySetting->toMap();
0397                         settingName = QStringLiteral("802-1x");
0398 
0399                         if (requiredSecrets.contains(NM_SETTING_802_1X_PASSWORD_RAW)) {
0400                             requiredSecrets.removeAll(NM_SETTING_802_1X_PASSWORD_RAW);
0401                         }
0402                     }
0403                 } else {
0404                     if (!wifiSecuritySetting->needSecrets().isEmpty()) {
0405                         requiredSecrets = wifiSecuritySetting->needSecrets();
0406                         setting = wifiSecuritySetting->toMap();
0407                         settingName = QStringLiteral("802-11-wireless-security");
0408                     }
0409                 }
0410             } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Vpn) {
0411                 settingName = QStringLiteral("vpn");
0412             }
0413 
0414             if (!requiredSecrets.isEmpty() || m_connection->connectionType() == NetworkManager::ConnectionSettings::Vpn) {
0415                 bool requestSecrets = false;
0416                 if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Vpn) {
0417                     NetworkManager::VpnSetting::Ptr vpnSetting =
0418                         connection->settings()->setting(NetworkManager::Setting::Vpn).staticCast<NetworkManager::VpnSetting>();
0419                     for (const QString &key : vpnSetting->data().keys()) {
0420                         if (key.endsWith(QStringLiteral("-flags"))) {
0421                             NetworkManager::Setting::SecretFlagType secretFlag = (NetworkManager::Setting::SecretFlagType)vpnSetting->data().value(key).toInt();
0422                             if (secretFlag == NetworkManager::Setting::None || secretFlag == NetworkManager::Setting::AgentOwned) {
0423                                 requestSecrets = true;
0424                             }
0425                         }
0426                     }
0427                 } else {
0428                     for (const QString &secret : std::as_const(requiredSecrets)) {
0429                         if (setting.contains(secret + QLatin1String("-flags"))) {
0430                             NetworkManager::Setting::SecretFlagType secretFlag =
0431                                 (NetworkManager::Setting::SecretFlagType)setting.value(secret + QLatin1String("-flags")).toInt();
0432                             if (secretFlag == NetworkManager::Setting::None || secretFlag == NetworkManager::Setting::AgentOwned) {
0433                                 requestSecrets = true;
0434                             }
0435                         } else {
0436                             requestSecrets = true;
0437                         }
0438                     }
0439                 }
0440 
0441                 if (requestSecrets) {
0442                     m_pendingReplies++;
0443                     reply = connection->secrets(settingName);
0444                     auto watcher = new QDBusPendingCallWatcher(reply, this);
0445                     watcher->setProperty("connection", connection->name());
0446                     watcher->setProperty("settingName", settingName);
0447                     connect(watcher, &QDBusPendingCallWatcher::finished, this, &ConnectionEditorBase::replyFinished);
0448                     m_valid = false;
0449                     Q_EMIT validityChanged(false);
0450                     return;
0451                 }
0452             }
0453         }
0454     }
0455 
0456     // We should be now fully initialized as we don't wait for secrets
0457     if (m_pendingReplies == 0) {
0458         m_initialized = true;
0459     }
0460 }
0461 
0462 void ConnectionEditorBase::replyFinished(QDBusPendingCallWatcher *watcher)
0463 {
0464     QDBusPendingReply<NMVariantMapMap> reply = *watcher;
0465     const QString settingName = watcher->property("settingName").toString();
0466     if (reply.isValid()) {
0467         NMVariantMapMap secrets = reply.argumentAt<0>();
0468         for (const QString &key : secrets.keys()) {
0469             if (key == settingName) {
0470                 NetworkManager::Setting::Ptr setting = m_connection->setting(NetworkManager::Setting::typeFromString(key));
0471                 if (setting) {
0472                     setting->secretsFromMap(secrets.value(key));
0473                     for (SettingWidget *widget : std::as_const(m_settingWidgets)) {
0474                         const QString type = widget->type();
0475                         if (type == settingName
0476                             || (settingName == NetworkManager::Setting::typeAsString(NetworkManager::Setting::Security8021x)
0477                                 && type == NetworkManager::Setting::typeAsString(NetworkManager::Setting::WirelessSecurity))) {
0478                             widget->loadSecrets(setting);
0479                         }
0480                     }
0481                 }
0482             }
0483         }
0484     } else {
0485         auto notification = new KNotification(QStringLiteral("FailedToGetSecrets"), KNotification::CloseOnTimeout);
0486         notification->setComponentName(QStringLiteral("networkmanagement"));
0487         notification->setTitle(i18n("Failed to get secrets for %1", watcher->property("connection").toString()));
0488         notification->setText(reply.error().message());
0489         notification->setIconName(QStringLiteral("dialog-warning"));
0490         notification->sendEvent();
0491     }
0492 
0493     watcher->deleteLater();
0494     validChanged(true);
0495 
0496     // We should be now fully with secrets
0497     m_pendingReplies--;
0498     m_initialized = true;
0499 }
0500 
0501 void ConnectionEditorBase::validChanged(bool valid)
0502 {
0503     if (!valid) {
0504         m_valid = false;
0505         Q_EMIT validityChanged(false);
0506         return;
0507     } else {
0508         for (SettingWidget *widget : std::as_const(m_settingWidgets)) {
0509             if (!widget->isValid()) {
0510                 m_valid = false;
0511                 Q_EMIT validityChanged(false);
0512                 return;
0513             }
0514         }
0515     }
0516 
0517     m_valid = true;
0518     Q_EMIT validityChanged(true);
0519 }
0520 
0521 void ConnectionEditorBase::onAllUsersChanged()
0522 {
0523     if (!m_wifiSecurity) {
0524         return;
0525     }
0526 
0527     auto allUsers = m_connectionWidget->allUsers();
0528     m_wifiSecurity->setStoreSecretsSystemWide(allUsers);
0529 }
0530 
0531 #include "moc_connectioneditorbase.cpp"