@@ -0,0 +1,150 @@
1+/*
2+ * Copyright (C) 2014 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.3
18+import Ubuntu.Components 1.2
19+import Ubuntu.SystemSettings.SecurityPrivacy 1.0
20+import ".." as LocalComponents
21+
22+/**
23+ * One quirk with this page: we don't actually set the password. We avoid
24+ * doing it here because the user can come back to this page and change their
25+ * answer. We don't run as root, so if we did set the password immediately,
26+ * we'd need to prompt for their previous password when they came back and
27+ * changed their answer. Which is silly UX. So instead, we just keep track
28+ * of their choice and set the password at the end (see main.qml).
29+ * Setting the password shouldn't fail, since Ubuntu Touch has loose password
30+ * requirements, but we'll check what we can here. Ideally we'd be able to ask
31+ * the system if a password is legal without actually setting that password.
32+ */
33+
34+LocalComponents.Page {
35+ id: passwdPage
36+ objectName: "passwdPage"
37+
38+ title: i18n.tr("Lock security")
39+ forwardButtonSourceComponent: forwardButton
40+
41+ function indexToMethod(index) {
42+ if (index === 0)
43+ return UbuntuSecurityPrivacyPanel.Passcode
44+ else if (index === 1)
45+ return UbuntuSecurityPrivacyPanel.Passphrase
46+ else
47+ return UbuntuSecurityPrivacyPanel.Swipe
48+ }
49+
50+ function methodToIndex(method) {
51+ if (method === UbuntuSecurityPrivacyPanel.Swipe)
52+ return 2
53+ else if (method === UbuntuSecurityPrivacyPanel.Passcode)
54+ return 0
55+ else
56+ return 1
57+ }
58+
59+ Component.onCompleted: {
60+ selector.currentIndex = methodToIndex(root.passwordMethod)
61+ }
62+
63+ Column {
64+ id: column
65+ anchors.fill: content
66+ spacing: units.gu(4)
67+ anchors.topMargin: units.gu(4)
68+
69+ Label {
70+ anchors.left: parent.left
71+ anchors.right: parent.right
72+ wrapMode: Text.Wrap
73+ text: i18n.tr("Choose how to secure your device to protect your personal information.")
74+ color: "black"
75+ fontSize: "small"
76+ font.weight: Font.Light
77+ }
78+
79+ ListView {
80+ id: selector
81+ anchors.left: parent.left
82+ anchors.right: parent.right
83+
84+ boundsBehavior: Flickable.StopAtBounds;
85+ clip: true;
86+ height: column.height
87+
88+ // this is the order we want to display it; cf indexToMethod()
89+ model: [UbuntuSecurityPrivacyPanel.Passcode, UbuntuSecurityPrivacyPanel.Passphrase, UbuntuSecurityPrivacyPanel.Swipe]
90+
91+ delegate: ListItem {
92+ id: itemDelegate
93+ readonly property bool isCurrent: index === ListView.view.currentIndex
94+ Label {
95+ id: methodLabel
96+ objectName: "passwdDelegate" + index
97+ anchors.verticalCenter: parent.verticalCenter;
98+ fontSize: "medium"
99+ color: "black"
100+ font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
101+ text: {
102+ var method = modelData
103+ var name = ""
104+ var desc = ""
105+ if (method === UbuntuSecurityPrivacyPanel.Swipe) {
106+ return i18n.ctr("Label: Type of security method", "None")
107+ } else if (method === UbuntuSecurityPrivacyPanel.Passcode) {
108+ name = i18n.ctr("Label: Type of security method", "Passcode")
109+ desc = i18n.ctr("Label: Description of security method", "4 digits only")
110+ } else {
111+ name = i18n.ctr("Label: Type of security method", "Password")
112+ desc = i18n.ctr("Label: Description of security method", "numbers and letters")
113+ }
114+ return "%1 (%2)".arg(name).arg(desc)
115+ }
116+ }
117+
118+ Image {
119+ anchors {
120+ right: parent.right;
121+ verticalCenter: parent.verticalCenter;
122+ }
123+ fillMode: Image.PreserveAspectFit
124+ height: methodLabel.paintedHeight
125+
126+ source: "data/tick@30.png"
127+ visible: itemDelegate.isCurrent
128+ }
129+
130+ onClicked: {
131+ selector.currentIndex = index
132+ print("Current method: " + indexToMethod(index))
133+ }
134+ }
135+ }
136+ }
137+
138+ Component {
139+ id: forwardButton
140+ LocalComponents.StackButton {
141+ text: i18n.tr("Next")
142+ onClicked: {
143+ print("Clicked next")
144+ root.passwordMethod = indexToMethod(selector.currentIndex)
145+ print("Current method: " + root.passwordMethod)
146+ pageStack.load(Qt.resolvedUrl("passwd-set.qml"))
147+ }
148+ }
149+ }
150+}