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