diff --git a/mobile/CMakeLists.txt b/mobile/CMakeLists.txt --- a/mobile/CMakeLists.txt +++ b/mobile/CMakeLists.txt @@ -3,4 +3,5 @@ endif() add_subdirectory(wifi) +add_subdirectory(hotspot) diff --git a/mobile/hotspot/CMakeLists.txt b/mobile/hotspot/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mobile/hotspot/CMakeLists.txt @@ -0,0 +1,17 @@ +set (hotspotsettings_SRCS hotspotsettings.cpp) + +add_library(kcm_mobile_hotspot MODULE ${hotspotsettings_SRCS}) + +target_link_libraries(kcm_mobile_hotspot + Qt5::Quick + Qt5::Qml + KF5::I18n + KF5::CoreAddons + KF5::QuickAddons +) + +kcoreaddons_desktop_to_json(kcm_mobile_hotspot "package/metadata.desktop") + +install(FILES package/metadata.desktop RENAME hotspotsettings.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) +install(TARGETS kcm_mobile_hotspot DESTINATION ${PLUGIN_INSTALL_DIR}/kcms) +kpackage_install_package(package kcm_mobile_hotspot kcms) diff --git a/mobile/hotspot/Messages.sh b/mobile/hotspot/Messages.sh new file mode 100644 --- /dev/null +++ b/mobile/hotspot/Messages.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +$XGETTEXT `find . -name \*.cpp -o -name \*.qml` -o $podir/kcm_mobile_hotspot.pot diff --git a/mobile/hotspot/hotspotsettings.h b/mobile/hotspot/hotspotsettings.h new file mode 100644 --- /dev/null +++ b/mobile/hotspot/hotspotsettings.h @@ -0,0 +1,35 @@ +/* + * Copyright 2020 Tobias Fella + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 or + * (at your option) any later version. + * + * 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#ifndef HOTSPOTSETTINGS_H +#define HOTSPOTSETTINGS_H + + +#include + +class HotspotSettings : public KQuickAddons::ConfigModule +{ + Q_OBJECT +public: + HotspotSettings(QObject *parent, const QVariantList &args); + virtual ~HotspotSettings() override; +}; + +#endif // HOTSPOTSETTINGS_H diff --git a/mobile/hotspot/hotspotsettings.cpp b/mobile/hotspot/hotspotsettings.cpp new file mode 100644 --- /dev/null +++ b/mobile/hotspot/hotspotsettings.cpp @@ -0,0 +1,40 @@ +/* + * Copyright 2020 Tobias Fella + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 or + * (at your option) any later version. + * + * 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "hotspotsettings.h" + +#include +#include +#include + +K_PLUGIN_CLASS_WITH_JSON(HotspotSettings, "metadata.json") + +HotspotSettings::HotspotSettings(QObject* parent, const QVariantList& args) : KQuickAddons::ConfigModule(parent, args) +{ + KAboutData* about = new KAboutData("kcm_mobile_hotspot", i18n("Hotspot"), + "0.1", QString(), KAboutLicense::LGPL); + about->addAuthor(i18n("Tobias Fella"), QString(), "fella@posteo.de"); + setAboutData(about); +} + +HotspotSettings::~HotspotSettings() +{ +} + +#include "hotspotsettings.moc" diff --git a/mobile/hotspot/package/contents/ui/main.qml b/mobile/hotspot/package/contents/ui/main.qml new file mode 100644 --- /dev/null +++ b/mobile/hotspot/package/contents/ui/main.qml @@ -0,0 +1,74 @@ +/* + * Copyright 2020 Tobias Fella + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 or + * (at your option) any later version. + * + * 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +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 + } + + PlasmaNM.Configuration { + id: configuration + } + + 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: configuration.hotspotName + } + + Kirigami.PasswordField { + id: hotspotPassword + Kirigami.FormData.label: i18n("Password:") + text: configuration.hotspotPassword + } + + Controls.Button { + text: i18n("Save") + onClicked: { + configuration.hotspotName = hotspotName.text + configuration.hotspotPassword = hotspotPassword.text + if (hotspotToggle.checked) { + handler.stopHotspot() + handler.createHotspot() + } + } + } + } +} diff --git a/mobile/hotspot/package/metadata.desktop b/mobile/hotspot/package/metadata.desktop new file mode 100644 --- /dev/null +++ b/mobile/hotspot/package/metadata.desktop @@ -0,0 +1,19 @@ +[Desktop Entry] +Name=Hotspot +Comment=Wi-Fi Hotspots +Encoding=UTF-8 +Type=Service +Icon=network-wireless-symbolic +X-KDE-ServiceTypes=KCModule +X-KDE-Library=kcm_mobile_hotspot +X-KDE-PluginInfo-Author=Tobias Fella +X-KDE-PluginInfo-Email=fella@posteo.de +X-KDE-PluginInfo-Name=kcm_mobile_hotspot +X-KDE-PluginInfo-Version=0.1 +X-KDE-PluginInfo-Website=https://plasma-mobile.org/ +X-KDE-PluginInfo-Category=System Information +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-FormFactors=handset,tablet,mediacenter +X-Plasma-Package=kcm_mobile_hotspot +X-Plasma-MainScript=ui/main.qml diff --git a/mobile/wifi/package/contents/ui/TetheringSetting.qml b/mobile/wifi/package/contents/ui/TetheringSetting.qml deleted file mode 100644 --- a/mobile/wifi/package/contents/ui/TetheringSetting.qml +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright 2017-2018 Martin Kacej - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 or - * (at your option) any later version. - * - * 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 Library General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick 2.6 -import QtQuick.Layouts 1.3 -import QtQuick.Controls 2.2 as Controls -import org.kde.plasma.networkmanagement 0.2 as PlasmaNM -import org.kde.kirigami 2.10 as Kirigami - -Kirigami.ScrollablePage { - property var connectPath - property var devicePath - property alias name: hotSpotName.text - - title: i18n("Wi-Fi Hotspot") - - ColumnLayout { - spacing: Kirigami.Units.gridUnit - Kirigami.Separator{} - - RowLayout { - id: hotSpotStatus - spacing: Kirigami.Units.gridUnit - property alias text: hotSpotStatusLabel.text - Controls.Label { - id: hotSpotStatusLabel - } - Kirigami.Icon { - id: hotSpotStatusIcon - width: Kirigami.Units.iconSizes.smallMedium - height: width - source: "network-wireless-disconnected" - } - } - Controls.Button { - id: hotSpotConfigButton - checkable: true - checked: false - text: i18n("Configure") - onPressed: { - loadSettings() - } - } - Column { - id: hotSpotSettings - width: parent.width / 2 - visible: hotSpotConfigButton.checked - Column { - width: parent.width - Controls.Label { - text: i18n("SSID") - font.weight: Font.Bold - } - - Controls.TextField { - id: hotSpotName - width: parent.width / 2 - placeholderText: i18n("My Hotspot") - } - } - RowLayout { - Controls.CheckBox { - id: hotSpotConfigHidden - checked: false - } - - Controls.Label { - text: i18n("Hide this network") - } - } - RowLayout { - Controls.CheckBox { - id: hotSpotConfigSecurity - checked: false - } - - Controls.Label { - text: i18n("Protect hotspot with WPA2/PSK password") - } - } - PasswordField { - id: hotSpotConfigPassword - width: parent.width / 2 - visible: hotSpotConfigSecurity.checked - securityType: PlasmaNM.Enums.Wpa2Psk - } - Controls.Button { - text: i18n("Save Hotspot configuration") - enabled: name && (!hotSpotConfigSecurity.checked || (hotSpotConfigSecurity.checked && hotSpotConfigPassword.acceptableInput)) - onPressed: { - saveSettings() - hotSpotConfigButton.checked = false - } - } - } - } - - actions { - main: Kirigami.Action { - icon.name: checked ? "network-wireless-disconnected" : "network-wireless-connected" - text: checked ? i18n("Disable Wi-Fi Hotspot") : i18n("Enable Wi-Fi Hotspot") - checkable: true - onCheckedChanged: { - if (checked) { - initTethering() - } else { - disableTethering() - } - } - } - right: Kirigami.Action { - icon.name: "dialog-close" - text: i18n("Cancel") - onTriggered: kcm.pop() - } - } - - Component.onCompleted: { - hotSpotStatus.text = i18n("Hotspot is inactive") - checkTethering() - } - - function checkTethering() { - devicePath = kcm.getAccessPointDevice(); - if (devicePath === "") { - hotSpotStatus.text = i18n("Not possible to start Access point.") - hotSpotStatusIcon.source = "dialog-close" - hotSpotSwitch.enabled = false - return - } - connectPath = kcm.getAccessPointConnection() - var map = kcm.getActiveConnectionInfo(connectPath); - if (map["address"]) { // means AP connection is active - hotSpotSwitch.checked = true - hotSpotStatus.text = i18n("Access point running: %1", name) - } - } - - function initTethering() { - connectPath = kcm.getAccessPointConnection() - if (connectPath === "") { - hotSpotStatus.text = i18n("No suitable configuration found.") - hotSpotStatusIcon.source = "error" - hotSpotSwitch.checked = false - return - } - loadSettings() - handler.activateConnection(connectPath,devicePath,"") - hotSpotStatus.text = i18n("Access point running: %1", name) - hotSpotStatusIcon.source = "network-wireless-symbolic" - } - - function disableTethering(){ - if (connectPath !== "") { - handler.deactivateConnection(connectPath,devicePath) - hotSpotStatus.text = i18n("Hotspot is inactive") - hotSpotStatusIcon.source = "network-wireless-disconnected" - } - } - - function saveSettings() { - var map = {} - map["id"] = name - map["mode"] = "ap" - map["method"] = "shared" - map["hidden"] = hotSpotConfigHidden.checked - if (hotSpotConfigSecurity.checked) { - var securityMap = {} - securityMap["type"] = PlasmaNM.Enums.Wpa2Psk - securityMap["password"] = hotSpotConfigPassword.text - map["802-11-wireless-security"] = securityMap - } - if (connectPath === "") { - kcm.addConnectionFromQML(map) - } else { - kcm.updateConnectionFromQML(connectPath,map) - } - } - - function loadSettings() { - var map = kcm.getConnectionSettings(connectPath,"connection"); - name = map["id"] - map = kcm.getConnectionSettings(connectPath,"802-11-wireless"); - if (map["hidden"]) - hotSpotConfigHidden.checked = map["hidden"] - map = kcm.getConnectionSettings(connectPath,"802-11-wireless-security") - if (map["key-mgmt"]) { - hotSpotConfigSecurity.checked = true - } - hotSpotStatus.text = i18n("Access point available: %1", name) - } -} diff --git a/mobile/wifi/package/contents/ui/main.qml b/mobile/wifi/package/contents/ui/main.qml --- a/mobile/wifi/package/contents/ui/main.qml +++ b/mobile/wifi/package/contents/ui/main.qml @@ -106,15 +106,6 @@ contextDrawer.close() } }, - - Kirigami.Action { - iconName: "edit" - text: i18n("Create Hotspot") - onTriggered: { - kcm.push("TetheringSetting.qml") - contextDrawer.close() - } - }, Kirigami.Action { iconName: "edit" text: i18n("Saved Connections")