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
24 // to be read from outside
25 readonly property bool fullscreen: application ? application.fullscreen : false
26 property alias interactive: sessionContainer.interactive
27 property bool orientationChangesEnabled: d.supportsSurfaceResize ? d.surfaceOldEnoughToBeResized : true
29 // to be set from outside
30 property QtObject application
31 property int surfaceOrientationAngle
36 // helpers so that we don't have to check for the existence of an application everywhere
37 // (in order to avoid breaking qml binding due to a javascript exception)
38 readonly property string name: root.application ? root.application.name : ""
39 readonly property url icon: root.application ? root.application.icon : ""
40 readonly property int applicationState: root.application ? root.application.state : -1
41 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
42 readonly property url splashImage: root.application ? root.application.splashImage : ""
43 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
44 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
45 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
46 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
47 readonly property url defaultScreenshot: (root.application && root.application.defaultScreenshot !== undefined) ? root.application.defaultScreenshot : ""
49 // Whether the Application had a surface before but lost it.
50 property bool hadSurface: sessionContainer.surfaceContainer.hadSurface
52 property bool needToTakeScreenshot:
53 ((sessionContainer.surface && d.surfaceInitialized) || d.hadSurface)
54 && screenshotImage.status === Image.Null
55 && d.applicationState === ApplicationInfoInterface.Stopped
56 onNeedToTakeScreenshotChanged: {
57 if (needToTakeScreenshot) {
58 screenshotImage.take();
62 //FIXME - this is a hack to avoid the first few rendered frames as they
63 // might show the UI accommodating due to surface resizes on startup.
64 // Remove this when possible
65 property bool surfaceInitialized: false
67 property bool supportsSurfaceResize:
69 ((application.supportedOrientations & Qt.PortraitOrientation)
70 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
72 ((application.supportedOrientations & Qt.LandscapeOrientation)
73 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
75 property bool surfaceOldEnoughToBeResized: false
81 onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
87 onTriggered: { if (stateGroup.state === "surface") { d.surfaceOldEnoughToBeResized = true; } }
92 objectName: "screenshotImage"
93 source: d.defaultScreenshot
95 antialiasing: !root.interactive
98 // Save memory by using a half-resolution (thus quarter size) screenshot.
99 // Do not make this a binding, we can only take the screenshot once!
100 sourceSize.width = root.width / 2;
101 sourceSize.height = root.height / 2;
103 // Format: "image://application/$APP_ID/$CURRENT_TIME_MS"
104 // eg: "image://application/calculator-app/123456"
105 var timeMs = new Date().getTime();
106 source = "image://application/" + root.application.appId + "/" + timeMs;
115 sourceComponent: Component {
118 title: d.splashTitle ? d.splashTitle : d.name
119 imageSource: d.splashImage
121 showHeader: d.splashShowHeader
122 backgroundColor: d.splashColor
123 headerColor: d.splashColorHeader
124 footerColor: d.splashColorFooter
131 // A fake application might not even have a session property.
132 session: application && application.session ? application.session : null
135 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
138 if (sessionContainer.surface) {
139 surfaceInitTimer.start();
140 if (ApplicationManager.focusedApplicationId == application.appId) {
141 root.forceActiveFocus();
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();