diff options
| author | luigi1111 <luigi1111w@gmail.com> | 2019-04-08 14:33:59 -0400 |
|---|---|---|
| committer | luigi1111 <luigi1111w@gmail.com> | 2019-04-08 14:33:59 -0400 |
| commit | 2f22503c8b54208afbca9fbac8a51f0bfe397339 (patch) | |
| tree | 009c64488d89a4f0754455a54ce38cfd693496be | |
| parent | 19c2208dc447ccb5ba9ff990cbdd6ecf6b96f23d (diff) | |
| parent | 5dbcd714eae8bfd6e900adde6910789e5cce6613 (diff) | |
| download | monzero-gui-2f22503c8b54208afbca9fbac8a51f0bfe397339.tar.gz monzero-gui-2f22503c8b54208afbca9fbac8a51f0bfe397339.tar.xz monzero-gui-2f22503c8b54208afbca9fbac8a51f0bfe397339.zip | |
Merge pull request #1822
5dbcd71 PasswordDialog: add CAPSLOCK checking (mmbyday)
| -rw-r--r-- | components/PasswordDialog.qml | 41 | ||||
| -rw-r--r-- | js/Utils.js | 19 |
2 files changed, 55 insertions, 5 deletions
diff --git a/components/PasswordDialog.qml b/components/PasswordDialog.qml index a5758306..f820e4df 100644 --- a/components/PasswordDialog.qml +++ b/components/PasswordDialog.qml @@ -34,6 +34,7 @@ import QtQuick.Controls.Styles 1.4 import QtQuick.Window 2.0 import "../components" as MoneroComponents +import "../js/Utils.js" as Utils Item { id: root @@ -44,6 +45,9 @@ Item { property alias password: passwordInput.text property string walletName property string errorText + property bool shiftIsPressed: false + property bool isCapsLocksActive: false + property bool backspaceIsPressed: false // same signals as Dialog has signal accepted() @@ -51,9 +55,11 @@ Item { signal closeCallback() function open(walletName, errorText) { + passwordInput.text = "" + passwordInput.forceActiveFocus(); inactiveOverlay.visible = true // draw appwindow inactive root.walletName = walletName ? walletName : "" - root.errorText = errorText ? errorText : ""; + errorTextLabel.text = errorText ? errorText : ""; leftPanel.enabled = false middlePanel.enabled = false titleBar.enabled = false @@ -104,8 +110,8 @@ Item { } Label { - text: root.errorText - visible: root.errorText + id: errorTextLabel + visible: root.errorText || text !== "" color: MoneroComponents.Style.errorColor font.pixelSize: 16 * scaleRatio @@ -131,6 +137,17 @@ Item { selectionColor: MoneroComponents.Style.dimmedFontColor selectedTextColor: MoneroComponents.Style.defaultFontColor + onTextChanged: { + var letter = text[passwordInput.text.length - 1]; + isCapsLocksActive = Utils.isUpperLock(shiftIsPressed, letter); + if(isCapsLocksActive && !backspaceIsPressed){ + errorTextLabel.text = qsTr("CAPSLOCKS IS ON.") + translationManager.emptyString; + } + else{ + errorTextLabel.text = ""; + } + } + background: Rectangle { radius: 2 border.color: Qt.rgba(255, 255, 255, 0.35) @@ -172,12 +189,26 @@ Item { Keys.onReturnPressed: { root.close() root.accepted() - } Keys.onEscapePressed: { root.close() root.rejected() - + } + Keys.onPressed: { + if(event.key === Qt.Key_Shift){ + shiftIsPressed = true; + } + if(event.key === Qt.Key_Backspace){ + backspaceIsPressed = true; + } + } + Keys.onReleased: { + if(event.key === Qt.Key_Shift){ + shiftIsPressed = false; + } + if(event.key === Qt.Key_Backspace){ + backspaceIsPressed =false; + } } } diff --git a/js/Utils.js b/js/Utils.js index 4f522a35..f02303c5 100644 --- a/js/Utils.js +++ b/js/Utils.js @@ -107,3 +107,22 @@ function filterNodes(nodes, port) { function epoch(){ return Math.floor((new Date).getTime()/1000); } + +function isAlpha(letter){ return letter.match(/^[A-Za-z0-9]+$/) !== null; } + +function isLowerCaseChar(letter){ return letter === letter.toLowerCase(); } + +function isUpperLock(shift, letter){ + if(!isAlpha((letter))) return false; + if(shift) { + if(isLowerCaseChar(letter)) + return true; + else + return false; + } else { + if(isLowerCaseChar(letter)) + return false; + else + return true; + } +} |
