Warning, /network/kdenetwork-filesharing/samba/filepropertiesplugin/qml/ChangePassword.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003     SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com>
0004     SPDX-FileCopyrightText: 2020 Harld Sitter <sitter@kde.org>
0005 */
0006 
0007 import QtQuick 2.6
0008 import QtQuick.Layouts 1.3
0009 import QtQuick.Controls 2.5 as QQC2
0010 
0011 import org.kde.kirigami 2.8 as Kirigami
0012 
0013 Kirigami.OverlaySheet {
0014     id: passwordRoot
0015 
0016     property string password
0017     property bool busy: false
0018     property alias errorMessage: persistentError.text
0019     signal accepted()
0020 
0021     header: Kirigami.Heading {
0022         // FIXME make qml user name aware so we can be more contextually accurate and label it 'set password for foo'
0023         text: i18nc("@title", "Set password")
0024     }
0025 
0026     function openAndClear() {
0027         verifyField.text = ""
0028         passwordField.text = ""
0029         passwordField.forceActiveFocus()
0030         open()
0031     }
0032 
0033     function isAcceptable() {
0034         return !passwordWarning.visible && verifyField.text && passwordField.text;
0035     }
0036 
0037     function maybeAccept() {
0038         if (!isAcceptable()) {
0039             return
0040         }
0041 
0042         close()
0043         passwordRoot.password = passwordField.text
0044         accepted()
0045     }
0046 
0047     function handleKeyEvent(event) {
0048         if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
0049             // 🤮 https://bugreports.qt.io/browse/QTBUG-70934
0050             event.accepted = true
0051             maybeAccept()
0052         } else if (event.key === Qt.Key_Escape) {
0053             // Handle Esc manually, within the sheet we'll want it to close the sheet rater than let the event fall
0054             // through to a higher level item (or worse yet QWidget).
0055             event.accepted = true
0056             close()
0057         }
0058     }
0059 
0060     ColumnLayout {
0061         id: mainColumn
0062         spacing: Kirigami.Units.smallSpacing
0063         Layout.preferredWidth: Kirigami.Units.gridUnit * 15
0064 
0065         // We don't use a FormLayout here because layouting breaks at small widths.
0066         ColumnLayout {
0067             id: inputLayout
0068             Layout.alignment: Qt.AlignHCenter
0069             visible: !busy.running
0070 
0071             Kirigami.PasswordField {
0072                 id: passwordField
0073                 Layout.fillWidth: true
0074                 Layout.alignment: Qt.AlignLeft
0075                 placeholderText: i18nc("@label:textbox", "Password")
0076 
0077                 // Reset external error on any password change
0078                 onTextChanged: errorMessage = ""
0079                 // Don't use onAccepted it's no bueno. See handleKeyEvent
0080             }
0081 
0082             Kirigami.PasswordField {
0083                 id: verifyField
0084                 Layout.fillWidth: true
0085                 Layout.alignment: Qt.AlignLeft
0086                 placeholderText: i18nc("@label:textbox", "Confirm password")
0087 
0088                 // Reset external error on any password change
0089                 onTextChanged: errorMessage = ""
0090                 // Don't use onAccepted it's no bueno. See handleKeyEvent
0091             }
0092 
0093             Kirigami.InlineMessage {
0094                 id: passwordWarning
0095                 Layout.fillWidth: true
0096                 type: Kirigami.MessageType.Error
0097                 text: i18nc("@label error message", "Passwords must match")
0098                 visible: passwordField.text != "" && verifyField.text != "" && passwordField.text != verifyField.text
0099                 Layout.alignment: Qt.AlignLeft
0100             }
0101 
0102             // This is a separate, second, message because otherwise we'd have to do a whole state conversion dance
0103             // logic that hurts my eyes.
0104             // This message is for problems in the backend that we need to tell the user about. It's different in
0105             // that the text is mutable and not controlled by us.
0106             Kirigami.InlineMessage {
0107                 id: persistentError
0108                 Layout.fillWidth: true
0109                 Layout.alignment: Qt.AlignLeft
0110                 type: Kirigami.MessageType.Error
0111                 visible: text != ""
0112             }
0113 
0114             QQC2.Button {
0115                 id: passButton
0116                 icon.name: "dialog-ok"
0117                 text: i18nc("@action:button creates a new samba user with the user-specified password", "Set Password")
0118                 enabled: isAcceptable()
0119                 Layout.alignment: Qt.AlignRight
0120                 onClicked: maybeAccept()
0121             }
0122         }
0123 
0124         QQC2.BusyIndicator {
0125             id: busyIndicator
0126             Layout.alignment: Qt.AlignCenter
0127             visible: running
0128             running: passwordRoot.busy
0129         }
0130     }
0131 }