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