on bb09f86 help sign in
unity8/qml/Greeter/PromptList.qml
148 lines 4.4 kB history raw
1/*
2 * Copyright (C) 2017 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.4
18import Ubuntu.Components 1.3
19import "../Components"
20import "." 0.1
22FocusScope {
23 id: root
24 height: childrenRect.height
26 property bool alphanumeric: true
27 property bool interactive: true
29 signal responded(string text)
30 signal clicked()
31 signal canceled()
33 function showFakePassword() {
34 for (var i = 0; i < repeater.count; i++) {
35 var item = repeater.itemAt(i).item;
36 if (item.isPrompt) {
37 item.showFakePassword();
38 }
39 }
40 }
42 QtObject {
43 id: d
45 function sendResponse() {
46 for (var i = 0; i < repeater.count; i++) {
47 var item = repeater.itemAt(i).item;
48 if (item.isPrompt) {
49 root.responded(item.enteredText);
50 }
51 }
52 }
53 }
55 Column {
56 width: parent.width
57 spacing: units.gu(0.5)
59 Repeater {
60 id: repeater
61 model: LightDMService.prompts
63 delegate: Loader {
64 id: loader
66 readonly property bool isLabel: model.type == LightDMService.prompts.Message ||
67 model.type == LightDMService.prompts.Error
68 readonly property var modelData: model
70 sourceComponent: isLabel ? infoLabel : greeterPrompt
72 onLoaded: {
73 for (var i = 0; i < repeater.count; i++) {
74 var item = repeater.itemAt(i);
75 if (item && !item.isLabel) {
76 item.focus = true;
77 break;
78 }
79 }
80 loader.item.opacity = 1;
81 }
83 Binding {
84 target: loader.item
85 property: "model"
86 value: loader.modelData
87 }
88 }
89 }
90 }
92 Component {
93 id: infoLabel
95 FadingLabel {
96 objectName: "infoLabel" + model.index
97 width: root.width
99 property var model
100 readonly property bool isPrompt: false
102 color: model.type === LightDMService.prompts.Message ? theme.palette.normal.raisedText
103 : theme.palette.normal.negative
104 fontSize: "small"
105 textFormat: Text.PlainText
106 text: model.text
108 Behavior on opacity { UbuntuNumberAnimation {} }
109 opacity: 0
110 }
111 }
113 Component {
114 id: greeterPrompt
116 GreeterPrompt {
117 objectName: "greeterPrompt" + model.index
118 width: root.width
120 property var model
122 interactive: root.interactive
123 isAlphanumeric: model.text !== "" || root.alphanumeric
124 isPrompt: model.type !== LightDMService.prompts.Button
125 isSecret: model.type === LightDMService.prompts.Secret
126 text: model.text ? model.text : (isAlphanumeric ? i18n.tr("Passphrase") : i18n.tr("Passcode"))
128 onClicked: root.clicked()
129 onAccepted: {
130 // If there is another GreeterPrompt, focus it.
131 for (var i = model.index + 1; i < repeater.count; i++) {
132 var item = repeater.itemAt(i).item;
133 if (item.isPrompt) {
134 item.forceActiveFocus();
135 return;
136 }
137 }
139 // Nope we're the last one; just send our response.
140 d.sendResponse();
141 }
142 onCanceled: root.canceled()
144 Behavior on opacity { UbuntuNumberAnimation {} }
145 opacity: 0
146 }
147 }