Unity 8
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 
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: "passcodeDesktopPage"
31  title: i18n.tr("Lock Screen Passcode")
32  forwardButtonSourceComponent: forwardButton
33 
34  readonly property alias password: passwordField.text
35  readonly property alias password2: password2Field.text
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 - customMargin
47 
48  Behavior on contentY { UbuntuNumberAnimation {} }
49 
50  Label {
51  id: infoLabel
52  objectName: "infoLabel"
53  anchors {
54  left: parent.left
55  right: parent.right
56  top: parent.top
57  }
58  wrapMode: Text.Wrap
59  font.weight: Font.Light
60  color: textColor
61  text: i18n.tr("Enter 4 numbers to setup your passcode")
62  }
63 
64  GridLayout {
65  anchors {
66  left: parent.left
67  right: parent.right
68  top: infoLabel.bottom
69  topMargin: units.gu(3)
70  }
71 
72  columns: 2
73  columnSpacing: units.gu(2)
74  rowSpacing: units.gu(2)
75 
76  Label {
77  text: i18n.tr("Choose passcode")
78  color: textColor
79  }
80  LocalComponents.WizardTextField {
81  Layout.fillWidth: true
82  id: passwordField
83  objectName: "passwordField"
84  echoMode: TextInput.Password
85  inputMethodHints: Qt.ImhDigitsOnly
86  validator: RegExpValidator { regExp: /^\d{4}$/ }
87  maximumLength: 4
88  onAccepted: password2Field.forceActiveFocus()
89  onActiveFocusChanged: {
90  if (activeFocus) {
91  column.contentY = y
92  }
93  }
94  }
95 
96  Label {
97  text: i18n.tr("Confirm passcode")
98  color: textColor
99  }
100  LocalComponents.WizardTextField {
101  Layout.fillWidth: true
102  id: password2Field
103  objectName: "password2Field"
104  echoMode: TextInput.Password
105  inputMethodHints: Qt.ImhDigitsOnly
106  validator: RegExpValidator { regExp: /^\d{4}$/ }
107  maximumLength: 4
108  onActiveFocusChanged: {
109  if (activeFocus) {
110  column.contentY = y
111  }
112  }
113  }
114 
115  Label {
116  Layout.row: 2
117  Layout.column: 1
118  id: errorLabel
119  property bool hasError: password && password != password2
120  wrapMode: Text.Wrap
121  color: hasError ? errorColor : UbuntuColors.ash
122  visible: password && password2
123  fontSize: "small"
124  text: {
125  if (password) {
126  if (password2.length < password2Field.maximumLength)
127  return i18n.tr("Passcode too short");
128  else if (password == password2)
129  return i18n.tr("Passcodes match");
130  else if (password2)
131  return i18n.tr("Passcodes do not match");
132  }
133  return "";
134  }
135  }
136  }
137  }
138 
139  Component {
140  id: forwardButton
141  LocalComponents.StackButton {
142  text: i18n.tr("Next")
143  enabled: password != "" && password == password2
144  onClicked: {
145  root.password = password;
146  pageStack.next();
147  }
148  }
149  }
150 }