controlcenter: password input errors/wrong pass

This commit is contained in:
ATMDA 2025-11-15 01:31:53 -05:00
parent 6a92f985d8
commit 05b0660627
4 changed files with 552 additions and 449 deletions

View file

@ -32,14 +32,22 @@ ColumnLayout {
} }
} }
// Force focus to password container when popout becomes active // Force focus to password container when popout becomes active
Qt.callLater(() => { // Use Timer for actual delay to ensure dialog is fully rendered
passwordContainer.forceActiveFocus(); focusTimer.start();
}, 100); });
}, 100);
} }
} }
} }
Timer {
id: focusTimer
interval: 150
onTriggered: {
root.forceActiveFocus();
passwordContainer.forceActiveFocus();
}
}
spacing: Appearance.spacing.normal spacing: Appearance.spacing.normal
implicitWidth: 400 implicitWidth: 400
@ -51,19 +59,15 @@ ColumnLayout {
Component.onCompleted: { Component.onCompleted: {
if (shouldBeVisible) { if (shouldBeVisible) {
Qt.callLater(() => { // Use Timer for actual delay to ensure dialog is fully rendered
root.forceActiveFocus(); focusTimer.start();
passwordContainer.forceActiveFocus();
}, 150);
} }
} }
onShouldBeVisibleChanged: { onShouldBeVisibleChanged: {
if (shouldBeVisible) { if (shouldBeVisible) {
Qt.callLater(() => { // Use Timer for actual delay to ensure dialog is fully rendered
root.forceActiveFocus(); focusTimer.start();
passwordContainer.forceActiveFocus();
}, 150);
} }
} }
@ -243,20 +247,26 @@ ColumnLayout {
target: root target: root
function onShouldBeVisibleChanged(): void { function onShouldBeVisibleChanged(): void {
if (root.shouldBeVisible) { if (root.shouldBeVisible) {
Qt.callLater(() => { // Use Timer for actual delay to ensure focus works correctly
passwordContainer.forceActiveFocus(); passwordFocusTimer.start();
}, 50);
passwordContainer.passwordBuffer = ""; passwordContainer.passwordBuffer = "";
connectButton.hasError = false; connectButton.hasError = false;
} }
} }
} }
Timer {
id: passwordFocusTimer
interval: 50
onTriggered: {
passwordContainer.forceActiveFocus();
}
}
Component.onCompleted: { Component.onCompleted: {
if (root.shouldBeVisible) { if (root.shouldBeVisible) {
Qt.callLater(() => { // Use Timer for actual delay to ensure focus works correctly
passwordContainer.forceActiveFocus(); passwordFocusTimer.start();
}, 100);
} }
} }
@ -489,22 +499,8 @@ ColumnLayout {
if (isConnected) { if (isConnected) {
// Successfully connected - give it a moment for network list to update // Successfully connected - give it a moment for network list to update
Qt.callLater(() => { // Use Timer for actual delay
// Double-check connection is still active connectionSuccessTimer.start();
if (root.shouldBeVisible && Nmcli.active && Nmcli.active.ssid) {
const stillConnected = Nmcli.active.ssid.toLowerCase().trim() === root.network.ssid.toLowerCase().trim();
if (stillConnected) {
connectionMonitor.stop();
connectButton.connecting = false;
connectButton.text = qsTr("Connect");
// Return to network popout on successful connection
if (root.wrapper.currentName === "wirelesspassword") {
root.wrapper.currentName = "network";
}
closeDialog();
}
}
}, 500);
return; return;
} }
@ -545,6 +541,27 @@ ColumnLayout {
} }
} }
Timer {
id: connectionSuccessTimer
interval: 500
onTriggered: {
// Double-check connection is still active
if (root.shouldBeVisible && Nmcli.active && Nmcli.active.ssid) {
const stillConnected = Nmcli.active.ssid.toLowerCase().trim() === root.network.ssid.toLowerCase().trim();
if (stillConnected) {
connectionMonitor.stop();
connectButton.connecting = false;
connectButton.text = qsTr("Connect");
// Return to network popout on successful connection
if (root.wrapper.currentName === "wirelesspassword") {
root.wrapper.currentName = "network";
}
closeDialog();
}
}
}
}
Connections { Connections {
target: Nmcli target: Nmcli
function onActiveChanged() { function onActiveChanged() {

View file

@ -15,13 +15,17 @@ import Quickshell.Widgets
import QtQuick import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
RowLayout { Item {
id: root id: root
required property Session session required property Session session
anchors.fill: parent anchors.fill: parent
RowLayout {
id: contentLayout
anchors.fill: parent
spacing: 0 spacing: 0
Item { Item {
@ -287,15 +291,18 @@ RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
color: Qt.alpha(Colours.tPalette.m3surfaceContainer, root.session.network.active === modelData ? Colours.tPalette.m3surfaceContainer.a : 0) color: Qt.alpha(Colours.tPalette.m3surfaceContainer, (modelData && root.session.network.active === modelData) ? Colours.tPalette.m3surfaceContainer.a : 0)
radius: Appearance.rounding.normal radius: Appearance.rounding.normal
StateLayer { StateLayer {
function onClicked(): void { function onClicked(): void {
if (!modelData) {
return;
}
root.session.ethernet.active = null; root.session.ethernet.active = null;
root.session.network.active = modelData; root.session.network.active = modelData;
// Check if we need to refresh saved connections when selecting a network // Check if we need to refresh saved connections when selecting a network
if (modelData && modelData.ssid) { if (modelData.ssid) {
checkSavedProfileForNetwork(modelData.ssid); checkSavedProfileForNetwork(modelData.ssid);
} }
} }
@ -316,16 +323,16 @@ RowLayout {
implicitHeight: wirelessIcon.implicitHeight + Appearance.padding.normal * 2 implicitHeight: wirelessIcon.implicitHeight + Appearance.padding.normal * 2
radius: Appearance.rounding.normal radius: Appearance.rounding.normal
color: modelData.active ? Colours.palette.m3primaryContainer : Colours.tPalette.m3surfaceContainerHigh color: (modelData && modelData.active) ? Colours.palette.m3primaryContainer : Colours.tPalette.m3surfaceContainerHigh
MaterialIcon { MaterialIcon {
id: wirelessIcon id: wirelessIcon
anchors.centerIn: parent anchors.centerIn: parent
text: Icons.getNetworkIcon(modelData.strength) text: Icons.getNetworkIcon(modelData && modelData.strength !== undefined ? modelData.strength : 0)
font.pointSize: Appearance.font.size.large font.pointSize: Appearance.font.size.large
fill: modelData.active ? 1 : 0 fill: (modelData && modelData.active) ? 1 : 0
color: modelData.active ? Colours.palette.m3onPrimaryContainer : Colours.palette.m3onSurface color: (modelData && modelData.active) ? Colours.palette.m3onPrimaryContainer : Colours.palette.m3onSurface
} }
} }
@ -334,14 +341,14 @@ RowLayout {
elide: Text.ElideRight elide: Text.ElideRight
maximumLineCount: 1 maximumLineCount: 1
text: modelData.ssid || qsTr("Unknown") text: (modelData && modelData.ssid) ? modelData.ssid : qsTr("Unknown")
} }
StyledText { StyledText {
text: modelData.active ? qsTr("Connected") : (modelData.isSecure ? qsTr("Secured") : qsTr("Open")) text: (modelData && modelData.active) ? qsTr("Connected") : ((modelData && modelData.isSecure) ? qsTr("Secured") : qsTr("Open"))
color: modelData.active ? Colours.palette.m3primary : Colours.palette.m3outline color: (modelData && modelData.active) ? Colours.palette.m3primary : Colours.palette.m3outline
font.pointSize: Appearance.font.size.small font.pointSize: Appearance.font.size.small
font.weight: modelData.active ? 500 : 400 font.weight: (modelData && modelData.active) ? 500 : 400
} }
StyledRect { StyledRect {
@ -349,13 +356,13 @@ RowLayout {
implicitHeight: wirelessConnectIcon.implicitHeight + Appearance.padding.smaller * 2 implicitHeight: wirelessConnectIcon.implicitHeight + Appearance.padding.smaller * 2
radius: Appearance.rounding.full radius: Appearance.rounding.full
color: Qt.alpha(Colours.palette.m3primaryContainer, modelData.active ? 1 : 0) color: Qt.alpha(Colours.palette.m3primaryContainer, (modelData && modelData.active) ? 1 : 0)
StateLayer { StateLayer {
function onClicked(): void { function onClicked(): void {
if (modelData.active) { if (modelData && modelData.active) {
Nmcli.disconnectFromNetwork(); Nmcli.disconnectFromNetwork();
} else { } else if (modelData) {
handleWirelessConnect(modelData); handleWirelessConnect(modelData);
} }
} }
@ -365,8 +372,8 @@ RowLayout {
id: wirelessConnectIcon id: wirelessConnectIcon
anchors.centerIn: parent anchors.centerIn: parent
text: modelData.active ? "link_off" : "link" text: (modelData && modelData.active) ? "link_off" : "link"
color: modelData.active ? Colours.palette.m3onPrimaryContainer : Colours.palette.m3onSurface color: (modelData && modelData.active) ? Colours.palette.m3onPrimaryContainer : Colours.palette.m3onSurface
} }
} }
} }
@ -505,10 +512,10 @@ RowLayout {
} }
} }
} }
}
WirelessPasswordDialog { WirelessPasswordDialog {
Layout.fillWidth: true anchors.fill: parent
Layout.fillHeight: true
session: root.session session: root.session
z: 1000 z: 1000
} }

View file

@ -131,14 +131,17 @@ Item {
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
Layout.topMargin: Appearance.spacing.small Layout.topMargin: Appearance.spacing.small
visible: connectButton.connecting visible: connectButton.connecting || connectButton.hasError
text: { text: {
if (connectButton.hasError) {
return qsTr("Connection failed. Please check your password and try again.");
}
if (connectButton.connecting) { if (connectButton.connecting) {
return qsTr("Connecting..."); return qsTr("Connecting...");
} }
return ""; return "";
} }
color: Colours.palette.m3onSurfaceVariant color: connectButton.hasError ? Colours.palette.m3error : Colours.palette.m3onSurfaceVariant
font.pointSize: Appearance.font.size.small font.pointSize: Appearance.font.size.small
font.weight: 400 font.weight: 400
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
@ -153,18 +156,31 @@ Item {
focus: true focus: true
Keys.onPressed: event => { Keys.onPressed: event => {
// Ensure we have focus when receiving keyboard input
if (!activeFocus) {
forceActiveFocus();
}
// Clear error when user starts typing
if (connectButton.hasError && event.text && event.text.length > 0) {
connectButton.hasError = false;
}
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
if (connectButton.enabled) { if (connectButton.enabled) {
connectButton.clicked(); connectButton.clicked();
} }
event.accepted = true;
} else if (event.key === Qt.Key_Backspace) { } else if (event.key === Qt.Key_Backspace) {
if (event.modifiers & Qt.ControlModifier) { if (event.modifiers & Qt.ControlModifier) {
passwordBuffer = ""; passwordBuffer = "";
} else { } else {
passwordBuffer = passwordBuffer.slice(0, -1); passwordBuffer = passwordBuffer.slice(0, -1);
} }
event.accepted = true;
} else if (event.text && event.text.length > 0) { } else if (event.text && event.text.length > 0) {
passwordBuffer += event.text; passwordBuffer += event.text;
event.accepted = true;
} }
} }
@ -178,6 +194,7 @@ Item {
Qt.callLater(() => { Qt.callLater(() => {
passwordContainer.forceActiveFocus(); passwordContainer.forceActiveFocus();
passwordContainer.passwordBuffer = ""; passwordContainer.passwordBuffer = "";
connectButton.hasError = false;
}); });
} }
} }
@ -198,13 +215,29 @@ Item {
StyledRect { StyledRect {
anchors.fill: parent anchors.fill: parent
radius: Appearance.rounding.normal radius: Appearance.rounding.normal
color: Colours.tPalette.m3surfaceContainer color: passwordContainer.activeFocus ? Qt.lighter(Colours.tPalette.m3surfaceContainer, 1.05) : Colours.tPalette.m3surfaceContainer
border.width: passwordContainer.activeFocus ? 2 : 1 border.width: passwordContainer.activeFocus || connectButton.hasError ? 4 : (root.visible ? 1 : 0)
border.color: passwordContainer.activeFocus ? Colours.palette.m3primary : Colours.palette.m3outline border.color: {
if (connectButton.hasError) {
return Colours.palette.m3error;
}
if (passwordContainer.activeFocus) {
return Colours.palette.m3primary;
}
return root.visible ? Colours.palette.m3outline : "transparent";
}
Behavior on border.color { Behavior on border.color {
CAnim {} CAnim {}
} }
Behavior on border.width {
CAnim {}
}
Behavior on color {
CAnim {}
}
} }
StateLayer { StateLayer {
@ -329,6 +362,9 @@ Item {
TextButton { TextButton {
id: connectButton id: connectButton
property bool connecting: false
property bool hasError: false
Layout.fillWidth: true Layout.fillWidth: true
Layout.minimumHeight: Appearance.font.size.normal + Appearance.padding.normal * 2 Layout.minimumHeight: Appearance.font.size.normal + Appearance.padding.normal * 2
inactiveColour: Colours.palette.m3primary inactiveColour: Colours.palette.m3primary
@ -336,8 +372,6 @@ Item {
text: qsTr("Connect") text: qsTr("Connect")
enabled: passwordContainer.passwordBuffer.length > 0 && !connecting enabled: passwordContainer.passwordBuffer.length > 0 && !connecting
property bool connecting: false
onClicked: { onClicked: {
if (!root.network || connecting) { if (!root.network || connecting) {
return; return;
@ -348,6 +382,9 @@ Item {
return; return;
} }
// Clear any previous error
hasError = false;
// Set connecting state // Set connecting state
connecting = true; connecting = true;
enabled = false; enabled = false;
@ -361,11 +398,27 @@ Item {
// Shouldn't happen since we provided password // Shouldn't happen since we provided password
connectionMonitor.stop(); connectionMonitor.stop();
connecting = false; connecting = false;
hasError = true;
enabled = true; enabled = true;
text = qsTr("Connect"); text = qsTr("Connect");
} else passwordContainer.passwordBuffer = "";
// Connection failed, monitor will handle timeout // Delete the failed connection
{} if (root.network && root.network.ssid) {
Nmcli.forgetNetwork(root.network.ssid);
}
} else {
// Connection failed immediately - show error
connectionMonitor.stop();
connecting = false;
hasError = true;
enabled = true;
text = qsTr("Connect");
passwordContainer.passwordBuffer = "";
// Delete the failed connection
if (root.network && root.network.ssid) {
Nmcli.forgetNetwork(root.network.ssid);
}
}
}); });
// Start monitoring connection // Start monitoring connection
@ -386,18 +439,8 @@ Item {
if (isConnected) { if (isConnected) {
// Successfully connected - give it a moment for network list to update // Successfully connected - give it a moment for network list to update
Qt.callLater(() => { // Use Timer for actual delay
// Double-check connection is still active connectionSuccessTimer.start();
if (root.visible && Nmcli.active && Nmcli.active.ssid) {
const stillConnected = Nmcli.active.ssid.toLowerCase().trim() === root.network.ssid.toLowerCase().trim();
if (stillConnected) {
connectionMonitor.stop();
connectButton.connecting = false;
connectButton.text = qsTr("Connect");
closeDialog();
}
}
}, 500);
return; return;
} }
@ -407,8 +450,14 @@ Item {
if (connectionMonitor.repeatCount > 10) { if (connectionMonitor.repeatCount > 10) {
connectionMonitor.stop(); connectionMonitor.stop();
connectButton.connecting = false; connectButton.connecting = false;
connectButton.hasError = true;
connectButton.enabled = true; connectButton.enabled = true;
connectButton.text = qsTr("Connect"); connectButton.text = qsTr("Connect");
passwordContainer.passwordBuffer = "";
// Delete the failed connection
if (root.network && root.network.ssid) {
Nmcli.forgetNetwork(root.network.ssid);
}
} }
} }
} }
@ -432,6 +481,23 @@ Item {
} }
} }
Timer {
id: connectionSuccessTimer
interval: 500
onTriggered: {
// Double-check connection is still active
if (root.visible && Nmcli.active && Nmcli.active.ssid) {
const stillConnected = Nmcli.active.ssid.toLowerCase().trim() === root.network.ssid.toLowerCase().trim();
if (stillConnected) {
connectionMonitor.stop();
connectButton.connecting = false;
connectButton.text = qsTr("Connect");
closeDialog();
}
}
}
}
Connections { Connections {
target: Nmcli target: Nmcli
function onActiveChanged() { function onActiveChanged() {
@ -443,8 +509,12 @@ Item {
if (root.visible && root.network && root.network.ssid === ssid && connectButton.connecting) { if (root.visible && root.network && root.network.ssid === ssid && connectButton.connecting) {
connectionMonitor.stop(); connectionMonitor.stop();
connectButton.connecting = false; connectButton.connecting = false;
connectButton.hasError = true;
connectButton.enabled = true; connectButton.enabled = true;
connectButton.text = qsTr("Connect"); connectButton.text = qsTr("Connect");
passwordContainer.passwordBuffer = "";
// Delete the failed connection
Nmcli.forgetNetwork(ssid);
} }
} }
} }
@ -457,6 +527,7 @@ Item {
isClosing = true; isClosing = true;
passwordContainer.passwordBuffer = ""; passwordContainer.passwordBuffer = "";
connectButton.connecting = false; connectButton.connecting = false;
connectButton.hasError = false;
connectButton.text = qsTr("Connect"); connectButton.text = qsTr("Connect");
connectionMonitor.stop(); connectionMonitor.stop();
} }

View file

@ -1272,7 +1272,15 @@ Singleton {
stdout: SplitParser { stdout: SplitParser {
onRead: root.refreshOnConnectionChange() onRead: root.refreshOnConnectionChange()
} }
onExited: Qt.callLater(() => monitorProc.running = true, 2000) onExited: monitorRestartTimer.start()
}
Timer {
id: monitorRestartTimer
interval: 2000
onTriggered: {
monitorProc.running = true;
}
} }
function refreshOnConnectionChange(): void { function refreshOnConnectionChange(): void {