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