2 * Copyright (C) 2013,2014,2015 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.3
19 import "../Components"
24 height: shakeContainer.height
26 property string infoText
27 property string errorText
28 property bool entryEnabled: true
29 property color foregroundColor: "#000000"
31 readonly property string passphrase: pinentryField.text
33 signal entered(string passphrase)
36 function clear(playAnimation) {
37 pinentryField.text = "";
38 pinentryField.incorrectOverride = false;
39 pinentryField.forceActiveFocus();
41 wrongPasswordAnimation.start();
45 onActiveFocusChanged: if (activeFocus) pinentryField.forceActiveFocus()
49 anchors.horizontalCenter: parent.horizontalCenter
55 objectName: "infoTextLabel"
57 color: root.foregroundColor
58 anchors.horizontalCenter: parent.horizontalCenter
64 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
69 objectName: "pinentryField"
71 property bool incorrectOverride: false
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: root.foregroundColor
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
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)
101 // simulate being disabled, but without removing OSK focus
102 maximumLength: root.entryEnabled ? 32767 : length
104 onTextChanged: incorrectOverride = true
107 if (pinentryField.text) {
108 root.entered(pinentryField.text);
115 anchors.centerIn: entryContainer
117 property real dotSize: Math.min(units.gu(2), entryContainer.width / pinentryField.length)
118 spacing: Math.min(units.gu(2), Math.max(0, (entryContainer.width / pinentryField.length) - dotSize))
121 model: pinentryField.length
122 delegate: Rectangle {
123 color: root.foregroundColor
124 width: dotRow.dotSize
133 objectName: "wrongNoticeLabel"
135 color: root.foregroundColor
136 anchors.horizontalCenter: parent.horizontalCenter
137 horizontalAlignment: Text.AlignHCenter
139 visible: pinentryField.text.length == 0 && !pinentryField.incorrectOverride
144 WrongPasswordAnimation {
145 id: wrongPasswordAnimation
146 objectName: "wrongPasswordAnimation"
147 target: shakeContainer