2 * Copyright 2014-2015 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
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 Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import Ubuntu.Components 1.3
19 import Unity.Application 0.1
23 implicitWidth: sessionContainer.implicitWidth
24 implicitHeight: sessionContainer.implicitHeight
26 // to be read from outside
27 readonly property bool fullscreen: application ? application.fullscreen : false
28 property alias interactive: sessionContainer.interactive
29 property bool orientationChangesEnabled: d.supportsSurfaceResize ? d.surfaceOldEnoughToBeResized : true
30 readonly property string title: sessionContainer.surface && sessionContainer.surface.name !== "" ?
31 sessionContainer.surface.name : d.name
33 // to be set from outside
34 property QtObject application
35 property int surfaceOrientationAngle
36 property alias resizeSurface: sessionContainer.resizeSurface
41 // helpers so that we don't have to check for the existence of an application everywhere
42 // (in order to avoid breaking qml binding due to a javascript exception)
43 readonly property string name: root.application ? root.application.name : ""
44 readonly property url icon: root.application ? root.application.icon : ""
45 readonly property int applicationState: root.application ? root.application.state : -1
46 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
47 readonly property url splashImage: root.application ? root.application.splashImage : ""
48 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
49 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
50 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
51 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
52 readonly property url defaultScreenshot: (root.application && root.application.defaultScreenshot !== undefined) ? root.application.defaultScreenshot : ""
54 // Whether the Application had a surface before but lost it.
55 property bool hadSurface: sessionContainer.surfaceContainer.hadSurface
57 property bool needToTakeScreenshot:
58 ((sessionContainer.surface && d.surfaceInitialized) || d.hadSurface)
59 && screenshotImage.status === Image.Null
60 && d.applicationState === ApplicationInfoInterface.Stopped
61 onNeedToTakeScreenshotChanged: {
62 if (needToTakeScreenshot) {
63 screenshotImage.take();
67 //FIXME - this is a hack to avoid the first few rendered frames as they
68 // might show the UI accommodating due to surface resizes on startup.
69 // Remove this when possible
70 property bool surfaceInitialized: false
72 property bool supportsSurfaceResize:
74 ((application.supportedOrientations & Qt.PortraitOrientation)
75 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
77 ((application.supportedOrientations & Qt.LandscapeOrientation)
78 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
80 property bool surfaceOldEnoughToBeResized: false
86 onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
92 onTriggered: { if (stateGroup.state === "surface") { d.surfaceOldEnoughToBeResized = true; } }
97 objectName: "screenshotImage"
98 source: d.defaultScreenshot
100 antialiasing: !root.interactive
103 // Save memory by using a half-resolution (thus quarter size) screenshot.
104 // Do not make this a binding, we can only take the screenshot once!
105 sourceSize.width = root.width / 2;
106 sourceSize.height = root.height / 2;
108 // Format: "image://application/$APP_ID/$CURRENT_TIME_MS"
109 // eg: "image://application/calculator-app/123456"
110 var timeMs = new Date().getTime();
111 source = "image://application/" + root.application.appId + "/" + timeMs;
120 sourceComponent: Component {
123 title: d.splashTitle ? d.splashTitle : d.name
124 imageSource: d.splashImage
126 showHeader: d.splashShowHeader
127 backgroundColor: d.splashColor
128 headerColor: d.splashColorHeader
129 footerColor: d.splashColorFooter
136 // A fake application might not even have a session property.
137 session: application && application.session ? application.session : null
140 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
143 if (sessionContainer.surface) {
144 surfaceInitTimer.start();
146 d.surfaceInitialized = false;
155 objectName: "applicationWindowStateGroup"
160 d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
162 screenshotImage.status !== Image.Ready
167 !d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
169 screenshotImage.status !== Image.Ready
174 (sessionContainer.surface && d.surfaceInitialized)
176 (d.applicationState !== ApplicationInfoInterface.Stopped
177 || screenshotImage.status !== Image.Ready)
182 screenshotImage.status === Image.Ready
184 (d.applicationState === ApplicationInfoInterface.Stopped
185 || !sessionContainer.surface || !d.surfaceInitialized)
191 from: ""; to: "splashScreen"
192 PropertyAction { target: splashLoader; property: "active"; value: true }
193 PropertyAction { target: sessionContainer.surfaceContainer
194 property: "visible"; value: false }
197 from: "splashScreen"; to: "surface"
198 SequentialAnimation {
199 PropertyAction { target: sessionContainer.surfaceContainer
200 property: "opacity"; value: 0.0 }
201 PropertyAction { target: sessionContainer.surfaceContainer
202 property: "visible"; value: true }
203 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
205 duration: UbuntuAnimation.BriskDuration }
206 ScriptAction { script: {
207 splashLoader.active = false;
208 surfaceIsOldTimer.start();
213 from: "surface"; to: "splashScreen"
214 SequentialAnimation {
215 ScriptAction { script: {
216 surfaceIsOldTimer.stop();
217 d.surfaceOldEnoughToBeResized = false;
218 splashLoader.active = true;
219 sessionContainer.surfaceContainer.visible = true;
221 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
223 duration: UbuntuAnimation.BriskDuration }
224 PropertyAction { target: sessionContainer.surfaceContainer
225 property: "visible"; value: false }
229 from: "surface"; to: "screenshot"
230 SequentialAnimation {
231 ScriptAction { script: {
232 surfaceIsOldTimer.stop();
233 d.surfaceOldEnoughToBeResized = false;
234 screenshotImage.visible = true;
236 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
238 duration: UbuntuAnimation.BriskDuration }
239 ScriptAction { script: {
240 sessionContainer.surfaceContainer.visible = false;
241 if (sessionContainer.session) { sessionContainer.session.release(); }
246 from: "screenshot"; to: "surface"
247 SequentialAnimation {
248 PropertyAction { target: sessionContainer.surfaceContainer
249 property: "visible"; value: true }
250 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
252 duration: UbuntuAnimation.BriskDuration }
253 ScriptAction { script: {
254 screenshotImage.visible = false;
255 screenshotImage.source = "";
256 surfaceIsOldTimer.start();
261 from: "splashScreen"; to: "screenshot"
262 SequentialAnimation {
263 PropertyAction { target: screenshotImage
264 property: "visible"; value: true }
265 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
267 duration: UbuntuAnimation.BriskDuration }
268 PropertyAction { target: splashLoader; property: "active"; value: false }
272 from: "surface"; to: "void"
273 ScriptAction { script: {
274 surfaceIsOldTimer.stop();
275 d.surfaceOldEnoughToBeResized = false;
276 sessionContainer.surfaceContainer.visible = false;
277 if (sessionContainer.session) { sessionContainer.session.release(); }
281 from: "void"; to: "surface"
282 SequentialAnimation {
283 PropertyAction { target: sessionContainer.surfaceContainer; property: "opacity"; value: 0.0 }
284 PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: true }
285 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
287 duration: UbuntuAnimation.BriskDuration }
288 ScriptAction { script: {
289 surfaceIsOldTimer.start();