controlcenter: wireless panel refactoring
This commit is contained in:
parent
fc223237f0
commit
b62a22b13d
4 changed files with 123 additions and 96 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue