2 * Copyright (C) 2015-2016 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/>.
18import QtQuick.Layouts 1.1
19import Lomiri.Components 1.3
20import ".." as LocalComponents
21import "../../Components"
24 * See the main passwd-type page for an explanation of why we don't actually
25 * directly set the password here.
30 objectName: "passcodeDesktopPage"
31 title: i18n.tr("Lock Screen Passcode")
32 focusItem: passwordField
33 forwardButtonSourceComponent: forwardButton
35 readonly property alias password: passwordField.text
36 readonly property alias password2: password2Field.text
37 readonly property bool passwordsMatching: password != "" && password == password2
39 function savePasswordAndGoNext() {
40 root.password = password;
47 flickableDirection: Flickable.VerticalFlick
49 anchors.leftMargin: parent.leftMargin
50 anchors.rightMargin: parent.rightMargin
51 anchors.topMargin: customMargin
53 bottomMargin: Qt.inputMethod.keyboardRectangle.height - height - customMargin
55 Behavior on contentY { LomiriNumberAnimation {} }
59 objectName: "infoLabel"
66 font.weight: Font.Light
68 text: i18n.tr("Enter at least 4 numbers to setup your passcode")
76 topMargin: units.gu(3)
80 columnSpacing: units.gu(2)
81 rowSpacing: units.gu(2)
84 text: i18n.tr("Choose passcode")
87 LocalComponents.WizardTextField {
88 Layout.fillWidth: true
90 objectName: "passwordField"
91 echoMode: TextInput.Password
92 inputMethodHints: Qt.ImhDigitsOnly
93 validator: RegExpValidator { regExp: /^\d{4,}$/ }
95 onAccepted: password2Field.forceActiveFocus()
96 onActiveFocusChanged: {
104 text: i18n.tr("Confirm passcode")
107 LocalComponents.WizardTextField {
108 Layout.fillWidth: true
110 objectName: "password2Field"
111 echoMode: TextInput.Password
112 inputMethodHints: Qt.ImhDigitsOnly
113 validator: RegExpValidator { regExp: /^\d{4,}$/ }
116 if (passwordsMatching) {
117 savePasswordAndGoNext();
120 onActiveFocusChanged: {
131 property bool hasError: password && password != password2
133 color: hasError ? errorColor : LomiriColors.ash
134 visible: password && password2
138 if (password2.length < password2Field.maximumLength)
139 return i18n.tr("Passcode too short");
140 else if (password == password2)
141 return i18n.tr("Passcodes match");
143 return i18n.tr("Passcodes do not match");
153 LocalComponents.StackButton {
154 text: i18n.tr("Next")
155 enabled: passwordsMatching
156 onClicked: savePasswordAndGoNext()