2 * Copyright (C) 2013 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 0.1
19 import "../Components"
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 signal entered(string passphrase)
34 function clear(playAnimation) {
35 pinentryField.text = "";
36 pinentryField.incorrectOverride = false;
37 pinentryField.forceActiveFocus();
39 wrongPasswordAnimation.start();
43 onActiveFocusChanged: if (activeFocus) pinentryField.forceActiveFocus()
47 anchors.horizontalCenter: parent.horizontalCenter
53 objectName: "infoTextLabel"
56 anchors.horizontalCenter: parent.horizontalCenter
62 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
67 objectName: "pinentryField"
69 property bool incorrectOverride: false
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
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
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)
99 // simulate being disabled, but without removing OSK focus
100 maximumLength: root.entryEnabled ? 32767 : length
102 onTextChanged: incorrectOverride = true
105 if (pinentryField.text) {
106 root.entered(pinentryField.text);
113 anchors.centerIn: entryContainer
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))
119 model: pinentryField.length
120 delegate: Rectangle {
122 width: dotRow.dotSize
131 objectName: "wrongNoticeLabel"
134 anchors.horizontalCenter: parent.horizontalCenter
135 horizontalAlignment: Text.AlignHCenter
137 visible: pinentryField.text.length == 0 && !pinentryField.incorrectOverride
142 WrongPasswordAnimation {
143 id: wrongPasswordAnimation
144 objectName: "wrongPasswordAnimation"
145 target: shakeContainer