Warning, /plasma/plasma-workspace/lookandfeel/sddm-theme/Login.qml is written in an unsupported language. File is not indexed.

0001 import "components"
0002 
0003 import QtQuick 2.15
0004 import QtQuick.Layouts 1.15
0005 import QtQuick.Controls 2.15 as QQC2
0006 
0007 import org.kde.plasma.core 2.0 as PlasmaCore
0008 import org.kde.plasma.components 3.0 as PlasmaComponents3
0009 import org.kde.plasma.extras 2.0 as PlasmaExtras
0010 
0011 SessionManagementScreen {
0012     id: root
0013     property Item mainPasswordBox: passwordBox
0014 
0015     property bool showUsernamePrompt: !showUserList
0016 
0017     property string lastUserName
0018     property bool loginScreenUiVisible: false
0019 
0020     //the y position that should be ensured visible when the on screen keyboard is visible
0021     property int visibleBoundary: mapFromItem(loginButton, 0, 0).y
0022     onHeightChanged: visibleBoundary = mapFromItem(loginButton, 0, 0).y + loginButton.height + PlasmaCore.Units.smallSpacing
0023 
0024     property int fontSize: parseInt(config.fontSize)
0025 
0026     signal loginRequest(string username, string password)
0027 
0028     onShowUsernamePromptChanged: {
0029         if (!showUsernamePrompt) {
0030             lastUserName = ""
0031         }
0032     }
0033 
0034     onUserSelected: {
0035         // Don't startLogin() here, because the signal is connected to the
0036         // Escape key as well, for which it wouldn't make sense to trigger
0037         // login.
0038         focusFirstVisibleFormControl();
0039     }
0040 
0041     QQC2.StackView.onActivating: {
0042         // Controls are not visible yet.
0043         Qt.callLater(focusFirstVisibleFormControl);
0044     }
0045 
0046     function focusFirstVisibleFormControl() {
0047         const nextControl = (userNameInput.visible
0048             ? userNameInput
0049             : (passwordBox.visible
0050                 ? passwordBox
0051                 : loginButton));
0052         // Using TabFocusReason, so that the loginButton gets the visual highlight.
0053         nextControl.forceActiveFocus(Qt.TabFocusReason);
0054     }
0055 
0056     /*
0057      * Login has been requested with the following username and password
0058      * If username field is visible, it will be taken from that, otherwise from the "name" property of the currentIndex
0059      */
0060     function startLogin() {
0061         const username = showUsernamePrompt ? userNameInput.text : userList.selectedUser
0062         const password = passwordBox.text
0063 
0064         footer.enabled = false
0065         mainStack.enabled = false
0066         userListComponent.userList.opacity = 0.5
0067 
0068         // This is partly because it looks nicer, but more importantly it
0069         // works round a Qt bug that can trigger if the app is closed with a
0070         // TextField focused.
0071         //
0072         // See https://bugreports.qt.io/browse/QTBUG-55460
0073         loginButton.forceActiveFocus();
0074         loginRequest(username, password);
0075     }
0076 
0077     PlasmaComponents3.TextField {
0078         id: userNameInput
0079         font.pointSize: fontSize + 1
0080         Layout.fillWidth: true
0081 
0082         text: lastUserName
0083         visible: showUsernamePrompt
0084         focus: showUsernamePrompt && !lastUserName //if there's a username prompt it gets focus first, otherwise password does
0085         placeholderText: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Username")
0086 
0087         onAccepted: {
0088             if (root.loginScreenUiVisible) {
0089                 passwordBox.forceActiveFocus()
0090             }
0091         }
0092     }
0093 
0094     RowLayout {
0095         Layout.fillWidth: true
0096 
0097         PlasmaExtras.PasswordField {
0098             id: passwordBox
0099             font.pointSize: fontSize + 1
0100             Layout.fillWidth: true
0101 
0102             placeholderText: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Password")
0103             focus: !showUsernamePrompt || lastUserName
0104 
0105             // Disable reveal password action because SDDM does not have the breeze icon set loaded
0106             rightActions: []
0107 
0108             onAccepted: {
0109                 if (root.loginScreenUiVisible) {
0110                     startLogin();
0111                 }
0112             }
0113 
0114             visible: root.showUsernamePrompt || userList.currentItem.needsPassword
0115 
0116             Keys.onEscapePressed: {
0117                 mainStack.currentItem.forceActiveFocus();
0118             }
0119 
0120             //if empty and left or right is pressed change selection in user switch
0121             //this cannot be in keys.onLeftPressed as then it doesn't reach the password box
0122             Keys.onPressed: {
0123                 if (event.key === Qt.Key_Left && !text) {
0124                     userList.decrementCurrentIndex();
0125                     event.accepted = true
0126                 }
0127                 if (event.key === Qt.Key_Right && !text) {
0128                     userList.incrementCurrentIndex();
0129                     event.accepted = true
0130                 }
0131             }
0132 
0133             Connections {
0134                 target: sddm
0135                 function onLoginFailed() {
0136                     passwordBox.selectAll()
0137                     passwordBox.forceActiveFocus()
0138                 }
0139             }
0140         }
0141 
0142         PlasmaComponents3.Button {
0143             id: loginButton
0144             Accessible.name: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Log In")
0145             Layout.preferredHeight: passwordBox.implicitHeight
0146             Layout.preferredWidth: text.length === 0 ? loginButton.Layout.preferredHeight : -1
0147 
0148             icon.name: text.length === 0 ? (root.LayoutMirroring.enabled ? "go-previous" : "go-next") : ""
0149 
0150             text: root.showUsernamePrompt || userList.currentItem.needsPassword ? "" : i18n("Log In")
0151             onClicked: startLogin()
0152             Keys.onEnterPressed: clicked()
0153             Keys.onReturnPressed: clicked()
0154         }
0155     }
0156 }