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