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.1
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
31 // to be set from outside
32 property QtObject application
33 property int surfaceOrientationAngle
34 property alias resizeSurface: sessionContainer.resizeSurface
39 // helpers so that we don't have to check for the existence of an application everywhere
40 // (in order to avoid breaking qml binding due to a javascript exception)
41 readonly property string name: root.application ? root.application.name : ""
42 readonly property url icon: root.application ? root.application.icon : ""
43 readonly property int applicationState: root.application ? root.application.state : -1
44 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
45 readonly property url splashImage: root.application ? root.application.splashImage : ""
46 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
47 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
48 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
49 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
50 readonly property url defaultScreenshot: (root.application && root.application.defaultScreenshot !== undefined) ? root.application.defaultScreenshot : ""
52 // Whether the Application had a surface before but lost it.
53 property bool hadSurface: sessionContainer.surfaceContainer.hadSurface
55 property bool needToTakeScreenshot:
56 ((sessionContainer.surface && d.surfaceInitialized) || d.hadSurface)
57 && screenshotImage.status === Image.Null
58 && d.applicationState === ApplicationInfoInterface.Stopped
59 onNeedToTakeScreenshotChanged: {
60 if (needToTakeScreenshot) {
61 screenshotImage.take();
65 //FIXME - this is a hack to avoid the first few rendered frames as they
66 // might show the UI accommodating due to surface resizes on startup.
67 // Remove this when possible
68 property bool surfaceInitialized: false
70 property bool supportsSurfaceResize:
72 ((application.supportedOrientations & Qt.PortraitOrientation)
73 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
75 ((application.supportedOrientations & Qt.LandscapeOrientation)
76 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
78 property bool surfaceOldEnoughToBeResized: false
84 onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
90 onTriggered: { if (stateGroup.state === "surface") { d.surfaceOldEnoughToBeResized = true; } }
95 objectName: "screenshotImage"
96 source: d.defaultScreenshot
98 antialiasing: !root.interactive
101 // Save memory by using a half-resolution (thus quarter size) screenshot.
102 // Do not make this a binding, we can only take the screenshot once!
103 sourceSize.width = root.width / 2;
104 sourceSize.height = root.height / 2;
106 // Format: "image://application/$APP_ID/$CURRENT_TIME_MS"
107 // eg: "image://application/calculator-app/123456"
108 var timeMs = new Date().getTime();
109 source = "image://application/" + root.application.appId + "/" + timeMs;
118 sourceComponent: Component {
121 title: d.splashTitle ? d.splashTitle : d.name
122 imageSource: d.splashImage
124 showHeader: d.splashShowHeader
125 backgroundColor: d.splashColor
126 headerColor: d.splashColorHeader
127 footerColor: d.splashColorFooter
134 // A fake application might not even have a session property.
135 session: application && application.session ? application.session : null
138 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
141 if (sessionContainer.surface) {
142 surfaceInitTimer.start();
144 d.surfaceInitialized = false;
153 objectName: "applicationWindowStateGroup"
158 d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
160 screenshotImage.status !== Image.Ready
165 !d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
167 screenshotImage.status !== Image.Ready
172 (sessionContainer.surface && d.surfaceInitialized)
174 (d.applicationState !== ApplicationInfoInterface.Stopped
175 || screenshotImage.status !== Image.Ready)
180 screenshotImage.status === Image.Ready
182 (d.applicationState === ApplicationInfoInterface.Stopped
183 || !sessionContainer.surface || !d.surfaceInitialized)
189 from: ""; to: "splashScreen"
190 PropertyAction { target: splashLoader; property: "active"; value: true }
191 PropertyAction { target: sessionContainer.surfaceContainer
192 property: "visible"; value: false }
195 from: "splashScreen"; to: "surface"
196 SequentialAnimation {
197 PropertyAction { target: sessionContainer.surfaceContainer
198 property: "opacity"; value: 0.0 }
199 PropertyAction { target: sessionContainer.surfaceContainer
200 property: "visible"; value: true }
201 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
203 duration: UbuntuAnimation.BriskDuration }
204 ScriptAction { script: {
205 splashLoader.active = false;
206 surfaceIsOldTimer.start();
211 from: "surface"; to: "splashScreen"
212 SequentialAnimation {
213 ScriptAction { script: {
214 surfaceIsOldTimer.stop();
215 d.surfaceOldEnoughToBeResized = false;
216 splashLoader.active = true;
217 sessionContainer.surfaceContainer.visible = true;
219 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
221 duration: UbuntuAnimation.BriskDuration }
222 PropertyAction { target: sessionContainer.surfaceContainer
223 property: "visible"; value: false }
227 from: "surface"; to: "screenshot"
228 SequentialAnimation {
229 ScriptAction { script: {
230 surfaceIsOldTimer.stop();
231 d.surfaceOldEnoughToBeResized = false;
232 screenshotImage.visible = true;
234 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
236 duration: UbuntuAnimation.BriskDuration }
237 ScriptAction { script: {
238 sessionContainer.surfaceContainer.visible = false;
239 if (sessionContainer.session) { sessionContainer.session.release(); }
244 from: "screenshot"; to: "surface"
245 SequentialAnimation {
246 PropertyAction { target: sessionContainer.surfaceContainer
247 property: "visible"; value: true }
248 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
250 duration: UbuntuAnimation.BriskDuration }
251 ScriptAction { script: {
252 screenshotImage.visible = false;
253 screenshotImage.source = "";
254 surfaceIsOldTimer.start();
259 from: "splashScreen"; to: "screenshot"
260 SequentialAnimation {
261 PropertyAction { target: screenshotImage
262 property: "visible"; value: true }
263 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
265 duration: UbuntuAnimation.BriskDuration }
266 PropertyAction { target: splashLoader; property: "active"; value: false }
270 from: "surface"; to: "void"
271 ScriptAction { script: {
272 surfaceIsOldTimer.stop();
273 d.surfaceOldEnoughToBeResized = false;
274 sessionContainer.surfaceContainer.visible = false;
275 if (sessionContainer.session) { sessionContainer.session.release(); }
279 from: "void"; to: "surface"
280 SequentialAnimation {
281 PropertyAction { target: sessionContainer.surfaceContainer; property: "opacity"; value: 0.0 }
282 PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: true }
283 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
285 duration: UbuntuAnimation.BriskDuration }
286 ScriptAction { script: {
287 surfaceIsOldTimer.start();