Unity 8
70-passwd-type.qml
1 /*
2  * Copyright (C) 2014-2016 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 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.
33  */
34 
35 LocalComponents.Page {
36  id: passwdPage
37  objectName: "passwdPage"
38 
39  title: i18n.tr("Lock Screen")
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/* || index === 1*/)
49  return UbuntuSecurityPrivacyPanel.Passphrase;
50  else if (index === 1/*2*/)
51  return UbuntuSecurityPrivacyPanel.Passcode;
52  else
53  return UbuntuSecurityPrivacyPanel.Swipe;
54  }
55 
56 // Component.onCompleted: {
57 // if (root.password !== "") // the user has set a password as part of the previous page
58 // selector.currentIndex = 0;
59 // else
60 // selector.currentIndex = 1;
61 // }
62 
63  Item {
64  id: column
65  anchors.fill: content
66  anchors.topMargin: customMargin
67  anchors.leftMargin: wideMode ? parent.leftMargin : 0
68  anchors.rightMargin: wideMode ? parent.rightMargin : 0
69 
70  ListView {
71  id: selector
72  anchors.left: parent.left
73  anchors.right: parent.right
74  boundsBehavior: Flickable.StopAtBounds
75  clip: true
76  height: childrenRect.height
77 
78  // this is the order we want to display it; cf indexToMethod()
79  model: [/*UbuntuSecurityPrivacyPanel.Passphrase, */UbuntuSecurityPrivacyPanel.Passphrase,
80  UbuntuSecurityPrivacyPanel.Passcode, UbuntuSecurityPrivacyPanel.Swipe]
81 
82  delegate: ListItem {
83  id: itemDelegate
84  objectName: "passwdDelegate" + index
85  readonly property bool isCurrent: index === ListView.view.currentIndex
86  highlightColor: backgroundColor
87  divider.colorFrom: dividerColor
88  divider.colorTo: backgroundColor
89  Label {
90  anchors.verticalCenter: parent.verticalCenter;
91  anchors.left: parent.left
92  anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
93  fontSize: "medium"
94  color: textColor
95  font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
96  text: {
97  switch (index) {
98 // case 0:
99 // return i18n.ctr("Label: Type of security method", "Ubuntu administrator password");
100  case 0:
101  return i18n.ctr("Label: Type of security method", "Create new password");
102  case 1:
103  return i18n.ctr("Label: Type of security method", "Create passcode (numbers only)");
104  case 2:
105  return i18n.ctr("Label: Type of security method", "No lock code");
106  }
107  }
108  width: parent.width
109  wrapMode: Text.WordWrap
110  }
111 
112  Image {
113  anchors {
114  right: parent.right
115  verticalCenter: parent.verticalCenter
116  rightMargin: column.anchors.rightMargin == 0 ? staticMargin : 0
117  }
118  fillMode: Image.PreserveAspectFit
119  height: units.gu(1.5)
120 
121  source: "data/Tick@30.png"
122  visible: itemDelegate.isCurrent
123  }
124 
125  onClicked: {
126  selector.currentIndex = index;
127  }
128  }
129  }
130 
131  Rectangle {
132  id: divider2
133  anchors.left: parent.left
134  anchors.right: parent.right
135  anchors.top: selector.bottom
136  height: units.dp(1)
137  color: dividerColor
138  }
139  }
140 
141  Component {
142  id: forwardButton
143  LocalComponents.StackButton {
144  text: i18n.tr("Next")
145  onClicked: {
146  var method = indexToMethod(selector.currentIndex);
147  root.passwordMethod = method;
148 
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
152  else
153  pageStack.next(); // got the password already, go next page
154  } else if (method === UbuntuSecurityPrivacyPanel.Passcode) { // passcode
155  if (wideMode) {
156  pageStack.load(Qt.resolvedUrl("passcode-desktop.qml"));
157  } else {
158  pageStack.load(Qt.resolvedUrl("passcode-set.qml"));
159  }
160  } else { //swipe
161  pageStack.next();
162  }
163  }
164  }
165  }
166 }