~gerboland/unity8/initialSurfaceGeometry

« back to all changes in this revision

Viewing changes to qml/Wizard/Pages/30-passwd-type.qml

  • Committer: Gerry Boland
  • Date: 2014-12-09 12:55:58 UTC
  • mfrom: (1139.1.343 unity8)
  • Revision ID: gerry.boland@canonical.com-20141209125558-d68labgupwxfz91r
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.1
 
19
import Ubuntu.Components.ListItems 1.0
 
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
    function indexToMethod(index) {
 
43
        if (index === 0)
 
44
            return UbuntuSecurityPrivacyPanel.Swipe
 
45
        else if (index === 1)
 
46
            return UbuntuSecurityPrivacyPanel.Passcode
 
47
        else
 
48
            return UbuntuSecurityPrivacyPanel.Passphrase
 
49
    }
 
50
 
 
51
    function methodToIndex(method) {
 
52
        if (method === UbuntuSecurityPrivacyPanel.Swipe)
 
53
            return 0
 
54
        else if (method === UbuntuSecurityPrivacyPanel.Passcode)
 
55
            return 1
 
56
        else
 
57
            return 2
 
58
    }
 
59
 
 
60
    Connections {
 
61
        target: root
 
62
        onPasswordMethodChanged: selector.selectedIndex = methodToIndex(root.passwordMethod)
 
63
    }
 
64
 
 
65
    Column {
 
66
        id: column
 
67
        anchors.fill: content
 
68
        spacing: units.gu(4)
 
69
 
 
70
        Label {
 
71
            anchors.left: parent.left
 
72
            anchors.right: parent.right
 
73
            wrapMode: Text.Wrap
 
74
            text: i18n.tr("Please select how you’d like to unlock your phone.")
 
75
        }
 
76
 
 
77
        ItemSelector {
 
78
            id: selector
 
79
            expanded: true
 
80
            anchors.left: parent.left
 
81
            anchors.right: parent.right
 
82
            property color originalBackground
 
83
 
 
84
            model: ["", "", ""] // otherwise the delegate will show the text itself and we only want subText
 
85
 
 
86
            selectedIndex: methodToIndex(root.passwordMethod)
 
87
 
 
88
            delegate: OptionSelectorDelegate {
 
89
                objectName: "passwdDelegate" + index
 
90
 
 
91
                // use subText because we want the text to be small, and we have no other way to control it
 
92
                subText: {
 
93
                    var method = indexToMethod(index)
 
94
                    var name = ""
 
95
                    var desc = ""
 
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")
 
102
                    } else {
 
103
                        name = i18n.tr("Passphrase")
 
104
                        desc = i18n.tr("Numbers and letters")
 
105
                    }
 
106
                    return "<b>%1</b> (%2)".arg(name).arg(desc)
 
107
                }
 
108
            }
 
109
 
 
110
            style: Item {}
 
111
 
 
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"
 
116
            }
 
117
 
 
118
            Component.onDestruction: {
 
119
                // Restore original theme background
 
120
                Theme.palette.selected.background = originalBackground
 
121
            }
 
122
        }
 
123
    }
 
124
 
 
125
    Component {
 
126
        id: forwardButton
 
127
        LocalComponents.StackButton {
 
128
            text: i18n.tr("Continue")
 
129
            onClicked: {
 
130
                root.passwordMethod = indexToMethod(selector.selectedIndex)
 
131
                pageStack.load(Qt.resolvedUrl("passwd-set.qml"))
 
132
            }
 
133
        }
 
134
    }
 
135
}