2019-07-25 16:43:52 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-09-09 22:57:38 +10:00
|
|
|
import "../Base"
|
2019-07-25 16:43:52 +10:00
|
|
|
|
2019-09-09 22:57:38 +10:00
|
|
|
BoxPopup {
|
2019-07-25 16:43:52 +10:00
|
|
|
id: popup
|
2019-09-09 21:49:07 +10:00
|
|
|
okEnabled: Boolean(passwordField.text)
|
2019-07-25 16:43:52 +10:00
|
|
|
|
2019-08-28 13:51:38 +10:00
|
|
|
onAboutToShow: {
|
2019-09-09 02:17:42 +10:00
|
|
|
okClicked = false
|
2019-08-28 13:51:38 +10:00
|
|
|
acceptedPassword = ""
|
|
|
|
passwordValid = null
|
|
|
|
errorMessage.text = ""
|
|
|
|
}
|
2019-07-25 16:43:52 +10:00
|
|
|
onOpened: passwordField.forceActiveFocus()
|
|
|
|
|
2019-09-09 02:17:42 +10:00
|
|
|
|
2019-08-28 12:25:13 +10:00
|
|
|
property bool validateWhileTyping: false
|
|
|
|
|
|
|
|
property string acceptedPassword: ""
|
|
|
|
property var passwordValid: null
|
|
|
|
|
2019-07-25 16:43:52 +10:00
|
|
|
property alias field: passwordField
|
2019-08-28 12:25:13 +10:00
|
|
|
|
|
|
|
|
2019-08-28 13:51:38 +10:00
|
|
|
function verifyPassword(pass, callback) {
|
2019-09-08 09:17:32 +10:00
|
|
|
// Can be reimplemented when using this component.
|
|
|
|
// Pass to the callback true on success, false on invalid password, or
|
2019-08-28 13:51:38 +10:00
|
|
|
// a [error message, translated] array for any other error.
|
2019-09-08 09:17:32 +10:00
|
|
|
callback(true)
|
2019-08-28 12:25:13 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-09 02:17:42 +10:00
|
|
|
box.buttonCallbacks: ({
|
|
|
|
ok: button => {
|
2019-11-10 02:15:24 +11:00
|
|
|
let password = passwordField.text
|
|
|
|
okClicked = true
|
|
|
|
button.loading = true
|
|
|
|
errorMessage.text = ""
|
2019-09-09 02:17:42 +10:00
|
|
|
|
|
|
|
verifyPassword(password, result => {
|
|
|
|
if (result === true) {
|
|
|
|
passwordValid = true
|
|
|
|
popup.acceptedPassword = password
|
|
|
|
popup.close()
|
|
|
|
} else if (result === false) {
|
|
|
|
passwordValid = false
|
|
|
|
} else {
|
|
|
|
let [msg, translated] = result
|
|
|
|
errorMessage.text = translated ? msg : qsTr(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
button.loading = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
cancel: button => { popup.close() },
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
HRowLayout {
|
|
|
|
spacing: box.horizontalSpacing
|
|
|
|
|
|
|
|
HTextField {
|
|
|
|
id: passwordField
|
|
|
|
placeholderText: qsTr("Passphrase")
|
|
|
|
echoMode: TextInput.Password
|
|
|
|
focus: true
|
|
|
|
error: passwordValid === false
|
|
|
|
|
|
|
|
onTextChanged: passwordValid =
|
|
|
|
validateWhileTyping ? verifyPassword(text) : null
|
2019-07-25 16:43:52 +10:00
|
|
|
|
2019-08-28 12:25:13 +10:00
|
|
|
Layout.fillWidth: true
|
2019-07-25 16:43:52 +10:00
|
|
|
}
|
|
|
|
|
2019-09-09 02:17:42 +10:00
|
|
|
HIcon {
|
|
|
|
visible: Layout.preferredWidth > 0
|
2019-09-09 02:19:40 +10:00
|
|
|
svgName: passwordValid ? "ok" : "cancel"
|
|
|
|
colorize: passwordValid ?
|
|
|
|
theme.colors.positiveBackground :
|
|
|
|
theme.colors.negativeBackground
|
2019-07-25 16:43:52 +10:00
|
|
|
|
2019-09-09 02:17:42 +10:00
|
|
|
Layout.preferredWidth:
|
|
|
|
passwordValid == null ||
|
|
|
|
(validateWhileTyping && ! okClicked && ! passwordValid) ?
|
|
|
|
0 :implicitWidth
|
2019-07-25 16:43:52 +10:00
|
|
|
|
2019-09-09 02:17:42 +10:00
|
|
|
Behavior on Layout.preferredWidth { HNumberAnimation {} }
|
2019-07-25 16:43:52 +10:00
|
|
|
}
|
2019-09-09 02:17:42 +10:00
|
|
|
}
|
2019-08-28 13:51:38 +10:00
|
|
|
|
2019-09-09 02:17:42 +10:00
|
|
|
HLabel {
|
|
|
|
id: errorMessage
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
color: theme.colors.errorText
|
2019-08-28 13:51:38 +10:00
|
|
|
|
2019-09-09 02:17:42 +10:00
|
|
|
visible: Layout.maximumHeight > 0
|
|
|
|
Layout.maximumHeight: text ? implicitHeight : 0
|
|
|
|
Behavior on Layout.maximumHeight { HNumberAnimation {} }
|
2019-08-28 13:51:38 +10:00
|
|
|
|
2019-09-09 02:17:42 +10:00
|
|
|
Layout.fillWidth: true
|
2019-07-25 16:43:52 +10:00
|
|
|
}
|
|
|
|
}
|