~mzanetti/unity8/fix-left-edge-on-spread

« back to all changes in this revision

Viewing changes to qml/Wizard/Pages.qml

  • Committer: Michael Zanetti
  • Date: 2015-01-12 11:21:17 UTC
  • mfrom: (1459.1.85 unity8)
  • Revision ID: michael.zanetti@canonical.com-20150112112117-0x9srs9dx0ndp60g
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 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.SystemSettings.SecurityPrivacy 1.0
 
20
import Wizard 0.1
 
21
import "../Components"
 
22
 
 
23
Item {
 
24
    id: root
 
25
    objectName: "wizardPages"
 
26
    focus: true
 
27
 
 
28
    // The background wallpaper to use
 
29
    property string background
 
30
 
 
31
    signal quit()
 
32
 
 
33
    // These should be set by a security page and we apply the settings when
 
34
    // the user exits the wizard.
 
35
    property int passwordMethod: UbuntuSecurityPrivacyPanel.Passcode
 
36
    property string password: ""
 
37
 
 
38
    UbuntuSecurityPrivacyPanel {
 
39
        id: securityPrivacy
 
40
        objectName: "securityPrivacy"
 
41
    }
 
42
 
 
43
    function quitWizard() {
 
44
        var errorMsg = securityPrivacy.setSecurity("", password, passwordMethod)
 
45
        if (errorMsg !== "") {
 
46
            // Ignore (but log) any errors, since we're past where the user set
 
47
            // the method.  Worst case, we just leave the user with a swipe
 
48
            // security method and they fix it in the system settings.
 
49
            console.log("Error setting security method:", errorMsg)
 
50
        }
 
51
 
 
52
        quit();
 
53
    }
 
54
 
 
55
    MouseArea { // eat anything that gets past widgets
 
56
        anchors.fill: parent
 
57
    }
 
58
 
 
59
    Image {
 
60
        id: image
 
61
        // Use x/y/height/width instead of anchors so that we don't adjust
 
62
        // the image when the OSK appears.
 
63
        x: 0
 
64
        y: 0
 
65
        height: root.height
 
66
        width: root.width
 
67
        sourceSize.height: height
 
68
        sourceSize.width: width
 
69
        source: root.background
 
70
        fillMode: Image.PreserveAspectCrop
 
71
        visible: status === Image.Ready
 
72
    }
 
73
 
 
74
    PageList {
 
75
        id: pageList
 
76
    }
 
77
 
 
78
    PageStack {
 
79
        id: pageStack
 
80
        objectName: "pageStack"
 
81
        anchors.fill: parent
 
82
 
 
83
        function next() {
 
84
            // If we've opened any extra (non-main) pages, pop them before
 
85
            // continuing so back button returns to the previous main page.
 
86
            while (pageList.index < pageStack.depth - 1)
 
87
                pop()
 
88
            load(pageList.next())
 
89
        }
 
90
 
 
91
        function prev() {
 
92
            if (pageList.index >= pageStack.depth - 1)
 
93
                pageList.prev() // update pageList.index, but not for extra pages
 
94
            pop()
 
95
            if (!currentPage || currentPage.opacity === 0) { // undo skipped pages
 
96
                prev()
 
97
            } else {
 
98
                currentPage.enabled = true
 
99
            }
 
100
        }
 
101
 
 
102
        function load(path) {
 
103
            if (currentPage) {
 
104
                currentPage.enabled = false
 
105
            }
 
106
 
 
107
            // First load it invisible, check that we should actually use
 
108
            // this page, and either skip it or continue.
 
109
            push(path, {"opacity": 0, "enabled": false})
 
110
 
 
111
            // Check for immediate skip or not.  We may have to wait for
 
112
            // skipValid to be assigned (see Connections object below)
 
113
            checkSkip()
 
114
        }
 
115
 
 
116
        function checkSkip() {
 
117
            if (!currentPage) { // may have had a parse error
 
118
                next()
 
119
            } else if (currentPage.skipValid) {
 
120
                if (currentPage.skip) {
 
121
                    next()
 
122
                } else {
 
123
                    currentPage.opacity = 1
 
124
                    currentPage.enabled = true
 
125
                }
 
126
            }
 
127
        }
 
128
 
 
129
        Connections {
 
130
            target: pageStack.currentPage
 
131
            onSkipValidChanged: pageStack.checkSkip()
 
132
        }
 
133
 
 
134
        Component.onCompleted: next()
 
135
    }
 
136
}