diff --git a/CMakeLists.txt b/CMakeLists.txt index 72a07d08..ee1e491e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,135 +1,132 @@ cmake_minimum_required(VERSION 3.0) project(plasma-networkmanagement) set(PROJECT_VERSION "5.18.80") set(PROJECT_VERSION_MAJOR 5) set(QT_MIN_VERSION "5.14.0") set(KF5_MIN_VERSION "5.66.0") set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED On) ################# set KDE specific information ################# find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDEClangFormat) include(ECMQMLModules) include(FeatureSummary) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core DBus - Network Quick QuickWidgets Widgets ) -find_package(KF5 ${KF5_MIN_VERSION} REQUIRED +find_package(KF5 REQUIRED ConfigWidgets - Completion CoreAddons Declarative - DBusAddons - KIO I18n IconThemes - NetworkManagerQt + Kirigami2 + KDELibs4Support Notifications Plasma Service - Solid - Wallet - WidgetsAddons WindowSystem + Wallet ) +find_package(KF5NetworkManagerQt REQUIRED 5.42.0) + find_package(KF5ModemManagerQt ${KF5_MIN_VERSION}) set_package_properties(KF5ModemManagerQt PROPERTIES TYPE OPTIONAL) ecm_find_qmlmodule(org.kde.prison 1.0) find_package(KF5Kirigami2 ${KF5_MIN_VERSION} CONFIG) set_package_properties(KF5Kirigami2 PROPERTIES DESCRIPTION "A QtQuick based components set" PURPOSE "Required at runtime by the KCMs" TYPE RUNTIME ) # Required only for getting information about NetworkManager version in CMake find_package(NetworkManager 1.4.0) set_package_properties(NetworkManager PROPERTIES TYPE REQUIRED) find_package(MobileBroadbandProviderInfo) set_package_properties(MobileBroadbandProviderInfo PROPERTIES DESCRIPTION "Database of mobile broadband service providers" URL "https://wiki.gnome.org/action/show/Projects/NetworkManager/MobileBroadband/ServiceProviders" TYPE OPTIONAL) find_package(Qca-qt5 2.1.0) set_package_properties(Qca-qt5 PROPERTIES DESCRIPTION "Support for encryption" URL "https://download.kde.org/stable/qca-qt5/" TYPE REQUIRED) find_package(KF5Prison ${KF5_MIN_VERSION}) set_package_properties(KF5Prison PROPERTIES DESCRIPTION "Prison library" URL "https://commits.kde.org/prison" TYPE RUNTIME PURPOSE "Needed to create mobile barcodes for WiFi networks" ) if (DISABLE_MODEMMANAGER_SUPPORT) message(STATUS "Disabling ModemManager support") set(WITH_MODEMMANAGER_SUPPORT 0) else() if (KF5ModemManagerQt_FOUND) message(STATUS "Enabling ModemManager support") set(WITH_MODEMMANAGER_SUPPORT 1) else() message(STATUS "ModemManager or ModemManagerQt not found") set(WITH_MODEMMANAGER_SUPPORT 0) endif() endif() add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0) add_definitions(-DQT_USE_FAST_OPERATOR_PLUS) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_FROM_BYTEARRAY) add_definitions(-DWITH_MODEMMANAGER_SUPPORT=${WITH_MODEMMANAGER_SUPPORT}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs ${CMAKE_CURRENT_SOURCE_DIR}/libs/editor/) add_subdirectory(applet) add_subdirectory(kded) add_subdirectory(kcm) add_subdirectory(libs) add_subdirectory(vpn) if (BUILD_MOBILE) add_subdirectory(mobile) endif() # Enable unit testing if (BUILD_TESTING) add_subdirectory(tests) endif() # add clang-format target for all our real source files file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/kcm/CMakeLists.txt b/kcm/CMakeLists.txt index 430249ca..0ba308a0 100755 --- a/kcm/CMakeLists.txt +++ b/kcm/CMakeLists.txt @@ -1,40 +1,33 @@ -include_directories(${CMAKE_SOURCE_DIR}/libs/editor - ${CMAKE_SOURCE_DIR}/libs/editor/widgets) - #KI18N Translation Domain for this library add_definitions(-DTRANSLATION_DOMAIN=\"plasmanetworkmanagement-kcm\") -set(kcm_networkmanagement_PART_SRCS - ../libs/debug.cpp +set(kcm_networkmanagement_SRCS kcm.cpp ) -ki18n_wrap_ui(kcm_networkmanagement_PART_SRCS - kcm.ui -) +add_library(kcm_networkmanagement MODULE ${kcm_networkmanagement_SRCS}) -add_library(kcm_networkmanagement MODULE ${kcm_networkmanagement_PART_SRCS}) target_link_libraries(kcm_networkmanagement plasmanm_internal plasmanm_editor + Qt5::Quick + Qt5::QuickWidgets + KF5::Completion KF5::ConfigWidgets + KF5::CoreAddons KF5::Declarative KF5::I18n + KF5::NetworkManagerQt KF5::Service - Qt5::Quick - Qt5::QuickWidgets + KF5::QuickAddons + KF5::WindowSystem ) install(TARGETS kcm_networkmanagement DESTINATION ${KDE_INSTALL_PLUGINDIR} ) -########### install files ############### +kcoreaddons_desktop_to_json(kcm_networkmanagement "kcm_networkmanagement.desktop" SERVICE_TYPES kcmodule.desktop) -install( FILES kcm_networkmanagement.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) -install( FILES - qml/AddConnectionDialog.qml - qml/ConfigurationDialog.qml - qml/ConnectionItem.qml - qml/Header.qml - qml/ListItem.qml - qml/main.qml +########### install files ############### +install(TARGETS kcm_networkmanagement DESTINATION ${PLUGIN_INSTALL_DIR}/kcms) +install( FILES kcm_networkmanagement.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) - DESTINATION ${KDE_INSTALL_DATADIR}/kcm_networkmanagement/qml) +kpackage_install_package(package kcm_networkmanagement kcms) diff --git a/kcm/Messages.sh b/kcm/Messages.sh index 46a1a4f0..c3575aac 100755 --- a/kcm/Messages.sh +++ b/kcm/Messages.sh @@ -1,6 +1,2 @@ #!/usr/bin/env bash - -$EXTRACTRC `find . -name "*.ui" -o -name "*.rc"` >> rc.cpp -$XGETTEXT `find . -name '*.cpp'` -o $podir/plasmanetworkmanagement-kcm.pot -$XGETTEXT `find . -name '*.qml'` -j -L Java -o $podir/plasmanetworkmanagement-kcm.pot -rm -f rc.cpp +$XGETTEXT `find . -name "*.cpp" -o -name "*.qml"` -o $podir/plasmanetworkmanagement-kcm.pot diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index d60e3c4d..c5e2d179 100755 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -1,603 +1,548 @@ /* - Copyright 2016 Jan Grulich + Copyright 2016-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 "kcm.h" #include "debug.h" -#include "connectioneditordialog.h" -#include "mobileconnectionwizard.h" +#include "settings/connectionsetting.h" +// #include "mobileconnectionwizard.h" #include "uiutils.h" -#include "vpnuiplugin.h" -#include "settings/wireguardinterfacewidget.h" + +// #include "vpnuiplugin.h" // KDE +#include +#include #include #include #include -#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Qt #include -#include -#include #include -#include -#include -#include -#include -#include +#include + +Q_LOGGING_CATEGORY(KCM_NETWORKMANAGEMENT, "kcm_networkmanagement") -K_PLUGIN_FACTORY(KCMNetworkConfigurationFactory, registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(KCMNetworkmanagementFactory, "kcm_networkmanagement.json", registerPlugin();) -KCMNetworkmanagement::KCMNetworkmanagement(QWidget *parent, const QVariantList &args) - : KCModule(parent, args) +KCMNetworkmanagement::KCMNetworkmanagement(QObject *parent, const QVariantList &args) + : KQuickAddons::ConfigModule(parent, args) , m_handler(new Handler(this)) - , m_tabWidget(nullptr) - , m_ui(new Ui::KCMForm) { - QWidget *mainWidget = new QWidget(this); - m_ui->setupUi(mainWidget); - - KDeclarative::KDeclarative kdeclarative; - kdeclarative.setDeclarativeEngine(m_ui->connectionView->engine()); - kdeclarative.setTranslationDomain(QStringLiteral(TRANSLATION_DOMAIN)); - kdeclarative.setupEngine(m_ui->connectionView->engine()); - kdeclarative.setupContext(); + KAboutData* about = new KAboutData(QStringLiteral("kcm_networkmanagement"), i18n("Edit your Network Connections"), + QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); + about->addAuthor(i18n("Jan Grulich"), QString(), QStringLiteral("jgrulich@redhat.com")); + setAboutData(about); + setButtons(Apply); // Check if we can use AP mode to identify security type bool useApMode = false; bool foundInactive = false; NetworkManager::WirelessDevice::Ptr wifiDev; for (const NetworkManager::Device::Ptr &device : NetworkManager::networkInterfaces()) { if (device->type() == NetworkManager::Device::Wifi) { wifiDev = device.objectCast(); if (wifiDev) { if (!wifiDev->isActive()) { foundInactive = true; } else { // Prefer previous device if it was inactive if (foundInactive) { break; } } if (wifiDev->wirelessCapabilities().testFlag(NetworkManager::WirelessDevice::ApCap)) { useApMode = true; } // We prefer inactive wireless card with AP capabilities if (foundInactive && useApMode) { break; } } } } - m_ui->connectionView->setMinimumWidth(300); - m_ui->connectionView->rootContext()->setContextProperty("alternateBaseColor", mainWidget->palette().color(QPalette::Active, QPalette::AlternateBase)); - m_ui->connectionView->rootContext()->setContextProperty("backgroundColor", mainWidget->palette().color(QPalette::Active, QPalette::Window)); - m_ui->connectionView->rootContext()->setContextProperty("baseColor", mainWidget->palette().color(QPalette::Active, QPalette::Base)); - m_ui->connectionView->rootContext()->setContextProperty("highlightColor", mainWidget->palette().color(QPalette::Active, QPalette::Highlight)); - m_ui->connectionView->rootContext()->setContextProperty("textColor", mainWidget->palette().color(QPalette::Active, QPalette::Text)); - m_ui->connectionView->rootContext()->setContextProperty("connectionModified", false); - m_ui->connectionView->rootContext()->setContextProperty("useApMode", useApMode); - m_ui->connectionView->setClearColor(Qt::transparent); - m_ui->connectionView->setResizeMode(QQuickWidget::SizeRootObjectToView); - m_ui->connectionView->setSource(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kcm_networkmanagement/qml/main.qml")))); - - QObject *rootItem = m_ui->connectionView->rootObject(); - connect(rootItem, SIGNAL(selectedConnectionChanged(QString)), this, SLOT(onSelectedConnectionChanged(QString))); - connect(rootItem, SIGNAL(requestCreateConnection(int,QString,QString,bool)), this, SLOT(onRequestCreateConnection(int,QString,QString,bool))); - connect(rootItem, SIGNAL(requestExportConnection(QString)), this, SLOT(onRequestExportConnection(QString))); - connect(rootItem, SIGNAL(requestToChangeConnection(QString,QString)), this, SLOT(onRequestToChangeConnection(QString,QString))); - - QVBoxLayout *l = new QVBoxLayout(this); - l->addWidget(mainWidget); - - setButtons(Button::Apply); + // TODO +// m_ui->connectionView->rootContext()->setContextProperty("connectionModified", false); +// m_ui->connectionView->rootContext()->setContextProperty("useApMode", useApMode); + + m_connectionSetting = new ConnectionSetting(this); +// connect(m_connectionSetting, &ConnectionSetting::settingChanged, +// [this] () { +// if (m_connectionSetting->isInitialized() && m_connectionSetting->isValid()) { +// setNeedsSave(true); +// } +// }); + connect(m_connectionSetting, &ConnectionSetting::validityChanged, + [this] (bool valid) { + if (m_connectionSetting->isInitialized()) { + setNeedsSave(true); + } + }); NetworkManager::Connection::Ptr selectedConnection; // Look in the arguments for a connection ID to preselect static const QLatin1String uuidArgumentMarker { "Uuid=" }; for (QVariant arg : args) { if (arg.canConvert(QMetaType::QString)) { QString uuid = arg.toString(); if (uuid.startsWith(uuidArgumentMarker)) { uuid = uuid.replace(uuidArgumentMarker, QString()); selectedConnection = NetworkManager::findConnectionByUuid(uuid); qDebug() << "Selecting user connection:" << uuid; break; } } } - // Pre-select the currently active primary connection - if (!selectedConnection || !selectedConnection->isValid()) { - NetworkManager::ActiveConnection::Ptr activeConnection = NetworkManager::primaryConnection(); - if (activeConnection && activeConnection->isValid()) { - selectedConnection = activeConnection->connection(); - qDebug() << "Selecting active connection:" << selectedConnection->uuid(); + // Pre-select currently active primary connection and if there is none then just select + // the very first connection + NetworkManager::ActiveConnection::Ptr activeConnection = NetworkManager::primaryConnection(); + if (activeConnection && activeConnection->isValid()) { + // Also check if the connection type is supported by KCM + const NetworkManager::ConnectionSettings::ConnectionType type = activeConnection->type(); + if (UiUtils::isConnectionTypeSupported(type)) { + QMetaObject::invokeMethod(mainUi(), "selectConnectionInView", Q_ARG(QVariant, activeConnection->id()), Q_ARG(QVariant, activeConnection->connection()->path())); } } // Select the very first connection as a fallback if (!selectedConnection || !selectedConnection->isValid()) { NetworkManager::Connection::List connectionList = NetworkManager::listConnections(); std::sort(connectionList.begin(), connectionList.end(), [] (const NetworkManager::Connection::Ptr &left, const NetworkManager::Connection::Ptr &right) { const QString leftName = left->settings()->id(); const UiUtils::SortedConnectionType leftType = UiUtils::connectionTypeToSortedType(left->settings()->connectionType()); const QDateTime leftDate = left->settings()->timestamp(); const QString rightName = right->settings()->id(); const UiUtils::SortedConnectionType rightType = UiUtils::connectionTypeToSortedType(right->settings()->connectionType()); const QDateTime rightDate = right->settings()->timestamp(); if (leftType < rightType) { return true; } else if (leftType > rightType) { return false; } if (leftDate > rightDate) { return true; } else if (leftDate < rightDate) { return false; } if (QString::localeAwareCompare(leftName, rightName) > 0) { return true; } else { return false; } }); for (const NetworkManager::Connection::Ptr &connection : connectionList) { const NetworkManager::ConnectionSettings::ConnectionType type = connection->settings()->connectionType(); if (UiUtils::isConnectionTypeSupported(type)) { - selectedConnection = connection; - qDebug() << "Selecting first connection:" << connection->uuid(); + QMetaObject::invokeMethod(mainUi(), "selectConnectionInView", Q_ARG(QVariant, connection->settings()->id()), Q_ARG(QVariant, connection->path())); break; } } } if (selectedConnection && selectedConnection->isValid()) { const NetworkManager::ConnectionSettings::Ptr settings = selectedConnection->settings(); if (UiUtils::isConnectionTypeSupported(settings->connectionType())) { QMetaObject::invokeMethod(rootItem, "selectConnection", Q_ARG(QVariant, settings->id()), Q_ARG(QVariant, selectedConnection->path())); } } else { qDebug() << "Cannot preselect a connection"; } connect(NetworkManager::settingsNotifier(), &NetworkManager::SettingsNotifier::connectionAdded, this, &KCMNetworkmanagement::onConnectionAdded, Qt::UniqueConnection); // Initialize first scan and then scan every 15 seconds m_handler->requestScan(); m_timer = new QTimer(this); m_timer->setInterval(15000); connect(m_timer, &QTimer::timeout, [this] () { m_handler->requestScan(); }); m_timer->start(); } KCMNetworkmanagement::~KCMNetworkmanagement() { delete m_handler; - if (m_tabWidget) { - delete m_tabWidget; - } - delete m_ui; } void KCMNetworkmanagement::defaults() { - KCModule::defaults(); + KQuickAddons::ConfigModule::defaults(); } void KCMNetworkmanagement::load() { // If there is no loaded connection do nothing if (m_currentConnectionPath.isEmpty()) { return; } NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(m_currentConnectionPath); if (connection) { NetworkManager::ConnectionSettings::Ptr connectionSettings = connection->settings(); // Re-load the connection again to load stored values - if (m_tabWidget) { - m_tabWidget->setConnection(connectionSettings); - } + m_connectionSetting->loadConfig(connectionSettings); } - KCModule::load(); + KQuickAddons::ConfigModule::load(); } void KCMNetworkmanagement::save() { - NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(m_currentConnectionPath); - - if (connection) { - m_handler->updateConnection(connection, m_tabWidget->setting()); - } +// NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(m_currentConnectionPath); +// +// if (connection) { +// m_handler->updateConnection(connection, m_connectionSetting->setting()); +// } - kcmChanged(false); - - KCModule::save(); + KQuickAddons::ConfigModule::save(); } void KCMNetworkmanagement::onConnectionAdded(const QString &connection) { if (m_createdConnectionUuid.isEmpty()) { return; } NetworkManager::Connection::Ptr newConnection = NetworkManager::findConnection(connection); if (newConnection) { NetworkManager::ConnectionSettings::Ptr connectionSettings = newConnection->settings(); if (connectionSettings && connectionSettings->uuid() == m_createdConnectionUuid) { - QObject *rootItem = m_ui->connectionView->rootObject(); loadConnectionSettings(connectionSettings); - QMetaObject::invokeMethod(rootItem, "selectConnection", Q_ARG(QVariant, connectionSettings->id()), Q_ARG(QVariant, newConnection->path())); + QMetaObject::invokeMethod(mainUi(), "selectConnectionInView", Q_ARG(QVariant, connectionSettings->id()), Q_ARG(QVariant, newConnection->path())); m_createdConnectionUuid.clear(); } } } -void KCMNetworkmanagement::onRequestCreateConnection(int connectionType, const QString &vpnType, const QString &specificType, bool shared) +void KCMNetworkmanagement::selectConnection(const QString &connectionPath) +{ + if (connectionPath.isEmpty()) { + resetSelection(); + return; + } + + m_currentConnectionPath = connectionPath; + + NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(m_currentConnectionPath); + if (connection) { + NetworkManager::ConnectionSettings::Ptr connectionSettings = connection->settings(); + loadConnectionSettings(connectionSettings); + } +} + +void KCMNetworkmanagement::requestCreateConnection(int connectionType, const QString &vpnType, const QString &specificType, bool shared) { NetworkManager::ConnectionSettings::ConnectionType type = static_cast(connectionType); if (type == NetworkManager::ConnectionSettings::Vpn && vpnType == "imported") { importVpn(); } else if (type == NetworkManager::ConnectionSettings::Gsm) { // launch the mobile broadband wizard, both gsm/cdma -#if WITH_MODEMMANAGER_SUPPORT - QPointer wizard = new MobileConnectionWizard(NetworkManager::ConnectionSettings::Unknown, this); - connect(wizard.data(), &MobileConnectionWizard::accepted, - [wizard, this] () { - if (wizard->getError() == MobileProviders::Success) { - qCDebug(PLASMA_NM) << "Mobile broadband wizard finished:" << wizard->type() << wizard->args(); - - if (wizard->args().count() == 2) { - QVariantMap tmp = qdbus_cast(wizard->args().value(1)); - - NetworkManager::ConnectionSettings::Ptr connectionSettings; - connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(wizard->type())); - connectionSettings->setId(wizard->args().value(0).toString()); - if (wizard->type() == NetworkManager::ConnectionSettings::Gsm) { - NetworkManager::GsmSetting::Ptr gsmSetting = connectionSettings->setting(NetworkManager::Setting::Gsm).staticCast(); - gsmSetting->fromMap(tmp); - gsmSetting->setPasswordFlags(NetworkManager::Setting::NotRequired); - gsmSetting->setPinFlags(NetworkManager::Setting::NotRequired); - } else if (wizard->type() == NetworkManager::ConnectionSettings::Cdma) { - connectionSettings->setting(NetworkManager::Setting::Cdma)->fromMap(tmp); - } else { - qCWarning(PLASMA_NM) << Q_FUNC_INFO << "Unhandled setting type"; - } - // Generate new UUID - connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); - addConnection(connectionSettings); - } else { - qCWarning(PLASMA_NM) << Q_FUNC_INFO << "Unexpected number of args to parse"; - } - } - }); - connect(wizard.data(), &MobileConnectionWizard::finished, - [wizard] () { - if (wizard) { - wizard->deleteLater(); - } - }); - wizard->setModal(true); - wizard->show(); -#endif +// #if WITH_MODEMMANAGER_SUPPORT +// QPointer wizard = new MobileConnectionWizard(NetworkManager::ConnectionSettings::Unknown, this); +// connect(wizard.data(), &MobileConnectionWizard::accepted, +// [wizard, this] () { +// if (wizard->getError() == MobileProviders::Success) { +// qCDebug(KCM_NETWORKMANAGEMENT) << "Mobile broadband wizard finished:" << wizard->type() << wizard->args(); +// +// if (wizard->args().count() == 2) { +// QVariantMap tmp = qdbus_cast(wizard->args().value(1)); +// +// NetworkManager::ConnectionSettings::Ptr connectionSettings; +// connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(wizard->type())); +// connectionSettings->setId(wizard->args().value(0).toString()); +// if (wizard->type() == NetworkManager::ConnectionSettings::Gsm) { +// NetworkManager::GsmSetting::Ptr gsmSetting = connectionSettings->setting(NetworkManager::Setting::Gsm).staticCast(); +// gsmSetting->fromMap(tmp); +// gsmSetting->setPasswordFlags(NetworkManager::Setting::NotRequired); +// gsmSetting->setPinFlags(NetworkManager::Setting::NotRequired); +// } else if (wizard->type() == NetworkManager::ConnectionSettings::Cdma) { +// connectionSettings->setting(NetworkManager::Setting::Cdma)->fromMap(tmp); +// } else { +// qCWarning(KCM_NETWORKMANAGEMENT) << Q_FUNC_INFO << "Unhandled setting type"; +// } +// // Generate new UUID +// connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); +// addConnection(connectionSettings); +// } else { +// qCWarning(KCM_NETWORKMANAGEMENT) << Q_FUNC_INFO << "Unexpected number of args to parse"; +// } +// } +// }); +// connect(wizard.data(), &MobileConnectionWizard::finished, +// [wizard] () { +// if (wizard) { +// wizard->deleteLater(); +// } +// }); +// wizard->setModal(true); +// wizard->show(); +// #endif } else { NetworkManager::ConnectionSettings::Ptr connectionSettings; connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(type)); if (type == NetworkManager::ConnectionSettings::Vpn) { NetworkManager::VpnSetting::Ptr vpnSetting = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast(); vpnSetting->setServiceType(vpnType); // Set VPN subtype in case of Openconnect to add support for juniper if (vpnType == QLatin1String("org.freedesktop.NetworkManager.openconnect")) { NMStringMap data = vpnSetting->data(); data.insert(QLatin1String("protocol"), specificType); vpnSetting->setData(data); } } if (type == NetworkManager::ConnectionSettings::Wired || type == NetworkManager::ConnectionSettings::Wireless) { // Set auto-negotiate to true, NM sets it to false by default, but we used to have this before and also // I don't think it's wise to request users to specify speed and duplex as most of them don't know what is that // and what to set if (type == NetworkManager::ConnectionSettings::Wired) { NetworkManager::WiredSetting::Ptr wiredSetting = connectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast(); wiredSetting->setAutoNegotiate(true); } if (shared) { if (type == NetworkManager::ConnectionSettings::Wireless) { NetworkManager::WirelessSetting::Ptr wifiSetting = connectionSettings->setting(NetworkManager::Setting::Wireless).dynamicCast(); wifiSetting->setMode(NetworkManager::WirelessSetting::Adhoc); wifiSetting->setSsid(i18n("my_shared_connection").toUtf8()); for (const NetworkManager::Device::Ptr & device : NetworkManager::networkInterfaces()) { if (device->type() == NetworkManager::Device::Wifi) { NetworkManager::WirelessDevice::Ptr wifiDev = device.objectCast(); if (wifiDev) { if (wifiDev->wirelessCapabilities().testFlag(NetworkManager::WirelessDevice::ApCap)) { wifiSetting->setMode(NetworkManager::WirelessSetting::Ap); wifiSetting->setMacAddress(NetworkManager::macAddressFromString(wifiDev->permanentHardwareAddress())); } } } } } NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast(); ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Shared); connectionSettings->setAutoconnect(false); } } if (type == NetworkManager::ConnectionSettings::WireGuard) { NetworkManager::WireGuardSetting::Ptr wireguardSetting = connectionSettings->setting(NetworkManager::Setting::WireGuard).dynamicCast(); NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast(); NetworkManager::Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast(); connectionSettings->setAutoconnect(false); ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Disabled); ipv6Setting->setMethod(NetworkManager::Ipv6Setting::Ignored); } // Generate new UUID connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); addConnection(connectionSettings); } } -void KCMNetworkmanagement::onRequestExportConnection(const QString &connectionPath) +void KCMNetworkmanagement::requestExportConnection(const QString &connectionPath) { NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(connectionPath); if (!connection) { return; } NetworkManager::ConnectionSettings::Ptr connSettings = connection->settings(); if (connSettings->connectionType() != NetworkManager::ConnectionSettings::Vpn) return; NetworkManager::VpnSetting::Ptr vpnSetting = connSettings->setting(NetworkManager::Setting::Vpn).dynamicCast(); - qCDebug(PLASMA_NM) << "Exporting VPN connection" << connection->name() << "type:" << vpnSetting->serviceType(); + qCDebug(KCM_NETWORKMANAGEMENT) << "Exporting VPN connection" << connection->name() << "type:" << vpnSetting->serviceType(); QString error; - VpnUiPlugin * vpnPlugin = KServiceTypeTrader::createInstanceFromQuery(QStringLiteral("PlasmaNetworkManagement/VpnUiPlugin"), - QStringLiteral("[X-NetworkManager-Services]=='%1'").arg(vpnSetting->serviceType()), - this, QVariantList(), &error); - - if (vpnPlugin) { - if (vpnPlugin->suggestedFileName(connSettings).isEmpty()) { // this VPN doesn't support export - qCWarning(PLASMA_NM) << "This VPN doesn't support export"; - return; - } - - const QString url = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + QDir::separator() + vpnPlugin->suggestedFileName(connSettings); - const QString filename = QFileDialog::getSaveFileName(this, i18n("Export VPN Connection"), url, vpnPlugin->supportedFileExtensions()); - if (!filename.isEmpty()) { - if (!vpnPlugin->exportConnectionSettings(connSettings, filename)) { - // TODO display failure - qCWarning(PLASMA_NM) << "Failed to export VPN connection"; - } else { - // TODO display success - } - } - delete vpnPlugin; - } else { - qCWarning(PLASMA_NM) << "Error getting VpnUiPlugin for export:" << error; - } +// VpnUiPlugin * vpnPlugin = KServiceTypeTrader::createInstanceFromQuery(QStringLiteral("PlasmaNetworkManagement/VpnUiPlugin"), +// QStringLiteral("[X-NetworkManager-Services]=='%1'").arg(vpnSetting->serviceType()), +// this, QVariantList(), &error); + +// if (vpnPlugin) { +// if (vpnPlugin->suggestedFileName(connSettings).isEmpty()) { // this VPN doesn't support export +// qCWarning(KCM_NETWORKMANAGEMENT) << "This VPN doesn't support export"; +// return; +// } +// +// const QString url = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + QDir::separator() + vpnPlugin->suggestedFileName(connSettings); +// const QString filename = QFileDialog::getSaveFileName(this, i18n("Export VPN Connection"), url, vpnPlugin->supportedFileExtensions()); +// if (!filename.isEmpty()) { +// if (!vpnPlugin->exportConnectionSettings(connSettings, filename)) { +// // TODO display failure +// qCWarning(KCM_NETWORKMANAGEMENT) << "Failed to export VPN connection"; +// } else { +// // TODO display success +// } +// } +// delete vpnPlugin; +// } else { +// qCWarning(KCM_NETWORKMANAGEMENT) << "Error getting VpnUiPlugin for export:" << error; +// } } -void KCMNetworkmanagement::onRequestToChangeConnection( const QString &connectionName, const QString &connectionPath) +QObject * KCMNetworkmanagement::connectionSetting() const { - NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(m_currentConnectionPath); - - if (connection) { - if (KMessageBox::questionYesNo(this, i18n("Do you want to save changes made to the connection '%1'?", connection->name()), i18nc("@title:window", "Save Changes"), - KStandardGuiItem::save(), KStandardGuiItem::discard(), QString(), KMessageBox::Notify) == KMessageBox::Yes) { - save(); - } - } - - QObject *rootItem = m_ui->connectionView->rootObject(); - QMetaObject::invokeMethod(rootItem, "selectConnection", Q_ARG(QVariant, connectionName), Q_ARG(QVariant, connectionPath)); -} - -void KCMNetworkmanagement::onSelectedConnectionChanged(const QString &connectionPath) -{ - if (connectionPath.isEmpty()) { - resetSelection(); - return; - } - - m_currentConnectionPath = connectionPath; - - NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(m_currentConnectionPath); - if (connection) { - NetworkManager::ConnectionSettings::Ptr connectionSettings = connection->settings(); - loadConnectionSettings(connectionSettings); - } + return m_connectionSetting; } void KCMNetworkmanagement::addConnection(const NetworkManager::ConnectionSettings::Ptr &connectionSettings) { - QPointer editor = new ConnectionEditorDialog(connectionSettings); - connect(editor.data(), &ConnectionEditorDialog::accepted, - [connectionSettings, editor, this] () { - // We got confirmation so watch this connection and select it once it is created - m_createdConnectionUuid = connectionSettings->uuid(); - m_handler->addConnection(editor->setting()); - }); - connect(editor.data(), &ConnectionEditorDialog::finished, - [editor] () { - if (editor) { - editor->deleteLater(); - } - }); - editor->setModal(true); - editor->show(); -} - -void KCMNetworkmanagement::kcmChanged(bool kcmChanged) -{ - m_ui->connectionView->rootContext()->setContextProperty("connectionModified", kcmChanged); - Q_EMIT changed(kcmChanged); +// QPointer editor = new ConnectionEditorDialog(connectionSettings); +// connect(editor.data(), &ConnectionEditorDialog::accepted, +// [connectionSettings, editor, this] () { +// // We got confirmation so watch this connection and select it once it is created +// m_createdConnectionUuid = connectionSettings->uuid(); +// m_handler->addConnection(editor->setting()); +// }); +// connect(editor.data(), &ConnectionEditorDialog::finished, +// [editor] () { +// if (editor) { +// editor->deleteLater(); +// } +// }); +// editor->setModal(true); +// editor->show(); } void KCMNetworkmanagement::loadConnectionSettings(const NetworkManager::ConnectionSettings::Ptr& connectionSettings) { - if (m_tabWidget) { - m_tabWidget->setConnection(connectionSettings); - } else { - m_tabWidget = new ConnectionEditorTabWidget(connectionSettings); - connect(m_tabWidget, &ConnectionEditorTabWidget::settingChanged, - [this] () { - if (m_tabWidget->isInitialized() && m_tabWidget->isValid()) { - kcmChanged(true); - } - }); - connect(m_tabWidget, &ConnectionEditorTabWidget::validityChanged, - [this] (bool valid) { - if (m_tabWidget->isInitialized() && m_tabWidget->isValid() != valid) { - kcmChanged(valid); - } - }); - QVBoxLayout *layout = new QVBoxLayout(m_ui->connectionConfiguration); - layout->addWidget(m_tabWidget); - } + m_connectionSetting->loadConfig(connectionSettings); + + QMetaObject::invokeMethod(mainUi(), "loadConnectionSetting"); - kcmChanged(false); + setNeedsSave(false); } void KCMNetworkmanagement::importVpn() { // get the list of supported extensions - const KService::List services = KServiceTypeTrader::self()->query("PlasmaNetworkManagement/VpnUiPlugin"); - QString extensions; - for (const KService::Ptr &service : services) { - VpnUiPlugin * vpnPlugin = service->createInstance(this); - if (vpnPlugin) { - extensions += vpnPlugin->supportedFileExtensions() % QStringLiteral(" "); - delete vpnPlugin; - } - } - - const QString &filename = QFileDialog::getOpenFileName(this, i18n("Import VPN Connection"), QDir::homePath(), extensions.simplified()); - - if (!filename.isEmpty()) { - const KService::List services = KServiceTypeTrader::self()->query("PlasmaNetworkManagement/VpnUiPlugin"); - - QFileInfo fi(filename); - const QString ext = QStringLiteral("*.") % fi.suffix(); - qCDebug(PLASMA_NM) << "Importing VPN connection " << filename << "extension:" << ext; - - // Handle WireGuard separately because it is different than all the other VPNs - if (WireGuardInterfaceWidget::supportedFileExtensions().contains(ext)) { - NMVariantMapMap connection = WireGuardInterfaceWidget::importConnectionSettings(filename); - NetworkManager::ConnectionSettings connectionSettings; - connectionSettings.fromMap(connection); - connectionSettings.setUuid(NetworkManager::ConnectionSettings::createNewUuid()); - - // qCDebug(PLASMA_NM) << "Converted connection:" << connectionSettings; - - m_handler->addConnection(connectionSettings.toMap()); - // qCDebug(PLASMA_NM) << "Adding imported connection under id:" << conId; - - if (!connection.isEmpty()) { - return; // get out if the import produced at least some output - } - } - for (const KService::Ptr &service : services) { - VpnUiPlugin * vpnPlugin = service->createInstance(this); - if (vpnPlugin && vpnPlugin->supportedFileExtensions().contains(ext)) { - qCDebug(PLASMA_NM) << "Found VPN plugin" << service->name() << ", type:" << service->property("X-NetworkManager-Services", QVariant::String).toString(); - - NMVariantMapMap connection = vpnPlugin->importConnectionSettings(filename); - - // qCDebug(PLASMA_NM) << "Raw connection:" << connection; - - NetworkManager::ConnectionSettings connectionSettings; - connectionSettings.fromMap(connection); - connectionSettings.setUuid(NetworkManager::ConnectionSettings::createNewUuid()); - - // qCDebug(PLASMA_NM) << "Converted connection:" << connectionSettings; - - m_handler->addConnection(connectionSettings.toMap()); - // qCDebug(PLASMA_NM) << "Adding imported connection under id:" << conId; - - if (connection.isEmpty()) { // the "positive" part will arrive with connectionAdded - // TODO display success - } else { - delete vpnPlugin; - break; // stop iterating over the plugins if the import produced at least some output - } - - delete vpnPlugin; - } - } - } +// const KService::List services = KServiceTypeTrader::self()->query("PlasmaNetworkManagement/VpnUiPlugin"); +// QString extensions; +// for (const KService::Ptr &service : services) { +// VpnUiPlugin * vpnPlugin = service->createInstance(this); +// if (vpnPlugin) { +// extensions += vpnPlugin->supportedFileExtensions() % QStringLiteral(" "); +// delete vpnPlugin; +// } +// } +// +// const QString &filename = QFileDialog::getOpenFileName(this, i18n("Import VPN Connection"), QDir::homePath(), extensions.simplified()); +// +// if (!filename.isEmpty()) { +// const KService::List services = KServiceTypeTrader::self()->query("PlasmaNetworkManagement/VpnUiPlugin"); +// +// QFileInfo fi(filename); +// const QString ext = QStringLiteral("*.") % fi.suffix(); +// qCDebug(PLASMA_NM) << "Importing VPN connection " << filename << "extension:" << ext; +// +// // Handle WireGuard separately because it is different than all the other VPNs +// if (WireGuardInterfaceWidget::supportedFileExtensions().contains(ext)) { +// NMVariantMapMap connection = WireGuardInterfaceWidget::importConnectionSettings(filename); +// NetworkManager::ConnectionSettings connectionSettings; +// connectionSettings.fromMap(connection); +// connectionSettings.setUuid(NetworkManager::ConnectionSettings::createNewUuid()); +// +// // qCDebug(PLASMA_NM) << "Converted connection:" << connectionSettings; +// +// m_handler->addConnection(connectionSettings.toMap()); +// // qCDebug(PLASMA_NM) << "Adding imported connection under id:" << conId; +// +// if (!connection.isEmpty()) { +// return; // get out if the import produced at least some output +// } +// } +// for (const KService::Ptr &service : services) { +// VpnUiPlugin * vpnPlugin = service->createInstance(this); +// if (vpnPlugin && vpnPlugin->supportedFileExtensions().contains(ext)) { +// qCDebug(PLASMA_NM) << "Found VPN plugin" << service->name() << ", type:" << service->property("X-NetworkManager-Services", QVariant::String).toString(); +// +// NMVariantMapMap connection = vpnPlugin->importConnectionSettings(filename); +// +// // qCDebug(PLASMA_NM) << "Raw connection:" << connection; +// +// NetworkManager::ConnectionSettings connectionSettings; +// connectionSettings.fromMap(connection); +// connectionSettings.setUuid(NetworkManager::ConnectionSettings::createNewUuid()); +// +// // qCDebug(PLASMA_NM) << "Converted connection:" << connectionSettings; +// +// m_handler->addConnection(connectionSettings.toMap()); +// // qCDebug(PLASMA_NM) << "Adding imported connection under id:" << conId; +// +// if (connection.isEmpty()) { // the "positive" part will arrive with connectionAdded +// // TODO display success +// } else { +// delete vpnPlugin; +// break; // stop iterating over the plugins if the import produced at least some output +// } +// +// delete vpnPlugin; +// } +// } +// } } void KCMNetworkmanagement::resetSelection() { // Reset selected connections m_currentConnectionPath.clear(); - QObject *rootItem = m_ui->connectionView->rootObject(); - QMetaObject::invokeMethod(rootItem, "deselectConnections"); - if (m_tabWidget) { - delete m_ui->connectionConfiguration->layout(); - delete m_tabWidget; - m_tabWidget = nullptr; - } - Q_EMIT changed(false); + QMetaObject::invokeMethod(mainUi(), "deselectConnectionsInView"); +// if (m_connectionSetting) { +// delete m_connectionSetting; +// m_connectionSetting = nullptr; +// } + setNeedsSave(false); } #include "kcm.moc" diff --git a/kcm/kcm.h b/kcm/kcm.h index 1e45c893..3cc8f502 100755 --- a/kcm/kcm.h +++ b/kcm/kcm.h @@ -1,66 +1,72 @@ /* - Copyright 2016 Jan Grulich + Copyright 2016-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_KCM_H #define PLASMA_NM_KCM_H -#include "connectioneditortabwidget.h" #include "handler.h" -#include -#include +#include class QQuickView; -class KCMNetworkmanagement : public KCModule +class ConnectionSetting; + +class KCMNetworkmanagement : public KQuickAddons::ConfigModule { Q_OBJECT + Q_PROPERTY(QObject * connectionSetting READ connectionSetting NOTIFY connectionSettingChanged) public: explicit KCMNetworkmanagement(QWidget *parent = nullptr, const QVariantList &args = QVariantList()); ~KCMNetworkmanagement() override; + // Called from QML + Q_INVOKABLE void selectConnection(const QString &connectionPath); + Q_INVOKABLE void requestCreateConnection(int connectionType, const QString &vpnType, const QString &specificType, bool share); + Q_INVOKABLE void requestExportConnection(const QString &connectionPath); + + QObject *connectionSetting() const; + public Q_SLOTS: void defaults() override; void load() override; void save() override; private Q_SLOTS: void onConnectionAdded(const QString &connection); - void onSelectedConnectionChanged(const QString &connectionPath); - void onRequestCreateConnection(int connectionType, const QString &vpnType, const QString &specificType, bool shared); - void onRequestExportConnection(const QString &connectionPath); - void onRequestToChangeConnection(const QString &connectionName, const QString &connectionPath); + +Q_SIGNALS: + void connectionSettingChanged(); private: void addConnection(const NetworkManager::ConnectionSettings::Ptr &connectionSettings); void importVpn(); - void kcmChanged(bool kcmChanged); void loadConnectionSettings(const NetworkManager::ConnectionSettings::Ptr &connectionSettings); void resetSelection(); QString m_currentConnectionPath; QString m_createdConnectionUuid; Handler *m_handler; - ConnectionEditorTabWidget *m_tabWidget; QTimer *m_timer; - Ui::KCMForm *m_ui; + + ConnectionSetting *m_connectionSetting = nullptr; }; #endif diff --git a/kcm/kcm.ui b/kcm/kcm.ui deleted file mode 100755 index 5e866bea..00000000 --- a/kcm/kcm.ui +++ /dev/null @@ -1,47 +0,0 @@ - - - KCMForm - - - - 0 - 0 - 800 - 500 - - - - - 0 - 0 - - - - - 800 - 500 - - - - - - - QQuickWidget::SizeRootObjectToView - - - - - - - - - - - QQuickWidget - QWidget -
QtQuickWidgets/QQuickWidget
-
-
- - -
diff --git a/kcm/package/contents/ui/AddConnectionDialog.qml b/kcm/package/contents/ui/AddConnectionDialog.qml new file mode 100644 index 00000000..367f1eb5 --- /dev/null +++ b/kcm/package/contents/ui/AddConnectionDialog.qml @@ -0,0 +1,182 @@ +/* + Copyright 2016-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.3 +import QtQuick.Dialogs 1.2 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.2 as QtControls + +import org.kde.kirigami 2.3 as Kirigami + +import org.kde.plasma.networkmanagement 0.2 as PlasmaNM + +Dialog { + id: addConnectionDialog + title: i18nc("@title:window", "Choose a Connection Type") + + signal requestCreateConnection(int type, string vpnType, string specificType, bool shared) + + contentItem: Item { + implicitHeight: 600 + implicitWidth: 500 + + PlasmaNM.CreatableConnectionsModel { + id: connectionModel + } + + Kirigami.Theme.colorSet: Kirigami.Theme.View + + Rectangle { + anchors.fill: parent + focus: true + color: Kirigami.Theme.backgroundColor + } + + ColumnLayout { + anchors.fill: parent + spacing: Kirigami.Units.smallSpacing + + Kirigami.ScrollablePage { + Layout.fillHeight: true + + ListView { + id: view + + property int currentlySelectedIndex: -1 + property bool connectionShared + property string connectionSpecificType + property int connectionType + property string connectionVpnType + + clip: true + model: connectionModel + currentIndex: -1 + boundsBehavior: Flickable.StopAtBounds + + section { + property: "ConnectionTypeSection" + delegate: Kirigami.AbstractListItem { + supportsMouseEvents: false + background: Rectangle { + color: palette.window + } + QtControls.Label { + id: headerLabel + anchors.centerIn: parent + font.weight: Font.DemiBold + text: section + } + } + } + + delegate: Kirigami.AbstractListItem { + checked: view.currentlySelectedIndex == index + highlighted: hovered + + + RowLayout { + anchors { + left: parent.left + right: parent.right + verticalCenter: parent.verticalCenter + leftMargin: Kirigami.Units.largeSpacing + } + spacing: Kirigami.Units.largeSpacing + + Kirigami.Icon { + Layout.minimumHeight: Kirigami.Units.iconSizes.smallMedium + Layout.maximumHeight: Layout.minimumHeight + Layout.minimumWidth: height + source: ConnectionIcon + } + + ColumnLayout { + spacing: 0 + + QtControls.Label { + id: nameLabel + Layout.fillWidth: true + height: paintedHeight + elide: Text.ElideRight + text: ConnectionTypeName + textFormat: Text.PlainText + } + + QtControls.Label { + id: statusLabel + Layout.fillWidth: true + height: paintedHeight + elide: Text.ElideRight + font.pointSize: theme.smallestFont.pointSize + text: ConnectionDescription + textFormat: Text.PlainText + opacity: 0.6 + visible: ConnectionType == 11 // VPN + } + } + } + + onClicked: { + createConnectionButton.enabled = true + view.currentlySelectedIndex = index + view.connectionSpecificType = ConnectionSpecificType + view.connectionShared = ConnectionShared + view.connectionType = ConnectionType + view.connectionVpnType = ConnectionVpnType + } + + onDoubleClicked: { + addConnectionDialog.close() + addConnectionDialog.requestCreateConnection(view.connectionType, view.connectionVpnType, view.connectionSpecificType, view.connectionShared) + } + } + } + } + + RowLayout { + spacing: Kirigami.Units.smallSpacing + + Layout.fillWidth: true + Layout.alignment: Qt.AlignRight + Layout.bottomMargin: Kirigami.Units.smallSpacing + Layout.rightMargin: Kirigami.Units.smallSpacing + + QtControls.Button { + id: createConnectionButton + enabled: false + text: i18n("Create") + + onClicked: { + addConnectionDialog.close() + addConnectionDialog.requestCreateConnection(view.connectionType, view.connectionVpnType, view.connectionSpecificType, view.connectionShared) + } + } + + QtControls.Button { + text: i18n("Cancel") + + onClicked: { + addConnectionDialog.close() + } + } + } + } + } +} diff --git a/kcm/package/contents/ui/ConnectionItemDelegate.qml b/kcm/package/contents/ui/ConnectionItemDelegate.qml new file mode 100644 index 00000000..7edb92d8 --- /dev/null +++ b/kcm/package/contents/ui/ConnectionItemDelegate.qml @@ -0,0 +1,135 @@ +/* + Copyright 2016-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.2 +import QtQuick.Controls 2.5 as QQC2 + +import org.kde.kirigami 2.9 as Kirigami + +import org.kde.plasma.networkmanagement 0.2 as PlasmaNM + +Kirigami.AbstractListItem { + id: connectionItem + + checked: ConnectionPath === scrollablePage.currentConnectionPath + highlighted: hovered + + signal aboutToChangeConnection(bool exportable, string name, string path) + signal aboutToExportConnection(string path) + signal aboutToRemoveConnection(string name, string path) + + RowLayout { + anchors { + left: parent.left + right: parent.right + verticalCenter: parent.verticalCenter + leftMargin: Kirigami.Units.largeSpacing + } + spacing: Kirigami.Units.largeSpacing + + Kirigami.Icon { + id: connectionIcon + Layout.minimumHeight: Kirigami.Units.iconSizes.smallMedium + Layout.maximumHeight: Layout.minimumHeight + Layout.minimumWidth: height + source: KcmConnectionIcon + } + + ColumnLayout { + spacing: 0 + + QQC2.Label { + id: nameLabel + Layout.fillWidth: true + height: paintedHeight + elide: Text.ElideRight + font.weight: ConnectionState == PlasmaNM.Enums.Activated ? Font.DemiBold : Font.Normal + font.italic: ConnectionState == PlasmaNM.Enums.Activating ? true : false + text: Name + textFormat: Text.PlainText + } + + QQC2.Label { + id: statusLabel + Layout.fillWidth: true + height: paintedHeight + elide: Text.ElideRight + font.pointSize: theme.smallestFont.pointSize + text: itemText() + textFormat: Text.PlainText + opacity: 0.6 + } + } + } + + QQC.Menu { + id: connectionItemMenu + + QQC.MenuItem { + text: ConnectionState == PlasmaNM.Enums.Deactivated ? i18n("Connect") : i18n("Disconnect") + visible: ItemType == 1 + onTriggered: { + if (ConnectionState == PlasmaNM.Enums.Deactivated) { + handler.activateConnection(ConnectionPath, DevicePath, SpecificPath); + } else { + handler.deactivateConnection(ConnectionPath, DevicePath); + } + } + } + + QQC.MenuItem { + iconName: "list-remove" + text: i18n("Delete"); + + onTriggered: { + aboutToRemoveConnection(Name, ConnectionPath) + } + } + + QQC.MenuItem { + iconName: "document-export" + visible: KcmVpnConnectionExportable + text: i18n("Export"); + + onTriggered: aboutToExportConnection(ConnectionPath) + } + } + + onClicked: { + if (mouse.button === Qt.LeftButton) { + aboutToChangeConnection(KcmVpnConnectionExportable, Name, ConnectionPath) + } else if (mouse.button == Qt.RightButton) { + connectionItemMenu.popup() + } + } + + /* This generates the status description under each connection + in the list at the left side of the applet. */ + function itemText() { + if (ConnectionState == PlasmaNM.Enums.Activated) { + return i18n("Connected") + } else if (ConnectionState == PlasmaNM.Enums.Activating) { + return i18n("Connecting") + } else { + return LastUsed + } + } +} diff --git a/kcm/package/contents/ui/ConnectionView.qml b/kcm/package/contents/ui/ConnectionView.qml new file mode 100644 index 00000000..a0e177c7 --- /dev/null +++ b/kcm/package/contents/ui/ConnectionView.qml @@ -0,0 +1,92 @@ +/* + Copyright 2016-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.Controls 2.2 as QtControls + +import org.kde.kcm 1.0 +import org.kde.kirigami 2.3 as Kirigami + +Kirigami.ScrollablePage { + id: scrollablePage + + property bool currentConnectionExportable: false + property string currentConnectionName + property string currentConnectionPath + + Kirigami.Theme.colorSet: Kirigami.Theme.View + + background: Rectangle { + color: Kirigami.Theme.backgroundColor + } + + ListView { + anchors.fill: parent + clip: true + model: editorProxyModel + currentIndex: -1 + boundsBehavior: Flickable.StopAtBounds + + section { + property: "KcmConnectionType" + delegate: Kirigami.AbstractListItem { + supportsMouseEvents: false + background: Rectangle { + color: palette.window + } + QtControls.Label { + id: headerLabel + anchors.centerIn: parent + font.weight: Font.DemiBold + text: section + } + } + } + + delegate: ConnectionItemDelegate { + onAboutToChangeConnection: { + // Shouldn't be problem to set this in advance + scrollablePage.currentConnectionExportable = exportable + if (kcm.needsSave) { + confirmSaveDialog.connectionName = name + confirmSaveDialog.connectionPath = path + confirmSaveDialog.open() + } else { + scrollablePage.currentConnectionName = name + scrollablePage.currentConnectionPath = path + } + } + + onAboutToExportConnection: { + requestExportConnection(path) + } + + onAboutToRemoveConnection: { + deleteConfirmationDialog.connectionName = name + deleteConfirmationDialog.connectionPath = path + deleteConfirmationDialog.open() + } + } + } + + onCurrentConnectionPathChanged: { + kcm.selectConnection(scrollablePage.currentConnectionPath) + } +} diff --git a/kcm/qml/ConfigurationDialog.qml b/kcm/package/contents/ui/editor/ConfigurationDialog.qml similarity index 100% rename from kcm/qml/ConfigurationDialog.qml rename to kcm/package/contents/ui/editor/ConfigurationDialog.qml diff --git a/kcm/package/contents/ui/editor/ConnectionEditor.qml b/kcm/package/contents/ui/editor/ConnectionEditor.qml new file mode 100644 index 00000000..7b586be9 --- /dev/null +++ b/kcm/package/contents/ui/editor/ConnectionEditor.qml @@ -0,0 +1,90 @@ +/* + 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 + +// FIXME add horizontal scrollbar? +Item { + id: connectionEditorTab + + QtControls.TextField { + id: connectionNameTextField + + anchors.top: parent.top + + hoverEnabled: true + } + + QtControls.TabBar { + id: tabBar + + width: parent.width + anchors { + top: connectionNameTextField.bottom + topMargin: Math.round(Units.gridUnit / 2) + } + + QtControls.TabButton { + text: i18n("Connection") + } + + // FIXME just placeholders for now + QtControls.TabButton { + text: i18n("Wireless") + } + + QtControls.TabButton { + text: i18n("Wireless security") + } + + QtControls.TabButton { + text: i18n("IPv4") + } + + QtControls.TabButton { + text: i18n("IPv6") + } + } + + StackLayout { + anchors { + horizontalCenter: parent.horizontalCenter + top: tabBar.bottom + topMargin: Math.round(Units.gridUnit / 2) + } + + currentIndex: tabBar.currentIndex + + ConnectionSetting { + id: connectionSetting + } + } + + function loadConnectionSetting() { + connectionNameTextField.text = connectionSettingObject.id + // Load general connection setting + connectionSetting.loadSetting() + } +} + diff --git a/kcm/package/contents/ui/editor/ConnectionSetting.qml b/kcm/package/contents/ui/editor/ConnectionSetting.qml new file mode 100644 index 00000000..9e6eebde --- /dev/null +++ b/kcm/package/contents/ui/editor/ConnectionSetting.qml @@ -0,0 +1,133 @@ +/* + 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 + + 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.CheckBox { + id: autoconnectVpnCheckbox + + Layout.fillWidth: true + + text: i18n("Automatically connect to VPN when using this connection") + } + + QtControls.ComboBox { + id: vpnListCombobox + + Layout.fillWidth: true + + model: connectionSettingObject.vpnConnections + } + + RowLayout { + ColumnLayout { + QtControls.Label { + Layout.fillHeight: true + Layout.alignment: Qt.AlignRight + + text: i18n("Firewall zone:") + } + + QtControls.Label { + Layout.fillHeight: true + Layout.alignment: Qt.AlignRight + + text: i18n("Priority:") + } + } + + ColumnLayout { + QtControls.ComboBox { + id: firewallZoneCombobox + + Layout.fillWidth: true + } + + QtControls.SpinBox { + id: prioritySpinBox + + Layout.fillWidth: true + + value: 0 + } + } + } + + function loadSetting() { + if (connectionSettingObject.connectionType == PlasmaNM.Enums.Vpn) { + autoconnectCheckbox.enabled = false + autoconnectVpnCheckbox.enabled = false + prioritySpinBox.enabled = false + vpnListCombobox.enabled = false + } else { + autoconnectCheckbox.enabled = true + autoconnectVpnCheckbox.enabled = true + prioritySpinBox.enabled = true + vpnListCombobox.enabled = true + } + + autoconnectCheckbox.checked = connectionSettingObject.autoconnect + allUsersAllowedCheckbox.checked = !connectionSettingObject.permissions.length + prioritySpinBox.value = connectionSettingObject.priority + + // TODO set firewall zone and vpn + } +} diff --git a/kcm/qml/Header.qml b/kcm/package/contents/ui/editor/Ipv4Setting.qml similarity index 65% rename from kcm/qml/Header.qml rename to kcm/package/contents/ui/editor/Ipv4Setting.qml index 3364c0c7..5269c2af 100644 --- a/kcm/qml/Header.qml +++ b/kcm/package/contents/ui/editor/Ipv4Setting.qml @@ -1,41 +1,19 @@ /* - Copyright 2013-2014 Jan Grulich + 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.2 -import org.kde.plasma.components 2.0 as PlasmaComponents - -ListItem { - id: header - - property alias text: headerLabel.text - - height: headerLabel.height + units.gridUnit - width: parent.width - sectionDelegate: true - - Text { - id: headerLabel - - anchors.centerIn: parent - color: textColor - height: paintedHeight - font.weight: Font.DemiBold - } -} diff --git a/libs/editor/settings/pppwidget.h b/kcm/package/contents/ui/editor/Ipv6Setting.qml similarity index 56% rename from libs/editor/settings/pppwidget.h rename to kcm/package/contents/ui/editor/Ipv6Setting.qml index bb6e0035..5269c2af 100644 --- a/libs/editor/settings/pppwidget.h +++ b/kcm/package/contents/ui/editor/Ipv6Setting.qml @@ -1,50 +1,19 @@ /* - Copyright 2013 Lukas Tinkl + 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_PPP_WIDGET_H -#define PLASMA_NM_PPP_WIDGET_H - -#include - -#include - -#include "settingwidget.h" - -namespace Ui -{ -class PPPWidget; -} - -class Q_DECL_EXPORT PPPWidget : public SettingWidget -{ - Q_OBJECT -public: - explicit PPPWidget(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~PPPWidget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - -private: - Ui::PPPWidget *m_ui; -}; - -#endif // PLASMA_NM_PPP_WIDGET_H diff --git a/kcm/package/contents/ui/main.qml b/kcm/package/contents/ui/main.qml new file mode 100755 index 00000000..7925c47e --- /dev/null +++ b/kcm/package/contents/ui/main.qml @@ -0,0 +1,258 @@ +/* + Copyright 2016-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 "editor" + +import QtQuick 2.6 +import QtQuick.Dialogs 1.1 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.5 as QQC2 + +import org.kde.kcm 1.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.plasma.networkmanagement 0.2 as PlasmaNM +import org.kde.kirigami 2.9 as Kirigami + +Kirigami.ApplicationItem { + id: root + + property QtObject connectionSettingObject: kcm.connectionSetting + + implicitWidth: Kirigami.Units.gridUnit * 20 + implicitHeight: Kirigami.Units.gridUnit * 20 + + SystemPalette { + id: palette + colorGroup: SystemPalette.Active + } + + PlasmaNM.Handler { + id: handler + } + + PlasmaNM.KcmIdentityModel { + id: connectionModel + } + + PlasmaNM.EditorProxyModel { + id: editorProxyModel + + sourceModel: connectionModel + } + + PlasmaNM.Configuration { + id: configuration + } + + RowLayout { + anchors.fill: parent + + spacing: units.smallSpacing + + ColumnLayout { + + spacing: units.smallSpacing + + ConnectionView { + id: connectionView + Layout.fillWidth: true + Layout.fillHeight: true + Layout.minimumWidth: 300 + Layout.preferredWidth: 400 + } + + RowLayout { + spacing: units.smallSpacing + + QQC2.TextField { + id: searchField + + Layout.fillWidth: true + + placeholderText: i18n("Search...") + + onTextChanged: { + editorProxyModel.setFilterRegExp(text) + } + } + + QQC2.ToolButton { + id: addConnectionButton + + width: Kirigami.Units.iconSizes.medium * 3 + height: Kirigami.Units.iconSizes.medium + + icon.name: "list-add" + + QQC2.ToolTip.text: i18n("Add new connection") + QQC2.ToolTip.visible: hovered + + onClicked: { + addNewConnectionDialog.open() + } + } + + QQC2.ToolButton { + id: removeConnectionButton + + height: Kirigami.Units.iconSizes.medium + width: Kirigami.Units.iconSizes.medium + + enabled: connectionView.currentConnectionPath && connectionView.currentConnectionPath.length + icon.name: "list-remove" + + QQC2.ToolTip.text: i18n("Remove selected connection") + QQC2.ToolTip.visible: hovered + + onClicked: { + deleteConfirmationDialog.connectionName = connectionView.currentConnectionName + deleteConfirmationDialog.connectionPath = connectionView.currentConnectionPath + deleteConfirmationDialog.open() + } + } + + QQC2.ToolButton { + id: exportConnectionButton + + height: Kirigami.Units.iconSizes.medium + width: Kirigami.Units.iconSizes.medium + + enabled: connectionView.currentConnectionExportable + icon.name: "document-export" + + QQC2.ToolTip.text: i18n("Export selected connection") + QQC2.ToolTip.visible: hovered + + onClicked: { + kcm.requestExportConnection(connectionView.currentConnectionPath) + } + } + } + } + + ConnectionEditor { + id: connectionEditor + + Layout.fillWidth: true + Layout.fillHeight: true + Layout.minimumWidth: childrenRect.width + } + } + + Row { + id: leftButtonRow + + anchors { + bottom: parent.bottom + left: parent.left + margins: units.smallSpacing + } + spacing: units.smallSpacing + + QQC2.ToolButton { + id: configureButton + + icon.name: "configure" + + QQC2.ToolTip.text: i18n("Configuration") + QQC2.ToolTip.visible: hovered + + onClicked: { + configurationDialog.open() + } + } + } + + MessageDialog { + id: deleteConfirmationDialog + + property string connectionName + property string connectionPath + + icon: StandardIcon.Question + standardButtons: StandardButton.Ok | StandardButton.Cancel + title: i18nc("@title:window", "Remove Connection") + text: i18n("Do you want to remove the connection '%1'?", connectionName) + + onAccepted: { + if (connectionPath == connectionView.currentConnectionPath) { + // Deselect now non-existing connection + deselectConnectionsInView() + } + handler.removeConnection(connectionPath) + } + } + + MessageDialog { + id: deleteConfirmationDialog + + property string connectionName + property string connectionPath + + /* Like QString::toHtmlEscaped */ + function toHtmlEscaped(s) { + return s.replace(/[&<>]/g, function (tag) { + return { + '&': '&', + '<': '<', + '>': '>' + }[tag] || tag + }); + } + + icon: StandardIcon.Question + standardButtons: StandardButton.Ok | StandardButton.Cancel + title: i18nc("@title:window", "Remove Connection") + text: i18n("Do you want to remove the connection '%1'?", toHtmlEscaped(connectionName)) + + onAccepted: { + if (connectionPath == connectionView.currentConnectionPath) { + // Deselect now non-existing connection + deselectConnections() + } + handler.removeConnection(connectionPath) + } + } + + AddConnectionDialog { + id: addNewConnectionDialog + + onRequestCreateConnection: { + root.requestCreateConnection(type, vpnType, specificType, shared) + } + } + + ConfigurationDialog { + id: configurationDialog + } + + function loadConnectionSetting() { + connectionEditor.loadConnectionSetting() + } + + function deselectConnectionsInView() { + connectionView.currentConnectionPath = "" + } + + function selectConnectionInView(connectionName, connectionPath) { + connectionView.currentConnectionName = connectionName + connectionView.currentConnectionPath = connectionPath + } +} diff --git a/kcm/package/metadata.desktop b/kcm/package/metadata.desktop new file mode 100644 index 00000000..1ab67c62 --- /dev/null +++ b/kcm/package/metadata.desktop @@ -0,0 +1,91 @@ +[Desktop Entry] +Name=Connections +Name[ar]=الاتّصالات +Name[ca]=Connexions +Name[ca@valencia]=Connexions +Name[cs]=Spojení +Name[da]=Forbindelser +Name[de]=Verbindungen +Name[el]=Συνδέσεις +Name[en_GB]=Connections +Name[es]=Conexiones +Name[eu]=Konexioak +Name[fi]=Yhteydet +Name[fr]=Connexions +Name[gl]=Conexións +Name[he]=חיבורים +Name[hu]=Kapcsolatok +Name[it]=Connessioni +Name[ko]=연결 +Name[lt]=Ryšiai +Name[nl]=Verbindingen +Name[nn]=Tilkoplingar +Name[pa]=ਕਨੈਕਸ਼ਨ +Name[pl]=Połączenia +Name[pt]=Ligações +Name[pt_BR]=Conexões +Name[ru]=Соединения +Name[sk]=Pripojenia +Name[sl]=Povezave +Name[sr]=Везе +Name[sr@ijekavian]=Везе +Name[sr@ijekavianlatin]=Veze +Name[sr@latin]=Veze +Name[sv]=Anslutningar +Name[tr]=Bağlantılar +Name[uk]=З’єднання +Name[x-test]=xxConnectionsxx +Name[zh_CN]=连接 +Name[zh_TW]=連線 +Comment=Edit your Network Connections +Comment[ar]=حرّر اتّصالاتك الشّبكيّة +Comment[ca]=Edita les connexions de xarxa +Comment[ca@valencia]=Edita les connexions de xarxa +Comment[cs]=Upravit vaše síťová spojení +Comment[da]=Redigér dine netværksforbindelser +Comment[de]=Bearbeiten Sie Ihre Netzwerkverbindungen +Comment[el]=Επεξεργασία των συνδέσεων δικτύου +Comment[en_GB]=Edit your Network Connections +Comment[es]=Editar las conexiones de red +Comment[eu]=Editatu zure sareko konexioak +Comment[fi]=Verkkoyhteyksien muokkaus +Comment[fr]=Modifier vos connexions réseau +Comment[gl]=Edite as súas conexións de rede +Comment[he]=ערוך את חיבורי הרשת שלך +Comment[hu]=A hálózati kapcsolatok szerkesztése +Comment[it]=Modifica le tue connessioni di rete +Comment[ko]=네트워크 연결 편집 +Comment[lt]=Keisti tinklo ryšius +Comment[nl]=Bewerk uw netwerkverbindingen +Comment[nn]=Rediger nettverkstilkoplingar +Comment[pa]=ਆਪਣੇ ਨੈੱਟਵਰਕ ਕਨੈਕਸ਼ਨਾਂ ਨੂੰ ਸੋਧੋ +Comment[pl]=Edytuj swoje połączenia sieciowe +Comment[pt]=Editar as Suas Ligações de Rede +Comment[pt_BR]=Edite suas conexões de rede +Comment[ru]=Настройка сетевых соединений +Comment[sk]=Upraviť vaše sieťové pripojenia +Comment[sl]=Uredite vaše omrežne povezave +Comment[sr]=Уређујте мрежне везе +Comment[sr@ijekavian]=Уређујте мрежне везе +Comment[sr@ijekavianlatin]=Uređujte mrežne veze +Comment[sr@latin]=Uređujte mrežne veze +Comment[sv]=Redigera dina nätverksanslutningar +Comment[tr]=Ağ bağlantılarınızı düzenleyin +Comment[uk]=Редагування ваших записів з’єднань з мережею +Comment[x-test]=xxEdit your Network Connectionsxx +Comment[zh_CN]=编辑您的网络连接 +Comment[zh_TW]=編輯您的網路連線 +Icon=preferences-system-network +Keywords= +Type=Service +X-KDE-ParentApp= +X-KDE-PluginInfo-Author=Jan Grulich +X-KDE-PluginInfo-Email=jgrulich@redhat.com +X-KDE-PluginInfo-License=GPL-2.0+ +X-KDE-PluginInfo-Name=kcm_networkmanagement +X-KDE-PluginInfo-Version= +X-KDE-PluginInfo-Website= +X-KDE-ServiceTypes=Plasma/Generic +X-Plasma-API=declarativeappletscript + +X-Plasma-MainScript=ui/main.qml diff --git a/kcm/qml/AddConnectionDialog.qml b/kcm/qml/AddConnectionDialog.qml deleted file mode 100644 index 2735ddc9..00000000 --- a/kcm/qml/AddConnectionDialog.qml +++ /dev/null @@ -1,192 +0,0 @@ -/* - Copyright 2016 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.3 -import QtQuick.Dialogs 1.2 -import QtQuick.Controls 1.2 as QtControls -import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons -import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.plasma.extras 2.0 as PlasmaExtras -import org.kde.plasma.networkmanagement 0.2 as PlasmaNM - -Dialog { - id: dialog - title: i18nc("@title:window", "Choose a Connection Type") - - signal requestCreateConnection(int type, string vpnType, string specificType, bool shared) - - contentItem: Item { - implicitHeight: 600 - implicitWidth: 500 - - PlasmaNM.CreatableConnectionsModel { - id: connectionModel - } - - Rectangle { - id: background - anchors.fill: parent - focus: true - color: baseColor - } - - QtControls.ScrollView { - id: scrollView - anchors { - bottom: buttonRow.top - bottomMargin: Math.round(units.gridUnit / 2) - left: parent.left - right: parent.right - top: parent.top - } - - ListView { - id: view - - property int currentlySelectedIndex: -1 - property bool connectionShared - property string connectionSpecificType - property int connectionType - property string connectionVpnType - - anchors.fill: parent - clip: true - model: connectionModel - currentIndex: -1 - boundsBehavior: Flickable.StopAtBounds - section.property: "ConnectionTypeSection" - section.delegate: Header { text: section } - delegate: ListItem { - checked: mouseArea.containsMouse || view.currentlySelectedIndex == index - height: connectionTypeBase.height - - Item { - id: connectionTypeBase - - anchors { - left: parent.left - right: parent.right - top: parent.top - // Reset top margin from PlasmaComponents.ListItem - topMargin: -Math.round(units.gridUnit / 3) - } - height: Math.max(units.iconSizes.medium, connectionNameLabel.height + connectionDescriptionLabel.height) + Math.round(units.gridUnit / 2) - - KQuickControlsAddons.QIconItem { - id: connectionIcon - - anchors { - left: parent.left - verticalCenter: parent.verticalCenter - } - height: units.iconSizes.medium; width: height - icon: ConnectionIcon - } - - Text { - id: connectionNameLabel - - anchors { - bottom: ConnectionType == 11 ? connectionIcon.verticalCenter : undefined - left: connectionIcon.right - leftMargin: Math.round(units.gridUnit / 2) - right: parent.right - verticalCenter: ConnectionType == 11 ? undefined : parent.verticalCenter - } - color: textColor - height: paintedHeight - elide: Text.ElideRight - text: ConnectionTypeName - textFormat: Text.PlainText - } - - Text { - id: connectionDescriptionLabel - - anchors { - left: connectionIcon.right - leftMargin: Math.round(units.gridUnit / 2) - right: parent.right - top: connectionNameLabel.bottom - } - color: textColor - height: visible ? paintedHeight : 0 - elide: Text.ElideRight - font.pointSize: theme.smallestFont.pointSize - opacity: 0.6 - text: ConnectionDescription - visible: ConnectionType == 11 // VPN - } - } - - MouseArea { - id: mouseArea - anchors.fill: parent - hoverEnabled: true - - onClicked: { - createButton.enabled = true - view.currentlySelectedIndex = index - view.connectionSpecificType = ConnectionSpecificType - view.connectionShared = ConnectionShared - view.connectionType = ConnectionType - view.connectionVpnType = ConnectionVpnType - } - - onDoubleClicked: { - dialog.close() - dialog.requestCreateConnection(view.connectionType, view.connectionVpnType, view.connectionSpecificType, view.connectionShared) - } - } - } - } - } - - Row { - id: buttonRow - anchors { - bottom: parent.bottom - right: parent.right - margins: Math.round(units.gridUnit / 2) - } - spacing: Math.round(units.gridUnit / 2) - - QtControls.Button { - id: createButton - enabled: false - text: i18n("Create") - - onClicked: { - dialog.close() - dialog.requestCreateConnection(view.connectionType, view.connectionVpnType, view.connectionSpecificType, view.connectionShared) - } - } - - QtControls.Button { - id: cancelButton - text: i18n("Cancel") - - onClicked: { - dialog.close() - } - } - } - } -} diff --git a/kcm/qml/ConnectionItem.qml b/kcm/qml/ConnectionItem.qml deleted file mode 100644 index 99a740ca..00000000 --- a/kcm/qml/ConnectionItem.qml +++ /dev/null @@ -1,167 +0,0 @@ -/* - Copyright 2016 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.1 -import QtQuick.Controls 1.4 as QQC -import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons -import org.kde.plasma.components 2.0 as PlasmaComponents -import org.kde.plasma.networkmanagement 0.2 as PlasmaNM - -ListItem { - id: connectionItem - - checked: mouseArea.containsMouse || ConnectionPath === connectionView.currentConnectionPath - height: connectionItemBase.height - - signal aboutToChangeConnection(bool exportable, string name, string path) - signal aboutToExportConnection(string path) - signal aboutToRemoveConnection(string name, string path) - - Item { - id: connectionItemBase - - anchors { - left: parent.left - right: parent.right - top: parent.top - topMargin: -Math.round(units.gridUnit / 3) - } - height: Math.max(units.iconSizes.medium, connectionNameLabel.height + connectionStatusLabel.height) + Math.round(units.gridUnit / 2) - - KQuickControlsAddons.QIconItem { - id: connectionIcon - - anchors { - left: parent.left - verticalCenter: parent.verticalCenter - } - height: units.iconSizes.medium; width: height - icon: KcmConnectionIcon - } - - Text { - id: connectionNameLabel - - anchors { - bottom: connectionIcon.verticalCenter - left: connectionIcon.right - leftMargin: Math.round(units.gridUnit / 2) - right: connectingIndicator.visible ? connectingIndicator.left : parent.right - } - color: textColor - height: paintedHeight - elide: Text.ElideRight - font.weight: ConnectionState == PlasmaNM.Enums.Activated ? Font.DemiBold : Font.Normal - font.italic: ConnectionState == PlasmaNM.Enums.Activating ? true : false - text: Name - textFormat: Text.PlainText - } - - Text { - id: connectionStatusLabel - - anchors { - left: connectionIcon.right - leftMargin: Math.round(units.gridUnit / 2) - right: connectingIndicator.visible ? connectingIndicator.left : parent.right - top: connectionNameLabel.bottom - } - color: textColor - height: paintedHeight - elide: Text.ElideRight - font.pointSize: theme.smallestFont.pointSize - opacity: 0.6 - text: itemText() - } - - PlasmaComponents.BusyIndicator { - id: connectingIndicator - - anchors { - right: parent.right - rightMargin: Math.round(units.gridUnit / 2) - verticalCenter: connectionIcon.verticalCenter - } - height: units.iconSizes.medium; width: height - running: ConnectionState == PlasmaNM.Enums.Activating - visible: running - } - } - - QQC.Menu { - id: connectionItemMenu - - QQC.MenuItem { - text: ConnectionState == PlasmaNM.Enums.Deactivated ? i18n("Connect") : i18n("Disconnect") - visible: ItemType == 1 - onTriggered: { - if (ConnectionState == PlasmaNM.Enums.Deactivated) { - handler.activateConnection(ConnectionPath, DevicePath, SpecificPath); - } else { - handler.deactivateConnection(ConnectionPath, DevicePath); - } - } - } - - QQC.MenuItem { - iconName: "list-remove" - text: i18n("Delete"); - - onTriggered: { - aboutToRemoveConnection(Name, ConnectionPath) - } - } - - QQC.MenuItem { - iconName: "document-export" - visible: KcmVpnConnectionExportable - text: i18n("Export"); - - onTriggered: aboutToExportConnection(ConnectionPath) - } - } - - MouseArea { - id: mouseArea - anchors.fill: parent - acceptedButtons: Qt.AllButtons; - hoverEnabled: true - - onClicked: { - if (mouse.button === Qt.LeftButton) { - aboutToChangeConnection(KcmVpnConnectionExportable, Name, ConnectionPath) - } else if (mouse.button == Qt.RightButton) { - connectionItemMenu.popup() - } - } - } - - /* This generates the status description under each connection - in the list at the left side of the applet. */ - function itemText() { - if (ConnectionState == PlasmaNM.Enums.Activated) { - return i18n("Connected") - } else if (ConnectionState == PlasmaNM.Enums.Activating) { - return i18n("Connecting") - } else { - return LastUsed - } - } -} diff --git a/kcm/qml/ListItem.qml b/kcm/qml/ListItem.qml deleted file mode 100644 index 3d5da486..00000000 --- a/kcm/qml/ListItem.qml +++ /dev/null @@ -1,93 +0,0 @@ -/* - Copyright 2010 Marco Martin - Copyright 2016 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.1 -import org.kde.plasma.core 2.0 as PlasmaCore - -Item { - id: listItem - - default property alias content: paddingItem.data - property alias containsMouse: itemMouse.containsMouse - property alias enabled: itemMouse.enabled - property bool checked: false - property bool sectionDelegate: false - - signal clicked - - width: parent ? parent.width : childrenRect.width - height: paddingItem.childrenRect.height + background.margins.top + background.margins.bottom - - implicitHeight: paddingItem.childrenRect.height + Math.round(units.gridUnit / 2) - - Connections { - target: listItem - onCheckedChanged: background.color = (listItem.checked ? highlightColor : baseColor) - onSectionDelegateChanged: background.color = (listItem.sectionDelegate ? alternateBaseColor : baseColor) - } - - Rectangle { - id : background - - anchors.fill: parent - visible: listItem.ListView.view ? listItem.ListView.view.highlight === null : true - opacity: itemMouse.containsMouse && !itemMouse.pressed ? 0.5 : 1 - Component.onCompleted: { - color = (listItem.sectionDelegate ? alternateBaseColor : (listItem.checked ? highlightColor : baseColor)) - } - Behavior on opacity { NumberAnimation { duration: units.longDuration } } - } - - PlasmaCore.SvgItem { - svg: PlasmaCore.Svg {imagePath: "widgets/listitem"} - elementId: "separator" - anchors { - left: parent.left - right: parent.right - top: parent.top - } - height: naturalSize.height - visible: listItem.sectionDelegate || (typeof(index) != "undefined" && index > 0 && !listItem.checked && !itemMouse.pressed) - } - - MouseArea { - id: itemMouse - property bool changeBackgroundOnPress: !listItem.checked && !listItem.sectionDelegate - anchors.fill: background - enabled: false - - onClicked: listItem.clicked() - onPressAndHold: listItem.pressAndHold() - onPressed: if (changeBackgroundOnPress) background.prefix = "pressed" - onReleased: if (changeBackgroundOnPress) background.prefix = "normal" - onCanceled: if (changeBackgroundOnPress) background.prefix = "normal" - - Item { - id: paddingItem - anchors { - fill: parent - margins: Math.round(units.gridUnit / 3) - } - } - } - - Accessible.role: Accessible.ListItem -} diff --git a/kcm/qml/main.qml b/kcm/qml/main.qml deleted file mode 100755 index 3ada6ac6..00000000 --- a/kcm/qml/main.qml +++ /dev/null @@ -1,268 +0,0 @@ -/* - Copyright 2016 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.1 -import QtQuick.Dialogs 1.1 -import QtQuick.Controls 2.5 as QQC2 -import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.plasma.extras 2.0 as PlasmaExtras -import org.kde.plasma.networkmanagement 0.2 as PlasmaNM -import org.kde.kirigami 2.9 as Kirigami - -Item { - id: root - - focus: true - - signal selectedConnectionChanged(string connection) - signal requestCreateConnection(int type, string vpnType, string specificType, bool shared) - signal requestExportConnection(string connection) - signal requestToChangeConnection(string name, string path) - - Kirigami.Theme.colorSet: Kirigami.Theme.Window - - Rectangle { - id: background - anchors.fill: parent - focus: true - color: Kirigami.Theme.backgroundColor - } - - PlasmaNM.Handler { - id: handler - } - - PlasmaNM.KcmIdentityModel { - id: connectionModel - } - - PlasmaNM.EditorProxyModel { - id: editorProxyModel - - sourceModel: connectionModel - } - - PlasmaNM.Configuration { - id: configuration - } - - QQC2.TextField { - id: searchField - - anchors { - left: parent.left - right: parent.right - top: parent.top - } - - placeholderText: i18n("Search...") - - onTextChanged: { - editorProxyModel.setFilterRegExp(text) - } - } - - QQC2.ScrollView { - id: scrollView - - Component.onCompleted: scrollView.background.visible = true // show frame - - anchors { - bottom: rightButtonRow.top - bottomMargin: units.smallSpacing - left: parent.left - right: parent.right - top: searchField.bottom - } - - ListView { - id: connectionView - - property bool currentConnectionExportable: false - property string currentConnectionName - property string currentConnectionPath - - clip: true - focus: true - activeFocusOnTab: true - model: editorProxyModel - currentIndex: -1 - boundsBehavior: Flickable.StopAtBounds - section.property: "KcmConnectionType" - section.delegate: Header { text: section } - delegate: ConnectionItem { - onAboutToChangeConnection: { - // Shouldn't be problem to set this in advance - connectionView.currentConnectionExportable = exportable - if (connectionModified) { - requestToChangeConnection(name, path) - } else { - connectionView.currentConnectionName = name - connectionView.currentConnectionPath = path - } - } - - onAboutToExportConnection: { - requestExportConnection(path) - } - - onAboutToRemoveConnection: { - deleteConfirmationDialog.connectionName = name - deleteConfirmationDialog.connectionPath = path - deleteConfirmationDialog.open() - } - } - - onCurrentConnectionPathChanged: { - root.selectedConnectionChanged(currentConnectionPath) - } - } - } - - Row { - id: rightButtonRow - - anchors { - bottom: parent.bottom - right: parent.right - margins: units.smallSpacing - } - spacing: units.smallSpacing - - QQC2.ToolButton { - id: addConnectionButton - - icon.name: "list-add" - - QQC2.ToolTip.text: i18n("Add new connection") - QQC2.ToolTip.visible: hovered - - onClicked: { - addNewConnectionDialog.open() - } - } - - QQC2.ToolButton { - id: removeConnectionButton - - enabled: connectionView.currentConnectionPath && connectionView.currentConnectionPath.length - icon.name: "list-remove" - - QQC2.ToolTip.text: i18n("Remove selected connection") - QQC2.ToolTip.visible: hovered - - onClicked: { - deleteConfirmationDialog.connectionName = connectionView.currentConnectionName - deleteConfirmationDialog.connectionPath = connectionView.currentConnectionPath - deleteConfirmationDialog.open() - } - } - - QQC2.ToolButton { - id: exportConnectionButton - - enabled: connectionView.currentConnectionExportable - icon.name: "document-export" - - QQC2.ToolTip.text: i18n("Export selected connection") - QQC2.ToolTip.visible: hovered - - onClicked: { - root.requestExportConnection(connectionView.currentConnectionPath) - } - } - } - - Row { - id: leftButtonRow - - anchors { - bottom: parent.bottom - left: parent.left - margins: units.smallSpacing - } - spacing: units.smallSpacing - - QQC2.ToolButton { - id: configureButton - - icon.name: "configure" - - QQC2.ToolTip.text: i18n("Configuration") - QQC2.ToolTip.visible: hovered - - onClicked: { - configurationDialog.open() - } - } - } - - MessageDialog { - id: deleteConfirmationDialog - - property string connectionName - property string connectionPath - - /* Like QString::toHtmlEscaped */ - function toHtmlEscaped(s) { - return s.replace(/[&<>]/g, function (tag) { - return { - '&': '&', - '<': '<', - '>': '>' - }[tag] || tag - }); - } - - icon: StandardIcon.Question - standardButtons: StandardButton.Ok | StandardButton.Cancel - title: i18nc("@title:window", "Remove Connection") - text: i18n("Do you want to remove the connection '%1'?", toHtmlEscaped(connectionName)) - - onAccepted: { - if (connectionPath == connectionView.currentConnectionPath) { - // Deselect now non-existing connection - deselectConnections() - } - handler.removeConnection(connectionPath) - } - } - - AddConnectionDialog { - id: addNewConnectionDialog - - onRequestCreateConnection: { - root.requestCreateConnection(type, vpnType, specificType, shared) - } - } - - ConfigurationDialog { - id: configurationDialog - } - - function deselectConnections() { - connectionView.currentConnectionPath = "" - } - - function selectConnection(connectionName, connectionPath) { - connectionView.currentConnectionName = connectionName - connectionView.currentConnectionPath = connectionPath - } -} diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 7e66d119..6bfbae52 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -1,42 +1,31 @@ add_definitions(-DTRANSLATION_DOMAIN=\"plasmanetworkmanagement-libs\") set(plasmanm_internal_SRCS - models/appletproxymodel.cpp - models/creatableconnectionsmodel.cpp - models/editorproxymodel.cpp - models/kcmidentitymodel.cpp - models/mobileproxymodel.cpp - models/networkitemslist.cpp - models/networkmodel.cpp - models/networkmodelitem.cpp - configuration.cpp debug.cpp handler.cpp uiutils.cpp ) add_library(plasmanm_internal SHARED ${plasmanm_internal_SRCS}) target_link_libraries(plasmanm_internal -PUBLIC KF5::NetworkManagerQt - plasmanm_editor - ${NETWORKMANAGER_LIBRARIES} -PRIVATE + KF5::ConfigCore + KF5::CoreAddons KF5::I18n KF5::IconThemes KF5::Notifications KF5::Service KF5::Wallet KF5::WindowSystem ) if (WITH_MODEMMANAGER_SUPPORT) target_link_libraries(plasmanm_internal PUBLIC KF5::ModemManagerQt) endif() install(TARGETS plasmanm_internal ${INSTALL_TARGETS_DEFAULT_ARGS}) add_subdirectory(declarative) add_subdirectory(editor) diff --git a/libs/declarative/CMakeLists.txt b/libs/declarative/CMakeLists.txt index 275cd531..b285a85f 100644 --- a/libs/declarative/CMakeLists.txt +++ b/libs/declarative/CMakeLists.txt @@ -1,26 +1,37 @@ -include_directories(${CMAKE_SOURCE_DIR}/libs/models) +include_directories(models) set(plasmanm_qml_plugins_SRCS - availabledevices.cpp - connectionicon.cpp - enabledconnections.cpp - enums.cpp - networkstatus.cpp - qmlplugins.cpp + # FIXME + ../debug.cpp + + availabledevices.cpp + connectionicon.cpp + enabledconnections.cpp + enums.cpp + networkstatus.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 - plasmanm_editor 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/models/appletproxymodel.cpp b/libs/declarative/models/appletproxymodel.cpp similarity index 100% rename from libs/models/appletproxymodel.cpp rename to libs/declarative/models/appletproxymodel.cpp diff --git a/libs/models/appletproxymodel.h b/libs/declarative/models/appletproxymodel.h similarity index 100% rename from libs/models/appletproxymodel.h rename to libs/declarative/models/appletproxymodel.h diff --git a/libs/models/creatableconnectionsmodel.cpp b/libs/declarative/models/creatableconnectionsmodel.cpp similarity index 100% rename from libs/models/creatableconnectionsmodel.cpp rename to libs/declarative/models/creatableconnectionsmodel.cpp diff --git a/libs/models/creatableconnectionsmodel.h b/libs/declarative/models/creatableconnectionsmodel.h similarity index 100% rename from libs/models/creatableconnectionsmodel.h rename to libs/declarative/models/creatableconnectionsmodel.h diff --git a/libs/models/editorproxymodel.cpp b/libs/declarative/models/editorproxymodel.cpp similarity index 100% rename from libs/models/editorproxymodel.cpp rename to libs/declarative/models/editorproxymodel.cpp diff --git a/libs/models/editorproxymodel.h b/libs/declarative/models/editorproxymodel.h similarity index 100% rename from libs/models/editorproxymodel.h rename to libs/declarative/models/editorproxymodel.h diff --git a/libs/models/kcmidentitymodel.cpp b/libs/declarative/models/kcmidentitymodel.cpp similarity index 100% rename from libs/models/kcmidentitymodel.cpp rename to libs/declarative/models/kcmidentitymodel.cpp diff --git a/libs/models/kcmidentitymodel.h b/libs/declarative/models/kcmidentitymodel.h similarity index 100% rename from libs/models/kcmidentitymodel.h rename to libs/declarative/models/kcmidentitymodel.h diff --git a/libs/models/networkitemslist.cpp b/libs/declarative/models/networkitemslist.cpp similarity index 100% rename from libs/models/networkitemslist.cpp rename to libs/declarative/models/networkitemslist.cpp diff --git a/libs/models/networkitemslist.h b/libs/declarative/models/networkitemslist.h similarity index 100% rename from libs/models/networkitemslist.h rename to libs/declarative/models/networkitemslist.h diff --git a/libs/models/networkmodel.cpp b/libs/declarative/models/networkmodel.cpp similarity index 100% rename from libs/models/networkmodel.cpp rename to libs/declarative/models/networkmodel.cpp diff --git a/libs/models/networkmodel.h b/libs/declarative/models/networkmodel.h similarity index 100% rename from libs/models/networkmodel.h rename to libs/declarative/models/networkmodel.h diff --git a/libs/models/networkmodelitem.cpp b/libs/declarative/models/networkmodelitem.cpp similarity index 100% rename from libs/models/networkmodelitem.cpp rename to libs/declarative/models/networkmodelitem.cpp diff --git a/libs/models/networkmodelitem.h b/libs/declarative/models/networkmodelitem.h similarity index 100% rename from libs/models/networkmodelitem.h rename to libs/declarative/models/networkmodelitem.h diff --git a/libs/editor/CMakeLists.txt b/libs/editor/CMakeLists.txt index e14a0183..e8cb27de 100644 --- a/libs/editor/CMakeLists.txt +++ b/libs/editor/CMakeLists.txt @@ -1,118 +1,48 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/widgets) set(plasmanm_editor_SRCS - settings/bondwidget.cpp - settings/bridgewidget.cpp - settings/btwidget.cpp - settings/cdmawidget.cpp - settings/connectionwidget.cpp - settings/gsmwidget.cpp - settings/infinibandwidget.cpp - settings/ipv4widget.cpp - settings/ipv6widget.cpp - settings/pppoewidget.cpp - settings/pppwidget.cpp - settings/security802-1x.cpp - settings/teamwidget.cpp - settings/vlanwidget.cpp - settings/wificonnectionwidget.cpp - settings/wifisecurity.cpp - settings/wiredconnectionwidget.cpp - settings/wiredsecurity.cpp - settings/wireguardinterfacewidget.cpp - settings/wireguardtabwidget.cpp - settings/wireguardpeerwidget.cpp + # FIXME + ../debug.cpp + + settings/connectionsetting.cpp + settings/setting.cpp - widgets/advancedpermissionswidget.cpp - widgets/bssidcombobox.cpp - widgets/delegate.cpp - widgets/editlistdialog.cpp - widgets/hwaddrcombobox.cpp - widgets/intdelegate.cpp - widgets/ipv4delegate.cpp - widgets/ipv4routeswidget.cpp - widgets/ipv6delegate.cpp - widgets/ipv6routeswidget.cpp widgets/passwordfield.cpp widgets/settingwidget.cpp - widgets/ssidcombobox.cpp - connectioneditorbase.cpp - connectioneditordialog.cpp - connectioneditortabwidget.cpp listvalidator.cpp simpleipv4addressvalidator.cpp simpleipv6addressvalidator.cpp simpleiplistvalidator.cpp wireguardkeyvalidator.cpp vpnuiplugin.cpp - - ../configuration.cpp - ../debug.cpp - ../uiutils.cpp ) if (WITH_MODEMMANAGER_SUPPORT) set(plasmanm_editor_SRCS ${plasmanm_editor_SRCS} widgets/mobileconnectionwizard.cpp mobileproviders.cpp) endif() -ki18n_wrap_ui(plasmanm_editor_SRCS - settings/ui/802-1x.ui - settings/ui/bond.ui - settings/ui/bridge.ui - settings/ui/bt.ui - settings/ui/cdma.ui - settings/ui/connectionwidget.ui - settings/ui/gsm.ui - settings/ui/infiniband.ui - settings/ui/ipv4.ui - settings/ui/ipv6.ui - settings/ui/ppp.ui - settings/ui/pppoe.ui - settings/ui/team.ui - settings/ui/vlan.ui - settings/ui/team.ui - settings/ui/wificonnectionwidget.ui - settings/ui/wifisecurity.ui - settings/ui/wiredconnectionwidget.ui - settings/ui/wiredsecurity.ui - settings/ui/wireguardinterfacewidget.ui - settings/ui/wireguardtabwidget.ui - settings/ui/wireguardpeerwidget.ui - - widgets/ui/advancedpermissionswidget.ui - widgets/ui/ipv4routes.ui - widgets/ui/ipv6routes.ui - - connectioneditortabwidget.ui -) - add_library(plasmanm_editor SHARED ${plasmanm_editor_SRCS}) target_link_libraries(plasmanm_editor -PUBLIC - KF5::ConfigWidgets - KF5::Completion - KF5::NetworkManagerQt - KF5::WidgetsAddons + plasmanm_internal + Qt5::DBus Qt5::Widgets -PRIVATE - KF5::IconThemes + KF5::CoreAddons + KF5::KDELibs4Support KF5::I18n - KF5::KIOWidgets - KF5::Notifications - KF5::Solid - KF5::Wallet - Qt5::DBus - Qt5::Network - qca-qt5 + KF5::NetworkManagerQt +# KF5::Declarative +# KF5::Notifications +# qca-qt5 ) if (WITH_MODEMMANAGER_SUPPORT) target_link_libraries(plasmanm_editor PUBLIC 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/connectioneditorbase.cpp b/libs/editor/connectioneditorbase.cpp deleted file mode 100644 index ccb30ddb..00000000 --- a/libs/editor/connectioneditorbase.cpp +++ /dev/null @@ -1,515 +0,0 @@ -/* - Copyright 2013-2016 Jan Grulich - Copyright 2013, 2014 Lukas Tinkl - - 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 "connectioneditorbase.h" - -#include "debug.h" -#include "settings/bondwidget.h" -#include "settings/bridgewidget.h" -#include "settings/btwidget.h" -#include "settings/cdmawidget.h" -#include "settings/connectionwidget.h" -#include "settings/gsmwidget.h" -#include "settings/infinibandwidget.h" -#include "settings/ipv4widget.h" -#include "settings/ipv6widget.h" -#include "settings/pppwidget.h" -#include "settings/pppoewidget.h" -#include "settings/teamwidget.h" -#include "settings/vlanwidget.h" -#include "settings/wificonnectionwidget.h" -#include "settings/wifisecurity.h" -#include "settings/wiredconnectionwidget.h" -#include "settings/wiredsecurity.h" -#include "settings/wireguardinterfacewidget.h" -#include "vpnuiplugin.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -ConnectionEditorBase::ConnectionEditorBase(const NetworkManager::ConnectionSettings::Ptr &connection, - QWidget *parent, Qt::WindowFlags f) - : QWidget(parent, f) - , m_initialized(false) - , m_valid(false) - , m_pendingReplies(0) - , m_connection(connection) -{ -} - -ConnectionEditorBase::ConnectionEditorBase(QWidget *parent, Qt::WindowFlags f) - : QWidget(parent, f) -{ -} - -ConnectionEditorBase::~ConnectionEditorBase() -{ - m_connection.clear(); -} - -void ConnectionEditorBase::setConnection(const NetworkManager::ConnectionSettings::Ptr &connection) -{ - // Set connection settings - m_connection.clear(); - m_connection = connection; - m_initialized = false; - - // Reset UI setting widgets - delete m_connectionWidget; - m_connectionWidget = nullptr; - qDeleteAll(m_settingWidgets); - m_settingWidgets.clear(); - - initialize(); -} - -NMVariantMapMap ConnectionEditorBase::setting() const -{ - NMVariantMapMap settings = m_connectionWidget->setting(); - - for (SettingWidget *widget : m_settingWidgets) { - const QString type = widget->type(); - if (type != NetworkManager::Setting::typeAsString(NetworkManager::Setting::Security8021x) && - type != NetworkManager::Setting::typeAsString(NetworkManager::Setting::WirelessSecurity)) { - settings.insert(type, widget->setting()); - } - - // add 802.1x security if needed - QVariantMap security8021x; - if (type == NetworkManager::Setting::typeAsString(NetworkManager::Setting::WirelessSecurity)) { - WifiSecurity *wifiSecurity = static_cast(widget); - if (wifiSecurity->enabled()) { - settings.insert(type, wifiSecurity->setting()); - } - if (wifiSecurity->enabled8021x()) { - security8021x = static_cast(widget)->setting8021x(); - settings.insert(NetworkManager::Setting::typeAsString(NetworkManager::Setting::Security8021x), security8021x); - } - } else if (type == NetworkManager::Setting::typeAsString(NetworkManager::Setting::Security8021x)) { - WiredSecurity *wiredSecurity = static_cast(widget); - if (wiredSecurity->enabled8021x()) { - security8021x = static_cast(widget)->setting(); - settings.insert(NetworkManager::Setting::typeAsString(NetworkManager::Setting::Security8021x), security8021x); - } - } - } - - // Set properties which are not returned from setting widgets - NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(m_connection->connectionType())); - - connectionSettings->fromMap(settings); - connectionSettings->setId(connectionName()); - if (connectionSettings->connectionType() == NetworkManager::ConnectionSettings::WireGuard) - connectionSettings->setInterfaceName(connectionName()); - connectionSettings->setUuid(m_connection->uuid()); - - if (connectionSettings->connectionType() == NetworkManager::ConnectionSettings::Wireless) { - NetworkManager::WirelessSecuritySetting::Ptr securitySetting = connectionSettings->setting(NetworkManager::Setting::WirelessSecurity).staticCast(); - NetworkManager::WirelessSetting::Ptr wirelessSetting = connectionSettings->setting(NetworkManager::Setting::Wireless).staticCast(); - - if (securitySetting && wirelessSetting) { - if (securitySetting->keyMgmt() != NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting::Unknown) { - wirelessSetting->setSecurity("802-11-wireless-security"); - } - - if (securitySetting->keyMgmt() == NetworkManager::WirelessSecuritySetting::SAE && - wirelessSetting->mode() == NetworkManager::WirelessSetting::Adhoc) { - // Ad-Hoc settings as specified by the supplicant - // Proto - QList protoVersions = securitySetting->proto(); - protoVersions << NetworkManager::WirelessSecuritySetting::Rsn; - securitySetting->setProto(protoVersions); - // Pairwise - QList pairwiseEncrypts = securitySetting->pairwise(); - pairwiseEncrypts << NetworkManager::WirelessSecuritySetting::Ccmp; - securitySetting->setPairwise(pairwiseEncrypts); - // Group - QList groupEncrypts = securitySetting->group(); - groupEncrypts << NetworkManager::WirelessSecuritySetting::Ccmp; - securitySetting->setGroup(groupEncrypts); - } - } - } - return connectionSettings->toMap(); -} - -bool ConnectionEditorBase::isInitialized() const -{ - return m_initialized; -} - -bool ConnectionEditorBase::isValid() const -{ - return m_valid; -} - -void ConnectionEditorBase::addConnectionWidget(ConnectionWidget *widget, const QString &text) -{ - m_connectionWidget = widget; - - connect(widget, &ConnectionWidget::settingChanged, this, &ConnectionEditorBase::settingChanged); - - addWidget(widget, text); -} - -void ConnectionEditorBase::addSettingWidget(SettingWidget *widget, const QString &text) -{ - m_settingWidgets << widget; - - connect(widget, &SettingWidget::settingChanged, this, &ConnectionEditorBase::settingChanged); - - addWidget(widget, text); -} - -void ConnectionEditorBase::initialize() -{ - const bool emptyConnection = m_connection->id().isEmpty(); - const NetworkManager::ConnectionSettings::ConnectionType type = m_connection->connectionType(); - - if (emptyConnection) { - m_connection->addToPermissions(KUser().loginName(), QString()); - } - - // General configuration common to all connection types - ConnectionWidget *connectionWidget = new ConnectionWidget(m_connection); - addConnectionWidget(connectionWidget, i18nc("General", "General configuration")); - - // 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) { - 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, QOverload::of(&WifiConnectionWidget::ssidChanged), wifiSecurity, &WifiSecurity::onSsidChanged); - } 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->id(), 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->id(), 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->id(), m_connection->setting(NetworkManager::Setting::Team), this); - addSettingWidget(teamWidget, i18n("Team")); - } else if (type == NetworkManager::ConnectionSettings::WireGuard) { // WireGuard - WireGuardInterfaceWidget *wireGuardInterfaceWidget = new WireGuardInterfaceWidget(m_connection->setting(NetworkManager::Setting::WireGuard), this); - addSettingWidget(wireGuardInterfaceWidget, i18n("WireGuard Interface")); - } else if (type == NetworkManager::ConnectionSettings::Vpn) { // VPN - QString error; - VpnUiPlugin *vpnPlugin = nullptr; - 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 - || type == NetworkManager::ConnectionSettings::Team - || type == NetworkManager::ConnectionSettings::Cdma - || type == NetworkManager::ConnectionSettings::Gsm - || type == NetworkManager::ConnectionSettings::Bond - || type == NetworkManager::ConnectionSettings::Bridge - || type == NetworkManager::ConnectionSettings::Vlan - || type == NetworkManager::ConnectionSettings::WireGuard - || (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")); - } - - // Re-check validation - bool valid = true; - for (SettingWidget *widget : m_settingWidgets) { - valid = valid && widget->isValid(); - connect(widget, &SettingWidget::validChanged, this, &ConnectionEditorBase::validChanged); - } - - m_valid = valid; - Q_EMIT validityChanged(valid); - - KAcceleratorManager::manage(this); - - // If the connection is not empty (not new) we want to load its secrets - if (!emptyConnection) { - NetworkManager::Connection::Ptr connection = NetworkManager::findConnectionByUuid(m_connection->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::WireGuard) { - NetworkManager::WireGuardSetting::Ptr securitySetting = connection->settings()->setting(NetworkManager::Setting::WireGuard).staticCast(); - if (securitySetting && !securitySetting->needSecrets().isEmpty()) { - requiredSecrets = securitySetting->needSecrets(); - setting = securitySetting->toMap(); - settingName = QLatin1String("wireguard"); - } - } 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) { - NetworkManager::VpnSetting::Ptr vpnSetting = connection->settings()->setting(NetworkManager::Setting::Vpn).staticCast(); - for (const QString &key : vpnSetting->data().keys()) { - if (key.endsWith(QStringLiteral("-flags"))) { - NetworkManager::Setting::SecretFlagType secretFlag = (NetworkManager::Setting::SecretFlagType)vpnSetting->data().value(key).toInt(); - if (secretFlag == NetworkManager::Setting::None || secretFlag == NetworkManager::Setting::AgentOwned) { - requestSecrets = true; - } - } - } - } else { - for (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 (m_pendingReplies == 0) { - m_initialized = true; - } -} - -void ConnectionEditorBase::replyFinished(QDBusPendingCallWatcher *watcher) -{ - QDBusPendingReply reply = *watcher; - const QString settingName = watcher->property("settingName").toString(); - if (reply.isValid()) { - NMVariantMapMap secrets = reply.argumentAt<0>(); - for (const QString &key : secrets.keys()) { - if (key == settingName) { - NetworkManager::Setting::Ptr setting = m_connection->setting(NetworkManager::Setting::typeFromString(key)); - if (setting) { - setting->secretsFromMap(secrets.value(key)); - for (SettingWidget *widget : m_settingWidgets) { - const QString type = widget->type(); - if (type == settingName || - (settingName == NetworkManager::Setting::typeAsString(NetworkManager::Setting::Security8021x) && - type == NetworkManager::Setting::typeAsString(NetworkManager::Setting::WirelessSecurity))) { - widget->loadSecrets(setting); - } - } - } - } - } - } else { - KNotification *notification = new KNotification("FailedToGetSecrets", KNotification::CloseOnTimeout); - notification->setComponentName("networkmanagement"); - notification->setTitle(i18n("Failed to get secrets for %1", watcher->property("connection").toString())); - notification->setText(reply.error().message()); - notification->setIconName(QStringLiteral("dialog-warning")); - notification->sendEvent(); - } - - watcher->deleteLater(); - validChanged(true); - - // We should be now fully with secrets - m_pendingReplies--; - m_initialized = true; -} - -void ConnectionEditorBase::validChanged(bool valid) -{ - if (!valid) { - m_valid = false; - Q_EMIT validityChanged(false); - return; - } else { - for (SettingWidget *widget : m_settingWidgets) { - if (!widget->isValid()) { - m_valid = false; - Q_EMIT validityChanged(false); - return; - } - } - } - - m_valid = true; - Q_EMIT validityChanged(true); -} diff --git a/libs/editor/connectioneditorbase.h b/libs/editor/connectioneditorbase.h deleted file mode 100644 index e8b5b8c6..00000000 --- a/libs/editor/connectioneditorbase.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright 2013-2016 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_EDITOR_BASE_H -#define PLASMA_NM_CONNECTION_EDITOR_BASE_H - -#include -#include - -#include - -class ConnectionWidget; -class SettingWidget; - -class Q_DECL_EXPORT ConnectionEditorBase : public QWidget -{ -Q_OBJECT -public: - explicit ConnectionEditorBase(const NetworkManager::ConnectionSettings::Ptr &connection, - QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - explicit ConnectionEditorBase(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - ~ConnectionEditorBase() override; - - // When reimplementing do not forget to call the base method as well to initialize widgets - virtual void setConnection(const NetworkManager::ConnectionSettings::Ptr &connection); - - NMVariantMapMap setting() const; - - // Returns whether the editor is fully initialized (including secrets) - bool isInitialized() const; - - // Returns whether the filled values are valid - 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); - - // Emitted when user changed configuration - void settingChanged(); - -private Q_SLOTS: - void replyFinished(QDBusPendingCallWatcher *watcher); - void validChanged(bool valid); - -protected: - // Subclassed widget is supposed to take care of layouting for setting widgets - virtual void addWidget(QWidget *widget, const QString &text) = 0; - - // Subclassed widget is supposed to provide an UI (input label) for editing connection name separately - virtual QString connectionName() const = 0; - - // Subclassed widget is supposed to call initialization after the UI is initialized - void initialize(); - -private: - bool m_initialized; - bool m_valid; - int m_pendingReplies; - NetworkManager::ConnectionSettings::Ptr m_connection; - ConnectionWidget *m_connectionWidget; - QList m_settingWidgets; - - void addConnectionWidget(ConnectionWidget *widget, const QString &text); - void addSettingWidget(SettingWidget *widget, const QString &text); - -}; - -#endif // PLASMA_NM_CONNECTION_EDITOR_BASE_H diff --git a/libs/editor/connectioneditordialog.cpp b/libs/editor/connectioneditordialog.cpp deleted file mode 100644 index 898970dc..00000000 --- a/libs/editor/connectioneditordialog.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - Copyright 2016 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 "connectioneditordialog.h" - -#include -#include -#include - -#include - -ConnectionEditorDialog::ConnectionEditorDialog(const NetworkManager::ConnectionSettings::Ptr &connection, - QWidget *parent, Qt::WindowFlags f) - : QDialog(parent, f) - , m_buttonBox(new QDialogButtonBox(this)) - , m_connectionEditorTabWidget(new ConnectionEditorTabWidget(connection, parent, f)) -{ - QVBoxLayout *layout = new QVBoxLayout(this); - layout->addWidget(m_connectionEditorTabWidget); - - m_buttonBox->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel); - m_buttonBox->button(QDialogButtonBox::Save)->setEnabled(m_connectionEditorTabWidget->isValid()); - layout->addWidget(m_buttonBox); - - setLayout(layout); - - connect(m_buttonBox, &QDialogButtonBox::accepted, this, &ConnectionEditorDialog::accept); - connect(m_buttonBox, &QDialogButtonBox::rejected, this, &ConnectionEditorDialog::reject); - connect(m_connectionEditorTabWidget, &ConnectionEditorTabWidget::validityChanged, this, &ConnectionEditorDialog::onValidityChanged); - - if (connection->id().isEmpty()) { - setWindowTitle(i18n("New Connection (%1)", connection->typeAsString(connection->connectionType()))); - } else { - setWindowTitle(i18n("Edit Connection '%1'", connection->id())); - } -} - -ConnectionEditorDialog::~ConnectionEditorDialog() -{ -} - -NMVariantMapMap ConnectionEditorDialog::setting() const -{ - return m_connectionEditorTabWidget->setting(); -} - -void ConnectionEditorDialog::onValidityChanged(bool valid) -{ - m_buttonBox->button(QDialogButtonBox::Save)->setEnabled(valid); -} - diff --git a/libs/editor/connectioneditordialog.h b/libs/editor/connectioneditordialog.h deleted file mode 100644 index 75900a11..00000000 --- a/libs/editor/connectioneditordialog.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright 2016 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_EDITOR_DIALOG_H -#define PLASMA_NM_CONNECTION_EDITOR_DIALOG_H - -#include "connectioneditortabwidget.h" - -#include -#include -#include - -class Q_DECL_EXPORT ConnectionEditorDialog : public QDialog -{ -Q_OBJECT -public: - explicit ConnectionEditorDialog(const NetworkManager::ConnectionSettings::Ptr &connection, - QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - ~ConnectionEditorDialog() override; - - NMVariantMapMap setting() const; - -private Q_SLOTS: - void onValidityChanged(bool valid); - -private: - QDialogButtonBox *m_buttonBox; - ConnectionEditorTabWidget *m_connectionEditorTabWidget; -}; - -#endif // PLASMA_NM_CONNECTION_EDITOR_BASE_H - diff --git a/libs/editor/connectioneditortabwidget.cpp b/libs/editor/connectioneditortabwidget.cpp deleted file mode 100644 index 96a94b3f..00000000 --- a/libs/editor/connectioneditortabwidget.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - Copyright 2016 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 "connectioneditortabwidget.h" -#include "ui_connectioneditortabwidget.h" - -ConnectionEditorTabWidget::ConnectionEditorTabWidget(const NetworkManager::ConnectionSettings::Ptr &connection, - QWidget *parent, Qt::WindowFlags f) - : ConnectionEditorBase(connection, parent, f) - , m_ui(new Ui::ConnectionEditorTabWidget) -{ - m_ui->setupUi(this); - m_ui->tabWidget->setUsesScrollButtons(false); - - connect(m_ui->connectionName, &QLineEdit::textChanged, this, &ConnectionEditorTabWidget::settingChanged); - - initialize(); - - initializeTabWidget(connection); -} - -void ConnectionEditorTabWidget::setConnection(const NetworkManager::ConnectionSettings::Ptr &connection) -{ - // Init tabs first as we need to set current tab after that - ConnectionEditorBase::setConnection(connection); - - initializeTabWidget(connection); -} - -ConnectionEditorTabWidget::~ConnectionEditorTabWidget() -{ -} - -void ConnectionEditorTabWidget::addWidget(QWidget *widget, const QString &text) -{ - m_ui->tabWidget->addTab(widget, text); -} - -QString ConnectionEditorTabWidget::connectionName() const -{ - return m_ui->connectionName->text(); -} - -void ConnectionEditorTabWidget::initializeTabWidget(const NetworkManager::ConnectionSettings::Ptr &connection) -{ - if (connection->id().isEmpty()) { - m_ui->connectionName->setText(i18n("New %1 connection", connection->typeAsString(connection->connectionType()))); - } else { - m_ui->connectionName->setText(connection->id()); - } - - // Set current tab to the connection specific configuration - m_ui->tabWidget->setCurrentIndex(1); -} diff --git a/libs/editor/connectioneditortabwidget.h b/libs/editor/connectioneditortabwidget.h deleted file mode 100644 index 5d5426d8..00000000 --- a/libs/editor/connectioneditortabwidget.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright 2016 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_EDITOR_TAB_WIDGET_H -#define PLASMA_NM_CONNECTION_EDITOR_TAB_WIDGET_H - -#include "connectioneditorbase.h" - -#include -#include - -namespace Ui -{ -class ConnectionEditorTabWidget; -} - -class Q_DECL_EXPORT ConnectionEditorTabWidget : public ConnectionEditorBase -{ -Q_OBJECT -public: - explicit ConnectionEditorTabWidget(const NetworkManager::ConnectionSettings::Ptr &connection, - QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - ~ConnectionEditorTabWidget() override; - - void setConnection(const NetworkManager::ConnectionSettings::Ptr &connection) override; - -protected: - void addWidget(QWidget *widget, const QString &text) override; - QString connectionName() const override; - -private: - Ui::ConnectionEditorTabWidget *m_ui; - - void initializeTabWidget(const NetworkManager::ConnectionSettings::Ptr &connection); -}; - -#endif // PLASMA_NM_CONNECTION_EDITOR_TAB_WIDGET_H - diff --git a/libs/editor/connectioneditortabwidget.ui b/libs/editor/connectioneditortabwidget.ui deleted file mode 100644 index d6222e9a..00000000 --- a/libs/editor/connectioneditortabwidget.ui +++ /dev/null @@ -1,41 +0,0 @@ - - - ConnectionEditorTabWidget - - - - 0 - 0 - 498 - 427 - - - - - - - Connection name: - - - connectionName - - - - - - - - - - -1 - - - Qt::ElideRight - - - - - - - - diff --git a/libs/editor/settings/bondwidget.cpp b/libs/editor/settings/bondwidget.cpp deleted file mode 100644 index a0f2d1d3..00000000 --- a/libs/editor/settings/bondwidget.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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 "bondwidget.h" -#include "ui_bond.h" -#include "connectioneditordialog.h" -#include "debug.h" - -#include - -#include -#include -#include -#include - -#include -#include - -#define NM_SETTING_BOND_OPTION_MII_MONITOR "mii" -#define NM_SETTING_BOND_OPTION_ARP_MONITOR "arp" - -BondWidget::BondWidget(const QString & masterUuid, const QString &masterId, - const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting, parent, f), - m_uuid(masterUuid), - m_id(masterId), - m_ui(new Ui::BondWidget) -{ - m_ui->setupUi(this); - - // Action buttons and menu - m_menu = new QMenu(this); - QAction * action = new QAction(i18n("Ethernet"), this); - action->setData(NetworkManager::ConnectionSettings::Wired); - m_menu->addAction(action); - action = new QAction(i18n("InfiniBand"), this); - action->setData(NetworkManager::ConnectionSettings::Infiniband); - m_menu->addAction(action); - m_ui->btnAdd->setMenu(m_menu); - connect(m_menu, &QMenu::triggered, this, &BondWidget::addBond); - connect(m_ui->btnEdit, &QPushButton::clicked, this, &BondWidget::editBond); - connect(m_ui->btnDelete, &QPushButton::clicked, this, &BondWidget::deleteBond); - - // mode - m_ui->mode->addItem(i18nc("bond mode", "Round-robin"), QLatin1String("balance-rr")); - m_ui->mode->addItem(i18nc("bond mode", "Active backup"), QLatin1String("active-backup")); - m_ui->mode->addItem(i18nc("bond mode", "Broadcast"), QLatin1String("broadcast")); - m_ui->mode->addItem(i18nc("bond mode", "802.3ad"), QLatin1String("802.3ad")); - m_ui->mode->addItem(i18nc("bond mode", "Adaptive transmit load balancing"), QLatin1String("balance-tlb")); - m_ui->mode->addItem(i18nc("bond mode", "Adaptive load balancing"), QLatin1String("balance-alb")); - - // link monitor - m_ui->linkMonitoring->addItem(i18nc("bond link monitoring", "MII (recommended)"), NM_SETTING_BOND_OPTION_MII_MONITOR); - m_ui->linkMonitoring->addItem(i18nc("bond link monitoring", "ARP"), NM_SETTING_BOND_OPTION_ARP_MONITOR); - - // bonds - populateBonds(); - connect(m_ui->bonds, &QListWidget::currentItemChanged, this, &BondWidget::currentBondChanged); - connect(m_ui->bonds, &QListWidget::itemDoubleClicked, this, &BondWidget::editBond); - - connect(m_ui->ifaceName, &KLineEdit::textChanged, this, &BondWidget::slotWidgetChanged); - connect(m_ui->arpTargets, &KLineEdit::textChanged, this, &BondWidget::slotWidgetChanged); - connect(m_ui->linkMonitoring, QOverload::of(&KComboBox::currentIndexChanged), this, &BondWidget::slotWidgetChanged); - - // Connect for setting check - watchChangedSetting(); - - KAcceleratorManager::manage(this); - KAcceleratorManager::manage(m_menu); - - if (setting) { - loadConfig(setting); - } -} - -BondWidget::~BondWidget() -{ - delete m_ui; -} - -void BondWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::BondSetting::Ptr bondSetting = setting.staticCast(); - - m_ui->ifaceName->setText(bondSetting->interfaceName()); - - const NMStringMap options = bondSetting->options(); - - // mode - int modeIndex = m_ui->mode->findData(options.value(NM_SETTING_BOND_OPTION_MODE)); - if (modeIndex == -1) - modeIndex = 0; - m_ui->mode->setCurrentIndex(modeIndex); - - const QString arpTargets = options.value(NM_SETTING_BOND_OPTION_ARP_IP_TARGET); - if (!arpTargets.isEmpty()) { // ARP - m_ui->linkMonitoring->setCurrentIndex(m_ui->linkMonitoring->findData(NM_SETTING_BOND_OPTION_ARP_MONITOR)); - - bool ok = false; - const int arpMonFreq = options.value(NM_SETTING_BOND_OPTION_ARP_INTERVAL).toInt(&ok); - if (ok && arpMonFreq > 0) - m_ui->monitorFreq->setValue(arpMonFreq); - - m_ui->arpTargets->setText(arpTargets); - } else { // MII - m_ui->linkMonitoring->setCurrentIndex(m_ui->linkMonitoring->findData(NM_SETTING_BOND_OPTION_MII_MONITOR)); - - bool ok = false; - const int miiMonFreq = options.value(NM_SETTING_BOND_OPTION_MIIMON).toInt(&ok); - if (ok && miiMonFreq > 0) - m_ui->monitorFreq->setValue(miiMonFreq); - - ok = false; - const int upDelay = options.value(NM_SETTING_BOND_OPTION_UPDELAY).toInt(&ok); - if (ok && upDelay > 0) - m_ui->upDelay->setValue(upDelay); - - ok = false; - const int downDelay = options.value(NM_SETTING_BOND_OPTION_DOWNDELAY).toInt(&ok); - if (ok && downDelay > 0) - m_ui->upDelay->setValue(downDelay); - } -} - -QVariantMap BondWidget::setting() const -{ - NetworkManager::BondSetting setting; - setting.setInterfaceName(m_ui->ifaceName->text()); - - NMStringMap options; - options.insert(NM_SETTING_BOND_OPTION_MODE, m_ui->mode->itemData(m_ui->mode->currentIndex()).toString()); - - if (m_ui->linkMonitoring->itemData(m_ui->linkMonitoring->currentIndex()).toString() == NM_SETTING_BOND_OPTION_MII_MONITOR) { // MII - options.insert(NM_SETTING_BOND_OPTION_MIIMON, QString::number(m_ui->monitorFreq->value())); - const int upDelay = m_ui->upDelay->value(); - if (upDelay) - options.insert(NM_SETTING_BOND_OPTION_UPDELAY, QString::number(upDelay)); - const int downDelay = m_ui->downDelay->value(); - if (downDelay) - options.insert(NM_SETTING_BOND_OPTION_DOWNDELAY, QString::number(downDelay)); - } else { // ARP - options.insert(NM_SETTING_BOND_OPTION_ARP_INTERVAL, QString::number(m_ui->monitorFreq->value())); - const QString arpTargets = m_ui->arpTargets->text(); - if (!arpTargets.isEmpty()) - options.insert(NM_SETTING_BOND_OPTION_ARP_IP_TARGET, arpTargets); - } - - setting.setOptions(options); - return setting.toMap(); -} - -void BondWidget::addBond(QAction *action) -{ - qCDebug(PLASMA_NM) << "Adding bonded connection:" << action->data(); - qCDebug(PLASMA_NM) << "Master UUID:" << m_uuid; - qCDebug(PLASMA_NM) << "Slave type:" << type(); - - NetworkManager::ConnectionSettings::ConnectionType connectionType = static_cast(action->data().toInt()); - NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(connectionType)); - connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); - connectionSettings->setMaster(m_uuid); - connectionSettings->setSlaveType(type()); - connectionSettings->setAutoconnect(false); - - QPointer bondEditor = new ConnectionEditorDialog(connectionSettings); - connect(bondEditor.data(), &ConnectionEditorDialog::accepted, - [bondEditor, this] () { - qCDebug(PLASMA_NM) << "Saving slave connection"; - // qCDebug(PLASMA_NM) << bondEditor->setting(); - QDBusPendingReply reply = NetworkManager::addConnection(bondEditor->setting()); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); - connect(watcher, &QDBusPendingCallWatcher::finished, this, &BondWidget::bondAddComplete); - }); - connect(bondEditor.data(), &ConnectionEditorDialog::finished, - [bondEditor] () { - if (bondEditor) { - bondEditor->deleteLater(); - } - }); - bondEditor->setModal(true); - bondEditor->show(); -} - -void BondWidget::currentBondChanged(QListWidgetItem *current, QListWidgetItem *previous) -{ - Q_UNUSED(previous) - - m_ui->btnEdit->setEnabled(current); - m_ui->btnDelete->setEnabled(current); -} - -void BondWidget::bondAddComplete(QDBusPendingCallWatcher * watcher) -{ - QDBusPendingReply reply = *watcher; - - if (reply.isValid()) { - // find the slave connection with matching UUID - NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(reply.value().path()); - if (connection && connection->settings()->master() == m_uuid) { - const QString label = QString("%1 (%2)").arg(connection->name()).arg(connection->settings()->typeAsString(connection->settings()->connectionType())); - QListWidgetItem * slaveItem = new QListWidgetItem(label, m_ui->bonds); - slaveItem->setData(Qt::UserRole, connection->uuid()); - slotWidgetChanged(); - } - } else { - qCWarning(PLASMA_NM) << "Bonded connection not added:" << reply.error().message(); - } -} - -void BondWidget::editBond() -{ - QListWidgetItem * currentItem = m_ui->bonds->currentItem(); - if (!currentItem) - return; - - const QString uuid = currentItem->data(Qt::UserRole).toString(); - NetworkManager::Connection::Ptr connection = NetworkManager::findConnectionByUuid(uuid); - - if (connection) { - // qCDebug(PLASMA_NM) << "Editing bonded connection" << currentItem->text() << uuid; - QPointer bondEditor = new ConnectionEditorDialog(connection->settings()); - connect(bondEditor.data(), &ConnectionEditorDialog::accepted, - [connection, bondEditor, this] () { - connection->update(bondEditor->setting()); - connect(connection.data(), &NetworkManager::Connection::updated, this, &BondWidget::populateBonds); - }); - connect(bondEditor.data(), &ConnectionEditorDialog::finished, - [bondEditor] () { - if (bondEditor) { - bondEditor->deleteLater(); - } - }); - bondEditor->setModal(true); - bondEditor->show(); - } -} - -void BondWidget::deleteBond() -{ - QListWidgetItem * currentItem = m_ui->bonds->currentItem(); - if (!currentItem) - return; - - const QString uuid = currentItem->data(Qt::UserRole).toString(); - NetworkManager::Connection::Ptr connection = NetworkManager::findConnectionByUuid(uuid); - - if (connection) { - // qCDebug(PLASMA_NM) << "About to delete bonded connection" << currentItem->text() << uuid; - if (KMessageBox::questionYesNo(this, i18n("Do you want to remove the connection '%1'?", connection->name()), i18n("Remove Connection"), - KStandardGuiItem::remove(), KStandardGuiItem::no(), QString(), KMessageBox::Dangerous) - == KMessageBox::Yes) { - connection->remove(); - delete currentItem; - slotWidgetChanged(); - } - } -} - -void BondWidget::populateBonds() -{ - m_ui->bonds->clear(); - - for (const NetworkManager::Connection::Ptr &connection : NetworkManager::listConnections()) { - NetworkManager::ConnectionSettings::Ptr settings = connection->settings(); - // The mapping from slave to master may be by uuid or name, try our best to - // figure out if we are master to the slave. - const QString master = settings->master(); - bool isSlave = ((master == m_uuid) || // by-uuid - (!m_id.isEmpty() && master == m_id)); // by-name - if (isSlave && (settings->slaveType() == type())) { - const QString label = QString("%1 (%2)").arg(connection->name()).arg(connection->settings()->typeAsString(connection->settings()->connectionType())); - QListWidgetItem * slaveItem = new QListWidgetItem(label, m_ui->bonds); - slaveItem->setData(Qt::UserRole, connection->uuid()); - } - } -} - -bool BondWidget::isValid() const -{ - if (m_ui->linkMonitoring->itemData(m_ui->linkMonitoring->currentIndex()).toString() == NM_SETTING_BOND_OPTION_ARP_MONITOR) { - const QStringList ipAddresses = m_ui->arpTargets->text().split(','); - if (ipAddresses.isEmpty()) { - return false; - } - - for (const QString &ip : ipAddresses) { - QHostAddress ipAddress(ip); - if (ipAddress.isNull()) { - return false; - } - } - } - - return !m_ui->ifaceName->text().isEmpty() && m_ui->bonds->count() > 0; -} diff --git a/libs/editor/settings/bondwidget.h b/libs/editor/settings/bondwidget.h deleted file mode 100644 index 08acf5ac..00000000 --- a/libs/editor/settings/bondwidget.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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_BOND_WIDGET_H -#define PLASMA_NM_BOND_WIDGET_H - -#include -#include -#include -#include - -#include - -#include "settingwidget.h" - -namespace Ui -{ -class BondWidget; -} - -class Q_DECL_EXPORT BondWidget : public SettingWidget -{ - Q_OBJECT -public: - explicit BondWidget(const QString & masterUuid, const QString &masterId, - const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), - QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~BondWidget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -private Q_SLOTS: - void addBond(QAction * action); - void currentBondChanged(QListWidgetItem * current, QListWidgetItem * previous); - void bondAddComplete(QDBusPendingCallWatcher * watcher); - - void editBond(); - void deleteBond(); - - void populateBonds(); - -private: - QString m_uuid; - QString m_id; - Ui::BondWidget * m_ui; - QMenu * m_menu; -}; - -#endif // PLASMA_NM_BOND_WIDGET_H diff --git a/libs/editor/settings/bridgewidget.cpp b/libs/editor/settings/bridgewidget.cpp deleted file mode 100644 index 719a6680..00000000 --- a/libs/editor/settings/bridgewidget.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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 "bridgewidget.h" -#include "ui_bridge.h" -#include "connectioneditordialog.h" -#include "debug.h" - -#include - -#include -#include -#include -#include - -#include -#include - -BridgeWidget::BridgeWidget(const QString & masterUuid, const QString &masterId, - const NetworkManager::Setting::Ptr &setting, - QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting, parent, f), - m_uuid(masterUuid), - m_id(masterId), - m_ui(new Ui::BridgeWidget) -{ - m_ui->setupUi(this); - - // Action buttons and menu - m_menu = new QMenu(this); - QAction * action = new QAction(i18n("Ethernet"), this); - action->setData(NetworkManager::ConnectionSettings::Wired); - m_menu->addAction(action); - action = new QAction(i18n("VLAN"), this); - action->setData(NetworkManager::ConnectionSettings::Vlan); - m_menu->addAction(action); - action = new QAction(i18n("Wi-Fi"), this); - action->setData(NetworkManager::ConnectionSettings::Wireless); - m_menu->addAction(action); - m_ui->btnAdd->setMenu(m_menu); - connect(m_menu, &QMenu::triggered, this, &BridgeWidget::addBridge); - connect(m_ui->btnEdit, &QPushButton::clicked, this, &BridgeWidget::editBridge); - connect(m_ui->btnDelete, &QPushButton::clicked, this, &BridgeWidget::deleteBridge); - - // bridges - populateBridges(); - connect(m_ui->bridges, &QListWidget::currentItemChanged, this, &BridgeWidget::currentBridgeChanged); - connect(m_ui->bridges, &QListWidget::itemDoubleClicked, this, &BridgeWidget::editBridge); - - connect(m_ui->ifaceName, &KLineEdit::textChanged, this, &BridgeWidget::slotWidgetChanged); - - // Connect for setting check - watchChangedSetting(); - - KAcceleratorManager::manage(this); - KAcceleratorManager::manage(m_menu); - - if (setting) { - loadConfig(setting); - } -} - -BridgeWidget::~BridgeWidget() -{ - delete m_ui; -} - -void BridgeWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::BridgeSetting::Ptr bridgeSetting = setting.staticCast(); - - m_ui->ifaceName->setText(bridgeSetting->interfaceName()); - m_ui->agingTime->setValue(bridgeSetting->agingTime()); - - const bool stp = bridgeSetting->stp(); - m_ui->stpGroup->setChecked(stp); - if (stp) { - m_ui->priority->setValue(bridgeSetting->priority()); - m_ui->forwardDelay->setValue(bridgeSetting->forwardDelay()); - m_ui->helloTime->setValue(bridgeSetting->helloTime()); - m_ui->maxAge->setValue(bridgeSetting->maxAge()); - } -} - -QVariantMap BridgeWidget::setting() const -{ - NetworkManager::BridgeSetting setting; - setting.setInterfaceName(m_ui->ifaceName->text()); - setting.setAgingTime(m_ui->agingTime->value()); - - const bool stp = m_ui->stpGroup->isChecked(); - setting.setStp(stp); - if (stp) { - setting.setPriority(m_ui->priority->value()); - setting.setForwardDelay(m_ui->forwardDelay->value()); - setting.setHelloTime(m_ui->helloTime->value()); - setting.setMaxAge(m_ui->maxAge->value()); - } - - return setting.toMap(); -} - -void BridgeWidget::addBridge(QAction *action) -{ - qCDebug(PLASMA_NM) << "Adding bridged connection:" << action->data(); - qCDebug(PLASMA_NM) << "Master UUID:" << m_uuid; - qCDebug(PLASMA_NM) << "Slave type:" << type(); - - NetworkManager::ConnectionSettings::ConnectionType connectionType = static_cast(action->data().toInt()); - NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(connectionType)); - connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); - connectionSettings->setMaster(m_uuid); - connectionSettings->setSlaveType(type()); - connectionSettings->setAutoconnect(false); - - QPointer bridgeEditor = new ConnectionEditorDialog(connectionSettings); - connect(bridgeEditor.data(), &ConnectionEditorDialog::accepted, - [bridgeEditor, this] () { - qCDebug(PLASMA_NM) << "Saving slave connection"; - // qCDebug(PLASMA_NM) << bridgeEditor->setting(); - QDBusPendingReply reply = NetworkManager::addConnection(bridgeEditor->setting()); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); - connect(watcher, &QDBusPendingCallWatcher::finished, this, &BridgeWidget::bridgeAddComplete); - }); - connect(bridgeEditor.data(), &ConnectionEditorDialog::finished, - [bridgeEditor] () { - if (bridgeEditor) { - bridgeEditor->deleteLater(); - } - }); - bridgeEditor->setModal(true); - bridgeEditor->show(); -} - -void BridgeWidget::currentBridgeChanged(QListWidgetItem *current, QListWidgetItem *previous) -{ - Q_UNUSED(previous) - - m_ui->btnEdit->setEnabled(current); - m_ui->btnDelete->setEnabled(current); -} - -void BridgeWidget::bridgeAddComplete(QDBusPendingCallWatcher * watcher) -{ - QDBusPendingReply reply = *watcher; - - if (reply.isValid()) { - // find the slave connection with matching UUID - NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(reply.value().path()); - if (connection && connection->settings()->master() == m_uuid) { - const QString label = QString("%1 (%2)").arg(connection->name()).arg(connection->settings()->typeAsString(connection->settings()->connectionType())); - QListWidgetItem * slaveItem = new QListWidgetItem(label, m_ui->bridges); - slaveItem->setData(Qt::UserRole, connection->uuid()); - slotWidgetChanged(); - } - } else { - qCWarning(PLASMA_NM) << "Bridged connection not added:" << reply.error().message(); - } -} - -void BridgeWidget::editBridge() -{ - QListWidgetItem * currentItem = m_ui->bridges->currentItem(); - if (!currentItem) - return; - - const QString uuid = currentItem->data(Qt::UserRole).toString(); - NetworkManager::Connection::Ptr connection = NetworkManager::findConnectionByUuid(uuid); - - if (connection) { - qCDebug(PLASMA_NM) << "Editing bridged connection" << currentItem->text() << uuid; - QPointer bridgeEditor = new ConnectionEditorDialog(connection->settings()); - connect(bridgeEditor.data(), &ConnectionEditorDialog::accepted, - [connection, bridgeEditor, this] () { - connection->update(bridgeEditor->setting()); - connect(connection.data(), &NetworkManager::Connection::updated, this, &BridgeWidget::populateBridges); - }); - connect(bridgeEditor.data(), &ConnectionEditorDialog::finished, - [bridgeEditor] () { - if (bridgeEditor) { - bridgeEditor->deleteLater(); - } - }); - bridgeEditor->setModal(true); - bridgeEditor->show(); - } -} - -void BridgeWidget::deleteBridge() -{ - QListWidgetItem * currentItem = m_ui->bridges->currentItem(); - if (!currentItem) - return; - - const QString uuid = currentItem->data(Qt::UserRole).toString(); - NetworkManager::Connection::Ptr connection = NetworkManager::findConnectionByUuid(uuid); - - if (connection) { - // qCDebug(PLASMA_NM) << "About to delete bridged connection" << currentItem->text() << uuid; - if (KMessageBox::questionYesNo(this, i18n("Do you want to remove the connection '%1'?", connection->name()), i18n("Remove Connection"), KStandardGuiItem::remove(), - KStandardGuiItem::no(), QString(), KMessageBox::Dangerous) - == KMessageBox::Yes) { - connection->remove(); - delete currentItem; - slotWidgetChanged(); - } - } -} - -void BridgeWidget::populateBridges() -{ - m_ui->bridges->clear(); - - for (const NetworkManager::Connection::Ptr &connection : NetworkManager::listConnections()) { - NetworkManager::ConnectionSettings::Ptr settings = connection->settings(); - // The mapping from slave to master may be by uuid or name, try our best to - // figure out if we are master to the slave. - const QString master = settings->master(); - bool isSlave = ((master == m_uuid) || // by-uuid - (!m_id.isEmpty() && master == m_id)); // by-name - if (isSlave && (settings->slaveType() == type())) { - const QString label = QString("%1 (%2)").arg(connection->name()).arg(connection->settings()->typeAsString(connection->settings()->connectionType())); - QListWidgetItem * slaveItem = new QListWidgetItem(label, m_ui->bridges); - slaveItem->setData(Qt::UserRole, connection->uuid()); - } - } -} - -bool BridgeWidget::isValid() const -{ - return !m_ui->ifaceName->text().isEmpty() && m_ui->bridges->count() > 0; -} diff --git a/libs/editor/settings/bridgewidget.h b/libs/editor/settings/bridgewidget.h deleted file mode 100644 index bea0395b..00000000 --- a/libs/editor/settings/bridgewidget.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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_BRIDGE_WIDGET_H -#define PLASMA_NM_BRIDGE_WIDGET_H - -#include -#include -#include -#include - -#include - -#include "settingwidget.h" - -namespace Ui -{ -class BridgeWidget; -} - -class Q_DECL_EXPORT BridgeWidget : public SettingWidget -{ - Q_OBJECT -public: - explicit BridgeWidget(const QString & masterUuid, const QString &masterId, - const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), - QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~BridgeWidget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -private Q_SLOTS: - void addBridge(QAction * action); - void currentBridgeChanged(QListWidgetItem * current, QListWidgetItem * previous); - void bridgeAddComplete(QDBusPendingCallWatcher * watcher); - - void editBridge(); - void deleteBridge(); - - void populateBridges(); - -private: - QString m_uuid; - QString m_id; - Ui::BridgeWidget * m_ui; - QMenu * m_menu; -}; - -#endif // PLASMA_NM_BRIDGE_WIDGET_H diff --git a/libs/editor/settings/btwidget.cpp b/libs/editor/settings/btwidget.cpp deleted file mode 100644 index aa02d4ce..00000000 --- a/libs/editor/settings/btwidget.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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 "btwidget.h" -#include "ui_bt.h" -#include "uiutils.h" - -#include - -#include - -BtWidget::BtWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting, parent, f), - m_ui(new Ui::BtWidget) -{ - m_ui->setupUi(this); - - m_ui->type->addItem(i18n("DUN (dial up networking)"), NetworkManager::BluetoothSetting::Dun); - m_ui->type->addItem(i18n("PAN (personal area network)"), NetworkManager::BluetoothSetting::Panu); - - m_ui->type->setEnabled(false); - - // Connect for setting check - watchChangedSetting(); - - // Connect for validity check - connect(m_ui->bdaddr, &HwAddrComboBox::hwAddressChanged, this, &BtWidget::slotWidgetChanged); - - KAcceleratorManager::manage(this); - - if (setting) { - loadConfig(setting); - } -} - -BtWidget::~BtWidget() -{ - delete m_ui; -} - -void BtWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::BluetoothSetting::Ptr btSetting = setting.staticCast(); - - m_ui->bdaddr->init(NetworkManager::Device::Bluetooth, NetworkManager::macAddressAsString(btSetting->bluetoothAddress())); - m_ui->type->setCurrentIndex(m_ui->type->findData(btSetting->profileType())); -} - -QVariantMap BtWidget::setting() const -{ - NetworkManager::BluetoothSetting btSetting; - - btSetting.setBluetoothAddress(NetworkManager::macAddressFromString(m_ui->bdaddr->hwAddress())); - btSetting.setProfileType(static_cast(m_ui->type->itemData(m_ui->type->currentIndex()).toInt())); - - return btSetting.toMap(); -} - -bool BtWidget::isValid() const -{ - return m_ui->bdaddr->isValid(); -} diff --git a/libs/editor/settings/btwidget.h b/libs/editor/settings/btwidget.h deleted file mode 100644 index f3b53ed7..00000000 --- a/libs/editor/settings/btwidget.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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_BT_WIDGET_H -#define PLASMA_NM_BT_WIDGET_H - -#include - -#include - -#include "settingwidget.h" - -namespace Ui -{ -class BtWidget; -} - -class Q_DECL_EXPORT BtWidget : public SettingWidget -{ - Q_OBJECT -public: - explicit BtWidget(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~BtWidget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -private: - Ui::BtWidget * m_ui; -}; - -#endif // PLASMA_NM_BT_WIDGET_H diff --git a/libs/editor/settings/cdmawidget.cpp b/libs/editor/settings/cdmawidget.cpp deleted file mode 100644 index 88464273..00000000 --- a/libs/editor/settings/cdmawidget.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - Copyright 2015 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 "cdmawidget.h" -#include "ui_cdma.h" - -#include - -CdmaWidget::CdmaWidget(const NetworkManager::Setting::Ptr &setting, QWidget *parent, Qt::WindowFlags f) - : SettingWidget(setting, parent, f) - , m_ui(new Ui::CdmaWidget) -{ - m_ui->setupUi(this); - - m_ui->password->setPasswordOptionsEnabled(true); - m_ui->password->setPasswordNotRequiredEnabled(true); - - // Connect for setting check - watchChangedSetting(); - - // Connect for validity check - connect(m_ui->number, &KLineEdit::textChanged, this, &CdmaWidget::slotWidgetChanged); - connect(m_ui->password, &PasswordField::textChanged, this, &CdmaWidget::slotWidgetChanged); - connect(m_ui->password, &PasswordField::passwordOptionChanged, this, &CdmaWidget::slotWidgetChanged); - connect(m_ui->username, &KLineEdit::textChanged, this, &CdmaWidget::slotWidgetChanged); - - KAcceleratorManager::manage(this); - - if (setting && !setting->isNull()) { - loadConfig(setting); - } -} - -CdmaWidget::~CdmaWidget() -{ - delete m_ui; -} - -void CdmaWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::CdmaSetting::Ptr cdmaSetting = setting.staticCast(); - const QString number = cdmaSetting->number(); - - if (!number.isEmpty()) { - m_ui->number->setText(number); - } - - m_ui->username->setText(cdmaSetting->username()); - if (cdmaSetting->passwordFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->password->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (cdmaSetting->passwordFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->password->setPasswordOption(PasswordField::StoreForUser); - } else if (cdmaSetting->passwordFlags().testFlag(NetworkManager::Setting::NotSaved)) { - m_ui->password->setPasswordOption(PasswordField::AlwaysAsk); - } else { - m_ui->password->setPasswordOption(PasswordField::NotRequired); - } - - loadSecrets(setting); -} - -void CdmaWidget::loadSecrets(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::CdmaSetting::Ptr cdmaSetting = setting.staticCast(); - - if (cdmaSetting) { - const QString password = cdmaSetting->password(); - if (!password.isEmpty()) { - m_ui->password->setText(password); - } - } -} - -QVariantMap CdmaWidget::setting() const -{ - NetworkManager::CdmaSetting cdmaSetting; - if (!m_ui->number->text().isEmpty()) { - cdmaSetting.setNumber(m_ui->number->text()); - } - - if (!m_ui->username->text().isEmpty()) { - cdmaSetting.setUsername(m_ui->username->text()); - } - - if (!m_ui->password->text().isEmpty()) { - cdmaSetting.setPassword(m_ui->password->text()); - } - - if (m_ui->password->passwordOption() == PasswordField::StoreForAllUsers) { - cdmaSetting.setPasswordFlags(NetworkManager::Setting::None); - } else if (m_ui->password->passwordOption() == PasswordField::StoreForUser) { - cdmaSetting.setPasswordFlags(NetworkManager::Setting::AgentOwned); - } else if (m_ui->password->passwordOption() == PasswordField::AlwaysAsk) { - cdmaSetting.setPasswordFlags(NetworkManager::Setting::NotSaved); - } else { - cdmaSetting.setPasswordFlags(NetworkManager::Setting::NotRequired); - } - - return cdmaSetting.toMap(); -} - -bool CdmaWidget::isValid() const -{ - bool passwordUserValid = true; - - if (m_ui->password->passwordOption() == PasswordField::StoreForUser || - m_ui->password->passwordOption() == PasswordField::StoreForAllUsers) { - passwordUserValid = !m_ui->username->text().isEmpty() && !m_ui->password->text().isEmpty(); - } else if (m_ui->password->passwordOption() == PasswordField::AlwaysAsk) { - passwordUserValid = !m_ui->username->text().isEmpty(); - } - - return !m_ui->number->text().isEmpty() && passwordUserValid; -} diff --git a/libs/editor/settings/cdmawidget.h b/libs/editor/settings/cdmawidget.h deleted file mode 100644 index e9d259e0..00000000 --- a/libs/editor/settings/cdmawidget.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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_CDMA_WIDGET_H -#define PLASMA_NM_CDMA_WIDGET_H - -#include - -#include - -#include "settingwidget.h" - -namespace Ui -{ -class CdmaWidget; -} - -class Q_DECL_EXPORT CdmaWidget : public SettingWidget -{ - Q_OBJECT -public: - explicit CdmaWidget(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), QWidget *parent = nullptr, Qt::WindowFlags f = {}); - ~CdmaWidget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - void loadSecrets(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -private: - Ui::CdmaWidget *m_ui; -}; - -#endif // PLASMA_NM_CDMA_WIDGET_H diff --git a/libs/editor/settings/connectionsetting.cpp b/libs/editor/settings/connectionsetting.cpp new file mode 100644 index 00000000..2ad067ad --- /dev/null +++ b/libs/editor/settings/connectionsetting.cpp @@ -0,0 +1,508 @@ +/* + 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 "connectionsetting.h" +#include "setting.h" + +#include +#include +#include +#include + +#include +#include +#include + +#include + +class ConnectionSettingPrivate +{ +public: + NetworkManager::ConnectionSettings::Ptr connectionSettings; + + QMap settings; + + int pendingReplies; + bool valid; + bool secretsLoaded; + QStringList firewallZones; + NMStringMap vpnConnections; +}; + +ConnectionSetting::ConnectionSetting(QObject *parent) + : ConnectionSetting(nullptr, parent) +{ +} + +ConnectionSetting::ConnectionSetting(const NetworkManager::ConnectionSettings::Ptr &settings, QObject *parent) + : QObject(parent) + , d_ptr(new ConnectionSettingPrivate()) +{ + Q_D(ConnectionSetting); + + // 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); + } +} + +ConnectionSetting::~ConnectionSetting() +{ + delete d_ptr; +} + +void ConnectionSetting::loadConfig(const NetworkManager::ConnectionSettings::Ptr &settings) +{ + Q_D(ConnectionSetting); + + 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) { +// 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 +// 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, &ConnectionSetting::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 ConnectionSetting::settingMap() const +{ + return NMVariantMapMap(); +} + +QString ConnectionSetting::id() const +{ + Q_D(const ConnectionSetting); + + return d->connectionSettings->id(); +} + +void ConnectionSetting::setId(const QString &id) +{ + Q_D(ConnectionSetting); + + d->connectionSettings->setId(id); +} + +QString ConnectionSetting::uuid() const +{ + Q_D(const ConnectionSetting); + + return d->connectionSettings->uuid(); +} + +void ConnectionSetting::setUuid(const QString &uuid) +{ + Q_D(ConnectionSetting); + + d->connectionSettings->setUuid(uuid); +} + +uint ConnectionSetting::connectionType() const +{ + Q_D(const ConnectionSetting); + + return (uint)d->connectionSettings->connectionType(); +} + +bool ConnectionSetting::autoconnect() const +{ + Q_D(const ConnectionSetting); + + return d->connectionSettings->autoconnect(); +} + +void ConnectionSetting::setAutoconnect(bool autoconnect) +{ + Q_D(ConnectionSetting); + + d->connectionSettings->setAutoconnect(autoconnect); +} + +QStringList ConnectionSetting::permissions() const +{ + Q_D(const ConnectionSetting); + + return d->connectionSettings->permissions().keys(); +} + +void ConnectionSetting::setPermissions(const QStringList &permissions) +{ + Q_D(ConnectionSetting); + + foreach (const QString &user, permissions) { + d->connectionSettings->addToPermissions(user, QString()); + } +} + +QString ConnectionSetting::secondaryConnection() const +{ + Q_D(const ConnectionSetting); + + if (!d->connectionSettings->secondaries().isEmpty()) { + return d->connectionSettings->secondaries().first(); + } + + return nullptr; +} + +void ConnectionSetting::setSecondaryConnection(const QString &secondaryConnection) +{ + Q_D(ConnectionSetting); + + d->connectionSettings->setSecondaries({secondaryConnection}); +} + +int ConnectionSetting::priority() const +{ + Q_D(const ConnectionSetting); + + return d->connectionSettings->autoconnectPriority(); +} + +void ConnectionSetting::setPriority(int priority) +{ + Q_D(ConnectionSetting); + + d->connectionSettings->setAutoconnectPriority(priority); +} + +QStringList ConnectionSetting::firewallZones() const +{ + Q_D(const ConnectionSetting); + + return d->firewallZones; +} + +QStringList ConnectionSetting::vpnConnections() const +{ + Q_D(const ConnectionSetting); + + return d->vpnConnections.values(); +} + +Setting * ConnectionSetting::setting(NetworkManager::Setting::SettingType type) const +{ + Q_D(const ConnectionSetting); + + return d->settings.value(type); +} + +QList ConnectionSetting::settingTypes() const +{ + Q_D(const ConnectionSetting); + + return d->settings.keys(); +} + +void ConnectionSetting::addSetting(NetworkManager::Setting::SettingType type, Setting *setting) +{ + Q_D(ConnectionSetting); + + d->settings.insert(type, setting); +} + +bool ConnectionSetting::isInitialized() const +{ + Q_D(const ConnectionSetting); + + return d->secretsLoaded; +} + +bool ConnectionSetting::isValid() const +{ + Q_D(const ConnectionSetting); + + return d->valid; +} + +void ConnectionSetting::onReplyFinished(QDBusPendingCallWatcher *watcher) +{ +} + +void ConnectionSetting::onValidityChanged(bool valid) +{ + Q_D(ConnectionSetting); + + 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/connectionsetting.h b/libs/editor/settings/connectionsetting.h new file mode 100644 index 00000000..3d1deac4 --- /dev/null +++ b/libs/editor/settings/connectionsetting.h @@ -0,0 +1,102 @@ +/* + 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 ConnectionSettingPrivate; + +#include + +class Setting; + +class Q_DECL_EXPORT ConnectionSetting : 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(int priority READ priority WRITE setPriority) + + Q_PROPERTY(QStringList firewallZones READ firewallZones CONSTANT) + Q_PROPERTY(QStringList vpnConnections READ vpnConnections CONSTANT) +public: + explicit ConnectionSetting(QObject *parent = nullptr); + ConnectionSetting(const NetworkManager::ConnectionSettings::Ptr &settings = NetworkManager::ConnectionSettings::Ptr(), QObject *parent = nullptr); + + virtual ~ConnectionSetting(); + + 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); + + int priority() const; + void setPriority(int priority); + + QStringList firewallZones() const; + QStringList vpnConnections() 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: + ConnectionSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(ConnectionSetting) + +}; + +#endif // PLASMA_NM_CONNECTION_SETTING_H diff --git a/libs/editor/settings/connectionwidget.cpp b/libs/editor/settings/connectionwidget.cpp deleted file mode 100644 index dcbb1fb6..00000000 --- a/libs/editor/settings/connectionwidget.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* - 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 "connectionwidget.h" -#include "ui_connectionwidget.h" -#include "advancedpermissionswidget.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -ConnectionWidget::ConnectionWidget(const NetworkManager::ConnectionSettings::Ptr &settings, QWidget* parent, Qt::WindowFlags f): - QWidget(parent, f), - m_widget(new Ui::ConnectionWidget), - m_type(settings->connectionType()), - m_masterUuid(settings->master()), - m_slaveType(settings->slaveType()) -{ - m_widget->setupUi(this); - - m_widget->firewallZone->addItems(firewallZones()); - - // VPN combo - populateVpnConnections(); - if (settings->connectionType() == NetworkManager::ConnectionSettings::Vpn) { - m_widget->autoconnectVpn->setEnabled(false); - m_widget->vpnCombobox->setEnabled(false); - m_widget->autoconnect->setEnabled(false); - } else { - m_widget->autoconnectVpn->setEnabled(true); - m_widget->autoconnect->setEnabled(true); - } - - connect(m_widget->autoconnectVpn, &QCheckBox::toggled, this, &ConnectionWidget::autoVpnToggled); - - if (settings) { - loadConfig(settings); - } - - m_tmpSetting.setPermissions(settings->permissions()); - - KAcceleratorManager::manage(this); - - connect(m_widget->autoconnect, &QCheckBox::stateChanged, this, &ConnectionWidget::settingChanged); - connect(m_widget->allUsers, &QCheckBox::stateChanged, this, &ConnectionWidget::settingChanged); - connect(m_widget->autoconnectVpn, &QCheckBox::stateChanged, this, &ConnectionWidget::settingChanged); - connect(m_widget->pushButtonPermissions, &QPushButton::clicked, this, &ConnectionWidget::settingChanged); - connect(m_widget->firewallZone, QOverload::of(&QComboBox::currentIndexChanged), this, &ConnectionWidget::settingChanged); - connect(m_widget->firewallZone, &QComboBox::currentTextChanged, this, &ConnectionWidget::settingChanged); - connect(m_widget->vpnCombobox, QOverload::of(&QComboBox::currentIndexChanged), this, &ConnectionWidget::settingChanged); - connect(m_widget->vpnCombobox, &QComboBox::currentTextChanged, this, &ConnectionWidget::settingChanged); - connect(m_widget->prioritySpin, QOverload::of(&QSpinBox::valueChanged), this, &ConnectionWidget::settingChanged); - connect(m_widget->metered, QOverload::of(&QComboBox::currentIndexChanged), this, &ConnectionWidget::settingChanged); - - connect(m_widget->pushButtonPermissions, &QPushButton::clicked, this, &ConnectionWidget::openAdvancedPermissions); -} - -ConnectionWidget::~ConnectionWidget() -{ - delete m_widget; -} - -void ConnectionWidget::loadConfig(const NetworkManager::ConnectionSettings::Ptr &settings) -{ - if (settings->permissions().isEmpty()) { - m_widget->allUsers->setChecked(true); - } else { - m_widget->allUsers->setChecked(false); - } - - const QString zone = settings->zone(); - m_widget->firewallZone->setCurrentIndex(m_widget->firewallZone->findText(zone)); - - const QStringList secondaries = settings->secondaries(); - const QStringList vpnKeys = vpnConnections().keys(); - if (!secondaries.isEmpty() && !vpnKeys.isEmpty()) { - for (const QString &vpnKey : vpnKeys) { - if (secondaries.contains(vpnKey)) { - m_widget->vpnCombobox->setCurrentIndex(m_widget->vpnCombobox->findData(vpnKey)); - m_widget->autoconnectVpn->setChecked(true); - break; - } - } - } else { - m_widget->autoconnectVpn->setChecked(false); - } - - m_widget->autoconnect->setChecked(settings->autoconnect()); - - if (m_widget->prioritySpin->isEnabled()) { - m_widget->prioritySpin->setValue(settings->autoconnectPriority()); - } - - m_widget->metered->setCurrentIndex(settings->metered()); -} - -NMVariantMapMap ConnectionWidget::setting() const -{ - NetworkManager::ConnectionSettings settings; - - settings.setConnectionType(m_type); - settings.setAutoconnect(m_widget->autoconnect->isChecked()); - settings.setMaster(m_masterUuid); - settings.setSlaveType(m_slaveType); - - if (m_widget->allUsers->isChecked()) { - settings.setPermissions(QHash()); - } else { - if (m_tmpSetting.permissions().isEmpty()) { - settings.addToPermissions(KUser().loginName(), QString()); - } else { - settings.setPermissions(m_tmpSetting.permissions()); - } - } - - if (m_widget->autoconnectVpn->isChecked() && m_widget->vpnCombobox->count() > 0) { - settings.setSecondaries(QStringList() << m_widget->vpnCombobox->itemData(m_widget->vpnCombobox->currentIndex()).toString()); - } - - const QString zone = m_widget->firewallZone->currentText(); - if (!zone.isEmpty()) { - settings.setZone(zone); - } - - if (m_widget->prioritySpin->isEnabled()) { - settings.setAutoconnectPriority(m_widget->prioritySpin->value()); - } - - settings.setMetered(static_cast(m_widget->metered->currentIndex())); - - return settings.toMap(); -} - -void ConnectionWidget::autoVpnToggled(bool on) -{ - m_widget->vpnCombobox->setEnabled(on); -} - -void ConnectionWidget::openAdvancedPermissions() -{ - QPointer dialog = new AdvancedPermissionsWidget(m_tmpSetting.permissions(), this); - dialog->setWindowTitle(i18nc("@title:window advanced permissions editor", - "Advanced Permissions Editor")); - if (dialog->exec() == QDialog::Accepted) { - m_tmpSetting.setPermissions(dialog->currentUsers()); - } - delete dialog; -} - -NMStringMap ConnectionWidget::vpnConnections() const -{ - NetworkManager::Connection::List list = NetworkManager::listConnections(); - NMStringMap result; - - for (const NetworkManager::Connection::Ptr &conn : list) { - NetworkManager::ConnectionSettings::Ptr conSet = conn->settings(); - if (conSet->connectionType() == NetworkManager::ConnectionSettings::Vpn - || conSet->connectionType() == NetworkManager::ConnectionSettings::WireGuard) { - // qCDebug(PLASMA_NM) << "Found VPN" << conSet->id() << conSet->uuid(); - result.insert(conSet->uuid(), conSet->id()); - } - } - - return result; -} - -QStringList ConnectionWidget::firewallZones() const -{ - 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()) - return reply.value(); - - return QStringList(); -} - -void ConnectionWidget::populateVpnConnections() -{ - QMapIterator it(vpnConnections()); - while (it.hasNext()) { - it.next(); - m_widget->vpnCombobox->addItem(it.value(), it.key()); - } -} diff --git a/libs/editor/settings/connectionwidget.h b/libs/editor/settings/connectionwidget.h deleted file mode 100644 index 3f3f9b2a..00000000 --- a/libs/editor/settings/connectionwidget.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - 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 . -*/ - -#ifndef PLASMA_NM_CONNECTION_WIDGET_H -#define PLASMA_NM_CONNECTION_WIDGET_H - -#include - -#include - -namespace Ui -{ -class ConnectionWidget; -} - -class ConnectionWidget : public QWidget -{ -Q_OBJECT - -public: - explicit ConnectionWidget(const NetworkManager::ConnectionSettings::Ptr &settings = NetworkManager::ConnectionSettings::Ptr(), - QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~ConnectionWidget() override; - - void loadConfig(const NetworkManager::ConnectionSettings::Ptr &settings); - - NMVariantMapMap setting() const; - -private Q_SLOTS: - void autoVpnToggled(bool on); - void openAdvancedPermissions(); - -Q_SIGNALS: - void settingChanged(); - -private: - // list of VPN: UUID, name - NMStringMap vpnConnections() const; - // list of firewalld zones - QStringList firewallZones() const; - - void populateVpnConnections(); - Ui::ConnectionWidget * m_widget; - NetworkManager::ConnectionSettings m_tmpSetting; - NetworkManager::ConnectionSettings::ConnectionType m_type; - QString m_masterUuid; - QString m_slaveType; -}; - -#endif // PLASMA_NM_CONNECTION_WIDGET_H diff --git a/libs/editor/settings/gsmwidget.cpp b/libs/editor/settings/gsmwidget.cpp deleted file mode 100644 index 7d515607..00000000 --- a/libs/editor/settings/gsmwidget.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* - Copyright 2013, 2014 Lukas Tinkl - - 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 "gsmwidget.h" -#include "ui_gsm.h" - -#include - -#include - -GsmWidget::GsmWidget(const NetworkManager::Setting::Ptr &setting, QWidget *parent, Qt::WindowFlags f) - : SettingWidget(setting, parent, f) - , m_ui(new Ui::GsmWidget) -{ - m_ui->setupUi(this); - - // Network ID not supported yet in NM - m_ui->labelNetworkId->setHidden(true); - m_ui->networkId->setHidden(true); - - m_ui->password->setPasswordOptionsEnabled(true); - m_ui->password->setPasswordNotRequiredEnabled(true); - m_ui->pin->setPasswordOptionsEnabled(true); - m_ui->pin->setPasswordNotRequiredEnabled(true); - - // Connect for setting check - watchChangedSetting(); - - // Connect for validity check - connect(m_ui->apn, &KLineEdit::textChanged, this, &GsmWidget::slotWidgetChanged); - connect(m_ui->password, &PasswordField::textChanged, this, &GsmWidget::slotWidgetChanged); - connect(m_ui->password, &PasswordField::passwordOptionChanged, this, &GsmWidget::slotWidgetChanged); - connect(m_ui->pin, &PasswordField::textChanged, this, &GsmWidget::slotWidgetChanged); - connect(m_ui->pin, &PasswordField::passwordOptionChanged, this, &GsmWidget::slotWidgetChanged); - connect(m_ui->username, &KLineEdit::textChanged, this, &GsmWidget::slotWidgetChanged); - - KAcceleratorManager::manage(this); - - if (setting) { - loadConfig(setting); - } -} - -GsmWidget::~GsmWidget() -{ - delete m_ui; -} - -void GsmWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::GsmSetting::Ptr gsmSetting = setting.staticCast(); - - const QString number = gsmSetting->number(); - if (!number.isEmpty()) - m_ui->number->setText(number); - m_ui->username->setText(gsmSetting->username()); - if (gsmSetting->passwordFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->password->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (gsmSetting->passwordFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->password->setPasswordOption(PasswordField::StoreForUser); - } else if (gsmSetting->passwordFlags().testFlag(NetworkManager::Setting::NotSaved)) { - m_ui->password->setPasswordOption(PasswordField::AlwaysAsk); - } else { - m_ui->password->setPasswordOption(PasswordField::NotRequired); - } - - m_ui->apn->setText(gsmSetting->apn()); - m_ui->networkId->setText(gsmSetting->networkId()); - m_ui->roaming->setChecked(!gsmSetting->homeOnly()); - if (gsmSetting->pinFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->pin->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (gsmSetting->pinFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->pin->setPasswordOption(PasswordField::StoreForUser); - } else if (gsmSetting->pinFlags().testFlag(NetworkManager::Setting::NotSaved)) { - m_ui->pin->setPasswordOption(PasswordField::AlwaysAsk); - } else { - m_ui->pin->setPasswordOption(PasswordField::NotRequired); - } - - loadSecrets(setting); -} - -void GsmWidget::loadSecrets(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::GsmSetting::Ptr gsmSetting = setting.staticCast(); - - if (gsmSetting) { - const QString password = gsmSetting->password(); - if (!password.isEmpty()) { - m_ui->password->setText(password); - } - - const QString pin = gsmSetting->pin(); - if (!pin.isEmpty()) { - m_ui->pin->setText(pin); - } - } -} - -QVariantMap GsmWidget::setting() const -{ - NetworkManager::GsmSetting gsmSetting; - if (!m_ui->number->text().isEmpty()) - gsmSetting.setNumber(m_ui->number->text()); - if (!m_ui->username->text().isEmpty()) - gsmSetting.setUsername(m_ui->username->text()); - if (!m_ui->password->text().isEmpty()) - gsmSetting.setPassword(m_ui->password->text()); - if (m_ui->password->passwordOption() == PasswordField::StoreForAllUsers) { - gsmSetting.setPasswordFlags(NetworkManager::Setting::None); - } else if (m_ui->password->passwordOption() == PasswordField::StoreForUser) { - gsmSetting.setPasswordFlags(NetworkManager::Setting::AgentOwned); - } else if (m_ui->password->passwordOption() == PasswordField::AlwaysAsk) { - gsmSetting.setPasswordFlags(NetworkManager::Setting::NotSaved); - } else { - gsmSetting.setPasswordFlags(NetworkManager::Setting::NotRequired); - } - - if (!m_ui->apn->text().isEmpty()) - gsmSetting.setApn(m_ui->apn->text()); - if (!m_ui->networkId->text().isEmpty()) - gsmSetting.setNetworkId(m_ui->networkId->text()); - gsmSetting.setHomeOnly(!m_ui->roaming->isChecked()); - if (!m_ui->pin->text().isEmpty()) - gsmSetting.setPin(m_ui->pin->text()); - if (m_ui->pin->passwordOption() == PasswordField::StoreForAllUsers) { - gsmSetting.setPinFlags(NetworkManager::Setting::None); - } else if (m_ui->pin->passwordOption() == PasswordField::StoreForUser) { - gsmSetting.setPinFlags(NetworkManager::Setting::AgentOwned); - } else if (m_ui->pin->passwordOption() == PasswordField::AlwaysAsk) { - gsmSetting.setPinFlags(NetworkManager::Setting::NotSaved); - } else { - gsmSetting.setPinFlags(NetworkManager::Setting::NotRequired); - } - - return gsmSetting.toMap(); -} - -bool GsmWidget::isValid() const -{ - bool passwordUserValid = true; - bool pinValid = true; - - if (m_ui->password->passwordOption() == PasswordField::StoreForUser || - m_ui->password->passwordOption() == PasswordField::StoreForAllUsers) { - passwordUserValid = !m_ui->username->text().isEmpty() && !m_ui->password->text().isEmpty(); - } else if (m_ui->password->passwordOption() == PasswordField::AlwaysAsk) { - passwordUserValid = !m_ui->username->text().isEmpty(); - } - - if (m_ui->pin->passwordOption() == PasswordField::StoreForUser || - m_ui->pin->passwordOption() == PasswordField::StoreForAllUsers) { - pinValid = !m_ui->pin->text().isEmpty(); - } - - return !m_ui->apn->text().isEmpty() && passwordUserValid && pinValid; -} diff --git a/libs/editor/settings/gsmwidget.h b/libs/editor/settings/gsmwidget.h deleted file mode 100644 index ea16c476..00000000 --- a/libs/editor/settings/gsmwidget.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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_GSM_WIDGET_H -#define PLASMA_NM_GSM_WIDGET_H - -#include - -#include - -#include "settingwidget.h" - -namespace Ui -{ -class GsmWidget; -} - -class Q_DECL_EXPORT GsmWidget : public SettingWidget -{ - Q_OBJECT -public: - explicit GsmWidget(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), QWidget *parent = nullptr, Qt::WindowFlags f = {}); - ~GsmWidget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - void loadSecrets(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -private: - Ui::GsmWidget *m_ui; -}; - -#endif // PLASMA_NM_GSM_WIDGET_H diff --git a/libs/editor/settings/infinibandwidget.cpp b/libs/editor/settings/infinibandwidget.cpp deleted file mode 100644 index e9bbdae5..00000000 --- a/libs/editor/settings/infinibandwidget.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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 "infinibandwidget.h" -#include "ui_infiniband.h" -#include "uiutils.h" - -#include - -#include -#include - -InfinibandWidget::InfinibandWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting, parent, f), - m_ui(new Ui::InfinibandWidget) -{ - m_ui->setupUi(this); - - m_ui->transport->addItem(i18nc("infiniband transport mode", "Datagram"), NetworkManager::InfinibandSetting::Datagram); - m_ui->transport->addItem(i18nc("infiniband transport mode", "Connected"), NetworkManager::InfinibandSetting::Connected); - m_ui->transport->setCurrentIndex(0); - - // Connect for setting check - watchChangedSetting(); - - // Connect for validity check - connect(m_ui->macAddress, &HwAddrComboBox::hwAddressChanged, this, &InfinibandWidget::slotWidgetChanged); - - KAcceleratorManager::manage(this); - - if (setting) { - loadConfig(setting); - } -} - -InfinibandWidget::~InfinibandWidget() -{ - delete m_ui; -} - -void InfinibandWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::InfinibandSetting::Ptr infinibandSetting = setting.staticCast(); - - if (infinibandSetting->transportMode() != NetworkManager::InfinibandSetting::Unknown) { - if (infinibandSetting->transportMode() == NetworkManager::InfinibandSetting::Datagram) { - m_ui->transport->setCurrentIndex(0); - } else if (infinibandSetting->transportMode() == NetworkManager::InfinibandSetting::Connected) { - m_ui->transport->setCurrentIndex(1); - } - } - m_ui->macAddress->init(NetworkManager::Device::InfiniBand, NetworkManager::macAddressAsString(infinibandSetting->macAddress())); - if (infinibandSetting->mtu()) { - m_ui->mtu->setValue(infinibandSetting->mtu()); - } -} - -QVariantMap InfinibandWidget::setting() const -{ - NetworkManager::InfinibandSetting setting; - if (m_ui->transport->currentIndex() == 0) { - setting.setTransportMode(NetworkManager::InfinibandSetting::Datagram); - } else { - setting.setTransportMode(NetworkManager::InfinibandSetting::Connected); - } - setting.setMacAddress(NetworkManager::macAddressFromString(m_ui->macAddress->hwAddress())); - if (m_ui->mtu->value()) { - setting.setMtu(m_ui->mtu->value()); - } - - return setting.toMap(); -} - -bool InfinibandWidget::isValid() const -{ - return m_ui->macAddress->isValid(); -} diff --git a/libs/editor/settings/infinibandwidget.h b/libs/editor/settings/infinibandwidget.h deleted file mode 100644 index 9e8e90b7..00000000 --- a/libs/editor/settings/infinibandwidget.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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_INFINIBAND_WIDGET_H -#define PLASMA_NM_INFINIBAND_WIDGET_H - -#include - -#include - -#include "settingwidget.h" - -namespace Ui -{ -class InfinibandWidget; -} - -class Q_DECL_EXPORT InfinibandWidget : public SettingWidget -{ - Q_OBJECT -public: - explicit InfinibandWidget(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~InfinibandWidget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -private: - Ui::InfinibandWidget * m_ui; -}; - -#endif // PLASMA_NM_INFI_WIDGET_H diff --git a/libs/editor/settings/ipv4widget.cpp b/libs/editor/settings/ipv4widget.cpp deleted file mode 100644 index 7bfb7304..00000000 --- a/libs/editor/settings/ipv4widget.cpp +++ /dev/null @@ -1,566 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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 "ipv4widget.h" -#include "ui_ipv4.h" -#include "ipv4delegate.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -quint32 suggestNetmask(quint32 ip) -{ - /* - A 0 0.0.0.0 <-->127.255.255.255 255.0.0.0 <--->/8 - B 10 128.0.0.0 <>191.255.255.255 255.255.0.0 <->/16 - C 110 192.0.0.0 <>223.255.255.255 255.255.255.0 >/24 - D 1110 224.0.0.0 <>239.255.255.255 not defined <->not defined - E 1111 240.0.0.0 <>255.255.255.254 not defined <->not defined - */ - quint32 netmask = 0; - - if (!(ip & 0x80000000)) { - // test 0 leading bit - netmask = 0xFF000000; - } - else if (!(ip & 0x40000000)) { - // test 10 leading bits - netmask = 0xFFFF0000; - } - else if (!(ip & 0x20000000)) { - // test 110 leading bits - netmask = 0xFFFFFF00; - } - - return netmask; -} - -class IPv4Widget::Private -{ -public: - Private() : model(0,3) - { - QStandardItem * headerItem = new QStandardItem(i18nc("Header text for IPv4 address", "Address")); - model.setHorizontalHeaderItem(0, headerItem); - headerItem = new QStandardItem(i18nc("Header text for IPv4 netmask", "Netmask")); - model.setHorizontalHeaderItem(1, headerItem); - headerItem = new QStandardItem(i18nc("Header text for IPv4 gateway", "Gateway")); - model.setHorizontalHeaderItem(2, headerItem); - } - QStandardItemModel model; -}; - - -IPv4Widget::IPv4Widget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting, parent, f), - m_ui(new Ui::IPv4Widget), - d(new IPv4Widget::Private()) -{ - m_ui->setupUi(this); - - m_ui->tableViewAddresses->setModel(&d->model); - m_ui->tableViewAddresses->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); - m_ui->tableViewAddresses->horizontalHeader()->setStretchLastSection(true); - - IpV4Delegate *ipDelegate = new IpV4Delegate(this); - m_ui->tableViewAddresses->setItemDelegateForColumn(0, ipDelegate); - m_ui->tableViewAddresses->setItemDelegateForColumn(1, ipDelegate); - m_ui->tableViewAddresses->setItemDelegateForColumn(2, ipDelegate); - - connect(m_ui->btnAdd, &QPushButton::clicked, this, &IPv4Widget::slotAddIPAddress); - connect(m_ui->btnRemove, &QPushButton::clicked, this, &IPv4Widget::slotRemoveIPAddress); - - connect(m_ui->dnsMorePushButton, &QPushButton::clicked, this, &IPv4Widget::slotDnsServers); - connect(m_ui->dnsSearchMorePushButton, &QPushButton::clicked, this, &IPv4Widget::slotDnsDomains); - - connect(m_ui->tableViewAddresses->selectionModel(), &QItemSelectionModel::selectionChanged, this, &IPv4Widget::selectionChanged); - - connect(&d->model, &QStandardItemModel::itemChanged, this, &IPv4Widget::tableViewItemChanged); - - if (setting) { - loadConfig(setting); - } - - connect(m_ui->method, QOverload::of(&KComboBox::currentIndexChanged), this, &IPv4Widget::slotModeComboChanged); - slotModeComboChanged(m_ui->method->currentIndex()); - - connect(m_ui->btnRoutes, &QPushButton::clicked, this, &IPv4Widget::slotRoutesDialog); - connect(m_ui->btnAdvanced, &QPushButton::clicked, this, &IPv4Widget::slotAdvancedDialog); - - // Connect for setting check - watchChangedSetting(); - - // Connect for validity check - connect(m_ui->dns, &KLineEdit::textChanged, this, &IPv4Widget::slotWidgetChanged); - connect(m_ui->method, QOverload::of(&KComboBox::currentIndexChanged), this, &IPv4Widget::slotWidgetChanged); - connect(&d->model, &QStandardItemModel::dataChanged, this, &IPv4Widget::slotWidgetChanged); - connect(&d->model, &QStandardItemModel::rowsRemoved, this, &IPv4Widget::slotWidgetChanged); - - KAcceleratorManager::manage(this); -} - -IPv4Widget::~IPv4Widget() -{ - delete d; - delete m_ui; -} - -void IPv4Widget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::Ipv4Setting::Ptr ipv4Setting = setting.staticCast(); - - // BUG:406118 - // We don't have route-metric in the UI, maybe even won't have for now, but that doesn't mean we - // want to loose it when it's configured manually in a config file - m_tmpIpv4Setting.setRouteMetric(ipv4Setting->routeMetric()); - - m_tmpIpv4Setting.setRoutes(ipv4Setting->routes()); - m_tmpIpv4Setting.setNeverDefault(ipv4Setting->neverDefault()); - m_tmpIpv4Setting.setIgnoreAutoRoutes(ipv4Setting->ignoreAutoRoutes()); - - m_tmpIpv4Setting.setDhcpHostname(ipv4Setting->dhcpHostname()); - m_tmpIpv4Setting.setDhcpSendHostname(ipv4Setting->dhcpSendHostname()); - m_tmpIpv4Setting.setDadTimeout(ipv4Setting->dadTimeout()); - - // method - switch (ipv4Setting->method()) { - case NetworkManager::Ipv4Setting::Automatic: - if (ipv4Setting->ignoreAutoDns()) { - m_ui->method->setCurrentIndex(AutomaticOnlyIP); - } else { - m_ui->method->setCurrentIndex(Automatic); - } - break; - case NetworkManager::Ipv4Setting::Manual: - m_ui->method->setCurrentIndex(Manual); - break; - case NetworkManager::Ipv4Setting::LinkLocal: - m_ui->method->setCurrentIndex(LinkLocal); - break; - case NetworkManager::Ipv4Setting::Shared: - m_ui->method->setCurrentIndex(Shared); - break; - case NetworkManager::Ipv4Setting::Disabled: - m_ui->method->setCurrentIndex(Disabled); - break; - } - - // dns - QStringList tmp; - for (const QHostAddress &addr : ipv4Setting->dns()) { - tmp.append(addr.toString()); - } - m_ui->dns->setText(tmp.join(",")); - m_ui->dnsSearch->setText(ipv4Setting->dnsSearch().join(",")); - - m_ui->dhcpClientId->setText(ipv4Setting->dhcpClientId()); - - // addresses - for (const NetworkManager::IpAddress &addr : ipv4Setting->addresses()) { - QList item; - item << new QStandardItem(addr.ip().toString()) - << new QStandardItem(addr.netmask().toString()) - << new QStandardItem(addr.gateway().toString()); - - d->model.appendRow(item); - } - - // may-fail - m_ui->ipv4RequiredCB->setChecked(!ipv4Setting->mayFail()); -} - -QVariantMap IPv4Widget::setting() const -{ - NetworkManager::Ipv4Setting ipv4Setting; - - // BUG:406118 - // We don't have route-metric in the UI, maybe even won't have for now, but that doesn't mean we - // want to loose it when it's configured manually in a config file - ipv4Setting.setRouteMetric(m_tmpIpv4Setting.routeMetric()); - - ipv4Setting.setRoutes(m_tmpIpv4Setting.routes()); - ipv4Setting.setNeverDefault(m_tmpIpv4Setting.neverDefault()); - ipv4Setting.setIgnoreAutoRoutes(m_tmpIpv4Setting.ignoreAutoRoutes()); - - ipv4Setting.setDhcpHostname(m_tmpIpv4Setting.dhcpHostname()); - ipv4Setting.setDhcpSendHostname(m_tmpIpv4Setting.dhcpSendHostname()); - ipv4Setting.setDadTimeout(m_tmpIpv4Setting.dadTimeout()); - - // method - switch ((MethodIndex)m_ui->method->currentIndex()) { - case Automatic: - ipv4Setting.setMethod(NetworkManager::Ipv4Setting::Automatic); - break; - case IPv4Widget::AutomaticOnlyIP: - ipv4Setting.setMethod(NetworkManager::Ipv4Setting::Automatic); - ipv4Setting.setIgnoreAutoDns(true); - break; - case Manual: - ipv4Setting.setMethod(NetworkManager::Ipv4Setting::Manual); - break; - case LinkLocal: - ipv4Setting.setMethod(NetworkManager::Ipv4Setting::LinkLocal); - break; - case Shared: - ipv4Setting.setMethod(NetworkManager::Ipv4Setting::Shared); - break; - case Disabled: - ipv4Setting.setMethod(NetworkManager::Ipv4Setting::Disabled); - break; - } - - // dns - if (m_ui->dns->isEnabled() && !m_ui->dns->text().isEmpty()) { - QStringList tmp = m_ui->dns->text().split(','); - QList tmpAddrList; - for (const QString &str : tmp) { - QHostAddress addr(str); - if (!addr.isNull()) - tmpAddrList.append(addr); - } - ipv4Setting.setDns(tmpAddrList); - } - if (m_ui->dnsSearch->isEnabled() && !m_ui->dnsSearch->text().isEmpty()) { - ipv4Setting.setDnsSearch(m_ui->dnsSearch->text().split(',')); - } - - // dhcp id - if (m_ui->dhcpClientId->isEnabled() && !m_ui->dhcpClientId->text().isEmpty()) { - ipv4Setting.setDhcpClientId(m_ui->dhcpClientId->text()); - } - - // addresses - if (m_ui->tableViewAddresses->isEnabled()) { - QList list; - for (int i = 0, rowCount = d->model.rowCount(); i < rowCount; i++) { - NetworkManager::IpAddress address; - address.setIp(QHostAddress(d->model.item(i, 0)->text())); - address.setNetmask(QHostAddress(d->model.item(i, 1)->text())); - address.setGateway(QHostAddress(d->model.item(i, 2)->text())); - list << address; - } - if (!list.isEmpty()) { - ipv4Setting.setAddresses(list); - } - } - - // may-fail - if (m_ui->ipv4RequiredCB->isEnabled()) { - ipv4Setting.setMayFail(!m_ui->ipv4RequiredCB->isChecked()); - } - - return ipv4Setting.toMap(); -} - -void IPv4Widget::slotModeComboChanged(int index) -{ - if (index == Automatic) { // Automatic - m_ui->dnsLabel->setText(i18n("Other DNS Servers:")); - m_ui->dns->setEnabled(true); - m_ui->dnsMorePushButton->setEnabled(true); - m_ui->dnsSearch->setEnabled(true); - m_ui->dnsSearchMorePushButton->setEnabled(true); - m_ui->dhcpClientId->setEnabled(true); - m_ui->ipv4RequiredCB->setEnabled(true); - m_ui->btnRoutes->setEnabled(true); - m_ui->tableViewAddresses->setEnabled(false); - m_ui->btnAdd->setEnabled(false); - m_ui->btnRemove->setEnabled(false); - } else if (index == AutomaticOnlyIP) { - m_ui->dnsLabel->setText(i18n("DNS Servers:")); - m_ui->dns->setEnabled(true); - m_ui->dnsMorePushButton->setEnabled(true); - m_ui->dnsSearch->setEnabled(true); - m_ui->dnsSearchMorePushButton->setEnabled(true); - m_ui->dhcpClientId->setEnabled(true); - m_ui->ipv4RequiredCB->setEnabled(true); - m_ui->btnRoutes->setEnabled(true); - m_ui->tableViewAddresses->setEnabled(false); - m_ui->btnAdd->setEnabled(false); - m_ui->btnRemove->setEnabled(false); - } else if (index == Manual) { // Manual - m_ui->dnsLabel->setText(i18n("DNS Servers:")); - m_ui->dns->setEnabled(true); - m_ui->dnsMorePushButton->setEnabled(true); - m_ui->dnsSearch->setEnabled(true); - m_ui->dnsSearchMorePushButton->setEnabled(true); - m_ui->dhcpClientId->setEnabled(false); - m_ui->ipv4RequiredCB->setEnabled(true); - m_ui->btnRoutes->setEnabled(true); - m_ui->tableViewAddresses->setEnabled(true); - m_ui->btnAdd->setEnabled(true); - m_ui->btnRemove->setEnabled(true); - } else if (index == LinkLocal || index == Shared) { // Link-local or Shared - m_ui->dnsLabel->setText(i18n("DNS Servers:")); - m_ui->dns->setEnabled(false); - m_ui->dnsMorePushButton->setEnabled(false); - m_ui->dnsSearch->setEnabled(false); - m_ui->dnsSearchMorePushButton->setEnabled(false); - m_ui->dhcpClientId->setEnabled(false); - m_ui->ipv4RequiredCB->setEnabled(true); - m_ui->btnRoutes->setEnabled(false); - m_ui->tableViewAddresses->setEnabled(false); - m_ui->btnAdd->setEnabled(false); - m_ui->btnRemove->setEnabled(false); - } else if (index == Disabled) { // Disabled - m_ui->dnsLabel->setText(i18n("DNS Servers:")); - m_ui->dns->setEnabled(false); - m_ui->dnsMorePushButton->setEnabled(false); - m_ui->dnsSearch->setEnabled(false); - m_ui->dnsSearchMorePushButton->setEnabled(false); - m_ui->dhcpClientId->setEnabled(false); - m_ui->ipv4RequiredCB->setEnabled(false); - m_ui->btnRoutes->setEnabled(false); - m_ui->tableViewAddresses->setEnabled(false); - m_ui->btnAdd->setEnabled(false); - m_ui->btnRemove->setEnabled(false); - } -} - -void IPv4Widget::slotAddIPAddress() -{ - QList item; - item << new QStandardItem << new QStandardItem << new QStandardItem; - d->model.appendRow(item); - - const int rowCount = d->model.rowCount(); - if (rowCount > 0) { - m_ui->tableViewAddresses->selectRow(rowCount - 1); - - QItemSelectionModel * selectionModel = m_ui->tableViewAddresses->selectionModel(); - QModelIndexList list = selectionModel->selectedIndexes(); - if (!list.isEmpty()) { - // QTableView is configured to select only rows. - // So, list[0] - IP address. - m_ui->tableViewAddresses->edit(list[0]); - } - } -} - -void IPv4Widget::slotRemoveIPAddress() -{ - QItemSelectionModel * selectionModel = m_ui->tableViewAddresses->selectionModel(); - if (selectionModel->hasSelection()) { - QModelIndexList indexes = selectionModel->selectedIndexes(); - d->model.takeRow(indexes[0].row()); - } - m_ui->btnRemove->setEnabled(m_ui->tableViewAddresses->selectionModel()->hasSelection()); -} - -void IPv4Widget::selectionChanged(const QItemSelection & selected) -{ - m_ui->btnRemove->setEnabled(!selected.isEmpty()); -} - -void IPv4Widget::tableViewItemChanged(QStandardItem *item) -{ - if (item->text().isEmpty()) { - return; - } - - const int column = item->column(); - if (column == 0) { // ip - int row = item->row(); - - QStandardItem *netmaskItem = d->model.item(row, column + 1); // netmask - if (netmaskItem && netmaskItem->text().isEmpty()) { - QHostAddress addr(item->text()); - const quint32 netmask = suggestNetmask(addr.toIPv4Address()); - if (netmask) { - QHostAddress v(netmask); - netmaskItem->setText(v.toString()); - } - } - } -} - -void IPv4Widget::slotRoutesDialog() -{ - QPointer dlg = new IpV4RoutesWidget(this); - - dlg->setRoutes(m_tmpIpv4Setting.routes()); - dlg->setNeverDefault(m_tmpIpv4Setting.neverDefault()); - if (m_ui->method->currentIndex() == 2) { // manual - dlg->setIgnoreAutoRoutesCheckboxEnabled(false); - } else { - dlg->setIgnoreAutoRoutes(m_tmpIpv4Setting.ignoreAutoRoutes()); - } - - connect(dlg.data(), &QDialog::accepted, - [dlg, this] () { - m_tmpIpv4Setting.setRoutes(dlg->routes()); - m_tmpIpv4Setting.setNeverDefault(dlg->neverDefault()); - m_tmpIpv4Setting.setIgnoreAutoRoutes(dlg->ignoreautoroutes()); - }); - connect(dlg.data(), &QDialog::finished, - [dlg] () { - if (dlg) { - dlg->deleteLater(); - } - }); - dlg->setModal(true); - dlg->show(); -} - -void IPv4Widget::slotAdvancedDialog() -{ - auto dlg = new QDialog(this); - dlg->setAttribute(Qt::WA_DeleteOnClose); - - auto layout = new QFormLayout(dlg); - dlg->setLayout(layout); - - layout->addRow(new QLabel(i18n("You can find more information about these values here:
https://developer.gnome.org/NetworkManager/stable/nm-settings.html
"))); - - auto sendHostname = new QCheckBox(dlg); - sendHostname->setChecked(m_tmpIpv4Setting.dhcpSendHostname()); - layout->addRow(i18n("Send hostname:"), sendHostname); - - auto dhcpHostname = new QLineEdit(dlg); - dhcpHostname->setText(m_tmpIpv4Setting.dhcpHostname()); - dhcpHostname->setPlaceholderText(QHostInfo::localHostName()); - layout->addRow(i18n("DHCP hostname:"), dhcpHostname); - - connect(sendHostname, &QCheckBox::toggled, dhcpHostname, &QLineEdit::setEnabled); - - auto dadTimeout = new QSpinBox(dlg); - dadTimeout->setSpecialValueText(i18n("Default")); - dadTimeout->setSuffix(i18nc("Milliseconds", " ms")); - dadTimeout->setMinimum(-1); - dadTimeout->setValue(m_tmpIpv4Setting.dadTimeout()); - layout->addRow(i18n("DAD timeout:"), dadTimeout); - - QDialogButtonBox* box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dlg); - connect(box, &QDialogButtonBox::accepted, dlg, &QDialog::accept); - connect(box, &QDialogButtonBox::rejected, dlg, &QDialog::reject); - layout->addWidget(box); - - connect(dlg, &QDialog::accepted, this, - [=] () { - m_tmpIpv4Setting.setDhcpSendHostname(sendHostname->isChecked()); - m_tmpIpv4Setting.setDhcpHostname(dhcpHostname->text()); - m_tmpIpv4Setting.setDadTimeout(dadTimeout->value()); - }); - - dlg->setModal(true); - dlg->show(); -} - -void IPv4Widget::slotDnsServers() -{ - QPointer dialog = new QDialog(this); - dialog->setWindowTitle(i18n("Edit DNS servers")); - dialog->setLayout(new QVBoxLayout); - QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, dialog); - connect(buttons, &QDialogButtonBox::accepted, dialog.data(), &QDialog::accept); - connect(buttons, &QDialogButtonBox::rejected, dialog.data(), &QDialog::reject); - KEditListWidget * listWidget = new KEditListWidget(dialog); - listWidget->setItems(m_ui->dns->text().split(',').replaceInStrings(" ", "")); - listWidget->lineEdit()->setFocus(Qt::OtherFocusReason); - dialog->layout()->addWidget(listWidget); - dialog->layout()->addWidget(buttons); - connect(dialog.data(), &QDialog::accepted, - [listWidget, this] () { - QString text = listWidget->items().join(","); - if (text.endsWith(',')) { - text.chop(1); - } - m_ui->dns->setText(text); - }); - connect(dialog.data(), &QDialog::finished, - [dialog] () { - if (dialog) { - dialog->deleteLater(); - } - }); - dialog->setModal(true); - dialog->show(); -} - -void IPv4Widget::slotDnsDomains() -{ - QPointer dialog = new QDialog(this); - dialog->setWindowTitle(i18n("Edit DNS search domains")); - dialog->setLayout(new QVBoxLayout); - QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, dialog); - connect(buttons, &QDialogButtonBox::accepted, dialog.data(), &QDialog::accept); - connect(buttons, &QDialogButtonBox::rejected, dialog.data(), &QDialog::reject); - KEditListWidget * listWidget = new KEditListWidget(dialog); - listWidget->setItems(m_ui->dnsSearch->text().split(',').replaceInStrings(" ", "")); - listWidget->lineEdit()->setFocus(Qt::OtherFocusReason); - dialog->layout()->addWidget(listWidget); - dialog->layout()->addWidget(buttons); - connect(dialog.data(), &QDialog::accepted, - [listWidget, this] () { - QString text = listWidget->items().join(","); - if (text.endsWith(',')) { - text.chop(1); - } - m_ui->dnsSearch->setText(text); - }); - connect(dialog.data(), &QDialog::finished, - [dialog] () { - if (dialog) { - dialog->deleteLater(); - } - }); - dialog->setModal(true); - dialog->show(); -} - -bool IPv4Widget::isValid() const -{ - if (m_ui->method->currentIndex() == Manual) { - if (!d->model.rowCount()) { - return false; - } - - for (int i = 0, rowCount = d->model.rowCount(); i < rowCount; i++) { - QHostAddress ip = QHostAddress(d->model.item(i, 0)->text()); - QHostAddress netmask = QHostAddress(d->model.item(i, 1)->text()); - QHostAddress gateway = QHostAddress(d->model.item(i, 2)->text()); - - if (ip.isNull() || netmask.isNull() || (gateway.isNull() && !d->model.item(i, 2)->text().isEmpty())) { - return false; - } - } - } - - if (!m_ui->dns->text().isEmpty() && (m_ui->method->currentIndex() == Automatic || m_ui->method->currentIndex() == Manual || m_ui->method->currentIndex() == AutomaticOnlyIP)) { - const QStringList tmp = m_ui->dns->text().split(','); - for (const QString &str : tmp) { - QHostAddress addr(str); - if (addr.isNull()) { - return false; - } - } - } - - return true; -} diff --git a/libs/editor/settings/ipv4widget.h b/libs/editor/settings/ipv4widget.h deleted file mode 100644 index 469fc5ff..00000000 --- a/libs/editor/settings/ipv4widget.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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_IPV4_WIDGET_H -#define PLASMA_NM_IPV4_WIDGET_H - -#include -#include - -#include "settingwidget.h" -#include "ipv4routeswidget.h" - -namespace Ui -{ -class IPv4Widget; -} - -class Q_DECL_EXPORT IPv4Widget : public SettingWidget -{ -Q_OBJECT -public: - enum MethodIndex { Automatic = 0, AutomaticOnlyIP, LinkLocal, Manual, Shared, Disabled }; - - explicit IPv4Widget(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~IPv4Widget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -private Q_SLOTS: - void slotModeComboChanged(int index); - void slotRoutesDialog(); - void slotAdvancedDialog(); - - void slotDnsServers(); - void slotDnsDomains(); - - void slotAddIPAddress(); - void slotRemoveIPAddress(); - - void selectionChanged(const QItemSelection & selected); - void tableViewItemChanged(QStandardItem * item); - -private: - Ui::IPv4Widget * m_ui; - NetworkManager::Ipv4Setting m_tmpIpv4Setting; - - class Private; - Private * const d; -}; - -#endif // PLASMA_NM_IPV4_WIDGET_H diff --git a/libs/editor/settings/ipv6widget.cpp b/libs/editor/settings/ipv6widget.cpp deleted file mode 100644 index f6ac8c1e..00000000 --- a/libs/editor/settings/ipv6widget.cpp +++ /dev/null @@ -1,501 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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 "ipv6widget.h" -#include "ui_ipv6.h" -#include "ipv6delegate.h" -#include "intdelegate.h" - -#include -#include -#include -#include -#include - -#include -#include - -quint32 suggestNetmask(Q_IPV6ADDR ip) -{ - Q_UNUSED(ip); - - /* - TODO: find out common IPv6-netmasks and make a complete function - - */ - quint32 netmask = 64; - - return netmask; -} - -class IPv6Widget::Private -{ -public: - Private() : model(0,3) - { - QStandardItem * headerItem = new QStandardItem(i18nc("Header text for IPv6 address", "Address")); - model.setHorizontalHeaderItem(0, headerItem); - headerItem = new QStandardItem(i18nc("Header text for IPv6 prefix", "Prefix")); - model.setHorizontalHeaderItem(1, headerItem); - headerItem = new QStandardItem(i18nc("Header text for IPv6 gateway", "Gateway")); - model.setHorizontalHeaderItem(2, headerItem); - } - QStandardItemModel model; -}; - - -IPv6Widget::IPv6Widget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting, parent, f), - m_ui(new Ui::IPv6Widget), - d(new IPv6Widget::Private()) -{ - m_ui->setupUi(this); - - m_ui->tableViewAddresses->setModel(&d->model); - m_ui->tableViewAddresses->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); - m_ui->tableViewAddresses->horizontalHeader()->setStretchLastSection(true); - - IpV6Delegate *ipDelegate = new IpV6Delegate(this); - IntDelegate *prefixDelegate = new IntDelegate (0, 128, this); - m_ui->tableViewAddresses->setItemDelegateForColumn(0, ipDelegate); - m_ui->tableViewAddresses->setItemDelegateForColumn(1, prefixDelegate); - m_ui->tableViewAddresses->setItemDelegateForColumn(2, ipDelegate); - - connect(m_ui->btnAdd, &QPushButton::clicked, this, &IPv6Widget::slotAddIPAddress); - connect(m_ui->btnRemove, &QPushButton::clicked, this, &IPv6Widget::slotRemoveIPAddress); - - connect(m_ui->dnsMorePushButton, &QPushButton::clicked, this, &IPv6Widget::slotDnsServers); - connect(m_ui->dnsSearchMorePushButton, &QPushButton::clicked, this, &IPv6Widget::slotDnsDomains); - - connect(m_ui->tableViewAddresses->selectionModel(), &QItemSelectionModel::selectionChanged, this, &IPv6Widget::selectionChanged); - - - connect(&d->model, &QStandardItemModel::itemChanged, this, &IPv6Widget::tableViewItemChanged); - - if (setting) { - loadConfig(setting); - } - - connect(m_ui->method, QOverload::of(&KComboBox::currentIndexChanged), this, &IPv6Widget::slotModeComboChanged); - slotModeComboChanged(m_ui->method->currentIndex()); - - connect(m_ui->btnRoutes, &QPushButton::clicked, this, &IPv6Widget::slotRoutesDialog); - - // Connect for setting check - watchChangedSetting(); - - // Connect for validity check - connect(m_ui->dns, &KLineEdit::textChanged, this, &IPv6Widget::slotWidgetChanged); - connect(m_ui->method, QOverload::of(&KComboBox::currentIndexChanged), this, &IPv6Widget::slotWidgetChanged); - connect(&d->model, &QStandardItemModel::dataChanged, this, &IPv6Widget::slotWidgetChanged); - connect(&d->model, &QStandardItemModel::rowsRemoved, this, &IPv6Widget::slotWidgetChanged); - - KAcceleratorManager::manage(this); -} - -IPv6Widget::~IPv6Widget() -{ - delete d; - delete m_ui; -} - -void IPv6Widget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::Ipv6Setting::Ptr ipv6Setting = setting.staticCast(); - - // BUG:406118 - // We don't have route-metric in the UI, maybe even won't have for now, but that doesn't mean we - // want to loose it when it's configured manually in a config file - m_tmpIpv6Setting.setRouteMetric(ipv6Setting->routeMetric()); - - m_tmpIpv6Setting.setRoutes(ipv6Setting->routes()); - m_tmpIpv6Setting.setNeverDefault(ipv6Setting->neverDefault()); - m_tmpIpv6Setting.setIgnoreAutoRoutes(ipv6Setting->ignoreAutoRoutes()); - - // method - switch (ipv6Setting->method()) { - case NetworkManager::Ipv6Setting::Automatic: - if (ipv6Setting->ignoreAutoDns()) { - m_ui->method->setCurrentIndex(AutomaticOnlyIP); - } else { - m_ui->method->setCurrentIndex(Automatic); - } - break; - case NetworkManager::Ipv6Setting::Dhcp: - m_ui->method->setCurrentIndex(AutomaticOnlyDHCP); - break; - case NetworkManager::Ipv6Setting::Manual: - m_ui->method->setCurrentIndex(Manual); - break; - case NetworkManager::Ipv6Setting::LinkLocal: - m_ui->method->setCurrentIndex(LinkLocal); - break; - case NetworkManager::Ipv6Setting::Ignored: - m_ui->method->setCurrentIndex(Disabled); - break; - } - - // dns - QStringList tmp; - for (const QHostAddress &addr : ipv6Setting->dns()) { - tmp.append(addr.toString()); - } - m_ui->dns->setText(tmp.join(",")); - m_ui->dnsSearch->setText(ipv6Setting->dnsSearch().join(",")); - - // addresses - for (const NetworkManager::IpAddress &address : ipv6Setting->addresses()) { - QList item; - - item << new QStandardItem(address.ip().toString()) - << new QStandardItem(QString::number(address.prefixLength(),10)) - << new QStandardItem(address.gateway().toString()); - - d->model.appendRow(item); - } - - // may-fail - m_ui->ipv6RequiredCB->setChecked(!ipv6Setting->mayFail()); - - // privacy - if (ipv6Setting->privacy() != NetworkManager::Ipv6Setting::Unknown) { - m_ui->privacyCombo->setCurrentIndex(static_cast(ipv6Setting->privacy()) + 1); - } -} - -QVariantMap IPv6Widget::setting() const -{ - NetworkManager::Ipv6Setting ipv6Setting; - - // BUG:406118 - // We don't have route-metric in the UI, maybe even won't have for now, but that doesn't mean we - // want to loose it when it's configured manually in a config file - ipv6Setting.setRouteMetric(m_tmpIpv6Setting.routeMetric()); - - ipv6Setting.setRoutes(m_tmpIpv6Setting.routes()); - ipv6Setting.setNeverDefault(m_tmpIpv6Setting.neverDefault()); - ipv6Setting.setIgnoreAutoRoutes(m_tmpIpv6Setting.ignoreAutoRoutes()); - - // method - switch ((MethodIndex)m_ui->method->currentIndex()) { - case Automatic: - ipv6Setting.setMethod(NetworkManager::Ipv6Setting::Automatic); - break; - case AutomaticOnlyIP: - ipv6Setting.setMethod(NetworkManager::Ipv6Setting::Automatic); - ipv6Setting.setIgnoreAutoDns(true); - break; - case IPv6Widget::AutomaticOnlyDHCP: - ipv6Setting.setMethod(NetworkManager::Ipv6Setting::Dhcp); - break; - case Manual: - ipv6Setting.setMethod(NetworkManager::Ipv6Setting::Manual); - break; - case LinkLocal: - ipv6Setting.setMethod(NetworkManager::Ipv6Setting::LinkLocal); - break; - case Disabled: - ipv6Setting.setMethod(NetworkManager::Ipv6Setting::Ignored); - break; - } - - // dns - if (m_ui->dns->isEnabled() && !m_ui->dns->text().isEmpty()) { - QStringList tmp = m_ui->dns->text().split(','); - QList tmpAddrList; - for (const QString &str : tmp) { - QHostAddress addr(str); - if (!addr.isNull()) - tmpAddrList.append(addr); - } - ipv6Setting.setDns(tmpAddrList); - } - if (m_ui->dnsSearch->isEnabled() && !m_ui->dnsSearch->text().isEmpty()) { - ipv6Setting.setDnsSearch(m_ui->dnsSearch->text().split(',')); - } - - // addresses - if (m_ui->tableViewAddresses->isEnabled()) { - QList list; - for (int i = 0, rowCount = d->model.rowCount(); i < rowCount; i++) { - NetworkManager::IpAddress address; - address.setIp(QHostAddress(d->model.item(i, 0)->text())); - address.setPrefixLength(d->model.item(i, 1)->text().toInt()); - address.setGateway(QHostAddress(d->model.item(i, 2)->text())); - - list << address; - } - ipv6Setting.setAddresses(list); - } - - // may-fail - if (m_ui->ipv6RequiredCB->isEnabled()) { - ipv6Setting.setMayFail(!m_ui->ipv6RequiredCB->isChecked()); - } - - // privacy - if (m_ui->privacyCombo->isEnabled() && m_ui->privacyCombo->currentIndex()) { - ipv6Setting.setPrivacy(static_cast(m_ui->privacyCombo->currentIndex() - 1)); - } - - return ipv6Setting.toMap(); -} - -void IPv6Widget::slotModeComboChanged(int index) -{ - if (index == Automatic) { // Automatic - m_ui->dnsLabel->setText(i18n("Other DNS Servers:")); - m_ui->dns->setEnabled(true); - m_ui->dnsMorePushButton->setEnabled(true); - m_ui->dnsSearch->setEnabled(true); - m_ui->dnsSearchMorePushButton->setEnabled(true); - m_ui->ipv6RequiredCB->setEnabled(true); - m_ui->privacyCombo->setEnabled(true); - m_ui->btnRoutes->setEnabled(true); - m_ui->tableViewAddresses->setEnabled(false); - m_ui->btnAdd->setEnabled(false); - m_ui->btnRemove->setEnabled(false); - } else if (index == AutomaticOnlyIP) { - m_ui->dnsLabel->setText(i18n("DNS Servers:")); - m_ui->dns->setEnabled(true); - m_ui->dnsMorePushButton->setEnabled(true); - m_ui->dnsSearch->setEnabled(true); - m_ui->dnsSearchMorePushButton->setEnabled(true); - m_ui->ipv6RequiredCB->setEnabled(true); - m_ui->privacyCombo->setEnabled(true); - m_ui->btnRoutes->setEnabled(true); - m_ui->tableViewAddresses->setEnabled(false); - m_ui->btnAdd->setEnabled(false); - m_ui->btnRemove->setEnabled(false); - } else if (index == Manual) { // Manual - m_ui->dnsLabel->setText(i18n("DNS Servers:")); - m_ui->dns->setEnabled(true); - m_ui->dnsMorePushButton->setEnabled(true); - m_ui->dnsSearch->setEnabled(true); - m_ui->dnsSearchMorePushButton->setEnabled(true); - m_ui->ipv6RequiredCB->setEnabled(true); - m_ui->privacyCombo->setEnabled(true); - m_ui->btnRoutes->setEnabled(true); - m_ui->tableViewAddresses->setEnabled(true); - m_ui->btnAdd->setEnabled(true); - m_ui->btnRemove->setEnabled(true); - } else if (index == AutomaticOnlyDHCP || index == LinkLocal) { // Link-local or DHCP - m_ui->dnsLabel->setText(i18n("DNS Servers:")); - m_ui->dns->setEnabled(false); - m_ui->dnsMorePushButton->setEnabled(false); - m_ui->dnsSearch->setEnabled(false); - m_ui->dnsSearchMorePushButton->setEnabled(false); - m_ui->ipv6RequiredCB->setEnabled(true); - m_ui->privacyCombo->setEnabled(true); - m_ui->btnRoutes->setEnabled(false); - m_ui->tableViewAddresses->setEnabled(false); - m_ui->btnAdd->setEnabled(false); - m_ui->btnRemove->setEnabled(false); - } else if (index == Disabled) { // Ignored - m_ui->dnsLabel->setText(i18n("DNS Servers:")); - m_ui->dns->setEnabled(false); - m_ui->dnsMorePushButton->setEnabled(false); - m_ui->dnsSearch->setEnabled(false); - m_ui->dnsSearchMorePushButton->setEnabled(false); - m_ui->ipv6RequiredCB->setEnabled(false); - m_ui->privacyCombo->setEnabled(false); - m_ui->btnRoutes->setEnabled(false); - m_ui->tableViewAddresses->setEnabled(false); - m_ui->btnAdd->setEnabled(false); - m_ui->btnRemove->setEnabled(false); - } -} - -void IPv6Widget::slotAddIPAddress() -{ - QList item; - item << new QStandardItem << new QStandardItem << new QStandardItem; - d->model.appendRow(item); - - const int rowCount = d->model.rowCount(); - if (rowCount > 0) { - m_ui->tableViewAddresses->selectRow(rowCount - 1); - - QItemSelectionModel * selectionModel = m_ui->tableViewAddresses->selectionModel(); - QModelIndexList list = selectionModel->selectedIndexes(); - if (list.size()) { - // QTableView is configured to select only rows. - // So, list[0] - IP address. - m_ui->tableViewAddresses->edit(list[0]); - } - } -} - -void IPv6Widget::slotRemoveIPAddress() -{ - QItemSelectionModel * selectionModel = m_ui->tableViewAddresses->selectionModel(); - if (selectionModel->hasSelection()) { - QModelIndexList indexes = selectionModel->selectedIndexes(); - d->model.takeRow(indexes[0].row()); - } - m_ui->btnRemove->setEnabled(m_ui->tableViewAddresses->selectionModel()->hasSelection()); -} - -void IPv6Widget::selectionChanged(const QItemSelection & selected) -{ - m_ui->btnRemove->setEnabled(!selected.isEmpty()); -} - -void IPv6Widget::tableViewItemChanged(QStandardItem *item) -{ - if (item->text().isEmpty()) { - return; - } - - const int column = item->column(); - if (column == 0) { // ip - int row = item->row(); - - QStandardItem *netmaskItem = d->model.item(row, column + 1); // netmask - if (netmaskItem && netmaskItem->text().isEmpty()) { - QHostAddress addr(item->text()); - const quint32 netmask = suggestNetmask(addr.toIPv6Address()); - if (netmask) { - netmaskItem->setText(QString::number(netmask,10)); - } - } - } -} - -void IPv6Widget::slotRoutesDialog() -{ - QPointer dlg = new IpV6RoutesWidget(this); - - dlg->setRoutes(m_tmpIpv6Setting.routes()); - dlg->setNeverDefault(m_tmpIpv6Setting.neverDefault()); - if (m_ui->method->currentIndex() == 3) { // manual - dlg->setIgnoreAutoRoutesCheckboxEnabled(false); - } else { - dlg->setIgnoreAutoRoutes(m_tmpIpv6Setting.ignoreAutoRoutes()); - } - - connect(dlg.data(), &QDialog::accepted, - [dlg, this] () { - m_tmpIpv6Setting.setRoutes(dlg->routes()); - m_tmpIpv6Setting.setNeverDefault(dlg->neverDefault()); - m_tmpIpv6Setting.setIgnoreAutoRoutes(dlg->ignoreautoroutes()); - }); - connect(dlg.data(), &QDialog::finished, - [dlg] () { - if (dlg) { - dlg->deleteLater(); - } - }); - dlg->setModal(true); - dlg->show(); -} - -void IPv6Widget::slotDnsServers() -{ - QPointer dialog = new QDialog(this); - dialog->setWindowTitle(i18n("Edit DNS servers")); - dialog->setLayout(new QVBoxLayout); - QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, dialog); - connect(buttons, &QDialogButtonBox::accepted, dialog.data(), &QDialog::accept); - connect(buttons, &QDialogButtonBox::rejected, dialog.data(), &QDialog::reject); - KEditListWidget * listWidget = new KEditListWidget(dialog); - listWidget->setItems(m_ui->dns->text().split(',').replaceInStrings(" ", "")); - listWidget->lineEdit()->setFocus(Qt::OtherFocusReason); - dialog->layout()->addWidget(listWidget); - dialog->layout()->addWidget(buttons); - connect(dialog.data(), &QDialog::accepted, - [listWidget, this] () { - QString text = listWidget->items().join(","); - if (text.endsWith(',')) { - text.chop(1); - } - m_ui->dns->setText(text); - }); - connect(dialog.data(), &QDialog::finished, - [dialog] () { - if (dialog) { - dialog->deleteLater(); - } - }); - dialog->setModal(true); - dialog->show(); -} - -void IPv6Widget::slotDnsDomains() -{ - QPointer dialog = new QDialog(this); - dialog->setWindowTitle(i18n("Edit DNS search domains")); - dialog->setLayout(new QVBoxLayout); - QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, dialog); - connect(buttons, &QDialogButtonBox::accepted, dialog.data(), &QDialog::accept); - connect(buttons, &QDialogButtonBox::rejected, dialog.data(), &QDialog::reject); - KEditListWidget * listWidget = new KEditListWidget(dialog); - listWidget->setItems(m_ui->dnsSearch->text().split(',').replaceInStrings(" ", "")); - listWidget->lineEdit()->setFocus(Qt::OtherFocusReason); - dialog->layout()->addWidget(listWidget); - dialog->layout()->addWidget(buttons); - connect(dialog.data(), &QDialog::accepted, - [listWidget, this] () { - QString text = listWidget->items().join(","); - if (text.endsWith(',')) { - text.chop(1); - } - m_ui->dnsSearch->setText(text); - }); - connect(dialog.data(), &QDialog::finished, - [dialog] () { - if (dialog) { - dialog->deleteLater(); - } - }); - dialog->setModal(true); - dialog->show(); -} - -bool IPv6Widget::isValid() const -{ - if (m_ui->method->currentIndex() == Manual) { - if (!d->model.rowCount()) { - return false; - } - - for (int i = 0, rowCount = d->model.rowCount(); i < rowCount; i++) { - QHostAddress ip = QHostAddress(d->model.item(i, 0)->text()); - const int prefix = d->model.item(i,1)->text().toInt(); - QHostAddress gateway = QHostAddress(d->model.item(i, 2)->text()); - - if (ip.isNull() || !(prefix >= 1 && prefix <= 128) || (gateway.isNull() && !d->model.item(i, 2)->text().isEmpty())) { - return false; - } - } - } - - if (!m_ui->dns->text().isEmpty() && (m_ui->method->currentIndex() == Automatic || m_ui->method->currentIndex() == Manual || m_ui->method->currentIndex() == AutomaticOnlyIP)) { - const QStringList tmp = m_ui->dns->text().split(','); - for (const QString &str : tmp) { - QHostAddress addr(str); - if (addr.isNull()) { - return false; - } - } - } - - return true; -} diff --git a/libs/editor/settings/ipv6widget.h b/libs/editor/settings/ipv6widget.h deleted file mode 100644 index 4dc80ba2..00000000 --- a/libs/editor/settings/ipv6widget.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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_IPV6_WIDGET_H -#define PLASMA_NM_IPV6_WIDGET_H - -#include -#include - -#include "settingwidget.h" -#include "ipv6routeswidget.h" - -namespace Ui -{ -class IPv6Widget; -} - -class Q_DECL_EXPORT IPv6Widget : public SettingWidget -{ -Q_OBJECT -public: - enum MethodIndex { Automatic = 0, AutomaticOnlyIP, AutomaticOnlyDHCP, LinkLocal, Manual, Disabled }; - - explicit IPv6Widget(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~IPv6Widget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -private Q_SLOTS: - void slotModeComboChanged(int index); - void slotRoutesDialog(); - - void slotDnsServers(); - void slotDnsDomains(); - - void slotAddIPAddress(); - void slotRemoveIPAddress(); - - void selectionChanged(const QItemSelection & selected); - void tableViewItemChanged(QStandardItem * item); - -private: - Ui::IPv6Widget * m_ui; - NetworkManager::Ipv6Setting m_tmpIpv6Setting; - - class Private; - Private * const d; -}; - -#endif // PLASMA_NM_IPV4_WIDGET_H diff --git a/libs/editor/settings/pppoewidget.cpp b/libs/editor/settings/pppoewidget.cpp deleted file mode 100644 index df47c3eb..00000000 --- a/libs/editor/settings/pppoewidget.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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 "pppoewidget.h" -#include "ui_pppoe.h" - -#include - -PppoeWidget::PppoeWidget(const NetworkManager::Setting::Ptr &setting, QWidget *parent, Qt::WindowFlags f) - : SettingWidget(setting, parent, f) - , m_ui(new Ui::PppoeWidget) -{ - m_ui->setupUi(this); - - KAcceleratorManager::manage(this); - - m_ui->password->setPasswordOptionsEnabled(true); - m_ui->password->setPasswordNotRequiredEnabled(true); - - // Connect for setting check - watchChangedSetting(); - - // Connect for validity check - connect(m_ui->service, &KLineEdit::textChanged, this, &PppoeWidget::slotWidgetChanged); - connect(m_ui->username, &KLineEdit::textChanged, this, &PppoeWidget::slotWidgetChanged); - connect(m_ui->password, &PasswordField::textChanged, this, &PppoeWidget::slotWidgetChanged); - connect(m_ui->password, &PasswordField::passwordOptionChanged, this, &PppoeWidget::slotWidgetChanged); - - if (setting && !setting->isNull()) { - loadConfig(setting); - } -} - -PppoeWidget::~PppoeWidget() -{ - delete m_ui; -} - -void PppoeWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::PppoeSetting::Ptr pppoeSetting = setting.staticCast(); - - m_ui->service->setText(pppoeSetting->service()); - m_ui->username->setText(pppoeSetting->username()); - if (pppoeSetting->passwordFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->password->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (pppoeSetting->passwordFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->password->setPasswordOption(PasswordField::StoreForUser); - } else if (pppoeSetting->passwordFlags().testFlag(NetworkManager::Setting::NotSaved)) { - m_ui->password->setPasswordOption(PasswordField::AlwaysAsk); - } else { - m_ui->password->setPasswordOption(PasswordField::NotRequired); - } - - loadSecrets(setting); -} - -void PppoeWidget::loadSecrets(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::PppoeSetting::Ptr pppoeSetting = setting.staticCast(); - - if (pppoeSetting) { - const QString password = pppoeSetting->password(); - if (!password.isEmpty()) { - m_ui->password->setText(password); - } - } -} - -QVariantMap PppoeWidget::setting() const -{ - NetworkManager::PppoeSetting pppoeSetting; - if (!m_ui->service->text().isEmpty()) { - pppoeSetting.setService(m_ui->service->text()); - } - - if (!m_ui->username->text().isEmpty()) { - pppoeSetting.setUsername(m_ui->username->text()); - } - - if (!m_ui->password->text().isEmpty()) { - pppoeSetting.setPassword(m_ui->password->text()); - } - - if (m_ui->password->passwordOption() == PasswordField::StoreForAllUsers) { - pppoeSetting.setPasswordFlags(NetworkManager::Setting::None); - } else if (m_ui->password->passwordOption() == PasswordField::StoreForUser) { - pppoeSetting.setPasswordFlags(NetworkManager::Setting::AgentOwned); - } else if (m_ui->password->passwordOption() == PasswordField::AlwaysAsk) { - pppoeSetting.setPasswordFlags(NetworkManager::Setting::NotSaved); - } else { - pppoeSetting.setPasswordFlags(NetworkManager::Setting::NotRequired); - } - - return pppoeSetting.toMap(); -} - -bool PppoeWidget::isValid() const -{ - bool passwordUserValid = true; - - if (m_ui->password->passwordOption() == PasswordField::StoreForUser || - m_ui->password->passwordOption() == PasswordField::StoreForAllUsers) { - passwordUserValid = !m_ui->username->text().isEmpty() && !m_ui->password->text().isEmpty(); - } else if (m_ui->password->passwordOption() == PasswordField::AlwaysAsk) { - passwordUserValid = !m_ui->username->text().isEmpty(); - } - - return passwordUserValid; -} diff --git a/libs/editor/settings/pppwidget.cpp b/libs/editor/settings/pppwidget.cpp deleted file mode 100644 index 45732a06..00000000 --- a/libs/editor/settings/pppwidget.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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 "pppwidget.h" -#include "ui_ppp.h" - -#include - -PPPWidget::PPPWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting, parent, f), - m_ui(new Ui::PPPWidget) -{ - m_ui->setupUi(this); - - // Connect for setting check - watchChangedSetting(); - - KAcceleratorManager::manage(this); - - if (setting) { - loadConfig(setting); - } -} - -PPPWidget::~PPPWidget() -{ - delete m_ui; -} - -void PPPWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::PppSetting::Ptr pppSetting = setting.staticCast(); - - m_ui->eap->setChecked(!pppSetting->refuseEap()); - m_ui->pap->setChecked(!pppSetting->refusePap()); - m_ui->chap->setChecked(!pppSetting->refuseChap()); - m_ui->mschap->setChecked(!pppSetting->refuseMschap()); - m_ui->mschapv2->setChecked(!pppSetting->refuseMschapv2()); - - m_ui->mppe->setChecked(pppSetting->requireMppe()); - m_ui->mppe128->setChecked(pppSetting->requireMppe128()); - m_ui->mppeStateful->setChecked(pppSetting->mppeStateful()); - - m_ui->bsdComp->setChecked(!pppSetting->noBsdComp()); - m_ui->deflateComp->setChecked(!pppSetting->noDeflate()); - m_ui->tcpComp->setChecked(!pppSetting->noVjComp()); - - if (pppSetting->lcpEchoInterval() > 0) { - m_ui->senddEcho->setChecked(true); - } else { - m_ui->senddEcho->setChecked(false); - } -} - -QVariantMap PPPWidget::setting() const -{ - NetworkManager::PppSetting pppSetting; - - pppSetting.setRefuseEap(!m_ui->eap->isChecked()); - pppSetting.setRefusePap(!m_ui->pap->isChecked()); - pppSetting.setRefuseChap(!m_ui->chap->isChecked()); - pppSetting.setRefuseMschap(!m_ui->mschap->isChecked()); - pppSetting.setRefuseMschapv2(!m_ui->mschapv2->isChecked()); - - pppSetting.setRequireMppe(m_ui->mppe->isChecked()); - pppSetting.setRequireMppe128(m_ui->mppe128->isChecked()); - pppSetting.setMppeStateful(m_ui->mppeStateful->isChecked()); - - pppSetting.setNoBsdComp(!m_ui->bsdComp->isChecked()); - pppSetting.setNoDeflate(!m_ui->deflateComp->isChecked()); - pppSetting.setNoVjComp(!m_ui->tcpComp->isChecked()); - - if (m_ui->senddEcho->isChecked()) { - pppSetting.setLcpEchoFailure(5); - pppSetting.setLcpEchoInterval(30); - } - - return pppSetting.toMap(); -} diff --git a/libs/editor/settings/security802-1x.cpp b/libs/editor/settings/security802-1x.cpp deleted file mode 100644 index de5a6a64..00000000 --- a/libs/editor/settings/security802-1x.cpp +++ /dev/null @@ -1,638 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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 "security802-1x.h" -#include "ui_802-1x.h" -#include "editlistdialog.h" -#include "listvalidator.h" - -#include -#include - -#include - -Security8021x::Security8021x(const NetworkManager::Setting::Ptr &setting, bool wifiMode, QWidget *parent, Qt::WindowFlags f) - : SettingWidget(setting, parent, f) - , m_ui(new Ui::Security8021x) -{ - m_setting = setting.staticCast(); - - m_ui->setupUi(this); - - m_ui->fastPassword->setPasswordOptionsEnabled(true); - m_ui->leapPassword->setPasswordOptionsEnabled(true); - m_ui->md5Password->setPasswordOptionsEnabled(true); - m_ui->peapPassword->setPasswordOptionsEnabled(true); - m_ui->pwdPassword->setPasswordOptionsEnabled(true); - m_ui->tlsPrivateKeyPassword->setPasswordOptionsEnabled(true); - m_ui->ttlsPassword->setPasswordOptionsEnabled(true); - - if (wifiMode) { - m_ui->auth->removeItem(0); // MD 5 - m_ui->stackedWidget->removeWidget(m_ui->md5Page); - - m_ui->auth->setItemData(0, NetworkManager::Security8021xSetting::EapMethodTls); - m_ui->auth->setItemData(1, NetworkManager::Security8021xSetting::EapMethodLeap); - m_ui->auth->setItemData(2, NetworkManager::Security8021xSetting::EapMethodPwd); - m_ui->auth->setItemData(3, NetworkManager::Security8021xSetting::EapMethodFast); - m_ui->auth->setItemData(4, NetworkManager::Security8021xSetting::EapMethodTtls); - m_ui->auth->setItemData(5, NetworkManager::Security8021xSetting::EapMethodPeap); - } else { - m_ui->auth->removeItem(2); // LEAP - m_ui->stackedWidget->removeWidget(m_ui->leapPage); - - m_ui->auth->setItemData(0, NetworkManager::Security8021xSetting::EapMethodMd5); - m_ui->auth->setItemData(1, NetworkManager::Security8021xSetting::EapMethodTls); - m_ui->auth->setItemData(2, NetworkManager::Security8021xSetting::EapMethodPwd); - m_ui->auth->setItemData(3, NetworkManager::Security8021xSetting::EapMethodFast); - m_ui->auth->setItemData(4, NetworkManager::Security8021xSetting::EapMethodTtls); - m_ui->auth->setItemData(5, NetworkManager::Security8021xSetting::EapMethodPeap); - } - - // Set PEAP authentication as default - m_ui->auth->setCurrentIndex(m_ui->auth->findData(NetworkManager::Security8021xSetting::EapMethodPeap)); - - connect(m_ui->btnTlsAltSubjectMatches, &QPushButton::clicked, this, &Security8021x::altSubjectMatchesButtonClicked); - connect(m_ui->btnTlsConnectToServers, &QPushButton::clicked, this, &Security8021x::connectToServersButtonClicked); - - // Connect for setting check - watchChangedSetting(); - - // Connect for validity check - connect(m_ui->auth, QOverload::of(&KComboBox::currentIndexChanged), this, &Security8021x::slotWidgetChanged); - connect(m_ui->md5UserName, &KLineEdit::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->md5Password, &PasswordField::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->md5Password, &PasswordField::passwordOptionChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->tlsIdentity, &KLineEdit::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->tlsCACert, &KUrlRequester::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->tlsUserCert, &KUrlRequester::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->tlsPrivateKey, &KUrlRequester::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->tlsPrivateKeyPassword, &PasswordField::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->tlsPrivateKeyPassword, &PasswordField::passwordOptionChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->leapUsername, &KLineEdit::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->leapPassword, &PasswordField::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->leapPassword, &PasswordField::passwordOptionChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->fastAllowPacProvisioning, &QCheckBox::stateChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->pacFile, &KUrlRequester::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->pwdUsername, &KLineEdit::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->pwdPassword, &PasswordField::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->fastUsername, &KLineEdit::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->fastPassword, &PasswordField::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->fastPassword, &PasswordField::passwordOptionChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->ttlsCACert, &KUrlRequester::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->ttlsUsername, &KLineEdit::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->ttlsPassword, &PasswordField::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->ttlsPassword, &PasswordField::passwordOptionChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->peapCACert, &KUrlRequester::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->peapUsername, &KLineEdit::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->peapPassword, &PasswordField::textChanged, this, &Security8021x::slotWidgetChanged); - connect(m_ui->peapPassword, &PasswordField::passwordOptionChanged, this, &Security8021x::slotWidgetChanged); - - KAcceleratorManager::manage(this); - connect(m_ui->stackedWidget, &QStackedWidget::currentChanged, this, &Security8021x::currentAuthChanged); - - altSubjectValidator = new QRegExpValidator(QRegExp(QLatin1String("^(DNS:[a-zA-Z0-9_-]+\\.[a-zA-Z0-9_.-]+|EMAIL:[a-zA-Z0-9._-]+@[a-zA-Z0-9_-]+\\.[a-zA-Z0-9_.-]+|URI:[a-zA-Z0-9.+-]+:.+|)$")), this); - serversValidator = new QRegExpValidator(QRegExp(QLatin1String("^[a-zA-Z0-9_-]+\\.[a-zA-Z0-9_.-]+$")), this); - - ListValidator *altSubjectListValidator = new ListValidator(this); - altSubjectListValidator->setInnerValidator(altSubjectValidator); - m_ui->leTlsSubjectMatch->setValidator(altSubjectListValidator); - - ListValidator *serverListValidator = new ListValidator(this); - serverListValidator->setInnerValidator(serversValidator); - m_ui->leTlsConnectToServers->setValidator(serverListValidator); - - if (setting) { - loadConfig(setting); - } -} - -Security8021x::~Security8021x() -{ - delete m_ui; -} - -void Security8021x::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::Security8021xSetting::Ptr securitySetting = setting.staticCast(); - - const QList eapMethods = securitySetting->eapMethods(); - const NetworkManager::Security8021xSetting::AuthMethod phase2AuthMethod = securitySetting->phase2AuthMethod(); - - if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodMd5)) { - m_ui->auth->setCurrentIndex(m_ui->auth->findData(NetworkManager::Security8021xSetting::EapMethodMd5)); - m_ui->md5UserName->setText(securitySetting->identity()); - - if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->md5Password->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->md5Password->setPasswordOption(PasswordField::StoreForUser); - } else { - m_ui->md5Password->setPasswordOption(PasswordField::AlwaysAsk); - } - } else if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodTls)) { - QStringList servers; - m_ui->auth->setCurrentIndex(m_ui->auth->findData(NetworkManager::Security8021xSetting::EapMethodTls)); - m_ui->tlsIdentity->setText(securitySetting->identity()); - m_ui->tlsDomain->setText(securitySetting->domainSuffixMatch()); - m_ui->tlsUserCert->setUrl(QUrl::fromLocalFile(securitySetting->clientCertificate())); - m_ui->tlsCACert->setUrl(QUrl::fromLocalFile(securitySetting->caCertificate())); - m_ui->leTlsSubjectMatch->setText(securitySetting->subjectMatch()); - m_ui->leTlsAlternativeSubjectMatches->setText(securitySetting->altSubjectMatches().join(QLatin1String(", "))); - for (const QString &match : securitySetting->altSubjectMatches()) { - if (match.startsWith(QLatin1String("DNS:"))) { - servers.append(match.right(match.length()-4)); - } - } - m_ui->leTlsConnectToServers->setText(servers.join(QLatin1String(", "))); - m_ui->tlsPrivateKey->setUrl(QUrl::fromLocalFile(securitySetting->privateKey())); - if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->tlsPrivateKeyPassword->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->tlsPrivateKeyPassword->setPasswordOption(PasswordField::StoreForUser); - } else { - m_ui->tlsPrivateKeyPassword->setPasswordOption(PasswordField::AlwaysAsk); - } - } else if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodLeap)) { - m_ui->auth->setCurrentIndex(m_ui->auth->findData(NetworkManager::Security8021xSetting::EapMethodLeap)); - m_ui->leapUsername->setText(securitySetting->identity()); - if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->leapPassword->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->leapPassword->setPasswordOption(PasswordField::StoreForUser); - } else { - m_ui->leapPassword->setPasswordOption(PasswordField::AlwaysAsk); - } - - } else if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodPwd)) { - m_ui->auth->setCurrentIndex(m_ui->auth->findData(NetworkManager::Security8021xSetting::EapMethodPwd)); - m_ui->pwdUsername->setText(securitySetting->identity()); - - if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->pwdPassword->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->pwdPassword->setPasswordOption(PasswordField::StoreForUser); - } else { - m_ui->pwdPassword->setPasswordOption(PasswordField::AlwaysAsk); - } - } else if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodFast)) { - m_ui->auth->setCurrentIndex(m_ui->auth->findData(NetworkManager::Security8021xSetting::EapMethodFast)); - m_ui->fastAnonIdentity->setText(securitySetting->anonymousIdentity()); - m_ui->fastAllowPacProvisioning->setChecked((int)securitySetting->phase1FastProvisioning() > 0); - m_ui->pacMethod->setCurrentIndex(securitySetting->phase1FastProvisioning() - 1); - m_ui->pacFile->setUrl(QUrl::fromLocalFile(securitySetting->pacFile())); - if (phase2AuthMethod == NetworkManager::Security8021xSetting::AuthMethodGtc) { - m_ui->fastInnerAuth->setCurrentIndex(0); - } else { - m_ui->fastInnerAuth->setCurrentIndex(1); - } - m_ui->fastUsername->setText(securitySetting->identity()); - if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->fastPassword->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->fastPassword->setPasswordOption(PasswordField::StoreForUser); - } else { - m_ui->fastPassword->setPasswordOption(PasswordField::AlwaysAsk); - } - } else if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodTtls)) { - m_ui->auth->setCurrentIndex(m_ui->auth->findData(NetworkManager::Security8021xSetting::EapMethodTtls)); - m_ui->ttlsAnonIdentity->setText(securitySetting->anonymousIdentity()); - m_ui->ttlsDomain->setText(securitySetting->domainSuffixMatch()); - m_ui->ttlsCACert->setUrl(QUrl::fromLocalFile(securitySetting->caCertificate())); - if (phase2AuthMethod == NetworkManager::Security8021xSetting::AuthMethodPap) { - m_ui->ttlsInnerAuth->setCurrentIndex(0); - } else if (phase2AuthMethod == NetworkManager::Security8021xSetting::AuthMethodMschap) { - m_ui->ttlsInnerAuth->setCurrentIndex(1); - } else if (phase2AuthMethod == NetworkManager::Security8021xSetting::AuthMethodMschapv2) { - m_ui->ttlsInnerAuth->setCurrentIndex(2); - } else if (phase2AuthMethod == NetworkManager::Security8021xSetting::AuthMethodChap) { - m_ui->ttlsInnerAuth->setCurrentIndex(3); - } - m_ui->ttlsUsername->setText(securitySetting->identity()); - if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->ttlsPassword->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->ttlsPassword->setPasswordOption(PasswordField::StoreForUser); - } else { - m_ui->ttlsPassword->setPasswordOption(PasswordField::AlwaysAsk); - } - } else if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodPeap)) { - m_ui->auth->setCurrentIndex(m_ui->auth->findData(NetworkManager::Security8021xSetting::EapMethodPeap)); - m_ui->peapAnonIdentity->setText(securitySetting->anonymousIdentity()); - m_ui->peapDomain->setText(securitySetting->domainSuffixMatch()); - m_ui->peapCACert->setUrl(QUrl::fromLocalFile(securitySetting->caCertificate())); - m_ui->peapVersion->setCurrentIndex(securitySetting->phase1PeapVersion() + 1); - if (phase2AuthMethod == NetworkManager::Security8021xSetting::AuthMethodMschapv2) { - m_ui->peapInnerAuth->setCurrentIndex(0); - } else if (phase2AuthMethod == NetworkManager::Security8021xSetting::AuthMethodMd5) { - m_ui->peapInnerAuth->setCurrentIndex(1); - } else if (phase2AuthMethod == NetworkManager::Security8021xSetting::AuthMethodGtc) { - m_ui->peapInnerAuth->setCurrentIndex(2); - } - m_ui->peapUsername->setText(securitySetting->identity()); - if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->peapPassword->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (securitySetting->passwordFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->peapPassword->setPasswordOption(PasswordField::StoreForUser); - } else { - m_ui->peapPassword->setPasswordOption(PasswordField::AlwaysAsk); - } - } - - loadSecrets(setting); -} - -void Security8021x::loadSecrets(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::Security8021xSetting::Ptr securitySetting = setting.staticCast(); - - const QString password = securitySetting->password(); - const QList eapMethods = securitySetting->eapMethods(); - - if (!password.isEmpty()) { - if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodMd5)) { - m_ui->md5Password->setText(securitySetting->password()); - } else if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodLeap)) { - m_ui->leapPassword->setText(securitySetting->password()); - } else if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodFast)) { - m_ui->fastPassword->setText(securitySetting->password()); - } else if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodPwd)) { - m_ui->pwdPassword->setText(securitySetting->password()); - } else if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodTtls)) { - m_ui->ttlsPassword->setText(securitySetting->password()); - } else if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodPeap)) { - m_ui->peapPassword->setText(securitySetting->password()); - } - } - - if (eapMethods.contains(NetworkManager::Security8021xSetting::EapMethodTls)) { - const QString privateKeyPassword = securitySetting->privateKeyPassword(); - if (!privateKeyPassword.isEmpty()) { - m_ui->tlsPrivateKeyPassword->setText(securitySetting->privateKeyPassword()); - } - } -} - -QVariantMap Security8021x::setting() const -{ - NetworkManager::Security8021xSetting setting; - - NetworkManager::Security8021xSetting::EapMethod method = - static_cast(m_ui->auth->itemData(m_ui->auth->currentIndex()).toInt()); - - setting.setEapMethods(QList() << method); - - if (method == NetworkManager::Security8021xSetting::EapMethodMd5) { - if (!m_ui->md5UserName->text().isEmpty()) { - setting.setIdentity(m_ui->md5UserName->text()); - } - - if (m_ui->md5Password->passwordOption() == PasswordField::StoreForAllUsers) { - setting.setPasswordFlags(NetworkManager::Setting::None); - } else if (m_ui->md5Password->passwordOption() == PasswordField::StoreForUser) { - setting.setPasswordFlags(NetworkManager::Setting::AgentOwned); - } else { - setting.setPasswordFlags(NetworkManager::Setting::NotSaved); - } - - if (!m_ui->md5Password->text().isEmpty()) { - setting.setPassword(m_ui->md5Password->text()); - } - } else if (method == NetworkManager::Security8021xSetting::EapMethodTls) { - if (!m_ui->tlsIdentity->text().isEmpty()) { - setting.setIdentity(m_ui->tlsIdentity->text()); - } - - if (!m_ui->tlsDomain->text().isEmpty()) { - setting.setDomainSuffixMatch(m_ui->tlsDomain->text()); - } - - if (m_ui->tlsUserCert->url().isValid()) { - setting.setClientCertificate(m_ui->tlsUserCert->url().toString().toUtf8().append('\0')); - } - - if (m_ui->tlsCACert->url().isValid()) { - setting.setCaCertificate(m_ui->tlsCACert->url().toString().toUtf8().append('\0')); - } - - QStringList altsubjectmatches = m_ui->leTlsAlternativeSubjectMatches->text().remove(QLatin1Char(' ')).split(QLatin1Char(','), QString::SkipEmptyParts); - for (const QString &match : m_ui->leTlsConnectToServers->text().remove(QLatin1Char(' ')).split(QLatin1Char(','), QString::SkipEmptyParts)) { - const QString tempstr = QLatin1String("DNS:") + match; - if (!altsubjectmatches.contains(tempstr)) { - altsubjectmatches.append(tempstr); - } - } - setting.setSubjectMatch(m_ui->leTlsSubjectMatch->text()); - setting.setAltSubjectMatches(altsubjectmatches); - - if (m_ui->tlsPrivateKey->url().isValid()) { - setting.setPrivateKey(m_ui->tlsPrivateKey->url().toString().toUtf8().append('\0')); - } - - if (!m_ui->tlsPrivateKeyPassword->text().isEmpty()) { - setting.setPrivateKeyPassword(m_ui->tlsPrivateKeyPassword->text()); - } - - QCA::Initializer init; - QCA::ConvertResult convRes; - - // Try if the private key is in pkcs12 format bundled with client certificate - if (QCA::isSupported("pkcs12")) { - QCA::KeyBundle keyBundle = QCA::KeyBundle::fromFile(m_ui->tlsPrivateKey->url().path(), m_ui->tlsPrivateKeyPassword->text().toUtf8(), &convRes); - // Set client certificate to the same path as private key - if (convRes == QCA::ConvertGood && keyBundle.privateKey().canDecrypt()) { - setting.setClientCertificate(m_ui->tlsPrivateKey->url().toString().toUtf8().append('\0')); - } - } - - if (m_ui->tlsPrivateKeyPassword->passwordOption() == PasswordField::StoreForAllUsers) { - setting.setPrivateKeyPasswordFlags(NetworkManager::Setting::None); - } else if (m_ui->tlsPrivateKeyPassword->passwordOption() == PasswordField::StoreForUser) { - setting.setPrivateKeyPasswordFlags(NetworkManager::Setting::AgentOwned); - } else { - setting.setPrivateKeyPasswordFlags(NetworkManager::Setting::NotSaved); - } - } else if (method == NetworkManager::Security8021xSetting::EapMethodLeap) { - if (!m_ui->leapUsername->text().isEmpty()) { - setting.setIdentity(m_ui->leapUsername->text()); - } - - if (!m_ui->leapPassword->text().isEmpty()) { - setting.setPassword(m_ui->leapPassword->text()); - } - - if (m_ui->leapPassword->passwordOption() == PasswordField::StoreForAllUsers) { - setting.setPasswordFlags(NetworkManager::Setting::None); - } else if (m_ui->leapPassword->passwordOption() == PasswordField::StoreForUser) { - setting.setPasswordFlags(NetworkManager::Setting::AgentOwned); - } else { - setting.setPasswordFlags(NetworkManager::Setting::NotSaved); - } - } else if (method == NetworkManager::Security8021xSetting::EapMethodPwd) { - if (!m_ui->pwdUsername->text().isEmpty()) { - setting.setIdentity(m_ui->pwdUsername->text()); - } - - if (m_ui->pwdPassword->passwordOption() == PasswordField::StoreForAllUsers) { - setting.setPasswordFlags(NetworkManager::Setting::None); - } else if (m_ui->pwdPassword->passwordOption() == PasswordField::StoreForUser) { - setting.setPasswordFlags(NetworkManager::Setting::AgentOwned); - } else { - setting.setPasswordFlags(NetworkManager::Setting::NotSaved); - } - - if (!m_ui->pwdPassword->text().isEmpty()) { - setting.setPassword(m_ui->pwdPassword->text()); - } - } else if (method == NetworkManager::Security8021xSetting::EapMethodFast) { - if (!m_ui->fastAnonIdentity->text().isEmpty()) { - setting.setAnonymousIdentity(m_ui->fastAnonIdentity->text()); - } - - if (!m_ui->fastAllowPacProvisioning->isChecked()) { - setting.setPhase1FastProvisioning(NetworkManager::Security8021xSetting::FastProvisioningDisabled); - } else { - setting.setPhase1FastProvisioning(static_cast(m_ui->pacMethod->currentIndex() + 1)); - } - - if (m_ui->pacFile->url().isValid()) { - setting.setPacFile(QFile::encodeName(m_ui->pacFile->url().toLocalFile())); - } - - if (m_ui->fastInnerAuth->currentIndex() == 0) { - setting.setPhase2AuthMethod(NetworkManager::Security8021xSetting::AuthMethodGtc); - } else { - setting.setPhase2AuthMethod(NetworkManager::Security8021xSetting::AuthMethodMschapv2); - } - - if (!m_ui->fastUsername->text().isEmpty()) { - setting.setIdentity(m_ui->fastUsername->text()); - } - - if (!m_ui->fastPassword->text().isEmpty()) { - setting.setPassword(m_ui->fastPassword->text()); - } - - if (m_ui->fastPassword->passwordOption() == PasswordField::StoreForAllUsers) { - setting.setPasswordFlags(NetworkManager::Setting::None); - } else if (m_ui->fastPassword->passwordOption() == PasswordField::StoreForUser) { - setting.setPasswordFlags(NetworkManager::Setting::AgentOwned); - } else { - setting.setPasswordFlags(NetworkManager::Setting::NotSaved); - } - } else if (method == NetworkManager::Security8021xSetting::EapMethodTtls) { - if (!m_ui->ttlsAnonIdentity->text().isEmpty()) { - setting.setAnonymousIdentity(m_ui->ttlsAnonIdentity->text()); - } - - if (!m_ui->ttlsDomain->text().isEmpty()) { - setting.setDomainSuffixMatch(m_ui->ttlsDomain->text()); - } - - if (m_ui->ttlsCACert->url().isValid()) { - setting.setCaCertificate(m_ui->ttlsCACert->url().toString().toUtf8().append('\0')); - } - - const int innerAuth = m_ui->ttlsInnerAuth->currentIndex(); - if (innerAuth == 0) { - setting.setPhase2AuthMethod(NetworkManager::Security8021xSetting::AuthMethodPap); - } else if (innerAuth == 1) { - setting.setPhase2AuthMethod(NetworkManager::Security8021xSetting::AuthMethodMschap); - } else if (innerAuth == 2) { - setting.setPhase2AuthMethod(NetworkManager::Security8021xSetting::AuthMethodMschapv2); - } else if (innerAuth == 3) { - setting.setPhase2AuthMethod(NetworkManager::Security8021xSetting::AuthMethodChap); - } - - if (!m_ui->ttlsUsername->text().isEmpty()) { - setting.setIdentity(m_ui->ttlsUsername->text()); - } - - if (!m_ui->ttlsPassword->text().isEmpty()) { - setting.setPassword(m_ui->ttlsPassword->text()); - } - - if (m_ui->ttlsPassword->passwordOption() == PasswordField::StoreForAllUsers) { - setting.setPasswordFlags(NetworkManager::Setting::None); - } else if (m_ui->ttlsPassword->passwordOption() == PasswordField::StoreForUser) { - setting.setPasswordFlags(NetworkManager::Setting::AgentOwned); - } else { - setting.setPasswordFlags(NetworkManager::Setting::NotSaved); - } - } else if (method == NetworkManager::Security8021xSetting::EapMethodPeap) { - if (!m_ui->peapAnonIdentity->text().isEmpty()) { - setting.setAnonymousIdentity(m_ui->peapAnonIdentity->text()); - } - - if (!m_ui->peapDomain->text().isEmpty()) { - setting.setDomainSuffixMatch(m_ui->peapDomain->text()); - } - - if (m_ui->peapCACert->url().isValid()) { - setting.setCaCertificate(m_ui->peapCACert->url().toString().toUtf8().append('\0')); - } - - setting.setPhase1PeapVersion(static_cast(m_ui->peapVersion->currentIndex() - 1)); - const int innerAuth = m_ui->peapInnerAuth->currentIndex(); - if (innerAuth == 0) { - setting.setPhase2AuthMethod(NetworkManager::Security8021xSetting::AuthMethodMschapv2); - } else if (innerAuth == 1) { - setting.setPhase2AuthMethod(NetworkManager::Security8021xSetting::AuthMethodMd5); - } else if (innerAuth == 2) { - setting.setPhase2AuthMethod(NetworkManager::Security8021xSetting::AuthMethodGtc); - } - - if (!m_ui->peapUsername->text().isEmpty()) { - setting.setIdentity(m_ui->peapUsername->text()); - } - - if (!m_ui->peapPassword->text().isEmpty()) { - setting.setPassword(m_ui->peapPassword->text()); - } - - if (m_ui->peapPassword->passwordOption() == PasswordField::StoreForAllUsers) { - setting.setPasswordFlags(NetworkManager::Setting::None); - } else if (m_ui->peapPassword->passwordOption() == PasswordField::StoreForUser) { - setting.setPasswordFlags(NetworkManager::Setting::AgentOwned); - } else { - setting.setPasswordFlags(NetworkManager::Setting::NotSaved); - } - } - - return setting.toMap(); -} - -void Security8021x::altSubjectMatchesButtonClicked() -{ - QPointer editor = new EditListDialog(this); - - editor->setItems(m_ui->leTlsSubjectMatch->text().remove(QLatin1Char(' ')).split(QLatin1Char(','), QString::SkipEmptyParts)); - editor->setWindowTitle(i18n("Alternative Subject Matches")); - editor->setToolTip(i18n("This entry must be one of:
  • DNS: <name or ip address>
  • EMAIL: <email>
  • URI: <uri, e.g. https://www.kde.org>
")); - editor->setValidator(altSubjectValidator); - - connect(editor.data(), &QDialog::accepted, - [editor, this] () { - m_ui->leTlsSubjectMatch->setText(editor->items().join(QLatin1String(", "))); - }); - connect(editor.data(), &QDialog::finished, - [editor] () { - if (editor) { - editor->deleteLater(); - } - }); - editor->setModal(true); - editor->show(); -} - -void Security8021x::connectToServersButtonClicked() -{ - QPointer editor = new EditListDialog(this); - - editor->setItems(m_ui->leTlsConnectToServers->text().remove(QLatin1Char(' ')).split(QLatin1Char(','), QString::SkipEmptyParts)); - editor->setWindowTitle(i18n("Connect to these servers only")); - editor->setValidator(serversValidator); - - connect(editor.data(), &QDialog::accepted, - [editor, this] () { - m_ui->leTlsConnectToServers->setText(editor->items().join(QLatin1String(", "))); - }); - connect(editor.data(), &QDialog::finished, - [editor] () { - if (editor) { - editor->deleteLater(); - } - }); - editor->setModal(true); - editor->show(); -} - -bool Security8021x::isValid() const -{ - NetworkManager::Security8021xSetting::EapMethod method = - static_cast(m_ui->auth->itemData(m_ui->auth->currentIndex()).toInt()); - - if (method == NetworkManager::Security8021xSetting::EapMethodMd5) { - return !m_ui->md5UserName->text().isEmpty() && (!m_ui->md5Password->text().isEmpty() || m_ui->md5Password->passwordOption() == PasswordField::AlwaysAsk); - } else if (method == NetworkManager::Security8021xSetting::EapMethodTls) { - if (m_ui->tlsIdentity->text().isEmpty()) { - return false; - } - - if (!m_ui->tlsPrivateKey->url().isValid()) { - return false; - } - - if (m_ui->tlsPrivateKeyPassword->passwordOption() == PasswordField::AlwaysAsk) { - return true; - } - - if (m_ui->tlsPrivateKeyPassword->text().isEmpty()) { - return false; - } - - QCA::Initializer init; - QCA::ConvertResult convRes; - - // Try if the private key is in pkcs12 format bundled with client certificate - if (QCA::isSupported("pkcs12")) { - QCA::KeyBundle keyBundle = QCA::KeyBundle::fromFile(m_ui->tlsPrivateKey->url().path(), m_ui->tlsPrivateKeyPassword->text().toUtf8(), &convRes); - // We can return the result of decryption when we managed to import the private key - if (convRes == QCA::ConvertGood) { - return keyBundle.privateKey().canDecrypt(); - } - } - - // If the private key is not in pkcs12 format, we need client certificate to be set - if (!m_ui->tlsUserCert->url().isValid()) { - return false; - } - - // Try if the private key is in PEM format and return the result of decryption if we managed to open it - QCA::PrivateKey key = QCA::PrivateKey::fromPEMFile(m_ui->tlsPrivateKey->url().path(), m_ui->tlsPrivateKeyPassword->text().toUtf8(), &convRes); - if (convRes == QCA::ConvertGood) { - return key.canDecrypt(); - } - - // TODO Try other formats (DER - mainly used in Windows) - // TODO Validate other certificates?? - } else if (method == NetworkManager::Security8021xSetting::EapMethodLeap) { - return !m_ui->leapUsername->text().isEmpty() && (!m_ui->leapPassword->text().isEmpty() || m_ui->leapPassword->passwordOption() == PasswordField::AlwaysAsk); - } else if (method == NetworkManager::Security8021xSetting::EapMethodPwd) { - return !m_ui->pwdUsername->text().isEmpty() && (!m_ui->pwdPassword->text().isEmpty() || m_ui->pwdPassword->passwordOption() == PasswordField::AlwaysAsk); - } else if (method == NetworkManager::Security8021xSetting::EapMethodFast) { - if (!m_ui->fastAllowPacProvisioning->isChecked() && !m_ui->pacFile->url().isValid()) { - return false; - } - return !m_ui->fastUsername->text().isEmpty() && (!m_ui->fastPassword->text().isEmpty() || m_ui->fastPassword->passwordOption() == PasswordField::AlwaysAsk); - } else if (method == NetworkManager::Security8021xSetting::EapMethodTtls) { - return !m_ui->ttlsUsername->text().isEmpty() && (!m_ui->ttlsPassword->text().isEmpty() || m_ui->ttlsPassword->passwordOption() == PasswordField::AlwaysAsk); - } else if (method == NetworkManager::Security8021xSetting::EapMethodPeap) { - return !m_ui->peapUsername->text().isEmpty() && (!m_ui->peapPassword->text().isEmpty() || m_ui->peapPassword->passwordOption() == PasswordField::AlwaysAsk); - } - - return true; -} - -void Security8021x::currentAuthChanged(int index) -{ - Q_UNUSED(index); - KAcceleratorManager::manage(m_ui->stackedWidget->currentWidget()); -} diff --git a/libs/editor/settings/security802-1x.h b/libs/editor/settings/security802-1x.h deleted file mode 100644 index c8a93241..00000000 --- a/libs/editor/settings/security802-1x.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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_SECURITY8021X_H -#define PLASMA_NM_SECURITY8021X_H - -#include -#include - -#include - -#include "settingwidget.h" - -namespace Ui -{ -class Security8021x; -} - -class Q_DECL_EXPORT Security8021x: public SettingWidget -{ - Q_OBJECT -public: - explicit Security8021x(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), bool wifiMode = true, QWidget *parent = nullptr, Qt::WindowFlags f = {}); - ~Security8021x() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - void loadSecrets(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -private Q_SLOTS: - void altSubjectMatchesButtonClicked(); - void connectToServersButtonClicked(); - void currentAuthChanged(int index); - -private: - NetworkManager::Security8021xSetting::Ptr m_setting; - Ui::Security8021x *m_ui; - QRegExpValidator *altSubjectValidator; - QRegExpValidator *serversValidator; -}; - -#endif // SECURITY8021X_H diff --git a/libs/editor/settings/vlanwidget.h b/libs/editor/settings/setting.cpp similarity index 57% rename from libs/editor/settings/vlanwidget.h rename to libs/editor/settings/setting.cpp index 5aad2dab..c6b562ec 100644 --- a/libs/editor/settings/vlanwidget.h +++ b/libs/editor/settings/setting.cpp @@ -1,52 +1,53 @@ /* - Copyright 2013 Lukas Tinkl + 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_VLAN_WIDGET_H -#define PLASMA_NM_VLAN_WIDGET_H +#include "setting.h" -#include - -#include "settingwidget.h" +class SettingPrivate +{ +public: + explicit SettingPrivate(NetworkManager::Setting::SettingType type) + : type(type) + { } + NetworkManager::Setting::SettingType type; +}; -namespace Ui +Setting::Setting(const NetworkManager::Setting::Ptr &setting, QObject *parent) + : QObject(parent) + , d_ptr(new SettingPrivate(setting->type())) { -class VlanWidget; } -class Q_DECL_EXPORT VlanWidget : public SettingWidget +Setting::~Setting() { -Q_OBJECT - -public: - explicit VlanWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~VlanWidget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; + delete d_ptr; +} - bool isValid() const override; +NetworkManager::Setting::SettingType Setting::type() const +{ + Q_D(const Setting); -private: - void fillConnections(); - Ui::VlanWidget * m_ui; -}; + return d->type; +} -#endif // PLASMA_NM_VLAN_WIDGET_H +bool Setting::isValid() const +{ + return true; +} diff --git a/libs/editor/settings/pppoewidget.h b/libs/editor/settings/setting.h similarity index 54% rename from libs/editor/settings/pppoewidget.h rename to libs/editor/settings/setting.h index a3ee7ba6..3a582d02 100644 --- a/libs/editor/settings/pppoewidget.h +++ b/libs/editor/settings/setting.h @@ -1,53 +1,58 @@ /* - Copyright 2013 Lukas Tinkl + 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_PPPOE_WIDGET_H -#define PLASMA_NM_PPPOE_WIDGET_H +#ifndef PLASMA_NM_SETTING_H +#define PLASMA_NM_SETTING_H -#include +class QObject; -#include - -#include "settingwidget.h" +class SettingPrivate; -namespace Ui -{ -class PppoeWidget; -} +#include -class Q_DECL_EXPORT PppoeWidget : public SettingWidget +class Setting : public QObject { Q_OBJECT public: - explicit PppoeWidget(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~PppoeWidget() override; + explicit Setting(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), QObject *parent = nullptr); + virtual ~Setting(); - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - void loadSecrets(const NetworkManager::Setting::Ptr &setting) override; + virtual void loadConfig(const NetworkManager::Setting::Ptr &setting) = 0; + virtual void loadSecrets(const NetworkManager::Setting::Ptr &setting) = 0; - QVariantMap setting() const override; + virtual QVariantMap setting() const = 0; - bool isValid() const override; + virtual NetworkManager::Setting::SettingType type() const; + + virtual bool isValid() const; + +Q_SIGNALS: + void changed(); + void validityChanged(bool valid); + +protected: + SettingPrivate *d_ptr; private: - Ui::PppoeWidget *m_ui; + Q_DECLARE_PRIVATE(Setting) + }; -#endif // PLASMA_NM_PPPOE_WIDGET_H +#endif // PLASMA_NM_SETTING_H diff --git a/libs/editor/settings/teamwidget.cpp b/libs/editor/settings/teamwidget.cpp deleted file mode 100644 index a11d85a9..00000000 --- a/libs/editor/settings/teamwidget.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/* - Copyright 2014 Lukas Tinkl - - 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 "teamwidget.h" -#include "ui_team.h" -#include "connectioneditordialog.h" -#include "debug.h" - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -TeamWidget::TeamWidget(const QString & masterUuid, const QString &masterId, - const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting, parent, f), - m_uuid(masterUuid), - m_id(masterId), - m_ui(new Ui::TeamWidget) -{ - m_ui->setupUi(this); - - // Action buttons and menu - m_menu = new QMenu(this); - QAction * action = new QAction(i18n("Ethernet"), this); - action->setData(NetworkManager::ConnectionSettings::Wired); - m_menu->addAction(action); - action = new QAction(i18n("Infiniband"), this); - action->setData(NetworkManager::ConnectionSettings::Infiniband); - m_menu->addAction(action); - action = new QAction(i18n("Wi-Fi"), this); - action->setData(NetworkManager::ConnectionSettings::Wireless); - m_menu->addAction(action); - action = new QAction(i18n("VLAN"), this); - action->setData(NetworkManager::ConnectionSettings::Vlan); - m_menu->addAction(action); - m_ui->btnAdd->setMenu(m_menu); - connect(m_menu, &QMenu::triggered, this, &TeamWidget::addTeam); - connect(m_ui->btnEdit, &QPushButton::clicked, this, &TeamWidget::editTeam); - connect(m_ui->btnDelete, &QPushButton::clicked, this, &TeamWidget::deleteTeam); - - connect(m_ui->btnImport, &QPushButton::clicked, this, &TeamWidget::importConfig); - - // teams - populateTeams(); - connect(m_ui->teams, &QListWidget::currentItemChanged, this, &TeamWidget::currentTeamChanged); - connect(m_ui->teams, &QListWidget::itemDoubleClicked, this, &TeamWidget::editTeam); - - connect(m_ui->ifaceName, &KLineEdit::textChanged, this, &TeamWidget::slotWidgetChanged); - - // Connect for setting check - watchChangedSetting(); - - KAcceleratorManager::manage(this); - KAcceleratorManager::manage(m_menu); - - if (setting) { - loadConfig(setting); - } -} - -TeamWidget::~TeamWidget() -{ - delete m_ui; -} - -void TeamWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::TeamSetting::Ptr teamSetting = setting.staticCast(); - - m_ui->ifaceName->setText(teamSetting->interfaceName()); - m_ui->config->setPlainText(teamSetting->config()); -} - -QVariantMap TeamWidget::setting() const -{ - NetworkManager::TeamSetting setting; - setting.setInterfaceName(m_ui->ifaceName->text()); - setting.setConfig(m_ui->config->toPlainText()); - - return setting.toMap(); -} - -void TeamWidget::addTeam(QAction *action) -{ - qCDebug(PLASMA_NM) << "Adding teamed connection:" << action->data(); - qCDebug(PLASMA_NM) << "Master UUID:" << m_uuid; - qCDebug(PLASMA_NM) << "Slave type:" << type(); - - NetworkManager::ConnectionSettings::ConnectionType connectionType = static_cast(action->data().toInt()); - NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(connectionType)); - connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); - connectionSettings->setMaster(m_uuid); - connectionSettings->setSlaveType(type()); - connectionSettings->setAutoconnect(false); - - QPointer teamEditor = new ConnectionEditorDialog(connectionSettings); - connect(teamEditor.data(), &ConnectionEditorDialog::accepted, - [teamEditor, this] () { - qCDebug(PLASMA_NM) << "Saving slave connection"; - // qCDebug(PLASMA_NM) << teamEditor->setting(); - QDBusPendingReply reply = NetworkManager::addConnection(teamEditor->setting()); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); - connect(watcher, &QDBusPendingCallWatcher::finished, this, &TeamWidget::teamAddComplete); - }); - connect(teamEditor.data(), &ConnectionEditorDialog::finished, - [teamEditor] () { - if (teamEditor) { - teamEditor->deleteLater(); - } - }); - teamEditor->setModal(true); - teamEditor->show(); -} - -void TeamWidget::currentTeamChanged(QListWidgetItem *current, QListWidgetItem *previous) -{ - Q_UNUSED(previous) - - m_ui->btnEdit->setEnabled(current); - m_ui->btnDelete->setEnabled(current); -} - -void TeamWidget::teamAddComplete(QDBusPendingCallWatcher * watcher) -{ - QDBusPendingReply reply = *watcher; - - if (reply.isValid()) { - // find the slave connection with matching UUID - NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(reply.value().path()); - if (connection && connection->settings()->master() == m_uuid) { - const QString label = QString("%1 (%2)").arg(connection->name()).arg(connection->settings()->typeAsString(connection->settings()->connectionType())); - QListWidgetItem * slaveItem = new QListWidgetItem(label, m_ui->teams); - slaveItem->setData(Qt::UserRole, connection->uuid()); - slotWidgetChanged(); - } - } else { - qCWarning(PLASMA_NM) << "Teamed connection not added:" << reply.error().message(); - } -} - -void TeamWidget::editTeam() -{ - QListWidgetItem * currentItem = m_ui->teams->currentItem(); - if (!currentItem) - return; - - const QString uuid = currentItem->data(Qt::UserRole).toString(); - NetworkManager::Connection::Ptr connection = NetworkManager::findConnectionByUuid(uuid); - - if (connection) { - qCDebug(PLASMA_NM) << "Editing teamed connection" << currentItem->text() << uuid; - QPointer teamEditor = new ConnectionEditorDialog(connection->settings()); - connect(teamEditor.data(), &ConnectionEditorDialog::accepted, - [connection, teamEditor, this] () { - connection->update(teamEditor->setting()); - connect(connection.data(), &NetworkManager::Connection::updated, this, &TeamWidget::populateTeams); - }); - connect(teamEditor.data(), &ConnectionEditorDialog::finished, - [teamEditor] () { - if (teamEditor) { - teamEditor->deleteLater(); - } - }); - teamEditor->setModal(true); - teamEditor->show(); - } -} - -void TeamWidget::deleteTeam() -{ - QListWidgetItem * currentItem = m_ui->teams->currentItem(); - if (!currentItem) - return; - - const QString uuid = currentItem->data(Qt::UserRole).toString(); - NetworkManager::Connection::Ptr connection = NetworkManager::findConnectionByUuid(uuid); - - if (connection) { - qCDebug(PLASMA_NM) << "About to delete teamed connection" << currentItem->text() << uuid; - if (KMessageBox::questionYesNo(this, i18n("Do you want to remove the connection '%1'?", connection->name()), i18n("Remove Connection"), KStandardGuiItem::remove(), - KStandardGuiItem::no(), QString(), KMessageBox::Dangerous) - == KMessageBox::Yes) { - connection->remove(); - delete currentItem; - slotWidgetChanged(); - } - } -} - -void TeamWidget::populateTeams() -{ - m_ui->teams->clear(); - - for (const NetworkManager::Connection::Ptr &connection : NetworkManager::listConnections()) { - NetworkManager::ConnectionSettings::Ptr settings = connection->settings(); - // The mapping from slave to master may be by uuid or name, try our best to - // figure out if we are master to the slave. - const QString master = settings->master(); - bool isSlave = ((master == m_uuid) || // by-uuid - (!m_id.isEmpty() && master == m_id)); // by-name - if (isSlave && (settings->slaveType() == type())) { - const QString label = QString("%1 (%2)").arg(connection->name()).arg(connection->settings()->typeAsString(connection->settings()->connectionType())); - QListWidgetItem * slaveItem = new QListWidgetItem(label, m_ui->teams); - slaveItem->setData(Qt::UserRole, connection->uuid()); - } - } -} - -void TeamWidget::importConfig() -{ - const QString filename = QFileDialog::getOpenFileName(this, i18n("Select file to import"), QStandardPaths::writableLocation(QStandardPaths::HomeLocation), - "text/plain"); - if (!filename.isEmpty()) { - //qCDebug(PLASMA_NM) << "Importing" << filename; - QFile file(filename); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream stream(&file); - m_ui->config->setPlainText(stream.readAll()); - file.close(); - } - } -} - -bool TeamWidget::isValid() const -{ - return !m_ui->ifaceName->text().isEmpty() && m_ui->teams->count() > 0; -} diff --git a/libs/editor/settings/teamwidget.h b/libs/editor/settings/teamwidget.h deleted file mode 100644 index 0f7555a5..00000000 --- a/libs/editor/settings/teamwidget.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - Copyright 2014 Lukas Tinkl - - 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_TEAM_WIDGET_H -#define PLASMA_NM_TEAM_WIDGET_H - -#include -#include -#include -#include - -#include "settingwidget.h" - -#include - -namespace Ui -{ -class TeamWidget; -} - -class Q_DECL_EXPORT TeamWidget : public SettingWidget -{ - Q_OBJECT -public: - explicit TeamWidget(const QString & masterUuid, const QString &masterId, - const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), - QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~TeamWidget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -private Q_SLOTS: - void addTeam(QAction * action); - void currentTeamChanged(QListWidgetItem * current, QListWidgetItem * previous); - void teamAddComplete(QDBusPendingCallWatcher * watcher); - - void editTeam(); - void deleteTeam(); - - void populateTeams(); - - void importConfig(); - -private: - QString m_uuid; - QString m_id; - Ui::TeamWidget * m_ui; - QMenu * m_menu; -}; - -#endif // PLASMA_NM_TEAM_WIDGET_H diff --git a/libs/editor/settings/ui/802-1x.ui b/libs/editor/settings/ui/802-1x.ui deleted file mode 100644 index 202cdf88..00000000 --- a/libs/editor/settings/ui/802-1x.ui +++ /dev/null @@ -1,842 +0,0 @@ - - - Lukáš Tinkl <ltinkl@redhat.com> - Security8021x - - - - 0 - 0 - 563 - 471 - - - - - - - Authentication: - - - auth - - - - - - - - 0 - 0 - - - - 0 - - - - MD5 - - - - - TLS - - - - - LEAP - - - - - PWD - - - - - FAST - - - - - Tunneled TLS (TTLS) - - - - - Protected EAP (PEAP) - - - - - - - - 0 - - - - - - - Username: - - - md5UserName - - - - - - - - - - Password: - - - md5Password - - - - - - - true - - - - - - - - - - - Identity: - - - tlsIdentity - - - - - - - - - - Domain: - - - - - - - - - - User certificate: - - - tlsUserCert - - - - - - - *.der *.pem *.crt *.cer - - - - - - - CA certificate: - - - tlsCACert - - - - - - - *.der *.pem *.crt *.cer - - - - - - - Subject match: - - - leTlsSubjectMatch - - - - - - - - - - - - - - Alternative subject matches: - - - leTlsAlternativeSubjectMatches - - - - - - - - - - - - ... - - - - - - - - - Connect to these servers: - - - leTlsConnectToServers - - - - - - - - - - - - ... - - - - - - - - - Private key: - - - tlsPrivateKey - - - - - - - *.der *.pem *.p12 *.key - - - - - - - Private key password: - - - tlsPrivateKeyPassword - - - - - - - true - - - - - - - - - - - Username: - - - leapUsername - - - - - - - - - - Password: - - - leapPassword - - - - - - - true - - - - - - - - - - - Username: - - - md5UserName - - - - - - - - - - Password: - - - md5Password - - - - - - - true - - - - - - - - - - - Anonymous identity: - - - fastAnonIdentity - - - - - - - - - - Automatic PAC provisioning - - - - - - - false - - - - 0 - 0 - - - - - Anonymous - - - - - Authenticated - - - - - Both - - - - - - - - PAC file: - - - pacFile - - - - - - - *.pac - - - - - - - Inner authentication: - - - fastInnerAuth - - - - - - - - 0 - 0 - - - - - GTC - - - - - MSCHAPv2 - - - - - - - - Username: - - - fastUsername - - - - - - - - - - Password: - - - fastPassword - - - - - - - true - - - - - - - - - - - Anonymous identity: - - - fastAnonIdentity - - - - - - - - - - CA certificate: - - - tlsCACert - - - - - - - *.der *.pem *.crt *.cer - - - - - - - Inner authentication: - - - fastInnerAuth - - - - - - - - 0 - 0 - - - - - PAP - - - - - MSCHAP - - - - - MSCHAPv2 - - - - - CHAP - - - - - - - - Username: - - - fastUsername - - - - - - - - - - Password: - - - fastPassword - - - - - - - true - - - - - - - Domain: - - - - - - - - - - - - - - Anonymous identity: - - - fastAnonIdentity - - - - - - - - - - CA certificate: - - - tlsCACert - - - - - - - *.der *.pem *.crt *.cer - - - - - - - PEAP version: - - - peapVersion - - - - - - - - 0 - 0 - - - - - Automatic - - - - - Version 0 - - - - - Version 1 - - - - - - - - Inner authentication: - - - fastInnerAuth - - - - - - - - 0 - 0 - - - - - MSCHAPv2 - - - - - MD5 - - - - - GTC - - - - - - - - Username: - - - fastUsername - - - - - - - - - - Password: - - - fastPassword - - - - - - - true - - - - - - - Domain: - - - - - - - - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - KLineEdit - QLineEdit -
klineedit.h
-
- - KUrlRequester - QWidget -
kurlrequester.h
-
- - PasswordField - QLineEdit -
passwordfield.h
-
-
- - auth - md5UserName - md5Password - tlsIdentity - tlsDomain - tlsUserCert - tlsCACert - leTlsSubjectMatch - leTlsAlternativeSubjectMatches - btnTlsAltSubjectMatches - leTlsConnectToServers - btnTlsConnectToServers - tlsPrivateKey - tlsPrivateKeyPassword - leapUsername - leapPassword - fastAnonIdentity - fastAllowPacProvisioning - pacMethod - pacFile - fastInnerAuth - fastUsername - fastPassword - ttlsAnonIdentity - ttlsDomain - ttlsCACert - ttlsInnerAuth - ttlsUsername - ttlsPassword - peapAnonIdentity - peapDomain - peapCACert - peapVersion - peapInnerAuth - peapUsername - peapPassword - - - - - auth - currentIndexChanged(int) - stackedWidget - setCurrentIndex(int) - - - 156 - 16 - - - 149 - 72 - - - - - stackedWidget - currentChanged(int) - auth - setCurrentIndex(int) - - - 376 - 114 - - - 355 - 14 - - - - - fastAllowPacProvisioning - toggled(bool) - pacMethod - setEnabled(bool) - - - 95 - 73 - - - 285 - 77 - - - - -
diff --git a/libs/editor/settings/ui/bond.ui b/libs/editor/settings/ui/bond.ui deleted file mode 100644 index 3bb7cb25..00000000 --- a/libs/editor/settings/ui/bond.ui +++ /dev/null @@ -1,306 +0,0 @@ - - - Lukáš Tinkl <ltinkl@redhat.com> - BondWidget - - - - 0 - 0 - 473 - 417 - - - - - 6 - - - - - Interface name: - - - ifaceName - - - - - - - - - - Bonded connections: - - - bonds - - - - - - - - - QAbstractItemView::NoEditTriggers - - - true - - - true - - - - - - - Add... - - - - .. - - - - - - - false - - - Edit... - - - - .. - - - - - - - false - - - Delete - - - - .. - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Mode: - - - mode - - - - - - - - 0 - 0 - - - - - - - - Link monitoring: - - - linkMonitoring - - - - - - - - 0 - 0 - - - - - - - - Monitoring frequency: - - - monitorFreq - - - - - - - ms - - - 1 - - - 999999999 - - - 100 - - - - - - - - 0 - 0 - - - - 0 - - - - - 6 - - - - - Link up delay: - - - upDelay - - - - - - - ms - - - 999999999 - - - - - - - Link down delay: - - - downDelay - - - - - - - ms - - - 999999999 - - - - - - - - - 0 - - - - - ARP targets: - - - arpTargets - - - - - - - An IP address or comma-separated list of addresses. - - - - - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - KLineEdit - QLineEdit -
klineedit.h
-
-
- - ifaceName - bonds - btnAdd - btnEdit - btnDelete - mode - linkMonitoring - monitorFreq - upDelay - downDelay - arpTargets - - - - - linkMonitoring - currentIndexChanged(int) - monitorStack - setCurrentIndex(int) - - - 310 - 273 - - - 360 - 334 - - - - -
diff --git a/libs/editor/settings/ui/bridge.ui b/libs/editor/settings/ui/bridge.ui deleted file mode 100644 index 9a122944..00000000 --- a/libs/editor/settings/ui/bridge.ui +++ /dev/null @@ -1,288 +0,0 @@ - - - Lukáš Tinkl <ltinkl@redhat.com> - BridgeWidget - - - - 0 - 0 - 436 - 449 - - - - - - - Interface name: - - - ifaceName - - - - - - - - - - Bridged connections: - - - bridges - - - - - - - - - QAbstractItemView::NoEditTriggers - - - true - - - true - - - - - - - Add... - - - - .. - - - - - - - false - - - Edit... - - - - .. - - - - - - - false - - - Delete - - - - .. - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Aging time: - - - agingTime - - - - - - - - 0 - 0 - - - - s - - - 999999999 - - - 300 - - - - - - - Enable STP (Spanning Tree Protocol) - - - true - - - - 6 - - - - - Priority: - - - priority - - - - - - - - 0 - 0 - - - - 999999999 - - - 128 - - - - - - - Forward delay: - - - forwardDelay - - - - - - - - 0 - 0 - - - - s - - - 999999999 - - - 15 - - - - - - - Hello time: - - - helloTime - - - - - - - - 0 - 0 - - - - s - - - 999999999 - - - 2 - - - - - - - Max age: - - - maxAge - - - - - - - - 0 - 0 - - - - s - - - 999999999 - - - 20 - - - - - - - - - - - KLineEdit - QLineEdit -
klineedit.h
-
-
- - ifaceName - bridges - btnAdd - btnEdit - btnDelete - agingTime - stpGroup - priority - forwardDelay - helloTime - maxAge - - - -
diff --git a/libs/editor/settings/ui/bt.ui b/libs/editor/settings/ui/bt.ui deleted file mode 100644 index c367afd7..00000000 --- a/libs/editor/settings/ui/bt.ui +++ /dev/null @@ -1,74 +0,0 @@ - - - Lukáš Tinkl <ltinkl@redhat.com> - BtWidget - - - - 0 - 0 - 400 - 300 - - - - - 6 - - - - - Address of the device: - - - bdaddr - - - - - - - - 0 - 0 - - - - - - - - Connection type: - - - type - - - - - - - - 0 - 0 - - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - HwAddrComboBox - QComboBox -
hwaddrcombobox.h
-
-
- - -
diff --git a/libs/editor/settings/ui/cdma.ui b/libs/editor/settings/ui/cdma.ui deleted file mode 100644 index 379013d1..00000000 --- a/libs/editor/settings/ui/cdma.ui +++ /dev/null @@ -1,85 +0,0 @@ - - - CdmaWidget - - - - 0 - 0 - 400 - 300 - - - - - 6 - - - - - Number: - - - number - - - - - - - #777 - - - - - - - Username: - - - username - - - - - - - - - - Password: - - - - - - - - - true - - - - - - - - - - KLineEdit - QLineEdit -
klineedit.h
-
- - PasswordField - QLineEdit -
passwordfield.h
-
-
- - number - username - - - -
diff --git a/libs/editor/settings/ui/connectionwidget.ui b/libs/editor/settings/ui/connectionwidget.ui deleted file mode 100644 index 38d7cdae..00000000 --- a/libs/editor/settings/ui/connectionwidget.ui +++ /dev/null @@ -1,240 +0,0 @@ - - - ConnectionWidget - - - - 0 - 0 - 471 - 262 - - - - - - - Connect automatically with priority - - - true - - - - - - - true - - - - 0 - 0 - - - - If the connection is set to autoconnect, connections with higher priority will be preferred. Defaults to 0. -The higher number means higher priority. An negative number can be used to indicate priority lower than the default. - - - - -100 - - - - - - - All users may connect to this network - - - false - - - - - - - - 0 - 0 - - - - Edit advanced permissions for this connection - - - Fine-grained permissions editor for this connection. It lets you choose which users can activate/modify/delete this connection. - - - Advanced... - - - - .. - - - - - - - Automatically connect to VPN - - - - - - - false - - - - 0 - 0 - - - - - - - - Firewall zone: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - firewallZone - - - - - - - - 0 - 0 - - - - true - - - QComboBox::InsertAlphabetically - - - - - - - Metered: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - firewallZone - - - - - - - - 0 - 0 - - - - NetworkManager indicates to applications whether the connection is metered and therefore -data usage should be restricted. - - - false - - - QComboBox::InsertAlphabetically - - - - Automatic - - - - - Yes - - - - - No - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
-
- - autoconnect - allUsers - pushButtonPermissions - autoconnectVpn - vpnCombobox - firewallZone - - - - - allUsers - toggled(bool) - pushButtonPermissions - setDisabled(bool) - - - 199 - 39 - - - 382 - 51 - - - - - autoconnect - toggled(bool) - prioritySpin - setEnabled(bool) - - - 150 - 16 - - - 375 - 21 - - - - -
diff --git a/libs/editor/settings/ui/gsm.ui b/libs/editor/settings/ui/gsm.ui deleted file mode 100644 index 992b1747..00000000 --- a/libs/editor/settings/ui/gsm.ui +++ /dev/null @@ -1,192 +0,0 @@ - - - Lukáš Tinkl <lukas@redhat.com> - GsmWidget - - - - 0 - 0 - 554 - 461 - - - - - - - Basic - - - - - - Number: - - - number - - - - - - - *99# - - - - - - - Username: - - - username - - - - - - - - - - Password: - - - password - - - - - - - - - true - - - - - - - - - - - - - 0 - 0 - - - - Advanced - - - false - - - - - - Allow roaming if home network is not available - - - - - - - APN: - - - apn - - - - - - - Network ID: - - - networkId - - - - - - - - 0 - 0 - - - - - - - - PIN: - - - pin - - - - - - - - - - - - true - - - - - - - - - - - - Qt::Vertical - - - - 20 - 130 - - - - - - - - - KLineEdit - QLineEdit -
klineedit.h
-
- - PasswordField - QLineEdit -
passwordfield.h
-
-
- - number - username - password - apn - networkId - roaming - pin - - - -
diff --git a/libs/editor/settings/ui/infiniband.ui b/libs/editor/settings/ui/infiniband.ui deleted file mode 100644 index f56d002a..00000000 --- a/libs/editor/settings/ui/infiniband.ui +++ /dev/null @@ -1,111 +0,0 @@ - - - Lukáš Tinkl <ltinkl@redhat.com> - InfinibandWidget - - - - 0 - 0 - 414 - 362 - - - - - 6 - - - - - Transport mode: - - - transport - - - - - - - - 0 - 0 - - - - - - - - Restrict to device: - - - macAddress - - - - - - - - 0 - 0 - - - - - - - - MTU: - - - mtu - - - - - - - - 0 - 0 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - Automatic - - - bytes - - - 2044 - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - HwAddrComboBox - QComboBox -
hwaddrcombobox.h
-
-
- - transport - macAddress - mtu - - - -
diff --git a/libs/editor/settings/ui/ipv4.ui b/libs/editor/settings/ui/ipv4.ui deleted file mode 100644 index 99dffdcb..00000000 --- a/libs/editor/settings/ui/ipv4.ui +++ /dev/null @@ -1,384 +0,0 @@ - - - IPv4Widget - - - true - - - - 0 - 0 - 418 - 427 - - - - - - - - - - - 0 - 0 - - - - Method: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - method - - - - - - - - 0 - 0 - - - - - Automatic - - - - - Automatic (Only addresses) - - - - - Link-Local - - - - - Manual - - - - - Shared to other computers - - - - - Disabled - - - - - - - - - 0 - 0 - - - - DNS Servers: - - - Qt::AutoText - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - dns - - - - - - - - - - 0 - 0 - - - - - 250 - 0 - - - - Use this field to specify the IP address(es) of one or more DNS servers. Use ',' to separate entries. - - - - - - - Edit DNS the list of servers - - - - .. - - - - - - - - - - 0 - 0 - - - - Search Domains: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - dnsSearch - - - - - - - - - - 250 - 0 - - - - Use this field to specify one or more DNS domains to search. Use ',' to separate entries. - - - - - - - Edit the list of DNS domains being searched - - - - .. - - - - - - - - - - 0 - 0 - - - - DHCP Client ID: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - dhcpClientId - - - - - - - Use this field to specify the DHCP client ID which is a string sent to the DHCP server -to identify the local machine that the DHCP server may use to customize the DHCP -lease and options. - - - - - - - - - Remove - - - - .. - - - - - - - Add - - - - .. - - - - - - - - 0 - 0 - - - - IP addresses identify your computer on the network. Click the "Add" button to add -an IP address - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - true - - - false - - - - - - - Qt::Vertical - - - QSizePolicy::MinimumExpanding - - - - 20 - 40 - - - - - - - - - - Allows the connection to complete if IPv4 configuration fails -but IPv6 configuration succeeds - - - IPv4 is required for this connection - - - true - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Advanced... - - - - - - - true - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Qt::RightToLeft - - - Routes... - - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 40 - - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - KLineEdit - QLineEdit -
klineedit.h
-
-
- - method - dns - dnsMorePushButton - dnsSearch - dnsSearchMorePushButton - dhcpClientId - tableViewAddresses - btnAdd - btnRemove - - - -
diff --git a/libs/editor/settings/ui/ipv6.ui b/libs/editor/settings/ui/ipv6.ui deleted file mode 100644 index e20f43af..00000000 --- a/libs/editor/settings/ui/ipv6.ui +++ /dev/null @@ -1,408 +0,0 @@ - - - IPv6Widget - - - - 0 - 0 - 418 - 427 - - - - - 0 - 0 - - - - - - - Qt::LeftToRight - - - - - - When connecting to IPv4-capable networks, allows the connection to complete if -IPv6 configuration fails but IPv4 configuration succeeds - - - IPv6 is required for this connection - - - true - - - - - - - - 0 - 0 - - - - Method: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - method - - - - - - - - - - 0 - 0 - - - - - 250 - 0 - - - - Use this field to specify the IP address(es) of one or more DNS servers. Use ',' to separate entries. - - - - - - - Edit the list of DNS servers - - - - .. - - - - - - - - - - - Remove - - - - .. - - - - - - - Add - - - - .. - - - - - - - - 0 - 0 - - - - IP addresses identify your computer on the network. Click the "Add" button to add -an IP address - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - true - - - false - - - - - - - Qt::Vertical - - - QSizePolicy::MinimumExpanding - - - - 20 - 40 - - - - - - - - - - - 0 - 0 - - - - DNS Servers: - - - Qt::AutoText - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - dns - - - - - - - - 0 - 0 - - - - Configure IPv6 Privacy Extensions for SLAAC, described in RFC4941. If enabled, it makes the kernel generate -a temporary IPv6 address in addition to the public one generated from MAC address via modified EUI-64. - - - - Default - - - - - Disabled - - - - - Enabled (prefer public address) - - - - - Enabled (prefer temporary addresses) - - - - - - - - - 0 - 0 - - - - - Automatic - - - - - Automatic (Only addresses) - - - - - Automatic (Only DHCP) - - - - - Link-Local - - - - - Manual - - - - - Ignored - - - - - - - - - - - 250 - 0 - - - - Use this field to specify one or more DNS domains to search. Use ',' to separate entries. - - - - - - - Edit the list of DNS domains being searched - - - - .. - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Routes... - - - - - - - - - - 0 - 0 - - - - Privacy: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - privacyCombo - - - - - - - - 0 - 0 - - - - Search Domains: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - dnsSearch - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - labelPrivacy - ipv6RequiredCB - method - dnsLabel - dnsSearchLabel - privacyCombo - label - verticalSpacer - - - - KComboBox - QComboBox -
kcombobox.h
-
- - KLineEdit - QLineEdit -
klineedit.h
-
-
- - method - dns - dnsMorePushButton - dnsSearch - dnsSearchMorePushButton - privacyCombo - tableViewAddresses - btnAdd - btnRemove - btnRoutes - - - -
diff --git a/libs/editor/settings/ui/ppp.ui b/libs/editor/settings/ui/ppp.ui deleted file mode 100644 index 5897902f..00000000 --- a/libs/editor/settings/ui/ppp.ui +++ /dev/null @@ -1,258 +0,0 @@ - - - PPPWidget - - - - 0 - 0 - 440 - 423 - - - - - - - - 0 - 0 - - - - Authentication - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 6 - - - - - EAP - - - true - - - - - - - MSCHAP - - - true - - - - - - - PAP - - - true - - - - - - - MSCHAPv2 - - - true - - - - - - - CHAP - - - true - - - - - - - - - - Compression - - - false - - - false - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 6 - - - - - Use point-to-point encryption (MPPE) - - - - - - - Use BSD data compression - - - true - - - - - - - Use Deflate data compression - - - true - - - - - - - Use TCP header compression - - - true - - - - - - - false - - - padding-left: 20px - - - Require 128-bit encryption - - - - - - - false - - - padding-left: 20px - - - Use stateful MPPE - - - - - - - - - - Echo - - - false - - - - - - Send PPP echo packets - - - true - - - - - - - Qt::Vertical - - - - 20 - 113 - - - - - - - - - - - eap - mschap - pap - mschapv2 - chap - mppe - mppe128 - mppeStateful - bsdComp - deflateComp - tcpComp - senddEcho - - - - - mppe - toggled(bool) - mppe128 - setEnabled(bool) - - - 137 - 204 - - - 133 - 232 - - - - - mppe - toggled(bool) - mppeStateful - setEnabled(bool) - - - 199 - 205 - - - 177 - 256 - - - - - diff --git a/libs/editor/settings/ui/pppoe.ui b/libs/editor/settings/ui/pppoe.ui deleted file mode 100644 index b5b21cae..00000000 --- a/libs/editor/settings/ui/pppoe.ui +++ /dev/null @@ -1,80 +0,0 @@ - - - PppoeWidget - - - - 0 - 0 - 400 - 300 - - - - - 6 - - - - - Service: - - - service - - - - - - - If specified, instruct PPPoE to only initiate sessions with access concentrators that provide the specified service. For most providers, this should be left blank. It is only required if there are multiple access concentrators or a specific service is known to be required. - - - - - - - Username: - - - username - - - - - - - - - - Password: - - - password - - - - - - - true - - - - - - - - KLineEdit - QLineEdit -
klineedit.h
-
- - PasswordField - QLineEdit -
passwordfield.h
-
-
- - -
diff --git a/libs/editor/settings/ui/team.ui b/libs/editor/settings/ui/team.ui deleted file mode 100644 index 261c5fd0..00000000 --- a/libs/editor/settings/ui/team.ui +++ /dev/null @@ -1,145 +0,0 @@ - - - Lukáš Tinkl <ltinkl@redhat.com> - TeamWidget - - - - 0 - 0 - 394 - 436 - - - - - - - Interface name: - - - ifaceName - - - - - - - - - - Teamed connections: - - - teams - - - - - - - - - QAbstractItemView::NoEditTriggers - - - true - - - true - - - - - - - Add... - - - - - - - - - - - - false - - - Edit... - - - - - - - - - - - - false - - - Delete - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - JSON config: - - - - - - - - - - Import configuration from file... - - - - - - - - KLineEdit - QLineEdit -
klineedit.h
-
-
- - ifaceName - teams - btnAdd - btnEdit - btnDelete - - - -
diff --git a/libs/editor/settings/ui/vlan.ui b/libs/editor/settings/ui/vlan.ui deleted file mode 100644 index 460a40af..00000000 --- a/libs/editor/settings/ui/vlan.ui +++ /dev/null @@ -1,119 +0,0 @@ - - - Lukáš Tinkl <ltinkl@redhat.com> - VlanWidget - - - - 0 - 0 - 412 - 193 - - - - - - - Parent interface: - - - parent - - - - - - - - 0 - 0 - - - - true - - - - - - - VLAN id: - - - id - - - - - - - - 0 - 0 - - - - 999999999 - - - - - - - VLAN interface name: - - - ifaceName - - - - - - - - - - Output packet headers reordering - - - - - - - GARP VLAN Registration Protocol - - - GVRP - - - - - - - Loose binding - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - KLineEdit - QLineEdit -
klineedit.h
-
-
- - parent - id - ifaceName - - - -
diff --git a/libs/editor/settings/ui/wificonnectionwidget.ui b/libs/editor/settings/ui/wificonnectionwidget.ui deleted file mode 100644 index 8b9ecc40..00000000 --- a/libs/editor/settings/ui/wificonnectionwidget.ui +++ /dev/null @@ -1,366 +0,0 @@ - - - WifiConnectionWidget - - - - 0 - 0 - 401 - 334 - - - - - - - SSID: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - SSIDCombo - - - - - - - - 0 - 0 - - - - QComboBox::AdjustToMinimumContentsLength - - - - - - - Mode: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - modeComboBox - - - - - - - - 0 - 0 - - - - - Infrastructure - - - - - Ad-hoc - - - - - Access Point - - - - - - - - BSSID: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - BSSIDCombo - - - - - - - - 0 - 0 - - - - This option locks this connection to the Wi-Fi access point (AP) specified by the - BSSID entered here. Example: 00:11:22:33:44:55 - - - QComboBox::AdjustToMinimumContentsLength - - - - - - - - 0 - 0 - - - - Band: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - band - - - - - - - - 0 - 0 - - - - This option locks the connection to the Wi-Fi network associated to the specified band. This setting depends - on specific driver capability and may not work with all drivers - - - - Automatic - - - - - A (5 GHz) - - - - - B/G (2.4 GHz) - - - - - - - - Channel: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - channel - - - - - - - - 0 - 0 - - - - Wireless channel to use for the Wi-Fi connection. The device will only join (or create for Ad-Hoc networks) -a Wi-Fi network on the specified channel - - - - - - - Restrict to device: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - macAddress - - - - - - - - 0 - 0 - - - - - - - - Cloned MAC address: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - clonedMacAddress - - - - - - - - - - 0 - 0 - - - - HH:HH:HH:HH:HH:HH;_ - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Random... - - - - - - - - - MTU: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - mtu - - - - - - - - 0 - 0 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - Automatic - - - bytes - - - - - - 10000 - - - - - - - Mark this if you want to create a connection for a hidden network - - - Visibility: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - hiddenNetwork - - - - - - - Mark this if you want to create a connection for a hidden network - - - Hidden network - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - KLineEdit - QLineEdit -
klineedit.h
-
- - HwAddrComboBox - QComboBox -
hwaddrcombobox.h
-
- - SsidComboBox - QComboBox -
ssidcombobox.h
-
- - BssidComboBox - QComboBox -
bssidcombobox.h
-
-
- - SSIDCombo - modeComboBox - BSSIDCombo - band - channel - macAddress - clonedMacAddress - btnRandomMacAddr - mtu - hiddenNetwork - - - -
diff --git a/libs/editor/settings/ui/wifisecurity.ui b/libs/editor/settings/ui/wifisecurity.ui deleted file mode 100644 index dd617e6c..00000000 --- a/libs/editor/settings/ui/wifisecurity.ui +++ /dev/null @@ -1,265 +0,0 @@ - - - Lukáš Tinkl <ltinkl@redhat.com> - WifiSecurity - - - - 0 - 0 - 489 - 374 - - - - Wifi Security - - - - - - - 0 - 0 - - - - - None - - - - - WEP key 40/128 bits (Hex or ASCII) - - - - - WEP key 128 bits - - - - - LEAP - - - - - Dynamic WEP (802.1x) - - - - - WPA/WPA2 Personal - - - - - WPA/WPA2 Enterprise - - - - - WPA3 Personal - - - - - - - - Security: - - - securityCombo - - - - - - - 0 - - - - - - 6 - - - - - Key: - - - wepKey - - - - - - - 26 - - - true - - - - - - - WEP index: - - - wepIndex - - - - - - - - 0 - 0 - - - - - 1 (default) - - - - - 2 - - - - - 3 - - - - - 4 - - - - - - - - Authentication: - - - wepAuth - - - - - - - - 0 - 0 - - - - - Open System - - - - - Shared Key - - - - - - - - - - 6 - - - - - Username: - - - leapUsername - - - - - - - - - - Password: - - - leapPassword - - - - - - - true - - - - - - - - - 6 - - - - - Password: - - - psk - - - - - - - true - - - - - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - KLineEdit - QLineEdit -
klineedit.h
-
- - PasswordField - QLineEdit -
passwordfield.h
-
-
- - -
diff --git a/libs/editor/settings/ui/wiredconnectionwidget.ui b/libs/editor/settings/ui/wiredconnectionwidget.ui deleted file mode 100644 index 1983fb40..00000000 --- a/libs/editor/settings/ui/wiredconnectionwidget.ui +++ /dev/null @@ -1,274 +0,0 @@ - - - WiredConnectionWidget - - - - 0 - 0 - 437 - 232 - - - - - QFormLayout::ExpandingFieldsGrow - - - 6 - - - - - Restrict to device: - - - macAddress - - - - - - - - 0 - 0 - - - - This option locks this connection to the network device specified by its -permanent MAC address entered here. Example: 00:11:22:33:44:55 - - - - - - - Cloned MAC address: - - - clonedMacAddress - - - - - - - - - - 0 - 0 - - - - The MAC address entered here will be used as hardware address for the -network device this connection is activated on. This feature is known as MAC -cloning or spoofing. Example 11:22:33:44:55 - - - HH:HH:HH:HH:HH:HH;_ - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Random - - - - - - - - - MTU: - - - mtu - - - - - - - - 0 - 0 - - - - Only transmit packets of the specified size or smaller, breaking larger packets up -into multiple Ethernet frames - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - Automatic - - - bytes - - - 10000 - - - - - - - Speed: - - - - - - - Duplex: - - - duplex - - - - - - - false - - - - 0 - 0 - - - - Request that the device use the specified duplex mode. Either "half" or "full" - - - 1 - - - - Half - - - - - Full - - - - - - - - - - - Link negotiation: - - - - - - - - 0 - 0 - - - - Device link negotiation. If “Manual” is chosen, “Speed” and “Duplex” values will be forced without checking -the device compatibility. If unsure, leave here “Ignore” or pick “Automatic”. - - - - Ignore - - - - - Automatic - - - - - Manual - - - - - - - - false - - - - 0 - 0 - - - - Request that the device use only the specified speed. - - - 1 - - - - 10 Mb/s - - - - - 100 Mb/s - - - - - 1 Gb/s - - - - - 10 Gb/s - - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - KLineEdit - QLineEdit -
klineedit.h
-
- - HwAddrComboBox - QComboBox -
hwaddrcombobox.h
-
-
- - macAddress - clonedMacAddress - btnRandomMacAddr - mtu - duplex - - - -
diff --git a/libs/editor/settings/ui/wiredsecurity.ui b/libs/editor/settings/ui/wiredsecurity.ui deleted file mode 100644 index e5c7dd17..00000000 --- a/libs/editor/settings/ui/wiredsecurity.ui +++ /dev/null @@ -1,25 +0,0 @@ - - - WiredSecurity - - - - 0 - 0 - 487 - 379 - - - - - - - Use 802.1x security for this connection - - - - - - - - diff --git a/libs/editor/settings/vlanwidget.cpp b/libs/editor/settings/vlanwidget.cpp deleted file mode 100644 index fddea2c4..00000000 --- a/libs/editor/settings/vlanwidget.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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 "vlanwidget.h" -#include "ui_vlan.h" -#include "uiutils.h" - -#include -#include - -VlanWidget::VlanWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting, parent, f), - m_ui(new Ui::VlanWidget) -{ - m_ui->setupUi(this); - - fillConnections(); - - connect(m_ui->ifaceName, &KLineEdit::textChanged, this, &VlanWidget::slotWidgetChanged); - connect(m_ui->parent, QOverload::of(&KComboBox::currentIndexChanged), this, &VlanWidget::slotWidgetChanged); - connect(m_ui->parent->lineEdit(), &QLineEdit::textChanged, this, &VlanWidget::slotWidgetChanged); - - // Connect for setting check - watchChangedSetting(); - - KAcceleratorManager::manage(this); - - if (setting) { - loadConfig(setting); - } -} - -VlanWidget::~VlanWidget() -{ - delete m_ui; -} - -void VlanWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::VlanSetting::Ptr vlanSetting = setting.staticCast(); - - m_ui->parent->setCurrentIndex(m_ui->parent->findData(vlanSetting->parent())); - - m_ui->id->setValue(vlanSetting->id()); - m_ui->ifaceName->setText(vlanSetting->interfaceName()); - - m_ui->reorderHeaders->setChecked(vlanSetting->flags().testFlag(NetworkManager::VlanSetting::ReorderHeaders)); - m_ui->gvrp->setChecked(vlanSetting->flags().testFlag(NetworkManager::VlanSetting::Gvrp)); - m_ui->looseBinding->setChecked(vlanSetting->flags().testFlag(NetworkManager::VlanSetting::LooseBinding)); -} - -QVariantMap VlanWidget::setting() const -{ - NetworkManager::VlanSetting setting; - - setting.setParent(m_ui->parent->itemData(m_ui->parent->currentIndex()).toString()); - setting.setId(m_ui->id->value()); - - const QString ifaceName = m_ui->ifaceName->text(); - if (!ifaceName.isEmpty()) - setting.setInterfaceName(ifaceName); - - NetworkManager::VlanSetting::Flags flags; - if (m_ui->reorderHeaders->isChecked()) - flags |= NetworkManager::VlanSetting::ReorderHeaders; - if (m_ui->gvrp->isChecked()) - flags |= NetworkManager::VlanSetting::Gvrp; - if (m_ui->looseBinding->isChecked()) - flags |= NetworkManager::VlanSetting::LooseBinding; - if (flags) - setting.setFlags(flags); - - return setting.toMap(); -} - -void VlanWidget::fillConnections() -{ - m_ui->parent->clear(); - - for (const NetworkManager::Connection::Ptr &con : NetworkManager::listConnections()) { - if (!con->settings()->isSlave() && con->settings()->connectionType() == NetworkManager::ConnectionSettings::Wired) - m_ui->parent->addItem(con->name(), con->uuid()); - } -} - -bool VlanWidget::isValid() const -{ - return !m_ui->parent->currentText().isEmpty() || !m_ui->ifaceName->text().isEmpty(); -} diff --git a/libs/editor/settings/wificonnectionwidget.cpp b/libs/editor/settings/wificonnectionwidget.cpp deleted file mode 100644 index 48ced259..00000000 --- a/libs/editor/settings/wificonnectionwidget.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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 "debug.h" -#include "wificonnectionwidget.h" -#include "ui_wificonnectionwidget.h" - -#include -#include -#include - -#include "uiutils.h" - -WifiConnectionWidget::WifiConnectionWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting, parent, f), - m_ui(new Ui::WifiConnectionWidget) -{ - m_ui->setupUi(this); - - connect(m_ui->btnRandomMacAddr, &QPushButton::clicked, this, &WifiConnectionWidget::generateRandomClonedMac); - connect(m_ui->SSIDCombo, &SsidComboBox::ssidChanged, this, QOverload<>::of(&WifiConnectionWidget::ssidChanged)); - connect(m_ui->modeComboBox, QOverload::of(&KComboBox::currentIndexChanged), this, &WifiConnectionWidget::modeChanged); - connect(m_ui->band, QOverload::of(&KComboBox::currentIndexChanged), this, &WifiConnectionWidget::bandChanged); - - // Connect for setting check - watchChangedSetting(); - - // Connect for validity check - connect(m_ui->macAddress, &HwAddrComboBox::hwAddressChanged, this, &WifiConnectionWidget::slotWidgetChanged); - connect(m_ui->BSSIDCombo, &BssidComboBox::bssidChanged, this, &WifiConnectionWidget::slotWidgetChanged); - - KAcceleratorManager::manage(this); - - if (setting) { - loadConfig(setting); - } -} - -WifiConnectionWidget::~WifiConnectionWidget() -{ - delete m_ui; -} - -void WifiConnectionWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::WirelessSetting::Ptr wifiSetting = setting.staticCast(); - - m_ui->SSIDCombo->init(QString::fromUtf8(wifiSetting->ssid())); - - if (wifiSetting->mode() != NetworkManager::WirelessSetting::Infrastructure) { - m_ui->modeComboBox->setCurrentIndex(wifiSetting->mode()); - } - modeChanged(wifiSetting->mode()); - - m_ui->BSSIDCombo->init(NetworkManager::macAddressAsString(wifiSetting->bssid()), QString::fromUtf8(wifiSetting->ssid())); - - m_ui->band->setCurrentIndex(wifiSetting->band()); - if (wifiSetting->band() != NetworkManager::WirelessSetting::Automatic) { - m_ui->channel->setCurrentIndex(m_ui->channel->findData(wifiSetting->channel())); - } - - m_ui->macAddress->init(NetworkManager::Device::Wifi, NetworkManager::macAddressAsString(wifiSetting->macAddress())); - - if (!wifiSetting->clonedMacAddress().isEmpty()) { - m_ui->clonedMacAddress->setText(NetworkManager::macAddressAsString(wifiSetting->clonedMacAddress())); - } - - if (wifiSetting->mtu()) { - m_ui->mtu->setValue(wifiSetting->mtu()); - } - - if (wifiSetting->hidden()) { - m_ui->hiddenNetwork->setChecked(true); - } -} - -QVariantMap WifiConnectionWidget::setting() const -{ - NetworkManager::WirelessSetting wifiSetting; - - wifiSetting.setSsid(m_ui->SSIDCombo->ssid().toUtf8()); - - wifiSetting.setMode(static_cast(m_ui->modeComboBox->currentIndex())); - - wifiSetting.setBssid(NetworkManager::macAddressFromString(m_ui->BSSIDCombo->bssid())); - - if (wifiSetting.mode() != NetworkManager::WirelessSetting::Infrastructure && m_ui->band->currentIndex() != 0) { - wifiSetting.setBand((NetworkManager::WirelessSetting::FrequencyBand)m_ui->band->currentIndex()); - wifiSetting.setChannel(m_ui->channel->itemData(m_ui->channel->currentIndex()).toUInt()); - } - - wifiSetting.setMacAddress(NetworkManager::macAddressFromString(m_ui->macAddress->hwAddress())); - - if (!m_ui->clonedMacAddress->text().isEmpty() && m_ui->clonedMacAddress->text() != ":::::") { - wifiSetting.setClonedMacAddress(NetworkManager::macAddressFromString(m_ui->clonedMacAddress->text())); - } - - if (m_ui->mtu->value()) { - wifiSetting.setMtu(m_ui->mtu->value()); - } - - wifiSetting.setHidden(m_ui->hiddenNetwork->isChecked()); - - return wifiSetting.toMap(); -} - -void WifiConnectionWidget::generateRandomClonedMac() -{ - QByteArray mac; - auto *generator = QRandomGenerator::global(); - mac.resize(6); - for (int i = 0; i < 6; i++) { - const int random = generator->bounded(255); - mac[i] = random; - } - - // Disable the multicast bit and enable the locally administered bit. - mac[0] = mac[0] & ~0x1; - mac[0] = mac[0] | 0x2; - - m_ui->clonedMacAddress->setText(NetworkManager::macAddressAsString(mac)); -} - -void WifiConnectionWidget::ssidChanged() -{ - m_ui->BSSIDCombo->init(m_ui->BSSIDCombo->bssid(), m_ui->SSIDCombo->ssid()); - slotWidgetChanged(); - - // Emit that SSID has changed so we can pre-configure wireless security - Q_EMIT ssidChanged(m_ui->SSIDCombo->ssid()); -} - -void WifiConnectionWidget::modeChanged(int mode) -{ - if (mode == NetworkManager::WirelessSetting::Infrastructure) { - m_ui->BSSIDLabel->setVisible(true); - m_ui->BSSIDCombo->setVisible(true); - m_ui->bandLabel->setVisible(false); - m_ui->band->setVisible(false); - m_ui->channelLabel->setVisible(false); - m_ui->channel->setVisible(false); - } else { - m_ui->BSSIDLabel->setVisible(false); - m_ui->BSSIDCombo->setVisible(false); - m_ui->bandLabel->setVisible(true); - m_ui->band->setVisible(true); - m_ui->channelLabel->setVisible(true); - m_ui->channel->setVisible(true); - } -} - -void WifiConnectionWidget::bandChanged(int band) -{ - m_ui->channel->clear(); - - if (band == NetworkManager::WirelessSetting::Automatic) { - m_ui->channel->setEnabled(false); - } else { - fillChannels((NetworkManager::WirelessSetting::FrequencyBand)band); - m_ui->channel->setEnabled(true); - } -} - -void WifiConnectionWidget::fillChannels(NetworkManager::WirelessSetting::FrequencyBand band) -{ - QList > channels; - - if (band == NetworkManager::WirelessSetting::A) { - channels = NetworkManager::getAFreqs(); - } else if (band == NetworkManager::WirelessSetting::Bg) { - channels = NetworkManager::getBFreqs(); - } else { - qCWarning(PLASMA_NM) << Q_FUNC_INFO << "Unhandled band number" << band; - return; - } - - QListIterator > i(channels); - while (i.hasNext()) { - QPair channel = i.next(); - m_ui->channel->addItem(i18n("%1 (%2 MHz)", channel.first, channel.second), channel.first); - } -} - -bool WifiConnectionWidget::isValid() const -{ - return !m_ui->SSIDCombo->currentText().isEmpty() && m_ui->macAddress->isValid() && m_ui->BSSIDCombo->isValid(); -} diff --git a/libs/editor/settings/wificonnectionwidget.h b/libs/editor/settings/wificonnectionwidget.h deleted file mode 100644 index f737ebae..00000000 --- a/libs/editor/settings/wificonnectionwidget.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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_WIFI_CONNECTION_WIDGET_H -#define PLASMA_NM_WIFI_CONNECTION_WIDGET_H - -#include - -#include - -#include "settingwidget.h" - -namespace Ui -{ -class WifiConnectionWidget; -} - -class Q_DECL_EXPORT WifiConnectionWidget : public SettingWidget -{ -Q_OBJECT - -public: - explicit WifiConnectionWidget(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~WifiConnectionWidget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -Q_SIGNALS: - void ssidChanged(const QString &ssid); - -private Q_SLOTS: - void generateRandomClonedMac(); - void ssidChanged(); - void modeChanged(int mode); - void bandChanged(int band); - -private: - Ui::WifiConnectionWidget * m_ui; - void fillChannels(NetworkManager::WirelessSetting::FrequencyBand band); -}; - -#endif // PLASMA_NM_WIFI_CONNECTION_WIDGET_H diff --git a/libs/editor/settings/wifisecurity.cpp b/libs/editor/settings/wifisecurity.cpp deleted file mode 100644 index f16588ae..00000000 --- a/libs/editor/settings/wifisecurity.cpp +++ /dev/null @@ -1,418 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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 "wifisecurity.h" -#include "ui_wifisecurity.h" - -#include -#include -#include -#include - -WifiSecurity::WifiSecurity(const NetworkManager::Setting::Ptr &setting, const NetworkManager::Security8021xSetting::Ptr &setting8021x, - QWidget *parent, Qt::WindowFlags f) - : SettingWidget(setting, parent, f) - , m_ui(new Ui::WifiSecurity) -{ - m_wifiSecurity = setting.staticCast(); - - m_ui->setupUi(this); - - m_ui->leapPassword->setPasswordOptionsEnabled(true); - m_ui->psk->setPasswordOptionsEnabled(true); - m_ui->wepKey->setPasswordOptionsEnabled(true); - - m_8021xWidget = new Security8021x(setting8021x, true, this); // Dynamic WEP - m_WPA2Widget = new Security8021x(setting8021x, true, this); // WPA(2) Enterprise - m_ui->stackedWidget->insertWidget(3, m_8021xWidget); - m_ui->stackedWidget->insertWidget(5, m_WPA2Widget); - - // WPA3 Personal is available in NM 1.16+ - if (!NetworkManager::checkVersion(1, 16, 0)) { - m_ui->securityCombo->removeItem(7); - } - - connect(m_ui->securityCombo, QOverload::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::securityChanged); - connect(m_ui->wepIndex, QOverload::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::setWepKey); - - // Connect for setting check - watchChangedSetting(); - - // Connect for validity check - connect(m_ui->wepKey, &PasswordField::textChanged, this, &WifiSecurity::slotWidgetChanged); - connect(m_ui->wepKey, &PasswordField::passwordOptionChanged, this, &WifiSecurity::slotWidgetChanged); - connect(m_ui->leapUsername, &KLineEdit::textChanged, this, &WifiSecurity::slotWidgetChanged); - connect(m_ui->leapPassword, &PasswordField::textChanged, this, &WifiSecurity::slotWidgetChanged); - connect(m_ui->leapPassword, &PasswordField::passwordOptionChanged, this, &WifiSecurity::slotWidgetChanged); - connect(m_ui->psk, &PasswordField::textChanged, this, &WifiSecurity::slotWidgetChanged); - connect(m_ui->psk, &PasswordField::passwordOptionChanged, this, &WifiSecurity::slotWidgetChanged); - connect(m_ui->wepIndex, QOverload::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::slotWidgetChanged); - connect(m_ui->securityCombo, QOverload::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::slotWidgetChanged); - connect(m_8021xWidget, &Security8021x::validChanged, this, &WifiSecurity::slotWidgetChanged); - connect(m_WPA2Widget, &Security8021x::validChanged, this, &WifiSecurity::slotWidgetChanged); - - KAcceleratorManager::manage(this); - - if (setting && !setting->isNull()) { - loadConfig(setting); - } -} - -WifiSecurity::~WifiSecurity() -{ - delete m_ui; -} - -bool WifiSecurity::enabled() const -{ - return m_ui->securityCombo->currentIndex() > 0; -} - -bool WifiSecurity::enabled8021x() const -{ - if (m_ui->securityCombo->currentIndex() == 4 || m_ui->securityCombo->currentIndex() == 6) { - return true; - } - - return false; -} - -bool WifiSecurity::isValid() const -{ - const int securityIndex = m_ui->securityCombo->currentIndex(); - - if (securityIndex == WepHex) { // WEP Hex - return NetworkManager::wepKeyIsValid(m_ui->wepKey->text(), NetworkManager::WirelessSecuritySetting::Hex) || - m_ui->wepKey->passwordOption() == PasswordField::AlwaysAsk; - } else if (securityIndex == WepPassphrase) { // WEP Passphrase - return NetworkManager::wepKeyIsValid(m_ui->wepKey->text(), NetworkManager::WirelessSecuritySetting::Passphrase) || - m_ui->wepKey->passwordOption() == PasswordField::AlwaysAsk;; - }else if (securityIndex == Leap) { // LEAP - return !m_ui->leapUsername->text().isEmpty() && - (!m_ui->leapPassword->text().isEmpty() || m_ui->leapPassword->passwordOption() == PasswordField::AlwaysAsk); - } else if (securityIndex == WpaPsk) { // WPA - return NetworkManager::wpaPskIsValid(m_ui->psk->text()) || - m_ui->psk->passwordOption() == PasswordField::AlwaysAsk; - } else if (securityIndex == DynamicWep) { - return m_8021xWidget->isValid(); - } else if (securityIndex == WpaEap) { - return m_WPA2Widget->isValid(); - } else if (securityIndex == SAE) { - return !m_ui->psk->text().isEmpty() || m_ui->psk->passwordOption() == PasswordField::AlwaysAsk; - } - - return true; -} - -void WifiSecurity::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::WirelessSecuritySetting::Ptr wifiSecurity = setting.staticCast(); - - const NetworkManager::WirelessSecuritySetting::KeyMgmt keyMgmt = wifiSecurity->keyMgmt(); - const NetworkManager::WirelessSecuritySetting::AuthAlg authAlg = wifiSecurity->authAlg(); - - if (keyMgmt == NetworkManager::WirelessSecuritySetting::Unknown) { - m_ui->securityCombo->setCurrentIndex(None); // None - } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::Wep) { - if (wifiSecurity->wepKeyType() == NetworkManager::WirelessSecuritySetting::Hex || - wifiSecurity->wepKeyType() == NetworkManager::WirelessSecuritySetting::NotSpecified) { - m_ui->securityCombo->setCurrentIndex(WepHex); // WEP Hex - } else { - m_ui->securityCombo->setCurrentIndex(WepPassphrase); - } - const int keyIndex = static_cast(wifiSecurity->wepTxKeyindex()); - m_ui->wepIndex->setCurrentIndex(keyIndex); - - if (wifiSecurity->authAlg() == NetworkManager::WirelessSecuritySetting::Open) { - m_ui->wepAuth->setCurrentIndex(0); - } else { - m_ui->wepAuth->setCurrentIndex(1); - } - - if (wifiSecurity->wepKeyFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->wepKey->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (wifiSecurity->wepKeyFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->wepKey->setPasswordOption(PasswordField::StoreForUser); - } else { - m_ui->wepKey->setPasswordOption(PasswordField::AlwaysAsk); - } - } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x - && authAlg == NetworkManager::WirelessSecuritySetting::Leap) { - m_ui->securityCombo->setCurrentIndex(Leap); // LEAP - m_ui->leapUsername->setText(wifiSecurity->leapUsername()); - m_ui->leapPassword->setText(wifiSecurity->leapPassword()); - - if (wifiSecurity->leapPasswordFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->leapPassword->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (wifiSecurity->leapPasswordFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->leapPassword->setPasswordOption(PasswordField::StoreForUser); - } else { - m_ui->leapPassword->setPasswordOption(PasswordField::AlwaysAsk); - } - } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x) { - m_ui->securityCombo->setCurrentIndex(DynamicWep); // Dynamic WEP - // done in the widget - - } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaPsk) { - m_ui->securityCombo->setCurrentIndex(WpaPsk); // WPA - - if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->psk->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->psk->setPasswordOption(PasswordField::StoreForUser); - } else { - m_ui->psk->setPasswordOption(PasswordField::AlwaysAsk); - } - } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaEap) { - m_ui->securityCombo->setCurrentIndex(WpaEap); // WPA2 Enterprise - // done in the widget - } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::SAE) { - m_ui->securityCombo->setCurrentIndex(SAE); // WPA3 - - if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::None)) { - m_ui->psk->setPasswordOption(PasswordField::StoreForAllUsers); - } else if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::AgentOwned)) { - m_ui->psk->setPasswordOption(PasswordField::StoreForUser); - } else { - m_ui->psk->setPasswordOption(PasswordField::AlwaysAsk); - } - } - - if (keyMgmt != NetworkManager::WirelessSecuritySetting::Ieee8021x && - keyMgmt != NetworkManager::WirelessSecuritySetting::WpaEap) { - loadSecrets(setting); - } -} - -void WifiSecurity::loadSecrets(const NetworkManager::Setting::Ptr &setting) -{ - const NetworkManager::WirelessSecuritySetting::KeyMgmt keyMgmt = m_wifiSecurity->keyMgmt(); - const NetworkManager::WirelessSecuritySetting::AuthAlg authAlg = m_wifiSecurity->authAlg(); - - if ((keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x && authAlg != NetworkManager::WirelessSecuritySetting::Leap) || - keyMgmt == NetworkManager::WirelessSecuritySetting::WpaEap) { - NetworkManager::Security8021xSetting::Ptr security8021xSetting = setting.staticCast(); - if (security8021xSetting) { - if (keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x) { - m_8021xWidget->loadSecrets(security8021xSetting); - } else { - m_WPA2Widget->loadSecrets(security8021xSetting); - } - } - } else { - NetworkManager::WirelessSecuritySetting::Ptr wifiSecurity = setting.staticCast(); - if (wifiSecurity) { - if (keyMgmt == NetworkManager::WirelessSecuritySetting::Wep) { - m_wifiSecurity->secretsFromMap(wifiSecurity->secretsToMap()); - const int keyIndex = static_cast(m_wifiSecurity->wepTxKeyindex()); - setWepKey(keyIndex); - } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x - && authAlg == NetworkManager::WirelessSecuritySetting::Leap) { - const QString leapPassword = wifiSecurity->leapPassword(); - if (!leapPassword.isEmpty()) { - m_ui->leapPassword->setText(leapPassword); - } - } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaPsk || keyMgmt == NetworkManager::WirelessSecuritySetting::SAE) { - const QString psk = wifiSecurity->psk(); - if (!psk.isEmpty()) { - m_ui->psk->setText(psk); - } - } - } - } -} - -QVariantMap WifiSecurity::setting() const -{ - NetworkManager::WirelessSecuritySetting wifiSecurity; - - const int securityIndex = m_ui->securityCombo->currentIndex(); - if (securityIndex == None) { - wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::Unknown); - } else if (securityIndex == WepHex || securityIndex == WepPassphrase) { // WEP - wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::Wep); - if (securityIndex == WepHex) { - wifiSecurity.setWepKeyType(NetworkManager::WirelessSecuritySetting::Hex); - } else { - wifiSecurity.setWepKeyType(NetworkManager::WirelessSecuritySetting::Passphrase); - } - const int keyIndex = m_ui->wepIndex->currentIndex(); - const QString wepKey = m_ui->wepKey->text(); - wifiSecurity.setWepTxKeyindex(keyIndex); - if (keyIndex == 0) { - wifiSecurity.setWepKey0(wepKey); - } else if (keyIndex == 1) { - wifiSecurity.setWepKey1(wepKey); - } else if (keyIndex == 2) { - wifiSecurity.setWepKey2(wepKey); - } else if (keyIndex == 3) { - wifiSecurity.setWepKey3(wepKey); - } - - if (m_ui->wepKey->passwordOption() == PasswordField::StoreForAllUsers) { - wifiSecurity.setWepKeyFlags(NetworkManager::Setting::None); - } else if (m_ui->wepKey->passwordOption() == PasswordField::StoreForUser) { - wifiSecurity.setWepKeyFlags(NetworkManager::Setting::AgentOwned); - } else { - wifiSecurity.setWepKeyFlags(NetworkManager::Setting::NotSaved); - } - - if (m_ui->wepAuth->currentIndex() == 0) { - wifiSecurity.setAuthAlg(NetworkManager::WirelessSecuritySetting::Open); - } else { - wifiSecurity.setAuthAlg(NetworkManager::WirelessSecuritySetting::Shared); - } - } else if (securityIndex == Leap) { // LEAP - wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::Ieee8021x); - wifiSecurity.setAuthAlg(NetworkManager::WirelessSecuritySetting::Leap); - wifiSecurity.setLeapUsername(m_ui->leapUsername->text()); - wifiSecurity.setLeapPassword(m_ui->leapPassword->text()); - - if (m_ui->leapPassword->passwordOption() == PasswordField::StoreForAllUsers) { - wifiSecurity.setLeapPasswordFlags(NetworkManager::Setting::None); - } else if (m_ui->leapPassword->passwordOption() == PasswordField::StoreForUser) { - wifiSecurity.setLeapPasswordFlags(NetworkManager::Setting::AgentOwned); - } else { - wifiSecurity.setLeapPasswordFlags(NetworkManager::Setting::NotSaved); - } - } else if (securityIndex == DynamicWep) { // Dynamic WEP - wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::Ieee8021x); - } else if (securityIndex == WpaPsk) { // WPA - wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaPsk); - wifiSecurity.setPsk(m_ui->psk->text()); - - if (m_ui->psk->passwordOption() == PasswordField::StoreForAllUsers) { - wifiSecurity.setPskFlags(NetworkManager::Setting::None); - } else if (m_ui->psk->passwordOption() == PasswordField::StoreForUser) { - wifiSecurity.setPskFlags(NetworkManager::Setting::AgentOwned); - } else { - wifiSecurity.setPskFlags(NetworkManager::Setting::NotSaved); - } - } else if (securityIndex == WpaEap) { // WPA2 Enterprise - wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap); - } else if (securityIndex == SAE) { // WPA3 Personal - wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::SAE); - wifiSecurity.setPsk(m_ui->psk->text()); - - if (m_ui->psk->passwordOption() == PasswordField::StoreForAllUsers) { - wifiSecurity.setPskFlags(NetworkManager::Setting::None); - } else if (m_ui->psk->passwordOption() == PasswordField::StoreForUser) { - wifiSecurity.setPskFlags(NetworkManager::Setting::AgentOwned); - } else { - wifiSecurity.setPskFlags(NetworkManager::Setting::NotSaved); - } - } - - return wifiSecurity.toMap(); -} - -QVariantMap WifiSecurity::setting8021x() const -{ - if (m_ui->securityCombo->currentIndex() == DynamicWep) { // Dynamic WEP - return m_8021xWidget->setting(); - } else if (m_ui->securityCombo->currentIndex() == WpaEap) { // WPA2 Enterprise - return m_WPA2Widget->setting(); - } - - return QVariantMap(); -} - -void WifiSecurity::onSsidChanged(const QString &ssid) -{ - for (const NetworkManager::Device::Ptr &device : NetworkManager::networkInterfaces()) { - if (device->type() == NetworkManager::Device::Wifi) { - NetworkManager::WirelessDevice::Ptr wifiDevice = device.staticCast(); - if (wifiDevice) { - for (const NetworkManager::WirelessNetwork::Ptr wifiNetwork : wifiDevice->networks()) { - if (wifiNetwork && wifiNetwork->ssid() == ssid) { - NetworkManager::AccessPoint::Ptr ap = wifiNetwork->referenceAccessPoint(); - NetworkManager::WirelessSecurityType securityType = NetworkManager::findBestWirelessSecurity(wifiDevice->wirelessCapabilities(), true, (wifiDevice->mode() == NetworkManager::WirelessDevice::Adhoc), - ap->capabilities(), ap->wpaFlags(), ap->rsnFlags()); - switch (securityType) { - case NetworkManager::WirelessSecurityType::StaticWep: - m_ui->securityCombo->setCurrentIndex(WepHex); - break; - case NetworkManager::WirelessSecurityType::DynamicWep: - m_ui->securityCombo->setCurrentIndex(DynamicWep); - break; - case NetworkManager::WirelessSecurityType::Leap: - m_ui->securityCombo->setCurrentIndex(Leap); - break; - case NetworkManager::WirelessSecurityType::WpaPsk: - m_ui->securityCombo->setCurrentIndex(WpaPsk); - break; - case NetworkManager::WirelessSecurityType::Wpa2Psk: - m_ui->securityCombo->setCurrentIndex(WpaPsk); - break; - case NetworkManager::WirelessSecurityType::WpaEap: - m_ui->securityCombo->setCurrentIndex(WpaEap); - break; - case NetworkManager::WirelessSecurityType::Wpa2Eap: - m_ui->securityCombo->setCurrentIndex(WpaEap); - break; - case NetworkManager::WirelessSecurityType::SAE: - m_ui->securityCombo->setCurrentIndex(SAE); - break; - default: - m_ui->securityCombo->setCurrentIndex(None); - } - - return; - } - } - } - } - } - - // Reset to none security if we don't find any AP or Wifi device - m_ui->securityCombo->setCurrentIndex(None); -} - -void WifiSecurity::setWepKey(int keyIndex) -{ - if (keyIndex == 0) { - m_ui->wepKey->setText(m_wifiSecurity->wepKey0()); - } else if (keyIndex == 1) { - m_ui->wepKey->setText(m_wifiSecurity->wepKey1()); - } else if (keyIndex == 2) { - m_ui->wepKey->setText(m_wifiSecurity->wepKey2()); - } else if (keyIndex == 3) { - m_ui->wepKey->setText(m_wifiSecurity->wepKey3()); - } -} - -void WifiSecurity::securityChanged(int index) -{ - if (index == None) { - m_ui->stackedWidget->setCurrentIndex(0); - } else if (index == WepHex || index == WepPassphrase) { - m_ui->stackedWidget->setCurrentIndex(1); - } else if (index == Leap) { - m_ui->stackedWidget->setCurrentIndex(2); - } else if (index == DynamicWep) { - m_ui->stackedWidget->setCurrentIndex(3); - } else if (index == WpaPsk || index == SAE) { - m_ui->stackedWidget->setCurrentIndex(4); - } else if (index == WpaEap) { - m_ui->stackedWidget->setCurrentIndex(5); - } - - KAcceleratorManager::manage(m_ui->stackedWidget->currentWidget()); -} diff --git a/libs/editor/settings/wifisecurity.h b/libs/editor/settings/wifisecurity.h deleted file mode 100644 index c24d8a91..00000000 --- a/libs/editor/settings/wifisecurity.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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_WIFI_SECURITY_H -#define PLASMA_NM_WIFI_SECURITY_H - -#include - -#include -#include - -#include "settingwidget.h" -#include "security802-1x.h" - -namespace Ui -{ -class WifiSecurity; -} - -class Q_DECL_EXPORT WifiSecurity : public SettingWidget -{ - Q_OBJECT -public: - // Keep this in sync with NetworkManager::WirelessSecurityType from - // NetworkManagerQt. - enum SecurityTypeIndex { None = 0, WepHex, WepPassphrase, Leap, DynamicWep, WpaPsk, WpaEap, SAE }; - - explicit WifiSecurity(const NetworkManager::Setting::Ptr &setting = NetworkManager::Setting::Ptr(), - const NetworkManager::Security8021xSetting::Ptr &setting8021x = NetworkManager::Security8021xSetting::Ptr(), - QWidget *parent = nullptr, Qt::WindowFlags f = {}); - ~WifiSecurity() override; - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - void loadSecrets(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - QVariantMap setting8021x() const; - - bool enabled() const; - bool enabled8021x() const; - - bool isValid() const override; - -public Q_SLOTS: - void onSsidChanged(const QString &ssid); - -private Q_SLOTS: - void securityChanged(int index); - void setWepKey(int keyIndex); - -private: - Ui::WifiSecurity *m_ui; - Security8021x *m_8021xWidget; - Security8021x *m_WPA2Widget; - NetworkManager::WirelessSecuritySetting::Ptr m_wifiSecurity; -}; - -#endif // PLASMA_NM_WIFI_SECURITY_H diff --git a/libs/editor/settings/wiredconnectionwidget.cpp b/libs/editor/settings/wiredconnectionwidget.cpp deleted file mode 100644 index b9851942..00000000 --- a/libs/editor/settings/wiredconnectionwidget.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* - 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 "wiredconnectionwidget.h" -#include "ui_wiredconnectionwidget.h" -#include "uiutils.h" - -#include -#include - -#include - -WiredConnectionWidget::WiredConnectionWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting, parent, f), - m_widget(new Ui::WiredConnectionWidget) -{ - m_widget->setupUi(this); - - connect(m_widget->btnRandomMacAddr, &QPushButton::clicked, this, &WiredConnectionWidget::generateRandomClonedMac); - - // Connect for setting check - watchChangedSetting(); - - // Connect for validity check - connect(m_widget->clonedMacAddress, &KLineEdit::textChanged, this, &WiredConnectionWidget::slotWidgetChanged); - connect(m_widget->macAddress, &HwAddrComboBox::hwAddressChanged, this, &WiredConnectionWidget::slotWidgetChanged); - connect(m_widget->linkNegotiation, QOverload::of(&QComboBox::currentIndexChanged), this, [this] (int index) { - m_widget->duplex->setEnabled(index == LinkNegotiation::Manual); - m_widget->speed->setEnabled(index == LinkNegotiation::Manual); - }); - - KAcceleratorManager::manage(this); - - if (setting) { - loadConfig(setting); - } -} - -WiredConnectionWidget::~WiredConnectionWidget() -{ - delete m_widget; -} - -void WiredConnectionWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::WiredSetting::Ptr wiredSetting = setting.staticCast(); - - m_widget->macAddress->init(NetworkManager::Device::Ethernet, NetworkManager::macAddressAsString(wiredSetting->macAddress())); - - if (!wiredSetting->clonedMacAddress().isEmpty()) { - m_widget->clonedMacAddress->setText(NetworkManager::macAddressAsString(wiredSetting->clonedMacAddress())); - } - - if (wiredSetting->mtu()) { - m_widget->mtu->setValue(wiredSetting->mtu()); - } - - if (wiredSetting->autoNegotiate()) { - m_widget->linkNegotiation->setCurrentIndex(LinkNegotiation::Automatic); - } else if (wiredSetting->speed() && wiredSetting->duplexType() != NetworkManager::WiredSetting::UnknownDuplexType) { - m_widget->linkNegotiation->setCurrentIndex(LinkNegotiation::Manual); - } - - if (wiredSetting->speed()) { - switch(wiredSetting->speed()) { - case 10: - m_widget->speed->setCurrentIndex(0); - break; - case 100: - m_widget->speed->setCurrentIndex(1); - break; - case 1000: - m_widget->speed->setCurrentIndex(2); - break; - case 10000: - m_widget->speed->setCurrentIndex(3); - break; - } - } - - if (wiredSetting->duplexType() != NetworkManager::WiredSetting::Half) { - m_widget->duplex->setCurrentIndex(Duplex::Full); - } else { - m_widget->duplex->setCurrentIndex(Duplex::Half); - } -} - -QVariantMap WiredConnectionWidget::setting() const -{ - NetworkManager::WiredSetting wiredSetting; - - wiredSetting.setMacAddress(NetworkManager::macAddressFromString(m_widget->macAddress->hwAddress())); - - if (!m_widget->clonedMacAddress->text().isEmpty() && m_widget->clonedMacAddress->text() != ":::::") { - wiredSetting.setClonedMacAddress(NetworkManager::macAddressFromString(m_widget->clonedMacAddress->text())); - } - - if (m_widget->mtu->value()) { - wiredSetting.setMtu(m_widget->mtu->value()); - } - - if (m_widget->linkNegotiation->currentIndex() == LinkNegotiation::Automatic || m_widget->linkNegotiation->currentIndex() == LinkNegotiation::Ignore) { - wiredSetting.setDuplexType(NetworkManager::WiredSetting::UnknownDuplexType); - wiredSetting.setSpeed(0); - } else { - switch (m_widget->speed->currentIndex()) { - case 0: - wiredSetting.setSpeed(10); - break; - case 1: - wiredSetting.setSpeed(100); - break; - case 2: - wiredSetting.setSpeed(1000); - break; - case 3: - wiredSetting.setSpeed(10000); - break; - } - - if (m_widget->duplex->currentIndex() == Duplex::Full) { - wiredSetting.setDuplexType(NetworkManager::WiredSetting::Full); - } else { - wiredSetting.setDuplexType(NetworkManager::WiredSetting::Half); - } - } - - wiredSetting.setAutoNegotiate(m_widget->linkNegotiation->currentIndex() == LinkNegotiation::Automatic); - - - return wiredSetting.toMap(); -} - -void WiredConnectionWidget::generateRandomClonedMac() -{ - auto *generator = QRandomGenerator::global(); - QByteArray mac; - mac.resize(6); - for (int i = 0; i < 6; i++) { - const int random = generator->bounded(255); - mac[i] = random; - } - - // Disable the multicast bit and enable the locally administered bit. - mac[0] = mac[0] & ~0x1; - mac[0] = mac[0] | 0x2; - - m_widget->clonedMacAddress->setText(NetworkManager::macAddressAsString(mac)); -} - -bool WiredConnectionWidget::isValid() const -{ - if (!m_widget->macAddress->isValid()) { - return false; - } - - if (m_widget->clonedMacAddress->text() != ":::::") { - if (!NetworkManager::macAddressIsValid(m_widget->clonedMacAddress->text())) { - return false; - } - } - - return true; -} diff --git a/libs/editor/settings/wiredconnectionwidget.h b/libs/editor/settings/wiredconnectionwidget.h deleted file mode 100644 index 400bcc44..00000000 --- a/libs/editor/settings/wiredconnectionwidget.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - 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 . -*/ - -#ifndef PLASMA_NM_WIRED_CONNECTION_WIDGET_H -#define PLASMA_NM_WIRED_CONNECTION_WIDGET_H - -#include - -#include "settingwidget.h" - -namespace Ui -{ -class WiredConnectionWidget; -} - -class Q_DECL_EXPORT WiredConnectionWidget : public SettingWidget -{ -Q_OBJECT - -public: - enum LinkNegotiation { - Ignore = 0, - Automatic, - Manual - }; - - enum Duplex { - Half = 0, - Full - }; - - explicit WiredConnectionWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~WiredConnectionWidget() override; - - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - - QVariantMap setting() const override; - - bool isValid() const override; - -private Q_SLOTS: - void generateRandomClonedMac(); - -private: - Ui::WiredConnectionWidget * m_widget; -}; - -#endif // PLASMA_NM_WIRED_CONNECTION_WIDGET_H diff --git a/libs/editor/settings/wiredsecurity.cpp b/libs/editor/settings/wiredsecurity.cpp deleted file mode 100644 index 8f3de5b2..00000000 --- a/libs/editor/settings/wiredsecurity.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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 "wiredsecurity.h" -#include "ui_wiredsecurity.h" - -WiredSecurity::WiredSecurity(const NetworkManager::Security8021xSetting::Ptr &setting8021x, QWidget* parent, Qt::WindowFlags f): - SettingWidget(setting8021x, parent, f), - m_ui(new Ui::WiredSecurity), - m_8021xSetting(setting8021x) -{ - m_ui->setupUi(this); - - m_8021xWidget = new Security8021x(m_8021xSetting, false, this); - m_8021xWidget->setDisabled(true); - - m_ui->verticalLayout->addWidget(m_8021xWidget); - - connect(m_ui->use8021X, &QCheckBox::toggled, m_8021xWidget, &Security8021x::setEnabled); - - // Connect for setting check - watchChangedSetting(); - - KAcceleratorManager::manage(this); - - loadConfig(setting8021x); -} - -WiredSecurity::~WiredSecurity() -{ - delete m_ui; -} - -bool WiredSecurity::enabled8021x() const -{ - if (m_ui->use8021X->checkState() == Qt::Checked) { - return true; - } - - return false; -} - -void WiredSecurity::loadConfig(const NetworkManager::Setting::Ptr &setting) -{ - if (!setting->isNull()) { - m_8021xWidget->setEnabled(true); - m_ui->use8021X->setChecked(true); - } -} - -void WiredSecurity::loadSecrets(const NetworkManager::Setting::Ptr &setting) -{ - NetworkManager::Security8021xSetting::Ptr securitySetting = setting.staticCast(); - - if (securitySetting) { - m_8021xWidget->loadSecrets(securitySetting); - } -} - -QVariantMap WiredSecurity::setting() const -{ - if (m_ui->use8021X->isChecked()) { - return m_8021xWidget->setting(); - } - - return QVariantMap(); -} diff --git a/libs/editor/settings/wiredsecurity.h b/libs/editor/settings/wiredsecurity.h deleted file mode 100644 index 7c677cf6..00000000 --- a/libs/editor/settings/wiredsecurity.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - Copyright (c) 2013 Lukas Tinkl - - 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_WIRED_SECURITY_H -#define PLASMA_NM_WIRED_SECURITY_H - -#include - -#include - -#include "settingwidget.h" -#include "security802-1x.h" - -namespace Ui -{ -class WiredSecurity; -} - -class Q_DECL_EXPORT WiredSecurity : public SettingWidget -{ - Q_OBJECT -public: - explicit WiredSecurity(const NetworkManager::Security8021xSetting::Ptr &setting8021x = NetworkManager::Security8021xSetting::Ptr(), QWidget* parent = nullptr, Qt::WindowFlags f = {}); - ~WiredSecurity() override; - void loadConfig(const NetworkManager::Setting::Ptr &setting) override; - void loadSecrets(const NetworkManager::Setting::Ptr &setting) override; - QVariantMap setting() const override; - - bool enabled8021x() const; - -private: - Ui::WiredSecurity * m_ui; - Security8021x * m_8021xWidget; - NetworkManager::Security8021xSetting::Ptr m_8021xSetting; -}; - -#endif // PLASMA_NM_WIRED_SECURITY_H diff --git a/libs/editor/widgets/advancedpermissionswidget.cpp b/libs/editor/widgets/advancedpermissionswidget.cpp deleted file mode 100644 index 3b889cdc..00000000 --- a/libs/editor/widgets/advancedpermissionswidget.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - Copyright 2011 Ilia Kats - 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 "advancedpermissionswidget.h" -#include "ui_advancedpermissionswidget.h" - -#include -#include -#include -#include - -#define UserTagRole Qt::UserRole + 1 - -class AdvancedPermissionsWidgetPrivate -{ -public: - Ui_AdvancedPermissions ui; -}; - -AdvancedPermissionsWidget::AdvancedPermissionsWidget(QWidget *parent): - QDialog(parent), - d_ptr(new AdvancedPermissionsWidgetPrivate) -{ - Q_D(AdvancedPermissionsWidget); - d->ui.setupUi(this); - - for (const KUser &user : KUser::allUsers()) { - if (user.userId().nativeId() >= 1000 && user.loginName() != QLatin1String("nobody")) - d->ui.availUsers->addTopLevelItem(constructItem(user)); - } - setupCommon(); -} - -AdvancedPermissionsWidget::AdvancedPermissionsWidget(const QHash &users, QWidget *parent): - QDialog(parent), - d_ptr(new AdvancedPermissionsWidgetPrivate) -{ - Q_D(AdvancedPermissionsWidget); - d->ui.setupUi(this); - - for (const KUser &user : KUser::allUsers()) { - const QString name = user.loginName(); - if (!users.contains(name) && user.userId().nativeId() >= 1000 && user.loginName() != QLatin1String("nobody")) - d->ui.availUsers->addTopLevelItem(constructItem(user)); - else if (users.contains(name)) - d->ui.currentUsers->addTopLevelItem(constructItem(user, users.value(name))); - } - setupCommon(); -} - -AdvancedPermissionsWidget::~AdvancedPermissionsWidget() -{ - Q_D(AdvancedPermissionsWidget); - while (QTreeWidgetItem *item = d->ui.currentUsers->takeTopLevelItem(0)) { - delete item; - } - while (QTreeWidgetItem *item = d->ui.availUsers->takeTopLevelItem(0)) { - delete item; - } - delete d_ptr; -} - -void AdvancedPermissionsWidget::setupCommon() -{ - Q_D(AdvancedPermissionsWidget); - connect(d->ui.arrowLeft, &QPushButton::clicked, this, &AdvancedPermissionsWidget::leftArrowClicked); - connect(d->ui.arrowRight, &QPushButton::clicked, this, &AdvancedPermissionsWidget::rightArrowClicked); - d->ui.availUsers->sortByColumn(FullName, Qt::AscendingOrder); - d->ui.currentUsers->sortByColumn(FullName, Qt::AscendingOrder); - d->ui.availUsers->setSortingEnabled(true); - d->ui.currentUsers->setSortingEnabled(true); - - KAcceleratorManager::manage(this); -} - -QTreeWidgetItem * AdvancedPermissionsWidget::constructItem(const KUser &user, const QString &itemData) -{ - QStringList data; - QString name = user.property(KUser::FullName).toString(); - QString nametooltip; - if (name.isEmpty()) { - name = i18nc("@item:intable shortcut for Not Available", "N/A"); - nametooltip = i18nc("@info:tooltip real user name is not available", "Not Available"); - } else { - nametooltip = name; - } - data << name << user.loginName(); - QTreeWidgetItem *item = new QTreeWidgetItem(data); - item->setData(LoginName, UserTagRole, itemData); - item->setToolTip(FullName, nametooltip); - item->setToolTip(LoginName, user.loginName()); - return item; -} - -QHash AdvancedPermissionsWidget::currentUsers() const -{ - Q_D(const AdvancedPermissionsWidget); - QHash permissions; - const int itemNumber = d->ui.currentUsers->topLevelItemCount(); - for (int i = 0; i < itemNumber; i++) { - QTreeWidgetItem *item = d->ui.currentUsers->topLevelItem(i); - QString username = item->data(LoginName, Qt::DisplayRole).toString(); - QString tags = item->data(LoginName, UserTagRole).toString(); - permissions.insert(username, tags); - } - return permissions; -} - -void AdvancedPermissionsWidget::rightArrowClicked() -{ - Q_D(AdvancedPermissionsWidget); - for (QTreeWidgetItem *item : d->ui.availUsers->selectedItems()) { - const int index = d->ui.availUsers->indexOfTopLevelItem(item); - d->ui.availUsers->takeTopLevelItem(index); - d->ui.currentUsers->addTopLevelItem(item); - } -} - -void AdvancedPermissionsWidget::leftArrowClicked() -{ - Q_D(AdvancedPermissionsWidget); - for (QTreeWidgetItem *item : d->ui.currentUsers->selectedItems()) { - if (item->data(LoginName, Qt::DisplayRole) != KUser().loginName()) { - const int index = d->ui.currentUsers->indexOfTopLevelItem(item); - d->ui.currentUsers->takeTopLevelItem(index); - d->ui.availUsers->addTopLevelItem(item); - } - } -} diff --git a/libs/editor/widgets/advancedpermissionswidget.h b/libs/editor/widgets/advancedpermissionswidget.h deleted file mode 100644 index eae674b9..00000000 --- a/libs/editor/widgets/advancedpermissionswidget.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright 2011 Ilia Kats - 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 . -*/ - -#ifndef PLASMA_NM_ADVANCED_PERMISSIONS_WIDGET_H -#define PLASMA_NM_ADVANCED_PERMISSIONS_WIDGET_H - -#include -#include - -class QTreeWidgetItem; -class AdvancedPermissionsWidgetPrivate; -class KUser; - -class AdvancedPermissionsWidget : public QDialog -{ -Q_OBJECT -Q_DECLARE_PRIVATE(AdvancedPermissionsWidget) -public: - explicit AdvancedPermissionsWidget(QWidget *parent = nullptr); - AdvancedPermissionsWidget(const QHash&, QWidget *parent = nullptr); - ~AdvancedPermissionsWidget() override; - - QHash currentUsers() const; - -protected: - AdvancedPermissionsWidgetPrivate * const d_ptr; - -private: - enum Columns {FullName = 0, LoginName = 1}; - void setupCommon(); - QTreeWidgetItem * constructItem(const KUser &user, const QString &itemData = QString()); - -private Q_SLOTS: - void leftArrowClicked(); - void rightArrowClicked(); -}; - -#endif // PLASMA_NM_ADVANCED_PERMISSIONS_WIDGET_H diff --git a/libs/editor/widgets/bssidcombobox.cpp b/libs/editor/widgets/bssidcombobox.cpp deleted file mode 100644 index 60c2fd08..00000000 --- a/libs/editor/widgets/bssidcombobox.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - 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 "bssidcombobox.h" - -#include -#include -#include - -#include - -bool signalCompare(const NetworkManager::AccessPoint::Ptr & one, const NetworkManager::AccessPoint::Ptr & two) { - return one->signalStrength() > two->signalStrength(); -} - -BssidComboBox::BssidComboBox(QWidget *parent) : - QComboBox(parent), m_dirty(false) -{ - setEditable(true); - setInsertPolicy(QComboBox::NoInsert); - - connect(this, &BssidComboBox::editTextChanged, this, &BssidComboBox::slotEditTextChanged); - connect(this, QOverload::of(&BssidComboBox::activated), this, &BssidComboBox::slotCurrentIndexChanged); -} - -QString BssidComboBox::bssid() const -{ - QString result; - if (!m_dirty) - result = itemData(currentIndex()).toString(); - else - result = currentText(); - - // qCDebug(PLASMA_NM) << "Result:" << currentIndex() << result; - - return result; -} - -bool BssidComboBox::isValid() const -{ - if (bssid().isEmpty()) { - return true; - } - - return NetworkManager::macAddressIsValid(bssid()); -} - -void BssidComboBox::slotEditTextChanged(const QString &) -{ - m_dirty = true; - Q_EMIT bssidChanged(); -} - -void BssidComboBox::slotCurrentIndexChanged(int) -{ - m_dirty = false; - setEditText(bssid()); - Q_EMIT bssidChanged(); -} - -void BssidComboBox::init(const QString & bssid, const QString &ssid) -{ - m_initialBssid = bssid; - - // qCDebug(PLASMA_NM) << "Initial ssid:" << m_initialBssid; - - QList aps; - - for (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; - } - - for (const NetworkManager::AccessPoint::Ptr &newAp : wifiNetwork->accessPoints()) { - bool found = false;; - for (const NetworkManager::AccessPoint::Ptr &existingAp : aps) { - if (newAp->hardwareAddress() == existingAp->hardwareAddress()) { - if (newAp->signalStrength() > existingAp->signalStrength()) { - aps.removeOne(existingAp); - break; - } else { - found = true; - break; - } - } - } - - if (!found) { - aps << newAp; - } - } - } - } - - std::sort(aps.begin(), aps.end(), signalCompare); - addBssidsToCombo(aps); - - const int index = findData(m_initialBssid); - if (index == -1) { - insertItem(0, m_initialBssid, m_initialBssid); - setCurrentIndex(0); - } else { - setCurrentIndex(index); - } - setEditText(m_initialBssid); -} - -void BssidComboBox::addBssidsToCombo(const QList & aps) -{ - clear(); - - if (aps.isEmpty()) { - addItem(i18n("First select the SSID")); - return; - } - - for (const NetworkManager::AccessPoint::Ptr &ap : aps) { - if (!ap) { - continue; - } - - const QString text = i18n("%1 (%2%)\nFrequency: %3 Mhz\nChannel: %4", ap->hardwareAddress(), ap->signalStrength(), ap->frequency(), QString::number(NetworkManager::findChannel(ap->frequency()))); - addItem(text, QVariant::fromValue(ap->hardwareAddress())); - } -} diff --git a/libs/editor/widgets/bssidcombobox.h b/libs/editor/widgets/bssidcombobox.h deleted file mode 100644 index 40ba4187..00000000 --- a/libs/editor/widgets/bssidcombobox.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - 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 . -*/ - -#ifndef PLASMA_NM_BSSIDCOMBOBOX_H -#define PLASMA_NM_BSSIDCOMBOBOX_H - -#include - -#include -#include - -class Q_DECL_EXPORT BssidComboBox : public QComboBox -{ - Q_OBJECT -public: - explicit BssidComboBox(QWidget *parent = nullptr); - - QString bssid() const; - bool isValid() const; - -Q_SIGNALS: - void bssidChanged(); - -public Q_SLOTS: - void init(const QString & bssid, const QString &ssid); - -private Q_SLOTS: - void slotEditTextChanged(const QString &); - void slotCurrentIndexChanged(int); - -private: - void addBssidsToCombo(const QList & aps); - - QString m_initialBssid; - bool m_dirty; -}; - -#endif // PLASMA_NM_BSSIDCOMBOBOX_H diff --git a/libs/editor/widgets/delegate.cpp b/libs/editor/widgets/delegate.cpp deleted file mode 100644 index b92ae2b5..00000000 --- a/libs/editor/widgets/delegate.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "delegate.h" - -#include -#include -#include - - -Delegate::Delegate(QObject * parent) : QStyledItemDelegate(parent) {} -Delegate::~Delegate() {} - -QWidget * Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const -{ - QLineEdit *editor = new QLineEdit(parent); - - return editor; -} - -void Delegate::setEditorData(QWidget *editor, const QModelIndex &index) const -{ - QString value = index.model()->data(index, Qt::EditRole).toString(); - - QLineEdit *le = static_cast(editor); - le->setText(value); -} - -void Delegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const -{ - QLineEdit *le = static_cast(editor); - - model->setData(index, le->text(), Qt::EditRole); -} - -void Delegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const -{ - editor->setGeometry(option.rect); -} diff --git a/libs/editor/widgets/delegate.h b/libs/editor/widgets/delegate.h deleted file mode 100644 index f5628a5e..00000000 --- a/libs/editor/widgets/delegate.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#ifndef DELEGATE_H -#define DELEGATE_H - -#include -#include - -class Delegate : public QStyledItemDelegate -{ - Q_OBJECT -public: - explicit Delegate(QObject * parent = nullptr); - ~Delegate() override; - - QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const override; - void setEditorData(QWidget *editor, const QModelIndex &index) const override; - - void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const override; - - void updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, const QModelIndex &index) const override; -}; - -#endif diff --git a/libs/editor/widgets/editlistdialog.cpp b/libs/editor/widgets/editlistdialog.cpp deleted file mode 100644 index 02320820..00000000 --- a/libs/editor/widgets/editlistdialog.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright 2009 Andrey Batyiev - Copyright 2015 Jan Grulich - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "editlistdialog.h" - -#include -#include - -#include -#include - - -EditListDialog::EditListDialog(QWidget *parent) - : QDialog(parent) -{ - editListWidget = new KEditListWidget(this); - editListWidget->setCheckAtEntering(true); - - QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, this); - connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); - connect(buttons, &QDialogButtonBox::accepted, this, &EditListDialog::dialogAccepted); - connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); - - setLayout(new QVBoxLayout); - layout()->addWidget(editListWidget); - layout()->addWidget(buttons); -} - -EditListDialog::~EditListDialog() -{ -} - -void EditListDialog::setItems(const QStringList &items) -{ - editListWidget->setItems(items); -} - -QStringList EditListDialog::items() const -{ - return editListWidget->items(); -} - -void EditListDialog::removeEmptyItems(QStringList &list) -{ - QStringList::iterator it = list.begin(); - const QStringList::iterator end = list.end(); - while (it != end) { - if ((*it).trimmed().isEmpty()) { - it = list.erase(it); - } else { - it++; - } - } -} - -void EditListDialog::dialogAccepted() -{ - QStringList list = items(); - removeEmptyItems(list); - Q_EMIT itemsEdited(list); -} - -void EditListDialog::setValidator(const QValidator *validator) -{ - editListWidget->lineEdit()->setValidator(validator); -} - -const QValidator * EditListDialog::validator() const -{ - return editListWidget->lineEdit()->validator(); -} - -void EditListDialog::setToolTip(const QString toolTip) -{ - editListWidget->lineEdit()->setToolTip(toolTip); -} diff --git a/libs/editor/widgets/editlistdialog.h b/libs/editor/widgets/editlistdialog.h deleted file mode 100644 index 37629db0..00000000 --- a/libs/editor/widgets/editlistdialog.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - Copyright 2009 Andrey Batyiev - Copyright 2015 Jan Grulich - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef PLASMA_NM_EDIT_LIST_DIALOG_H -#define PLASMA_NM_EDIT_LIST_DIALOG_H - -#include -#include - -class QValidator; - -class EditListDialog : public QDialog -{ -Q_OBJECT -public: - explicit EditListDialog(QWidget *parent = nullptr); - ~EditListDialog() override; - - void setItems(const QStringList &items); - QStringList items() const; - - void setValidator(const QValidator *validator); - const QValidator *validator() const; - - void setToolTip(const QString toolTip); - -Q_SIGNALS: - void itemsEdited(const QStringList &items); - -protected Q_SLOTS: - void dialogAccepted(); - -private: - KEditListWidget *editListWidget; - - void removeEmptyItems(QStringList &list); -}; - -#endif // PLASMA_NM_EDIT_LIST_DIALOG_H - diff --git a/libs/editor/widgets/hwaddrcombobox.cpp b/libs/editor/widgets/hwaddrcombobox.cpp deleted file mode 100644 index f27f6c83..00000000 --- a/libs/editor/widgets/hwaddrcombobox.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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 "hwaddrcombobox.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -HwAddrComboBox::HwAddrComboBox(QWidget *parent) : - QComboBox(parent), m_dirty(false) -{ - setEditable(true); - setInsertPolicy(QComboBox::NoInsert); - - connect(this, &HwAddrComboBox::editTextChanged, this, &HwAddrComboBox::slotEditTextChanged); - connect(this, QOverload::of(&HwAddrComboBox::currentIndexChanged), this, &HwAddrComboBox::slotCurrentIndexChanged); -} - -bool HwAddrComboBox::isValid() const -{ - if (hwAddress().isEmpty()) { - return true; - } - - return NetworkManager::macAddressIsValid(hwAddress()); -} - -QString HwAddrComboBox::hwAddress() const -{ - QString result; - if (!m_dirty) - result = itemData(currentIndex()).toString(); - else - result = currentText(); - - // qCDebug(PLASMA_NM)() << "Result:" << currentIndex() << result; - - return result; -} - -void HwAddrComboBox::slotEditTextChanged(const QString &) -{ - m_dirty = true; - Q_EMIT hwAddressChanged(); -} - -void HwAddrComboBox::slotCurrentIndexChanged(int) -{ - m_dirty = false; - Q_EMIT hwAddressChanged(); -} - -void HwAddrComboBox::init(const NetworkManager::Device::Type &deviceType, const QString &address) -{ - m_initialAddress = address; - - // qCDebug(PLASMA_NM) << "Initial address:" << m_initialAddress; - - QString deviceName; - for (const NetworkManager::Device::Ptr &device : NetworkManager::networkInterfaces()) { - const NetworkManager::Device::Type type = device->type(); - if (type == deviceType) { - if (address == hwAddressFromDevice(device).toString()) { - if (device->state() == NetworkManager::Device::Activated) { - deviceName = device->ipInterfaceName(); - } else { - deviceName = device->interfaceName(); - } - } - addAddressToCombo(device); - } - } - - const int index = findData(m_initialAddress); - if (index == -1) { - if (!m_initialAddress.isEmpty()) { - const QString text = QStringLiteral("%1 (%2)").arg(deviceName).arg(m_initialAddress); - insertItem(0, text, m_initialAddress); - } else { - insertItem(0, m_initialAddress, m_initialAddress); - } - setCurrentIndex(0); - } else { - setCurrentIndex(index); - } -} - -void HwAddrComboBox::addAddressToCombo(const NetworkManager::Device::Ptr &device) -{ - const QVariant data = hwAddressFromDevice(device); - // qCDebug(PLASMA_NM) << "Data:" << data; - - QString name; - if (device->state() == NetworkManager::Device::Activated) - name = device->ipInterfaceName(); - else - name = device->interfaceName(); - - // qCDebug(PLASMA_NM) << "Name:" << name; - - if (!data.isNull()) { - if (name == data.toString()) { - addItem(data.toString(), data); - } - else { - addItem(QStringLiteral("%1 (%2)").arg(name).arg(data.toString()), data); - } - } -} - - -QVariant HwAddrComboBox::hwAddressFromDevice(const NetworkManager::Device::Ptr& device) -{ - const NetworkManager::Device::Type type = device->type(); - - QVariant data; - if (type == NetworkManager::Device::Ethernet) { - data = device->as()->permanentHardwareAddress(); - } else if (type == NetworkManager::Device::Wifi) { - data = device->as()->permanentHardwareAddress(); - } else if (type == NetworkManager::Device::Bluetooth) { - data = device->as()->hardwareAddress(); - } else if (type == NetworkManager::Device::OlpcMesh) { - data = device->as()->hardwareAddress(); - } else if (type == NetworkManager::Device::InfiniBand) { - data = device->as()->hwAddress(); - } else if (type == NetworkManager::Device::Bond) { - data = device->as()->hwAddress(); - } else if (type == NetworkManager::Device::Bridge) { - data = device->as()->hwAddress(); - } else if (type == NetworkManager::Device::Vlan) { - data = device->as()->hwAddress(); - } - - return data; -} diff --git a/libs/editor/widgets/hwaddrcombobox.h b/libs/editor/widgets/hwaddrcombobox.h deleted file mode 100644 index 2aef3938..00000000 --- a/libs/editor/widgets/hwaddrcombobox.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - - 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_HWADDRCOMBOBOX_H -#define PLASMA_NM_HWADDRCOMBOBOX_H - -#include - -#include - -class Q_DECL_EXPORT HwAddrComboBox : public QComboBox -{ - Q_OBJECT -public: - explicit HwAddrComboBox(QWidget *parent = nullptr); - - void init(const NetworkManager::Device::Type &deviceType, const QString &address); - - bool isValid() const; - QString hwAddress() const; - -Q_SIGNALS: - void hwAddressChanged(); - -private Q_SLOTS: - void slotEditTextChanged(const QString &); - void slotCurrentIndexChanged(int); - -private: - void addAddressToCombo(const NetworkManager::Device::Ptr &device); - QVariant hwAddressFromDevice(const NetworkManager::Device::Ptr &device); - QString m_initialAddress; - bool m_dirty; -}; - -#endif // PLASMA_NM_HWADDRCOMBOBOX_H diff --git a/libs/editor/widgets/intdelegate.cpp b/libs/editor/widgets/intdelegate.cpp deleted file mode 100644 index 4a92c8cb..00000000 --- a/libs/editor/widgets/intdelegate.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "intdelegate.h" -#include - -#include - -IntDelegate::IntDelegate(QObject * parent) : Delegate(parent), m_boundary(false) {} -IntDelegate::IntDelegate(int min, int max, QObject * parent) : Delegate(parent), m_min(min), m_max(max), m_boundary(true) {} -IntDelegate::~IntDelegate() {} - -QWidget * IntDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const -{ - QLineEdit *editor = new QLineEdit(parent); - if (m_boundary) - editor->setValidator(new QIntValidator(m_min, m_max, editor)); - else - editor->setValidator(new QIntValidator(editor)); - - return editor; -} diff --git a/libs/editor/widgets/intdelegate.h b/libs/editor/widgets/intdelegate.h deleted file mode 100644 index 345bb1dc..00000000 --- a/libs/editor/widgets/intdelegate.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#ifndef INTDELEGATE_H -#define INTDELEGATE_H - -#include -#include -#include - -#include "delegate.h" - -class IntDelegate : public Delegate -{ - Q_OBJECT -public: - explicit IntDelegate(QObject * parent = nullptr); - IntDelegate(int min, int max, QObject * parent = nullptr); - ~IntDelegate() override; - - QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - -private: - int m_min; - int m_max; - bool m_boundary; -}; - -#endif diff --git a/libs/editor/widgets/ipv4delegate.cpp b/libs/editor/widgets/ipv4delegate.cpp deleted file mode 100644 index 8b47e8a8..00000000 --- a/libs/editor/widgets/ipv4delegate.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "ipv4delegate.h" - -#include - -#include "simpleipv4addressvalidator.h" - -IpV4Delegate::IpV4Delegate(QObject * parent) : Delegate(parent) {} -IpV4Delegate::~IpV4Delegate() {} - -QWidget * IpV4Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const -{ - QLineEdit *editor = new QLineEdit(parent); - editor->setValidator(new SimpleIpV4AddressValidator(SimpleIpV4AddressValidator::Base, editor)); - - return editor; -} diff --git a/libs/editor/widgets/ipv4delegate.h b/libs/editor/widgets/ipv4delegate.h deleted file mode 100644 index c73d54aa..00000000 --- a/libs/editor/widgets/ipv4delegate.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#ifndef IPV4DELEGATE_H -#define IPV4DELEGATE_H - -#include -#include "delegate.h" - -class IpV4Delegate : public Delegate -{ - Q_OBJECT -public: - explicit IpV4Delegate(QObject * parent = nullptr); - ~IpV4Delegate() override; - - QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; -}; - -#endif diff --git a/libs/editor/widgets/ipv4routeswidget.cpp b/libs/editor/widgets/ipv4routeswidget.cpp deleted file mode 100644 index 85dc890e..00000000 --- a/libs/editor/widgets/ipv4routeswidget.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include -#include -#include - -#include -#include - -#include "ui_ipv4routes.h" -#include "ipv4routeswidget.h" -#include "ipv4delegate.h" -#include "intdelegate.h" - -class IpV4RoutesWidget::Private -{ -public: - Private() : model(0,4) - { - QStandardItem * headerItem = new QStandardItem(i18nc("Header text for IPv4 address", "Address")); - model.setHorizontalHeaderItem(0, headerItem); - headerItem = new QStandardItem(i18nc("Header text for IPv4 netmask", "Netmask")); - model.setHorizontalHeaderItem(1, headerItem); - headerItem = new QStandardItem(i18nc("Header text for IPv4 gateway", "Gateway")); - model.setHorizontalHeaderItem(2, headerItem); - headerItem = new QStandardItem(i18nc("Header text for IPv4 route metric", "Metric")); - model.setHorizontalHeaderItem(3, headerItem); - } - Ui_RoutesIp4Config ui; - QStandardItemModel model; -}; - -IpV4RoutesWidget::IpV4RoutesWidget(QWidget * parent) - : QDialog(parent), d(new IpV4RoutesWidget::Private()) -{ - d->ui.setupUi(this); - d->ui.tableViewAddresses->setModel(&d->model); - d->ui.tableViewAddresses->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); - - IpV4Delegate *ipDelegate = new IpV4Delegate(this); - IntDelegate *metricDelegate = new IntDelegate(this); - d->ui.tableViewAddresses->setItemDelegateForColumn(0, ipDelegate); - d->ui.tableViewAddresses->setItemDelegateForColumn(1, ipDelegate); - d->ui.tableViewAddresses->setItemDelegateForColumn(2, ipDelegate); - d->ui.tableViewAddresses->setItemDelegateForColumn(3, metricDelegate); - - connect(d->ui.pushButtonAdd, &QPushButton::clicked, this, &IpV4RoutesWidget::addRoute); - connect(d->ui.pushButtonRemove, &QPushButton::clicked, this, &IpV4RoutesWidget::removeRoute); - - connect(d->ui.tableViewAddresses->selectionModel(), &QItemSelectionModel::selectionChanged, this, &IpV4RoutesWidget::selectionChanged); - - connect(&d->model, &QStandardItemModel::itemChanged, this, &IpV4RoutesWidget::tableViewItemChanged); - - connect(d->ui.buttonBox, &QDialogButtonBox::accepted, this, &IpV4RoutesWidget::accept); - connect(d->ui.buttonBox, &QDialogButtonBox::rejected, this, &IpV4RoutesWidget::reject); - - KAcceleratorManager::manage(this); -} - -IpV4RoutesWidget::~IpV4RoutesWidget() -{ - delete d; -} - -void IpV4RoutesWidget::setNeverDefault(bool checked) -{ - d->ui.cbNeverDefault->setChecked(checked); -} - -bool IpV4RoutesWidget::neverDefault() const -{ - return d->ui.cbNeverDefault->isChecked(); -} - -void IpV4RoutesWidget::setIgnoreAutoRoutes(bool checked) -{ - d->ui.cbIgnoreAutoRoutes->setChecked(checked); -} - -void IpV4RoutesWidget::setIgnoreAutoRoutesCheckboxEnabled(bool enabled) -{ - d->ui.cbIgnoreAutoRoutes->setEnabled(enabled); -} - -bool IpV4RoutesWidget::ignoreautoroutes() const -{ - return d->ui.cbIgnoreAutoRoutes->isChecked(); -} - -void IpV4RoutesWidget::setRoutes(const QList &list) -{ - d->model.removeRows(0, d->model.rowCount()); - for (const NetworkManager::IpRoute &route : list) { - QList item; - - // qCDebug(PLASMA_NM) << route.ip(); - item << new QStandardItem(route.ip().toString()) - << new QStandardItem(route.netmask().toString()) - << new QStandardItem(route.nextHop().toString()) - << new QStandardItem(QString::number(route.metric(), 10)); - - d->model.appendRow(item); - } -} - -QList IpV4RoutesWidget::routes() -{ - QList list; - - for (int i = 0, rowCount = d->model.rowCount(); i < rowCount; i++) { - NetworkManager::IpRoute route; - QStandardItem *item = d->model.item(i,0); - if (item) { - route.setIp(QHostAddress(item->text())); - } - item = d->model.item(i, 1); - if (item) { - route.setNetmask(QHostAddress(item->text())); - } - item = d->model.item(i, 2); - if (item) { - route.setNextHop(QHostAddress(item->text())); - } - item = d->model.item(i, 3); - if (item) { - route.setMetric(item->text().toUInt()); - } - - list << route; - } - return list; -} - -void IpV4RoutesWidget::addRoute() -{ - QList item; - item << new QStandardItem << new QStandardItem << new QStandardItem; - d->model.appendRow(item); - - const int rowCount = d->model.rowCount(); - if (rowCount > 0) { - d->ui.tableViewAddresses->selectRow(rowCount - 1); - - QItemSelectionModel * selectionModel = d->ui.tableViewAddresses->selectionModel(); - QModelIndexList list = selectionModel->selectedIndexes(); - if (list.size()) { - // QTableView is configured to select only rows. - // So, list[0] - IP address. - d->ui.tableViewAddresses->edit(list[0]); - } - } -} - -void IpV4RoutesWidget::removeRoute() -{ - QItemSelectionModel * selectionModel = d->ui.tableViewAddresses->selectionModel(); - if (selectionModel->hasSelection()) { - QModelIndexList indexes = selectionModel->selectedIndexes(); - d->model.takeRow(indexes[0].row()); - } - d->ui.pushButtonRemove->setEnabled(d->ui.tableViewAddresses->selectionModel()->hasSelection()); -} - -void IpV4RoutesWidget::selectionChanged(const QItemSelection & selected) -{ - // qCDebug(PLASMA_NM) << "selectionChanged"; - d->ui.pushButtonRemove->setEnabled(!selected.isEmpty()); -} - -extern quint32 suggestNetmask(quint32 ip); - -void IpV4RoutesWidget::tableViewItemChanged(QStandardItem *item) -{ - if (item->text().isEmpty()) { - return; - } - - const int column = item->column(); - if (column == 0) { // ip - int row = item->row(); - - QStandardItem *netmaskItem = d->model.item(row, column + 1); // netmask - if (netmaskItem && netmaskItem->text().isEmpty()) { - QHostAddress addr(item->text()); - quint32 netmask = suggestNetmask(addr.toIPv4Address()); - if (netmask) { - QHostAddress v(netmask); - netmaskItem->setText(v.toString()); - } - } - } -} diff --git a/libs/editor/widgets/ipv4routeswidget.h b/libs/editor/widgets/ipv4routeswidget.h deleted file mode 100644 index 272390bd..00000000 --- a/libs/editor/widgets/ipv4routeswidget.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#ifndef IPV4ROUTESWIDGET_H -#define IPV4ROUTESWIDGET_H - -#include -#include - -#include - -class QStandardItem; -class QItemSelection; - -class IpV4RoutesWidget : public QDialog -{ - Q_OBJECT -public: - explicit IpV4RoutesWidget(QWidget * parent = nullptr); - ~IpV4RoutesWidget() override; - - void setRoutes(const QList &list); - QList routes(); - void setNeverDefault(bool checked); - bool neverDefault() const; - void setIgnoreAutoRoutes(bool checked); - void setIgnoreAutoRoutesCheckboxEnabled(bool enabled); - bool ignoreautoroutes() const; - -private Q_SLOTS: - void addRoute(); - void removeRoute(); - /** - * Update remove IP button depending on if there is a selection - */ - void selectionChanged(const QItemSelection &); - void tableViewItemChanged(QStandardItem *); - -private: - class Private; - Private *d; -}; - -#endif // IPV4ROUTESWIDGET_H diff --git a/libs/editor/widgets/ipv6delegate.cpp b/libs/editor/widgets/ipv6delegate.cpp deleted file mode 100644 index 89064eed..00000000 --- a/libs/editor/widgets/ipv6delegate.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "ipv6delegate.h" - -#include - -#include "simpleipv6addressvalidator.h" - -IpV6Delegate::IpV6Delegate(QObject * parent) : Delegate(parent) {} -IpV6Delegate::~IpV6Delegate() {} - -QWidget * IpV6Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const -{ - QLineEdit *editor = new QLineEdit(parent); - editor->setValidator(new SimpleIpV6AddressValidator(SimpleIpV6AddressValidator::Base, editor)); - - return editor; -} diff --git a/libs/editor/widgets/ipv6delegate.h b/libs/editor/widgets/ipv6delegate.h deleted file mode 100644 index eb01d261..00000000 --- a/libs/editor/widgets/ipv6delegate.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#ifndef IPV6DELEGATE_H -#define IPV6DELEGATE_H - -#include -#include - -#include "delegate.h" - -class IpV6Delegate : public Delegate -{ - Q_OBJECT -public: - explicit IpV6Delegate(QObject * parent = nullptr); - ~IpV6Delegate() override; - - QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; -}; - -#endif diff --git a/libs/editor/widgets/ipv6routeswidget.cpp b/libs/editor/widgets/ipv6routeswidget.cpp deleted file mode 100644 index 3c21ffa6..00000000 --- a/libs/editor/widgets/ipv6routeswidget.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include -#include -#include - -#include -#include - -#include "ui_ipv6routes.h" - -#include "ipv6delegate.h" -#include "intdelegate.h" -#include "ipv6routeswidget.h" - -class IpV6RoutesWidget::Private -{ -public: - Private() : model(0,4) - { - QStandardItem * headerItem = new QStandardItem(i18nc("Header text for IPv6 address", "Address")); - model.setHorizontalHeaderItem(0, headerItem); - headerItem = new QStandardItem(i18nc("Header text for IPv6 netmask", "Netmask")); - model.setHorizontalHeaderItem(1, headerItem); - headerItem = new QStandardItem(i18nc("Header text for IPv6 gateway", "Gateway")); - model.setHorizontalHeaderItem(2, headerItem); - headerItem = new QStandardItem(i18nc("Header text for IPv6 route metric", "Metric")); - model.setHorizontalHeaderItem(3, headerItem); - } - Ui_RoutesIp6Config ui; - QStandardItemModel model; -}; - -IpV6RoutesWidget::IpV6RoutesWidget(QWidget * parent) - : QDialog(parent), d(new IpV6RoutesWidget::Private()) -{ - d->ui.setupUi(this); - d->ui.tableViewAddresses->setModel(&d->model); - d->ui.tableViewAddresses->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); - - IpV6Delegate *ipDelegate = new IpV6Delegate(this); - IntDelegate *netmaskDelegate = new IntDelegate(0,128,this); - IntDelegate *metricDelegate = new IntDelegate(this); - d->ui.tableViewAddresses->setItemDelegateForColumn(0, ipDelegate); - d->ui.tableViewAddresses->setItemDelegateForColumn(1, netmaskDelegate); - d->ui.tableViewAddresses->setItemDelegateForColumn(2, ipDelegate); - d->ui.tableViewAddresses->setItemDelegateForColumn(3, metricDelegate); - - connect(d->ui.pushButtonAdd, &QPushButton::clicked, this, &IpV6RoutesWidget::addRoute); - connect(d->ui.pushButtonRemove, &QPushButton::clicked, this, &IpV6RoutesWidget::removeRoute); - - connect(d->ui.tableViewAddresses->selectionModel(), &QItemSelectionModel::selectionChanged, this, &IpV6RoutesWidget::selectionChanged); - - - connect(&d->model, &QStandardItemModel::itemChanged, this, &IpV6RoutesWidget::tableViewItemChanged); - - connect(d->ui.buttonBox, &QDialogButtonBox::accepted, this, &IpV6RoutesWidget::accept); - connect(d->ui.buttonBox, &QDialogButtonBox::rejected, this, &IpV6RoutesWidget::reject); - - KAcceleratorManager::manage(this); -} - -IpV6RoutesWidget::~IpV6RoutesWidget() -{ - delete d; -} - -void IpV6RoutesWidget::setNeverDefault(bool checked) -{ - d->ui.cbNeverDefault->setChecked(checked); -} - -bool IpV6RoutesWidget::neverDefault() const -{ - return d->ui.cbNeverDefault->isChecked(); -} - -void IpV6RoutesWidget::setIgnoreAutoRoutes(bool checked) -{ - d->ui.cbIgnoreAutoRoutes->setChecked(checked); -} - -void IpV6RoutesWidget::setIgnoreAutoRoutesCheckboxEnabled(bool enabled) -{ - d->ui.cbIgnoreAutoRoutes->setEnabled(enabled); -} - -bool IpV6RoutesWidget::ignoreautoroutes() const -{ - return d->ui.cbIgnoreAutoRoutes->isChecked(); -} - -void IpV6RoutesWidget::setRoutes(const QList &list) -{ - d->model.removeRows(0, d->model.rowCount()); - for (const NetworkManager::IpRoute &route : list) { - QList item; - // qCDebug(PLASMA_NM) << route.ip(); - item << new QStandardItem(route.ip().toString()) - << new QStandardItem(QString::number(route.prefixLength(), 10)) - << new QStandardItem(route.nextHop().toString()) - << new QStandardItem(QString::number(route.metric(), 10)); - - d->model.appendRow(item); - } -} - -QList IpV6RoutesWidget::routes() -{ - QList list; - - for (int i = 0, rowCount = d->model.rowCount(); i < rowCount; i++) { - NetworkManager::IpRoute route; - QStandardItem *item = d->model.item(i,0); - if (item) { - route.setIp(QHostAddress(item->text())); - } - item = d->model.item(i, 2); - if (item) { - route.setNextHop(QHostAddress(item->text())); - } - item = d->model.item(i, 1); - if (item) { - route.setPrefixLength(item->text().toInt()); - } - item = d->model.item(i, 3); - if (item) { - route.setMetric(item->text().toUInt()); - } - - list << route; - } - return list; -} - -void IpV6RoutesWidget::addRoute() -{ - QList item; - item << new QStandardItem << new QStandardItem << new QStandardItem; - d->model.appendRow(item); - - const int rowCount = d->model.rowCount(); - if (rowCount > 0) { - d->ui.tableViewAddresses->selectRow(rowCount - 1); - - QItemSelectionModel * selectionModel = d->ui.tableViewAddresses->selectionModel(); - QModelIndexList list = selectionModel->selectedIndexes(); - if (list.size()) { - // QTableView is configured to select only rows. - // So, list[0] - IP address. - d->ui.tableViewAddresses->edit(list[0]); - } - } -} - -void IpV6RoutesWidget::removeRoute() -{ - QItemSelectionModel * selectionModel = d->ui.tableViewAddresses->selectionModel(); - if (selectionModel->hasSelection()) { - QModelIndexList indexes = selectionModel->selectedIndexes(); - d->model.takeRow(indexes[0].row()); - } - d->ui.pushButtonRemove->setEnabled(false); -} - -void IpV6RoutesWidget::selectionChanged(const QItemSelection & selected) -{ - // qCDebug(PLASMA_NM) << "selectionChanged"; - d->ui.pushButtonRemove->setEnabled(!selected.isEmpty()); -} - -extern quint32 suggestNetmask(Q_IPV6ADDR ip); - -void IpV6RoutesWidget::tableViewItemChanged(QStandardItem *item) -{ - if (item->text().isEmpty()) { - return; - } - - const int column = item->column(); - if (column == 0) { // ip - int row = item->row(); - - QStandardItem *netmaskItem = d->model.item(row, column + 1); // netmask - if (netmaskItem && netmaskItem->text().isEmpty()) { - QHostAddress addr(item->text()); - quint32 netmask = suggestNetmask(addr.toIPv6Address()); - if (netmask) { - netmaskItem->setText(QString::number(netmask,10)); - } - } - } -} diff --git a/libs/editor/widgets/ipv6routeswidget.h b/libs/editor/widgets/ipv6routeswidget.h deleted file mode 100644 index 79d75cec..00000000 --- a/libs/editor/widgets/ipv6routeswidget.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2011 Ilia Kats - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 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 14 of version 3 of the license. - -This program 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 General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#ifndef IPV6ROUTESWIDGET_H -#define IPV6ROUTESWIDGET_H - -#include -#include - -#include - -class QStandardItem; -class QItemSelection; - -class IpV6RoutesWidget : public QDialog -{ - Q_OBJECT -public: - explicit IpV6RoutesWidget(QWidget * parent = nullptr); - ~IpV6RoutesWidget() override; - - void setRoutes(const QList &list); - QList routes(); - void setNeverDefault(bool checked); - bool neverDefault() const; - void setIgnoreAutoRoutes(bool checked); - void setIgnoreAutoRoutesCheckboxEnabled(bool enabled); - bool ignoreautoroutes() const; - -private Q_SLOTS: - void addRoute(); - void removeRoute(); - /** - * Update remove IP button depending on if there is a selection - */ - void selectionChanged(const QItemSelection &); - void tableViewItemChanged(QStandardItem *); - -private: - class Private; - Private *d; -}; - -#endif // IPV6ROUTESWIDGET_H diff --git a/libs/editor/widgets/settingwidget.cpp b/libs/editor/widgets/settingwidget.cpp index 8391a881..21cac51c 100644 --- a/libs/editor/widgets/settingwidget.cpp +++ b/libs/editor/widgets/settingwidget.cpp @@ -1,149 +1,146 @@ /* 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 "settingwidget.h" -#include "bssidcombobox.h" -#include "hwaddrcombobox.h" -#include "ssidcombobox.h" #include "passwordfield.h" #include #include #include #include #include #include #include #include SettingWidget::SettingWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f): QWidget(parent, f), m_type(setting->name()) { } SettingWidget::~SettingWidget() { } void SettingWidget::loadConfig(const NetworkManager::Setting::Ptr &setting) { Q_UNUSED(setting); } void SettingWidget::loadSecrets(const NetworkManager::Setting::Ptr &setting) { Q_UNUSED(setting); } void SettingWidget::watchChangedSetting() { // Attempt to connect to all widgets representing various configurations // to notify about setting change /************ Qt Widgets ************/ // Connect all QLineEdit widgets QList lineEdits = findChildren(); for (QLineEdit *lineedit : lineEdits) { connect(lineedit, &QLineEdit::textChanged, this, &SettingWidget::settingChanged); } // Connect all QComboBox widgets QList comboboxes = findChildren(); for (QComboBox *combobox : comboboxes) { connect(combobox, QOverload::of(&QComboBox::currentIndexChanged), this, &SettingWidget::settingChanged); connect(combobox, &QComboBox::currentTextChanged, this, &SettingWidget::settingChanged); } // Connect all QCheckBox widgets QList checkboxes = findChildren(); for (QCheckBox *checkbox : checkboxes) { connect(checkbox, &QCheckBox::stateChanged, this, &SettingWidget::settingChanged); } // Connect all QPushButton widgets QList pushbuttons = findChildren(); for (QPushButton *pushbutton : pushbuttons) { connect(pushbutton, &QPushButton::clicked, this, &SettingWidget::settingChanged); } // Connect all QSpinBox widgets QList spinboxes = findChildren(); for (QSpinBox *spinbox : spinboxes) { connect(spinbox, QOverload::of(&QSpinBox::valueChanged), this, &SettingWidget::settingChanged); } // Connect all KUrlRequester widgets QList urlrequesters = findChildren(); for (KUrlRequester *urlrequester : urlrequesters) { connect(urlrequester, &KUrlRequester::textChanged, this, &SettingWidget::settingChanged); connect(urlrequester, &KUrlRequester::urlSelected, this, &SettingWidget::settingChanged); } // Connect all QTableView widgets QList tableviews = findChildren(); for(QTableView *tableview : tableviews) { connect(tableview, &QTableView::clicked, this, &SettingWidget::settingChanged); } // Connect all QGroupBox widgets QList groupBoxes = findChildren(); for (QGroupBox *box : groupBoxes) { connect(box, &QGroupBox::toggled, this, &SettingWidget::settingChanged); } /********** OUR CUSTOM WIDGETS **********/ // Connect all PasswordField widgets QList passwordfields = findChildren(); for (PasswordField *passwordfield : passwordfields) { connect(passwordfield, &PasswordField::textChanged, this, &SettingWidget::settingChanged); connect(passwordfield, &PasswordField::passwordOptionChanged, this, &SettingWidget::settingChanged); } // Connect all HwAddrComboBox widgets - QList hwAddrcomboboxes = findChildren(); - for (HwAddrComboBox *combobox : hwAddrcomboboxes) { - connect(combobox, &HwAddrComboBox::hwAddressChanged, this, &SettingWidget::settingChanged); - } - - // Connect all SssidComboBox widgets - QList ssidcomboboxes = findChildren(); - for (SsidComboBox *combobox : ssidcomboboxes) { - connect(combobox, &SsidComboBox::ssidChanged, this, &SettingWidget::settingChanged); - } - - // Connect all BssidComboBox widgets - QList bssidcomboboxes = findChildren(); - for (BssidComboBox *combobox : bssidcomboboxes) { - connect(combobox, &BssidComboBox::bssidChanged, this, &SettingWidget::settingChanged); - } +// QList hwAddrcomboboxes = findChildren(); +// for (HwAddrComboBox *combobox : hwAddrcomboboxes) { +// connect(combobox, &HwAddrComboBox::hwAddressChanged, this, &SettingWidget::settingChanged); +// } +// +// // Connect all SssidComboBox widgets +// QList ssidcomboboxes = findChildren(); +// for (SsidComboBox *combobox : ssidcomboboxes) { +// connect(combobox, &SsidComboBox::ssidChanged, this, &SettingWidget::settingChanged); +// } +// +// // Connect all BssidComboBox widgets +// QList bssidcomboboxes = findChildren(); +// for (BssidComboBox *combobox : bssidcomboboxes) { +// connect(combobox, &BssidComboBox::bssidChanged, this, &SettingWidget::settingChanged); +// } } QString SettingWidget::type() const { return m_type; } void SettingWidget::slotWidgetChanged() { Q_EMIT validChanged(isValid()); } diff --git a/libs/editor/widgets/ssidcombobox.cpp b/libs/editor/widgets/ssidcombobox.cpp deleted file mode 100644 index 64fd2320..00000000 --- a/libs/editor/widgets/ssidcombobox.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - 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 "ssidcombobox.h" -#include "uiutils.h" - -#include -#include - -#include - -bool signalCompare(const NetworkManager::WirelessNetwork::Ptr & one, const NetworkManager::WirelessNetwork::Ptr & two) -{ - return one->signalStrength() > two->signalStrength(); -} - -SsidComboBox::SsidComboBox(QWidget *parent) : - KComboBox(parent) -{ - setEditable(true); - setInsertPolicy(QComboBox::NoInsert); - - connect(this, &SsidComboBox::editTextChanged, this, &SsidComboBox::slotEditTextChanged); - connect(this, QOverload::of(&SsidComboBox::activated), this, &SsidComboBox::slotCurrentIndexChanged); -} - -QString SsidComboBox::ssid() const -{ - if (currentIndex() == 0 || currentText() != itemData(currentIndex()).toString()) { - return currentText(); - } else { - return itemData(currentIndex()).toString(); - } -} - -void SsidComboBox::slotEditTextChanged(const QString &text) -{ - if (!text.contains(QLatin1String("Security:")) && !text.contains(QLatin1String("Frequency:"))) { - Q_EMIT ssidChanged(); - } -} - -void SsidComboBox::slotCurrentIndexChanged(int) -{ - setEditText(itemData(currentIndex()).toString()); -} - -void SsidComboBox::init(const QString &ssid) -{ - m_initialSsid = ssid; - - // qCDebug(PLASMA_NM) << "Initial ssid:" << m_initialSsid; - - QList networks; - - for (const NetworkManager::Device::Ptr &device : NetworkManager::networkInterfaces()) { - if (device->type() == NetworkManager::Device::Wifi) { - NetworkManager::WirelessDevice::Ptr wifiDevice = device.objectCast(); - - for (const NetworkManager::WirelessNetwork::Ptr &newNetwork : wifiDevice->networks()) { - bool found = false; - for (const NetworkManager::WirelessNetwork::Ptr &existingNetwork : networks) { - if (newNetwork->ssid() == existingNetwork->ssid()) { - if (newNetwork->signalStrength() > existingNetwork->signalStrength()) { - networks.removeOne(existingNetwork); - break; - } else { - found = true; - break; - } - } - } - if (!found) { - networks << newNetwork; - } - } - } - } - - std::sort(networks.begin(), networks.end(), signalCompare); - addSsidsToCombo(networks); - - int index = findData(m_initialSsid); - if (index == -1) { - insertItem(0, m_initialSsid, m_initialSsid); - setCurrentIndex(0); - } else { - setCurrentIndex(index); - } - setEditText(m_initialSsid); -} - -void SsidComboBox::addSsidsToCombo(const QList &networks) -{ - QList wifiDevices; - - for (const NetworkManager::Device::Ptr &dev : NetworkManager::networkInterfaces()) { - if (dev->type() == NetworkManager::Device::Wifi) { - wifiDevices << dev.objectCast(); - } - } - - bool empty = true; - - for (const NetworkManager::WirelessNetwork::Ptr &network : networks) { - NetworkManager::AccessPoint::Ptr accessPoint = network->referenceAccessPoint(); - - if (!accessPoint) { - continue; - } - - for (const NetworkManager::WirelessDevice::Ptr &wifiDev : wifiDevices) { - if (wifiDev->findNetwork(network->ssid()) == network) { - if (!empty) { - insertSeparator(count()); - } - empty = false; - - NetworkManager::WirelessSecurityType security = NetworkManager::findBestWirelessSecurity(wifiDev->wirelessCapabilities(), true, (wifiDev->mode() == NetworkManager::WirelessDevice::Adhoc), accessPoint->capabilities(), accessPoint->wpaFlags(), accessPoint->rsnFlags()); - if (security != NetworkManager::UnknownSecurity && security != NetworkManager::NoneSecurity) { - const QString text = i18n("%1 (%2%)\nSecurity: %3\nFrequency: %4 Mhz", accessPoint->ssid(), network->signalStrength(), UiUtils::labelFromWirelessSecurity(security), accessPoint->frequency()); - addItem(QIcon::fromTheme("object-locked"), text, accessPoint->ssid()); - } else { - const QString text = i18n("%1 (%2%)\nSecurity: Insecure\nFrequency: %3 Mhz", accessPoint->ssid(), network->signalStrength(), accessPoint->frequency()); - addItem(QIcon::fromTheme("object-unlocked"), text, accessPoint->ssid()); - } - } - } - } -} diff --git a/libs/editor/widgets/ssidcombobox.h b/libs/editor/widgets/ssidcombobox.h deleted file mode 100644 index d7e9dd97..00000000 --- a/libs/editor/widgets/ssidcombobox.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright 2013 Lukas Tinkl - 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 . -*/ - -#ifndef PLASMA_NM_SSIDCOMBOBOX_H -#define PLASMA_NM_SSIDCOMBOBOX_H - -#include - -#include - -class Q_DECL_EXPORT SsidComboBox : public KComboBox -{ - Q_OBJECT -public: - explicit SsidComboBox(QWidget *parent = nullptr); - - void init(const QString & ssid); - - QString ssid() const; - -Q_SIGNALS: - void ssidChanged(); - -private Q_SLOTS: - void slotEditTextChanged(const QString &text); - void slotCurrentIndexChanged(int); - -private: - void addSsidsToCombo(const QList &networks); - QString m_initialSsid; -}; - -#endif // PLASMA_NM_SSIDCOMBOBOX_H diff --git a/libs/editor/widgets/ui/advancedpermissionswidget.ui b/libs/editor/widgets/ui/advancedpermissionswidget.ui deleted file mode 100644 index 733038bb..00000000 --- a/libs/editor/widgets/ui/advancedpermissionswidget.ui +++ /dev/null @@ -1,271 +0,0 @@ - - - AdvancedPermissions - - - - 0 - 0 - 654 - 349 - - - - - 0 - 0 - - - - - 0 - 0 - - - - - - - - - - - Available Users - - - - - - - - 0 - 0 - - - - - 100 - 80 - - - - QAbstractItemView::NoEditTriggers - - - false - - - true - - - QAbstractItemView::ExtendedSelection - - - false - - - true - - - false - - - true - - - 2 - - - 100 - - - - Real Name - - - - - Username - - - - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - 0 - 0 - - - - - - - - - - - - - - 0 - 0 - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - - - - Users allowed to activate the connection - - - true - - - - - - - - 0 - 0 - - - - - 100 - 80 - - - - QAbstractItemView::NoEditTriggers - - - false - - - true - - - QAbstractItemView::ExtendedSelection - - - false - - - true - - - false - - - true - - - 2 - - - 100 - - - - Real Name - - - - - Username - - - - - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - AdvancedPermissions - accept() - - - 433 - 330 - - - 267 - 0 - - - - - buttonBox - rejected() - AdvancedPermissions - reject() - - - 342 - 329 - - - 299 - -6 - - - - - diff --git a/libs/editor/widgets/ui/ipv4routes.ui b/libs/editor/widgets/ui/ipv4routes.ui deleted file mode 100644 index 182a79f5..00000000 --- a/libs/editor/widgets/ui/ipv4routes.ui +++ /dev/null @@ -1,161 +0,0 @@ - - - RoutesIp4Config - - - - 0 - 0 - 499 - 356 - - - - - 0 - 0 - - - - Edit IPv4 Routes - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 12 - - - - - - - - If enabled, this connection will never be used as the default network connection - - - Use only for resources on this connection - - - - - - - Qt::Horizontal - - - - 119 - 20 - - - - - - - - false - - - - 16777215 - 16777215 - - - - Remove - - - - - - - - - - - - - 0 - 0 - - - - - 150 - 50 - - - - IP addresses identify your computer on the network. Click the "Add" button to add -an IP address - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - true - - - Qt::SolidLine - - - true - - - false - - - - - - - Add - - - - - - - - - - - - If enabled, automatically configured routes are ignored and only routes specified above are used - - - Ignore automatically obtained routes - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - tableViewAddresses - pushButtonAdd - pushButtonRemove - cbIgnoreAutoRoutes - cbNeverDefault - - - - diff --git a/libs/editor/widgets/ui/ipv6routes.ui b/libs/editor/widgets/ui/ipv6routes.ui deleted file mode 100644 index a436a4fe..00000000 --- a/libs/editor/widgets/ui/ipv6routes.ui +++ /dev/null @@ -1,148 +0,0 @@ - - - RoutesIp6Config - - - - 0 - 0 - 470 - 356 - - - - - 0 - 0 - - - - Edit IPv6 Routes - - - - - - - 0 - 0 - - - - - 150 - 50 - - - - IP addresses identify your computer on the network. Click the "Add" button to add -an IP address - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - true - - - Qt::SolidLine - - - true - - - false - - - - - - - Qt::Horizontal - - - - 119 - 20 - - - - - - - - Add - - - - - - - - - - - - false - - - R&emove - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 12 - - - - - - - - If enabled, automatically configured routes are ignored and only routes specified above are used - - - Ignore automatically obtained routes - - - - - - - If enabled, this connection will never be used as the default network connection - - - Use only for resources on this connection - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - diff --git a/libs/handler.cpp b/libs/handler.cpp index 4de2b4b1..58a04d6c 100644 --- a/libs/handler.cpp +++ b/libs/handler.cpp @@ -1,876 +1,876 @@ /* Copyright 2013-2014 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 "handler.h" -#include "connectioneditordialog.h" #include "configuration.h" #include "uiutils.h" #include "debug.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if WITH_MODEMMANAGER_SUPPORT #include #include #endif #include #include #include #include +#include #include #include #include #include #include #include #include #include #define AGENT_SERVICE "org.kde.kded5" #define AGENT_PATH "/modules/networkmanagement" #define AGENT_IFACE "org.kde.plasmanetworkmanagement" // 10 seconds #define NM_REQUESTSCAN_LIMIT_RATE 10000 Handler::Handler(QObject *parent) : QObject(parent) , m_tmpWirelessEnabled(NetworkManager::isWirelessEnabled()) , m_tmpWwanEnabled(NetworkManager::isWwanEnabled()) { QDBusConnection::sessionBus().connect(QStringLiteral(AGENT_SERVICE), QStringLiteral(AGENT_PATH), QStringLiteral(AGENT_IFACE), QStringLiteral("secretsError"), this, SLOT(secretAgentError(QString, QString))); if (!Configuration::hotspotConnectionPath().isEmpty()) { NetworkManager::ActiveConnection::Ptr hotspot = NetworkManager::findActiveConnection(Configuration::hotspotConnectionPath()); if (!hotspot) { Configuration::setHotspotConnectionPath(QString()); } } m_hotspotSupported = checkHotspotSupported(); if (NetworkManager::checkVersion(1, 16, 0)) { connect(NetworkManager::notifier(), &NetworkManager::Notifier::primaryConnectionTypeChanged, this, &Handler::primaryConnectionTypeChanged); } } Handler::~Handler() { } void Handler::activateConnection(const QString& connection, const QString& device, const QString& specificObject) { NetworkManager::Connection::Ptr con = NetworkManager::findConnection(connection); if (!con) { qCWarning(PLASMA_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(); if (vpnSetting) { qCDebug(PLASMA_NM) << "Checking VPN" << con->name() << "type:" << vpnSetting->serviceType(); bool pluginMissing = false; // Check missing plasma-nm VPN plugin const KService::List services = KServiceTypeTrader::self()->query("PlasmaNetworkManagement/VpnUiPlugin", QString::fromLatin1("[X-NetworkManager-Services]=='%1'").arg(vpnSetting->serviceType())); pluginMissing = services.isEmpty(); // Check missing NetworkManager VPN plugin if (!pluginMissing) { GSList *plugins = nullptr; plugins = nm_vpn_plugin_info_list_load(); NMVpnPluginInfo *plugin_info = nm_vpn_plugin_info_list_find_by_service(plugins, vpnSetting->serviceType().toStdString().c_str()); pluginMissing = !plugin_info; } if (pluginMissing) { qCWarning(PLASMA_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->setIconName(QStringLiteral("dialog-warning")); notification->sendEvent(); return; } } } #if WITH_MODEMMANAGER_SUPPORT if (con->settings()->connectionType() == NetworkManager::ConnectionSettings::Gsm) { NetworkManager::ModemDevice::Ptr nmModemDevice = NetworkManager::findNetworkInterface(device).objectCast(); if (nmModemDevice) { ModemManager::ModemDevice::Ptr mmModemDevice = ModemManager::findModemDevice(nmModemDevice->udi()); if (mmModemDevice) { ModemManager::Modem::Ptr modem = mmModemDevice->interface(ModemManager::ModemDevice::ModemInterface).objectCast(); NetworkManager::GsmSetting::Ptr gsmSetting = con->settings()->setting(NetworkManager::Setting::Gsm).staticCast(); 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 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); } QString Handler::wifiCode(const QString& connectionPath, const QString& ssid, int _securityType) const { NetworkManager::WirelessSecurityType securityType = static_cast(_securityType); QString ret = QStringLiteral("WIFI:S:") + ssid + QLatin1Char(';'); if (securityType != NetworkManager::NoneSecurity) { switch (securityType) { case NetworkManager::NoneSecurity: break; case NetworkManager::StaticWep: ret += "T:WEP;"; break; case NetworkManager::WpaPsk: case NetworkManager::Wpa2Psk: ret += "T:WPA;"; break; case NetworkManager::SAE: ret += "T:SAE;"; break; default: case NetworkManager::DynamicWep: case NetworkManager::WpaEap: case NetworkManager::Wpa2Eap: case NetworkManager::Leap: return {}; } } NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(connectionPath); if(!connection) return {}; const auto key = QStringLiteral("802-11-wireless-security"); auto reply = connection->secrets(key); const auto secret = reply.argumentAt<0>()[key]; QString pass; switch (securityType) { case NetworkManager::NoneSecurity: break; case NetworkManager::WpaPsk: case NetworkManager::Wpa2Psk: case NetworkManager::SAE: pass = secret["psk"].toString(); break; default: return {}; } if (!pass.isEmpty()) ret += QStringLiteral("P:") + pass + QLatin1Char(';'); return ret + QLatin1Char(';'); } void Handler::addAndActivateConnection(const QString& device, const QString& specificObject, const QString& password) { NetworkManager::AccessPoint::Ptr ap; NetworkManager::WirelessDevice::Ptr wifiDev; for (const NetworkManager::Device::Ptr &dev : NetworkManager::networkInterfaces()) { if (dev->type() == NetworkManager::Device::Wifi) { wifiDev = dev.objectCast(); ap = wifiDev->findAccessPoint(specificObject); if (ap) { break; } } } if (!ap) { return; } NetworkManager::ConnectionSettings::Ptr settings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wireless)); settings->setId(ap->ssid()); settings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); settings->setAutoconnect(true); settings->addToPermissions(KUser().loginName(), QString()); NetworkManager::WirelessSetting::Ptr wifiSetting = settings->setting(NetworkManager::Setting::Wireless).dynamicCast(); wifiSetting->setInitialized(true); wifiSetting = settings->setting(NetworkManager::Setting::Wireless).dynamicCast(); wifiSetting->setSsid(ap->ssid().toUtf8()); if (ap->mode() == NetworkManager::AccessPoint::Adhoc) { wifiSetting->setMode(NetworkManager::WirelessSetting::Adhoc); } NetworkManager::WirelessSecuritySetting::Ptr wifiSecurity = settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); NetworkManager::WirelessSecurityType securityType = NetworkManager::findBestWirelessSecurity(wifiDev->wirelessCapabilities(), true, (ap->mode() == NetworkManager::AccessPoint::Adhoc), ap->capabilities(), ap->wpaFlags(), ap->rsnFlags()); if (securityType != NetworkManager::NoneSecurity) { wifiSecurity->setInitialized(true); wifiSetting->setSecurity("802-11-wireless-security"); } if (securityType == NetworkManager::Leap || securityType == NetworkManager::DynamicWep || securityType == NetworkManager::Wpa2Eap || securityType == NetworkManager::WpaEap) { if (securityType == NetworkManager::DynamicWep || securityType == NetworkManager::Leap) { wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::Ieee8021x); if (securityType == NetworkManager::Leap) { wifiSecurity->setAuthAlg(NetworkManager::WirelessSecuritySetting::Leap); } } else { wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap); } m_tmpConnectionUuid = settings->uuid(); m_tmpDevicePath = device; m_tmpSpecificPath = specificObject; - QPointer editor = new ConnectionEditorDialog(settings); - editor->show(); - KWindowSystem::setState(editor->winId(), NET::KeepAbove); - KWindowSystem::forceActiveWindow(editor->winId()); - connect(editor.data(), &ConnectionEditorDialog::accepted, - [editor, this] () { - addConnection(editor->setting()); - }); - connect(editor.data(), &ConnectionEditorDialog::finished, - [editor] () { - if (editor) { - editor->deleteLater(); - } - }); - editor->setModal(true); - editor->show(); +// QPointer editor = new ConnectionEditorDialog(settings); +// editor->show(); +// KWindowSystem::setState(editor->winId(), NET::KeepAbove); +// KWindowSystem::forceActiveWindow(editor->winId()); +// connect(editor.data(), &ConnectionEditorDialog::accepted, +// [editor, this] () { +// addConnection(editor->setting()); +// }); +// connect(editor.data(), &ConnectionEditorDialog::finished, +// [editor] () { +// if (editor) { +// editor->deleteLater(); +// } +// }); +// editor->setModal(true); +// editor->show(); } else { if (securityType == NetworkManager::StaticWep) { wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::Wep); wifiSecurity->setWepKey0(password); if (KWallet::Wallet::isEnabled()) { wifiSecurity->setWepKeyFlags(NetworkManager::Setting::AgentOwned); } } else { if (ap->mode() == NetworkManager::AccessPoint::Adhoc) { wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaNone); } else { wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaPsk); } wifiSecurity->setPsk(password); if (KWallet::Wallet::isEnabled()) { wifiSecurity->setPskFlags(NetworkManager::Setting::AgentOwned); } } QDBusPendingReply reply = NetworkManager::addAndActivateConnection(settings->toMap(), device, specificObject); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); watcher->setProperty("action", Handler::AddAndActivateConnection); watcher->setProperty("connection", settings->name()); connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); } settings.clear(); } void Handler::addConnection(const NMVariantMapMap& map) { QDBusPendingReply reply = NetworkManager::addConnection(map); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); watcher->setProperty("action", AddConnection); watcher->setProperty("connection", map.value("connection").value("id")); connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); } void Handler::deactivateConnection(const QString& connection, const QString& device) { NetworkManager::Connection::Ptr con = NetworkManager::findConnection(connection); if (!con) { qCWarning(PLASMA_NM) << "Not possible to deactivate this connection"; return; } QDBusPendingReply<> reply; for (const NetworkManager::ActiveConnection::Ptr &active : NetworkManager::activeConnections()) { if (active->uuid() == con->uuid() && ((!active->devices().isEmpty() && active->devices().first() == device) || active->vpn())) { if (active->vpn()) { reply = NetworkManager::deactivateConnection(active->path()); } else { NetworkManager::Device::Ptr device = NetworkManager::findNetworkInterface(active->devices().first()); if (device) { reply = device->disconnectInterface(); } } } } QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); watcher->setProperty("action", Handler::DeactivateConnection); connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); } void Handler::disconnectAll() { for (const NetworkManager::Device::Ptr &device : NetworkManager::networkInterfaces()) { device->disconnectInterface(); } } void Handler::enableAirplaneMode(bool enable) { if (enable) { m_tmpWirelessEnabled = NetworkManager::isWirelessEnabled(); m_tmpWwanEnabled = NetworkManager::isWwanEnabled(); enableBluetooth(false); enableWireless(false); enableWwan(false); } else { enableBluetooth(true); if (m_tmpWirelessEnabled) { enableWireless(true); } if (m_tmpWwanEnabled) { enableWwan(true); } } } template void makeDBusCall(const QDBusMessage &message, QObject *context, std::function)> func) { QDBusPendingReply reply = QDBusConnection::systemBus().asyncCall(message); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, context); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, context, [func] (QDBusPendingCallWatcher *watcher) { const QDBusPendingReply reply = *watcher; if (!reply.isValid()) { qCWarning(PLASMA_NM) << reply.error().message(); return; } func(reply); watcher->deleteLater(); }); } void setBluetoothEnabled(QString path, bool enabled) { QDBusMessage message = QDBusMessage::createMethodCall("org.bluez", path, "org.freedesktop.DBus.Properties", "Set"); QList arguments; arguments << QLatin1String("org.bluez.Adapter1"); arguments << QLatin1String("Powered"); arguments << QVariant::fromValue(QDBusVariant(QVariant(enabled))); message.setArguments(arguments); QDBusConnection::systemBus().asyncCall(message); } void Handler::enableBluetooth(bool enable) { qDBusRegisterMetaType< QMap >(); const QDBusMessage getObjects = QDBusMessage::createMethodCall("org.bluez", "/", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); makeDBusCall>(getObjects, this, [enable, this](const auto reply) { for (const QDBusObjectPath &path : reply.value().keys()) { const QString objPath = path.path(); qCDebug(PLASMA_NM) << "inspecting path" << objPath; const QStringList interfaces = reply.value().value(path).keys(); qCDebug(PLASMA_NM) << "interfaces:" << interfaces; if (!interfaces.contains("org.bluez.Adapter1")) { continue; } // We need to check previous state first if (!enable) { QDBusMessage getPowered = QDBusMessage::createMethodCall("org.bluez", objPath, "org.freedesktop.DBus.Properties", "Get"); const QList arguments { QLatin1String("org.bluez.Adapter1"), QLatin1String("Powered") }; getPowered.setArguments(arguments); makeDBusCall(getPowered, this, [objPath, this](const auto reply){ m_bluetoothAdapters.insert(objPath, reply.value().toBool()); setBluetoothEnabled(objPath, false); }); } else if (m_bluetoothAdapters.value(objPath)) { setBluetoothEnabled(objPath, true); } } }); } void Handler::enableNetworking(bool enable) { NetworkManager::setNetworkingEnabled(enable); } void Handler::enableWireless(bool enable) { NetworkManager::setWirelessEnabled(enable); } void Handler::enableWwan(bool enable) { NetworkManager::setWwanEnabled(enable); } void Handler::removeConnection(const QString& connection) { NetworkManager::Connection::Ptr con = NetworkManager::findConnection(connection); if (!con || con->uuid().isEmpty()) { qCWarning(PLASMA_NM) << "Not possible to remove connection " << connection; return; } // Remove slave connections for (const NetworkManager::Connection::Ptr &connection : NetworkManager::listConnections()) { NetworkManager::ConnectionSettings::Ptr settings = connection->settings(); if (settings->master() == con->uuid()) { connection->remove(); } } QDBusPendingReply<> reply = con->remove(); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); watcher->setProperty("action", Handler::RemoveConnection); watcher->setProperty("connection", con->name()); connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); } void Handler::updateConnection(const NetworkManager::Connection::Ptr& connection, const NMVariantMapMap& map) { QDBusPendingReply<> reply = connection->update(map); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); watcher->setProperty("action", UpdateConnection); watcher->setProperty("connection", connection->name()); connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); } void Handler::requestScan(const QString &interface) { for (NetworkManager::Device::Ptr device : NetworkManager::networkInterfaces()) { if (device->type() == NetworkManager::Device::Wifi) { NetworkManager::WirelessDevice::Ptr wifiDevice = device.objectCast(); if (wifiDevice && wifiDevice->state() != NetworkManager::WirelessDevice::Unavailable) { if (!interface.isEmpty() && interface != wifiDevice->interfaceName()) { continue; } if (!checkRequestScanRateLimit(wifiDevice)) { QDateTime now = QDateTime::currentDateTime(); // for NM < 1.12, lastScan is not available QDateTime lastScan = wifiDevice->lastScan(); QDateTime lastRequestScan = wifiDevice->lastRequestScan(); // Compute the next time we can run a scan int timeout = NM_REQUESTSCAN_LIMIT_RATE; if (lastScan.isValid() && lastScan.msecsTo(now) < NM_REQUESTSCAN_LIMIT_RATE) { timeout = NM_REQUESTSCAN_LIMIT_RATE - lastScan.msecsTo(now); } else if (lastRequestScan.isValid() && lastRequestScan.msecsTo(now) < NM_REQUESTSCAN_LIMIT_RATE) { timeout = NM_REQUESTSCAN_LIMIT_RATE - lastRequestScan.msecsTo(now); } qCDebug(PLASMA_NM) << "Rescheduling a request scan for" << wifiDevice->interfaceName() << "in" << timeout; scheduleRequestScan(wifiDevice->interfaceName(), timeout); if (!interface.isEmpty()) { return; } continue; } else if (m_wirelessScanRetryTimer.contains(interface)){ m_wirelessScanRetryTimer.value(interface)->stop(); delete m_wirelessScanRetryTimer.take(interface); } qCDebug(PLASMA_NM) << "Requesting wifi scan on device" << wifiDevice->interfaceName(); QDBusPendingReply<> reply = wifiDevice->requestScan(); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); watcher->setProperty("action", Handler::RequestScan); watcher->setProperty("interface", wifiDevice->interfaceName()); connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); } } } } void Handler::createHotspot() { bool foundInactive = false; bool useApMode = false; NetworkManager::WirelessDevice::Ptr wifiDev; NetworkManager::ConnectionSettings::Ptr connectionSettings; connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wireless)); NetworkManager::WirelessSetting::Ptr wifiSetting = connectionSettings->setting(NetworkManager::Setting::Wireless).dynamicCast(); wifiSetting->setMode(NetworkManager::WirelessSetting::Adhoc); wifiSetting->setSsid(Configuration::hotspotName().toUtf8()); for (const NetworkManager::Device::Ptr &device : NetworkManager::networkInterfaces()) { if (device->type() == NetworkManager::Device::Wifi) { wifiDev = device.objectCast(); if (wifiDev) { if (!wifiDev->isActive()) { foundInactive = true; } else { // Prefer previous device if it was inactive if (foundInactive) { break; } } if (wifiDev->wirelessCapabilities().testFlag(NetworkManager::WirelessDevice::ApCap)) { useApMode = true; } // We prefer inactive wireless card with AP capabilities if (foundInactive && useApMode) { break; } } } } if (!wifiDev) { qCWarning(PLASMA_NM) << "Failed to create hotspot: missing wireless device"; return; } wifiSetting->setInitialized(true); wifiSetting->setMode(useApMode ? NetworkManager::WirelessSetting::Ap :NetworkManager::WirelessSetting::Adhoc); if (!Configuration::hotspotPassword().isEmpty()) { NetworkManager::WirelessSecuritySetting::Ptr wifiSecurity = connectionSettings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); wifiSecurity->setInitialized(true); if (useApMode) { // Use WPA2 wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaPsk); wifiSecurity->setPsk(Configuration::hotspotPassword()); wifiSecurity->setPskFlags(NetworkManager::Setting::AgentOwned); } else { // Use WEP wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::Wep); wifiSecurity->setWepKeyType(NetworkManager::WirelessSecuritySetting::Passphrase); wifiSecurity->setWepTxKeyindex(0); wifiSecurity->setWepKey0(Configuration::hotspotPassword()); wifiSecurity->setWepKeyFlags(NetworkManager::Setting::AgentOwned); wifiSecurity->setAuthAlg(NetworkManager::WirelessSecuritySetting::Open); } } NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast(); ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Shared); ipv4Setting->setInitialized(true); connectionSettings->setId(Configuration::hotspotName()); connectionSettings->setAutoconnect(false); connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); const QVariantMap options = { {QLatin1String("persist"), QLatin1String("volatile")} }; QDBusPendingReply reply = NetworkManager::addAndActivateConnection2(connectionSettings->toMap(), wifiDev->uni(), QString(), options); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); watcher->setProperty("action", Handler::CreateHotspot); watcher->setProperty("connection", Configuration::hotspotName()); connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); connect(watcher, &QDBusPendingCallWatcher::finished, this, QOverload::of(&Handler::hotspotCreated)); } void Handler::stopHotspot() { const QString activeConnectionPath = Configuration::hotspotConnectionPath(); if (activeConnectionPath.isEmpty()) { return; } NetworkManager::ActiveConnection::Ptr hotspot = NetworkManager::findActiveConnection(activeConnectionPath); if (!hotspot) { return; } NetworkManager::deactivateConnection(activeConnectionPath); Configuration::setHotspotConnectionPath(QString()); Q_EMIT hotspotDisabled(); } bool Handler::checkRequestScanRateLimit(const NetworkManager::WirelessDevice::Ptr &wifiDevice) { QDateTime now = QDateTime::currentDateTime(); QDateTime lastScan = wifiDevice->lastScan(); QDateTime lastRequestScan = wifiDevice->lastRequestScan(); // if the last scan finished within the last 10 seconds bool ret = lastScan.isValid() && lastScan.msecsTo(now) < NM_REQUESTSCAN_LIMIT_RATE; // or if the last Request was sent within the last 10 seconds ret |= lastRequestScan.isValid() && lastRequestScan.msecsTo(now) < NM_REQUESTSCAN_LIMIT_RATE; // skip the request scan if (ret) { qCDebug(PLASMA_NM) << "Last scan finished " << lastScan.msecsTo(now) << "ms ago and last request scan was sent " << lastRequestScan.msecsTo(now) << "ms ago, Skipping scanning interface:" << wifiDevice->interfaceName(); return false; } return true; } bool Handler::checkHotspotSupported() { if (NetworkManager::checkVersion(1, 16, 0)) { bool unusedWifiFound = false; bool wifiFound = false; for (const NetworkManager::Device::Ptr &device : NetworkManager::networkInterfaces()) { if (device->type() == NetworkManager::Device::Wifi) { wifiFound = true; NetworkManager::WirelessDevice::Ptr wifiDev = device.objectCast(); if (wifiDev && !wifiDev->isActive()) { unusedWifiFound = true; } } } if (!wifiFound) { return false; } if (unusedWifiFound) { return true; } // Check if the primary connection which is used for internet connectivity is not using WiFi if (NetworkManager::primaryConnectionType() != NetworkManager::ConnectionSettings::Wireless) { return true; } } return false; } void Handler::scheduleRequestScan(const QString &interface, int timeout) { QTimer *timer; if (!m_wirelessScanRetryTimer.contains(interface)) { // create a timer for the interface timer = new QTimer(); timer->setSingleShot(true); m_wirelessScanRetryTimer.insert(interface, timer); auto retryAction = [this, interface]() { requestScan(interface); }; connect(timer, &QTimer::timeout, this, retryAction); } else { // set the new value for an existing timer timer = m_wirelessScanRetryTimer.value(interface); if (timer->isActive()) { timer->stop(); } } // +1 ms is added to avoid having the scan being rejetted by nm // because it is run at the exact last millisecond of the requestScan threshold timer->setInterval(timeout + 1); timer->start(); } void Handler::scanRequestFailed(const QString &interface) { scheduleRequestScan(interface, 2000); } void Handler::secretAgentError(const QString &connectionPath, const QString &message) { // If the password was wrong, forget it removeConnection(connectionPath); emit connectionActivationFailed(connectionPath, message); } void Handler::replyFinished(QDBusPendingCallWatcher * watcher) { QDBusPendingReply<> reply = *watcher; if (reply.isError() || !reply.isValid()) { KNotification *notification = nullptr; QString error = reply.error().message(); Handler::HandlerAction action = (Handler::HandlerAction)watcher->property("action").toUInt(); switch (action) { case Handler::ActivateConnection: notification = new KNotification("FailedToActivateConnection", KNotification::CloseOnTimeout, this); notification->setTitle(i18n("Failed to activate %1", watcher->property("connection").toString())); break; case Handler::AddAndActivateConnection: notification = new KNotification("FailedToAddConnection", KNotification::CloseOnTimeout, this); notification->setTitle(i18n("Failed to add %1", watcher->property("connection").toString())); break; case Handler::AddConnection: notification = new KNotification("FailedToAddConnection", KNotification::CloseOnTimeout, this); notification->setTitle(i18n("Failed to add connection %1", watcher->property("connection").toString())); break; case Handler::DeactivateConnection: notification = new KNotification("FailedToDeactivateConnection", KNotification::CloseOnTimeout, this); notification->setTitle(i18n("Failed to deactivate %1", watcher->property("connection").toString())); break; case Handler::RemoveConnection: notification = new KNotification("FailedToRemoveConnection", KNotification::CloseOnTimeout, this); notification->setTitle(i18n("Failed to remove %1", watcher->property("connection").toString())); break; case Handler::UpdateConnection: notification = new KNotification("FailedToUpdateConnection", KNotification::CloseOnTimeout, this); notification->setTitle(i18n("Failed to update connection %1", watcher->property("connection").toString())); break; case Handler::RequestScan: { const QString interface = watcher->property("interface").toString(); qCWarning(PLASMA_NM) << "Wireless scan on" << interface << "failed:" << error; scanRequestFailed(interface); break; } case Handler::CreateHotspot: notification = new KNotification("FailedToCreateHotspot", KNotification::CloseOnTimeout, this); notification->setTitle(i18n("Failed to create hotspot %1", watcher->property("connection").toString())); break; default: break; } if (notification) { notification->setComponentName("networkmanagement"); notification->setText(error); notification->setIconName(QStringLiteral("dialog-warning")); notification->sendEvent(); } } else { KNotification *notification = nullptr; Handler::HandlerAction action = (Handler::HandlerAction)watcher->property("action").toUInt(); switch (action) { case Handler::AddConnection: notification = new KNotification("ConnectionAdded", KNotification::CloseOnTimeout, this); notification->setText(i18n("Connection %1 has been added", watcher->property("connection").toString())); break; case Handler::RemoveConnection: notification = new KNotification("ConnectionRemoved", KNotification::CloseOnTimeout, this); notification->setText(i18n("Connection %1 has been removed", watcher->property("connection").toString())); break; case Handler::UpdateConnection: notification = new KNotification("ConnectionUpdated", KNotification::CloseOnTimeout, this); notification->setText(i18n("Connection %1 has been updated", watcher->property("connection").toString())); break; case Handler::RequestScan: qCDebug(PLASMA_NM) << "Wireless scan on" << watcher->property("interface").toString() << "succeeded"; break; default: break; } if (notification) { notification->setComponentName("networkmanagement"); notification->setTitle(watcher->property("connection").toString()); notification->setIconName(QStringLiteral("dialog-information")); notification->sendEvent(); } } watcher->deleteLater(); } void Handler::hotspotCreated(QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; if (!reply.isError() && reply.isValid()) { const QString activeConnectionPath = reply.argumentAt(1).value().path(); if (activeConnectionPath.isEmpty()) { return; } Configuration::setHotspotConnectionPath(activeConnectionPath); NetworkManager::ActiveConnection::Ptr hotspot = NetworkManager::findActiveConnection(activeConnectionPath); if (!hotspot) { return; } connect(hotspot.data(), &NetworkManager::ActiveConnection::stateChanged, [=] (NetworkManager::ActiveConnection::State state) { if (state > NetworkManager::ActiveConnection::Activated) { Configuration::setHotspotConnectionPath(QString()); Q_EMIT hotspotDisabled(); } }); Q_EMIT hotspotCreated(); } } void Handler::primaryConnectionTypeChanged(NetworkManager::ConnectionSettings::ConnectionType type) { Q_UNUSED(type) m_hotspotSupported = checkHotspotSupported(); Q_EMIT hotspotSupportedChanged(m_hotspotSupported); } #if WITH_MODEMMANAGER_SUPPORT void Handler::unlockRequiredChanged(MMModemLock modemLock) { if (modemLock == MM_MODEM_LOCK_NONE) { activateConnection(m_tmpConnectionPath, m_tmpDevicePath, m_tmpSpecificPath); } } #endif