2 * Copyright (C) 2021 Capsia
3 * Copyright (C) 2016 Canonical, Ltd.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19import QtQuick.Window 2.2
20import AccountsService 0.1
21import Lomiri.Components 1.3
28 property bool isSecret
29 property bool interactive: true
30 property bool loginError: false
31 property bool hasKeyboard: false
32 property alias enteredText: passwordInput.text
33 property int pincodeLength: AccountsService.pincodeLength
37 signal accepted(string response)
39 // A fold/unfold drops and re-adds the single output; maliit hides on
40 // the surface reconfigure but the field keeps active focus, so the
41 // focus handler never re-fires and the OSK does not return. Re-request
42 // it when the window is reactivated while the field is still focused.
45 function onActiveChanged() {
46 if (Window.window && Window.window.active && passwordInput.activeFocus) {
47 Window.window.requestActivate();
48 Qt.inputMethod.show();
56 readonly property color textColor: passwordInput.enabled ? theme.palette.normal.raisedText
57 : theme.palette.disabled.raisedText
58 readonly property color selectedColor: passwordInput.enabled ? theme.palette.normal.raised
59 : theme.palette.disabled.raised
60 readonly property color drawColor: passwordInput.enabled ? theme.palette.normal.raisedSecondaryText
61 : theme.palette.disabled.raisedSecondaryText
62 readonly property color errorColor: passwordInput.enabled ? theme.palette.normal.negative
63 : theme.palette.disabled.negative
68 objectName: "promptField"
69 anchors.left: extraIcons.left
70 anchors.right: extraIcons.right
73 opacity: fakeLabel.visible ? 0 : 1
74 activeFocusOnTab: true
75 onActiveFocusChanged: {
77 // The greeter surface is not the active Qt window, so a focused
78 // field is never promoted to the input method focus object and
79 // maliit never shows; activate the window first.
80 if (Window.window) Window.window.requestActivate();
81 Qt.inputMethod.show();
85 onSelectedTextChanged: passwordInput.deselect()
86 onCursorPositionChanged: cursorPosition = length
88 validator: RegExpValidator {
92 inputMethodHints: Qt.ImhSensitiveData | Qt.ImhNoPredictiveText |
93 Qt.ImhMultiLine | // so OSK doesn't close on Enter
95 echoMode: TextInput.Password
98 cursorDelegate: Item {}
100 passwordCharacter: "●"
103 readonly property real letterSpacing: units.gu(1.75)
104 readonly property real frameSpacing: letterSpacing
106 font.pixelSize: units.gu(3)
107 font.letterSpacing: letterSpacing
111 styleName: "FocusShape"
113 // Properties needed by TextField
114 readonly property color color: d.textColor
115 readonly property color selectedTextColor: d.selectedColor
116 readonly property color selectionColor: d.textColor
117 readonly property color borderColor: "transparent"
118 readonly property color backgroundColor: "transparent"
119 readonly property color errorColor: d.errorColor
120 readonly property real frameSpacing: 0
122 // Properties needed by FocusShape
123 readonly property bool enabled: styledItem.enabled
124 readonly property bool keyNavigationFocus: styledItem.keyNavigationFocus
125 property bool activeFocusOnTab
128 onDisplayTextChanged: {
129 // We use onDisplayTextChanged instead of onTextChanged because
130 // displayText changes after text and if we did this before it
131 // updated, we would use the wrong displayText for fakeLabel.
132 root.loginError = false;
133 if (text.length === root.pincodeLength) {
138 onAccepted: respond()
141 if (root.interactive) {
142 root.accepted(passwordInput.text);
146 Keys.onEscapePressed: {
147 lomiriSettings.alwaysShowOsk = false
149 event.accepted = true;
155 spacing: passwordInput.frameSpacing
157 horizontalCenter: parent ? parent.horizontalCenter : undefined
158 horizontalCenterOffset: passwordInput.letterSpacing / 2
159 verticalCenter: passwordInput ? passwordInput.verticalCenter : undefined
164 objectName: "promptPinHint"
166 text: Array(root.pincodeLength).fill('○').join("")
170 pixelSize: units.gu(3)
171 letterSpacing: units.gu(1.75)
173 elide: Text.ElideRight
176 name: "keyboard-caps-enabled"
180 visible: false // TODO: detect when caps lock is on
181 anchors.verticalCenter: parent.verticalCenter
184 objectName: "greeterPromptKeyboardButton"
185 name: "input-keyboard-symbolic"
189 visible: !lomiriSettings.alwaysShowOsk && root.hasKeyboard
190 anchors.verticalCenter: parent.verticalCenter
193 onClicked: lomiriSettings.alwaysShowOsk = true
197 name: "dialog-warning-symbolic"
201 visible: root.loginError
202 anchors.verticalCenter: parent.verticalCenter
206 // Have a fake label that covers the text field after the user presses
207 // enter. What we *really* want is a disabled mode that doesn't lose OSK
208 // focus. Because our goal here is simply to keep the OSK up while
209 // we wait for PAM to get back to us, and while waiting, we don't want
210 // the user to be able to edit the field (simply because it would look
211 // weird if we allowed that). But until we have such a disabled mode,
212 // we'll fake it by covering the real text field with a label.
215 anchors.verticalCenter: extraIcons ? extraIcons.verticalCenter : undefined
216 anchors.left: extraIcons ? extraIcons.left : undefined
217 anchors.right: parent ? parent.right : undefined
218 anchors.rightMargin: passwordInput.frameSpacing * 2 + extraIcons.width
221 pixelSize: pinHint.font.pixelSize
222 letterSpacing: pinHint.font.letterSpacing
224 text: passwordInput.displayText
225 visible: !root.interactive