Lomiri
Loading...
Searching...
No Matches
password-set.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: "passwdSetPage"
31 title: i18n.tr("Lock Screen Password")
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 == password2 && password.trim().length > 7
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
54
55 Behavior on contentY { LomiriNumberAnimation {} }
56
57 // info label
58 Label {
59 id: infoLabel
60 objectName: "infoLabel"
61 anchors {
62 left: parent.left
63 right: parent.right
64 }
65 wrapMode: Text.Wrap
66 font.weight: Font.Light
67 color: textColor
68 text: i18n.tr("Enter at least 8 characters")
69 }
70
71 // password
72 Label {
73 id: pass1Label
74 anchors {
75 left: parent.left
76 right: parent.right
77 top: infoLabel.bottom
78 topMargin: units.gu(3)
79 }
80 text: i18n.tr("Choose password")
81 color: textColor
82 }
83 LocalComponents.WizardTextField {
84 id: passwordField
85 anchors {
86 left: parent.left
87 right: parent.right
88 top: pass1Label.bottom
89 topMargin: units.gu(1)
90 }
91 objectName: "passwordField"
92 echoMode: TextInput.Password
93 onAccepted: password2Field.forceActiveFocus()
94 onActiveFocusChanged: {
95 if (activeFocus) {
96 column.contentY = pass1Label.y
97 }
98 }
99 }
100
101 // password 2
102 Label {
103 id: pass2Label
104 anchors {
105 left: parent.left
106 right: parent.right
107 top: passwordField.bottom
108 topMargin: units.gu(3)
109 }
110 text: i18n.tr("Confirm password")
111 color: textColor
112 }
113 LocalComponents.WizardTextField {
114 anchors {
115 left: parent.left
116 right: parent.right
117 top: pass2Label.bottom
118 topMargin: units.gu(1)
119 }
120 id: password2Field
121 objectName: "password2Field"
122 echoMode: TextInput.Password
123 onAccepted: {
124 if (passwordsMatching) {
125 savePasswordAndGoNext();
126 }
127 }
128 onActiveFocusChanged: {
129 if (activeFocus) {
130 column.contentY = pass2Label.y
131 }
132 }
133 }
134
135 // password meter
136 LocalComponents.PasswordMeter {
137 id: passMeter
138 anchors {
139 left: parent.left
140 right: parent.right
141 top: password2Field.bottom
142 topMargin: units.gu(1)
143 }
144
145 password: passwordField.text
146 matching: passwordsMatching ? true : (password2.trim().length > 0 ? false : undefined)
147 }
148 }
149
150 Component {
151 id: forwardButton
152 LocalComponents.StackButton {
153 text: i18n.tr("Next")
154 enabled: passwordsMatching
155 onClicked: savePasswordAndGoNext()
156 }
157 }
158}