Lomiri
Loading...
Searching...
No Matches
Pages.qml
1/*
2 * Copyright (C) 2018 The UBports project
3 * Copyright (C) 2013-2016 Canonical Ltd.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18import QtQuick 2.15
19import QOfono 0.2
20import Lomiri.Components 1.3
21import Lomiri.SystemSettings.SecurityPrivacy 1.0
22import Lomiri.Connectivity 1.0
23import Wizard 0.1
24import "../Components"
25
26StyledItem {
27 id: root
28 objectName: "wizardPages"
29 focus: true
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: LomiriSecurityPrivacyPanel.Passphrase
36 property string password: ""
37
38 property bool seenSIMPage: false // we want to see the SIM page at most once
39 readonly property bool connected: NetworkingStatus.online
40
41 property alias modemManager: modemManager
42 property alias simManager0: simManager0
43 property alias simManager1: simManager1
44
45 theme: ThemeSettings {
46 name: "Lomiri.Components.Themes.Ambiance"
47 }
48
49 LomiriSecurityPrivacyPanel {
50 id: securityPrivacy
51 objectName: "securityPrivacy"
52 }
53
54 OfonoManager { // need it here for the language and country detection
55 id: modemManager
56 readonly property bool gotSimCard: available && ((simManager0.ready && simManager0.present) || (simManager1.ready && simManager1.present))
57 property bool ready: false
58 onModemsChanged: {
59 ready = true;
60 }
61 }
62
63 // Ideally we would query the system more cleverly than hardcoding two
64 // sims. But we don't yet have a more clever way. :(
65 OfonoSimManager {
66 id: simManager0
67 modemPath: modemManager.modems.length >= 1 ? modemManager.modems[0] : ""
68 }
69
70 OfonoSimManager {
71 id: simManager1
72 modemPath: modemManager.modems.length >= 2 ? modemManager.modems[1] : ""
73 }
74
75 function quitWizard() {
76 pageStack.currentPage.enabled = false;
77
78 if (password != "") {
79 var errorMsg = securityPrivacy.setSecurity("", password, passwordMethod)
80 if (errorMsg !== "") {
81 // Ignore (but log) any errors, since we're past where the user set
82 // the method. Worst case, we just leave the user with a swipe
83 // security method and they fix it in the system settings.
84 console.log("Wizard: Error setting security method:", errorMsg)
85 }
86 }
87
88 quit();
89 }
90
91 MouseArea { // eat anything that gets past widgets
92 anchors.fill: parent
93 }
94
95 Rectangle {
96 id: background
97 anchors.fill: root
98 color: "#fdfdfd"
99 }
100
101 PageList {
102 id: pageList
103 }
104
105 ActivityIndicator {
106 id: pagesSpinner
107 anchors.centerIn: parent
108 z: 100
109 running: false
110 visible: running
111
112 NumberAnimation on opacity {
113 id: fadeInAnimation
114 from: 0
115 to: 1
116 duration: 200
117 }
118
119 onVisibleChanged: {
120 if (visible) {
121 opacity = 0;
122 fadeInAnimation.start();
123 }
124 }
125 }
126
127 Timer {
128 id: impatientLoadingTimer
129 interval: 1700
130 onTriggered: {
131 console.warn("Wizard: Impatient timer going off. Fix the wizard, it's too slow at skipping pages.")
132 pagesSpinner.running = true;
133 }
134 }
135
136 PageStack {
137 id: pageStack
138 objectName: "pageStack"
139 anchors.fill: parent
140
141 function next() {
142 // If we've opened any extra (non-main) pages, pop them before
143 // continuing so back button returns to the previous main page.
144 while (pageList.index < pageStack.depth - 1)
145 pop();
146 load(pageList.next());
147 }
148
149 function prev() {
150 var isPrimaryPage = currentPage && !currentPage.customTitle;
151 if (pageList.index >= pageStack.depth - 1) {
152 pageList.prev(); // update pageList.index, but not for extra pages
153 }
154 pop()
155 if (!currentPage || currentPage.opacity === 0) { // undo skipped pages
156 prev();
157 } else {
158 currentPage.enabled = true;
159 }
160
161 if (isPrimaryPage) {
162 currentPage.aboutToShow(LomiriAnimation.BriskDuration, Qt.LeftToRight);
163 } else {
164 currentPage.aboutToShowSecondary(LomiriAnimation.BriskDuration);
165 }
166 }
167
168 function load(path) {
169 if (currentPage) {
170 currentPage.enabled = false;
171 }
172
173 // First load it invisible, check that we should actually use
174 // this page, and either skip it or continue.
175 push(path, {"opacity": 0, "enabled": false});
176
177 timeout.restart();
178 impatientLoadingTimer.start();
179
180 console.info("Wizard: Loading page " + currentPage.objectName);
181
182 // Check for immediate skip or not. We may have to wait for
183 // skipValid to be assigned (see Connections object below)
184 checkSkip();
185
186 var isPrimaryPage = !currentPage.customTitle;
187 if (isPrimaryPage) {
188 currentPage.aboutToShow(LomiriAnimation.BriskDuration, Qt.RightToLeft);
189 } else {
190 currentPage.aboutToShowSecondary(LomiriAnimation.BriskDuration);
191 }
192 }
193
194 function checkSkip() {
195 if (!currentPage) { // may have had a parse error
196 console.warn("Wizard: page skipped due to possible parse error.");
197 next();
198 } else if (currentPage.skipValid) {
199 if (currentPage.skip) {
200 next();
201 } else if ((currentPage.onlyOnUpdate && !wizard.isUpdate) ||
202 (currentPage.onlyOnInstall && wizard.isUpdate)) {
203 next();
204 } else {
205 impatientLoadingTimer.stop()
206 pagesSpinner.running = false;
207 currentPage.opacity = 1;
208 currentPage.enabled = true;
209 timeout.stop();
210 }
211 }
212 }
213
214 Timer {
215 id: timeout
216 objectName: "timeout"
217 interval: 2000 // wizard pages shouldn't take long
218 onTriggered: {
219 console.warn("Wizard: Page " + pageStack.currentPage.objectName + " skipped due to taking too long!!!");
220 pageStack.currentPage.skip = true;
221 pageStack.currentPage.skipValid = true;
222 }
223 }
224
225 Connections {
226 target: pageStack.currentPage
227 function onSkipValidChanged() { pageStack.checkSkip() }
228 }
229
230 Component.onCompleted: {
231 next();
232 }
233 }
234}