From 41f0f73bed7c31a3d0dd0197cd8a78ee5e5f42c6 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Fri, 3 Mar 2023 10:41:06 +0100 Subject: [PATCH] qml: PIN enable/disable/change more in line with other preferences items --- electrum/gui/qml/components/Preferences.qml | 79 +++++++++++---------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/electrum/gui/qml/components/Preferences.qml b/electrum/gui/qml/components/Preferences.qml index 2047b4b80..ac1ac2d6d 100644 --- a/electrum/gui/qml/components/Preferences.qml +++ b/electrum/gui/qml/components/Preferences.qml @@ -180,46 +180,53 @@ Pane { text: qsTr('Wallet behavior') } - Label { - text: qsTr('PIN') - } - RowLayout { - Label { - text: Config.pinCode == '' ? qsTr('Off'): qsTr('On') - color: Material.accentColor - Layout.rightMargin: constants.paddingMedium - } - Button { - text: qsTr('Enable') - visible: Config.pinCode == '' - onClicked: { - var dialog = pinSetup.createObject(preferences, {mode: 'enter'}) - dialog.accepted.connect(function() { - Config.pinCode = dialog.pincode - dialog.close() - }) - dialog.open() + Layout.fillWidth: true + Layout.leftMargin: -constants.paddingSmall + spacing: 0 + Switch { + id: usePin + checked: Config.pinCode + onCheckedChanged: { + if (activeFocus) { + console.log('PIN active ' + checked) + if (checked) { + var dialog = pinSetup.createObject(preferences, {mode: 'enter'}) + dialog.accepted.connect(function() { + Config.pinCode = dialog.pincode + dialog.close() + }) + dialog.rejected.connect(function() { + checked = false + }) + dialog.open() + } else { + focus = false + Config.pinCode = '' + // re-add binding, pincode still set if auth failed + checked = Qt.binding(function () { return Config.pinCode }) + } + } + } } - Button { - text: qsTr('Modify') - visible: Config.pinCode != '' - onClicked: { - var dialog = pinSetup.createObject(preferences, {mode: 'change', pincode: Config.pinCode}) - dialog.accepted.connect(function() { - Config.pinCode = dialog.pincode - dialog.close() - }) - dialog.open() - } + Label { + Layout.fillWidth: true + text: qsTr('PIN') + wrapMode: Text.Wrap } - Button { - text: qsTr('Remove') - visible: Config.pinCode != '' - onClicked: { - Config.pinCode = '' - } + } + + Button { + text: qsTr('Modify') + visible: Config.pinCode != '' + onClicked: { + var dialog = pinSetup.createObject(preferences, {mode: 'change', pincode: Config.pinCode}) + dialog.accepted.connect(function() { + Config.pinCode = dialog.pincode + dialog.close() + }) + dialog.open() } }