From 346913f3db3512a254341d2576124787c5024198 Mon Sep 17 00:00:00 2001 From: reemuru Date: Sat, 12 Mar 2022 19:24:08 -0500 Subject: [PATCH] SettingsWallet: lock wallet on demand This commit adds the ability to lock the wallet on demand instead of waiting for the user inactivity time out. It is binded to the hot keys Ctrl+L. Pressing cancel or the esc key will send the user back to the wizard home for wallet selection. Incorrect password returns the error message. Correct password will remove the PasswordDialog allowing access. Add lock functionality in the wallet settings section and title bar. --- components/SettingsListItem.qml | 13 ++++++++++ components/TitleBar.qml | 41 +++++++++++++++++++++++++++++++ fonts/FontAwesome/FontAwesome.qml | 1 + main.qml | 14 +++++++++++ pages/settings/SettingsWallet.qml | 8 ++++++ 5 files changed, 77 insertions(+) diff --git a/components/SettingsListItem.qml b/components/SettingsListItem.qml index d6a10ca6..7c778704 100644 --- a/components/SettingsListItem.qml +++ b/components/SettingsListItem.qml @@ -7,6 +7,7 @@ import "../components" as MoneroComponents ColumnLayout { id: settingsListItem property alias iconText: iconLabel.text + property alias symbol: symbolText.text property alias description: area.text property alias title: header.text property bool isLast: false @@ -114,5 +115,17 @@ ColumnLayout { settingsListItem.clicked() } } + + MoneroComponents.TextPlain { + id: symbolText + anchors.right: parent.right + anchors.rightMargin: 44 + anchors.verticalCenter: parent.verticalCenter + font.pixelSize: 12 + font.bold: true + color: MoneroComponents.Style.menuButtonTextColor + visible: appWindow.ctrlPressed + themeTransition: false + } } } diff --git a/components/TitleBar.qml b/components/TitleBar.qml index ef04fdf4..1720c457 100644 --- a/components/TitleBar.qml +++ b/components/TitleBar.qml @@ -57,6 +57,7 @@ Rectangle { signal minimizeClicked signal languageClicked signal closeWalletClicked + signal lockWalletClicked state: "default" states: [ @@ -91,6 +92,46 @@ Rectangle { spacing: 0 anchors.fill: parent + // lock wallet + Rectangle { + id: btnLockWallet + color: "transparent" + Layout.preferredWidth: parent.height + Layout.preferredHeight: parent.height + + Text { + text: FontAwesome.lock + font.family: FontAwesome.fontFamilySolid + font.pixelSize: 16 + color: MoneroComponents.Style.defaultFontColor + font.styleName: "Solid" + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + opacity: 0.75 + } + + MoneroComponents.Tooltip { + id: btnLockWalletTooltip + anchors.fill: parent + text: qsTr("Lock this wallet") + translationManager.emptyString + } + + MouseArea { + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onEntered: { + parent.color = MoneroComponents.Style.titleBarButtonHoverColor + btnLockWalletTooltip.tooltipPopup.open() + } + onExited: { + parent.color = "transparent" + btnLockWalletTooltip.tooltipPopup.close() + } + onClicked: root.lockWalletClicked(leftPanel.visible) + } + } + // collapse sidebar Rectangle { id: btnCloseWallet diff --git a/fonts/FontAwesome/FontAwesome.qml b/fonts/FontAwesome/FontAwesome.qml index 533909a7..9c077a9a 100644 --- a/fonts/FontAwesome/FontAwesome.qml +++ b/fonts/FontAwesome/FontAwesome.qml @@ -53,6 +53,7 @@ Object { property string info : "\uf129" property string key : "\uf084" property string language : "\uf1ab" + property string lock : "\uf023" property string minus : "\uf068" property string minusCircle : "\uf056" property string moonO : "\uf186" diff --git a/main.qml b/main.qml index 6e04cfe0..18249c7b 100644 --- a/main.qml +++ b/main.qml @@ -131,6 +131,17 @@ ApplicationWindow { leftPanel.selectItem(page) } + function lock() { + passwordDialog.onRejectedCallback = function() { appWindow.showWizard(); } + passwordDialog.onAcceptedCallback = function() { + if(walletPassword === passwordDialog.password) + passwordDialog.close(); + else + passwordDialog.showError(qsTr("Wrong password") + translationManager.emptyString); + } + passwordDialog.open(usefulName(persistentSettings.wallet_path)); + } + function sequencePressed(obj, seq) { if(seq === undefined || !leftPanel.enabled) return @@ -139,6 +150,8 @@ ApplicationWindow { return } + // lock wallet on demand + if(seq === "Ctrl+L" && !passwordDialog.visible) lock() if(seq === "Ctrl+S") middlePanel.state = "Transfer" else if(seq === "Ctrl+R") middlePanel.state = "Receive" else if(seq === "Ctrl+H") middlePanel.state = "History" @@ -1923,6 +1936,7 @@ ApplicationWindow { anchors.left: parent.left anchors.right: parent.right onCloseClicked: appWindow.close(); + onLockWalletClicked: appWindow.lock(); onLanguageClicked: appWindow.toggleLanguageView(); onCloseWalletClicked: appWindow.showWizard(); onMaximizeClicked: appWindow.visibility = appWindow.visibility !== Window.Maximized ? Window.Maximized : Window.Windowed diff --git a/pages/settings/SettingsWallet.qml b/pages/settings/SettingsWallet.qml index c2a20168..2e5468ab 100644 --- a/pages/settings/SettingsWallet.qml +++ b/pages/settings/SettingsWallet.qml @@ -50,6 +50,14 @@ Rectangle { anchors.topMargin: 0 spacing: 0 + MoneroComponents.SettingsListItem { + iconText: FontAwesome.lock + description: qsTr("Locks the wallet on demand.") + translationManager.emptyString + title: qsTr("Lock this wallet") + translationManager.emptyString + symbol: (isMac ? "⌃" : qsTr("Ctrl+")) + "L" + translationManager.emptyString + onClicked: appWindow.lock(); + } + MoneroComponents.SettingsListItem { iconText: FontAwesome.signOutAlt description: qsTr("Logs out of this wallet.") + translationManager.emptyString