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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -17,33 +17,28 @@ Item {
|
||||||
required property Session session
|
required property Session session
|
||||||
readonly property var network: session.network.active
|
readonly property var network: session.network.active
|
||||||
|
|
||||||
readonly property var connectionHelper: WirelessConnectionHelper {
|
|
||||||
session: root.session
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (network && network.active) {
|
updateDeviceDetails();
|
||||||
Network.updateWirelessDeviceDetails();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onNetworkChanged: {
|
onNetworkChanged: {
|
||||||
if (network && network.active) {
|
updateDeviceDetails();
|
||||||
Network.updateWirelessDeviceDetails();
|
|
||||||
} else {
|
|
||||||
Network.wirelessDeviceDetails = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: Network
|
target: Network
|
||||||
function onActiveChanged() {
|
function onActiveChanged() {
|
||||||
if (root.network && root.network.active && Network.active && Network.active.ssid === root.network.ssid) {
|
updateDeviceDetails();
|
||||||
Network.updateWirelessDeviceDetails();
|
|
||||||
} else if (!root.network || !root.network.active) {
|
|
||||||
Network.wirelessDeviceDetails = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledFlickable {
|
StyledFlickable {
|
||||||
|
|
@ -75,7 +70,7 @@ Item {
|
||||||
checked: root.network?.active ?? false
|
checked: root.network?.active ?? false
|
||||||
toggle.onToggled: {
|
toggle.onToggled: {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
root.connectionHelper.connectToNetwork(root.network);
|
handleConnect();
|
||||||
} else {
|
} else {
|
||||||
Network.disconnectFromNetwork();
|
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
|
required property Session session
|
||||||
|
|
||||||
readonly property var connectionHelper: WirelessConnectionHelper {
|
|
||||||
session: root.session
|
|
||||||
}
|
|
||||||
|
|
||||||
spacing: Appearance.spacing.small
|
spacing: Appearance.spacing.small
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
|
|
@ -185,7 +181,7 @@ ColumnLayout {
|
||||||
if (modelData.active) {
|
if (modelData.active) {
|
||||||
Network.disconnectFromNetwork();
|
Network.disconnectFromNetwork();
|
||||||
} else {
|
} else {
|
||||||
root.connectionHelper.connectToNetwork(modelData);
|
handleConnect(modelData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -203,5 +199,45 @@ ColumnLayout {
|
||||||
implicitHeight: rowLayout.implicitHeight + Appearance.padding.normal * 2
|
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 {
|
Timer {
|
||||||
id: connectionMonitor
|
id: connectionMonitor
|
||||||
interval: 1000
|
interval: 1000
|
||||||
|
|
@ -250,39 +276,15 @@ Item {
|
||||||
triggeredOnStart: false
|
triggeredOnStart: false
|
||||||
|
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
// Check if we're connected to the target network
|
checkConnectionStatus();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: Network
|
target: Network
|
||||||
function onActiveChanged() {
|
function onActiveChanged() {
|
||||||
if (root.visible && root.network && Network.active && Network.active.ssid === root.network.ssid) {
|
if (root.visible) {
|
||||||
// Connected successfully
|
checkConnectionStatus();
|
||||||
connectionMonitor.stop();
|
|
||||||
connectButton.connecting = false;
|
|
||||||
connectButton.text = qsTr("Connect");
|
|
||||||
closeDialog();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue