1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/*
* Copyright 2014 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import Ubuntu.Components 1.1
import Unity.Application 0.1
Item {
id: root
// to be read from outside
readonly property bool fullscreen: application ? application.fullscreen : false
property alias interactive: sessionContainer.interactive
// to be set from outside
property QtObject application
property int orientation
QtObject {
id: d
// helpers so that we don't have to check for the existence of an application everywhere
// (in order to avoid breaking qml binding due to a javascript exception)
readonly property string name: root.application ? root.application.name : ""
readonly property url icon: root.application ? root.application.icon : ""
readonly property int applicationState: root.application ? root.application.state : -1
readonly property string splashTitle: root.application ? root.application.splashTitle : ""
readonly property url splashImage: root.application ? root.application.splashImage : ""
readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
// Whether the Application had a surface before but lost it.
property bool hadSurface: sessionContainer.surfaceContainer.hadSurface
property bool needToTakeScreenshot:
sessionContainer.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
&& d.applicationState === ApplicationInfoInterface.Stopped
onNeedToTakeScreenshotChanged: {
if (needToTakeScreenshot) {
screenshotImage.take();
}
}
//FIXME - this is a hack to avoid the first few rendered frames as they
// might show the UI accommodating due to surface resizes on startup.
// Remove this when possible
property bool surfaceInitialized: false
}
Timer {
id: surfaceInitTimer
interval: 100
onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
}
Image {
id: screenshotImage
objectName: "screenshotImage"
source: ""
anchors.fill: parent
function take() {
// Format: "image://application/$APP_ID/$CURRENT_TIME_MS"
// eg: "image://application/calculator-app/123456"
var timeMs = new Date().getTime();
source = "image://application/" + root.application.appId + "/" + timeMs;
}
// Save memory by using a half-resolution (thus quarter size) screenshot
sourceSize.width: root.width / 2
sourceSize.height: root.height / 2
}
Loader {
id: splashLoader
visible: active
active: false
anchors.fill: parent
sourceComponent: Component {
Splash {
id: splash
title: d.splashTitle ? d.splashTitle : d.name
imageSource: d.splashImage
icon: d.icon
showHeader: d.splashShowHeader
backgroundColor: d.splashColor
headerColor: d.splashColorHeader
footerColor: d.splashColorFooter
}
}
}
SessionContainer {
id: sessionContainer
session: application ? application.session : null
anchors.fill: parent
orientation: root.orientation
onSurfaceChanged: {
if (sessionContainer.surface) {
surfaceInitTimer.start();
d.forceSurfaceActiveFocusIfReady();
} else {
d.surfaceInitialized = false;
}
}
}
StateGroup {
objectName: "applicationWindowStateGroup"
states: [
State {
name: "void"
when:
d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
&&
screenshotImage.status !== Image.Ready
},
State {
name: "splashScreen"
when:
!d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
&&
screenshotImage.status !== Image.Ready
},
State {
name: "surface"
when:
(sessionContainer.surface && d.surfaceInitialized)
&&
(d.applicationState !== ApplicationInfoInterface.Stopped
|| screenshotImage.status !== Image.Ready)
},
State {
name: "screenshot"
when:
screenshotImage.status === Image.Ready
&&
(d.applicationState === ApplicationInfoInterface.Stopped
|| !sessionContainer.surface || !d.surfaceInitialized)
}
]
transitions: [
Transition {
from: ""; to: "splashScreen"
PropertyAction { target: splashLoader; property: "active"; value: true }
PropertyAction { target: sessionContainer.surfaceContainer
property: "visible"; value: false }
},
Transition {
from: "splashScreen"; to: "surface"
SequentialAnimation {
PropertyAction { target: sessionContainer.surfaceContainer
property: "opacity"; value: 0.0 }
PropertyAction { target: sessionContainer.surfaceContainer
property: "visible"; value: true }
UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
from: 0.0; to: 1.0
duration: UbuntuAnimation.BriskDuration }
PropertyAction { target: splashLoader; property: "active"; value: false }
}
},
Transition {
from: "surface"; to: "splashScreen"
SequentialAnimation {
PropertyAction { target: splashLoader; property: "active"; value: true }
PropertyAction { target: sessionContainer.surfaceContainer
property: "visible"; value: true }
UbuntuNumberAnimation { target: splashLoader; property: "opacity";
from: 0.0; to: 1.0
duration: UbuntuAnimation.BriskDuration }
PropertyAction { target: sessionContainer.surfaceContainer
property: "visible"; value: false }
}
},
Transition {
from: "surface"; to: "screenshot"
SequentialAnimation {
PropertyAction { target: screenshotImage
property: "visible"; value: true }
UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
from: 0.0; to: 1.0
duration: UbuntuAnimation.BriskDuration }
PropertyAction { target: sessionContainer.surfaceContainer
property: "visible"; value: false }
ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
}
},
Transition {
from: "screenshot"; to: "surface"
SequentialAnimation {
PropertyAction { target: sessionContainer.surfaceContainer
property: "visible"; value: true }
UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
from: 1.0; to: 0.0
duration: UbuntuAnimation.BriskDuration }
PropertyAction { target: screenshotImage; property: "visible"; value: false }
PropertyAction { target: screenshotImage; property: "source"; value: "" }
}
},
Transition {
from: "surface"; to: "void"
SequentialAnimation {
PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: false }
ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
}
},
Transition {
from: "void"; to: "surface"
SequentialAnimation {
PropertyAction { target: sessionContainer.surfaceContainer; property: "opacity"; value: 0.0 }
PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: true }
UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
from: 0.0; to: 1.0
duration: UbuntuAnimation.BriskDuration }
}
}
]
}
}
|