~mterry/unity8/split

« back to all changes in this revision

Viewing changes to Components/EdgeDemo.qml

  • Committer: Michael Terry
  • Date: 2013-08-22 19:14:08 UTC
  • mto: (138.115.14 launcher-items)
  • mto: This revision was merged to the branch mainline in revision 148.
  • Revision ID: michael.terry@canonical.com-20130822191408-t324csvzul9x32ss
Move all edge demo logic into a new component that handles the flow and creates objects dynamically

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 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 AccountsService 0.1
 
18
import LightDM 0.1 as LightDM
 
19
import QtQuick 2.0
 
20
 
 
21
Item {
 
22
    id: demo
 
23
 
 
24
    property Item greeter
 
25
    property Item dash
 
26
    property Item launcher
 
27
    property Item indicators
 
28
    property Item overlay
 
29
 
 
30
    property bool launcherEnabled: true
 
31
    property bool dashEnabled: true
 
32
    property bool panelEnabled: true
 
33
 
 
34
    property bool showEdgeDemo: false
 
35
    property bool showEdgeDemoInGreeter: showEdgeDemo // TODO: AccountsService.getUserProperty("lightdm", "demo-edges")
 
36
 
 
37
    function hideEdgeDemoInShell() {
 
38
        var user = LightDM.Users.data(greeter.currentIndex, LightDM.UserRoles.NameRole);
 
39
        AccountsService.setUserProperty(user, "demo-edges", false);
 
40
        demo.showEdgeDemo = false;
 
41
        stopDemo();
 
42
    }
 
43
 
 
44
    function hideEdgeDemoInGreeter() {
 
45
        // TODO: AccountsService.setUserProperty("lightdm", "demo-edges", false);
 
46
        demo.showEdgeDemoInGreeter = false;
 
47
    }
 
48
 
 
49
    function hideEdgeDemos() {
 
50
        hideEdgeDemoInGreeter();
 
51
        hideEdgeDemoInShell();
 
52
    }
 
53
 
 
54
    function stopDemo() {
 
55
        launcherEnabled = true;
 
56
        dashEnabled = true;
 
57
        panelEnabled = true;
 
58
        if (d.rightEdgeDemo)  d.rightEdgeDemo.destroy()
 
59
        if (d.topEdgeDemo)    d.topEdgeDemo.destroy()
 
60
        if (d.bottomEdgeDemo) d.bottomEdgeDemo.destroy()
 
61
        if (d.leftEdgeDemo)   d.leftEdgeDemo.destroy()
 
62
        if (d.finalEdgeDemo)  d.finalEdgeDemo.destroy()
 
63
    }
 
64
 
 
65
    QtObject {
 
66
        id: d
 
67
        property Component overlay
 
68
        property QtObject rightEdgeDemo
 
69
        property QtObject topEdgeDemo
 
70
        property QtObject bottomEdgeDemo
 
71
        property QtObject leftEdgeDemo
 
72
        property QtObject finalEdgeDemo
 
73
    }
 
74
 
 
75
    onShowEdgeDemoInGreeterChanged: {
 
76
        if (!d.overlay && showEdgeDemoInGreeter) {
 
77
            d.overlay = Qt.createComponent("EdgeDemoOverlay.qml")
 
78
            startRightEdgeDemo()
 
79
        }
 
80
    }
 
81
 
 
82
    function startRightEdgeDemo() {
 
83
        launcherEnabled = false;
 
84
        demo.dashEnabled = false;
 
85
        demo.panelEnabled = false;
 
86
        if (demo.greeter) {
 
87
            d.rightEdgeDemo = d.overlay.createObject(demo.greeter, {
 
88
                "edge": "right",
 
89
                "title": i18n.tr("Right edge"),
 
90
                "text": i18n.tr("Try swiping from the right edge to unlock the phone"),
 
91
                "anchors.fill": demo.greeter,
 
92
            });
 
93
            d.rightEdgeDemo.onSkip.connect(demo.hideEdgeDemos)
 
94
        } else {
 
95
            stopDemo();
 
96
        }
 
97
    }
 
98
 
 
99
    Connections {
 
100
        target: demo.greeter
 
101
 
 
102
        function hide() {
 
103
            if (d.rightEdgeDemo) {
 
104
                d.rightEdgeDemo.hide()
 
105
                hideEdgeDemoInGreeter()
 
106
                startTopEdgeDemo()
 
107
            }
 
108
        }
 
109
 
 
110
        onUnlocked: hide()
 
111
        onShownChanged: if (!greeter.shown) hide()
 
112
 
 
113
        onSelected: {
 
114
            var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole)
 
115
            showEdgeDemo = true;///AccountsService.getUserProperty(user, "demo-edges")
 
116
        }
 
117
    }
 
