on 02f0ecb help sign in
unity8/qml/Tutorial/TutorialContent.qml
165 lines 5.9 kB history raw
1/*
2 * Copyright (C) 2013,2014 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 AccountsService 0.1
20import Unity.Application 0.1
22Item {
23 id: root
25 property Item launcher
26 property Item panel
27 property Item stage
28 property string usageScenario
29 property bool paused
30 property bool keyboardVisible
31 property var lastInputTimestamp
33 readonly property bool launcherEnabled: !running || tutorialLeft.shown
34 readonly property bool spreadEnabled: !running || tutorialRight.shown
35 readonly property bool panelEnabled: !running || tutorialTop.shown
36 readonly property bool running: tutorialLeft.shown
37 || tutorialTop.shown
38 || tutorialRight.shown
39 || tutorialBottom.shown
41 signal finished()
43 function finish() {
44 finished();
45 }
47 ////
49 QtObject {
50 id: d
52 // We allow "" because it is briefly empty on startup, and we don't
53 // want to improperly skip any mobile tutorials.
54 property bool mobileScenario: root.usageScenario === "" ||
55 root.usageScenario === "phone" ||
56 root.usageScenario === "tablet"
58 property bool endPointsFinished: tutorialRight.skipped && tutorialBottom.skipped
59 onEndPointsFinishedChanged: if (endPointsFinished) root.finish()
60 }
62 TutorialLeft {
63 id: tutorialLeft
64 objectName: "tutorialLeft"
65 anchors.fill: parent
66 launcher: root.launcher
67 hides: [launcher, panel.indicators]
68 paused: root.paused
70 readonly property bool skipped: !d.mobileScenario ||
71 AccountsService.demoEdgesCompleted.indexOf("left") != -1
72 isReady: !skipped && !paused && !keyboardVisible
74 onSkippedChanged: if (skipped && shown) hide()
75 onIsReadyChanged: if (isReady && !shown) show()
76 onFinished: AccountsService.markDemoEdgeCompleted("left")
77 }
79 TutorialTop {
80 id: tutorialTop
81 objectName: "tutorialTop"
82 anchors.fill: parent
83 panel: root.panel
84 hides: [launcher, panel.indicators]
85 paused: root.paused
87 readonly property bool skipped: !d.mobileScenario ||
88 AccountsService.demoEdgesCompleted.indexOf("top") != -1
89 isReady: tutorialLeft.skipped && !skipped && !paused && !keyboardVisible &&
90 !tutorialBottom.shown && !tutorialBottom.mightShow
92 // We fire 30s after left edge tutorial, with at least 3s of inactivity
94 InactivityTimer {
95 id: tutorialTopInactivityTimer
96 lastInputTimestamp: root.lastInputTimestamp
97 page: parent
98 }
100 Timer {
101 id: tutorialTopTimer
102 objectName: "tutorialTopTimer"
103 interval: 27000
104 onTriggered: tutorialTopInactivityTimer.start()
105 }
107 onSkippedChanged: if (skipped && shown) hide()
108 onIsReadyChanged: if (isReady && !shown) tutorialTopTimer.start()
109 onFinished: AccountsService.markDemoEdgeCompleted("top")
110 }
112 TutorialRight {
113 id: tutorialRight
114 objectName: "tutorialRight"
115 anchors.fill: parent
116 stage: root.stage
117 usageScenario: root.usageScenario
118 hides: [launcher, panel.indicators]
119 paused: root.paused
121 readonly property bool skipped: AccountsService.demoEdgesCompleted.indexOf("right") != -1
122 isReady: tutorialTop.skipped && !skipped && !paused && !keyboardVisible &&
123 !tutorialBottom.shown && !tutorialBottom.mightShow &&
124 ApplicationManager.count >= 3
126 InactivityTimer {
127 id: tutorialRightInactivityTimer
128 lastInputTimestamp: root.lastInputTimestamp
129 page: parent
130 }
132 Connections {
133 target: stage
134 onMainAppChanged: {
135 if (tutorialRight.isReady && !tutorialRight.shown && stage.mainApp
136 && stage.mainApp.state === ApplicationInfoInterface.Starting) {
137 tutorialRight.show();
138 }
139 }
140 }
142 onSkippedChanged: if (skipped && shown) hide()
143 onIsReadyChanged: if (isReady && !shown) tutorialRightInactivityTimer.start()
144 onFinished: AccountsService.markDemoEdgeCompleted("right")
145 }
147 TutorialBottom {
148 id: tutorialBottom
149 objectName: "tutorialBottom"
150 anchors.fill: parent
151 hides: [launcher, panel.indicators]
152 paused: root.paused
154 readonly property bool skipped: !d.mobileScenario ||
155 AccountsService.demoEdgesCompleted.indexOf("bottom") != -1
156 readonly property bool mightShow: !skipped && stage.mainApp && canShowForApp(stage.mainApp.appId)
157 isReady: !skipped && !paused && !keyboardVisible &&
158 !tutorialTop.shown && !tutorialRight.shown &&
159 mightShow && stage.mainApp.state === ApplicationInfoInterface.Running
161 onSkippedChanged: if (skipped && shown) hide()
162 onIsReadyChanged: if (isReady && !shown) show()
163 onFinished: AccountsService.markDemoEdgeCompleted("bottom")
164 }