on 19a9ecd help sign in
unity8/qml/Wizard/Pages.qml
195 lines 6.2 kB history raw
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 */
17import QtQuick 2.4
18import MeeGo.QOfono 0.2
19import Ubuntu.Components 1.3
20import Ubuntu.SystemSettings.SecurityPrivacy 1.0
21import Ubuntu.SystemSettings.Diagnostics 1.0
22import Wizard 0.1
23import "../Components"
25StyledItem {
26 id: root
27 objectName: "wizardPages"
28 focus: true
30 signal quit()
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: ""
37 property bool seenSIMPage: false // we want to see the SIM page at most once
39 property alias modemManager: modemManager
40 property alias simManager0: simManager0
41 property alias simManager1: simManager1
43 theme: ThemeSettings {
44 name: "Ubuntu.Components.Themes.Ambiance"
45 }
47 UbuntuSecurityPrivacyPanel {
48 id: securityPrivacy
49 objectName: "securityPrivacy"
50 }
52 UbuntuDiagnostics {
53 id: diagnostics
54 objectName: "diagnostics"
55 }
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 }
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 }
73 OfonoSimManager {
74 id: simManager1
75 modemPath: modemManager.modems.length >= 2 ? modemManager.modems[1] : ""
76 }
78 function quitWizard() {
79 pageStack.currentPage.enabled = false;
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 }
91 quit();
92 }
94 MouseArea { // eat anything that gets past widgets
95 anchors.fill: parent
96 }
98 Rectangle {
99 id: background
100 anchors.fill: root
101 color: "#fdfdfd"
102 }
104 PageList {
105 id: pageList
106 }
108 PageStack {
109 id: pageStack
110 objectName: "pageStack"
111 anchors.fill: parent
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 }
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 }
133 if (isPrimaryPage) {
134 currentPage.aboutToShow(UbuntuAnimation.BriskDuration, Qt.LeftToRight);
135 } else {
136 currentPage.aboutToShowSecondary(UbuntuAnimation.BriskDuration);
137 }
138 }
140 function load(path) {
141 if (currentPage) {
142 currentPage.enabled = false
143 }
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})
149 timeout.restart();
151 // Check for immediate skip or not. We may have to wait for
152 // skipValid to be assigned (see Connections object below)
153 checkSkip()
155 var isPrimaryPage = !currentPage.customTitle;
156 if (isPrimaryPage) {
157 currentPage.aboutToShow(UbuntuAnimation.BriskDuration, Qt.RightToLeft);
158 } else {
159 currentPage.aboutToShowSecondary(UbuntuAnimation.BriskDuration);
160 }
161 }
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 }
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 }
188 Connections {
189 target: pageStack.currentPage
190 onSkipValidChanged: pageStack.checkSkip()
191 }
193 Component.onCompleted: next()
194 }