118
 
 
119
    function startTopEdgeDemo() {
 
120
        demo.panelEnabled = true;
 
121
        if (demo.dash) {
 
122
            d.topEdgeDemo = d.overlay.createObject(demo.dash, {
 
123
                "edge": "top",
 
124
                "title": i18n.tr("Top edge"),
 
125
                "text": i18n.tr("Try swiping from the top edge to access the indicators"),
 
126
                "anchors.fill": demo.dash,
 
127
            });
 
128
            d.topEdgeDemo.onSkip.connect(demo.hideEdgeDemoInShell)
 
129
        } else {
 
130
            stopDemo();
 
131
        }
 
132
    }
 
133
 
 
134
    Connections {
 
135
        target: demo.indicators
 
136
        onFullyOpenedChanged: {
 
137
            if (d.topEdgeDemo && demo.indicators.fullyOpened) {
 
138
                d.topEdgeDemo.hideNow()
 
139
                startBottomEdgeDemo()
 
140
            }
 
141
        }
 
142
    }
 
143
 
 
144
    function startBottomEdgeDemo() {
 
145
        if (demo.indicators) {
 
146
            d.bottomEdgeDemo = d.overlay.createObject(demo.indicators, {
 
147
                "edge": "bottom",
 
148
                "title": i18n.tr("Close"),
 
149
                "text": i18n.tr("Swipe up again to close the settings screen"),
 
150
                "anchors.fill": demo.indicators,
 
151
            });
 
152
            d.bottomEdgeDemo.onSkip.connect(demo.hideEdgeDemoInShell)
 
153
        } else {
 
154
            stopDemo();
 
155
        }
 
156
    }
 
157
 
 
158
    Connections {
 
159
        target: demo.indicators
 
160
        onPartiallyOpenedChanged: {
 
161
            if (d.bottomEdgeDemo && !demo.indicators.partiallyOpened && !demo.indicators.fullyOpened) {
 
162
                d.bottomEdgeDemo.hideNow()
 
163
                startLeftEdgeDemo()
 
164
            }
 
165
        }
 
166
    }
 
167
 
 
168
    function startLeftEdgeDemo() {
 
169
        demo.panelEnabled = false;
 
170
        demo.launcherEnabled = true;
 
171
        if (demo.dash) {
 
172
            d.leftEdgeDemo = d.overlay.createObject(demo.dash, {
 
173
                "edge": "left",
 
174
                "title": i18n.tr("Left edge"),
 
175
                "text": i18n.tr("Swipe from the left to reveal the launcher for quick access to apps"),
 
176
                "anchors.fill": demo.dash,
 
177
            });
 
178
            d.leftEdgeDemo.onSkip.connect(demo.hideEdgeDemoInShell)
 
179
        } else {
 
180
            stopDemo();
 
181
        }
 
182
    }
 
183
 
 
184
    Connections {
 
185
        target: demo.launcher
 
186
        onStateChanged: {
 
187
            if (d.leftEdgeDemo && launcher.state == "visible") {
 
188
                d.leftEdgeDemo.hide()
 
189
                startFinalEdgeDemo()
 
190
            }
 
191
        }
 
192
    }
 
193
 
 
194
    function startFinalEdgeDemo() {
 
195
        demo.launcherEnabled = false;
 
196
        if (demo.dash) {
 
197
            d.finalEdgeDemo = d.overlay.createObject(demo.overlay, {
 
198
                "edge": "none",
 
199
                "title": i18n.tr("Well done"),
 
200
                "text": i18n.tr("You have now mastered the edge gestures and can start using the phone"),
 
201
                "anchors.fill": demo.overlay,
 
202
            });
 
203
            d.finalEdgeDemo.onSkip.connect(demo.hideEdgeDemoInShell)
 
204
        } else {
 
205
            stopDemo();
 
206
        }
 
207
    }
 
208
}