on 5578813 help sign in
unity8/qml/Tutorial/TutorialContent.qml
172 lines 6.2 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 var focusedApp: ApplicationManager.focusedApplicationId
59 ? ApplicationManager.findApplication(ApplicationManager.focusedApplicationId)
60 : null
62 property bool endPointsFinished: tutorialRight.skipped && tutorialBottom.skipped
63 onEndPointsFinishedChanged: if (endPointsFinished) root.finish()
64 }
66 TutorialLeft {
67 id: tutorialLeft
68 objectName: "tutorialLeft"
69 anchors.fill: parent
70 launcher: root.launcher
71 hides: [launcher, panel.indicators]
72 paused: root.paused
74 readonly property bool skipped: !d.mobileScenario ||
75 AccountsService.demoEdgesCompleted.indexOf("left") != -1
76 isReady: !skipped && !paused && !keyboardVisible
78 onSkippedChanged: if (skipped && shown) hide()
79 onIsReadyChanged: if (isReady && !shown) show()
80 onFinished: AccountsService.markDemoEdgeCompleted("left")
81 }
83 TutorialTop {
84 id: tutorialTop
85 objectName: "tutorialTop"
86 anchors.fill: parent
87 panel: root.panel
88 hides: [launcher, panel.indicators]
89 paused: root.paused
91 readonly property bool skipped: !d.mobileScenario ||
92 AccountsService.demoEdgesCompleted.indexOf("top") != -1
93 isReady: tutorialLeft.skipped && !skipped && !paused && !keyboardVisible &&
94 !tutorialBottom.shown && !tutorialBottom.mightShow
96 // We fire 30s after left edge tutorial, with at least 3s of inactivity
98 InactivityTimer {
99 id: tutorialTopInactivityTimer
100 lastInputTimestamp: root.lastInputTimestamp
101 page: parent
102 }
104 Timer {
105 id: tutorialTopTimer
106 objectName: "tutorialTopTimer"
107 interval: 27000
108 onTriggered: tutorialTopInactivityTimer.start()
109 }
111 onSkippedChanged: if (skipped && shown) hide()
112 onIsReadyChanged: if (isReady && !shown) tutorialTopTimer.start()
113 onFinished: AccountsService.markDemoEdgeCompleted("top")
114 }
116 TutorialRight {
117 id: tutorialRight
118 objectName: "tutorialRight"
119 anchors.fill: parent
120 stage: root.stage
121 usageScenario: root.usageScenario
122 hides: [launcher, panel.indicators]
123 paused: root.paused
125 readonly property bool skipped: AccountsService.demoEdgesCompleted.indexOf("right") != -1
126 isReady: tutorialTop.skipped && !skipped && !paused && !keyboardVisible &&
127 !tutorialBottom.shown && !tutorialBottom.mightShow &&
128 ApplicationManager.count >= 3
130 InactivityTimer {
131 id: tutorialRightInactivityTimer
132 lastInputTimestamp: root.lastInputTimestamp
133 page: parent
134 }
136 Connections {
137 target: d
138 onFocusedAppChanged: {
139 if (tutorialRight.isReady && !tutorialRight.shown && d.focusedApp
140 && d.focusedApp.state === ApplicationInfoInterface.Starting) {
141 tutorialRight.show();
142 }
143 }
144 }
146 onSkippedChanged: if (skipped && shown) hide()
147 onIsReadyChanged: if (isReady && !shown) tutorialRightInactivityTimer.start()
148 onFinished: AccountsService.markDemoEdgeCompleted("right")
149 }
151 TutorialBottom {
152 id: tutorialBottom
153 objectName: "tutorialBottom"
154 anchors.fill: parent
155 hides: [launcher, panel.indicators]
156 paused: root.paused
157 usageScenario: root.usageScenario
158 stage: root.stage
159 application: d.focusedApp
161 readonly property bool skipped: !d.mobileScenario ||
162 AccountsService.demoEdgesCompleted.indexOf("bottom") != -1
163 readonly property bool mightShow: !skipped && d.focusedApp && canShowForApp(d.focusedApp.appId)
164 isReady: !skipped && !paused && !keyboardVisible &&
165 !tutorialTop.shown && !tutorialRight.shown &&
166 mightShow && d.focusedApp.state === ApplicationInfoInterface.Running
168 onSkippedChanged: if (skipped && shown) hide()
169 onIsReadyChanged: if (isReady && !shown) show()
170 onFinished: AccountsService.markDemoEdgeCompleted("bottom")
171 }