Unity 8
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 
17 import QtQuick 2.4
18 import QtQuick.Layouts 1.1
19 import Ubuntu.Components 1.3
20 import ".." as LocalComponents
21 import "../../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 
28 LocalComponents.Page {
29  id: passwdSetPage
30  objectName: "passwdSetPage"
31  title: i18n.tr("Lock Screen Password")
32  forwardButtonSourceComponent: forwardButton
33 
34  readonly property alias password: passwordField.text
35  readonly property alias password2: password2Field.text
36  readonly property bool passwordsMatching: password == password2 && password.trim().length > 7
37 
38  Flickable {
39  id: column
40  clip: true
41  flickableDirection: Flickable.VerticalFlick
42  anchors.fill: content
43  anchors.leftMargin: parent.leftMargin
44  anchors.rightMargin: parent.rightMargin
45  anchors.topMargin: customMargin
46 
47  bottomMargin: Qt.inputMethod.keyboardRectangle.height - height
48 
49  Behavior on contentY { UbuntuNumberAnimation {} }
50 
51  // info label
52  Label {
53  id: infoLabel
54  objectName: "infoLabel"
55  anchors {
56  left: parent.left
57  right: parent.right
58  }
59  wrapMode: Text.Wrap
60  font.weight: Font.Light
61  color: textColor
62  text: i18n.tr("Enter at least 8 characters")
63  }
64 
65  // password
66  Label {
67  id: pass1Label
68  anchors {
69  left: parent.left
70  right: parent.right
71  top: infoLabel.bottom
72  topMargin: units.gu(3)
73  }
74  text: i18n.tr("Choose password")
75  color: textColor
76  }
77  LocalComponents.WizardTextField {
78  id: passwordField
79  anchors {
80  left: parent.left
81  right: parent.right
82  top: pass1Label.bottom
83  topMargin: units.gu(1)
84  }
85  objectName: "passwordField"
86  echoMode: TextInput.Password
87  onAccepted: password2Field.forceActiveFocus()
88  onActiveFocusChanged: {
89  if (activeFocus) {
90  column.contentY = pass1Label.y
91  }
92  }
93  }
94 
95  // password 2
96  Label {
97  id: pass2Label
98  anchors {
99  left: parent.left
100  right: parent.right
101  top: passwordField.bottom
102  topMargin: units.gu(3)
103  }
104  text: i18n.tr("Confirm password")
105  color: textColor
106  }
107  LocalComponents.WizardTextField {
108  anchors {
109  left: parent.left
110  right: parent.right
111  top: pass2Label.bottom
112  topMargin: units.gu(1)
113  }
114  id: password2Field
115  objectName: "password2Field"
116  echoMode: TextInput.Password
117  onActiveFocusChanged: {
118  if (activeFocus) {
119  column.contentY = pass2Label.y
120  }
121  }
122  }
123 
124  // password meter
125  LocalComponents.PasswordMeter {
126  id: passMeter
127  anchors {
128  left: parent.left
129  right: parent.right
130  top: password2Field.bottom
131  topMargin: units.gu(1)
132  }
133 
134  password: passwordField.text
135  matching: passwordsMatching ? true : (password2.trim().length > 0 ? false : undefined)
136  }
137  }
138 
139  Component {
140  id: forwardButton
141  LocalComponents.StackButton {
142  text: i18n.tr("Next")
143  enabled: passwordsMatching
144  onClicked: {
145  root.password = password;
146  pageStack.next();
147  }
148  }
149  }
150 }