2 * Copyright (C) 2014,2015 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 main.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 security")
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) {
49 return UbuntuSecurityPrivacyPanel.Swipe
51 return UbuntuSecurityPrivacyPanel.Passcode
53 return UbuntuSecurityPrivacyPanel.Passphrase
56 function methodToIndex(method) {
57 if (method === UbuntuSecurityPrivacyPanel.Swipe)
59 else if (method === UbuntuSecurityPrivacyPanel.Passcode)
67 onPasswordMethodChanged: selector.selectedIndex = methodToIndex(root.passwordMethod)
76 anchors.left: parent.left
77 anchors.right: parent.right
79 text: i18n.tr("Please select how you’d like to unlock your phone.")
85 anchors.left: parent.left
86 anchors.right: parent.right
87 property color originalBackground
89 model: ["", "", ""] // otherwise the delegate will show the text itself and we only want subText
91 selectedIndex: methodToIndex(root.passwordMethod)
93 delegate: OptionSelectorDelegate {
94 objectName: "passwdDelegate" + index
96 // use subText because we want the text to be small, and we have no other way to control it
98 var method = indexToMethod(index)
101 if (method === UbuntuSecurityPrivacyPanel.Swipe) {
102 name = i18n.ctr("Label: Type of security method", "Swipe")
103 desc = i18n.ctr("Label: Description of security method", "No security")
104 } else if (method === UbuntuSecurityPrivacyPanel.Passcode) {
105 name = i18n.ctr("Label: Type of security method", "Passcode")
106 desc = i18n.ctr("Label: Description of security method", "4 digits only")
108 name = i18n.ctr("Label: Type of security method", "Passphrase")
109 desc = i18n.ctr("Label: Description of security method", "Numbers and letters")
111 return "<b>%1</b> (%2)".arg(name).arg(desc)
117 Component.onCompleted: {
118 // A visible selected background looks bad in ListItem widgets with our theme
119 originalBackground = theme.palette.selected.background
120 theme.palette.selected.background = "transparent"
123 Component.onDestruction: {
124 // Restore original theme background
125 theme.palette.selected.background = originalBackground
132 LocalComponents.StackButton {
133 text: i18n.tr("Continue")
135 root.passwordMethod = indexToMethod(selector.selectedIndex)
136 pageStack.load(Qt.resolvedUrl("passwd-set.qml"))