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