Commit 1c9d021d authored by Tobias Fella's avatar Tobias Fella

Create a hotspot KCM for Plasma Mobile

Summary: Implements T12895. Might include things like bluetooth and usb tethering in the future when implemented

Test Plan: Edit SSID and password, start, connect

Reviewers: #vdg, jgrulich, nicolasfella, cblack

Reviewed By: #vdg, jgrulich, nicolasfella, cblack

Subscribers: cblack, nicolasfella, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D29019
parent 2e6878a3
......@@ -3,4 +3,5 @@ if (WITH_MODEMMANAGER_SUPPORT)
endif()
add_subdirectory(wifi)
add_subdirectory(hotspot)
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)
#!/usr/bin/env bash
$XGETTEXT `find . -name \*.cpp -o -name \*.qml` -o $podir/kcm_mobile_hotspot.pot
/*
* Copyright 2020 Tobias Fella <fella@posteo.de>
*
* 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 <KPluginFactory>
#include <KLocalizedString>
#include <KAboutData>
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"
/*
* Copyright 2020 Tobias Fella <fella@posteo.de>
*
* 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 <KQuickAddons/ConfigModule>
class HotspotSettings : public KQuickAddons::ConfigModule
{
Q_OBJECT
public:
HotspotSettings(QObject *parent, const QVariantList &args);
virtual ~HotspotSettings() override;
};
#endif // HOTSPOTSETTINGS_H
/*
* Copyright 2020 Tobias Fella <fella@posteo.de>
*
* 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()
}
}
}
}
}
[Desktop Entry]
Name=Hotspot
Comment=Wi-Fi Hotspots
Encoding=UTF-8
Type=Service
Icon=network-wireless-hotspot
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
/*
* Copyright 2017-2018 Martin Kacej <m.kacej@atlas.sk>
*
* 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)
}
}
......@@ -106,15 +106,6 @@ ScrollViewKCM {
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")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment