Unity 8
PassphraseLockscreen.qml
1 /*
2  * Copyright (C) 2013,2014,2015 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.0
18 import Ubuntu.Components 0.1
19 import "../Components"
20 
21 Item {
22  id: root
23  y: units.gu(4)
24  height: shakeContainer.height
25 
26  property string infoText
27  property string errorText
28  property bool entryEnabled: true
29 
30  readonly property string passphrase: pinentryField.text
31 
32  signal entered(string passphrase)
33  signal cancel()
34 
35  function clear(playAnimation) {
36  pinentryField.text = "";
37  pinentryField.incorrectOverride = false;
38  pinentryField.forceActiveFocus();
39  if (playAnimation) {
40  wrongPasswordAnimation.start();
41  }
42  }
43 
44  onActiveFocusChanged: if (activeFocus) pinentryField.forceActiveFocus()
45 
46  Column {
47  id: shakeContainer
48  anchors.horizontalCenter: parent.horizontalCenter
49  width: parent.width
50  spacing: units.gu(2)
51 
52  Label {
53  id: infoField
54  objectName: "infoTextLabel"
55  fontSize: "x-large"
56  color: "#f3f3e7"
57  anchors.horizontalCenter: parent.horizontalCenter
58  text: root.infoText
59  }
60 
61  Item {
62  id: entryContainer
63  anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
64  height: units.gu(4)
65 
66  TextInput {
67  id: pinentryField
68  objectName: "pinentryField"
69 
70  property bool incorrectOverride: false
71 
72  anchors {
73  top: parent.top
74  left: parent.left
75  right: parent.right
76  }
77  horizontalAlignment: Text.AlignHCenter
78  font.pixelSize: FontUtils.sizeToPixels("large")
79  echoMode: TextInput.Password
80  inputMethodHints: Qt.ImhHiddenText | Qt.ImhSensitiveData |
81  Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
82  color: "#f3f3e7"
83  cursorDelegate: Item {} // disable cursor
84  onCursorPositionChanged: {
85  // And because we don't show the cursor, always position the
86  // cursor at the end of the string (so backspace works like
87  // the user expects, even if they've clicked on us and
88  // thus accidentally moved the cursor)
89  if (cursorPosition !== length) {
90  cursorPosition = length
91  }
92  }
93  clip: true
94 
95  // This is so that we can draw our own dots, for we want
96  // complete control over the pixel sizes. (The ubuntu font
97  // has oddly sized password characters that don't scale right)
98  opacity: 0
99 
100  // simulate being disabled, but without removing OSK focus
101  maximumLength: root.entryEnabled ? 32767 : length
102 
103  onTextChanged: incorrectOverride = true
104 
105  onAccepted: {
106  if (pinentryField.text) {
107  root.entered(pinentryField.text);
108  }
109  }
110  }
111 
112  Row {
113  id: dotRow
114  anchors.centerIn: entryContainer
115 
116  property real dotSize: Math.min(units.gu(2), entryContainer.width / pinentryField.length)
117  spacing: Math.min(units.gu(2), Math.max(0, (entryContainer.width / pinentryField.length) - dotSize))
118 
119  Repeater {
120  model: pinentryField.length
121  delegate: Rectangle {
122  color: "#f3f3e7"
123  width: dotRow.dotSize
124  height: width
125  radius: width / 2
126  }
127  }
128  }
129 
130  Label {
131  id: wrongNoticeLabel
132  objectName: "wrongNoticeLabel"
133  fontSize: "large"
134  color: "#f3f3e7"
135  anchors.horizontalCenter: parent.horizontalCenter
136  horizontalAlignment: Text.AlignHCenter
137  text: root.errorText
138  visible: pinentryField.text.length == 0 && !pinentryField.incorrectOverride
139  }
140  }
141  }
142 
143  WrongPasswordAnimation {
144  id: wrongPasswordAnimation
145  objectName: "wrongPasswordAnimation"
146  target: shakeContainer
147  }
148 }