Lomiri
GreeterPrompt.qml
1/*
2 * Copyright (C) 2016 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 */
16
17import QtQuick 2.4
18import Lomiri.Components 1.3
19import GSettings 1.0
20import "../Components"
21
22FocusScope {
23 id: root
24 implicitHeight: units.gu(5)
25 focus: true
26
27 property bool isPrompt
28 property bool isAlphanumeric
29 property string text
30 property bool isSecret
31 property bool interactive: true
32 property bool loginError: false
33 readonly property string enteredText: loader.item.enteredText
34 property bool hasKeyboard: false
35 property bool waitingToAccept: false
36
37 signal clicked()
38 signal canceled()
39 signal accepted()
40
41 GSettings {
42 id: lomiriSettings
43 schema.id: "com.lomiri.Shell"
44 }
45
46 onEnteredTextChanged: if (waitingToAccept) root.accepted()
47
48 function showFakePassword() {
49 // Just a silly hack for looking like 4 pin numbers got entered, if
50 // a fingerprint was used and we happen to be using a pin. This was
51 // a request from Design.
52 if (isSecret) {
53 loader.item.enteredText = "...."; // actual text doesn't matter
54 }
55 }
56
57 Loader {
58 id: loader
59 objectName: "promptLoader"
60
61 focus: true
62
63 anchors.fill: parent
64
65 Connections {
66 target: loader.item
67 onClicked: root.clicked()
68 onCanceled: root.canceled()
69 onAccepted: {
70 if (response == enteredText)
71 root.accepted();
72 else
73 waitingToAccept = true;
74 }
75 }
76
77 Binding {
78 target: loader.item
79 property: "text"
80 value: root.text
81 }
82
83 Binding {
84 target: loader.item
85 property: "isSecret"
86 value: root.isSecret
87 }
88
89 Binding {
90 target: loader.item
91 property: "interactive"
92 value: root.interactive
93 }
94
95 Binding {
96 target: loader.item
97 property: "loginError"
98 value: root.loginError
99 }
100
101 Binding {
102 target: loader.item
103 property: "hasKeyboard"
104 value: root.hasKeyboard
105 }
106
107 onLoaded: loader.item.focus = true
108 }
109
110 states: [
111 State {
112 name: "ButtonPrompt"
113 when: !root.isPrompt
114 PropertyChanges { target: loader; source: "ButtonPrompt.qml" }
115 },
116 State {
117 name: "PinPrompt"
118 when: root.isPrompt && !root.isAlphanumeric && root.isSecret
119 PropertyChanges { target: loader; source: "PinPrompt.qml" }
120 },
121 State {
122 name: "TextPrompt"
123 when: root.isPrompt
124 PropertyChanges { target: loader; source: "TextPrompt.qml" }
125 }
126 ]
127}