Lomiri
Loading...
Searching...
No Matches
passcode-desktop.qml
1/*
2 * Copyright (C) 2015-2016 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
17import QtQuick 2.12
18import QtQuick.Layouts 1.1
19import Lomiri.Components 1.3
20import ".." as LocalComponents
21import "../../Components"
22
23/**
24 * See the main passwd-type page for an explanation of why we don't actually
25 * directly set the password here.
26 */
27
28LocalComponents.Page {
29 id: passwdSetPage
30 objectName: "passcodeDesktopPage"
31 title: i18n.tr("Lock Screen Passcode")
32 focusItem: passwordField
33 forwardButtonSourceComponent: forwardButton
34
35 readonly property alias password: passwordField.text
36 readonly property alias password2: password2Field.text
37 readonly property bool passwordsMatching: password != "" && password == password2
38
39 function savePasswordAndGoNext() {
40 root.password = password;
41 pageStack.next();
42 }
43
44 Flickable {
45 id: column
46 clip: true
47 flickableDirection: Flickable.VerticalFlick
48 anchors.fill: content
49 anchors.leftMargin: parent.leftMargin
50 anchors.rightMargin: parent.rightMargin
51 anchors.topMargin: customMargin
52
53 bottomMargin: Qt.inputMethod.keyboardRectangle.height - height - customMargin
54
55 Behavior on contentY { LomiriNumberAnimation {} }
56
57 Label {
58 id: infoLabel
59 objectName: "infoLabel"
60 anchors {
61 left: parent.left
62 right: parent.right
63 top: parent.top
64 }
65 wrapMode: Text.Wrap
66 font.weight: Font.Light
67 color: textColor
68 text: i18n.tr("Enter at least 4 numbers to setup your passcode")
69 }
70
71 GridLayout {
72 anchors {
73 left: parent.left
74 right: parent.right
75 top: infoLabel.bottom
76 topMargin: units.gu(3)
77 }
78
79 columns: 2
80 columnSpacing: units.gu(2)
81 rowSpacing: units.gu(2)
82
83 Label {
84 text: i18n.tr("Choose passcode")
85 color: textColor
86 }
87 LocalComponents.WizardTextField {
88 Layout.fillWidth: true
89 id: passwordField
90 objectName: "passwordField"
91 echoMode: TextInput.Password
92 inputMethodHints: Qt.ImhDigitsOnly
93 validator: RegExpValidator { regExp: /^\d{4,}$/ }
94 maximumLength: 12
95 onAccepted: password2Field.forceActiveFocus()
96 onActiveFocusChanged: {
97 if (activeFocus) {
98 column.contentY = y
99 }
100 }
101 }
102
103 Label {
104 text: i18n.tr("Confirm passcode")
105 color: textColor
106 }
107 LocalComponents.WizardTextField {
108 Layout.fillWidth: true
109 id: password2Field
110 objectName: "password2Field"
111 echoMode: TextInput.Password
112 inputMethodHints: Qt.ImhDigitsOnly
113 validator: RegExpValidator { regExp: /^\d{4,}$/ }
114 maximumLength: 12
115 onAccepted: {
116 if (passwordsMatching) {
117 savePasswordAndGoNext();
118 }
119 }
120 onActiveFocusChanged: {
121 if (activeFocus) {
122 column.contentY = y
123 }
124 }
125 }
126
127 Label {
128 Layout.row: 2
129 Layout.column: 1
130 id: errorLabel
131 property bool hasError: password && password != password2
132 wrapMode: Text.Wrap
133 color: hasError ? errorColor : LomiriColors.ash
134 visible: password && password2
135 fontSize: "small"
136 text: {
137 if (password) {
138 if (password2.length < password2Field.maximumLength)
139 return i18n.tr("Passcode too short");
140 else if (password == password2)
141 return i18n.tr("Passcodes match");
142 else if (password2)
143 return i18n.tr("Passcodes do not match");
144 }
145 return "";
146 }
147 }
148 }
149 }
150
151 Component {
152 id: forwardButton
153 LocalComponents.StackButton {
154 text: i18n.tr("Next")
155 enabled: passwordsMatching
156 onClicked: savePasswordAndGoNext()
157 }
158 }
159}