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