2019-07-25 16:43:52 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import "../SidePane"
|
|
|
|
|
|
|
|
Popup {
|
|
|
|
id: popup
|
|
|
|
anchors.centerIn: Overlay.overlay
|
|
|
|
modal: true
|
2019-08-28 12:25:13 +10:00
|
|
|
padding: 0
|
2019-07-25 16:43:52 +10:00
|
|
|
|
2019-08-28 13:51:38 +10:00
|
|
|
onAboutToShow: {
|
|
|
|
acceptedPassword = ""
|
|
|
|
passwordValid = null
|
|
|
|
okClicked = false
|
|
|
|
errorMessage.text = ""
|
|
|
|
}
|
2019-07-25 16:43:52 +10:00
|
|
|
onOpened: passwordField.forceActiveFocus()
|
|
|
|
|
2019-08-28 12:25:13 +10:00
|
|
|
property bool validateWhileTyping: false
|
|
|
|
|
|
|
|
property string acceptedPassword: ""
|
|
|
|
property var passwordValid: null
|
|
|
|
property bool okClicked: false
|
|
|
|
|
2019-07-25 16:43:52 +10:00
|
|
|
property alias label: popupLabel
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enter: Transition {
|
|
|
|
HNumberAnimation { property: "scale"; from: 0; to: 1; overshoot: 4 }
|
|
|
|
}
|
|
|
|
|
|
|
|
exit: Transition {
|
|
|
|
HNumberAnimation { property: "scale"; to: 0 }
|
|
|
|
}
|
2019-07-25 16:43:52 +10:00
|
|
|
|
2019-08-28 12:46:31 +10:00
|
|
|
background: Rectangle {
|
2019-07-25 16:43:52 +10:00
|
|
|
color: theme.controls.popup.background
|
|
|
|
}
|
|
|
|
|
2019-08-29 01:56:05 +10:00
|
|
|
contentItem: HBox {
|
2019-08-28 12:25:13 +10:00
|
|
|
id: box
|
|
|
|
implicitWidth: theme.minimumSupportedWidthPlusSpacing
|
|
|
|
enterButtonTarget: "ok"
|
|
|
|
buttonModel: [
|
|
|
|
{ name: "ok", text: qsTr("OK"), iconName: "ok",
|
|
|
|
enabled: passwordField.text &&
|
|
|
|
(validateWhileTyping ? passwordValid : true) },
|
|
|
|
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
|
|
|
|
]
|
|
|
|
buttonCallbacks: ({
|
|
|
|
ok: button => {
|
|
|
|
let password = passwordField.text
|
|
|
|
okClicked = true
|
|
|
|
button.loading = true
|
|
|
|
|
2019-08-28 13:51:38 +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
|
|
|
|
})
|
2019-08-28 12:25:13 +10:00
|
|
|
},
|
|
|
|
cancel: button => { popup.close() },
|
|
|
|
})
|
|
|
|
|
2019-07-25 16:43:52 +10:00
|
|
|
|
|
|
|
HLabel {
|
|
|
|
id: popupLabel
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
|
2019-08-28 12:25:13 +10:00
|
|
|
Layout.fillWidth: true
|
2019-07-25 16:43:52 +10:00
|
|
|
}
|
|
|
|
|
2019-08-28 12:25:13 +10:00
|
|
|
HRowLayout {
|
|
|
|
spacing: box.horizontalSpacing
|
|
|
|
|
|
|
|
HTextField {
|
|
|
|
id: passwordField
|
|
|
|
placeholderText: qsTr("Passphrase")
|
|
|
|
echoMode: TextInput.Password
|
|
|
|
focus: true
|
|
|
|
error: passwordValid === false
|
|
|
|
|
|
|
|
onTextChanged: passwordValid =
|
|
|
|
validateWhileTyping ? verifyPassword(text) : null
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2019-07-25 16:43:52 +10:00
|
|
|
}
|
|
|
|
|
2019-08-28 12:25:13 +10:00
|
|
|
HIcon {
|
|
|
|
svgName: passwordValid ? "ok" : "cancel"
|
|
|
|
visible: Layout.preferredWidth > 0
|
2019-07-25 16:43:52 +10:00
|
|
|
|
2019-08-28 12:25:13 +10:00
|
|
|
Layout.preferredWidth:
|
|
|
|
passwordValid == null ||
|
|
|
|
(validateWhileTyping && ! okClicked && ! passwordValid) ?
|
|
|
|
0 :implicitWidth
|
|
|
|
|
|
|
|
Behavior on Layout.preferredWidth { HNumberAnimation {} }
|
|
|
|
}
|
2019-07-25 16:43:52 +10:00
|
|
|
}
|
2019-08-28 13:51:38 +10:00
|
|
|
|
|
|
|
HLabel {
|
|
|
|
id: errorMessage
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
color: theme.colors.errorText
|
|
|
|
|
|
|
|
visible: Layout.maximumHeight > 0
|
|
|
|
Layout.maximumHeight: text ? implicitHeight : 0
|
|
|
|
Behavior on Layout.maximumHeight { HNumberAnimation {} }
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
2019-07-25 16:43:52 +10:00
|
|
|
}
|
|
|
|
}
|