2 * Copyright (C) 2014-2016 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.3
19 import Ubuntu.Components.ListItems 1.3
20 import Ubuntu.SystemSettings.SecurityPrivacy 1.0
21 import ".." as LocalComponents
24 * One quirk with this page: we don't actually set the password. We avoid
25 * doing it here because the user can come back to this page and change their
26 * answer. We don't run as root, so if we did set the password immediately,
27 * we'd need to prompt for their previous password when they came back and
28 * changed their answer. Which is silly UX. So instead, we just keep track
29 * of their choice and set the password at the end (see Pages.qml).
30 * Setting the password shouldn't fail, since Ubuntu Touch has loose password
31 * requirements, but we'll check what we can here. Ideally we'd be able to ask
32 * the system if a password is legal without actually setting that password.
35 LocalComponents.Page {
37 objectName: "passwdPage"
39 title: i18n.tr("Lock Screen")
40 forwardButtonSourceComponent: forwardButton
42 // If the user has set a password some other way (via ubuntu-device-flash
43 // or this isn't the first time the wizard has been run, etc). We can't
44 // properly set the password again, so let's not pretend we can.
45 skip: securityPrivacy.securityType !== UbuntuSecurityPrivacyPanel.Swipe
47 function indexToMethod(index) {
48 if (index === 0/* || index === 1*/)
49 return UbuntuSecurityPrivacyPanel.Passphrase;
50 else if (index === 1/*2*/)
51 return UbuntuSecurityPrivacyPanel.Passcode;
53 return UbuntuSecurityPrivacyPanel.Swipe;
56 // Component.onCompleted: {
57 // if (root.password !== "") // the user has set a password as part of the previous page
58 // selector.currentIndex = 0;
60 // selector.currentIndex = 1;
66 anchors.topMargin: customMargin
67 anchors.leftMargin: wideMode ? parent.leftMargin : 0
68 anchors.rightMargin: wideMode ? parent.rightMargin : 0
72 anchors.left: parent.left
73 anchors.right: parent.right
74 boundsBehavior: Flickable.StopAtBounds
76 height: childrenRect.height
78 // this is the order we want to display it; cf indexToMethod()
79 model: [/*UbuntuSecurityPrivacyPanel.Passphrase, */UbuntuSecurityPrivacyPanel.Passphrase,
80 UbuntuSecurityPrivacyPanel.Passcode, UbuntuSecurityPrivacyPanel.Swipe]
84 objectName: "passwdDelegate" + index
85 readonly property bool isCurrent: index === ListView.view.currentIndex
86 highlightColor: backgroundColor
87 divider.colorFrom: dividerColor
88 divider.colorTo: backgroundColor
90 anchors.verticalCenter: parent.verticalCenter;
91 anchors.left: parent.left
92 anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
95 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
99 // return i18n.ctr("Label: Type of security method", "Ubuntu administrator password");
101 return i18n.ctr("Label: Type of security method", "Create new password");
103 return i18n.ctr("Label: Type of security method", "Create passcode (numbers only)");
105 return i18n.ctr("Label: Type of security method", "No lock code");
109 wrapMode: Text.WordWrap
115 verticalCenter: parent.verticalCenter
116 rightMargin: column.anchors.rightMargin == 0 ? staticMargin : 0
118 fillMode: Image.PreserveAspectFit
119 height: units.gu(1.5)
121 source: "data/Tick@30.png"
122 visible: itemDelegate.isCurrent
126 selector.currentIndex = index;
133 anchors.left: parent.left
134 anchors.right: parent.right
135 anchors.top: selector.bottom
143 LocalComponents.StackButton {
144 text: i18n.tr("Next")
146 var method = indexToMethod(selector.currentIndex);
147 root.passwordMethod = method;
149 if (method === UbuntuSecurityPrivacyPanel.Passphrase) { // any password
150 if (selector.currentIndex == 0/*1*/)
151 pageStack.load(Qt.resolvedUrl("password-set.qml")); // let the user choose a new password
153 pageStack.next(); // got the password already, go next page
154 } else if (method === UbuntuSecurityPrivacyPanel.Passcode) { // passcode
156 pageStack.load(Qt.resolvedUrl("passcode-desktop.qml"));
158 pageStack.load(Qt.resolvedUrl("passcode-set.qml"));