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 && screenshotImage.status === Image.Null
54 && d.applicationState === ApplicationInfoInterface.Stopped
55 onNeedToTakeScreenshotChanged: {
56 if (needToTakeScreenshot) {
57 screenshotImage.take();
61 //FIXME - this is a hack to avoid the first few rendered frames as they
62 // might show the UI accommodating due to surface resizes on startup.
63 // Remove this when possible
64 property bool surfaceInitialized: false
66 property bool supportsSurfaceResize:
68 ((application.supportedOrientations & Qt.PortraitOrientation)
69 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
71 ((application.supportedOrientations & Qt.LandscapeOrientation)
72 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
74 property bool surfaceOldEnoughToBeResized: false
80 onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
86 onTriggered: { if (stateGroup.state === "surface") { d.surfaceOldEnoughToBeResized = true; } }
91 objectName: "screenshotImage"
92 source: d.defaultScreenshot
94 antialiasing: !root.interactive
97 // Format: "image://application/$APP_ID/$CURRENT_TIME_MS"
98 // eg: "image://application/calculator-app/123456"
99 var timeMs = new Date().getTime();
100 source = "image://application/" + root.application.appId + "/" + timeMs;
103 // Save memory by using a half-resolution (thus quarter size) screenshot
104 sourceSize.width: root.width / 2
105 sourceSize.height: root.height / 2
113 sourceComponent: Component {
116 title: d.splashTitle ? d.splashTitle : d.name
117 imageSource: d.splashImage
119 showHeader: d.splashShowHeader
120 backgroundColor: d.splashColor
121 headerColor: d.splashColorHeader
122 footerColor: d.splashColorFooter
129 // A fake application might not even have a session property.
130 session: application && application.session ? application.session : null
133 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
136 if (sessionContainer.surface) {
137 surfaceInitTimer.start();
138 if (ApplicationManager.focusedApplicationId == application.appId) {
139 root.forceActiveFocus();
142 d.surfaceInitialized = false;
151 objectName: "applicationWindowStateGroup"
156 d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
158 screenshotImage.status !== Image.Ready
163 !d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
165 screenshotImage.status !== Image.Ready
170 (sessionContainer.surface && d.surfaceInitialized)
172 (d.applicationState !== ApplicationInfoInterface.Stopped
173 || screenshotImage.status !== Image.Ready)
178 screenshotImage.status === Image.Ready
180 (d.applicationState === ApplicationInfoInterface.Stopped
181 || !sessionContainer.surface || !d.surfaceInitialized)
187 from: ""; to: "splashScreen"
188 PropertyAction { target: splashLoader; property: "active"; value: true }
189 PropertyAction { target: sessionContainer.surfaceContainer
190 property: "visible"; value: false }
193 from: "splashScreen"; to: "surface"
194 SequentialAnimation {
195 PropertyAction { target: sessionContainer.surfaceContainer
196 property: "opacity"; value: 0.0 }
197 PropertyAction { target: sessionContainer.surfaceContainer
198 property: "visible"; value: true }
199 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
201 duration: UbuntuAnimation.BriskDuration }
202 ScriptAction { script: {
203 splashLoader.active = false;
204 surfaceIsOldTimer.start();
209 from: "surface"; to: "splashScreen"
210 SequentialAnimation {
211 ScriptAction { script: {
212 surfaceIsOldTimer.stop();
213 d.surfaceOldEnoughToBeResized = false;
214 splashLoader.active = true;
215 sessionContainer.surfaceContainer.visible = true;
217 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
219 duration: UbuntuAnimation.BriskDuration }
220 PropertyAction { target: sessionContainer.surfaceContainer
221 property: "visible"; value: false }
225 from: "surface"; to: "screenshot"
226 SequentialAnimation {
227 ScriptAction { script: {
228 surfaceIsOldTimer.stop();
229 d.surfaceOldEnoughToBeResized = false;
230 screenshotImage.visible = true;
232 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
234 duration: UbuntuAnimation.BriskDuration }
235 ScriptAction { script: {
236 sessionContainer.surfaceContainer.visible = false;
237 if (sessionContainer.session) { sessionContainer.session.release(); }
242 from: "screenshot"; to: "surface"
243 SequentialAnimation {
244 PropertyAction { target: sessionContainer.surfaceContainer
245 property: "visible"; value: true }
246 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
248 duration: UbuntuAnimation.BriskDuration }
249 ScriptAction { script: {
250 screenshotImage.visible = false;
251 screenshotImage.source = "";
252 surfaceIsOldTimer.start();
257 from: "splashScreen"; to: "screenshot"
258 SequentialAnimation {
259 PropertyAction { target: screenshotImage
260 property: "visible"; value: true }
261 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
263 duration: UbuntuAnimation.BriskDuration }
264 PropertyAction { target: splashLoader; property: "active"; value: false }
268 from: "surface"; to: "void"
269 ScriptAction { script: {
270 surfaceIsOldTimer.stop();
271 d.surfaceOldEnoughToBeResized = false;
272 sessionContainer.surfaceContainer.visible = false;
273 if (sessionContainer.session) { sessionContainer.session.release(); }
277 from: "void"; to: "surface"
278 SequentialAnimation {
279 PropertyAction { target: sessionContainer.surfaceContainer; property: "opacity"; value: 0.0 }
280 PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: true }
281 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
283 duration: UbuntuAnimation.BriskDuration }
284 ScriptAction { script: {
285 surfaceIsOldTimer.start();