on fa2f331 help sign in
unity8/qml/Wizard/Pages.qml
151 lines 4.5 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.4
18import Ubuntu.Components 1.3
19import Ubuntu.SystemSettings.SecurityPrivacy 1.0
20import Wizard 0.1
21import "../Components"
23Item {
24 id: root
25 objectName: "wizardPages"
26 focus: true
28 // The background wallpaper to use
29 property string background
31 signal quit()
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: ""
38 UbuntuSecurityPrivacyPanel {
39 id: securityPrivacy
40 objectName: "securityPrivacy"
41 }
43 function quitWizard() {
44 pageStack.currentPage.enabled = false;
46 var errorMsg = securityPrivacy.setSecurity("", password, passwordMethod)
47 if (errorMsg !== "") {
48 // Ignore (but log) any errors, since we're past where the user set
49 // the method. Worst case, we just leave the user with a swipe
50 // security method and they fix it in the system settings.
51 console.log("Error setting security method:", errorMsg)
52 }
54 quit();
55 }
57 MouseArea { // eat anything that gets past widgets
58 anchors.fill: parent
59 }
61 Image {
62 id: image
63 // Use x/y/height/width instead of anchors so that we don't adjust
64 // the image when the OSK appears.
65 x: 0
66 y: 0
67 height: root.height
68 width: root.width
69 sourceSize.height: height
70 sourceSize.width: width
71 source: root.background
72 fillMode: Image.PreserveAspectCrop
73 visible: status === Image.Ready
74 }
76 PageList {
77 id: pageList
78 }
80 PageStack {
81 id: pageStack
82 objectName: "pageStack"
83 anchors.fill: parent
85 function next() {
86 // If we've opened any extra (non-main) pages, pop them before
87 // continuing so back button returns to the previous main page.
88 while (pageList.index < pageStack.depth - 1)
89 pop()
90 load(pageList.next())
91 }
93 function prev() {
94 if (pageList.index >= pageStack.depth - 1)
95 pageList.prev() // update pageList.index, but not for extra pages
96 pop()
97 if (!currentPage || currentPage.opacity === 0) { // undo skipped pages
98 prev()
99 } else {
100 currentPage.enabled = true
101 }
102 }
104 function load(path) {
105 if (currentPage) {
106 currentPage.enabled = false
107 }
109 // First load it invisible, check that we should actually use
110 // this page, and either skip it or continue.
111 push(path, {"opacity": 0, "enabled": false})
113 timeout.restart();
115 // Check for immediate skip or not. We may have to wait for
116 // skipValid to be assigned (see Connections object below)
117 checkSkip()
118 }
120 function checkSkip() {
121 if (!currentPage) { // may have had a parse error
122 next()
123 } else if (currentPage.skipValid) {
124 if (currentPage.skip) {
125 next()
126 } else {
127 currentPage.opacity = 1
128 currentPage.enabled = true
129 timeout.stop();
130 }
131 }
132 }
134 Timer {
135 id: timeout
136 objectName: "timeout"
137 interval: 2000 // wizard pages shouldn't take long
138 onTriggered: {
139 pageStack.currentPage.skip = true;
140 pageStack.currentPage.skipValid = true;
141 }
142 }
144 Connections {
145 target: pageStack.currentPage
146 onSkipValidChanged: pageStack.checkSkip()
147 }
149 Component.onCompleted: next()
150 }