/*SPDX-FileCopyrightText: 2016 David Edmundson <davidedmundson@kde.org>SPDX-License-Identifier: LGPL-2.0-or-later*/import QtQuickimport QtQuick.Layoutsimport QtQuick.Controls as QQC2import org.kde.plasma.components as PlasmaComponents3import org.kde.plasma.extras as PlasmaExtrasimport org.kde.kirigami as Kirigamiimport org.kde.kscreenlocker as ScreenLockerimport org.kde.breeze.componentsSessionManagementScreen {id: sessionManagerproperty alias passwordInputVisible: passwordLayout.visiblereadonly property alias mainPasswordBox: passwordBoxproperty bool lockScreenUiVisible: falseproperty alias showPassword: passwordBox.showPassword//the y position that should be ensured visible when the on screen keyboard is visibleproperty int visibleBoundary: mapFromItem(loginButton, 0, 0).yonHeightChanged: visibleBoundary = mapFromItem(loginButton, 0, 0).y + loginButton.height + Kirigami.Units.smallSpacing/** Login has been requested with the following username and password* If username field is visible, it will be taken from that, otherwise from the "name" property of the currentIndex*/signal passwordResult(string password)onUserSelected: {const nextControl = (passwordBox.visible ? passwordBox : loginButton);// Don't startLogin() here, because the signal is connected to the// Escape key as well, for which it wouldn't make sense to trigger// login. Using TabFocusReason, so that the loginButton gets the// visual highlight.nextControl.forceActiveFocus(Qt.TabFocusReason);}function startLogin() {const password = passwordBox.text// This is partly because it looks nicer, but more importantly it// works round a Qt bug that can trigger if the app is closed with a// TextField focused.//// See https://bugreports.qt.io/browse/QTBUG-55460loginButton.forceActiveFocus();passwordResult(password);}RowLayout {id: passwordLayoutLayout.fillWidth: truePlasmaExtras.PasswordField {id: passwordBoxfont.pointSize: Kirigami.Theme.defaultFont.pointSize + 1Layout.fillWidth: truetext: PasswordSync.passwordplaceholderText: i18ndc("plasma_shell_org.kde.plasma.desktop", "@info:placeholder in text field", "Password")focus: true// In Qt this is implicitly active based on focus rather than visibility// in any other application having a focussed invisible object would be weird// but here we are using to wake out of screensaver mode// We need to explicitly disable cursor flashing to avoid unnecessary renderscursorVisible: visibleonAccepted: {if (sessionManager.lockScreenUiVisible) {sessionManager.startLogin();}}//if empty and left or right is pressed change selection in user switch//this cannot be in keys.onLeftPressed as then it doesn't reach the password boxKeys.onPressed: event => {if (event.key === Qt.Key_Left && !text) {sessionManager.userList.decrementCurrentIndex();event.accepted = true}if (event.key === Qt.Key_Right && !text) {sessionManager.userList.incrementCurrentIndex();event.accepted = true}}Connections {target: rootfunction onClearPassword() {passwordBox.forceActiveFocus()passwordBox.text = "";passwordBox.text = Qt.binding(() => PasswordSync.password);}function onNotificationRepeated() {sessionManager.playHighlightAnimation();}}}Binding {target: PasswordSyncproperty: "password"value: passwordBox.text}PlasmaComponents3.Button {id: loginButtonAccessible.name: i18ndc("plasma_shell_org.kde.plasma.desktop", "@action:button accessible only", "Unlock")Layout.preferredHeight: passwordBox.implicitHeightLayout.preferredWidth: loginButton.Layout.preferredHeighticon.name: LayoutMirroring.enabled ? "go-previous" : "go-next"onClicked: sessionManager.startLogin()Keys.onEnterPressed: clicked()Keys.onReturnPressed: clicked()}}component FailableLabel : PlasmaComponents3.Label {id: _failableLabelrequired property int kindrequired property string labelvisible: authenticator.authenticatorTypes & kindtext: labeltextFormat: Text.PlainTexthorizontalAlignment: Text.AlignHCenterLayout.fillWidth: trueRejectPasswordAnimation {id: _rejectAnimationtarget: _failableLabelonFinished: _timer.restart()}Connections {target: authenticatorfunction onNoninteractiveError(kind, authenticator) {if (kind & _failableLabel.kind) {_failableLabel.text = Qt.binding(() => authenticator.errorMessage)_rejectAnimation.start()}}}Timer {id: _timerinterval: Kirigami.Units.humanMomentonTriggered: {_failableLabel.text = Qt.binding(() => _failableLabel.label)}}}FailableLabel {kind: ScreenLocker.Authenticator.Fingerprintlabel: i18ndc("plasma_shell_org.kde.plasma.desktop", "@info:usagetip", "(or scan your fingerprint on the reader)")}FailableLabel {kind: ScreenLocker.Authenticator.Smartcardlabel: i18ndc("plasma_shell_org.kde.plasma.desktop", "@info:usagetip", "(or scan your smartcard)")}}