Unity 8
30-passwd-type.qml
1 /*
2  * Copyright (C) 2014,2015 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 Ubuntu.Components 1.3
19 import Ubuntu.Components.ListItems 1.3
20 import Ubuntu.SystemSettings.SecurityPrivacy 1.0
21 import ".." as LocalComponents
22 
23 /**
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.
33  */
34 
35 LocalComponents.Page {
36  id: passwdPage
37  objectName: "passwdPage"
38 
39  title: i18n.tr("Lock security")
40  forwardButtonSourceComponent: forwardButton
41 
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
46 
47  function indexToMethod(index) {
48  if (index === 0)
49  return UbuntuSecurityPrivacyPanel.Swipe
50  else if (index === 1)
51  return UbuntuSecurityPrivacyPanel.Passcode
52  else
53  return UbuntuSecurityPrivacyPanel.Passphrase
54  }
55 
56  function methodToIndex(method) {
57  if (method === UbuntuSecurityPrivacyPanel.Swipe)
58  return 0
59  else if (method === UbuntuSecurityPrivacyPanel.Passcode)
60  return 1
61  else
62  return 2
63  }
64 
65  Connections {
66  target: root
67  onPasswordMethodChanged: selector.selectedIndex = methodToIndex(root.passwordMethod)
68  }
69 
70  Column {
71  id: column
72  anchors.fill: content
73  spacing: units.gu(4)
74 
75  Label {
76  anchors.left: parent.left
77  anchors.right: parent.right
78  wrapMode: Text.Wrap
79  text: i18n.tr("Please select how you’d like to unlock your phone.")
80  }
81 
82  ItemSelector {
83  id: selector
84  expanded: true
85  anchors.left: parent.left
86  anchors.right: parent.right
87  property color originalBackground
88 
89  model: ["", "", ""] // otherwise the delegate will show the text itself and we only want subText
90 
91  selectedIndex: methodToIndex(root.passwordMethod)
92 
93  delegate: OptionSelectorDelegate {
94  objectName: "passwdDelegate" + index
95 
96  // use subText because we want the text to be small, and we have no other way to control it
97  subText: {
98  var method = indexToMethod(index)
99  var name = ""
100  var desc = ""
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")
107  } else {
108  name = i18n.ctr("Label: Type of security method", "Passphrase")
109  desc = i18n.ctr("Label: Description of security method", "Numbers and letters")
110  }
111  return "<b>%1</b> (%2)".arg(name).arg(desc)
112  }
113  }
114 
115  style: Item {}
116 
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"
121  }
122 
123  Component.onDestruction: {
124  // Restore original theme background
125  theme.palette.selected.background = originalBackground
126  }
127  }
128  }
129 
130  Component {
131  id: forwardButton
132  LocalComponents.StackButton {
133  text: i18n.tr("Continue")
134  onClicked: {
135  root.passwordMethod = indexToMethod(selector.selectedIndex)
136  pageStack.load(Qt.resolvedUrl("passwd-set.qml"))
137  }
138  }
139  }
140 }