2019-12-19 07:46:16 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-07-25 02:43:52 -04:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-09-09 08:57:38 -04:00
|
|
|
import "../Base"
|
2019-07-25 02:43:52 -04:00
|
|
|
|
2019-09-09 08:57:38 -04:00
|
|
|
BoxPopup {
|
2019-07-25 02:43:52 -04:00
|
|
|
id: popup
|
2019-09-09 07:49:07 -04:00
|
|
|
okEnabled: Boolean(passwordField.text)
|
2019-07-25 02:43:52 -04:00
|
|
|
|
2019-08-27 23:51:38 -04:00
|
|
|
onAboutToShow: {
|
2019-09-08 12:17:42 -04:00
|
|
|
okClicked = false
|
2019-08-27 23:51:38 -04:00
|
|
|
acceptedPassword = ""
|
|
|
|
passwordValid = null
|
|
|
|
errorMessage.text = ""
|
|
|
|
}
|
2019-07-25 02:43:52 -04:00
|
|
|
onOpened: passwordField.forceActiveFocus()
|
|
|
|
|
2019-09-08 12:17:42 -04:00
|
|
|
|
2020-03-21 12:43:16 -04:00
|
|
|
signal cancelled()
|
|
|
|
|
|
|
|
|
2019-08-27 22:25:13 -04:00
|
|
|
property bool validateWhileTyping: false
|
|
|
|
|
|
|
|
property string acceptedPassword: ""
|
|
|
|
property var passwordValid: null
|
|
|
|
|
2019-07-25 02:43:52 -04:00
|
|
|
property alias field: passwordField
|
2019-08-27 22:25:13 -04:00
|
|
|
|
|
|
|
|
2019-08-27 23:51:38 -04:00
|
|
|
function verifyPassword(pass, callback) {
|
2019-09-07 19:17:32 -04:00
|
|
|
// Can be reimplemented when using this component.
|
2019-11-30 05:50:56 -04:00
|
|
|
// Pass to the callback true on success, false on invalid password,
|
|
|
|
// or a custom error message string.
|
2019-09-07 19:17:32 -04:00
|
|
|
callback(true)
|
2019-08-27 22:25:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-08 12:17:42 -04:00
|
|
|
box.buttonCallbacks: ({
|
|
|
|
ok: button => {
|
2020-03-08 04:46:20 -04:00
|
|
|
const password = passwordField.text
|
2019-11-09 11:15:24 -04:00
|
|
|
okClicked = true
|
|
|
|
button.loading = true
|
|
|
|
errorMessage.text = ""
|
2019-09-08 12:17:42 -04:00
|
|
|
|
|
|
|
verifyPassword(password, result => {
|
|
|
|
if (result === true) {
|
|
|
|
passwordValid = true
|
|
|
|
popup.acceptedPassword = password
|
|
|
|
popup.close()
|
|
|
|
} else if (result === false) {
|
|
|
|
passwordValid = false
|
|
|
|
} else {
|
2019-11-30 05:50:56 -04:00
|
|
|
errorMessage.text = result
|
2019-09-08 12:17:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
button.loading = false
|
|
|
|
})
|
|
|
|
},
|
2020-03-21 12:43:16 -04:00
|
|
|
cancel: button => {
|
|
|
|
popup.close()
|
|
|
|
cancelled()
|
|
|
|
},
|
2019-09-08 12:17:42 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
HRowLayout {
|
2019-12-07 10:59:43 -04:00
|
|
|
spacing: theme.spacing
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2019-09-08 12:17:42 -04:00
|
|
|
|
|
|
|
HTextField {
|
|
|
|
id: passwordField
|
|
|
|
echoMode: TextInput.Password
|
|
|
|
focus: true
|
|
|
|
error: passwordValid === false
|
|
|
|
|
|
|
|
onTextChanged: passwordValid =
|
|
|
|
validateWhileTyping ? verifyPassword(text) : null
|
2019-07-25 02:43:52 -04:00
|
|
|
|
2019-08-27 22:25:13 -04:00
|
|
|
Layout.fillWidth: true
|
2019-07-25 02:43:52 -04:00
|
|
|
}
|
|
|
|
|
2019-09-08 12:17:42 -04:00
|
|
|
HIcon {
|
|
|
|
visible: Layout.preferredWidth > 0
|
2019-09-08 12:19:40 -04:00
|
|
|
svgName: passwordValid ? "ok" : "cancel"
|
|
|
|
colorize: passwordValid ?
|
|
|
|
theme.colors.positiveBackground :
|
|
|
|
theme.colors.negativeBackground
|
2019-07-25 02:43:52 -04:00
|
|
|
|
2019-09-08 12:17:42 -04:00
|
|
|
Layout.preferredWidth:
|
2019-12-09 11:35:50 -04:00
|
|
|
passwordValid === null ||
|
2019-09-08 12:17:42 -04:00
|
|
|
(validateWhileTyping && ! okClicked && ! passwordValid) ?
|
|
|
|
0 :implicitWidth
|
2019-07-25 02:43:52 -04:00
|
|
|
|
2019-09-08 12:17:42 -04:00
|
|
|
Behavior on Layout.preferredWidth { HNumberAnimation {} }
|
2019-07-25 02:43:52 -04:00
|
|
|
}
|
2019-09-08 12:17:42 -04:00
|
|
|
}
|
2019-08-27 23:51:38 -04:00
|
|
|
|
2019-09-08 12:17:42 -04:00
|
|
|
HLabel {
|
|
|
|
id: errorMessage
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
color: theme.colors.errorText
|
2019-08-27 23:51:38 -04:00
|
|
|
|
2019-09-08 12:17:42 -04:00
|
|
|
visible: Layout.maximumHeight > 0
|
|
|
|
Layout.maximumHeight: text ? implicitHeight : 0
|
|
|
|
Behavior on Layout.maximumHeight { HNumberAnimation {} }
|
2019-08-27 23:51:38 -04:00
|
|
|
|
2019-09-08 12:17:42 -04:00
|
|
|
Layout.fillWidth: true
|
2019-07-25 02:43:52 -04:00
|
|
|
}
|
|
|
|
}
|