~unity-team/unity8/dash-only

« back to all changes in this revision

Viewing changes to qml/Wizard/Pages.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) 2013-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 MeeGo.QOfono 0.2
19
 
import Ubuntu.Components 1.3
20
 
import Ubuntu.SystemSettings.SecurityPrivacy 1.0
21
 
import Ubuntu.SystemSettings.Diagnostics 1.0
22
 
import Wizard 0.1
23
 
import "../Components"
24
 
 
25
 
StyledItem {
26
 
    id: root
27
 
    objectName: "wizardPages"
28
 
    focus: true
29
 
 
30
 
    signal quit()
31
 
 
32
 
    // These should be set by a security page and we apply the settings when
33
 
    // the user exits the wizard.
34
 
    property int passwordMethod: UbuntuSecurityPrivacyPanel.Passphrase
35
 
    property string password: ""
36
 
 
37
 
    property bool seenSIMPage: false // we want to see the SIM page at most once
38
 
 
39
 
    property alias modemManager: modemManager
40
 
    property alias simManager0: simManager0
41
 
    property alias simManager1: simManager1
42
 
 
43
 
    theme: ThemeSettings {
44
 
        name: "Ubuntu.Components.Themes.Ambiance"
45
 
    }
46
 
 
47
 
    UbuntuSecurityPrivacyPanel {
48
 
        id: securityPrivacy
49
 
        objectName: "securityPrivacy"
50
 
    }
51
 
 
52
 
    UbuntuDiagnostics {
53
 
        id: diagnostics
54
 
        objectName: "diagnostics"
55
 
    }
56
 
 
57
 
    OfonoManager { // need it here for the language and country detection
58
 
        id: modemManager
59
 
        readonly property bool gotSimCard: available && ((simManager0.ready && simManager0.present) || (simManager1.ready && simManager1.present))
60
 
        property bool ready: false
61
 
        onModemsChanged: {
62
 
            ready = true;
63
 
        }
64
 
    }
65
 
 
66
 
    // Ideally we would query the system more cleverly than hardcoding two
67
 
    // sims.  But we don't yet have a more clever way.  :(
68
 
    OfonoSimManager {
69
 
        id: simManager0
70
 
        modemPath: modemManager.modems.length >= 1 ? modemManager.modems[0] : ""
71
 
    }
72
 
 
73
 
    OfonoSimManager {
74
 
        id: simManager1
75
 
        modemPath: modemManager.modems.length >= 2 ? modemManager.modems[1] : ""
76
 
    }
77
 
 
78
 
    function quitWizard() {
79
 
        pageStack.currentPage.enabled = false;
80
 
 
81
 
        if (password != "") {
82
 
            var errorMsg = securityPrivacy.setSecurity("", password, passwordMethod)
83
 
            if (errorMsg !== "") {
84
 
                // Ignore (but log) any errors, since we're past where the user set
85
 
                // the method.  Worst case, we just leave the user with a swipe
86
 
                // security method and they fix it in the system settings.
87
 
                console.log("Error setting security method:", errorMsg)
88
 
            }
89
 
        }
90
 
 
91
 
        quit();
92
 
    }
93
 
 
94
 
    MouseArea { // eat anything that gets past widgets
95
 
        anchors.fill: parent
96
 
    }
97
 
 
98
 
    Rectangle {
99
 
        id: background
100
 
        anchors.fill: root
101
 
        color: "#fdfdfd"
102
 
    }
103
 
 
104
 
    PageList {
105
 
        id: pageList
106
 
    }
107
 
 
108
 
    PageStack {
109
 
        id: pageStack
110
 
        objectName: "pageStack"
111
 
        anchors.fill: parent
112
 
 
113
 
        function next() {
114
 
            // If we've opened any extra (non-main) pages, pop them before
115
 
            // continuing so back button returns to the previous main page.
116
 
            while (pageList.index < pageStack.depth - 1)
117
 
                pop();
118
 
            load(pageList.next());
119
 
        }
120
 
 
121
 
        function prev() {
122
 
            var isPrimaryPage = currentPage && !currentPage.customTitle;
123
 
            if (pageList.index >= pageStack.depth - 1) {
124
 
                pageList.prev(); // update pageList.index, but not for extra pages
125
 
            }
126
 
            pop()
127
 
            if (!currentPage || currentPage.opacity === 0) { // undo skipped pages
128
 
                prev();
129
 
            } else {
130
 
                currentPage.enabled = true;
131
 
            }
132
 
 
133
 
            if (isPrimaryPage) {
134
 
                currentPage.aboutToShow(UbuntuAnimation.BriskDuration, Qt.LeftToRight);
135
 
            } else {
136
 
                currentPage.aboutToShowSecondary(UbuntuAnimation.BriskDuration);
137
 
            }
138
 
        }
139
 
 
140
 
        function load(path) {
141
 
            if (currentPage) {
142
 
                currentPage.enabled = false
143
 
            }
144
 
 
145
 
            // First load it invisible, check that we should actually use
146
 
            // this page, and either skip it or continue.
147
 
            push(path, {"opacity": 0, "enabled": false})
148
 
 
149
 
            timeout.restart();
150
 
 
151
 
            // Check for immediate skip or not.  We may have to wait for
152
 
            // skipValid to be assigned (see Connections object below)
153
 
            checkSkip()
154
 
 
155
 
            var isPrimaryPage = !currentPage.customTitle;
156
 
            if (isPrimaryPage) {
157
 
                currentPage.aboutToShow(UbuntuAnimation.BriskDuration, Qt.RightToLeft);
158
 
            } else {
159
 
                currentPage.aboutToShowSecondary(UbuntuAnimation.BriskDuration);
160
 
            }
161
 
        }
162
 
 
163
 
        function checkSkip() {
164
 
            if (!currentPage) { // may have had a parse error
165
 
                next()
166
 
            } else if (currentPage.skipValid) {
167
 
                if (currentPage.skip) {
168
 
                    next()
169
 
                } else {
170
 
                    currentPage.opacity = 1
171
 
                    currentPage.enabled = true
172
 
                    timeout.stop();
173
 
                }
174
 
            }
175
 
        }
176
 
 
177
 
        Timer {
178
 
            id: timeout
179
 
            objectName: "timeout"
180
 
            interval: 2000 // wizard pages shouldn't take long
181
 
            onTriggered: {
182
 
                console.warn("Wizard page " + pageStack.currentPage.objectName + " skipped due to taking too long!!!");
183
 
                pageStack.currentPage.skip = true;
184
 
                pageStack.currentPage.skipValid = true;
185
 
            }
186
 
        }
187
 
 
188
 
        Connections {
189
 
            target: pageStack.currentPage
190
 
            onSkipValidChanged: pageStack.checkSkip()
191
 
        }
192
 
 
193
 
        Component.onCompleted: next()
194
 
    }
195
 
}