diff --git a/kcm/package/contents/ui/editor/ConnectionEditor.qml b/kcm/package/contents/ui/editor/ConnectionEditor.qml index b934126f..afd9588e 100644 --- a/kcm/package/contents/ui/editor/ConnectionEditor.qml +++ b/kcm/package/contents/ui/editor/ConnectionEditor.qml @@ -1,160 +1,177 @@ /* Copyright 2018 Jan Grulich 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 . */ import QtQuick 2.6 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.2 as QtControls import org.kde.kirigami 2.0 as Kirigami +import org.kde.plasma.networkmanagement 0.2 as PlasmaNM Kirigami.ScrollablePage { id: connectionEditorPage title: connectionNameTextField.text + PlasmaNM.Utils { + id: nmUtils + } + header: MouseArea { width: connectionEditorPage.width height: Math.round(Kirigami.Units.gridUnit * 2.5) enabled: !applicationWindow().wideScreen Accessible.role: Accessible.Button Accessible.name: i18n("Back") onClicked: { root.pageStack.currentIndex = 0 } Item { id: headerControls anchors.fill: parent QtControls.ToolButton { id: backButton anchors.fill: parent anchors.margins: Kirigami.Units.smallSpacing visible: !applicationWindow().wideScreen onClicked: { root.pageStack.currentIndex = 0 } RowLayout { anchors.fill: parent Kirigami.Icon { id: toolButtonIcon Layout.alignment: Qt.AlignVCenter Layout.preferredHeight: Kirigami.Units.iconSizes.small Layout.preferredWidth: Layout.preferredHeight source: LayoutMirroring.enabled ? "go-next" : "go-previous" } QtControls.Label { Layout.fillWidth: true Layout.fillHeight: true height: toolButtonIcon.height text: connectionEditorPage.title verticalAlignment: Text.AlignVCenter elide: Text.ElideRight //FIXME: QtControls bug, why? Component.onCompleted: { font.bold = true } } } } QtControls.Label { anchors.verticalCenter: parent.verticalCenter x: y text: connectionEditorPage.title elide: Text.ElideRight visible: !backButton.visible opacity: 0.3 //FIXME: QtControls bug, why? Component.onCompleted: { font.bold = true } } } Kirigami.Separator { anchors { left: parent.left right: parent.right top: parent.bottom } visible: !connectionEditorPage.atYBeginning } } ColumnLayout { width: connectionEditorPage.width QtControls.TextField { id: connectionNameTextField Layout.fillWidth: true hoverEnabled: true } QtControls.TabBar { id: tabBar Layout.fillWidth: true QtControls.TabButton { - text: i18n("Connection") + text: connectionSetting.settingName } // FIXME just placeholders for now QtControls.TabButton { - text: i18n("Wireless") + text: connectionSpecificSetting.item.settingName } QtControls.TabButton { text: i18n("IP") } } StackLayout { Layout.fillWidth: true currentIndex: tabBar.currentIndex ConnectionSetting { id: connectionSetting } + + Loader { + id: connectionSpecificSetting + } } } function loadConnectionSettings() { connectionNameTextField.text = connectionSettingsObject.id // Load general connection setting connectionSetting.loadSettings() + + // Load connection specific setting + if (connectionSettingsObject.connectionType == PlasmaNM.Enums.Wired) { + connectionSpecificSetting.source = "WiredSetting.qml" + } else if (connectionSettingsObject.connectionType == PlasmaNM.Enums.Wireless) { + connectionSpecificSetting.source = "WirelessSetting.qml" + } + connectionSpecificSetting.item.loadSettings() } } diff --git a/kcm/package/contents/ui/editor/ConnectionSetting.qml b/kcm/package/contents/ui/editor/ConnectionSetting.qml index 76e4083b..1752c917 100644 --- a/kcm/package/contents/ui/editor/ConnectionSetting.qml +++ b/kcm/package/contents/ui/editor/ConnectionSetting.qml @@ -1,150 +1,148 @@ /* Copyright 2018 Jan Grulich 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 . */ import QtQuick 2.6 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.2 as QtControls import org.kde.kirigami 2.0 // for units import org.kde.plasma.networkmanagement 0.2 as PlasmaNM ColumnLayout { id: connectionSetting + property string settingName: i18n("Connection") + spacing: Math.round(Units.gridUnit / 2) QtControls.CheckBox { id: autoconnectCheckbox checked: true Layout.fillWidth: true text: i18n("Automatically connect to this network when it is available") } RowLayout { Layout.fillWidth: true QtControls.CheckBox { id: allUsersAllowedCheckbox Layout.fillWidth: true text: i18n("All users may connect to this network") } QtControls.Button { id: advancedPermissionsButton Layout.alignment: Qt.AlignRight enabled: !allUsersAllowedCheckbox.checked text: i18n("Advanced...") QtControls.ToolTip.text: i18n("Edit advanced permissions for this connection") QtControls.ToolTip.visible: advancedPermissionsButton.hovered } } QtControls.CheckBox { id: autoconnectVpnCheckbox Layout.fillWidth: true text: i18n("Automatically connect to VPN when using this connection") } QtControls.ComboBox { id: vpnListCombobox Layout.fillWidth: true enabled: autoconnectVpnCheckbox.checked - model: connectionSettingsObject.vpnConnections + model: nmUtils.vpnConnections() } - RowLayout { - ColumnLayout { - QtControls.Label { - Layout.fillHeight: true - Layout.alignment: Qt.AlignRight + GridLayout { + columns: 2 - text: i18n("Firewall zone:") - } + QtControls.Label { + Layout.alignment: Qt.AlignRight + + text: i18n("Firewall zone:") + } - QtControls.Label { - Layout.fillHeight: true - Layout.alignment: Qt.AlignRight + QtControls.ComboBox { + id: firewallZoneCombobox - text: i18n("Priority:") - } + model: nmUtils.firewallZones() + Layout.fillWidth: true } - ColumnLayout { - QtControls.ComboBox { - id: firewallZoneCombobox + QtControls.Label { + Layout.alignment: Qt.AlignRight - model: connectionSettingsObject.firewallZones - Layout.fillWidth: true - } + text: i18n("Priority:") + } - QtControls.SpinBox { - id: prioritySpinBox + QtControls.SpinBox { + id: prioritySpinBox - Layout.fillWidth: true + Layout.fillWidth: true - value: 0 + value: 0 - QtControls.ToolTip.text: i18n("If the connection is set to autoconnect, connections with higher priority will be preferred.\nDefaults to 0. The higher number means higher priority. An negative number can be used to \nindicate priority lower than the default.") - QtControls.ToolTip.visible: prioritySpinBox.hovered - } + QtControls.ToolTip.text: i18n("If the connection is set to autoconnect, connections with higher priority will be preferred.\nDefaults to 0. The higher number means higher priority. An negative number can be used to \nindicate priority lower than the default.") + QtControls.ToolTip.visible: prioritySpinBox.hovered } } function loadSettings() { if (connectionSettingsObject.connectionType == PlasmaNM.Enums.Vpn) { autoconnectCheckbox.enabled = false autoconnectVpnCheckbox.enabled = false prioritySpinBox.enabled = false } else { autoconnectCheckbox.enabled = true autoconnectVpnCheckbox.enabled = true prioritySpinBox.enabled = true } autoconnectCheckbox.checked = connectionSettingsObject.autoconnect allUsersAllowedCheckbox.checked = !connectionSettingsObject.permissions.length prioritySpinBox.value = connectionSettingsObject.priority if (connectionSettingsObject.zone.length) { firewallZoneCombobox.currentIndex = firewallZoneCombobox.find(connectionSettingsObject.zone) } else { firewallZoneCombobox.currentIndex = 0 // Default } if (connectionSettingsObject.secondaryConnection.length && connectionSettingsObject.vpnConnections.length) { autoconnectVpnCheckbox.checked = true vpnListCombobox.currentIndex = vpnListCombobox.find(connectionSettingsObject.secondaryConnection) } else { autoconnectVpnCheckbox.checked = false } } } diff --git a/libs/declarative/CMakeLists.txt b/libs/declarative/CMakeLists.txt index b285a85f..fb3c997d 100644 --- a/libs/declarative/CMakeLists.txt +++ b/libs/declarative/CMakeLists.txt @@ -1,37 +1,38 @@ include_directories(models) set(plasmanm_qml_plugins_SRCS # FIXME ../debug.cpp availabledevices.cpp connectionicon.cpp enabledconnections.cpp enums.cpp networkstatus.cpp + utils.cpp qmlplugins.cpp models/appletproxymodel.cpp models/creatableconnectionsmodel.cpp models/editorproxymodel.cpp models/kcmidentitymodel.cpp models/networkitemslist.cpp models/networkmodel.cpp models/networkmodelitem.cpp ) add_library(plasmanm_qmlplugins SHARED ${plasmanm_qml_plugins_SRCS}) target_link_libraries(plasmanm_qmlplugins plasmanm_internal Qt5::Quick KF5::NetworkManagerQt KF5::I18n ) if (WITH_MODEMMANAGER_SUPPORT) target_link_libraries(plasmanm_qmlplugins KF5::ModemManagerQt) endif() install(TARGETS plasmanm_qmlplugins DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/networkmanagement) install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/networkmanagement) diff --git a/libs/declarative/qmlplugins.cpp b/libs/declarative/qmlplugins.cpp index 15f18d86..491c9889 100644 --- a/libs/declarative/qmlplugins.cpp +++ b/libs/declarative/qmlplugins.cpp @@ -1,69 +1,73 @@ /* Copyright 2013 Jan Grulich 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 . */ #include "qmlplugins.h" #include #include "availabledevices.h" #include "connectionicon.h" #include "enabledconnections.h" #include "networkstatus.h" #include "appletproxymodel.h" #include "configuration.h" #include "creatableconnectionsmodel.h" #include "editorproxymodel.h" #include "kcmidentitymodel.h" #include "networkmodel.h" #include "mobileproxymodel.h" +#include "utils.h" + #include "handler.h" #include "enums.h" void QmlPlugins::registerTypes(const char* uri) { // @uri org.kde.plasma.networkmanagement.AvailableDevices qmlRegisterType(uri, 0, 2, "AvailableDevices"); // @uri org.kde.plasma.networkmanagement.ConnectionIcon qmlRegisterType(uri, 0, 2, "ConnectionIcon"); // @uri org.kde.plasma.networkmanagement.Configuration qmlRegisterType(uri, 0, 2, "Configuration"); // @uri org.kde.plasma.networkmanagement.EnabledConnections qmlRegisterType(uri, 0, 2, "EnabledConnections"); // @uri org.kde.plasma.networkmanagement.Enums qmlRegisterUncreatableType(uri, 0, 2, "Enums", "You cannot create Enums on yourself"); // @uri org.kde.plasma.networkmanagement.NetworkStatus qmlRegisterType(uri, 0, 2, "NetworkStatus"); // @uri org.kde.plasma.networkmanagement.Handler qmlRegisterType(uri, 0, 2, "Handler"); // @uri org.kde.plasma.networkmanagement.NetworkModel qmlRegisterType(uri, 0, 2, "NetworkModel"); // @uri org.kde.plasma.networkmanagement.AppletProxyModel qmlRegisterType(uri, 0, 2, "AppletProxyModel"); // @uri org.kde.plasma.networkmanagement.EditorProxyModel qmlRegisterType(uri, 0, 2, "EditorProxyModel"); // @uri org.kde.plasma.networkmanagement.KcmIdentityModel qmlRegisterType(uri, 0, 2, "KcmIdentityModel"); // @uri org.kde.plasma.networkmanagement.CreatableConnectionsModel qmlRegisterType(uri, 0, 2, "CreatableConnectionsModel"); // @uri org.kde.plasma.networkmanagement.MobileProxyModel qmlRegisterType(uri, 0, 2, "MobileProxyModel"); + // @uri org.kde.plasma.networkmanagement.Utils + qmlRegisterType(uri, 0, 2, "Utils"); } diff --git a/libs/declarative/utils.cpp b/libs/declarative/utils.cpp new file mode 100644 index 00000000..8fb8f9ba --- /dev/null +++ b/libs/declarative/utils.cpp @@ -0,0 +1,275 @@ +/* + Copyright 2018 Jan Grulich + + 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 . +*/ + +#include "utils.h" +#include "uiutils.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +Utils::Utils(QObject *parent) + : QObject(parent) +{ +} + +Utils::~Utils() +{ +} + +QVariantList Utils::availableSsids(const QString &ssid) +{ + QVariantList list; + QList devices; + QList networks; + + foreach (const NetworkManager::Device::Ptr &device, NetworkManager::networkInterfaces()) { + if (device->type() == NetworkManager::Device::Wifi) { + NetworkManager::WirelessDevice::Ptr wifiDevice = device.objectCast(); + + devices << wifiDevice; + + foreach (const NetworkManager::WirelessNetwork::Ptr &newNetwork, wifiDevice->networks()) { + foreach (const NetworkManager::WirelessNetwork::Ptr &existingNetwork, networks) { + if (newNetwork->ssid() == existingNetwork->ssid() && + newNetwork->signalStrength() > existingNetwork->signalStrength()) { + networks.removeOne(existingNetwork); + break; + } + } + + networks << newNetwork; + } + } + } + + std::sort(networks.begin(), networks.end(), [] (const NetworkManager::WirelessNetwork::Ptr &one, const NetworkManager::WirelessNetwork::Ptr &two) { + return one->signalStrength() > two->signalStrength(); + }); + + bool found = false; + foreach (const NetworkManager::WirelessNetwork::Ptr &network, networks) { + NetworkManager::AccessPoint::Ptr accessPoint = network->referenceAccessPoint(); + + if (!accessPoint) { + continue; + } + + if (ssid == network->ssid()) { + found = true; + } + + foreach (const NetworkManager::WirelessDevice::Ptr &device, devices) { + if (device->findNetwork(network->ssid()) == network) { + NetworkManager::WirelessSecurityType security = NetworkManager::findBestWirelessSecurity(device->wirelessCapabilities(), true, (device->mode() == NetworkManager::WirelessDevice::Adhoc), accessPoint->capabilities(), accessPoint->wpaFlags(), accessPoint->rsnFlags()); + QVariantMap map; + map.insert(QLatin1String("ssid"), accessPoint->ssid()); + map.insert(QLatin1String("signal"), network->signalStrength()); + if (security != NetworkManager::UnknownSecurity && security != NetworkManager::NoneSecurity) { + map.insert(QLatin1String("security"), UiUtils::labelFromWirelessSecurity(security)); + } else { + map.insert(QLatin1String("security"), i18n("Insecure")); + } + + list << map; + } + } + } + + if (!found) { + QVariantMap map; + map.insert(QLatin1String("ssid"), ssid); + list.insert(0, map); + } + + return list; +} + +QVariantList Utils::availableBssids(const QString &ssid, const QString &bssid) +{ + QVariantList list; + QList aps; + + foreach (const NetworkManager::Device::Ptr &device, NetworkManager::networkInterfaces()) { + if (device->type() == NetworkManager::Device::Wifi) { + NetworkManager::WirelessDevice::Ptr wifiDevice = device.objectCast(); + NetworkManager::WirelessNetwork::Ptr wifiNetwork = wifiDevice->findNetwork(ssid); + + if (!wifiNetwork) { + continue; + } + + foreach (const NetworkManager::AccessPoint::Ptr &newAp, wifiNetwork->accessPoints()) { + foreach (const NetworkManager::AccessPoint::Ptr &existingAp, aps) { + if (newAp->hardwareAddress() == existingAp->hardwareAddress() && + newAp->signalStrength() > existingAp->signalStrength()) { + aps.removeOne(existingAp); + break; + } + } + + aps << newAp; + } + } + } + + std::sort(aps.begin(), aps.end(), [] (const NetworkManager::AccessPoint::Ptr &one, const NetworkManager::AccessPoint::Ptr &two) { + return one->signalStrength() > two->signalStrength(); + }); + + bool found = false; + + foreach (const NetworkManager::AccessPoint::Ptr &ap, aps) { + if (!ap) { + continue; + } + + if (bssid == ap->hardwareAddress()) { + found = true; + } + + QVariantMap map; + map.insert(QLatin1String("bssid"), ap->hardwareAddress()); + map.insert(QLatin1String("signal"), ap->signalStrength()); + map.insert(QLatin1String("frequency"), ap->frequency()); + map.insert(QLatin1String("channel"), QString::number(NetworkManager::findChannel(ap->frequency()))); + + list << map; + } + + if (!found) { + QVariantMap map; + map.insert(QLatin1String("bssid"), bssid); + list.insert(0, map); + } + + return list; +} + +QVariantList Utils::deviceHwAddresses(uint deviceType, const QString &address) +{ + bool found = false; + QString deviceAddress; + QString deviceName; + QVariantList list; + + foreach (const NetworkManager::Device::Ptr &device, NetworkManager::networkInterfaces()) { + const NetworkManager::Device::Type type = device->type(); + if ((NetworkManager::Device::Type)deviceType == type) { + // Only wifi and ethernet supported for now + if (type == NetworkManager::Device::Wifi) { + deviceAddress = device->as()->permanentHardwareAddress(); + } else if (type == NetworkManager::Device::Ethernet) { + deviceAddress = device->as()->permanentHardwareAddress(); + } + + if (device->state() == NetworkManager::Device::Activated) { + deviceName = device->ipInterfaceName(); + } else { + deviceName = device->interfaceName(); + } + + QVariantMap map; + if (!deviceAddress.isEmpty()) { + map.insert(QLatin1String("mac"), deviceAddress); + map.insert(QLatin1String("device"), deviceName); + } + + if (address == deviceAddress) { + found = true; + list.insert(0, map); + } else { + list << map; + } + } + } + + if (!found) { + list.insert(0, QVariantMap{{QLatin1String("mac"), address}}); + } + + return list; +} + +QStringList Utils::firewallZones() +{ + QStringList firewallZones = {i18n("Default")}; + + // Load list of firewall zones + QDBusMessage msg = QDBusMessage::createMethodCall("org.fedoraproject.FirewallD1", "/org/fedoraproject/FirewallD1", + "org.fedoraproject.FirewallD1.zone", "getZones"); + QDBusPendingReply reply = QDBusConnection::systemBus().asyncCall(msg); + reply.waitForFinished(); + if (reply.isValid()) { + firewallZones += reply.value(); + } + + return firewallZones; +} + +QStringList Utils::vpnConnections() +{ + QStringList vpnConnections; + + // Load list of VPN connections + NetworkManager::Connection::List list = NetworkManager::listConnections(); + + Q_FOREACH (const NetworkManager::Connection::Ptr & conn, list) { + NetworkManager::ConnectionSettings::Ptr conSet = conn->settings(); + if (conSet->connectionType() == NetworkManager::ConnectionSettings::Vpn) { + vpnConnections << conSet->id(); + } + } + + return vpnConnections; +} + +QStringList Utils::wirelessChannels(uint band) +{ + QStringList result; + QList > channels; + + if ((NetworkManager::WirelessSetting::FrequencyBand)band == NetworkManager::WirelessSetting::A) { + channels = NetworkManager::getAFreqs(); + } else if ((NetworkManager::WirelessSetting::FrequencyBand)band == NetworkManager::WirelessSetting::Bg) { + channels = NetworkManager::getBFreqs(); + } else { + return QStringList(); + } + + QListIterator > i(channels); + while (i.hasNext()) { + QPair channel = i.next(); + result << QStringLiteral("%1 (%2 MHz)").arg(channel.first).arg(channel.second); + } + + return result; +} diff --git a/libs/editor/settings/setting.cpp b/libs/declarative/utils.h similarity index 57% copy from libs/editor/settings/setting.cpp copy to libs/declarative/utils.h index c6b562ec..4b087867 100644 --- a/libs/editor/settings/setting.cpp +++ b/libs/declarative/utils.h @@ -1,53 +1,43 @@ /* Copyright 2018 Jan Grulich 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 . */ -#include "setting.h" +#ifndef PLASMA_NM_UTILS_H +#define PLASMA_NM_UTILS_H -class SettingPrivate -{ -public: - explicit SettingPrivate(NetworkManager::Setting::SettingType type) - : type(type) - { } - NetworkManager::Setting::SettingType type; -}; - -Setting::Setting(const NetworkManager::Setting::Ptr &setting, QObject *parent) - : QObject(parent) - , d_ptr(new SettingPrivate(setting->type())) -{ -} +#include -Setting::~Setting() -{ - delete d_ptr; -} +#include -NetworkManager::Setting::SettingType Setting::type() const +class Q_DECL_EXPORT Utils : public QObject { - Q_D(const Setting); - - return d->type; -} + Q_OBJECT +public: + explicit Utils(QObject *parent = nullptr); + virtual ~Utils(); + + Q_INVOKABLE QVariantList availableSsids(const QString &ssid = QString()); + Q_INVOKABLE QVariantList availableBssids(const QString &ssid, const QString &bssid = QString()); + Q_INVOKABLE QVariantList deviceHwAddresses(uint deviceType, const QString &address = QString()); + Q_INVOKABLE QStringList firewallZones(); + Q_INVOKABLE QStringList vpnConnections(); + Q_INVOKABLE QStringList wirelessChannels(uint band); +}; -bool Setting::isValid() const -{ - return true; -} +#endif //PLASMA_NM_UTILS_H diff --git a/libs/editor/CMakeLists.txt b/libs/editor/CMakeLists.txt index 1c4d3d53..73d16265 100644 --- a/libs/editor/CMakeLists.txt +++ b/libs/editor/CMakeLists.txt @@ -1,48 +1,49 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/widgets) set(plasmanm_editor_SRCS # FIXME ../debug.cpp settings/connectionsettings.cpp settings/setting.cpp + settings/wirelesssetting.cpp widgets/passwordfield.cpp widgets/settingwidget.cpp listvalidator.cpp simpleipv4addressvalidator.cpp simpleipv6addressvalidator.cpp simpleiplistvalidator.cpp wireguardkeyvalidator.cpp vpnuiplugin.cpp ) if (WITH_MODEMMANAGER_SUPPORT) set(plasmanm_editor_SRCS ${plasmanm_editor_SRCS} widgets/mobileconnectionwizard.cpp mobileproviders.cpp) endif() add_library(plasmanm_editor SHARED ${plasmanm_editor_SRCS}) target_link_libraries(plasmanm_editor plasmanm_internal Qt5::DBus Qt5::Widgets KF5::CoreAddons KF5::KDELibs4Support KF5::I18n KF5::NetworkManagerQt # KF5::Declarative # KF5::Notifications # qca-qt5 ) if (WITH_MODEMMANAGER_SUPPORT) target_link_libraries(plasmanm_editor KF5::ModemManagerQt) endif() install(TARGETS plasmanm_editor ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES plasma-networkmanagement-vpnuiplugin.desktop DESTINATION ${KDE_INSTALL_KSERVICETYPES5DIR}) diff --git a/libs/editor/settings/connectionsettings.cpp b/libs/editor/settings/connectionsettings.cpp index 30f21de0..c96244c1 100644 --- a/libs/editor/settings/connectionsettings.cpp +++ b/libs/editor/settings/connectionsettings.cpp @@ -1,523 +1,498 @@ /* Copyright 2018 Jan Grulich 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 . */ #include "connectionsettings.h" #include "setting.h" - -#include -#include -#include -#include +#include "wirelesssetting.h" #include #include #include #include #include class ConnectionSettingsPrivate { public: NetworkManager::ConnectionSettings::Ptr connectionSettings; QMap settings; int pendingReplies; bool valid; bool secretsLoaded; - QStringList firewallZones = {i18n("Default")}; NMStringMap vpnConnections; }; ConnectionSettings::ConnectionSettings(QObject *parent) : ConnectionSettings(nullptr, parent) { } ConnectionSettings::ConnectionSettings(const NetworkManager::ConnectionSettings::Ptr &settings, QObject *parent) : QObject(parent) , d_ptr(new ConnectionSettingsPrivate()) { Q_D(ConnectionSettings); - // Load list of firewall zones - QDBusMessage msg = QDBusMessage::createMethodCall("org.fedoraproject.FirewallD1", "/org/fedoraproject/FirewallD1", - "org.fedoraproject.FirewallD1.zone", "getZones"); - QDBusPendingReply reply = QDBusConnection::systemBus().asyncCall(msg); - reply.waitForFinished(); - if (reply.isValid()) { - d->firewallZones += reply.value(); - } - // Load list of VPN connections NetworkManager::Connection::List list = NetworkManager::listConnections(); Q_FOREACH (const NetworkManager::Connection::Ptr & conn, list) { NetworkManager::ConnectionSettings::Ptr conSet = conn->settings(); if (conSet->connectionType() == NetworkManager::ConnectionSettings::Vpn) { d->vpnConnections.insert(conSet->uuid(), conSet->id()); } } if (settings) { loadConfig(settings); } } ConnectionSettings::~ConnectionSettings() { delete d_ptr; } void ConnectionSettings::loadConfig(const NetworkManager::ConnectionSettings::Ptr &settings) { Q_D(ConnectionSettings); d->secretsLoaded = false; d->connectionSettings = settings; // In case of new connection id will be empty if (d->connectionSettings->id().isEmpty()) { d->connectionSettings->addToPermissions(KUser().loginName(), QString()); } // TODO add rest setting types // // Add the rest of widgets // QString serviceType; // if (type == NetworkManager::ConnectionSettings::Wired) { // WiredConnectionWidget *wiredWidget = new WiredConnectionWidget(m_connection->setting(NetworkManager::Setting::Wired), this); // addSettingWidget(wiredWidget, i18n("Wired")); // WiredSecurity *wiredSecurity = new WiredSecurity(m_connection->setting(NetworkManager::Setting::Security8021x).staticCast(), this); // addSettingWidget(wiredSecurity, i18n("802.1x Security")); -// } else if (type == NetworkManager::ConnectionSettings::Wireless) { +// } else + if (settings->connectionType() == NetworkManager::ConnectionSettings::Wireless) { + addSetting(NetworkManager::Setting::Wireless, new WirelessSetting(d->connectionSettings->setting(NetworkManager::Setting::Wireless))); // WifiConnectionWidget *wifiWidget = new WifiConnectionWidget(m_connection->setting(NetworkManager::Setting::Wireless), this); // addSettingWidget(wifiWidget, i18n("Wi-Fi")); // WifiSecurity *wifiSecurity = new WifiSecurity(m_connection->setting(NetworkManager::Setting::WirelessSecurity), // m_connection->setting(NetworkManager::Setting::Security8021x).staticCast(), // this); // addSettingWidget(wifiSecurity, i18n("Wi-Fi Security")); // connect(wifiWidget, static_cast(&WifiConnectionWidget::ssidChanged), wifiSecurity, &WifiSecurity::onSsidChanged); -// } else if (type == NetworkManager::ConnectionSettings::Pppoe) { // DSL + } +// else if (type == NetworkManager::ConnectionSettings::Pppoe) { // DSL // PppoeWidget *pppoeWidget = new PppoeWidget(m_connection->setting(NetworkManager::Setting::Pppoe), this); // addSettingWidget(pppoeWidget, i18n("DSL")); // WiredConnectionWidget *wiredWidget = new WiredConnectionWidget(m_connection->setting(NetworkManager::Setting::Wired), this); // addSettingWidget(wiredWidget, i18n("Wired")); // } else if (type == NetworkManager::ConnectionSettings::Gsm) { // GSM // GsmWidget *gsmWidget = new GsmWidget(m_connection->setting(NetworkManager::Setting::Gsm), this); // addSettingWidget(gsmWidget, i18n("Mobile Broadband (%1)", m_connection->typeAsString(m_connection->connectionType()))); // } else if (type == NetworkManager::ConnectionSettings::Cdma) { // CDMA // CdmaWidget *cdmaWidget = new CdmaWidget(m_connection->setting(NetworkManager::Setting::Cdma), this); // addSettingWidget(cdmaWidget, i18n("Mobile Broadband (%1)", m_connection->typeAsString(m_connection->connectionType()))); // } else if (type == NetworkManager::ConnectionSettings::Bluetooth) { // Bluetooth // BtWidget *btWidget = new BtWidget(m_connection->setting(NetworkManager::Setting::Bluetooth), this); // addSettingWidget(btWidget, i18n("Bluetooth")); // NetworkManager::BluetoothSetting::Ptr btSetting = m_connection->setting(NetworkManager::Setting::Bluetooth).staticCast(); // if (btSetting->profileType() == NetworkManager::BluetoothSetting::Dun) { // GsmWidget *gsmWidget = new GsmWidget(m_connection->setting(NetworkManager::Setting::Gsm), this); // addSettingWidget(gsmWidget, i18n("GSM")); // PPPWidget *pppWidget = new PPPWidget(m_connection->setting(NetworkManager::Setting::Ppp), this); // addSettingWidget(pppWidget, i18n("PPP")); // } // } else if (type == NetworkManager::ConnectionSettings::Infiniband) { // Infiniband // InfinibandWidget *infinibandWidget = new InfinibandWidget(m_connection->setting(NetworkManager::Setting::Infiniband), this); // addSettingWidget(infinibandWidget, i18n("Infiniband")); // } else if (type == NetworkManager::ConnectionSettings::Bond) { // Bond // BondWidget *bondWidget = new BondWidget(m_connection->uuid(), m_connection->setting(NetworkManager::Setting::Bond), this); // addSettingWidget(bondWidget, i18n("Bond")); // } else if (type == NetworkManager::ConnectionSettings::Bridge) { // Bridge // BridgeWidget *bridgeWidget = new BridgeWidget(m_connection->uuid(), m_connection->setting(NetworkManager::Setting::Bridge), this); // addSettingWidget(bridgeWidget, i18n("Bridge")); // } else if (type == NetworkManager::ConnectionSettings::Vlan) { // Vlan // VlanWidget *vlanWidget = new VlanWidget(m_connection->setting(NetworkManager::Setting::Vlan), this); // addSettingWidget(vlanWidget, i18n("Vlan")); // } else if (type == NetworkManager::ConnectionSettings::Team) { // Team // TeamWidget *teamWidget = new TeamWidget(m_connection->uuid(), m_connection->setting(NetworkManager::Setting::Team), this); // addSettingWidget(teamWidget, i18n("Team")); // } else if (type == NetworkManager::ConnectionSettings::Vpn) { // VPN // QString error; // VpnUiPlugin *vpnPlugin = 0; // NetworkManager::VpnSetting::Ptr vpnSetting = // m_connection->setting(NetworkManager::Setting::Vpn).staticCast(); // if (!vpnSetting) { // qCWarning(PLASMA_NM) << "Missing VPN setting!"; // } else { // serviceType = vpnSetting->serviceType(); // vpnPlugin = KServiceTypeTrader::createInstanceFromQuery(QString::fromLatin1("PlasmaNetworkManagement/VpnUiPlugin"), // QString::fromLatin1("[X-NetworkManager-Services]=='%1'").arg(serviceType), // this, QVariantList(), &error); // if (vpnPlugin && error.isEmpty()) { // const QString shortName = serviceType.section('.', -1); // SettingWidget *vpnWidget = vpnPlugin->widget(vpnSetting, this); // addSettingWidget(vpnWidget, i18n("VPN (%1)", shortName)); // } else { // qCWarning(PLASMA_NM) << error << ", serviceType == " << serviceType; // } // } // } // // // PPP widget // if (type == NetworkManager::ConnectionSettings::Pppoe || type == NetworkManager::ConnectionSettings::Cdma || type == NetworkManager::ConnectionSettings::Gsm) { // PPPWidget *pppWidget = new PPPWidget(m_connection->setting(NetworkManager::Setting::Ppp), this); // addSettingWidget(pppWidget, i18n("PPP")); // } // // // IPv4 widget // if (!m_connection->isSlave()) { // IPv4Widget *ipv4Widget = new IPv4Widget(m_connection->setting(NetworkManager::Setting::Ipv4), this); // addSettingWidget(ipv4Widget, i18n("IPv4")); // } // // // IPv6 widget // if ((type == NetworkManager::ConnectionSettings::Wired // || type == NetworkManager::ConnectionSettings::Wireless // || type == NetworkManager::ConnectionSettings::Infiniband // #if NM_CHECK_VERSION(0, 9, 10) // || type == NetworkManager::ConnectionSettings::Team // #endif // // #if NM_CHECK_VERSION(1, 0, 0) // || type == NetworkManager::ConnectionSettings::Cdma // || type == NetworkManager::ConnectionSettings::Gsm // #endif // || type == NetworkManager::ConnectionSettings::Bond // || type == NetworkManager::ConnectionSettings::Bridge // || type == NetworkManager::ConnectionSettings::Vlan // || (type == NetworkManager::ConnectionSettings::Vpn && serviceType == QLatin1String("org.freedesktop.NetworkManager.openvpn"))) && !m_connection->isSlave()) { // IPv6Widget *ipv6Widget = new IPv6Widget(m_connection->setting(NetworkManager::Setting::Ipv6), this); // addSettingWidget(ipv6Widget, i18n("IPv6")); // } bool valid = true; foreach (NetworkManager::Setting::SettingType settingType, d->settings.keys()) { valid = valid && d->settings.value(settingType)->isValid(); connect(d->settings.value(settingType), &Setting::validityChanged, this, &ConnectionSettings::onValidityChanged); } d->valid = valid; Q_EMIT validityChanged(valid); // // If the connection is not empty (not new) we want to load its secrets // if (!emptyConnection) { // NetworkManager::Connection::Ptr connection = NetworkManager::findConnectionByUuid(m_connectionSetting->uuid()); // if (connection) { // QStringList requiredSecrets; // QString settingName; // QVariantMap setting; // QDBusPendingReply reply; // // if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Adsl) { // NetworkManager::AdslSetting::Ptr adslSetting = connection->settings()->setting(NetworkManager::Setting::Adsl).staticCast(); // if (adslSetting && !adslSetting->needSecrets().isEmpty()) { // requiredSecrets = adslSetting->needSecrets(); // setting = adslSetting->toMap(); // settingName = QLatin1String("adsl"); // } // } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Bluetooth) { // NetworkManager::GsmSetting::Ptr gsmSetting = connection->settings()->setting(NetworkManager::Setting::Gsm).staticCast(); // if (gsmSetting && !gsmSetting->needSecrets().isEmpty()) { // requiredSecrets = gsmSetting->needSecrets(); // setting = gsmSetting->toMap(); // settingName = QLatin1String("gsm"); // } // } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Cdma) { // NetworkManager::CdmaSetting::Ptr cdmaSetting = connection->settings()->setting(NetworkManager::Setting::Cdma).staticCast(); // if (cdmaSetting && !cdmaSetting->needSecrets().isEmpty()) { // requiredSecrets = cdmaSetting->needSecrets(); // setting = cdmaSetting->toMap(); // settingName = QLatin1String("cdma"); // } // } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Gsm) { // NetworkManager::GsmSetting::Ptr gsmSetting = connection->settings()->setting(NetworkManager::Setting::Gsm).staticCast(); // if (gsmSetting && !gsmSetting->needSecrets().isEmpty()) { // requiredSecrets = gsmSetting->needSecrets(); // setting = gsmSetting->toMap(); // settingName = QLatin1String("gsm"); // } // } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Pppoe) { // NetworkManager::PppoeSetting::Ptr pppoeSetting = connection->settings()->setting(NetworkManager::Setting::Pppoe).staticCast(); // if (pppoeSetting && !pppoeSetting->needSecrets().isEmpty()) { // requiredSecrets = pppoeSetting->needSecrets(); // setting = pppoeSetting->toMap(); // settingName = QLatin1String("pppoe"); // } // } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Wired) { // NetworkManager::Security8021xSetting::Ptr securitySetting = connection->settings()->setting(NetworkManager::Setting::Security8021x).staticCast(); // if (securitySetting && !securitySetting->needSecrets().isEmpty()) { // requiredSecrets = securitySetting->needSecrets(); // setting = securitySetting->toMap(); // settingName = QLatin1String("802-1x"); // } // } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Wireless) { // NetworkManager::WirelessSecuritySetting::Ptr wifiSecuritySetting = connection->settings()->setting(NetworkManager::Setting::WirelessSecurity).staticCast(); // if (wifiSecuritySetting && // (wifiSecuritySetting->keyMgmt() == NetworkManager::WirelessSecuritySetting::WpaEap || // (wifiSecuritySetting->keyMgmt() == NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting::Ieee8021x && // wifiSecuritySetting->authAlg() != NetworkManager::WirelessSecuritySetting::Leap))) { // NetworkManager::Security8021xSetting::Ptr securitySetting = connection->settings()->setting(NetworkManager::Setting::Security8021x).staticCast(); // if (securitySetting && !securitySetting->needSecrets().isEmpty()) { // requiredSecrets = securitySetting->needSecrets(); // setting = securitySetting->toMap(); // settingName = QLatin1String("802-1x"); // // if (requiredSecrets.contains(NM_SETTING_802_1X_PASSWORD_RAW)) { // requiredSecrets.removeAll(NM_SETTING_802_1X_PASSWORD_RAW); // } // } // } else { // if (!wifiSecuritySetting->needSecrets().isEmpty()) { // requiredSecrets = wifiSecuritySetting->needSecrets(); // setting = wifiSecuritySetting->toMap(); // settingName = QLatin1String("802-11-wireless-security"); // } // } // } else if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Vpn) { // settingName = QLatin1String("vpn"); // } // // if (!requiredSecrets.isEmpty() || m_connection->connectionType() == NetworkManager::ConnectionSettings::Vpn) { // bool requestSecrets = false; // if (m_connection->connectionType() == NetworkManager::ConnectionSettings::Vpn) { // requestSecrets = true; // } else { // Q_FOREACH (const QString &secret, requiredSecrets) { // if (setting.contains(secret + QLatin1String("-flags"))) { // NetworkManager::Setting::SecretFlagType secretFlag = (NetworkManager::Setting::SecretFlagType)setting.value(secret + QLatin1String("-flags")).toInt(); // if (secretFlag == NetworkManager::Setting::None || secretFlag == NetworkManager::Setting::AgentOwned) { // requestSecrets = true; // } // } else { // requestSecrets = true; // } // } // } // // if (requestSecrets) { // m_pendingReplies++; // reply = connection->secrets(settingName); // QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); // watcher->setProperty("connection", connection->name()); // watcher->setProperty("settingName", settingName); // connect(watcher, &QDBusPendingCallWatcher::finished, this, &ConnectionEditorBase::replyFinished); // m_valid = false; // Q_EMIT validityChanged(false); // return; // } // } // } // } // // We should be now fully initialized as we don't wait for secrets if (d->pendingReplies == 0) { d->secretsLoaded = true; } } NMVariantMapMap ConnectionSettings::settingMap() const { return NMVariantMapMap(); } QString ConnectionSettings::id() const { Q_D(const ConnectionSettings); return d->connectionSettings->id(); } void ConnectionSettings::setId(const QString &id) { Q_D(ConnectionSettings); d->connectionSettings->setId(id); } QString ConnectionSettings::uuid() const { Q_D(const ConnectionSettings); return d->connectionSettings->uuid(); } void ConnectionSettings::setUuid(const QString &uuid) { Q_D(ConnectionSettings); d->connectionSettings->setUuid(uuid); } uint ConnectionSettings::connectionType() const { Q_D(const ConnectionSettings); return (uint)d->connectionSettings->connectionType(); } bool ConnectionSettings::autoconnect() const { Q_D(const ConnectionSettings); return d->connectionSettings->autoconnect(); } void ConnectionSettings::setAutoconnect(bool autoconnect) { Q_D(ConnectionSettings); d->connectionSettings->setAutoconnect(autoconnect); } QStringList ConnectionSettings::permissions() const { Q_D(const ConnectionSettings); return d->connectionSettings->permissions().keys(); } void ConnectionSettings::setPermissions(const QStringList &permissions) { Q_D(ConnectionSettings); foreach (const QString &user, permissions) { d->connectionSettings->addToPermissions(user, QString()); } } QString ConnectionSettings::secondaryConnection() const { Q_D(const ConnectionSettings); if (!d->connectionSettings->secondaries().isEmpty()) { return d->vpnConnections.value(d->connectionSettings->secondaries().first()); } return nullptr; } void ConnectionSettings::setSecondaryConnection(const QString &secondaryConnection) { Q_D(ConnectionSettings); d->connectionSettings->setSecondaries({secondaryConnection}); } QString ConnectionSettings::zone() const { Q_D(const ConnectionSettings); return d->connectionSettings->zone(); } void ConnectionSettings::setZone(const QString &zone) { Q_D(ConnectionSettings); d->connectionSettings->setZone(zone); } int ConnectionSettings::priority() const { Q_D(const ConnectionSettings); return d->connectionSettings->autoconnectPriority(); } void ConnectionSettings::setPriority(int priority) { Q_D(ConnectionSettings); d->connectionSettings->setAutoconnectPriority(priority); } -QStringList ConnectionSettings::firewallZones() const -{ - Q_D(const ConnectionSettings); - - return d->firewallZones; -} - -QStringList ConnectionSettings::vpnConnections() const -{ - Q_D(const ConnectionSettings); - - return d->vpnConnections.values(); -} - -Setting * ConnectionSettings::setting(NetworkManager::Setting::SettingType type) const +QObject * ConnectionSettings::setting(uint type) const { Q_D(const ConnectionSettings); - return d->settings.value(type); + return d->settings.value((NetworkManager::Setting::SettingType) type); } QList ConnectionSettings::settingTypes() const { Q_D(const ConnectionSettings); return d->settings.keys(); } void ConnectionSettings::addSetting(NetworkManager::Setting::SettingType type, Setting *setting) { Q_D(ConnectionSettings); d->settings.insert(type, setting); } bool ConnectionSettings::isInitialized() const { Q_D(const ConnectionSettings); return d->secretsLoaded; } bool ConnectionSettings::isValid() const { Q_D(const ConnectionSettings); return d->valid; } void ConnectionSettings::onReplyFinished(QDBusPendingCallWatcher *watcher) { } void ConnectionSettings::onValidityChanged(bool valid) { Q_D(ConnectionSettings); if (!valid) { d->valid = false; Q_EMIT validityChanged(false); return; } else { foreach (NetworkManager::Setting::SettingType settingType, d->settings.keys()) { if (!d->settings.value(settingType)->isValid()) { d->valid = false; Q_EMIT validityChanged(false); return; } } } d->valid = true; Q_EMIT validityChanged(true); } diff --git a/libs/editor/settings/connectionsettings.h b/libs/editor/settings/connectionsettings.h index 49f09c59..39a6580b 100644 --- a/libs/editor/settings/connectionsettings.h +++ b/libs/editor/settings/connectionsettings.h @@ -1,106 +1,101 @@ /* Copyright 2018 Jan Grulich 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 . */ #ifndef PLASMA_NM_CONNECTION_SETTING_H #define PLASMA_NM_CONNECTION_SETTING_H class QObject; class QDBusPendingCallWatcher; class ConnectionSettingsPrivate; #include class Setting; class Q_DECL_EXPORT ConnectionSettings : public QObject { Q_OBJECT Q_PROPERTY(QString id READ id WRITE setId) Q_PROPERTY(QString uuid READ uuid WRITE setUuid) Q_PROPERTY(uint connectionType READ connectionType) Q_PROPERTY(bool autoconnect READ autoconnect WRITE setAutoconnect) Q_PROPERTY(QStringList permissions READ permissions WRITE setPermissions) Q_PROPERTY(QString secondaryConnection READ secondaryConnection WRITE setSecondaryConnection) Q_PROPERTY(QString zone READ zone WRITE setZone) Q_PROPERTY(int priority READ priority WRITE setPriority) - - Q_PROPERTY(QStringList firewallZones READ firewallZones CONSTANT) - Q_PROPERTY(QStringList vpnConnections READ vpnConnections CONSTANT) public: explicit ConnectionSettings(QObject *parent = nullptr); ConnectionSettings(const NetworkManager::ConnectionSettings::Ptr &settings = NetworkManager::ConnectionSettings::Ptr(), QObject *parent = nullptr); virtual ~ConnectionSettings(); void loadConfig(const NetworkManager::ConnectionSettings::Ptr &settings); NMVariantMapMap settingMap() const; QString id() const; void setId(const QString &id); QString uuid() const; void setUuid(const QString &uuid); uint connectionType() const; bool autoconnect() const; void setAutoconnect(bool autoconnect); QStringList permissions() const; void setPermissions(const QStringList &permissions); QString secondaryConnection() const; void setSecondaryConnection(const QString &secondaryConnection); QString zone() const; void setZone(const QString &zone); int priority() const; void setPriority(int priority); - QStringList firewallZones() const; - QStringList vpnConnections() const; + Q_INVOKABLE QObject * setting(uint type) const; - Setting * setting(NetworkManager::Setting::SettingType type) const; QList settingTypes() const; void addSetting(NetworkManager::Setting::SettingType type, Setting *setting); bool isInitialized() const; bool isValid() const; Q_SIGNALS: // The default value is supposed to be false, watch this property for validity change after // proper initialization with secrets void validityChanged(bool valid); private Q_SLOTS: void onValidityChanged(bool valid); void onReplyFinished(QDBusPendingCallWatcher *watcher); protected: ConnectionSettingsPrivate *d_ptr; private: Q_DECLARE_PRIVATE(ConnectionSettings) }; #endif // PLASMA_NM_CONNECTION_SETTING_H diff --git a/libs/editor/settings/setting.cpp b/libs/editor/settings/setting.cpp index c6b562ec..e1165e3a 100644 --- a/libs/editor/settings/setting.cpp +++ b/libs/editor/settings/setting.cpp @@ -1,53 +1,45 @@ /* Copyright 2018 Jan Grulich 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 . */ #include "setting.h" - -class SettingPrivate -{ -public: - explicit SettingPrivate(NetworkManager::Setting::SettingType type) - : type(type) - { } - NetworkManager::Setting::SettingType type; -}; +#include "setting_p.h" Setting::Setting(const NetworkManager::Setting::Ptr &setting, QObject *parent) : QObject(parent) - , d_ptr(new SettingPrivate(setting->type())) + , d_ptr(new SettingPrivate(setting, setting->type())) { } Setting::~Setting() { delete d_ptr; } NetworkManager::Setting::SettingType Setting::type() const { Q_D(const Setting); return d->type; } bool Setting::isValid() const { return true; } diff --git a/libs/editor/settings/setting.h b/libs/editor/settings/setting.h index 3a582d02..a487f4a9 100644 --- a/libs/editor/settings/setting.h +++ b/libs/editor/settings/setting.h @@ -1,58 +1,58 @@ /* Copyright 2018 Jan Grulich 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 . */ #ifndef PLASMA_NM_SETTING_H #define PLASMA_NM_SETTING_H class QObject; class SettingPrivate; #include -class Setting : public QObject +class Q_DECL_EXPORT Setting : public QObject { Q_OBJECT public: explicit Setting(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), QObject *parent = nullptr); virtual ~Setting(); - virtual void loadConfig(const NetworkManager::Setting::Ptr &setting) = 0; - virtual void loadSecrets(const NetworkManager::Setting::Ptr &setting) = 0; +// virtual void loadConfig(const NetworkManager::Setting::Ptr &setting) = 0; +// virtual void loadSecrets(const NetworkManager::Setting::Ptr &setting) = 0; - virtual QVariantMap setting() const = 0; +// virtual QVariantMap setting() const = 0; - virtual NetworkManager::Setting::SettingType type() const; + NetworkManager::Setting::SettingType type() const; virtual bool isValid() const; Q_SIGNALS: void changed(); void validityChanged(bool valid); protected: SettingPrivate *d_ptr; private: Q_DECLARE_PRIVATE(Setting) }; #endif // PLASMA_NM_SETTING_H