diff --git a/components/mobileshell/CMakeLists.txt b/components/mobileshell/CMakeLists.txt index 729e4966..7b13e7ac 100644 --- a/components/mobileshell/CMakeLists.txt +++ b/components/mobileshell/CMakeLists.txt @@ -17,13 +17,16 @@ target_include_directories(mobileshellplugin PRIVATE notifications) target_sources(mobileshellplugin PRIVATE ${mobileshellplugin_SRCS}) # Singleton declarations -set_source_files_properties(qml/components/AppLaunch.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) -set_source_files_properties(qml/components/Constants.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) -set_source_files_properties(qml/dataproviders/AudioInfo.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) -set_source_files_properties(qml/dataproviders/BatteryInfo.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) -set_source_files_properties(qml/dataproviders/BluetoothInfo.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) -set_source_files_properties(qml/dataproviders/SignalStrengthInfo.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) -set_source_files_properties(qml/popups/PopupProviderLoader.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) +set_source_files_properties( + qml/components/AppLaunch.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE + qml/components/Constants.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE + qml/dataproviders/AudioInfo.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE + qml/dataproviders/BatteryInfo.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE + qml/dataproviders/BluetoothInfo.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE + qml/dataproviders/NetworkInfo.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE + qml/dataproviders/SignalStrengthInfo.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE + qml/popups/PopupProviderLoader.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE +) # Include qml and js files within ./qml/ file(GLOB_RECURSE _qml_sources diff --git a/components/mobileshell/qml/dataproviders/NetworkInfo.qml b/components/mobileshell/qml/dataproviders/NetworkInfo.qml new file mode 100644 index 00000000..1c7ff344 --- /dev/null +++ b/components/mobileshell/qml/dataproviders/NetworkInfo.qml @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2025 Devin Lin +// SPDX-License-Identifier: GPL-2.0-or-later + +pragma Singleton + +import QtQuick + +import org.kde.plasma.networkmanagement as PlasmaNM + +QtObject { + // Initialization of PlasmaNM.Handler is quite heavy, initialize it once for the shell as a singleton. + readonly property PlasmaNM.Handler handler: PlasmaNM.Handler {} + + readonly property PlasmaNM.WirelessStatus wirelessStatus: PlasmaNM.WirelessStatus {} +} \ No newline at end of file diff --git a/components/mobileshell/qml/statusbar/indicators/InternetIndicator.qml b/components/mobileshell/qml/statusbar/indicators/InternetIndicator.qml index 1f7e3ff2..2ed7adbf 100644 --- a/components/mobileshell/qml/statusbar/indicators/InternetIndicator.qml +++ b/components/mobileshell/qml/statusbar/indicators/InternetIndicator.qml @@ -15,23 +15,9 @@ import org.kde.kirigami as Kirigami Item { id: connectionIcon - // data - readonly property string icon: wirelessStatus.hotspotSSID.length !== 0 ? "network-wireless-hotspot" : connectionIconProvider.connectionIcon readonly property bool indicatorRunning: connectionIconProvider.connecting - readonly property var networkStatus: PlasmaNM.NetworkStatus { - id: networkStatus - } - - readonly property var networkModel: PlasmaNM.NetworkModel { - id: connectionModel - } - - readonly property var handler: PlasmaNM.Handler { - id: handler - } - readonly property var wirelessStatus: PlasmaNM.WirelessStatus { id: wirelessStatus } diff --git a/quicksettings/airplanemode/contents/ui/main.qml b/quicksettings/airplanemode/contents/ui/main.qml index 83e46bc5..5e5ca317 100644 --- a/quicksettings/airplanemode/contents/ui/main.qml +++ b/quicksettings/airplanemode/contents/ui/main.qml @@ -7,6 +7,7 @@ import org.kde.plasma.networkmanagement as PlasmaNM import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS +import org.kde.plasma.private.mobileshell as MobileShell QS.QuickSetting { text: i18n("Airplane Mode") @@ -14,12 +15,8 @@ QS.QuickSetting { status: "" enabled: PlasmaNM.Configuration.airplaneModeEnabled - PlasmaNM.Handler { - id: nmHandler - } - function toggle() { - nmHandler.enableAirplaneMode(!PlasmaNM.Configuration.airplaneModeEnabled); + MobileShell.NetworkInfo.handler.enableAirplaneMode(!PlasmaNM.Configuration.airplaneModeEnabled); PlasmaNM.Configuration.airplaneModeEnabled = !PlasmaNM.Configuration.airplaneModeEnabled; } } diff --git a/quicksettings/hotspot/contents/ui/main.qml b/quicksettings/hotspot/contents/ui/main.qml index ab412a83..d36ae218 100644 --- a/quicksettings/hotspot/contents/ui/main.qml +++ b/quicksettings/hotspot/contents/ui/main.qml @@ -3,32 +3,24 @@ import QtQuick 2.15 -import org.kde.plasma.networkmanagement as PlasmaNM import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS +import org.kde.plasma.private.mobileshell as MobileShell QS.QuickSetting { id: root - PlasmaNM.Handler { - id: nmHandler - } - - PlasmaNM.WirelessStatus { - id: wirelessStatus - } - text: i18n("Hotspot") icon: "network-wireless-hotspot" - enabled: wirelessStatus.hotspotSSID.length !== 0 - status: enabled ? wirelessStatus.hotspotSSID : "" + enabled: MobileShell.NetworkInfo.wirelessStatus.hotspotSSID.length !== 0 + status: enabled ? MobileShell.NetworkInfo.wirelessStatus.hotspotSSID : "" settingsCommand: "plasma-open-settings kcm_mobile_hotspot" function toggle() { if (!enabled) { - nmHandler.createHotspot(); + MobileShell.NetworkInfo.handler.createHotspot(); } else { - nmHandler.stopHotspot(); + MobileShell.NetworkInfo.handler.stopHotspot(); } } } diff --git a/quicksettings/wifi/contents/ui/main.qml b/quicksettings/wifi/contents/ui/main.qml index cb33dfa9..bbcbeec1 100644 --- a/quicksettings/wifi/contents/ui/main.qml +++ b/quicksettings/wifi/contents/ui/main.qml @@ -5,26 +5,20 @@ import QtQuick 2.15 import org.kde.plasma.networkmanagement as PlasmaNM import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS +import org.kde.plasma.private.mobileshell as MobileShell QS.QuickSetting { - PlasmaNM.Handler { - id: nmHandler - } - PlasmaNM.EnabledConnections { id: enabledConnections } - PlasmaNM.WirelessStatus { - id: wirelessStatus - } - text: i18n("Wi-Fi") - status: enabledConnections.wirelessEnabled ? wirelessStatus.wifiSSID : "" + status: enabledConnections.wirelessEnabled ? MobileShell.NetworkInfo.wirelessStatus.wifiSSID : "" icon: enabledConnections.wirelessEnabled ? "network-wireless" : "network-wireless-disconnected" settingsCommand: "plasma-open-settings kcm_mobile_wifi" - function toggle() { - nmHandler.enableWireless(!enabledConnections.wirelessEnabled) - } enabled: enabledConnections.wirelessEnabled + + function toggle() { + MobileShell.NetworkInfo.handler.enableWireless(!enabledConnections.wirelessEnabled); + } }