on cd4bc68 help sign in
unity8/qml/Wizard/Pages.qml
142 lines 4.3 kB history raw
1/*
2 * Copyright (C) 2013,2014,2015 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.3
18import Ubuntu.Components 1.2
19import Ubuntu.SystemSettings.SecurityPrivacy 1.0
20import Wizard 0.1
21import "../Components"
23Item {
24 id: root
25 objectName: "wizardPages"
26 focus: true
28 signal quit()
30 // These should be set by a security page and we apply the settings when
31 // the user exits the wizard.
32 property int passwordMethod: UbuntuSecurityPrivacyPanel.Passphrase
33 property string password: ""
34 property string countryCode: "US" // default country (for the timezone page)
35 property bool seenSIMPage: false // we want to see the SIM page at most once
37 UbuntuSecurityPrivacyPanel {
38 id: securityPrivacy
39 objectName: "securityPrivacy"
40 }
42 function quitWizard() {
43 pageStack.currentPage.enabled = false;
45 var errorMsg = securityPrivacy.setSecurity("", password, passwordMethod)
46 if (errorMsg !== "") {
47 // Ignore (but log) any errors, since we're past where the user set
48 // the method. Worst case, we just leave the user with a swipe
49 // security method and they fix it in the system settings.
50 console.log("Error setting security method:", errorMsg)
51 }
53 quit();
54 }
56 MouseArea { // eat anything that gets past widgets
57 anchors.fill: parent
58 }
60 Rectangle {
61 id: background
62 anchors.fill: root
63 color: "#fdfdfd"
64 }
66 PageList {
67 id: pageList
68 }
70 PageStack {
71 id: pageStack
72 objectName: "pageStack"
73 anchors.fill: parent
75 function next() {
76 // If we've opened any extra (non-main) pages, pop them before
77 // continuing so back button returns to the previous main page.
78 while (pageList.index < pageStack.depth - 1)
79 pop()
80 load(pageList.next())
81 }
83 function prev() {
84 if (pageList.index >= pageStack.depth - 1)
85 pageList.prev() // update pageList.index, but not for extra pages
86 pop()
87 if (!currentPage || currentPage.opacity === 0) { // undo skipped pages
88 prev()
89 } else {
90 currentPage.enabled = true
91 }
92 }
94 function load(path) {
95 if (currentPage) {
96 currentPage.enabled = false
97 }
99 // First load it invisible, check that we should actually use
100 // this page, and either skip it or continue.
101 push(path, {"opacity": 0, "enabled": false})
103 timeout.restart();
105 // Check for immediate skip or not. We may have to wait for
106 // skipValid to be assigned (see Connections object below)
107 checkSkip()
108 }
110 function checkSkip() {
111 if (!currentPage) { // may have had a parse error
112 next()
113 } else if (currentPage.skipValid) {
114 if (currentPage.skip) {
115 next()
116 } else {
117 currentPage.opacity = 1
118 currentPage.enabled = true
119 timeout.stop();
120 }
121 }
122 }
124 Timer {
125 id: timeout
126 objectName: "timeout"
127 interval: 2000 // wizard pages shouldn't take long
128 onTriggered: {
129 print("PAGE SKIPPED BY TIMEOUT!!!");
130 pageStack.currentPage.skip = true;
131 pageStack.currentPage.skipValid = true;
132 }
133 }
135 Connections {
136 target: pageStack.currentPage
137 onSkipValidChanged: pageStack.checkSkip()
138 }
140 Component.onCompleted: next()
141 }