diff options
| author | ATMDA <atdma2600@gmail.com> | 2025-11-12 22:09:51 -0500 |
|---|---|---|
| committer | ATMDA <atdma2600@gmail.com> | 2025-11-12 22:09:51 -0500 |
| commit | b62a22b13d6d0c9704b58cf9d79ee89d4b156a74 (patch) | |
| tree | 3b6cc06ff5a0343a8ce3b2a7c73c00e077f78423 /modules/controlcenter | |
| parent | controlcenter: wireless panel rewrite (diff) | |
| download | caelestia-shell-b62a22b13d6d0c9704b58cf9d79ee89d4b156a74.tar.gz caelestia-shell-b62a22b13d6d0c9704b58cf9d79ee89d4b156a74.tar.bz2 caelestia-shell-b62a22b13d6d0c9704b58cf9d79ee89d4b156a74.zip | |
controlcenter: wireless panel refactoring
Diffstat (limited to 'modules/controlcenter')
4 files changed, 123 insertions, 96 deletions
diff --git a/modules/controlcenter/network/WirelessConnectionHelper.qml b/modules/controlcenter/network/WirelessConnectionHelper.qml deleted file mode 100644 index d63b359..0000000 --- a/modules/controlcenter/network/WirelessConnectionHelper.qml +++ /dev/null @@ -1,46 +0,0 @@ -pragma ComponentBehavior: Bound - -import ".." -import qs.services -import QtQuick - -QtObject { - id: root - - required property Session session - - function connectToNetwork(network: var): void { - if (!network) { - return; - } - - // If already connected to a different network, disconnect first - if (Network.active && Network.active.ssid !== network.ssid) { - Network.disconnectFromNetwork(); - Qt.callLater(() => { - performConnect(network); - }); - } else { - performConnect(network); - } - } - - function performConnect(network: var): void { - if (network.isSecure) { - // Try connecting without password first (in case it's saved) - Network.connectToNetworkWithPasswordCheck( - network.ssid, - network.isSecure, - () => { - // Callback: connection failed, show password dialog - root.session.network.showPasswordDialog = true; - root.session.network.pendingNetwork = network; - }, - network.bssid - ); - } else { - Network.connectToNetwork(network.ssid, "", network.bssid, null); - } - } -} - diff --git a/modules/controlcenter/network/WirelessDetails.qml b/modules/controlcenter/network/WirelessDetails.qml index e858fbc..418c463 100644 --- a/modules/controlcenter/network/WirelessDetails.qml +++ b/modules/controlcenter/network/WirelessDetails.qml @@ -16,33 +16,28 @@ Item { required property Session session readonly property var network: session.network.active - - readonly property var connectionHelper: WirelessConnectionHelper { - session: root.session - } Component.onCompleted: { - if (network && network.active) { - Network.updateWirelessDeviceDetails(); - } + updateDeviceDetails(); } onNetworkChanged: { - if (network && network.active) { - Network.updateWirelessDeviceDetails(); - } else { - Network.wirelessDeviceDetails = null; - } + updateDeviceDetails(); } Connections { target: Network function onActiveChanged() { - if (root.network && root.network.active && Network.active && Network.active.ssid === root.network.ssid) { - Network.updateWirelessDeviceDetails(); - } else if (!root.network || !root.network.active) { - Network.wirelessDeviceDetails = null; - } + updateDeviceDetails(); + } + } + + function updateDeviceDetails(): void { + // Only update details if the selected network is currently active + if (network && Network.active && Network.active.ssid === network.ssid) { + Network.updateWirelessDeviceDetails(); + } else { + Network.wirelessDeviceDetails = null; } } @@ -75,7 +70,7 @@ Item { checked: root.network?.active ?? false toggle.onToggled: { if (checked) { - root.connectionHelper.connectToNetwork(root.network); + handleConnect(); } else { Network.disconnectFromNetwork(); } @@ -154,5 +149,45 @@ Item { } } + + function handleConnect(): void { + // If already connected to a different network, disconnect first + if (Network.active && Network.active.ssid !== root.network.ssid) { + Network.disconnectFromNetwork(); + Qt.callLater(() => { + connectToNetwork(); + }); + } else { + connectToNetwork(); + } + } + + function connectToNetwork(): void { + if (root.network.isSecure) { + // Check if we have a saved connection profile for this network + const hasSavedProfile = Network.savedConnections.includes(root.network.ssid); + + if (hasSavedProfile) { + // Try connecting with saved password - don't show dialog if it fails + // The saved password should work, but if connection fails for other reasons, + // we'll let the user try manually later + Network.connectToNetwork(root.network.ssid, "", root.network.bssid, null); + } else { + // No saved profile, try connecting without password first + Network.connectToNetworkWithPasswordCheck( + root.network.ssid, + root.network.isSecure, + () => { + // Callback: connection failed, show password dialog + root.session.network.showPasswordDialog = true; + root.session.network.pendingNetwork = root.network; + }, + root.network.bssid + ); + } + } else { + Network.connectToNetwork(root.network.ssid, "", root.network.bssid, null); + } + } } diff --git a/modules/controlcenter/network/WirelessList.qml b/modules/controlcenter/network/WirelessList.qml index 1a4ba00..c64c4be 100644 --- a/modules/controlcenter/network/WirelessList.qml +++ b/modules/controlcenter/network/WirelessList.qml @@ -15,10 +15,6 @@ ColumnLayout { required property Session session - readonly property var connectionHelper: WirelessConnectionHelper { - session: root.session - } - spacing: Appearance.spacing.small RowLayout { @@ -185,7 +181,7 @@ ColumnLayout { if (modelData.active) { Network.disconnectFromNetwork(); } else { - root.connectionHelper.connectToNetwork(modelData); + handleConnect(modelData); } } } @@ -203,5 +199,45 @@ ColumnLayout { implicitHeight: rowLayout.implicitHeight + Appearance.padding.normal * 2 } } + + function handleConnect(network): void { + // If already connected to a different network, disconnect first + if (Network.active && Network.active.ssid !== network.ssid) { + Network.disconnectFromNetwork(); + Qt.callLater(() => { + connectToNetwork(network); + }); + } else { + connectToNetwork(network); + } + } + + function connectToNetwork(network): void { + if (network.isSecure) { + // Check if we have a saved connection profile for this network + const hasSavedProfile = Network.savedConnections.includes(network.ssid); + + if (hasSavedProfile) { + // Try connecting with saved password - don't show dialog if it fails + // The saved password should work, but if connection fails for other reasons, + // we'll let the user try manually later + Network.connectToNetwork(network.ssid, "", network.bssid, null); + } else { + // No saved profile, try connecting without password first + Network.connectToNetworkWithPasswordCheck( + network.ssid, + network.isSecure, + () => { + // Callback: connection failed, show password dialog + root.session.network.showPasswordDialog = true; + root.session.network.pendingNetwork = network; + }, + network.bssid + ); + } + } else { + Network.connectToNetwork(network.ssid, "", network.bssid, null); + } + } } diff --git a/modules/controlcenter/network/WirelessPasswordDialog.qml b/modules/controlcenter/network/WirelessPasswordDialog.qml index 778fb4f..df8a8cf 100644 --- a/modules/controlcenter/network/WirelessPasswordDialog.qml +++ b/modules/controlcenter/network/WirelessPasswordDialog.qml @@ -243,6 +243,32 @@ Item { } } + function checkConnectionStatus(): void { + if (!root.visible || !connectButton.connecting) { + return; + } + + // Check if we're connected to the target network + if (root.network && Network.active && Network.active.ssid === root.network.ssid) { + // Successfully connected + connectionMonitor.stop(); + connectButton.connecting = false; + connectButton.text = qsTr("Connect"); + closeDialog(); + return; + } + + // Check for connection errors + const status = Network.connectionStatus; + if (status.includes("Error") || status.includes("error") || status.includes("failed")) { + // Connection failed + connectionMonitor.stop(); + connectButton.connecting = false; + connectButton.enabled = true; + connectButton.text = qsTr("Connect"); + } + } + Timer { id: connectionMonitor interval: 1000 @@ -250,39 +276,15 @@ Item { triggeredOnStart: false onTriggered: { - // Check if we're connected to the target network - if (root.network && Network.active && Network.active.ssid === root.network.ssid) { - // Successfully connected - stop(); - connectButton.connecting = false; - connectButton.text = qsTr("Connect"); - closeDialog(); - } else if (connectButton.connecting) { - // Still connecting, check status - const status = Network.connectionStatus; - if (status.includes("Error") || status.includes("error") || status.includes("failed")) { - // Connection failed - stop(); - connectButton.connecting = false; - connectButton.enabled = true; - connectButton.text = qsTr("Connect"); - } - } else { - // Not connecting anymore - stop(); - } + checkConnectionStatus(); } } Connections { target: Network function onActiveChanged() { - if (root.visible && root.network && Network.active && Network.active.ssid === root.network.ssid) { - // Connected successfully - connectionMonitor.stop(); - connectButton.connecting = false; - connectButton.text = qsTr("Connect"); - closeDialog(); + if (root.visible) { + checkConnectionStatus(); } } } |