2
* Copyright (C) 2014 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.1
19
import Ubuntu.Components.ListItems 1.0
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
function indexToMethod(index) {
44
return UbuntuSecurityPrivacyPanel.Swipe
46
return UbuntuSecurityPrivacyPanel.Passcode
48
return UbuntuSecurityPrivacyPanel.Passphrase
51
function methodToIndex(method) {
52
if (method === UbuntuSecurityPrivacyPanel.Swipe)
54
else if (method === UbuntuSecurityPrivacyPanel.Passcode)
62
onPasswordMethodChanged: selector.selectedIndex = methodToIndex(root.passwordMethod)
71
anchors.left: parent.left
72
anchors.right: parent.right
74
text: i18n.tr("Please select how you’d like to unlock your phone.")
80
anchors.left: parent.left
81
anchors.right: parent.right
82
property color originalBackground
84
model: ["", "", ""] // otherwise the delegate will show the text itself and we only want subText
86
selectedIndex: methodToIndex(root.passwordMethod)
88
delegate: OptionSelectorDelegate {
89
objectName: "passwdDelegate" + index
91
// use subText because we want the text to be small, and we have no other way to control it
93
var method = indexToMethod(index)
96
if (method === UbuntuSecurityPrivacyPanel.Swipe) {
97
name = i18n.tr("Swipe")
98
desc = i18n.tr("No security")
99
} else if (method === UbuntuSecurityPrivacyPanel.Passcode) {
100
name = i18n.tr("Passcode")
101
desc = i18n.tr("4 digits only")
103
name = i18n.tr("Passphrase")
104
desc = i18n.tr("Numbers and letters")
106
return "<b>%1</b> (%2)".arg(name).arg(desc)
112
Component.onCompleted: {
113
// A visible selected background looks bad in ListItem widgets with our theme
114
originalBackground = Theme.palette.selected.background
115
Theme.palette.selected.background = "transparent"
118
Component.onDestruction: {
119
// Restore original theme background
120
Theme.palette.selected.background = originalBackground
127
LocalComponents.StackButton {
128
text: i18n.tr("Continue")
130
root.passwordMethod = indexToMethod(selector.selectedIndex)
131
pageStack.load(Qt.resolvedUrl("passwd-set.qml"))