~unity-team/unity8/dash-only

« back to all changes in this revision

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

  • Committer: Kevin Gunn
  • Date: 2016-10-24 19:51:33 UTC
  • Revision ID: kevin.gunn@canonical.com-20161024195133-61lwdzzdwsnue1mn
shave some more

Show diffs side-by-side

added added

removed removed

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