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
22 import "../../Components"
25 * One quirk with this page: we don't actually set the password. We avoid
26 * doing it here because the user can come back to this page and change their
27 * answer. We don't run as root, so if we did set the password immediately,
28 * we'd need to prompt for their previous password when they came back and
29 * changed their answer. Which is silly UX. So instead, we just keep track
30 * of their choice and set the password at the end (see Pages.qml).
31 * Setting the password shouldn't fail, since Ubuntu Touch has loose password
32 * requirements, but we'll check what we can here. Ideally we'd be able to ask
33 * the system if a password is legal without actually setting that password.
36 LocalComponents.Page {
38 objectName: "passwdPage"
40 title: i18n.tr("Lock Screen")
41 forwardButtonSourceComponent: forwardButton
43 // If the user has set a password some other way (via ubuntu-device-flash
44 // or this isn't the first time the wizard has been run, etc). We can't
45 // properly set the password again, so let's not pretend we can.
46 skip: securityPrivacy.securityType !== UbuntuSecurityPrivacyPanel.Swipe
48 function indexToMethod(index) {
49 if (index === 0/* || index === 1*/)
50 return UbuntuSecurityPrivacyPanel.Passphrase;
51 else if (index === 1/*2*/)
52 return UbuntuSecurityPrivacyPanel.Passcode;
54 return UbuntuSecurityPrivacyPanel.Swipe;
57 // Component.onCompleted: {
58 // if (root.password !== "") // the user has set a password as part of the previous page
59 // selector.currentIndex = 0;
61 // selector.currentIndex = 1;
67 anchors.topMargin: customMargin
68 anchors.leftMargin: wideMode ? parent.leftMargin : 0
69 anchors.rightMargin: wideMode ? parent.rightMargin : 0
73 anchors.left: parent.left
74 anchors.right: parent.right
75 boundsBehavior: Flickable.StopAtBounds
77 height: childrenRect.height
79 // this is the order we want to display it; cf indexToMethod()
80 model: [/*UbuntuSecurityPrivacyPanel.Passphrase, */UbuntuSecurityPrivacyPanel.Passphrase,
81 UbuntuSecurityPrivacyPanel.Passcode, UbuntuSecurityPrivacyPanel.Swipe]
85 objectName: "passwdDelegate" + index
86 readonly property bool isCurrent: index === ListView.view.currentIndex
87 highlightColor: backgroundColor
88 divider.colorFrom: dividerColor
89 divider.colorTo: backgroundColor
91 anchors.verticalCenter: parent.verticalCenter;
92 anchors.left: parent.left
93 anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
96 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
100 // return i18n.ctr("Label: Type of security method", "Ubuntu administrator password");
102 return i18n.ctr("Label: Type of security method", "Create new password");
104 return i18n.ctr("Label: Type of security method", "Create passcode (numbers only)");
106 return i18n.ctr("Label: Type of security method", "No lock code");
110 wrapMode: Text.WordWrap
116 verticalCenter: parent.verticalCenter
117 rightMargin: column.anchors.rightMargin == 0 ? staticMargin : 0
119 fillMode: Image.PreserveAspectFit
120 height: units.gu(1.5)
122 source: "data/Tick@30.png"
123 visible: itemDelegate.isCurrent
127 selector.currentIndex = index;
134 anchors.left: parent.left
135 anchors.right: parent.right
136 anchors.top: selector.bottom
144 LocalComponents.StackButton {
145 text: i18n.tr("Next")
147 var method = indexToMethod(selector.currentIndex);
148 root.passwordMethod = method;
150 if (method === UbuntuSecurityPrivacyPanel.Passphrase) { // any password
151 if (selector.currentIndex == 0/*1*/)
152 pageStack.load(Qt.resolvedUrl("password-set.qml")); // let the user choose a new password
154 pageStack.next(); // got the password already, go next page
155 } else if (method === UbuntuSecurityPrivacyPanel.Passcode) { // passcode
157 pageStack.load(Qt.resolvedUrl("passcode-desktop.qml"));
159 pageStack.load(Qt.resolvedUrl("passcode-set.qml"));