From 1e2847ef96e441c890230d5bf1475f693c49fe2d Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Mon, 13 Mar 2023 19:26:52 -0700 Subject: [PATCH] kcms: Import mobile network kcms plasma-nm currently has the mobile network KCMs, but requires having a build flag in order to have them installed. This then requires distros to have multiple versions of the plasma-nm package. I think it makes sense to move them here so that packaging and development is easier. --- kcms/CMakeLists.txt | 2 + .../package/contents/ui/PopupDialog.qml | 2 +- kcms/hotspot/CMakeLists.txt | 18 ++ kcms/hotspot/Messages.sh | 4 + kcms/hotspot/hotspotsettings.cpp | 23 ++ kcms/hotspot/hotspotsettings.h | 20 ++ kcms/hotspot/kcm_mobile_hotspot.json | 133 ++++++++ kcms/hotspot/package/contents/ui/main.qml | 57 ++++ kcms/wifi/CMakeLists.txt | 23 ++ kcms/wifi/Messages.sh | 4 + kcms/wifi/kcm_mobile_wifi.json | 139 +++++++++ .../package/contents/ui/ConnectDialog.qml | 141 +++++++++ .../contents/ui/ConnectionItemDelegate.qml | 115 +++++++ .../package/contents/ui/NetworkSettings.qml | 214 +++++++++++++ .../package/contents/ui/PasswordField.qml | 21 ++ kcms/wifi/package/contents/ui/main.qml | 117 +++++++ kcms/wifi/wifisettings.cpp | 285 ++++++++++++++++++ kcms/wifi/wifisettings.h | 26 ++ 18 files changed, 1343 insertions(+), 1 deletion(-) create mode 100644 kcms/hotspot/CMakeLists.txt create mode 100644 kcms/hotspot/Messages.sh create mode 100644 kcms/hotspot/hotspotsettings.cpp create mode 100644 kcms/hotspot/hotspotsettings.h create mode 100644 kcms/hotspot/kcm_mobile_hotspot.json create mode 100644 kcms/hotspot/package/contents/ui/main.qml create mode 100644 kcms/wifi/CMakeLists.txt create mode 100644 kcms/wifi/Messages.sh create mode 100644 kcms/wifi/kcm_mobile_wifi.json create mode 100644 kcms/wifi/package/contents/ui/ConnectDialog.qml create mode 100644 kcms/wifi/package/contents/ui/ConnectionItemDelegate.qml create mode 100644 kcms/wifi/package/contents/ui/NetworkSettings.qml create mode 100644 kcms/wifi/package/contents/ui/PasswordField.qml create mode 100644 kcms/wifi/package/contents/ui/main.qml create mode 100644 kcms/wifi/wifisettings.cpp create mode 100644 kcms/wifi/wifisettings.h diff --git a/kcms/CMakeLists.txt b/kcms/CMakeLists.txt index 5df810d9..de9815a3 100644 --- a/kcms/CMakeLists.txt +++ b/kcms/CMakeLists.txt @@ -7,3 +7,5 @@ add_subdirectory(info) add_subdirectory(powermanagement) add_subdirectory(time) add_subdirectory(virtualkeyboard) +add_subdirectory(hotspot) +add_subdirectory(wifi) diff --git a/kcms/cellularnetwork/package/contents/ui/PopupDialog.qml b/kcms/cellularnetwork/package/contents/ui/PopupDialog.qml index d8c008e5..4045b2df 100644 --- a/kcms/cellularnetwork/package/contents/ui/PopupDialog.qml +++ b/kcms/cellularnetwork/package/contents/ui/PopupDialog.qml @@ -4,7 +4,7 @@ import QtQuick 2.15 import QtQuick.Layouts 1.2 import QtQuick.Controls 2.15 as Controls -import QtGraphicalEffects 1.12 +import Qt5Compat.GraphicalEffects import org.kde.kirigami 2.12 as Kirigami Controls.Dialog { diff --git a/kcms/hotspot/CMakeLists.txt b/kcms/hotspot/CMakeLists.txt new file mode 100644 index 00000000..f426ccc1 --- /dev/null +++ b/kcms/hotspot/CMakeLists.txt @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2020 Tobias Fella +# SPDX-License-Identifier: LGPL-2.0-or-later + +set (hotspotsettings_SRCS hotspotsettings.cpp) + +add_library(kcm_mobile_hotspot MODULE ${hotspotsettings_SRCS}) + +target_link_libraries(kcm_mobile_hotspot + Qt::Quick + Qt::Qml + KF6::I18n + KF6::CoreAddons + KF6::QuickAddons +) + +install(TARGETS kcm_mobile_hotspot DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms) +kpackage_install_package(package kcm_mobile_hotspot kcms) +kcmutils_generate_desktop_file(kcm_mobile_hotspot) diff --git a/kcms/hotspot/Messages.sh b/kcms/hotspot/Messages.sh new file mode 100644 index 00000000..54b6bd27 --- /dev/null +++ b/kcms/hotspot/Messages.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: 2020 Tobias Fella +# SPDX-License-Identifier: LGPL-2.0-or-later +$XGETTEXT `find . -name \*.cpp -o -name \*.qml` -o $podir/kcm_mobile_hotspot.pot diff --git a/kcms/hotspot/hotspotsettings.cpp b/kcms/hotspot/hotspotsettings.cpp new file mode 100644 index 00000000..47d77b3a --- /dev/null +++ b/kcms/hotspot/hotspotsettings.cpp @@ -0,0 +1,23 @@ +/* + SPDX-FileCopyrightText: 2020 Tobias Fella + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +#include "hotspotsettings.h" + +#include +#include + +K_PLUGIN_CLASS_WITH_JSON(HotspotSettings, "kcm_mobile_hotspot.json") + +HotspotSettings::HotspotSettings(QObject *parent, const KPluginMetaData &metaData, const QVariantList &args) + : KQuickAddons::ConfigModule(parent, metaData, args) +{ +} + +HotspotSettings::~HotspotSettings() +{ +} + +#include "hotspotsettings.moc" diff --git a/kcms/hotspot/hotspotsettings.h b/kcms/hotspot/hotspotsettings.h new file mode 100644 index 00000000..48eb20d5 --- /dev/null +++ b/kcms/hotspot/hotspotsettings.h @@ -0,0 +1,20 @@ +/* + SPDX-FileCopyrightText: 2020 Tobias Fella + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +#ifndef HOTSPOTSETTINGS_H +#define HOTSPOTSETTINGS_H + +#include + +class HotspotSettings : public KQuickAddons::ConfigModule +{ + Q_OBJECT +public: + HotspotSettings(QObject *parent, const KPluginMetaData &metaData, const QVariantList &args); + virtual ~HotspotSettings() override; +}; + +#endif // HOTSPOTSETTINGS_H diff --git a/kcms/hotspot/kcm_mobile_hotspot.json b/kcms/hotspot/kcm_mobile_hotspot.json new file mode 100644 index 00000000..e8d532aa --- /dev/null +++ b/kcms/hotspot/kcm_mobile_hotspot.json @@ -0,0 +1,133 @@ +{ + "KPlugin": { + "Authors": [ + { + "Email": "fella@posteo.de", + "Name": "Tobias Fella", + "Name[ar]": "Tobias Fella", + "Name[az]": "Tobias Fella", + "Name[bg]": "Tobias Fella", + "Name[ca@valencia]": "Tobias Fella", + "Name[ca]": "Tobias Fella", + "Name[cs]": "Tobias Fella", + "Name[de]": "Tobias Fella", + "Name[en_GB]": "Tobias Fella", + "Name[es]": "Tobias Fella", + "Name[eu]": "Tobias Fella", + "Name[fi]": "Tobias Fella", + "Name[fr]": "Tobias Fella", + "Name[hu]": "Tobias Fella", + "Name[ia]": "Tobias Fella", + "Name[is]": "Tobias Fella", + "Name[it]": "Tobias Fella", + "Name[ka]": "Tobias Fella", + "Name[ko]": "Tobias Fella", + "Name[lt]": "Tobias Fella", + "Name[nl]": "Tobias Fella", + "Name[nn]": "Tobias Fella", + "Name[pl]": "Tobias Fella", + "Name[pt]": "Tobias Fella", + "Name[pt_BR]": "Tobias Fella", + "Name[ro]": "Tobias Fella", + "Name[ru]": "Tobias Fella", + "Name[sk]": "Tobias Fella", + "Name[sl]": "Tobias Fella", + "Name[sv]": "Tobias Fella", + "Name[ta]": "டோபியாஸ் ஃபெல்லா", + "Name[tr]": "Tobias Fella", + "Name[uk]": "Tobias Fella", + "Name[x-test]": "xxTobias Fellaxx", + "Name[zh_CN]": "Tobias Fella", + "Name[zh_TW]": "Tobias Fella" + } + ], + "Category": "System Information", + "Description": "Wi-Fi Hotspot", + "Description[az]": "Wi-Fi qoşulma nöqtəsi", + "Description[bg]": "Wi-Fi точка за достъп", + "Description[ca@valencia]": "Punt d'accés Wi-Fi", + "Description[ca]": "Punt d'accés Wi-Fi", + "Description[cs]": "Hotspot WiFi", + "Description[de]": "Wi-Fi-Hotspot", + "Description[en_GB]": "WiFi Hotspot", + "Description[es]": "Puntos de acceso wifi", + "Description[eu]": "Wi-Fi berogunea", + "Description[fi]": "Langattomat tukiasemat", + "Description[fr]": "Point d'accès Wifi", + "Description[ia]": "Hotspots de Wi-Fi", + "Description[it]": "Hotspot Wi-Fi", + "Description[ka]": "Wi-Fi ჰოტსპოტი", + "Description[ko]": "Wi-Fi 핫스팟", + "Description[lt]": "Belaidis (Wi-Fi) prieigos taškas", + "Description[nl]": "Wi-Fi-hotspot", + "Description[nn]": "Trådlaussone", + "Description[pl]": "Hotspot Wi-Fi", + "Description[pt]": "Ponto de Acesso Wi-Fi", + "Description[ru]": "Точки доступа Wi-Fi", + "Description[sk]": "Prístupový bod Wi-Fi", + "Description[sl]": "Vroča točka Wi-Fi", + "Description[ta]": "அருகலை ஹாட்ஸ்பாட்டு", + "Description[tr]": "Wi-Fi Kişisel Erişim Noktası", + "Description[uk]": "Хот-спот Wi-Fi", + "Description[x-test]": "xxWi-Fi Hotspotxx", + "Description[zh_CN]": "Wi-Fi 热点", + "Description[zh_TW]": "Wi-Fi 熱點", + "EnabledByDefault": true, + "FormFactors": [ + "handset", + "tablet", + "mediacenter" + ], + "Icon": "network-wireless-hotspot", + "Id": "kcm_mobile_hotspot", + "License": "GPL", + "Name": "Hotspot", + "Name[ar]": "نقطة فعالة", + "Name[az]": "Qoşulma nöqtəsi", + "Name[bg]": "Точка за достъп", + "Name[ca@valencia]": "Punt d'accés", + "Name[ca]": "Punt d'accés", + "Name[cs]": "Hotspot", + "Name[da]": "Internetdeling", + "Name[de]": "Hotspot", + "Name[en_GB]": "Hotspot", + "Name[es]": "Punto de acceso", + "Name[et]": "Pääsupunkt", + "Name[eu]": "Berogunea", + "Name[fi]": "Tukiasema", + "Name[fr]": "Point d'accès", + "Name[hsb]": "Hotspot", + "Name[hu]": "Hotspot", + "Name[ia]": "Hotspot", + "Name[id]": "Hotspot", + "Name[is]": "Aðgangsstaður", + "Name[it]": "Hotspot", + "Name[ka]": "ჰოტსპოტი", + "Name[ko]": "핫스팟", + "Name[lt]": "Prieigos taškas", + "Name[nl]": "Hotspot", + "Name[nn]": "Trådlaussone", + "Name[pa]": "ਹਾਟਸਪਾਟ", + "Name[pl]": "Hotspot", + "Name[pt]": "Ponto de Acesso", + "Name[pt_BR]": "Ponto de acesso", + "Name[ro]": "Hotspot", + "Name[ru]": "Точка доступа Wi-Fi", + "Name[sk]": "Prístupový bod", + "Name[sl]": "Vroča točka", + "Name[sv]": "Accesspunkt", + "Name[ta]": "ஹாட்ஸ்பாட்", + "Name[tr]": "Kişisel Erişim Noktası", + "Name[uk]": "Хот-спот", + "Name[x-test]": "xxHotspotxx", + "Name[zh_CN]": "热点", + "Name[zh_TW]": "熱點", + "ServiceTypes": [ + "KCModule" + ], + "Version": "0.1", + "Website": "https://plasma-mobile.org/" + }, + "X-Plasma-MainScript": "ui/main.qml", + "X-Plasma-Package": "kcm_mobile_hotspot" +} diff --git a/kcms/hotspot/package/contents/ui/main.qml b/kcms/hotspot/package/contents/ui/main.qml new file mode 100644 index 00000000..2e3e004b --- /dev/null +++ b/kcms/hotspot/package/contents/ui/main.qml @@ -0,0 +1,57 @@ +/* + SPDX-FileCopyrightText: 2020 Tobias Fella + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +import QtQuick 2.6 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.2 as Controls +import org.kde.plasma.networkmanagement 0.2 as PlasmaNM +import org.kde.kirigami 2.10 as Kirigami +import org.kde.kcm 1.2 + +SimpleKCM { + + PlasmaNM.Handler { + id: handler + } + + Kirigami.FormLayout { + Controls.Switch { + id: hotspotToggle + Kirigami.FormData.label: i18n("Enabled:") + onToggled: { + if (hotspotToggle.checked) { + handler.createHotspot() + } else { + handler.stopHotspot() + } + } + } + + Controls.TextField { + id: hotspotName + Kirigami.FormData.label: i18n("SSID:") + text: PlasmaNM.Configuration.hotspotName + } + + Kirigami.PasswordField { + id: hotspotPassword + Kirigami.FormData.label: i18n("Password:") + text: PlasmaNM.Configuration.hotspotPassword + } + + Controls.Button { + text: i18n("Save") + onClicked: { + PlasmaNM.Configuration.hotspotName = hotspotName.text + PlasmaNM.Configuration.hotspotPassword = hotspotPassword.text + if (hotspotToggle.checked) { + handler.stopHotspot() + handler.createHotspot() + } + } + } + } +} diff --git a/kcms/wifi/CMakeLists.txt b/kcms/wifi/CMakeLists.txt new file mode 100644 index 00000000..cda58c74 --- /dev/null +++ b/kcms/wifi/CMakeLists.txt @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2018 Martin Kacej +# SPDX-License-Identifier: LGPL-2.0-or-later + +project (kcm_mobile_wifi) + +set (wifisettings_SRCS wifisettings.cpp) + +add_library(kcm_mobile_wifi MODULE ${wifisettings_SRCS}) + +target_link_libraries(kcm_mobile_wifi + Qt::DBus + Qt::Gui + Qt::Quick + Qt::Qml + KF6::I18n + KF6::NetworkManagerQt + KF6::Plasma + KF6::QuickAddons +) + +install(TARGETS kcm_mobile_wifi DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms) +kpackage_install_package(package kcm_mobile_wifi kcms) +kcmutils_generate_desktop_file(kcm_mobile_wifi) diff --git a/kcms/wifi/Messages.sh b/kcms/wifi/Messages.sh new file mode 100644 index 00000000..45b724d3 --- /dev/null +++ b/kcms/wifi/Messages.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: 2018 Martin Kacej +# SPDX-License-Identifier: LGPL-2.0-or-later +$XGETTEXT `find . -name \*.cpp -o -name \*.qml` -o $podir/kcm_mobile_wifi.pot diff --git a/kcms/wifi/kcm_mobile_wifi.json b/kcms/wifi/kcm_mobile_wifi.json new file mode 100644 index 00000000..0968e302 --- /dev/null +++ b/kcms/wifi/kcm_mobile_wifi.json @@ -0,0 +1,139 @@ +{ + "Categories": "Qt;KDE;X-KDE-settings-system;", + "KPlugin": { + "Description": "Wireless network setting", + "Description[ar]": "إعدادات الشبكة اللاسلكية", + "Description[az]": "Naqilsiz şəbəkə ayarları", + "Description[bg]": "Настройки на безжична мрежа", + "Description[ca@valencia]": "Configureu la xarxa sense fil", + "Description[ca]": "Configuració de la xarxa sense fil", + "Description[cs]": "Nastavení bezdrátové sítě", + "Description[de]": "Einstellungen für drahtloses Netzwerk", + "Description[en_GB]": "Wireless network setting", + "Description[es]": "Preferencias de la red inalámbrica", + "Description[eu]": "Haririk gabeko sare ezarpena", + "Description[fi]": "Langattoman verkon asetukset", + "Description[fr]": "Paramètre de réseau sans fil", + "Description[hu]": "Vezeték nélküli hálózati beállítások", + "Description[ia]": "Preferentia de rete sin cablos", + "Description[is]": "Stillingar þráðlauss nets", + "Description[it]": "Impostazioni rete senza fili", + "Description[ka]": "უსადენო ქსელის მორგება", + "Description[ko]": "무선 네트워크 설정", + "Description[lt]": "Belaidžio tinklo nuostata", + "Description[nl]": "Instelling van draadloos netwerk", + "Description[nn]": "Innstilling for trådlaust nettverk", + "Description[pl]": "Ustawienia sieci bezprzewodowej", + "Description[pt]": "Configuração da rede sem-fios", + "Description[pt_BR]": "Configurações da rede sem fio", + "Description[ro]": "Configurare rețea fără fir", + "Description[ru]": "Параметры беспроводного соединения", + "Description[sk]": "Nastavenia bezdrôtovej siete", + "Description[sl]": "Nastavitve brezžičnega omrežja", + "Description[sv]": "Trådlös nätverksinställning", + "Description[ta]": "கம்பியில்லா பிணையத்திற்கான அமைப்பு", + "Description[tr]": "Kablosuz ağ ayarı", + "Description[uk]": "Налаштовування бездротової мережі", + "Description[x-test]": "xxWireless network settingxx", + "Description[zh_CN]": "无线网络设置", + "Description[zh_TW]": "無線網路設定", + "FormFactors": [ + "handset", + "tablet", + "mediacenter" + ], + "Icon": "network-wireless-symbolic", + "Name": "Wi-Fi", + "Name[ar]": "واي فاي", + "Name[az]": "Wi-Fi", + "Name[bg]": "Wi-Fi", + "Name[ca@valencia]": "Wi-Fi", + "Name[ca]": "Wi-Fi", + "Name[cs]": "Wi-Fi", + "Name[da]": "Wi-fi", + "Name[de]": "Wi-Fi", + "Name[en_GB]": "Wi-Fi", + "Name[es]": "Wifi", + "Name[et]": "Wi-Fi", + "Name[eu]": "Wi-Fi", + "Name[fi]": "Langaton verkko", + "Name[fr]": "Wi-Fi", + "Name[gl]": "Sen fíos", + "Name[hsb]": "Wi-Fi", + "Name[hu]": "Wi-Fi", + "Name[ia]": "Wi-Fi", + "Name[id]": "Wi-Fi", + "Name[is]": "Þráðlaust Wi-Fi", + "Name[it]": "Wi-fi", + "Name[ka]": "Wi-Fi", + "Name[ko]": "Wi-Fi", + "Name[lt]": "Belaidis (Wi-Fi)", + "Name[ml]": "വൈ-ഫൈ", + "Name[nl]": "Wi-Fi", + "Name[nn]": "Wi-Fi", + "Name[pa]": "Wi-Fi", + "Name[pl]": "Wi-Fi", + "Name[pt]": "Wi-Fi", + "Name[pt_BR]": "Wi-Fi", + "Name[ro]": "Wi-Fi", + "Name[ru]": "Wi-Fi", + "Name[sk]": "Wi-Fi", + "Name[sl]": "Wi-Fi", + "Name[sv]": "WIFI", + "Name[ta]": "அருகலை", + "Name[tg]": "Wi-Fi", + "Name[tr]": "Wi-Fi", + "Name[uk]": "Wi-Fi", + "Name[x-test]": "xxWi-Fixx", + "Name[zh_CN]": "Wi-Fi", + "Name[zh_TW]": "Wi-Fi", + "ServiceTypes": [ + "KCModule" + ] + }, + "X-KDE-Keywords": "wifi,network", + "X-KDE-Keywords[ar]": "واي فاي,شبكة", + "X-KDE-Keywords[ast]": "wifi,rede", + "X-KDE-Keywords[az]": "wifi,network,şəbəkə", + "X-KDE-Keywords[ca@valencia]": "wifi,xarxa", + "X-KDE-Keywords[ca]": "wifi,xarxa", + "X-KDE-Keywords[cs]": "wifi,síť", + "X-KDE-Keywords[da]": "wifi,netværk", + "X-KDE-Keywords[de]": "netzwerk", + "X-KDE-Keywords[en_GB]": "wifi,network", + "X-KDE-Keywords[es]": "wifi,red", + "X-KDE-Keywords[et]": "wifi,võrk", + "X-KDE-Keywords[eu]": "wifi,haririk-gabeko,network,sarea", + "X-KDE-Keywords[fi]": "wifi,langaton,verkko", + "X-KDE-Keywords[fr]": "wifi,réseau", + "X-KDE-Keywords[gl]": "sen fíos,wifi,rede", + "X-KDE-Keywords[hsb]": "wifi,network,syć", + "X-KDE-Keywords[hu]": "wifi,hálózat", + "X-KDE-Keywords[ia]": "wifi,network", + "X-KDE-Keywords[id]": "wifi,jaringan", + "X-KDE-Keywords[it]": "wifi,rete", + "X-KDE-Keywords[ko]": "wifi,network,네트워크,무선", + "X-KDE-Keywords[lt]": "wifi,belaidis,bevielis,tinklas", + "X-KDE-Keywords[ml]": "വൈഫൈ,ശൃംഖല", + "X-KDE-Keywords[nl]": "wifi,netwerk", + "X-KDE-Keywords[nn]": "wifi,nettverk,trådlaust", + "X-KDE-Keywords[pa]": "wifi,ਨੈੱਟਵਰਕ", + "X-KDE-Keywords[pl]": "wifi,sieć", + "X-KDE-Keywords[pt]": "wifi,rede", + "X-KDE-Keywords[pt_BR]": "wifi,sem fio,rede", + "X-KDE-Keywords[ro]": "wifi,rețea", + "X-KDE-Keywords[ru]": "wifi,network,сеть", + "X-KDE-Keywords[sk]": "wifi,network", + "X-KDE-Keywords[sl]": "wifi,network,omrežje", + "X-KDE-Keywords[sv]": "wifi,nätverk", + "X-KDE-Keywords[ta]": "wifi,network,அருகலை,பிணையம்,வைஃபை,கம்பியில்லா", + "X-KDE-Keywords[tg]": "wifi,шабака", + "X-KDE-Keywords[tr]": "wifi, ağ", + "X-KDE-Keywords[uk]": "wifi,network,вайфай,мережа", + "X-KDE-Keywords[x-test]": "xxwifixx,xxnetworkxx", + "X-KDE-Keywords[zh_CN]": "wifi,network,网络,无线", + "X-KDE-Keywords[zh_TW]": "wifi,network,網路,無線網路", + "X-KDE-ParentApp": "kcontrol", + "X-KDE-System-Settings-Parent-Category": "network", + "X-KDE-Weight": 70 +} diff --git a/kcms/wifi/package/contents/ui/ConnectDialog.qml b/kcms/wifi/package/contents/ui/ConnectDialog.qml new file mode 100644 index 00000000..a7f7ca9f --- /dev/null +++ b/kcms/wifi/package/contents/ui/ConnectDialog.qml @@ -0,0 +1,141 @@ +/* + SPDX-FileCopyrightText: 2020 Devin Lin + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ +import QtQuick 2.6 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.2 as Controls +import Qt5Compat.GraphicalEffects +import org.kde.kirigami 2.12 as Kirigami + +Controls.Dialog { + id: dialogRoot + property int securityType + property string headingText + property string devicePath + property string specificPath + + signal donePressed(string password) + + function openAndClear() { + warning.visible = false; + this.open(); + passwordField.text = ""; + passwordField.focus = true; + } + + anchors.centerIn: parent + modal: true + standardButtons: Controls.Dialog.Ok | Controls.Dialog.Cancel + + onOpened: passwordField.forceActiveFocus() + onRejected: { + dialogRoot.close(); + passwordField.focus = false; + } + onAccepted: { + if (passwordField.acceptableInput) { + dialogRoot.close(); + handler.addAndActivateConnection(devicePath, specificPath, passwordField.text); + } else { + warning.visible = true; + } + passwordField.focus = false; + } + + property int translateY: (1 - opacity) * Kirigami.Units.gridUnit * 2 + + NumberAnimation on opacity { + to: 1 + from: 0 + duration: Kirigami.Units.veryShortDuration + easing.type: Easing.InOutQuad + running: true + } + + background: Item { + transform: Translate { y: dialogRoot.translateY } + + RectangularGlow { + anchors.fill: rect + anchors.topMargin: 1 + cornerRadius: rect.radius * 2 + glowRadius: 2 + spread: 0.2 + color: Qt.rgba(0, 0, 0, 0.3) + } + Rectangle { + id: rect + anchors.fill: parent + Kirigami.Theme.inherit: false + Kirigami.Theme.colorSet: Kirigami.Theme.Window + color: Kirigami.Theme.backgroundColor + radius: Kirigami.Units.smallSpacing + + Kirigami.Separator { + id: topSeparator + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + anchors.topMargin: dialogRoot.header.implicitHeight + } + + Kirigami.Separator { + id: bottomSeparator + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.bottomMargin: dialogRoot.footer.implicitHeight + } + + Rectangle { + Kirigami.Theme.inherit: false + Kirigami.Theme.colorSet: Kirigami.Theme.View + color: Kirigami.Theme.backgroundColor + anchors.left: parent.left + anchors.right: parent.right + anchors.top: topSeparator.bottom + anchors.bottom: bottomSeparator.top + } + } + } + + header: Item { + transform: Translate { y: dialogRoot.translateY } + implicitHeight: heading.implicitHeight + Kirigami.Units.largeSpacing * 2 + + Kirigami.Heading { + id: heading + level: 2 + text: headingText + wrapMode: Text.WordWrap + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: Kirigami.Units.largeSpacing + anchors.verticalCenter: parent.verticalCenter + } + } + + footer.transform: Translate { y: dialogRoot.translateY } + + ColumnLayout { + id: column + transform: Translate { y: dialogRoot.translateY } + spacing: Kirigami.Units.largeSpacing + + PasswordField { + id: passwordField + Layout.fillWidth: true + securityType: dialogRoot.securityType + onAccepted: dialogRoot.accept() + } + + Controls.Label { + id: warning + text: i18n("Invalid input.") + visible: false + } + } + +} diff --git a/kcms/wifi/package/contents/ui/ConnectionItemDelegate.qml b/kcms/wifi/package/contents/ui/ConnectionItemDelegate.qml new file mode 100644 index 00000000..f3b91f48 --- /dev/null +++ b/kcms/wifi/package/contents/ui/ConnectionItemDelegate.qml @@ -0,0 +1,115 @@ +/* + SPDX-FileCopyrightText: 2017 Martin Kacej + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +import QtQuick 2.6 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.2 as Controls +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.networkmanagement 0.2 as PlasmaNM +import org.kde.kirigami 2.2 as Kirigami + +Kirigami.SwipeListItem { + + enabled: true + + property var map : [] + property bool predictableWirelessPassword: !Uuid && Type == PlasmaNM.Enums.Wireless && + (SecurityType == PlasmaNM.Enums.StaticWep || + SecurityType == PlasmaNM.Enums.WpaPsk || + SecurityType == PlasmaNM.Enums.Wpa2Psk || + SecurityType == PlasmaNM.Enums.SAE) + + RowLayout { + anchors.leftMargin: Kirigami.Units.largeSpacing * 5 + spacing: Kirigami.Units.largeSpacing + Kirigami.Separator {} + + Item { + Layout.preferredWidth: Kirigami.Units.gridUnit + Layout.preferredHeight: Kirigami.Units.gridUnit + + PlasmaCore.SvgItem { + id: connectionSvgIcon + elementId: mobileProxyModel.showSavedMode ? "network-wireless-connected-100" : ConnectionIcon + + svg: PlasmaCore.Svg { + multipleImages: true + imagePath: "icons/network" + colorGroup: PlasmaCore.ColorScope.colorGroup + } + } + + Controls.BusyIndicator { + id: connectingIndicator + + anchors { + horizontalCenter: connectionSvgIcon.horizontalCenter + verticalCenter: connectionSvgIcon.verticalCenter + } + running: ConnectionState == PlasmaNM.Enums.Activating + visible: running + } + } + + Controls.Label { + id: connectionNameLabel + + Layout.fillWidth: true + elide: Text.ElideRight + text: ItemUniqueName + textFormat: Text.PlainText + } + } + + actions: [ + Kirigami.Action { + iconName: "network-connect" + visible: ConnectionState != PlasmaNM.Enums.Activated + onTriggered: changeState() + }, + Kirigami.Action { + iconName: "network-disconnect" + visible: ConnectionState == PlasmaNM.Enums.Activated + onTriggered: handler.deactivateConnection(ConnectionPath, DevicePath) + }, + Kirigami.Action { + iconName: "configure" + visible: (Uuid != "")? true : false + onTriggered: { + kcm.push("NetworkSettings.qml", {path: ConnectionPath}) + } + }, + Kirigami.Action { + iconName: "entry-delete" + visible: (Uuid != "")? true : false + onTriggered: handler.removeConnection(ConnectionPath) + } + ] + + onClicked: { + changeState() + } + + function changeState() { + if (Uuid || !predictableWirelessPassword) { + if (ConnectionState == PlasmaNM.Enums.Deactivated) { + if (!predictableWirelessPassword && !Uuid) { + handler.addAndActivateConnection(DevicePath, SpecificPath); + } else { + handler.activateConnection(ConnectionPath, DevicePath, SpecificPath); + } + } else{ + //show popup + } + } else if (predictableWirelessPassword) { + connectionDialog.headingText = i18n("Connect to") + " " + ItemUniqueName; + connectionDialog.devicePath = DevicePath; + connectionDialog.specificPath = SpecificPath; + connectionDialog.securityType = SecurityType; + connectionDialog.openAndClear(); + } + } +} diff --git a/kcms/wifi/package/contents/ui/NetworkSettings.qml b/kcms/wifi/package/contents/ui/NetworkSettings.qml new file mode 100644 index 00000000..0b0aa9af --- /dev/null +++ b/kcms/wifi/package/contents/ui/NetworkSettings.qml @@ -0,0 +1,214 @@ +/* + SPDX-FileCopyrightText: 2017 Martin Kacej + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ +import QtQuick 2.15 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.2 as Controls +import org.kde.kirigami 2.3 as Kirigami +import org.kde.plasma.networkmanagement 0.2 as PlasmaNM +import org.kde.kcm 1.1 + +SimpleKCM { + title: path ? wirelessSettings["ssid"] : i18n("Add new Connection") + + property var path + + property var wirelessSettings: ({}) + property var securitySettings: ({}) + property var ipSettings: ({}) + property var secrets: ({}) + + property var ipRegex: /^(([01]?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))\.){3}([01]?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))$/ + + property bool enabledSave: (ipMethodCombobox.currentIndex == 0 + || (ipMethodCombobox.currentIndex == 1 + && manualIPaddress.acceptableInput + && manualIPgateway.acceptableInput + && manualIPprefix.acceptableInput + && manualIPdns.acceptableInput)) + + actions.main: Kirigami.Action { + icon.name: "dialog-ok" + text: i18n("Save") + enabled: enabledSave + onTriggered: { + save() + kcm.pop() + } + } + + Kirigami.FormLayout { + Item { + Kirigami.FormData.label: i18n("General") + Kirigami.FormData.isSection: true + } + Controls.TextField { + id: ssidField + Kirigami.FormData.label: i18n("SSID:") + text: wirelessSettings["ssid"] ? wirelessSettings["ssid"] : "" + enabled: true + onTextChanged: { + ipSettings["id"] = text + } + } + Controls.CheckBox { + id: hidden + Kirigami.FormData.label: i18n("Hidden Network:") + checked: wirelessSettings["hidden"] ? wirelessSettings["hidden"] : false + onToggled: ipSettings["hidden"] = checked + } + + Kirigami.Separator { + Kirigami.FormData.label: i18n("Security") + Kirigami.FormData.isSection: true + } + + Controls.ComboBox { + id: securityCombobox + Kirigami.FormData.label: i18n("Security type:") + model: ListModel { + id: securityTypesModel + // FIXME just placeholder element to set "text" property as default + ListElement { + text: "placeholder" + } + function load() { + clear() + append({ "text": i18n("None"), "type": PlasmaNM.Enums.NoneSecurity }) + append({ "text": i18n("WEP Key"), "type": PlasmaNM.Enums.StaticWep }) + append({ "text": i18n("Dynamic WEP"), "type": PlasmaNM.Enums.DynamicWep }) + append({ "text": i18n("WPA/WPA2 Personal"), "type": PlasmaNM.Enums.Wpa2Psk }) + append({ "text": i18n("WPA/WPA2 Enterprise"), "type": PlasmaNM.Enums.Wpa2Eap }) + switch (securitySettings["key-mgmt"]) { + case "none": + securityCombobox.currentIndex = 0 + break + case "ieee8021x": + securityCombobox.currentIndex = 1 + break + case "wpa-psk": + securityCombobox.currentIndex = 3 + break + case "wpa-eap": + securityCombobox.currentIndex = 4 + break + default: + securityCombobox.currentIndex = 0 + break + } + } + } + + } + + PasswordField { + id: passwordField + Kirigami.FormData.label: i18n("Password:") + text: secrets["psk"] + visible: securityTypesModel.get(securityCombobox.currentIndex).type !== PlasmaNM.Enums.NoneSecurity + onTextChanged: securitySettings["password"] = text + } + + Controls.ComboBox { + id: authComboBox + Kirigami.FormData.label: i18n("Authentication:") + visible: securityCombobox.currentIndex === 2 + || securityCombobox.currentIndex === 4 + model: [i18n("TLS"), i18n("LEAP"), i18n("FAST"), i18n( + "Tunneled TLS"), i18n( + "Protected EAP")] // more - SIM, AKA, PWD ? + } + Controls.Label { + visible: securityCombobox.currentIndex !== 3 && securityCombobox.currentIndex !== 0 + text: "----Not yet implemented----" + color: "red" + } + + Kirigami.Separator { + Kirigami.FormData.label: i18n("IP settings") + Kirigami.FormData.isSection: true + } + + Controls.ComboBox { + id: ipMethodCombobox + model: [i18n("Automatic"), i18n("Manual")] + currentIndex: ipSettings["method"] === "manual" ? 1 : 0 + property var manualIp: currentIndex === 1 + onCurrentIndexChanged: { + ipSettings["method"] = currentIndex === 1 ? "manual" : "auto" + } + } + + Controls.TextField { + id: manualIPaddress + Kirigami.FormData.label: i18n("IP Address:") + visible: ipMethodCombobox.manualIp + placeholderText: "192.168.1.128" + text: ipSettings["address"] ? ipSettings["address"] : "" + onTextChanged: ipSettings["address"] = text + validator: RegularExpressionValidator { + regularExpression: ipRegex + } + } + + Controls.TextField { + id: manualIPgateway + Kirigami.FormData.label: i18n("Gateway:") + visible: ipMethodCombobox.manualIp + placeholderText: "192.168.1.1" + text: ipSettings["gateway"] ? ipSettings["gateway"] : "" + onTextChanged: ipSettings["gateway"] = text + validator: RegularExpressionValidator { + regularExpression: ipRegex + } + } + + Controls.TextField { + id: manualIPprefix + Kirigami.FormData.label: i18n("Network prefix length:") + visible: ipMethodCombobox.manualIp + placeholderText: "16" + text: ipSettings["prefix"] ? ipSettings["prefix"] : "" + onTextChanged: ipSettings["prefix"] = text + validator: IntValidator { + bottom: 1 + top: 32 + } + } + + Controls.TextField { + id: manualIPdns + Kirigami.FormData.label: i18n("DNS:") + visible: ipMethodCombobox.manualIp + placeholderText: "8.8.8.8" + text: ipSettings["dns"] ? ipSettings["dns"] : "" + onTextChanged: ipSettings["dns"] = text + validator: RegularExpressionValidator { + regularExpression: ipRegex + } + } + } + + Component.onCompleted: { + wirelessSettings = kcm.getConnectionSettings(path, "802-11-wireless") + securitySettings = kcm.getConnectionSettings(path, "802-11-wireless-security") + ipSettings = kcm.getConnectionSettings(path, "ipv4") + secrets = kcm.getConnectionSettings(path, "secrets") + + securityTypesModel.load() + } + + function save() { + var settings = ipSettings + settings["mode"] = "infrastructure" + securitySettings["type"] = securityTypesModel.get(securityCombobox.currentIndex).type + settings["802-11-wireless-security"] = securitySettings + + if (path) + kcm.updateConnectionFromQML(path, settings) + else + kcm.addConnectionFromQML(settings) + } +} diff --git a/kcms/wifi/package/contents/ui/PasswordField.qml b/kcms/wifi/package/contents/ui/PasswordField.qml new file mode 100644 index 00000000..2d8bd123 --- /dev/null +++ b/kcms/wifi/package/contents/ui/PasswordField.qml @@ -0,0 +1,21 @@ +/* + SPDX-FileCopyrightText: 2013-2017 Jan Grulich + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ + +import QtQuick 2.15 +import org.kde.kirigami 2.10 as Kirigami +import org.kde.plasma.networkmanagement 0.2 as PlasmaNM + +Kirigami.PasswordField { + property int securityType + placeholderText: i18n("Password…") + validator: RegularExpressionValidator { + regularExpression: if (securityType == PlasmaNM.Enums.StaticWep) { + /^(?:.{5}|[0-9a-fA-F]{10}|.{13}|[0-9a-fA-F]{26}){1}$/ + } else { + /^(?:.{8,64}){1}$/ + } + } +} diff --git a/kcms/wifi/package/contents/ui/main.qml b/kcms/wifi/package/contents/ui/main.qml new file mode 100644 index 00000000..ce76b266 --- /dev/null +++ b/kcms/wifi/package/contents/ui/main.qml @@ -0,0 +1,117 @@ +/* + SPDX-FileCopyrightText: 2017 Martin Kacej + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +import QtQuick 2.6 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.2 as Controls +import org.kde.plasma.networkmanagement 0.2 as PlasmaNM +import org.kde.kirigami 2.12 as Kirigami +import org.kde.kcm 1.2 + +ScrollViewKCM { + id: main + + PlasmaNM.Handler { + id: handler + } + + PlasmaNM.EnabledConnections { + id: enabledConnections + } + + PlasmaNM.NetworkModel { + id: connectionModel + } + + PlasmaNM.MobileProxyModel { + id: mobileProxyModel + sourceModel: connectionModel + showSavedMode: false + } + + Component.onCompleted: handler.requestScan() + + Timer { + id: scanTimer + interval: 10200 + repeat: true + running: parent.visible + + onTriggered: handler.requestScan() + } + + header: Kirigami.InlineMessage { + id: inlineError + showCloseButton: true + + type: Kirigami.MessageType.Warning + Connections { + target: handler + function onConnectionActivationFailed(connectionPath, message) { + inlineError.text = message; + inlineError.visible = true; + } + } + } + + ConnectDialog { + id: connectionDialog + } + + view: ListView { + id: view + + clip: true + currentIndex: -1 + + section.property: "Section" + section.delegate: Kirigami.ListSectionHeader { + text: section + } + + model: mobileProxyModel + delegate: ConnectionItemDelegate {} + + Kirigami.PlaceholderMessage { + anchors.centerIn: parent + width: parent.width - (Kirigami.Units.largeSpacing * 4) + visible: !enabledConnections.wirelessEnabled + text: i18n("Wi-Fi is disabled") + icon.name: "network-wireless-disconnected" + helpfulAction: Kirigami.Action { + iconName: "network-wireless-connected" + text: i18n("Enable") + onTriggered: handler.enableWireless(true) + } + } + } + + footer: Kirigami.ActionToolBar { + flat: false + actions: [ + Kirigami.Action { + text: i18n("Disable Wi-Fi") + icon.name: "network-disconnect" + visible: enabledConnections.wirelessEnabled + onTriggered: handler.enableWireless(false) + }, + Kirigami.Action { + text: i18n("Add Custom Connection") + icon.name: "list-add" + visible: enabledConnections.wirelessEnabled + onTriggered: kcm.push("NetworkSettings.qml") + }, + Kirigami.Action { + text: i18n("Show Saved Connections") + icon.name: "document-save" + onTriggered: mobileProxyModel.showSavedMode = !mobileProxyModel.showSavedMode + checkable: true + checked: false + visible: enabledConnections.wirelessEnabled + } + ] + } +} diff --git a/kcms/wifi/wifisettings.cpp b/kcms/wifi/wifisettings.cpp new file mode 100644 index 00000000..d73d0179 --- /dev/null +++ b/kcms/wifi/wifisettings.cpp @@ -0,0 +1,285 @@ +/* + SPDX-FileCopyrightText: 2018 Martin Kacej + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +#include "wifisettings.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +K_PLUGIN_CLASS_WITH_JSON(WifiSettings, "kcm_mobile_wifi.json") + +WifiSettings::WifiSettings(QObject *parent, const KPluginMetaData &metaData, const QVariantList &args) + : KQuickAddons::ConfigModule(parent, metaData, args) +{ +} + +WifiSettings::~WifiSettings() +{ +} + +QVariantMap WifiSettings::getConnectionSettings(const QString &connection, const QString &type) +{ + if (type.isEmpty()) + return QVariantMap(); + + NetworkManager::Connection::Ptr con = NetworkManager::findConnection(connection); + if (!con) + return QVariantMap(); + + if (type == "secrets") + return con->secrets(QLatin1String("802-11-wireless-security")).value().value(QLatin1String("802-11-wireless-security")); + + QVariantMap map = con->settings()->toMap().value(type); + if (type == "ipv4") { + NetworkManager::Ipv4Setting::Ptr ipSettings = NetworkManager::Ipv4Setting::Ptr(new NetworkManager::Ipv4Setting()); + ipSettings->fromMap(map); + map.clear(); + if (ipSettings->method() == NetworkManager::Ipv4Setting::Automatic) { + map.insert(QLatin1String("method"), QVariant(QLatin1String("auto"))); + } + + if (ipSettings->method() == NetworkManager::Ipv4Setting::Manual) { + map.insert(QLatin1String("method"), QVariant(QLatin1String("manual"))); + map.insert(QLatin1String("address"), QVariant(ipSettings->addresses().first().ip().toString())); + map.insert(QLatin1String("prefix"), QVariant(ipSettings->addresses().first().prefixLength())); + map.insert(QLatin1String("gateway"), QVariant(ipSettings->addresses().first().gateway().toString())); + map.insert(QLatin1String("dns"), QVariant(ipSettings->dns().first().toString())); + } + } + return map; +} + +QVariantMap WifiSettings::getActiveConnectionInfo(const QString &connection) +{ + if (connection.isEmpty()) + return QVariantMap(); + + NetworkManager::ActiveConnection::Ptr activeCon; + NetworkManager::Connection::Ptr con = NetworkManager::findConnection(connection); + foreach (const NetworkManager::ActiveConnection::Ptr &active, NetworkManager::activeConnections()) { + if (active->uuid() == con->uuid()) + activeCon = active; + } + + if (!activeCon) { + qWarning() << "Active" << connection << "not found"; + return QVariantMap(); + } + + QVariantMap map; + if (activeCon->ipV4Config().addresses().count() > 0) { + map.insert("address", QVariant(activeCon->ipV4Config().addresses().first().ip().toString())); + map.insert("prefix", QVariant(activeCon->ipV4Config().addresses().first().netmask().toString())); + } + map.insert("gateway", QVariant(activeCon->ipV4Config().gateway())); + if (activeCon->ipV4Config().nameservers().count() > 0) + map.insert("dns", QVariant(activeCon->ipV4Config().nameservers().first().toString())); + // qWarning() << map; + return map; +} + +void WifiSettings::addConnectionFromQML(const QVariantMap &QMLmap) +{ + if (QMLmap.isEmpty()) + return; + + NetworkManager::ConnectionSettings::Ptr connectionSettings = + NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wireless)); + connectionSettings->setId(QMLmap.value(QLatin1String("id")).toString()); + connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); + + NetworkManager::WirelessSetting::Ptr wirelessSettings = NetworkManager::WirelessSetting::Ptr(new NetworkManager::WirelessSetting()); + wirelessSettings->setSsid(QMLmap.value(QLatin1String("id")).toString().toUtf8()); + if (QMLmap["mode"].toString() == "infrastructure") { + wirelessSettings->setMode(NetworkManager::WirelessSetting::Infrastructure); + connectionSettings->setAutoconnect(true); + } + if (QMLmap["mode"].toString() == "ap") { + wirelessSettings->setMode(NetworkManager::WirelessSetting::Ap); + connectionSettings->setAutoconnect(false); + } + if (QMLmap.contains("hidden")) { + wirelessSettings->setHidden(QMLmap.value("hidden").toBool()); + } + + NetworkManager::Ipv4Setting::Ptr ipSettings = NetworkManager::Ipv4Setting::Ptr(new NetworkManager::Ipv4Setting()); + if (QMLmap["method"] == QLatin1String("auto")) { + ipSettings->setMethod(NetworkManager::Ipv4Setting::ConfigMethod::Automatic); + } + if (QMLmap["method"] == QLatin1String("shared")) { + ipSettings->setMethod(NetworkManager::Ipv4Setting::ConfigMethod::Shared); + } + if (QMLmap["method"] == QLatin1String("manual")) { + ipSettings->setMethod(NetworkManager::Ipv4Setting::ConfigMethod::Manual); + NetworkManager::IpAddress ipaddr; + ipaddr.setIp(QHostAddress(QMLmap["address"].toString())); + ipaddr.setPrefixLength(QMLmap["prefix"].toInt()); + ipaddr.setGateway(QHostAddress(QMLmap["gateway"].toString())); + ipSettings->setAddresses(QList({ipaddr})); + ipSettings->setDns(QList({QHostAddress(QMLmap["dns"].toString())})); + } + + NMVariantMapMap map = connectionSettings->toMap(); + map.insert("802-11-wireless", wirelessSettings->toMap()); + map.insert("ipv4", ipSettings->toMap()); + + // TODO can't set password for AP + // needs further inspection + + if (QMLmap.contains("802-11-wireless-security")) { + QVariantMap securMap = QMLmap["802-11-wireless-security"].toMap(); + int type = securMap["type"].toInt(); + if (!type == NetworkManager::NoneSecurity) { + NetworkManager::WirelessSecuritySetting::Ptr securitySettings = + NetworkManager::WirelessSecuritySetting::Ptr(new NetworkManager::WirelessSecuritySetting()); + if (type == NetworkManager::Wpa2Psk) { + if (QMLmap["mode"].toString() == "ap") { + securitySettings->setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaNone); + } else { + securitySettings->setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt::WpaPsk); + } + securitySettings->setAuthAlg(NetworkManager::WirelessSecuritySetting::AuthAlg::Open); + securitySettings->setPskFlags(NetworkManager::Setting::SecretFlagType::AgentOwned); + securitySettings->setPsk(securMap["password"].toString()); + } + if (type == NetworkManager::StaticWep) { + securitySettings->setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt::Wep); + securitySettings->setAuthAlg(NetworkManager::WirelessSecuritySetting::AuthAlg::Open); + securitySettings->setWepKeyType(NetworkManager::WirelessSecuritySetting::WepKeyType::Hex); + securitySettings->setWepKeyFlags(NetworkManager::Setting::SecretFlagType::AgentOwned); + securitySettings->setWepKey0(securMap["password"].toString()); + } + map.insert("802-11-wireless-security", securitySettings->toMap()); + } + } + // qWarning() << map; + NetworkManager::addConnection(map); +} + +void WifiSettings::updateConnectionFromQML(const QString &path, const QVariantMap &map) +{ + NetworkManager::Connection::Ptr con = NetworkManager::findConnection(path); + if (!con) + return; + + // qWarning() << map; + if (map.contains("id")) + con->settings()->setId(map.value("id").toString()); + + NMVariantMapMap toUpdateMap = con->settings()->toMap(); + + NetworkManager::Ipv4Setting::Ptr ipSetting = con->settings()->setting(NetworkManager::Setting::Ipv4).staticCast(); + if (ipSetting->method() == NetworkManager::Ipv4Setting::Automatic || ipSetting->method() == NetworkManager::Ipv4Setting::Manual) { + if (map.value("method") == "auto") { + ipSetting->setMethod(NetworkManager::Ipv4Setting::Automatic); + } + + if (map.value("method") == "manual") { + ipSetting->setMethod(NetworkManager::Ipv4Setting::ConfigMethod::Manual); + NetworkManager::IpAddress ipaddr; + ipaddr.setIp(QHostAddress(map["address"].toString())); + ipaddr.setPrefixLength(map["prefix"].toInt()); + ipaddr.setGateway(QHostAddress(map["gateway"].toString())); + ipSetting->setAddresses(QList({ipaddr})); + ipSetting->setDns(QList({QHostAddress(map["dns"].toString())})); + } + toUpdateMap.insert("ipv4", ipSetting->toMap()); + } + + NetworkManager::WirelessSetting::Ptr wirelessSetting = + con->settings()->setting(NetworkManager::Setting::Wireless).staticCast(); + if (map.contains("hidden")) { + wirelessSetting->setHidden(map.value("hidden").toBool()); + } + if (map.contains("id")) { + wirelessSetting->setSsid(map.value("id").toByteArray()); + } + toUpdateMap.insert("802-11-wireless", wirelessSetting->toMap()); + + if (map.contains("802-11-wireless-security")) { + QVariantMap secMap = map.value("802-11-wireless-security").toMap(); + // qWarning() << secMap; + NetworkManager::WirelessSecuritySetting::Ptr securitySetting = + con->settings()->setting(NetworkManager::Setting::WirelessSecurity).staticCast(); + if ((securitySetting->keyMgmt() == NetworkManager::WirelessSecuritySetting::Wep) && (secMap.value("type") == NetworkManager::StaticWep)) { + securitySetting->setWepKey0(secMap["password"].toString()); + } + + if ((securitySetting->keyMgmt() == NetworkManager::WirelessSecuritySetting::WpaPsk) && (secMap.value("type") == NetworkManager::Wpa2Psk)) { + securitySetting->setPsk(secMap["password"].toString()); + } + + // TODO can't set password for AP + // needs further inspection + if (wirelessSetting->mode() == NetworkManager::WirelessSetting::Ap) { + if (securitySetting->toMap().empty()) { // no security + if (secMap.value("type") == NetworkManager::Wpa2Psk) { + securitySetting->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaNone); + securitySetting->setPsk(secMap.value("password").toString()); + } + } + if (securitySetting->keyMgmt() == NetworkManager::WirelessSecuritySetting::WpaNone) { + if (secMap.empty()) { + securitySetting->setKeyMgmt(NetworkManager::WirelessSecuritySetting::Unknown); + } + if (secMap.value("type") == NetworkManager::Wpa2Psk) { + securitySetting->setPsk(secMap.value("password").toString()); + } + } + } + + toUpdateMap.insert("802-11-wireless-security", securitySetting->toMap()); + } + qWarning() << toUpdateMap; + con->update(toUpdateMap); +} + +QString WifiSettings::getAccessPointDevice() +{ + NetworkManager::WirelessDevice::Ptr device; + foreach (const NetworkManager::Device::Ptr &dev, NetworkManager::networkInterfaces()) { + if (dev->type() == NetworkManager::Device::Wifi) { + device = dev.staticCast(); + if (device->wirelessCapabilities().testFlag(NetworkManager::WirelessDevice::ApCap)) + break; // we have wireless device with access point capability + } + } + if (device) { + return device->uni(); + } else { + qWarning() << "No wireless device found"; + } + return QString(); +} + +QString WifiSettings::getAccessPointConnection() +{ + foreach (const NetworkManager::Connection::Ptr &con, NetworkManager::listConnections()) { + NetworkManager::Setting::Ptr d = con->settings()->setting(NetworkManager::Setting::Wireless); + if (!d.isNull()) { + if (d.staticCast()->mode() == NetworkManager::WirelessSetting::Ap) { + return con->path(); + } + } + } + return QString(); +} + +#include "wifisettings.moc" diff --git a/kcms/wifi/wifisettings.h b/kcms/wifi/wifisettings.h new file mode 100644 index 00000000..b469ef59 --- /dev/null +++ b/kcms/wifi/wifisettings.h @@ -0,0 +1,26 @@ +/* + SPDX-FileCopyrightText: 2018 Martin Kacej + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +#ifndef WIFISETTINGS_H +#define WIFISETTINGS_H + +#include + +class WifiSettings : public KQuickAddons::ConfigModule +{ + Q_OBJECT +public: + WifiSettings(QObject *parent, const KPluginMetaData &metaData, const QVariantList &args); + Q_INVOKABLE QVariantMap getConnectionSettings(const QString &connection, const QString &type); + Q_INVOKABLE QVariantMap getActiveConnectionInfo(const QString &connection); + Q_INVOKABLE void addConnectionFromQML(const QVariantMap &QMLmap); + Q_INVOKABLE void updateConnectionFromQML(const QString &path, const QVariantMap &map); + Q_INVOKABLE QString getAccessPointDevice(); + Q_INVOKABLE QString getAccessPointConnection(); + virtual ~WifiSettings(); +}; + +#endif // WIFISETTINGS_H