mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-11-16 15:58:11 +00:00
PasswordDialog: add CAPSLOCK checking
This commit is contained in:
parent
d4d8ff54e6
commit
5dbcd714ea
2 changed files with 55 additions and 5 deletions
|
@ -34,6 +34,7 @@ import QtQuick.Controls.Styles 1.4
|
||||||
import QtQuick.Window 2.0
|
import QtQuick.Window 2.0
|
||||||
|
|
||||||
import "../components" as MoneroComponents
|
import "../components" as MoneroComponents
|
||||||
|
import "../js/Utils.js" as Utils
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
@ -44,6 +45,9 @@ Item {
|
||||||
property alias password: passwordInput.text
|
property alias password: passwordInput.text
|
||||||
property string walletName
|
property string walletName
|
||||||
property string errorText
|
property string errorText
|
||||||
|
property bool shiftIsPressed: false
|
||||||
|
property bool isCapsLocksActive: false
|
||||||
|
property bool backspaceIsPressed: false
|
||||||
|
|
||||||
// same signals as Dialog has
|
// same signals as Dialog has
|
||||||
signal accepted()
|
signal accepted()
|
||||||
|
@ -51,9 +55,11 @@ Item {
|
||||||
signal closeCallback()
|
signal closeCallback()
|
||||||
|
|
||||||
function open(walletName, errorText) {
|
function open(walletName, errorText) {
|
||||||
|
passwordInput.text = ""
|
||||||
|
passwordInput.forceActiveFocus();
|
||||||
inactiveOverlay.visible = true // draw appwindow inactive
|
inactiveOverlay.visible = true // draw appwindow inactive
|
||||||
root.walletName = walletName ? walletName : ""
|
root.walletName = walletName ? walletName : ""
|
||||||
root.errorText = errorText ? errorText : "";
|
errorTextLabel.text = errorText ? errorText : "";
|
||||||
leftPanel.enabled = false
|
leftPanel.enabled = false
|
||||||
middlePanel.enabled = false
|
middlePanel.enabled = false
|
||||||
titleBar.enabled = false
|
titleBar.enabled = false
|
||||||
|
@ -104,8 +110,8 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: root.errorText
|
id: errorTextLabel
|
||||||
visible: root.errorText
|
visible: root.errorText || text !== ""
|
||||||
|
|
||||||
color: MoneroComponents.Style.errorColor
|
color: MoneroComponents.Style.errorColor
|
||||||
font.pixelSize: 16 * scaleRatio
|
font.pixelSize: 16 * scaleRatio
|
||||||
|
@ -131,6 +137,17 @@ Item {
|
||||||
selectionColor: MoneroComponents.Style.dimmedFontColor
|
selectionColor: MoneroComponents.Style.dimmedFontColor
|
||||||
selectedTextColor: MoneroComponents.Style.defaultFontColor
|
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 {
|
background: Rectangle {
|
||||||
radius: 2
|
radius: 2
|
||||||
border.color: Qt.rgba(255, 255, 255, 0.35)
|
border.color: Qt.rgba(255, 255, 255, 0.35)
|
||||||
|
@ -172,12 +189,26 @@ Item {
|
||||||
Keys.onReturnPressed: {
|
Keys.onReturnPressed: {
|
||||||
root.close()
|
root.close()
|
||||||
root.accepted()
|
root.accepted()
|
||||||
|
|
||||||
}
|
}
|
||||||
Keys.onEscapePressed: {
|
Keys.onEscapePressed: {
|
||||||
root.close()
|
root.close()
|
||||||
root.rejected()
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
js/Utils.js
19
js/Utils.js
|
@ -107,3 +107,22 @@ function filterNodes(nodes, port) {
|
||||||
function epoch(){
|
function epoch(){
|
||||||
return Math.floor((new Date).getTime()/1000);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue