2018-05-20 01:54:08 +02:00
|
|
|
import QtQuick 2.7
|
|
|
|
import QtQuick.Controls 2.1 as Controls
|
|
|
|
import QtQuick.Layouts 1.2
|
|
|
|
import org.kde.kirigami 2.4 as Kirigami
|
|
|
|
|
|
|
|
BasicDialog {
|
|
|
|
id: passwordDialog
|
|
|
|
property alias instruction: instructionLabel.text
|
|
|
|
property alias password: passwordTextField.text
|
|
|
|
property bool newPassword: false
|
|
|
|
readonly property bool canAccept: !newPassword
|
|
|
|
|| showCharactersCheckBox.checked
|
|
|
|
|| passwordTextField.text === repeatPasswordTextField.text
|
|
|
|
|
|
|
|
standardButtons: canAccept ? Controls.Dialog.Ok
|
|
|
|
| Controls.Dialog.Cancel : Controls.Dialog.Cancel
|
|
|
|
title: qsTr("Enter password")
|
2018-06-14 23:46:18 +02:00
|
|
|
onAccepted: {
|
|
|
|
nativeInterface.password = password
|
|
|
|
if (newPassword) {
|
|
|
|
showPassiveNotification(
|
|
|
|
qsTr("The new password will be used when saving next time."))
|
|
|
|
} else {
|
|
|
|
nativeInterface.load()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onRejected: {
|
|
|
|
if (newPassword) {
|
|
|
|
showPassiveNotification(
|
|
|
|
qsTr("You aborted. The password has not been altered."))
|
|
|
|
}
|
|
|
|
}
|
2018-05-20 01:54:08 +02:00
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
Controls.Label {
|
|
|
|
id: instructionLabel
|
|
|
|
Layout.preferredWidth: passwordDialog.availableWidth
|
|
|
|
wrapMode: Controls.Label.Wrap
|
|
|
|
}
|
|
|
|
|
|
|
|
Controls.TextField {
|
|
|
|
id: passwordTextField
|
|
|
|
Layout.preferredWidth: passwordDialog.availableWidth
|
|
|
|
echoMode: showCharactersCheckBox.checked ? TextInput.Normal : TextInput.Password
|
|
|
|
placeholderText: qsTr("enter password here, leave empty for no encryption")
|
|
|
|
background: Rectangle {
|
|
|
|
border.color: "#5d5e6d"
|
|
|
|
}
|
2018-09-10 20:43:58 +02:00
|
|
|
Keys.onPressed: passwordDialog.acceptOnReturn(event)
|
2018-05-20 01:54:08 +02:00
|
|
|
}
|
|
|
|
Controls.TextField {
|
|
|
|
id: repeatPasswordTextField
|
|
|
|
Layout.preferredWidth: passwordDialog.availableWidth
|
|
|
|
visible: passwordDialog.newPassword
|
|
|
|
&& !showCharactersCheckBox.checked
|
|
|
|
echoMode: TextInput.Password
|
|
|
|
placeholderText: qsTr("repeat password")
|
|
|
|
background: Rectangle {
|
|
|
|
border.color: passwordDialog.canAccept ? "#089900" : "#ff0000"
|
|
|
|
}
|
2018-09-10 20:43:58 +02:00
|
|
|
Keys.onPressed: passwordDialog.acceptOnReturn(event)
|
2018-05-20 01:54:08 +02:00
|
|
|
}
|
|
|
|
Controls.CheckBox {
|
|
|
|
id: showCharactersCheckBox
|
|
|
|
text: qsTr("Show characters")
|
|
|
|
checked: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function clear() {
|
|
|
|
passwordTextField.text = ""
|
|
|
|
repeatPasswordTextField.text = ""
|
|
|
|
}
|
|
|
|
|
2018-06-14 23:46:18 +02:00
|
|
|
function askForPassword(instruction) {
|
2018-05-20 01:54:08 +02:00
|
|
|
this.instruction = instruction
|
2018-06-14 23:46:18 +02:00
|
|
|
clear()
|
|
|
|
open()
|
2018-09-10 19:53:54 +02:00
|
|
|
passwordTextField.forceActiveFocus()
|
2018-05-20 01:54:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function askForExistingPassword(instruction) {
|
2018-06-14 23:46:18 +02:00
|
|
|
newPassword = false
|
|
|
|
askForPassword(instruction)
|
2018-05-20 01:54:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function askForNewPassword(instruction) {
|
2018-06-14 23:46:18 +02:00
|
|
|
newPassword = true
|
|
|
|
askForPassword(instruction)
|
2018-05-20 01:54:08 +02:00
|
|
|
}
|
|
|
|
}
|