Unity 8
Pages.qml
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  */
16 
17 import QtQuick 2.4
18 import Ubuntu.Components 1.3
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  pageStack.currentPage.enabled = false;
45 
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  }
53 
54  quit();
55  }
56 
57  MouseArea { // eat anything that gets past widgets
58  anchors.fill: parent
59  }
60 
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  }
75 
76  PageList {
77  id: pageList
78  }
79 
80  PageStack {
81  id: pageStack
82  objectName: "pageStack"
83  anchors.fill: parent
84 
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  }
92 
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  }
103 
104  function load(path) {
105  if (currentPage) {
106  currentPage.enabled = false
107  }
108 
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})
112 
113  timeout.restart();
114 
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  }
119 
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  }
133 
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  }
143 
144  Connections {
145  target: pageStack.currentPage
146  onSkipValidChanged: pageStack.checkSkip()
147  }
148 
149  Component.onCompleted: next()
150  }
151 }