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