on xenial help sign in
Support for nested prompt session. Fixes: 1358388, 1363081
afc6ec4Nick Dedekind
debian/control+1−1
@@ -85,7 +85,7 @@ Depends: gsettings-desktop-schemas,
85 qmenumodel-qml (>= 0.2.8),
85 qmenumodel-qml (>= 0.2.8),
86 qml-module-qtquick-xmllistmodel,
86 qml-module-qtquick-xmllistmodel,
87 qtdeclarative5-gsettings1.0,
87 qtdeclarative5-gsettings1.0,
88− qtdeclarative5-qtmir-plugin (>= 0.4.1),
88+ qtdeclarative5-qtmir-plugin (>= 0.4.3),
89 qtdeclarative5-ubuntu-telephony0.1,
89 qtdeclarative5-ubuntu-telephony0.1,
90 unity-launcher-impl-3,
90 unity-launcher-impl-3,
91 unity8-common (= ${source:Version}),
91 unity8-common (= ${source:Version}),
plugins/AccountsService/AccountsService.qmltypes+1
@@ -26,5 +26,6 @@ Module {
26 Property { name: "backgroundFile"; type: "string"; isReadonly: true }
26 Property { name: "backgroundFile"; type: "string"; isReadonly: true }
27 Property { name: "statsWelcomeScreen"; type: "bool"; isReadonly: true }
27 Property { name: "statsWelcomeScreen"; type: "bool"; isReadonly: true }
28 Property { name: "passwordDisplayHint"; type: "PasswordDisplayHint"; isReadonly: true }
28 Property { name: "passwordDisplayHint"; type: "PasswordDisplayHint"; isReadonly: true }
29+ Property { name: "failedLogins"; type: "uint" }
29 }
30 }
30}
31}
plugins/LightDM/LightDM.qmltypes+2
@@ -27,6 +27,7 @@ Module {
27 name: "showPrompt"
27 name: "showPrompt"
28 Parameter { name: "text"; type: "string" }
28 Parameter { name: "text"; type: "string" }
29 Parameter { name: "isSecret"; type: "bool" }
29 Parameter { name: "isSecret"; type: "bool" }
30+ Parameter { name: "isDefaultPrompt"; type: "bool" }
30 }
31 }
31 Signal { name: "authenticationComplete" }
32 Signal { name: "authenticationComplete" }
32 Signal {
33 Signal {
@@ -34,6 +35,7 @@ Module {
34 Parameter { name: "user"; type: "string" }
35 Parameter { name: "user"; type: "string" }
35 }
36 }
36 Signal { name: "isActiveChanged" }
37 Signal { name: "isActiveChanged" }
38+ Signal { name: "isAuthenticatedChanged" }
37 Signal { name: "showGreeter" }
39 Signal { name: "showGreeter" }
38 Signal {
40 Signal {
39 name: "requestAuthenticationUser"
41 name: "requestAuthenticationUser"
plugins/Ubuntu/SystemImage/SystemImage.qmltypes+2
@@ -11,6 +11,8 @@ Module {
11 name: "SystemImage"
11 name: "SystemImage"
12 prototype: "QObject"
12 prototype: "QObject"
13 exports: ["Ubuntu.SystemImage/SystemImage 0.1"]
13 exports: ["Ubuntu.SystemImage/SystemImage 0.1"]
14+ isCreatable: false
15+ isSingleton: true
14 exportMetaObjectRevisions: [0]
16 exportMetaObjectRevisions: [0]
15 Method { name: "factoryReset" }
17 Method { name: "factoryReset" }
16 }
18 }
plugins/Unity/Indicators/Indicators.qmltypes+6−4
@@ -219,12 +219,14 @@ Module {
219 Method {
219 Method {
220 name: "model"
220 name: "model"
221 type: "UnityMenuModel*"
221 type: "UnityMenuModel*"
222− Parameter { name: "path"; type: "string" }
222+ Parameter { name: "bus"; type: "QByteArray" }
223+ Parameter { name: "path"; type: "QByteArray" }
224+ Parameter { name: "actions"; type: "QVariantMap" }
223 }
225 }
224 Method {
226 Method {
225− name: "registerModel"
227+ name: "contains"
228+ type: "bool"
226− Parameter { name: "path"; type: "string" }
229+ Parameter { name: "path"; type: "QByteArray" }
227− Parameter { name: "menuModel"; type: "UnityMenuModel"; isPointer: true }
228 }
230 }
229 }
231 }
230 Component {
232 Component {
qml/Shell.qml+9
@@ -233,6 +233,15 @@ Item {
233 }
233 }
234 }
234 }
235 }
235 }
236+ Connections {
237+ target: SessionManager
238+ onSessionStopping: {
239+ if (!session.parentSession && !session.application) {
240+ // nothing is using it. delete it right away
241+ session.release();
242+ }
243+ }
244+ }
236
245
237 Lockscreen {
246 Lockscreen {
238 id: lockscreen
247 id: lockscreen
qml/Stages/Animations/BaseSurfaceAnimation.qml → qml/Stages/Animations/BaseSessionAnimation.qmlrenamed+23−20
@@ -37,57 +37,60 @@ import QtQuick 2.0
37 */
37 */
38Item {
38Item {
39 id: base
39 id: base
40− property Item surface: null
40+ property var container
41+ objectName: "sessionAnimation"
41
42
42− // changes applied when state changes to "in"
43+ // changes applied when state changes to "from"
43− property list<QtObject> outChanges
44+ property list<QtObject> fromChanges
44− // transition animations when changing state to "in"
45+ // transition animations when changing state to "from"
45− property list<QtObject> outAnimations
46+ property list<QtObject> fromAnimations
46
47
47− // changes applied when state changes to "out"
48+ // changes applied when state changes to "to"
48− property list<QtObject> inChanges
49+ property list<QtObject> toChanges
49− // transition animations when changing state to "out"
50+ // transition animations when changing state to "to"
50− property list<QtObject> inAnimations
51+ property list<QtObject> toAnimations
51
52
52 function start() {
53 function start() {
53− // "prep" state forces outChanges without transition animations.
54+ // "prep" state forces toChanges without transition animations.
54 state = "prep"
55 state = "prep"
55− state = "in";
56+ state = "to";
56 }
57 }
57 function end() {
58 function end() {
58− state = "out";
59+ state = "from";
59 }
60 }
60
61
62+ signal completed()
63+
61 states: [
64 states: [
62 State {
65 State {
63 name: "baseAnimation"
66 name: "baseAnimation"
64− PropertyChanges { target: base.surface; anchors.fill: undefined }
67+ PropertyChanges { target: container; anchors.fill: undefined }
65 },
68 },
66
69
67 State {
70 State {
68 name: "prep"
71 name: "prep"
69 extend: "baseAnimation"
72 extend: "baseAnimation"
70− changes: outChanges
73+ changes: fromChanges
71 },
74 },
72 State {
75 State {
73− name: "out"
76+ name: "from"
74 extend: "prep"
77 extend: "prep"
75 },
78 },
76 State {
79 State {
77 name: "in"
80 name: "in"
78 extend: "baseAnimation"
81 extend: "baseAnimation"
79− changes: inChanges
82+ changes: toChanges
80 }
83 }
81 ]
84 ]
82
85
83 transitions: [
86 transitions: [
84 Transition {
87 Transition {
85− to: "out"
88+ to: "from"
86− animations: outAnimations
89+ animations: fromAnimations
87 },
90 },
88 Transition {
91 Transition {
89− to: "in"
92+ to: "to"
90− animations: inAnimations
93+ animations: toAnimations
91 }
94 }
92 ]
95 ]
93}
96}
qml/Stages/Animations/DarkenAndFadeInAnimation.qmldeleted−48
@@ -1,48 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
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 General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−import Ubuntu.Components 1.1
19−
20−BaseSurfaceAnimation {
21− id: animation
22−
23− property Rectangle darkenItem: Rectangle {
24− parent: animation.surface.parent
25− anchors.fill: parent
26− color: Qt.rgba(0,0,0,0.0)
27− }
28−
29− outChanges: [ PropertyChanges { target: animation.surface; opacity: 0.0 } ]
30− outAnimations: [
31− SequentialAnimation {
32− UbuntuNumberAnimation { target: animation.surface; property: "opacity"; duration: UbuntuAnimation.FastDuration }
33− ColorAnimation { target: darkenItem; duration: UbuntuAnimation.FastDuration }
34− ScriptAction { script: { if (animation.parent.removing) animation.surface.release(); } }
35− }
36− ]
37−
38− inChanges: [
39− PropertyChanges { target: darkenItem; color: Qt.rgba(0,0,0,0.7) },
40− PropertyChanges { target: animation.surface; opacity: 1.0 }
41− ]
42− inAnimations: [
43− SequentialAnimation {
44− ColorAnimation { target: darkenItem; duration: UbuntuAnimation.FastDuration }
45− UbuntuNumberAnimation { target: animation.surface; property: "opacity"; duration: UbuntuAnimation.FastDuration }
46− }
47− ]
48−}
qml/Stages/Animations/SwipeFromBottomAnimation.qml+24−19
@@ -15,34 +15,39 @@
15 */
15 */
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18+import Ubuntu.Components 1.1
18
19
19−BaseSurfaceAnimation {
20+BaseSessionAnimation {
20 id: animation
21 id: animation
21
22
23+ fromChanges: [
24+ AnchorChanges {
25+ target: container;
22− outChanges: [ AnchorChanges { target: animation.surface; anchors.top: animation.parent.bottom } ]
26+ anchors.top: container.parent.bottom
23− outAnimations: [
27+ }
28+ ]
29+ fromAnimations: [
24 SequentialAnimation {
30 SequentialAnimation {
31+ // clip so we don't go out of parent's bounds during spread
25− PropertyAction { target: animation.parent; property: "clip"; value: true }
32+ PropertyAction { target: container.parent; property: "clip"; value: true }
26− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
33+ AnchorAnimation { easing: UbuntuAnimation.StandardEasing; duration: UbuntuAnimation.BriskDuration }
27− PropertyAction { target: animation.surface; property: "visible"; value: !animation.parent.removing }
28− PropertyAction { target: animation.parent; property: "clip"; value: false }
34+ PropertyAction { target: container.parent; property: "clip"; value: false }
29− ScriptAction { script: { if (animation.parent.removing) animation.surface.release(); } }
35+ ScriptAction { script: { animation.completed(); } }
30 }
36 }
31 ]
37 ]
32
38
33− inChanges: [
39+ toChanges: [
34 AnchorChanges {
40 AnchorChanges {
35− target: animation.surface;
41+ target: container;
36− anchors.top: animation.parent.top
42+ anchors.top: container.parent.top
37− anchors.right: undefined
38− anchors.bottom: undefined
39− anchors.left: undefined
40− } ]
43+ }
41− inAnimations: [
44+ ]
45+ toAnimations: [
42 SequentialAnimation {
46 SequentialAnimation {
47+ // clip so we don't go out of parent's bounds during spread
43− PropertyAction { target: animation.parent; property: "clip"; value: true }
48+ PropertyAction { target: container.parent; property: "clip"; value: true }
44− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
49+ AnchorAnimation { easing: UbuntuAnimation.StandardEasing; duration: UbuntuAnimation.BriskDuration }
45− PropertyAction { target: animation.parent; property: "clip"; value: false }
50+ PropertyAction { target: container.parent; property: "clip"; value: false }
46 }
51 }
47 ]
52 ]
48}
53}
qml/Stages/Animations/SwipeUpAnimation.qmldeleted−49
@@ -1,49 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
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 General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−
19−BaseSurfaceAnimation {
20− id: animation
21−
22− outAnimations: [
23− SequentialAnimation {
24− PropertyAction { target: animation.parent; property: "clip"; value: true }
25− PropertyAction { target: animation.surface; property: "visible"; value: true }
26− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
27− PropertyAction { target: animation.parent; property: "clip"; value: false }
28− ScriptAction { script: { if (animation.parent.removing) animation.surface.release(); } }
29− }
30− ]
31−
32− inChanges: [
33− AnchorChanges {
34− target: animation.surface;
35− anchors.top: undefined
36− anchors.right: undefined
37− anchors.bottom: animation.parent.top
38− anchors.left: undefined
39− }
40− ]
41− inAnimations: [
42− SequentialAnimation {
43− PropertyAction { target: animation.parent; property: "clip"; value: true }
44− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
45− PropertyAction { target: animation.surface; property: "visible"; value: false}
46− PropertyAction { target: animation.parent; property: "clip"; value: false }
47− }
48− ]
49−}
qml/Stages/ApplicationWindow.qml+50−71
@@ -23,9 +23,9 @@ Item {
23
23
24 // to be read from outside
24 // to be read from outside
25 readonly property bool fullscreen: application ? application.fullscreen : false
25 readonly property bool fullscreen: application ? application.fullscreen : false
26+ property alias interactive: sessionContainer.interactive
26
27
27 // to be set from outside
28 // to be set from outside
28− property bool interactive: true
29 property QtObject application
29 property QtObject application
30
30
31 QtObject {
31 QtObject {
@@ -35,16 +35,14 @@ Item {
35 // (in order to avoid breaking qml binding due to a javascript exception)
35 // (in order to avoid breaking qml binding due to a javascript exception)
36 readonly property string name: root.application ? root.application.name : ""
36 readonly property string name: root.application ? root.application.name : ""
37 readonly property url icon: root.application ? root.application.icon : ""
37 readonly property url icon: root.application ? root.application.icon : ""
38− readonly property Item surface: root.application ? root.application.surface : null
39 readonly property int applicationState: root.application ? root.application.state : -1
38 readonly property int applicationState: root.application ? root.application.state : -1
40− readonly property var promptSurfaces: root.application ? root.application.promptSurfaces : null
41
39
42 // Whether the Application had a surface before but lost it.
40 // Whether the Application had a surface before but lost it.
43− property bool hadSurface: false
41+ property bool hadSurface: sessionContainer.surfaceContainer.hadSurface
44
42
45 property bool needToTakeScreenshot:
43 property bool needToTakeScreenshot:
46− d.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
44+ sessionContainer.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
47− && d.applicationState === ApplicationInfo.Stopped
45+ && d.applicationState === ApplicationInfoInterface.Stopped
48 onNeedToTakeScreenshotChanged: {
46 onNeedToTakeScreenshotChanged: {
49 if (needToTakeScreenshot) {
47 if (needToTakeScreenshot) {
50 screenshotImage.take();
48 screenshotImage.take();
@@ -55,12 +53,12 @@ Item {
55 // might show the UI accommodating due to surface resizes on startup.
53 // might show the UI accommodating due to surface resizes on startup.
56 // Remove this when possible
54 // Remove this when possible
57 property bool surfaceInitialized: false
55 property bool surfaceInitialized: false
58− onSurfaceChanged: {
56+
57+ function forceSurfaceActiveFocusIfReady() {
59− if (surface) {
58+ if (sessionContainer.surface.focus &&
60− surfaceInitTimer.start();
59+ sessionContainer.surface.parent === sessionContainer.surfaceContainer &&
61− } else {
60+ sessionContainer.surface.enabled) {
62− hadSurface = true;
61+ sessionContainer.surface.forceActiveFocus();
63− surfaceInitialized = false;
64 }
62 }
65 }
63 }
66 }
64 }
@@ -68,40 +66,16 @@ Item {
68 Timer {
66 Timer {
69 id: surfaceInitTimer
67 id: surfaceInitTimer
70 interval: 100
68 interval: 100
71− onTriggered: { if (d.surface) {d.surfaceInitialized = true;} }
69+ onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
72 }
70 }
73
71
74− Binding {
75− target: d.surface
76− when: d.surface
77− property: "enabled"
78− value: root.interactive
79− }
80− Binding {
81− target: d.surface
82− when: d.surface
83− property: "focus"
84− value: root.interactive
85− }
86 Connections {
72 Connections {
87− target: d.surface
73+ target: sessionContainer.surface
88 // FIXME: I would rather not need to do this, but currently it doesn't get
74 // FIXME: I would rather not need to do this, but currently it doesn't get
89 // active focus without it and I don't know why.
75 // active focus without it and I don't know why.
90− onFocusChanged: forceSurfaceActiveFocusIfReady();
76+ onFocusChanged: d.forceSurfaceActiveFocusIfReady();
91− onParentChanged: forceSurfaceActiveFocusIfReady();
77+ onParentChanged: d.forceSurfaceActiveFocusIfReady();
92− onEnabledChanged: forceSurfaceActiveFocusIfReady();
78+ onEnabledChanged: d.forceSurfaceActiveFocusIfReady();
93− function forceSurfaceActiveFocusIfReady() {
94− if (d.surface.focus && d.surface.parent === surfaceContainer && d.surface.enabled) {
95− d.surface.forceActiveFocus();
96− }
97− }
98− }
99−
100− SurfaceContainer {
101− id: surfaceContainer
102− objectName: "surfaceContainer"
103− anchors.fill: parent
104− surface: d.surface
105 }
79 }
106
80
107 Image {
81 Image {
@@ -126,25 +100,24 @@ Item {
126 id: splashLoader
100 id: splashLoader
127 visible: active
101 visible: active
128 active: false
102 active: false
129− anchors.fill: surfaceContainer
103+ anchors.fill: parent
130 sourceComponent: Component {
104 sourceComponent: Component {
131 Splash { name: d.name; image: d.icon }
105 Splash { name: d.name; image: d.icon }
132 }
106 }
133 }
107 }
134
108
135− Repeater {
109+ SessionContainer {
136− model: d.promptSurfaces
110+ id: sessionContainer
137−
111+ session: application ? application.session : null
138− delegate: SurfaceContainer {
139− anchors {
112+ anchors.fill: parent
140− fill: surfaceContainer
141− }
142−
143− surface: modelData
144
113
145− Component.onCompleted: {
114+ onSurfaceChanged: {
146− animateIn();
115+ if (sessionContainer.surface) {
116+ surfaceInitTimer.start();
117+ } else {
118+ d.surfaceInitialized = false;
147 }
119 }
120+ d.forceSurfaceActiveFocusIfReady();
148 }
121 }
149 }
122 }
150
123
@@ -154,23 +127,23 @@ Item {
154 State {
127 State {
155 name: "void"
128 name: "void"
156 when:
129 when:
157− d.hadSurface && (!d.surface || !d.surfaceInitialized)
130+ d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
158 &&
131 &&
159 screenshotImage.status !== Image.Ready
132 screenshotImage.status !== Image.Ready
160 },
133 },
161 State {
134 State {
162 name: "splashScreen"
135 name: "splashScreen"
163 when:
136 when:
164− !d.hadSurface && (!d.surface || !d.surfaceInitialized)
137+ !d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
165 &&
138 &&
166 screenshotImage.status !== Image.Ready
139 screenshotImage.status !== Image.Ready
167 },
140 },
168 State {
141 State {
169 name: "surface"
142 name: "surface"
170 when:
143 when:
171− (d.surface && d.surfaceInitialized)
144+ (sessionContainer.surface && d.surfaceInitialized)
172 &&
145 &&
173− (d.applicationState !== ApplicationInfo.Stopped
146+ (d.applicationState !== ApplicationInfoInterface.Stopped
174 || screenshotImage.status !== Image.Ready)
147 || screenshotImage.status !== Image.Ready)
175 },
148 },
176 State {
149 State {
@@ -178,8 +151,8 @@ Item {
178 when:
151 when:
179 screenshotImage.status === Image.Ready
152 screenshotImage.status === Image.Ready
180 &&
153 &&
181− (d.applicationState === ApplicationInfo.Stopped
154+ (d.applicationState === ApplicationInfoInterface.Stopped
182− || !d.surface || !d.surfaceInitialized)
155+ || !sessionContainer.surface || !d.surfaceInitialized)
183 }
156 }
184 ]
157 ]
185
158
@@ -187,14 +160,18 @@ Item {
187 Transition {
160 Transition {
188 from: ""; to: "splashScreen"
161 from: ""; to: "splashScreen"
189 PropertyAction { target: splashLoader; property: "active"; value: true }
162 PropertyAction { target: splashLoader; property: "active"; value: true }
163+ PropertyAction { target: sessionContainer.surfaceContainer
164+ property: "visible"; value: false }
190 },
165 },
191 Transition {
166 Transition {
192 from: "splashScreen"; to: "surface"
167 from: "splashScreen"; to: "surface"
193 SequentialAnimation {
168 SequentialAnimation {
194− PropertyAction { target: surfaceContainer
169+ PropertyAction { target: sessionContainer.surfaceContainer
170+ property: "opacity"; value: 0.0 }
171+ PropertyAction { target: sessionContainer.surfaceContainer
195 property: "visible"; value: true }
172 property: "visible"; value: true }
196− UbuntuNumberAnimation { target: splashLoader; property: "opacity";
173+ UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
197− from: 1.0; to: 0.0
174+ from: 0.0; to: 1.0
198 duration: UbuntuAnimation.BriskDuration }
175 duration: UbuntuAnimation.BriskDuration }
199 PropertyAction { target: splashLoader; property: "active"; value: false }
176 PropertyAction { target: splashLoader; property: "active"; value: false }
200 }
177 }
@@ -203,11 +180,13 @@ Item {
203 from: "surface"; to: "splashScreen"
180 from: "surface"; to: "splashScreen"
204 SequentialAnimation {
181 SequentialAnimation {
205 PropertyAction { target: splashLoader; property: "active"; value: true }
182 PropertyAction { target: splashLoader; property: "active"; value: true }
206− PropertyAction { target: surfaceContainer
183+ PropertyAction { target: sessionContainer.surfaceContainer
207 property: "visible"; value: true }
184 property: "visible"; value: true }
208 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
185 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
209 from: 0.0; to: 1.0
186 from: 0.0; to: 1.0
210 duration: UbuntuAnimation.BriskDuration }
187 duration: UbuntuAnimation.BriskDuration }
188+ PropertyAction { target: sessionContainer.surfaceContainer
189+ property: "visible"; value: false }
211 }
190 }
212 },
191 },
213 Transition {
192 Transition {
@@ -218,15 +197,15 @@ Item {
218 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
197 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
219 from: 0.0; to: 1.0
198 from: 0.0; to: 1.0
220 duration: UbuntuAnimation.BriskDuration }
199 duration: UbuntuAnimation.BriskDuration }
221− PropertyAction { target: surfaceContainer
200+ PropertyAction { target: sessionContainer.surfaceContainer
222 property: "visible"; value: false }
201 property: "visible"; value: false }
223− ScriptAction { script: { if (d.surface) { d.surface.release(); } } }
202+ ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
224 }
203 }
225 },
204 },
226 Transition {
205 Transition {
227 from: "screenshot"; to: "surface"
206 from: "screenshot"; to: "surface"
228 SequentialAnimation {
207 SequentialAnimation {
229− PropertyAction { target: surfaceContainer
208+ PropertyAction { target: sessionContainer.surfaceContainer
230 property: "visible"; value: true }
209 property: "visible"; value: true }
231 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
210 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
232 from: 1.0; to: 0.0
211 from: 1.0; to: 0.0
@@ -238,16 +217,16 @@ Item {
238 Transition {
217 Transition {
239 from: "surface"; to: "void"
218 from: "surface"; to: "void"
240 SequentialAnimation {
219 SequentialAnimation {
241− PropertyAction { target: surfaceContainer; property: "visible"; value: false }
220+ PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: false }
242− ScriptAction { script: { if (d.surface) { d.surface.release(); } } }
221+ ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
243 }
222 }
244 },
223 },
245 Transition {
224 Transition {
246 from: "void"; to: "surface"
225 from: "void"; to: "surface"
247 SequentialAnimation {
226 SequentialAnimation {
248− PropertyAction { target: surfaceContainer; property: "opacity"; value: 0.0 }
227+ PropertyAction { target: sessionContainer.surfaceContainer; property: "opacity"; value: 0.0 }
249− PropertyAction { target: surfaceContainer; property: "visible"; value: true }
228+ PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: true }
250− UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
229+ UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
251 from: 0.0; to: 1.0
230 from: 0.0; to: 1.0
252 duration: UbuntuAnimation.BriskDuration }
231 duration: UbuntuAnimation.BriskDuration }
253 }
232 }
qml/Stages/SessionContainer.qmlnew file+143
@@ -0,0 +1,143 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+*/
16+
17+import QtQuick 2.0
18+import "Animations"
19+
20+Item {
21+ id: root
22+ objectName: "sessionContainer"
23+ property QtObject session
24+ readonly property var childSessions: session ? session.childSessions : null
25+ readonly property alias surface: _surfaceContainer.surface
26+ property bool interactive: true
27+
28+ readonly property alias surfaceContainer: _surfaceContainer
29+ SurfaceContainer {
30+ id: _surfaceContainer
31+ anchors.fill: parent
32+ surface: session ? session.surface : null
33+ }
34+
35+ Binding {
36+ target: surfaceContainer.surface
37+ when: surfaceContainer.surface
38+ property: "enabled"
39+ value: root.interactive
40+ }
41+ Binding {
42+ target: surfaceContainer.surface
43+ when: surfaceContainer.surface
44+ property: "focus"
45+ value: root.interactive
46+ }
47+
48+ Repeater {
49+ model: root.childSessions
50+
51+ delegate: Loader {
52+ objectName: "childDelegate" + index
53+ anchors.fill: surfaceContainer
54+
55+ // Only way to do recursive qml items.
56+ source: Qt.resolvedUrl("SessionContainer.qml")
57+
58+ Binding {
59+ target: item; when: item
60+ property: "interactive"; value: root.interactive
61+ }
62+
63+ Binding {
64+ target: item; when: item
65+ property: "session"; value: modelData
66+ }
67+
68+ Binding {
69+ target: item; when: item
70+ property: "width"; value: root.width
71+ }
72+
73+ Binding {
74+ target: item; when: item
75+ property: "height"; value: root.height
76+ }
77+ }
78+ }
79+
80+ states: [
81+ State {
82+ name: "rootSession"
83+ when: root.session && !root.session.parentSession
84+ },
85+
86+ State {
87+ name: "childSession"
88+ when: root.session && root.session.parentSession !== null && root.session.live
89+ && !root.session.surface
90+ },
91+
92+ State {
93+ name: "childSessionReady"
94+ when: root.session && root.session.parentSession !== null && root.session.live
95+ && root.session.surface !== null
96+ },
97+
98+ State {
99+ name: "childSessionZombie"
100+ when: root.session && root.session.parentSession !== null && !root.session.live
101+ }
102+ ]
103+
104+ transitions: [
105+ Transition {
106+ to: "childSessionReady"
107+ ScriptAction { script: { if (!surfaceContainer.hadSurface) { animateIn(swipeFromBottom); } } }
108+ },
109+ Transition {
110+ to: "childSessionZombie"
111+ ScriptAction { script: { animateOut(); } }
112+ }
113+ ]
114+
115+ function animateIn(component) {
116+ var animation = component.createObject(root, { "container": root, });
117+ animation.start();
118+
119+ var tmp = d.animations;
120+ tmp.push(animation);
121+ d.animations = tmp;
122+ }
123+
124+ function animateOut() {
125+ if (d.animations.length > 0) {
126+ var tmp = d.animations;
127+ var popped = tmp.pop();
128+ popped.completed.connect(function() { root.session.release(); } );
129+ popped.end();
130+ d.animations = tmp;
131+ }
132+ }
133+
134+ Component {
135+ id: swipeFromBottom
136+ SwipeFromBottomAnimation {}
137+ }
138+
139+ QtObject {
140+ id: d
141+ property var animations: []
142+ }
143+}
qml/Stages/SurfaceContainer.qml+22−67
@@ -15,86 +15,41 @@
15*/
15*/
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18−import "Animations"
18+import Ubuntu.Components 1.1
19
19
20Item {
20Item {
21− id: container
21+ id: root
22+ objectName: "surfaceContainer"
22 property Item surface: null
23 property Item surface: null
23− property bool removing: false
24+ property bool hadSurface: false
24
25
25 onSurfaceChanged: {
26 onSurfaceChanged: {
26 if (surface) {
27 if (surface) {
27− surface.parent = container;
28+ surface.parent = root;
28− surface.z = 1;
29+ } else {
30+ hadSurface = true;
29 }
31 }
30 }
32 }
31 Binding {
33 Binding {
32 target: surface
34 target: surface
33− property: "anchors.fill"; value: container
35+ property: "anchors.fill"; value: root
34 }
36 }
35
37
36− Connections {
38+ states: [
37− target: surface
39+ State {
38− onRemoved: {
40+ name: "zombie"
39− container.removing = true;
41+ when: surface && !surface.live
40−
41− var childSurfaces = surface.childSurfaces;
42− for (var i=0; i<childSurfaces.length; i++) {
43− childSurfaces[i].removed();
44− }
45−
46− animateOut();
47 }
42 }
48− }
43+ ]
49−
44+ transitions: [
50− Repeater {
45+ Transition {
51− model: surface ? surface.childSurfaces : null
46+ from: ""; to: "zombie"
52−
47+ SequentialAnimation {
53− delegate: Loader {
48+ UbuntuNumberAnimation { target: surface; property: "opacity"; to: 0.0
54− z: 2
49+ duration: UbuntuAnimation.BriskDuration }
55− anchors {
50+ PropertyAction { target: surface; property: "visible"; value: false }
56− fill: container
51+ ScriptAction { script: { if (root.surface) { root.surface.release(); } } }
57− topMargin: container.surface.anchors.topMargin
58− rightMargin: container.surface.anchors.rightMargin
59− bottomMargin: container.surface.anchors.bottomMargin
60− leftMargin: container.surface.anchors.leftMargin
61 }
52 }
62−
63− // Only way to do recursive qml items.
64− source: Qt.resolvedUrl("SurfaceContainer.qml")
65− onLoaded: {
66− item.surface = modelData;
67− item.animateIn();
68− }
69− }
70− }
71−
72− function animateIn() {
73− var animation = swipeFromBottom.createObject(container, { "surface": container.surface });
74− animation.start();
75−
76− var tmp = d.animations;
77− tmp.push(animation);
78− d.animations = tmp;
79− }
80−
81− function animateOut() {
82− if (d.animations.length > 0) {
83− var tmp = d.animations;
84− var popped = tmp.pop();
85− popped.end();
86− d.animations = tmp;
87 }
53 }
88− }
54+ ]
89−
90− QtObject {
91− id: d
92− property var animations: []
93− property var currentAnimation: animations.length > 0 ? animations[animations.length-1] : undefined
94− }
95−
96− Component {
97− id: swipeFromBottom
98− SwipeFromBottomAnimation {}
99− }
100}
55}
tests/mocks/AccountsService/AccountsService.qmltypes+1
@@ -26,5 +26,6 @@ Module {
26 Property { name: "backgroundFile"; type: "string" }
26 Property { name: "backgroundFile"; type: "string" }
27 Property { name: "statsWelcomeScreen"; type: "bool" }
27 Property { name: "statsWelcomeScreen"; type: "bool" }
28 Property { name: "passwordDisplayHint"; type: "PasswordDisplayHint"; isReadonly: true }
28 Property { name: "passwordDisplayHint"; type: "PasswordDisplayHint"; isReadonly: true }
29+ Property { name: "failedLogins"; type: "uint" }
29 }
30 }
30}
31}
tests/mocks/LightDM/LightDM.qmltypes+2
@@ -27,6 +27,7 @@ Module {
27 name: "showPrompt"
27 name: "showPrompt"
28 Parameter { name: "text"; type: "string" }
28 Parameter { name: "text"; type: "string" }
29 Parameter { name: "isSecret"; type: "bool" }
29 Parameter { name: "isSecret"; type: "bool" }
30+ Parameter { name: "isDefaultPrompt"; type: "bool" }
30 }
31 }
31 Signal { name: "authenticationComplete" }
32 Signal { name: "authenticationComplete" }
32 Signal {
33 Signal {
@@ -34,6 +35,7 @@ Module {
34 Parameter { name: "user"; type: "string" }
35 Parameter { name: "user"; type: "string" }
35 }
36 }
36 Signal { name: "isActiveChanged" }
37 Signal { name: "isActiveChanged" }
38+ Signal { name: "isAuthenticatedChanged" }
37 Signal { name: "showGreeter" }
39 Signal { name: "showGreeter" }
38 Signal {
40 Signal {
39 name: "requestAuthenticationUser"
41 name: "requestAuthenticationUser"
tests/mocks/Ubuntu/SystemImage/SystemImage.qmltypes+3−1
@@ -4,13 +4,15 @@ import QtQuick.tooling 1.1
4// It is used for QML tooling purposes only.
4// It is used for QML tooling purposes only.
5//
5//
6// This file was auto-generated by:
6// This file was auto-generated by:
7−// 'qmlplugindump -notrelocatable Ubuntu.SystemImage 0.1 plugins'
7+// 'qmlplugindump -notrelocatable Ubuntu.SystemImage 0.1 tests/mocks'
8
8
9Module {
9Module {
10 Component {
10 Component {
11 name: "MockSystemImage"
11 name: "MockSystemImage"
12 prototype: "QObject"
12 prototype: "QObject"
13 exports: ["Ubuntu.SystemImage/SystemImage 0.1"]
13 exports: ["Ubuntu.SystemImage/SystemImage 0.1"]
14+ isCreatable: false
15+ isSingleton: true
14 exportMetaObjectRevisions: [0]
16 exportMetaObjectRevisions: [0]
15 Signal { name: "resettingDevice" }
17 Signal { name: "resettingDevice" }
16 Method { name: "factoryReset" }
18 Method { name: "factoryReset" }
tests/mocks/Unity/Application/Application.qmltypes+115−70
@@ -13,58 +13,24 @@ Module {
13 exports: ["Unity.Application/ApplicationInfo 0.1"]
13 exports: ["Unity.Application/ApplicationInfo 0.1"]
14 exportMetaObjectRevisions: [0]
14 exportMetaObjectRevisions: [0]
15 Property { name: "fullscreen"; type: "bool" }
15 Property { name: "fullscreen"; type: "bool" }
16− Property { name: "stage"; type: "Stage" }
17− Property { name: "surface"; type: "MirSurfaceItem"; isReadonly: true; isPointer: true }
16+ Property { name: "session"; type: "Session"; isReadonly: true; isPointer: true }
18− Property { name: "promptSurfaces"; type: "MirSurfaceItem"; isList: true; isReadonly: true }
17+ Property { name: "manualSurfaceCreation"; type: "bool" }
19− Property { name: "imageQml"; type: "string" }
20− Property { name: "windowQml"; type: "string" }
21− Signal {
22− name: "appIdChanged"
23− Parameter { type: "string" }
24− }
25− Signal {
26− name: "nameChanged"
27− Parameter { type: "string" }
28− }
29− Signal {
30− name: "commentChanged"
31− Parameter { type: "string" }
32− }
33− Signal {
34− name: "iconChanged"
35− Parameter { type: "QUrl" }
36− }
37 Signal {
18 Signal {
38− name: "stageChanged"
19+ name: "sessionChanged"
39− Parameter { type: "Stage" }
20+ Parameter { type: "Session"; isPointer: true }
40− }
41− Signal {
42− name: "stateChanged"
43− Parameter { type: "State" }
44− }
45− Signal {
46− name: "focusedChanged"
47− Parameter { type: "bool" }
48 }
21 }
49 Signal {
22 Signal {
50 name: "fullscreenChanged"
23 name: "fullscreenChanged"
51− Parameter { type: "bool" }
24+ Parameter { name: "value"; type: "bool" }
52− }
53− Signal {
54− name: "imageQmlChanged"
55− Parameter { type: "string" }
56− }
57− Signal {
58− name: "windowQmlChanged"
59− Parameter { type: "string" }
60 }
25 }
61 Signal {
26 Signal {
62− name: "screenshotChanged"
27+ name: "manualSurfaceCreationChanged"
63− Parameter { type: "QUrl" }
28+ Parameter { name: "value"; type: "bool" }
64 }
29 }
65− Signal {
30+ Method { name: "createSession" }
66− name: "surfaceChanged"
31+ Method {
67− Parameter { type: "MirSurfaceItem"; isPointer: true }
32+ name: "setState"
33+ Parameter { name: "value"; type: "State" }
68 }
34 }
69 }
35 }
70 Component {
36 Component {
@@ -198,17 +164,50 @@ Module {
198 type: "bool"
164 type: "bool"
199 Parameter { name: "appId"; type: "string" }
165 Parameter { name: "appId"; type: "string" }
200 }
166 }
167+ Method { name: "availableApplications"; type: "QStringList" }
201 Method {
168 Method {
202− name: "updateScreenshot"
169+ name: "add"
203− type: "bool"
170+ type: "ApplicationInfo*"
204 Parameter { name: "appId"; type: "string" }
171 Parameter { name: "appId"; type: "string" }
205 }
172 }
206− Method { name: "availableApplications"; type: "QStringList" }
173+ }
174+ Component {
175+ name: "ApplicationTestInterface"
176+ prototype: "QDBusAbstractAdaptor"
177+ exports: ["Unity.Application/ApplicationTest 0.1"]
178+ isCreatable: false
179+ isSingleton: true
180+ exportMetaObjectRevisions: [0]
181+ Method {
182+ name: "addChildSession"
183+ type: "uint"
184+ Parameter { name: "appId"; type: "string" }
185+ Parameter { name: "existingSessionId"; type: "uint" }
186+ Parameter { name: "surfaceImage"; type: "string" }
187+ }
188+ Method {
189+ name: "removeSession"
190+ Parameter { name: "sessionId"; type: "uint" }
191+ }
192+ Method {
193+ name: "addChildSession"
194+ type: "Session*"
195+ Parameter { name: "existingSession"; type: "Session"; isPointer: true }
196+ Parameter { name: "surfaceImage"; type: "string" }
197+ }
198+ Method {
199+ name: "removeSession"
200+ Parameter { name: "existingSession"; type: "Session"; isPointer: true }
201+ }
202+ Method {
203+ name: "removeSurface"
204+ Parameter { name: "existingSurface"; type: "MirSurfaceItem"; isPointer: true }
205+ }
207 }
206 }
208 Component {
207 Component {
209 name: "MirSurfaceItem"
208 name: "MirSurfaceItem"
210 defaultProperty: "data"
209 defaultProperty: "data"
211− prototype: "QQuickPaintedItem"
210+ prototype: "QQuickItem"
212 exports: ["Unity.Application/MirSurfaceItem 0.1"]
211 exports: ["Unity.Application/MirSurfaceItem 0.1"]
213 isCreatable: false
212 isCreatable: false
214 exportMetaObjectRevisions: [0]
213 exportMetaObjectRevisions: [0]
@@ -238,8 +237,7 @@ Module {
238 Property { name: "type"; type: "Type"; isReadonly: true }
237 Property { name: "type"; type: "Type"; isReadonly: true }
239 Property { name: "state"; type: "State"; isReadonly: true }
238 Property { name: "state"; type: "State"; isReadonly: true }
240 Property { name: "name"; type: "string"; isReadonly: true }
239 Property { name: "name"; type: "string"; isReadonly: true }
241− Property { name: "parentSurface"; type: "MirSurfaceItem"; isReadonly: true; isPointer: true }
240+ Property { name: "live"; type: "bool"; isReadonly: true }
242− Property { name: "childSurfaces"; type: "MirSurfaceItem"; isList: true; isReadonly: true }
243 Signal {
241 Signal {
244 name: "typeChanged"
242 name: "typeChanged"
245 Parameter { type: "Type" }
243 Parameter { type: "Type" }
@@ -249,22 +247,72 @@ Module {
249 Parameter { type: "State" }
247 Parameter { type: "State" }
250 }
248 }
251 Signal {
249 Signal {
252− name: "nameChanged"
250+ name: "liveChanged"
253− Parameter { type: "string" }
251+ Parameter { name: "live"; type: "bool" }
254− }
255− Signal {
256− name: "parentSurfaceChanged"
257− Parameter { type: "MirSurfaceItem"; isPointer: true }
258 }
252 }
259− Signal { name: "removed" }
260 Signal { name: "inputMethodRequested" }
253 Signal { name: "inputMethodRequested" }
261 Signal { name: "inputMethodDismissed" }
254 Signal { name: "inputMethodDismissed" }
255+ Signal { name: "deregister" }
262 Method {
256 Method {
263 name: "setState"
257 name: "setState"
264 Parameter { name: "newState"; type: "State" }
258 Parameter { name: "newState"; type: "State" }
265 }
259 }
266 Method { name: "release" }
260 Method { name: "release" }
267 }
261 }
262+ Component { name: "QDBusAbstractAdaptor"; prototype: "QObject" }
263+ Component {
264+ name: "Session"
265+ prototype: "QObject"
266+ exports: ["Unity.Application/Session 0.1"]
267+ isCreatable: false
268+ exportMetaObjectRevisions: [0]
269+ Property { name: "name"; type: "string"; isReadonly: true }
270+ Property { name: "surface"; type: "MirSurfaceItem"; isReadonly: true; isPointer: true }
271+ Property { name: "parentSession"; type: "Session"; isReadonly: true; isPointer: true }
272+ Property { name: "childSessions"; type: "SessionModel"; isReadonly: true; isPointer: true }
273+ Property { name: "live"; type: "bool"; isReadonly: true }
274+ Signal {
275+ name: "surfaceChanged"
276+ Parameter { type: "MirSurfaceItem"; isPointer: true }
277+ }
278+ Signal {
279+ name: "parentSessionChanged"
280+ Parameter { type: "Session"; isPointer: true }
281+ }
282+ Signal {
283+ name: "liveChanged"
284+ Parameter { name: "live"; type: "bool" }
285+ }
286+ Signal { name: "deregister" }
287+ Method { name: "createSurface" }
288+ Method { name: "release" }
289+ Method {
290+ name: "addChildSession"
291+ Parameter { name: "session"; type: "Session"; isPointer: true }
292+ }
293+ }
294+ Component {
295+ name: "SessionManager"
296+ prototype: "QObject"
297+ exports: ["Unity.Application/SessionManager 0.1"]
298+ isCreatable: false
299+ isSingleton: true
300+ exportMetaObjectRevisions: [0]
301+ Signal {
302+ name: "sessionStarting"
303+ Parameter { name: "session"; type: "Session"; isPointer: true }
304+ }
305+ Signal {
306+ name: "sessionStopping"
307+ Parameter { name: "session"; type: "Session"; isPointer: true }
308+ }
309+ Method {
310+ name: "createSession"
311+ type: "Session*"
312+ Parameter { name: "name"; type: "string" }
313+ Parameter { name: "screenshot"; type: "QUrl" }
314+ }
315+ }
268 Component {
316 Component {
269 name: "SurfaceManager"
317 name: "SurfaceManager"
270 prototype: "QObject"
318 prototype: "QObject"
@@ -281,6 +329,14 @@ Module {
281 name: "surfaceDestroyed"
329 name: "surfaceDestroyed"
282 Parameter { name: "surface"; type: "MirSurfaceItem"; isPointer: true }
330 Parameter { name: "surface"; type: "MirSurfaceItem"; isPointer: true }
283 }
331 }
332+ Method {
333+ name: "createSurface"
334+ type: "MirSurfaceItem*"
335+ Parameter { name: "name"; type: "string" }
336+ Parameter { name: "type"; type: "MirSurfaceItem::Type" }
337+ Parameter { name: "state"; type: "MirSurfaceItem::State" }
338+ Parameter { name: "screenshot"; type: "QUrl" }
339+ }
284 Method { name: "inputMethodSurface"; type: "MirSurfaceItem*" }
340 Method { name: "inputMethodSurface"; type: "MirSurfaceItem*" }
285 }
341 }
286 Component {
342 Component {
@@ -312,7 +368,6 @@ Module {
312 Property { name: "stage"; type: "Stage"; isReadonly: true }
368 Property { name: "stage"; type: "Stage"; isReadonly: true }
313 Property { name: "state"; type: "State"; isReadonly: true }
369 Property { name: "state"; type: "State"; isReadonly: true }
314 Property { name: "focused"; type: "bool"; isReadonly: true }
370 Property { name: "focused"; type: "bool"; isReadonly: true }
315− Property { name: "screenshot"; type: "QUrl"; isReadonly: true }
316 Signal {
371 Signal {
317 name: "nameChanged"
372 name: "nameChanged"
318 Parameter { name: "name"; type: "string" }
373 Parameter { name: "name"; type: "string" }
@@ -337,10 +392,6 @@ Module {
337 name: "focusedChanged"
392 name: "focusedChanged"
338 Parameter { name: "focused"; type: "bool" }
393 Parameter { name: "focused"; type: "bool" }
339 }
394 }
340− Signal {
341− name: "screenshotChanged"
342− Parameter { name: "screenshot"; type: "QUrl" }
343− }
344 }
395 }
345 Component {
396 Component {
346 name: "unity::shell::application::ApplicationManagerInterface"
397 name: "unity::shell::application::ApplicationManagerInterface"
@@ -357,8 +408,7 @@ Module {
357 "RoleIcon": 259,
408 "RoleIcon": 259,
358 "RoleStage": 260,
409 "RoleStage": 260,
359 "RoleState": 261,
410 "RoleState": 261,
360− "RoleFocused": 262,
411+ "RoleFocused": 262
361− "RoleScreenshot": 263
362 }
412 }
363 }
413 }
364 Property { name: "count"; type: "int"; isReadonly: true }
414 Property { name: "count"; type: "int"; isReadonly: true }
@@ -408,10 +458,5 @@ Module {
408 type: "bool"
458 type: "bool"
409 Parameter { name: "appId"; type: "string" }
459 Parameter { name: "appId"; type: "string" }
410 }
460 }
411− Method {
412− name: "updateScreenshot"
413− type: "bool"
414− Parameter { name: "appId"; type: "string" }
415− }
416 }
461 }
417}
462}
tests/mocks/Unity/Application/ApplicationDBusAdaptor.cppdeleted−81
@@ -1,81 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
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 General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "ApplicationInfo.h"
18−#include "ApplicationDBusAdaptor.h"
19−#include "ApplicationManager.h"
20−#include "SurfaceManager.h"
21−#include "MirSurfaceItem.h"
22−
23−quint32 nextId = 0;
24−
25−ApplicationDBusAdaptor::ApplicationDBusAdaptor(ApplicationManager* applicationManager)
26− : QDBusAbstractAdaptor(applicationManager)
27− , m_applicationManager(applicationManager)
28−{
29−}
30−
31−MirSurfaceItem* topSurface(MirSurfaceItem* surface)
32−{
33− if (!surface)
34− return nullptr;
35−
36− MirSurfaceItem* child = nullptr;
37− Q_FOREACH (MirSurfaceItem *childSurface, surface->childSurfaceList()) {
38− child = topSurface(childSurface);
39− if (child) {
40− break;
41− }
42− }
43− return child ? child : surface;
44−}
45−
46−quint32 ApplicationDBusAdaptor::addPromptSurface(const QString &appId, const QString &surfaceImage)
47−{
48− qDebug() << "ApplicationDBusAdaptor::addPromptSurface to " << appId;
49−
50− ApplicationInfo* application = m_applicationManager->findApplication(appId);
51− if (!application) {
52− qDebug() << "ApplicationDBusAdaptor::addChildSurface - No application found for " << appId;
53− return 0;
54− }
55− quint32 surfaceId = ++nextId;
56− MirSurfaceItem* surface = new MirSurfaceItem(QString("%1-ChildSurface%2").arg(appId).arg(surfaceId),
57− MirSurfaceItem::Normal,
58− MirSurfaceItem::Maximized,
59− QUrl(surfaceImage));
60− m_childItems[surfaceId] = surface;
61−
62− if (application->promptSurfaceList().count() > 0) {
63− surface->setParentSurface(topSurface(application->promptSurfaceList()[0]));
64− } else {
65− application->addPromptSurface(surface);
66− }
67−
68− return surfaceId;
69−}
70−
71−void ApplicationDBusAdaptor::removeChildSurface(int surfaceId)
72−{
73− qDebug() << "ApplicationDBusAdaptor::removeChildSurface - " << surfaceId;
74−
75− if (!m_childItems.contains(surfaceId)) {
76− qDebug() << "ApplicationDBusAdaptor::removeChildSurface - No added surface for " << surfaceId;
77− return;
78− }
79− MirSurfaceItem* surface = m_childItems.take(surfaceId);
80− Q_EMIT surface->removed();
81−}
tests/mocks/Unity/Application/ApplicationInfo.cpp+36−85
@@ -15,8 +15,8 @@
15 */
15 */
16
16
17#include "ApplicationInfo.h"
17#include "ApplicationInfo.h"
18−#include "MirSurfaceItem.h"
18+#include "Session.h"
19−#include "SurfaceManager.h"
19+#include "SessionManager.h"
20
20
21#include <paths.h>
21#include <paths.h>
22
22
@@ -33,9 +33,8 @@ ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
33 , m_state(Starting)
33 , m_state(Starting)
34 , m_focused(false)
34 , m_focused(false)
35 , m_fullscreen(false)
35 , m_fullscreen(false)
36− , m_surface(0)
36+ , m_session(0)
37 , m_manualSurfaceCreation(false)
37 , m_manualSurfaceCreation(false)
38− , m_parentItem(0)
39{
38{
40}
39}
41
40
@@ -45,107 +44,50 @@ ApplicationInfo::ApplicationInfo(QObject *parent)
45 , m_state(Starting)
44 , m_state(Starting)
46 , m_focused(false)
45 , m_focused(false)
47 , m_fullscreen(false)
46 , m_fullscreen(false)
48− , m_surface(0)
47+ , m_session(0)
49 , m_manualSurfaceCreation(false)
48 , m_manualSurfaceCreation(false)
50− , m_parentItem(0)
51{
49{
52}
50}
53
51
54ApplicationInfo::~ApplicationInfo()
52ApplicationInfo::~ApplicationInfo()
55{
53{
56− if (m_surface) {
54+ delete m_session;
57− Q_EMIT SurfaceManager::singleton()->surfaceDestroyed(m_surface);
58− m_surface->deleteLater();
59− setSurface(nullptr);
60− }
61}
55}
62
56
63−void ApplicationInfo::createSurface()
57+void ApplicationInfo::createSession()
64{
58{
65− if (m_surface || state() == ApplicationInfo::Stopped) return;
59+ if (m_session || state() == ApplicationInfo::Stopped) { return; }
66
60
67 QUrl screenshotUrl = QString("file://%1").arg(m_screenshotFileName);
61 QUrl screenshotUrl = QString("file://%1").arg(m_screenshotFileName);
68−
62+ setSession(SessionManager::singleton()->createSession(appId(), screenshotUrl));
69− setSurface(new MirSurfaceItem(name(),
70− MirSurfaceItem::Normal,
71− fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
72− screenshotUrl));
73}
63}
74
64
75−void ApplicationInfo::setSurface(MirSurfaceItem* surface)
65+void ApplicationInfo::setSession(Session* session)
76{
66{
77− qDebug() << "Application::setSurface - appId=" << appId() << "surface=" << surface;
67+ qDebug() << "Application::setSession - appId=" << appId() << "session=" << session;
78− if (m_surface == surface)
68+ if (m_session == session)
79 return;
69 return;
80
70
81− if (m_surface) {
71+ if (m_session) {
82− m_surface->setApplication(nullptr);
72+ disconnect(this, 0, m_session, 0);
83− m_surface->setParent(nullptr);
84− SurfaceManager::singleton()->unregisterSurface(m_surface);
85− }
86−
87− m_surface = surface;
88−
89− if (m_surface) {
90− m_surface->setApplication(this);
73+ m_session->setApplication(nullptr);
91− m_surface->setParent(this);
74+ m_session->setParent(nullptr);
92− SurfaceManager::singleton()->registerSurface(m_surface);
75+ Q_EMIT m_session->deregister();
93 }
76 }
94
77
95− Q_EMIT surfaceChanged(m_surface);
78+ m_session = session;
96− SurfaceManager::singleton()->registerSurface(m_surface);
97−}
98
79
99−void ApplicationInfo::addPromptSurface(MirSurfaceItem* surface)
80+ if (m_session) {
100−{
81+ m_session->setApplication(this);
101− qDebug() << "ApplicationInfo::addPromptSurface " << surface->name() << " to " << name();
82+ m_session->setParent(this);
102− if (surface == m_surface || m_promptSurfaces.contains(surface)) return;
83+ SessionManager::singleton()->registerSession(m_session);
103
84
104− surface->setApplication(this);
85+ if (!m_manualSurfaceCreation) {
105− m_promptSurfaces.append(surface);
86+ QTimer::singleShot(500, m_session, SLOT(createSurface()));
106− Q_EMIT promptSurfacesChanged();
87+ }
107−}
108−
109−void ApplicationInfo::removeSurface(MirSurfaceItem* surface)
110−{
111− if (m_surface == surface) {
112− setSurface(nullptr);
113− } else if (m_promptSurfaces.contains(surface)) {
114− qDebug() << "Application::removeSurface " << surface->name() << " from " << name();
115−
116− m_promptSurfaces.removeAll(surface);
117− surface->setApplication(nullptr);
118−
119− Q_EMIT promptSurfacesChanged();
120 }
88 }
121−}
122
89
123−QList<MirSurfaceItem*> ApplicationInfo::promptSurfaceList() const
90+ Q_EMIT sessionChanged(m_session);
124−{
125− return m_promptSurfaces;
126−}
127−
128−QQmlListProperty<MirSurfaceItem> ApplicationInfo::promptSurfaces()
129−{
130− return QQmlListProperty<MirSurfaceItem>(this,
131− 0,
132− ApplicationInfo::promptSurfaceCount,
133− ApplicationInfo::promptSurfaceAt);
134−}
135−
136−int ApplicationInfo::promptSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop)
137−{
138− ApplicationInfo *p = qobject_cast<ApplicationInfo*>(prop->object);
139− return p->m_promptSurfaces.count();
140−}
141−
142−MirSurfaceItem* ApplicationInfo::promptSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index)
143−{
144− ApplicationInfo *p = qobject_cast<ApplicationInfo*>(prop->object);
145−
146− if (index < 0 || index >= p->m_promptSurfaces.count())
147− return nullptr;
148− return p->m_promptSurfaces[index];
149}
91}
150
92
151void ApplicationInfo::setIconId(const QString &iconId)
93void ApplicationInfo::setIconId(const QString &iconId)
@@ -157,9 +99,18 @@ void ApplicationInfo::setIconId(const QString &iconId)
157
99
158void ApplicationInfo::setScreenshotId(const QString &screenshotId)
100void ApplicationInfo::setScreenshotId(const QString &screenshotId)
159{
101{
160− m_screenshotFileName = QString("%1/Dash/graphics/phone/screenshots/%2@12.png")
102+ QString screenshotFileName = QString("%1/Dash/graphics/phone/screenshots/%2@12.png")
161 .arg(qmlDirectory())
103 .arg(qmlDirectory())
162 .arg(screenshotId);
104 .arg(screenshotId);
105+
106+ if (screenshotFileName != m_screenshotFileName) {
107+ m_screenshotFileName = screenshotFileName;
108+
109+ QUrl screenshotUrl = QString("file://%1").arg(m_screenshotFileName);
110+ if (m_session) {
111+ m_session->setScreenshot(screenshotUrl);
112+ }
113+ }
163}
114}
164
115
165void ApplicationInfo::setName(const QString &value)
116void ApplicationInfo::setName(const QString &value)
@@ -193,7 +144,7 @@ void ApplicationInfo::setState(State value)
193 Q_EMIT stateChanged(value);
144 Q_EMIT stateChanged(value);
194
145
195 if (!m_manualSurfaceCreation && m_state == ApplicationInfo::Running) {
146 if (!m_manualSurfaceCreation && m_state == ApplicationInfo::Running) {
196− QTimer::singleShot(1000, this, SLOT(createSurface()));
147+ QTimer::singleShot(500, this, SLOT(createSession()));
197 }
148 }
198 }
149 }
199}
150}
tests/mocks/Unity/Application/ApplicationInfo.h+11−23
@@ -17,8 +17,10 @@
17#ifndef APPLICATION_H
17#ifndef APPLICATION_H
18#define APPLICATION_H
18#define APPLICATION_H
19
19
20+#include "SurfaceManager.h"
21+#include "MirSurfaceItemModel.h"
22+
20#include <QObject>
23#include <QObject>
21−#include <QQmlComponent>
22
24
23class QQuickItem;
25class QQuickItem;
24class MirSurfaceItem;
26class MirSurfaceItem;
@@ -32,8 +34,7 @@ class ApplicationInfo : public ApplicationInfoInterface {
32 Q_OBJECT
34 Q_OBJECT
33
35
34 Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
36 Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
35− Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
37+ Q_PROPERTY(Session* session READ session NOTIFY sessionChanged)
36− Q_PROPERTY(QQmlListProperty<MirSurfaceItem> promptSurfaces READ promptSurfaces NOTIFY promptSurfacesChanged DESIGNABLE false)
37
38
38 // Only exists in this fake implementation
39 // Only exists in this fake implementation
39
40
@@ -72,32 +73,23 @@ public:
72 void setFullscreen(bool value);
73 void setFullscreen(bool value);
73 bool fullscreen() const { return m_fullscreen; }
74 bool fullscreen() const { return m_fullscreen; }
74
75
75− void setSurface(MirSurfaceItem* surface);
76− MirSurfaceItem* surface() const { return m_surface; }
77−
78− void removeSurface(MirSurfaceItem* surface);
79−
80− void addPromptSurface(MirSurfaceItem* surface);
81− QList<MirSurfaceItem*> promptSurfaceList() const;
82− QQmlListProperty<MirSurfaceItem> promptSurfaces();
83−
84 bool manualSurfaceCreation() const { return m_manualSurfaceCreation; }
76 bool manualSurfaceCreation() const { return m_manualSurfaceCreation; }
85 void setManualSurfaceCreation(bool value);
77 void setManualSurfaceCreation(bool value);
86
78
79+public:
80+ void setSession(Session* session);
81+ Session* session() const { return m_session; }
82+
87Q_SIGNALS:
83Q_SIGNALS:
88− void surfaceChanged(MirSurfaceItem*);
84+ void sessionChanged(Session*);
89− void promptSurfacesChanged();
90 void fullscreenChanged(bool value);
85 void fullscreenChanged(bool value);
91 void manualSurfaceCreationChanged(bool value);
86 void manualSurfaceCreationChanged(bool value);
92
87
93public Q_SLOTS:
88public Q_SLOTS:
94− Q_INVOKABLE void createSurface();
89+ Q_INVOKABLE void createSession();
95
90
96private:
91private:
97− static int promptSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop);
98− static MirSurfaceItem* promptSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index);
99 void setIcon(const QUrl &value);
92 void setIcon(const QUrl &value);
100− void setScreenshot(const QUrl &value);
101
93
102 QString m_screenshotFileName;
94 QString m_screenshotFileName;
103
95
@@ -108,15 +100,11 @@ private:
108 State m_state;
100 State m_state;
109 bool m_focused;
101 bool m_focused;
110 bool m_fullscreen;
102 bool m_fullscreen;
111− MirSurfaceItem* m_surface;
103+ Session* m_session;
112
104
113 bool m_manualSurfaceCreation;
105 bool m_manualSurfaceCreation;
114−
115− QQuickItem *m_parentItem;
116− QList<MirSurfaceItem*> m_promptSurfaces;
117};
106};
118
107
119Q_DECLARE_METATYPE(ApplicationInfo*)
108Q_DECLARE_METATYPE(ApplicationInfo*)
120−Q_DECLARE_METATYPE(QQmlListProperty<MirSurfaceItem>)
121
109
122#endif // APPLICATION_H
110#endif // APPLICATION_H
tests/mocks/Unity/Application/ApplicationManager.cpp+9−16
@@ -15,9 +15,9 @@
15 */
15 */
16
16
17#include "ApplicationManager.h"
17#include "ApplicationManager.h"
18−#include "ApplicationDBusAdaptor.h"
19#include "ApplicationInfo.h"
18#include "ApplicationInfo.h"
20−#include "MirSurfaceItem.h"
19+#include "Session.h"
20+#include "ApplicationTestInterface.h"
21
21
22#include <paths.h>
22#include <paths.h>
23
23
@@ -36,11 +36,6 @@ ApplicationManager *ApplicationManager::singleton()
36{
36{
37 if (!the_application_manager) {
37 if (!the_application_manager) {
38 the_application_manager = new ApplicationManager();
38 the_application_manager = new ApplicationManager();
39− new ApplicationDBusAdaptor(the_application_manager);
40−
41− QDBusConnection connection = QDBusConnection::sessionBus();
42− connection.registerService("com.canonical.Unity8");
43− connection.registerObject("/com/canonical/Unity8/Mocks", the_application_manager);
44 }
39 }
45 return the_application_manager;
40 return the_application_manager;
46}
41}
@@ -49,9 +44,8 @@ ApplicationManager::ApplicationManager(QObject *parent)
49 : ApplicationManagerInterface(parent)
44 : ApplicationManagerInterface(parent)
50 , m_suspended(false)
45 , m_suspended(false)
51{
46{
52− m_roleNames.insert(RoleSurface, "surface");
47+ m_roleNames.insert(RoleSession, "session");
53 m_roleNames.insert(RoleFullscreen, "fullscreen");
48 m_roleNames.insert(RoleFullscreen, "fullscreen");
54− m_roleNames.insert(RoleApplication, "application");
55
49
56 buildListOfAvailableApplications();
50 buildListOfAvailableApplications();
57
51
@@ -105,12 +99,10 @@ QVariant ApplicationManager::data(const QModelIndex& index, int role) const {
105 return app->state();
99 return app->state();
106 case RoleFocused:
100 case RoleFocused:
107 return app->focused();
101 return app->focused();
108− case RoleSurface:
102+ case RoleSession:
109− return QVariant::fromValue(app->surface());
103+ return QVariant::fromValue(app->session());
110 case RoleFullscreen:
104 case RoleFullscreen:
111 return app->fullscreen();
105 return app->fullscreen();
112− case RoleApplication:
113− return QVariant::fromValue(app);
114 default:
106 default:
115 return QVariant();
107 return QVariant();
116 }
108 }
@@ -154,10 +146,10 @@ void ApplicationManager::add(ApplicationInfo *application) {
154 Q_EMIT countChanged();
146 Q_EMIT countChanged();
155 if (count() == 1) Q_EMIT emptyChanged(isEmpty()); // was empty but not anymore
147 if (count() == 1) Q_EMIT emptyChanged(isEmpty()); // was empty but not anymore
156
148
157− connect(application, &ApplicationInfo::surfaceChanged, this, [application, this]() {
149+ connect(application, &ApplicationInfo::sessionChanged, this, [application, this]() {
158 QModelIndex appIndex = findIndex(application);
150 QModelIndex appIndex = findIndex(application);
159 if (!appIndex.isValid()) return;
151 if (!appIndex.isValid()) return;
160− Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleSurface);
152+ Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleSession);
161 });
153 });
162 connect(application, &ApplicationInfo::focusedChanged, this, [application, this]() {
154 connect(application, &ApplicationInfo::focusedChanged, this, [application, this]() {
163 QModelIndex appIndex = findIndex(application);
155 QModelIndex appIndex = findIndex(application);
@@ -181,7 +173,7 @@ void ApplicationManager::remove(ApplicationInfo *application) {
181 Q_EMIT countChanged();
173 Q_EMIT countChanged();
182 if (isEmpty()) Q_EMIT emptyChanged(isEmpty());
174 if (isEmpty()) Q_EMIT emptyChanged(isEmpty());
183 }
175 }
184− disconnect(application, 0, this, 0);
176+ application->disconnect(this);
185}
177}
186
178
187void ApplicationManager::move(int from, int to) {
179void ApplicationManager::move(int from, int to) {
@@ -464,6 +456,7 @@ void ApplicationManager::buildListOfAvailableApplications()
464 m_availableApplications.append(application);
456 m_availableApplications.append(application);
465}
457}
466
458
459+
467QStringList ApplicationManager::availableApplications()
460QStringList ApplicationManager::availableApplications()
468{
461{
469 QStringList appIds;
462 QStringList appIds;
tests/mocks/Unity/Application/ApplicationManager.h+1−2
@@ -52,9 +52,8 @@ class ApplicationManager : public ApplicationManagerInterface {
52 static ApplicationManager *singleton();
52 static ApplicationManager *singleton();
53
53
54 enum MoreRoles {
54 enum MoreRoles {
55− RoleSurface = RoleFocused+1,
55+ RoleSession = RoleFocused+1,
56 RoleFullscreen,
56 RoleFullscreen,
57− RoleApplication,
58 };
57 };
59 enum Role {
58 enum Role {
60 Dash, Default, Indicators, Notifications, Greeter, Launcher, OnScreenKeyboard,
59 Dash, Default, Indicators, Notifications, Greeter, Launcher, OnScreenKeyboard,
tests/mocks/Unity/Application/ApplicationTestInterface.cppnew file+117
@@ -0,0 +1,117 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "ApplicationInfo.h"
18+#include "ApplicationTestInterface.h"
19+#include "ApplicationManager.h"
20+#include "SessionManager.h"
21+#include "SurfaceManager.h"
22+#include "Session.h"
23+#include "MirSurfaceItem.h"
24+
25+#include <paths.h>
26+
27+#include <QtDBus/QtDBus>
28+
29+quint32 nextId = 0;
30+
31+ApplicationTestInterface::ApplicationTestInterface(QObject* parent)
32+ : QDBusAbstractAdaptor(parent)
33+{
34+ QDBusConnection connection = QDBusConnection::sessionBus();
35+ connection.registerService("com.canonical.Unity8");
36+ connection.registerObject("/com/canonical/Unity8/Mocks", parent);
37+}
38+
39+Session* ApplicationTestInterface::addChildSession(Session* existingSession, const QString& surfaceImage)
40+{
41+ if (!existingSession) return nullptr;
42+
43+ QUrl screenshotUrl = QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png")
44+ .arg(qmlDirectory())
45+ .arg(surfaceImage);
46+
47+ Session* session = SessionManager::singleton()->createSession(
48+ QString("%1-Child%2").arg(existingSession->name())
49+ .arg(existingSession->childSessions()->count()),
50+ screenshotUrl);
51+ existingSession->addChildSession(session);
52+ session->createSurface();
53+
54+ return session;
55+}
56+
57+void ApplicationTestInterface::removeSession(Session* existingSession)
58+{
59+ qDebug() << "ApplicationTestInterface::removeSession - " << existingSession;
60+
61+ if (existingSession)
62+ existingSession->setLive(false);
63+}
64+
65+void ApplicationTestInterface::removeSurface(MirSurfaceItem* existingSurface)
66+{
67+ qDebug() << "ApplicationTestInterface::removeSurface - " << existingSurface;
68+
69+ if (existingSurface)
70+ existingSurface->setLive(false);
71+}
72+
73+quint32 ApplicationTestInterface::addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage)
74+{
75+ qDebug() << "ApplicationTestInterface::addChildSession to " << appId;
76+
77+ ApplicationInfo* application = ApplicationManager::singleton()->findApplication(appId);
78+ if (!application) {
79+ qDebug() << "ApplicationTestInterface::addChildSession - No application found for " << appId;
80+ return 0;
81+ }
82+
83+ Session* parentSession = nullptr;
84+ if (m_childSessions.contains(existingSessionId)) {
85+ parentSession = m_childSessions[existingSessionId];
86+ } else if (application->session()) {
87+ parentSession = application->session();
88+ } else {
89+ qDebug() << "ApplicationTestInterface::addChildSession - No session for " << appId << ":" << existingSessionId;
90+ return 0;
91+ }
92+
93+ QUrl screenshotUrl = QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png")
94+ .arg(qmlDirectory())
95+ .arg(surfaceImage);
96+
97+ quint32 sessionId = ++nextId;
98+ Session* session = SessionManager::singleton()->createSession(
99+ QString("%1-Child%2").arg(parentSession->name())
100+ .arg(parentSession->childSessions()->count()),
101+ screenshotUrl);
102+ parentSession->addChildSession(session);
103+ session->createSurface();
104+ m_childSessions[sessionId] = session;
105+
106+ return sessionId;
107+}
108+
109+void ApplicationTestInterface::removeSession(quint32 sessionId)
110+{
111+ if (!m_childSessions.contains(sessionId)) {
112+ qDebug() << "ApplicationTestInterface::removeSession - No added session for " << sessionId;
113+ return;
114+ }
115+ Session* session = m_childSessions.take(sessionId);
116+ removeSession(session);
117+}
tests/mocks/Unity/Application/ApplicationDBusAdaptor.h → tests/mocks/Unity/Application/ApplicationTestInterface.hrenamed+13−11
@@ -14,30 +14,32 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−#ifndef APPLICATIONDBUSADAPTOR_H
17+#ifndef APPLICATIONTESTINTERFACE_H
18−#define APPLICATIONDBUSADAPTOR_H
18+#define APPLICATIONTESTINTERFACE_H
19
19
20#include <QtDBus/QtDBus>
20#include <QtDBus/QtDBus>
21
21
22class ApplicationManager;
22class ApplicationManager;
23−class SurfaceManager;
23+class Session;
24class MirSurfaceItem;
24class MirSurfaceItem;
25
25
26−class ApplicationDBusAdaptor : public QDBusAbstractAdaptor
26+class ApplicationTestInterface : public QDBusAbstractAdaptor
27{
27{
28 Q_OBJECT
28 Q_OBJECT
29 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity8.Mocks.Application")
29 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity8.Mocks.Application")
30public:
30public:
31− ApplicationDBusAdaptor(ApplicationManager* applicationManager);
31+ ApplicationTestInterface(QObject* parent = 0);
32+
33+ Q_INVOKABLE Session* addChildSession(Session* existingSession, const QString& surfaceImage);
34+ Q_INVOKABLE void removeSession(Session* existingSession);
35+ Q_INVOKABLE void removeSurface(MirSurfaceItem* existingSurface);
32
36
33public Q_SLOTS:
37public Q_SLOTS:
34− quint32 addPromptSurface(const QString& appId, const QString& surfaceImage);
38+ quint32 addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage);
35− void removeChildSurface(int surfaceId);
39+ void removeSession(quint32 sessionId);
36
40
37private:
41private:
38− ApplicationManager* m_applicationManager;
42+ QHash<quint32, Session*> m_childSessions;
39−
40− QHash<quint32, MirSurfaceItem*> m_childItems;
41};
43};
42
44
43−#endif // APPLICATIONDBUSADAPTOR_H
45+#endif // APPLICATIONTESTINTERFACE_H
tests/mocks/Unity/Application/CMakeLists.txt+6−1
@@ -2,12 +2,17 @@ pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=3)
2
2
3set(FakeUnityApplicationQml_SOURCES
3set(FakeUnityApplicationQml_SOURCES
4 plugin.cpp
4 plugin.cpp
5− ApplicationDBusAdaptor.cpp
6 ApplicationInfo.cpp
5 ApplicationInfo.cpp
7 ApplicationManager.cpp
6 ApplicationManager.cpp
8 ApplicationScreenshotProvider.cpp
7 ApplicationScreenshotProvider.cpp
8+ ApplicationTestInterface.cpp
9 MirSurfaceItem.cpp
9 MirSurfaceItem.cpp
10+ MirSurfaceItemModel.h
11+ ObjectListModel.h
12+ Session.cpp
13+ SessionManager.cpp
10 SurfaceManager.cpp
14 SurfaceManager.cpp
15+ SessionModel.h
11 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
16 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
12 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
17 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
13)
18)
tests/mocks/Unity/Application/MirSurfaceItem.cpp+19−79
@@ -15,7 +15,7 @@
15 */
15 */
16
16
17#include "MirSurfaceItem.h"
17#include "MirSurfaceItem.h"
18−#include "ApplicationInfo.h"
18+#include "Session.h"
19
19
20#include <paths.h>
20#include <paths.h>
21
21
@@ -34,11 +34,11 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
34 const QString &qmlFilePath,
34 const QString &qmlFilePath,
35 QQuickItem *parent)
35 QQuickItem *parent)
36 : QQuickItem(parent)
36 : QQuickItem(parent)
37− , m_application(nullptr)
37+ , m_session(nullptr)
38 , m_name(name)
38 , m_name(name)
39 , m_type(type)
39 , m_type(type)
40 , m_state(state)
40 , m_state(state)
41− , m_parentSurface(nullptr)
41+ , m_live(true)
42 , m_qmlItem(nullptr)
42 , m_qmlItem(nullptr)
43 , m_screenshotUrl(screenshot)
43 , m_screenshotUrl(screenshot)
44{
44{
@@ -83,16 +83,9 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
83MirSurfaceItem::~MirSurfaceItem()
83MirSurfaceItem::~MirSurfaceItem()
84{
84{
85 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
85 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
86−
86+ if (m_session) {
87− QList<MirSurfaceItem*> children(m_children);
87+ m_session->setSurface(nullptr);
88− for (MirSurfaceItem* child : children) {
89− child->setParentSurface(nullptr);
90 }
88 }
91− if (m_parentSurface)
92− m_parentSurface->removeChildSurface(this);
93−
94− if (m_application)
95− m_application->removeSurface(this);
96}
89}
97
90
98void MirSurfaceItem::printComponentErrors()
91void MirSurfaceItem::printComponentErrors()
@@ -105,91 +98,38 @@ void MirSurfaceItem::printComponentErrors()
105
98
106void MirSurfaceItem::release()
99void MirSurfaceItem::release()
107{
100{
108− QList<MirSurfaceItem*> children(m_children);
101+ qDebug() << "MirSurfaceItem::release " << name();
109− for (MirSurfaceItem* child : children) {
110− child->release();
111− }
112− if (m_parentSurface) {
113− m_parentSurface->removeChildSurface(this);
114− }
115
102
116− if (m_application) {
103+ if (m_session) {
117− m_application->removeSurface(this);
104+ m_session->setSurface(nullptr);
118 }
105 }
119 if (!parent()) {
106 if (!parent()) {
120 deleteLater();
107 deleteLater();
121 }
108 }
122}
109}
123
110
124−void MirSurfaceItem::setApplication(ApplicationInfo* application)
111+void MirSurfaceItem::setSession(Session* session)
125{
112{
126− m_application = application;
113+ m_session = session;
127}
114}
128
115
129−void MirSurfaceItem::setParentSurface(MirSurfaceItem* surface)
116+void MirSurfaceItem::setScreenshot(const QUrl& screenshot)
130{
117{
131− if (m_parentSurface == surface || surface == this)
118+ m_screenshotUrl = screenshot;
132− return;
119+ if (m_qmlItem) {
133−
120+ QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
134− if (m_parentSurface) {
121+ screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
135− m_parentSurface->removeChildSurface(this);
136− }
137−
138− m_parentSurface = surface;
139−
140− if (m_parentSurface) {
141− m_parentSurface->addChildSurface(this);
142 }
122 }
143− Q_EMIT parentSurfaceChanged(surface);
144}
123}
145
124
146−void MirSurfaceItem::addChildSurface(MirSurfaceItem* surface)
125+void MirSurfaceItem::setLive(bool live)
147{
126{
148− qDebug() << "MirSurfaceItem::addChildSurface " << surface->name() << " to " << name();
127+ if (m_live != live) {
149−
128+ m_live = live;
150− m_children.append(surface);
129+ Q_EMIT liveChanged(m_live);
151− Q_EMIT childSurfacesChanged();
152−}
153−
154−void MirSurfaceItem::removeChildSurface(MirSurfaceItem* surface)
155−{
156− qDebug() << "MirSurfaceItem::removeChildSurface " << surface->name() << " from " << name();
157−
158− if (m_children.contains(surface)) {
159− m_children.removeOne(surface);
160− Q_EMIT childSurfacesChanged();
161 }
130 }
162}
131}
163
132
164−QList<MirSurfaceItem*> MirSurfaceItem::childSurfaceList()
165−{
166− return m_children;
167−}
168−
169−QQmlListProperty<MirSurfaceItem> MirSurfaceItem::childSurfaces()
170−{
171− return QQmlListProperty<MirSurfaceItem>(this,
172− 0,
173− MirSurfaceItem::childSurfaceCount,
174− MirSurfaceItem::childSurfaceAt);
175−}
176−
177−int MirSurfaceItem::childSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop)
178−{
179− MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
180− return p->m_children.count();
181−}
182−
183−MirSurfaceItem* MirSurfaceItem::childSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index)
184−{
185− MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
186−
187− if (index < 0 || index >= p->m_children.count())
188− return nullptr;
189− return p->m_children[index];
190−}
191−
192−
193void MirSurfaceItem::onQmlWantInputMethodChanged()
133void MirSurfaceItem::onQmlWantInputMethodChanged()
194{
134{
195 QQmlProperty prop(m_qmlItem, "wantInputMethod");
135 QQmlProperty prop(m_qmlItem, "wantInputMethod");
tests/mocks/Unity/Application/MirSurfaceItem.h+24−31
@@ -17,11 +17,12 @@
17#ifndef MIRSURFACEITEM_H
17#ifndef MIRSURFACEITEM_H
18#define MIRSURFACEITEM_H
18#define MIRSURFACEITEM_H
19
19
20+#include "MirSurfaceItemModel.h"
21+
20#include <QQuickItem>
22#include <QQuickItem>
21−#include <QQmlComponent>
22#include <QUrl>
23#include <QUrl>
23
24
24−class ApplicationInfo;
25+class Session;
25
26
26class MirSurfaceItem : public QQuickItem
27class MirSurfaceItem : public QQuickItem
27{
28{
@@ -31,9 +32,8 @@ class MirSurfaceItem : public QQuickItem
31
32
32 Q_PROPERTY(Type type READ type NOTIFY typeChanged)
33 Q_PROPERTY(Type type READ type NOTIFY typeChanged)
33 Q_PROPERTY(State state READ state NOTIFY stateChanged)
34 Q_PROPERTY(State state READ state NOTIFY stateChanged)
34− Q_PROPERTY(QString name READ name NOTIFY nameChanged)
35+ Q_PROPERTY(QString name READ name CONSTANT)
35− Q_PROPERTY(MirSurfaceItem* parentSurface READ parentSurface NOTIFY parentSurfaceChanged)
36+ Q_PROPERTY(bool live READ live NOTIFY liveChanged)
36− Q_PROPERTY(QQmlListProperty<MirSurfaceItem> childSurfaces READ childSurfaces NOTIFY childSurfacesChanged DESIGNABLE false)
37
37
38public:
38public:
39 enum Type {
39 enum Type {
@@ -56,24 +56,18 @@ public:
56 Fullscreen,
56 Fullscreen,
57 };
57 };
58
58
59− explicit MirSurfaceItem(const QString& name,
60− Type type,
61− State state,
62− const QUrl& screenshot,
63− const QString &qmlFilePath = QString(),
64− QQuickItem *parent = 0);
65 ~MirSurfaceItem();
59 ~MirSurfaceItem();
66
60
67 //getters
61 //getters
68− ApplicationInfo* application() const { return m_application; }
62+ Session* session() const { return m_session; }
69 Type type() const { return m_type; }
63 Type type() const { return m_type; }
70 State state() const { return m_state; }
64 State state() const { return m_state; }
71 QString name() const { return m_name; }
65 QString name() const { return m_name; }
72− MirSurfaceItem* parentSurface() const { return m_parentSurface; }
66+ bool live() const { return m_live; }
73− QList<MirSurfaceItem*> childSurfaceList();
74
67
75− void setApplication(ApplicationInfo* item);
68+ void setSession(Session* item);
76− void setParentSurface(MirSurfaceItem* item);
69+ void setScreenshot(const QUrl& screenshot);
70+ void setLive(bool live);
77
71
78 Q_INVOKABLE void setState(State newState);
72 Q_INVOKABLE void setState(State newState);
79 Q_INVOKABLE void release();
73 Q_INVOKABLE void release();
@@ -81,42 +75,41 @@ public:
81Q_SIGNALS:
75Q_SIGNALS:
82 void typeChanged(Type);
76 void typeChanged(Type);
83 void stateChanged(State);
77 void stateChanged(State);
84− void nameChanged(QString);
78+ void liveChanged(bool live);
85− void parentSurfaceChanged(MirSurfaceItem*);
86− void childSurfacesChanged();
87−
88− void removed();
89
79
90 void inputMethodRequested();
80 void inputMethodRequested();
91 void inputMethodDismissed();
81 void inputMethodDismissed();
92
82
83+ // internal mock use
84+ void deregister();
85+
93private Q_SLOTS:
86private Q_SLOTS:
94 void onFocusChanged();
87 void onFocusChanged();
95 void onComponentStatusChanged(QQmlComponent::Status status);
88 void onComponentStatusChanged(QQmlComponent::Status status);
96 void onQmlWantInputMethodChanged();
89 void onQmlWantInputMethodChanged();
97
90
98private:
91private:
99− void addChildSurface(MirSurfaceItem* surface);
92+ explicit MirSurfaceItem(const QString& name,
100− void removeChildSurface(MirSurfaceItem* surface);
93+ Type type,
101−
94+ State state,
102− QQmlListProperty<MirSurfaceItem> childSurfaces();
95+ const QUrl& screenshot,
103− static int childSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop);
96+ const QString &qmlFilePath = QString(),
104− static MirSurfaceItem* childSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index);
97+ QQuickItem *parent = 0);
105
98
106 void createQmlContentItem();
99 void createQmlContentItem();
107 void printComponentErrors();
100 void printComponentErrors();
108
101
109− ApplicationInfo* m_application;
102+ Session* m_session;
110 const QString m_name;
103 const QString m_name;
111 const Type m_type;
104 const Type m_type;
112 State m_state;
105 State m_state;
113−
106+ bool m_live;
114− MirSurfaceItem* m_parentSurface;
115− QList<MirSurfaceItem*> m_children;
116
107
117 QQmlComponent *m_qmlContentComponent;
108 QQmlComponent *m_qmlContentComponent;
118 QQuickItem *m_qmlItem;
109 QQuickItem *m_qmlItem;
119 QUrl m_screenshotUrl;
110 QUrl m_screenshotUrl;
111+
112+ friend class SurfaceManager;
120};
113};
121
114
122Q_DECLARE_METATYPE(MirSurfaceItem*)
115Q_DECLARE_METATYPE(MirSurfaceItem*)
tests/mocks/Unity/Application/MirSurfaceItemModel.hnew file+35
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
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/>.
15+ */
16+
17+#ifndef MIRSURFACEITEMMODEL_H
18+#define MIRSURFACEITEMMODEL_H
19+
20+// Local
21+#include "ObjectListModel.h"
22+
23+class MirSurfaceItem;
24+class MirSurfaceItemModel: public ObjectListModel<MirSurfaceItem>
25+{
26+ Q_OBJECT
27+public:
28+ MirSurfaceItemModel(QObject *parent = 0): ObjectListModel(parent) {}
29+
30+ Q_INVOKABLE int count() const { return rowCount(); }
31+};
32+
33+Q_DECLARE_METATYPE(MirSurfaceItemModel*)
34+
35+#endif // MIRSURFACEITEMMODEL_H
tests/mocks/Unity/Application/ObjectListModel.hnew file+106
@@ -0,0 +1,106 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
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/>.
15+ */
16+
17+#ifndef OBJECTLISTMODEL_H
18+#define OBJECTLISTMODEL_H
19+
20+// Qt
21+#include <QAbstractListModel>
22+
23+template<class TYPE>
24+class ObjectListModel : public QAbstractListModel
25+{
26+public:
27+ ObjectListModel(QObject *parent = 0)
28+ : QAbstractListModel(parent)
29+ {}
30+
31+ enum Roles {
32+ RoleModelData = Qt::UserRole,
33+ };
34+
35+ const QList<TYPE*>& list() const { return m_items; }
36+ bool contains(TYPE* item) const { return m_items.contains(item); }
37+
38+ void insert(uint index, TYPE* item)
39+ {
40+ index = qMin(index, (uint)m_items.count());
41+
42+ int existingIndex = m_items.indexOf(item);
43+ if (existingIndex != -1) {
44+ move(existingIndex, qMin(index, (uint)(m_items.count()-1)));
45+ } else {
46+ beginInsertRows(QModelIndex(), index, index);
47+ m_items.insert(index, item);
48+ endInsertRows();
49+ }
50+ }
51+
52+ void remove(TYPE* item)
53+ {
54+ int existingIndex = m_items.indexOf(item);
55+ if (existingIndex != -1) {
56+ beginRemoveRows(QModelIndex(), existingIndex, existingIndex);
57+ m_items.removeAt(existingIndex);
58+ endRemoveRows();
59+ }
60+ }
61+
62+ // from QAbstractItemModel
63+ int rowCount(const QModelIndex& = QModelIndex()) const override
64+ {
65+ return m_items.count();
66+ }
67+
68+ QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override
69+ {
70+ if (index.row() >= 0 && index.row() < m_items.count()) {
71+ if (role == RoleModelData) {
72+ TYPE *item = m_items.at(index.row());
73+ return QVariant::fromValue(item);
74+ }
75+ }
76+ return QVariant();
77+ }
78+
79+ QHash<int, QByteArray> roleNames() const
80+ {
81+ QHash<int, QByteArray> roleNames;
82+ roleNames.insert(RoleModelData, "modelData");
83+ return roleNames;
84+ }
85+
86+protected:
87+ void move(int from, int to)
88+ {
89+ if (from == to) return;
90+
91+ if (from >= 0 && from < m_items.size() && to >= 0 && to < m_items.size()) {
92+ QModelIndex parent;
93+ /* When moving an item down, the destination index needs to be incremented
94+ by one, as explained in the documentation:
95+ http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#beginMoveRows */
96+
97+ beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
98+ m_items.move(from, to);
99+ endMoveRows();
100+ }
101+ }
102+
103+ QList<TYPE*> m_items;
104+};
105+
106+#endif // OBJECTLISTMODEL_H
tests/mocks/Unity/Application/Session.cppnew file+174
@@ -0,0 +1,174 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "Session.h"
18+#include "ApplicationInfo.h"
19+#include "SessionManager.h"
20+#include "SurfaceManager.h"
21+
22+#include <QPainter>
23+#include <QQmlEngine>
24+#include <QTimer>
25+
26+Session::Session(const QString &name,
27+ const QUrl& screenshot,
28+ QObject *parent)
29+ : QObject(parent)
30+ , m_name(name)
31+ , m_live(true)
32+ , m_screenshot(screenshot)
33+ , m_application(nullptr)
34+ , m_surface(nullptr)
35+ , m_parentSession(nullptr)
36+ , m_children(new SessionModel(this))
37+{
38+ qDebug() << "Session::Session() " << this->name();
39+
40+ QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
41+}
42+
43+Session::~Session()
44+{
45+ qDebug() << "Session::~Session() " << name();
46+
47+ QList<Session*> children(m_children->list());
48+ for (Session* child : children) {
49+ delete child;
50+ }
51+ if (m_parentSession) {
52+ m_parentSession->removeChildSession(this);
53+ }
54+ if (m_application) {
55+ m_application->setSession(nullptr);
56+ }
57+ delete m_surface;
58+ delete m_children;
59+}
60+
61+void Session::release()
62+{
63+ qDebug() << "Session::release " << name();
64+
65+ if (m_parentSession) {
66+ m_parentSession->removeChildSession(this);
67+ }
68+ if (m_application) {
69+ m_application->setSession(nullptr);
70+ }
71+ if (!parent()) {
72+ deleteLater();
73+ }
74+}
75+
76+void Session::setApplication(ApplicationInfo* application)
77+{
78+ if (m_application == application)
79+ return;
80+
81+ m_application = application;
82+ Q_EMIT applicationChanged(application);
83+}
84+
85+void Session::setSurface(MirSurfaceItem* surface)
86+{
87+ qDebug() << "Session::setSurface - session=" << name() << "surface=" << surface;
88+ if (m_surface == surface)
89+ return;
90+
91+ if (m_surface) {
92+ m_surface->setSession(nullptr);
93+ m_surface->setParent(nullptr);
94+ Q_EMIT m_surface->deregister();
95+ }
96+
97+ m_surface = surface;
98+
99+ if (m_surface) {
100+ m_surface->setSession(this);
101+ m_surface->setParent(this);
102+ SurfaceManager::singleton()->registerSurface(m_surface);
103+ }
104+
105+ Q_EMIT surfaceChanged(m_surface);
106+}
107+
108+void Session::setScreenshot(const QUrl& screenshot)
109+{
110+ if (screenshot != m_screenshot) {
111+ m_screenshot = screenshot;
112+ if (m_surface) {
113+ m_surface->setScreenshot(m_screenshot);
114+ }
115+ }
116+}
117+
118+void Session::setLive(bool live)
119+{
120+ if (m_live != live) {
121+ m_live = live;
122+ Q_EMIT liveChanged(m_live);
123+ }
124+}
125+
126+void Session::setParentSession(Session* session)
127+{
128+ if (m_parentSession == session || session == this)
129+ return;
130+
131+ m_parentSession = session;
132+ Q_EMIT parentSessionChanged(session);
133+}
134+
135+void Session::createSurface()
136+{
137+ if (m_surface) return;
138+
139+ setSurface(SurfaceManager::singleton()->createSurface(name(),
140+ MirSurfaceItem::Normal,
141+ m_application && m_application->fullscreen() ? MirSurfaceItem::Fullscreen :
142+ MirSurfaceItem::Maximized,
143+ m_screenshot));
144+}
145+
146+void Session::addChildSession(Session* session)
147+{
148+ insertChildSession(m_children->rowCount(), session);
149+}
150+
151+void Session::insertChildSession(uint index, Session* session)
152+{
153+ qDebug() << "Session::insertChildSession - " << session->name() << " to " << name() << " @ " << index;
154+
155+ session->setParentSession(this);
156+ m_children->insert(index, session);
157+ SessionManager::singleton()->registerSession(session);
158+}
159+
160+void Session::removeChildSession(Session* session)
161+{
162+ qDebug() << "Session::removeChildSession - " << session->name() << " from " << name();
163+
164+ if (m_children->contains(session)) {
165+ m_children->remove(session);
166+ session->setParentSession(nullptr);
167+ Q_EMIT session->deregister();
168+ }
169+}
170+
171+SessionModel* Session::childSessions() const
172+{
173+ return m_children;
174+}
tests/mocks/Unity/Application/Session.hnew file+90
@@ -0,0 +1,90 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef SESSION_H
18+#define SESSION_H
19+
20+#include "SessionModel.h"
21+
22+#include <QQuickItem>
23+
24+class ApplicationInfo;
25+class MirSurfaceItem;
26+
27+class Session : public QObject
28+{
29+ Q_OBJECT
30+ Q_PROPERTY(QString name READ name CONSTANT)
31+ Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
32+ Q_PROPERTY(ApplicationInfo* application READ application NOTIFY applicationChanged)
33+ Q_PROPERTY(Session* parentSession READ parentSession NOTIFY parentSessionChanged DESIGNABLE false)
34+ Q_PROPERTY(SessionModel* childSessions READ childSessions DESIGNABLE false CONSTANT)
35+ Q_PROPERTY(bool live READ live NOTIFY liveChanged)
36+
37+public:
38+ explicit Session(const QString &name,
39+ const QUrl& screenshot,
40+ QObject *parent = 0);
41+ ~Session();
42+
43+ Q_INVOKABLE void release();
44+
45+ //getters
46+ QString name() const { return m_name; }
47+ bool live() const { return m_live; }
48+ ApplicationInfo* application() const { return m_application; }
49+ MirSurfaceItem* surface() const { return m_surface; }
50+ Session* parentSession() const { return m_parentSession; }
51+
52+ void setApplication(ApplicationInfo* item);
53+ void setSurface(MirSurfaceItem* surface);
54+ void setScreenshot(const QUrl& m_screenshot);
55+ void setLive(bool live);
56+
57+ Q_INVOKABLE void addChildSession(Session* session);
58+ void insertChildSession(uint index, Session* session);
59+ void removeChildSession(Session* session);
60+
61+Q_SIGNALS:
62+ void applicationChanged(ApplicationInfo*);
63+ void surfaceChanged(MirSurfaceItem*);
64+ void parentSessionChanged(Session*);
65+ void liveChanged(bool live);
66+
67+ // internal mock use
68+ void deregister();
69+
70+public Q_SLOTS:
71+ Q_INVOKABLE void createSurface();
72+
73+private:
74+ SessionModel* childSessions() const;
75+ void setParentSession(Session* session);
76+
77+ QString m_name;
78+ bool m_live;
79+ QUrl m_screenshot;
80+ ApplicationInfo* m_application;
81+ MirSurfaceItem* m_surface;
82+ Session* m_parentSession;
83+ SessionModel* m_children;
84+
85+ friend class ApplicationTestInterface;
86+};
87+
88+Q_DECLARE_METATYPE(Session*)
89+
90+#endif // SESSION_H
tests/mocks/Unity/Application/SessionManager.cppnew file+55
@@ -0,0 +1,55 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "SessionManager.h"
18+
19+#include "Session.h"
20+
21+SessionManager *SessionManager::the_session_manager = nullptr;
22+
23+SessionManager *SessionManager::singleton()
24+{
25+ if (!the_session_manager) {
26+ the_session_manager = new SessionManager();
27+ }
28+ return the_session_manager;
29+}
30+
31+SessionManager::SessionManager(QObject *parent) :
32+ QObject(parent)
33+{
34+}
35+
36+
37+Session *SessionManager::createSession(const QString& name,
38+ const QUrl& screenshot)
39+{
40+ Session* session = new Session(name, screenshot);
41+ Q_EMIT sessionStarting(session);
42+ return session;
43+}
44+
45+void SessionManager::registerSession(Session *session)
46+{
47+ connect(session, &Session::deregister, this, [this] {
48+ Session* session = qobject_cast<Session*>(sender());
49+
50+ disconnect(session, 0, this, 0);
51+
52+ session->setLive(false);
53+ Q_EMIT sessionStopping(session);
54+ });
55+}
tests/mocks/Unity/Application/SessionManager.hnew file+44
@@ -0,0 +1,44 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef SESSIONMANAGER_H
18+#define SESSIONMANAGER_H
19+
20+#include <QObject>
21+
22+class Session;
23+
24+class SessionManager : public QObject
25+{
26+ Q_OBJECT
27+public:
28+ explicit SessionManager(QObject *parent = 0);
29+
30+ static SessionManager *singleton();
31+
32+ Q_INVOKABLE Session* createSession(const QString& name, const QUrl& screenshot);
33+
34+ void registerSession(Session *session);
35+
36+Q_SIGNALS:
37+ void sessionStarting(Session *session);
38+ void sessionStopping(Session *session);
39+
40+private:
41+ static SessionManager *the_session_manager;
42+};
43+
44+#endif // SESSIONMANAGER_H
tests/mocks/Unity/Application/SessionModel.hnew file+35
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
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/>.
15+ */
16+
17+#ifndef SESSIONMODEL_H
18+#define SESSIONMODEL_H
19+
20+// Local
21+#include "ObjectListModel.h"
22+
23+class Session;
24+class SessionModel: public ObjectListModel<Session>
25+{
26+ Q_OBJECT
27+public:
28+ SessionModel(QObject *parent = 0): ObjectListModel(parent) {}
29+
30+ Q_INVOKABLE int count() const { return rowCount(); }
31+};
32+
33+Q_DECLARE_METATYPE(SessionModel*)
34+
35+#endif // SESSIONMODEL_H
tests/mocks/Unity/Application/SurfaceManager.cpp+20−7
@@ -35,19 +35,32 @@ SurfaceManager::SurfaceManager(QObject *parent) :
35{
35{
36}
36}
37
37
38+MirSurfaceItem *SurfaceManager::createSurface(const QString& name,
39+ MirSurfaceItem::Type type,
40+ MirSurfaceItem::State state,
41+ const QUrl& screenshot)
42+{
43+ MirSurfaceItem* surface = new MirSurfaceItem(name,
44+ type,
45+ state,
46+ screenshot);
47+ Q_EMIT surfaceCreated(surface);
48+ return surface;
49+}
50+
38void SurfaceManager::registerSurface(MirSurfaceItem *surface)
51void SurfaceManager::registerSurface(MirSurfaceItem *surface)
39{
52{
53+ connect(surface, &MirSurfaceItem::deregister, this, [this] {
54+ MirSurfaceItem* surface = qobject_cast<MirSurfaceItem*>(sender());
55+ disconnect(surface, 0, this, 0);
56+
57+ surface->setLive(false);
58+ Q_EMIT surfaceDestroyed(surface);
59+ });
40 connect(surface, &MirSurfaceItem::inputMethodRequested,
60 connect(surface, &MirSurfaceItem::inputMethodRequested,
41 this, &SurfaceManager::showInputMethod);
61 this, &SurfaceManager::showInputMethod);
42 connect(surface, &MirSurfaceItem::inputMethodDismissed,
62 connect(surface, &MirSurfaceItem::inputMethodDismissed,
43 this, &SurfaceManager::hideInputMethod);
63 this, &SurfaceManager::hideInputMethod);
44− Q_EMIT surfaceCreated(surface);
45−}
46−
47−void SurfaceManager::unregisterSurface(MirSurfaceItem *surface)
48−{
49− disconnect(surface, 0, this, 0);
50− Q_EMIT surfaceDestroyed(surface);
51}
64}
52
65
53void SurfaceManager::showInputMethod()
66void SurfaceManager::showInputMethod()
tests/mocks/Unity/Application/SurfaceManager.h+6−2
@@ -19,7 +19,7 @@
19
19
20#include <QObject>
20#include <QObject>
21
21
22−class MirSurfaceItem;
22+#include "MirSurfaceItem.h"
23
23
24class SurfaceManager : public QObject
24class SurfaceManager : public QObject
25{
25{
@@ -29,9 +29,13 @@ public:
29
29
30 static SurfaceManager *singleton();
30 static SurfaceManager *singleton();
31
31
32+ Q_INVOKABLE MirSurfaceItem *createSurface(const QString& name,
33+ MirSurfaceItem::Type type,
34+ MirSurfaceItem::State state,
35+ const QUrl& screenshot);
36+
32 // Internal mock use
37 // Internal mock use
33 void registerSurface(MirSurfaceItem *surface);
38 void registerSurface(MirSurfaceItem *surface);
34− void unregisterSurface(MirSurfaceItem *surface);
35
39
36 // To be used in the tests
40 // To be used in the tests
37 Q_INVOKABLE MirSurfaceItem *inputMethodSurface();
41 Q_INVOKABLE MirSurfaceItem *inputMethodSurface();
tests/mocks/Unity/Application/plugin.cpp+37−4
@@ -18,8 +18,12 @@
18#include "ApplicationInfo.h"
18#include "ApplicationInfo.h"
19#include "ApplicationManager.h"
19#include "ApplicationManager.h"
20#include "ApplicationScreenshotProvider.h"
20#include "ApplicationScreenshotProvider.h"
21+#include "Session.h"
21#include "MirSurfaceItem.h"
22#include "MirSurfaceItem.h"
23+#include "MirSurfaceItemModel.h"
22#include "SurfaceManager.h"
24#include "SurfaceManager.h"
25+#include "SessionManager.h"
26+#include "ApplicationTestInterface.h"
23
27
24#include <qqml.h>
28#include <qqml.h>
25#include <QQmlEngine>
29#include <QQmlEngine>
@@ -36,18 +40,45 @@ static QObject* surfaceManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEng
36 return SurfaceManager::singleton();
40 return SurfaceManager::singleton();
37}
41}
38
42
43+static QObject* sessionManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
44+ Q_UNUSED(engine);
45+ Q_UNUSED(scriptEngine);
46+ return SessionManager::singleton();
47+}
48+
49+ApplicationTestInterface* s_appTestInterface = nullptr;
50+
51+static QObject* applicationTestInterface(QQmlEngine* engine, QJSEngine* scriptEngine) {
52+ Q_UNUSED(engine);
53+ Q_UNUSED(scriptEngine);
54+ if (!s_appTestInterface) {
55+ s_appTestInterface = new ApplicationTestInterface(engine);
56+ }
57+ return s_appTestInterface;
58+}
59+
39void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
60void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
40{
61{
62+ qRegisterMetaType<Session*>("Session*");
63+ qRegisterMetaType<ApplicationInfo*>("ApplicationInfo*");
64+ qRegisterMetaType<MirSurfaceItemModel*>("SessionModel*");
41 qRegisterMetaType<MirSurfaceItem*>("MirSurfaceItem*");
65 qRegisterMetaType<MirSurfaceItem*>("MirSurfaceItem*");
66+ qRegisterMetaType<MirSurfaceItemModel*>("MirSurfaceItemModel*");
42
67
43 qmlRegisterUncreatableType<unity::shell::application::ApplicationManagerInterface>(uri, 0, 1, "ApplicationManagerInterface", "Abstract interface. Cannot be created in QML");
68 qmlRegisterUncreatableType<unity::shell::application::ApplicationManagerInterface>(uri, 0, 1, "ApplicationManagerInterface", "Abstract interface. Cannot be created in QML");
44− qmlRegisterSingletonType<ApplicationManager>(uri, 0, 1, "ApplicationManager", applicationManagerSingleton);
45− qmlRegisterSingletonType<SurfaceManager>(uri, 0, 1, "SurfaceManager", surfaceManagerSingleton);
46−
47 qmlRegisterUncreatableType<unity::shell::application::ApplicationInfoInterface>(uri, 0, 1, "ApplicationInfoInterface", "Abstract interface. Cannot be created in QML");
69 qmlRegisterUncreatableType<unity::shell::application::ApplicationInfoInterface>(uri, 0, 1, "ApplicationInfoInterface", "Abstract interface. Cannot be created in QML");
70+ qmlRegisterUncreatableType<Session>(uri, 0, 1, "Session", "Session can't be instantiated from QML");
71+ qmlRegisterUncreatableType<MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem", "MirSurfaceItem can't be instantiated from QML");
72+
48 qmlRegisterType<ApplicationInfo>(uri, 0, 1, "ApplicationInfo");
73 qmlRegisterType<ApplicationInfo>(uri, 0, 1, "ApplicationInfo");
49
74
50− qmlRegisterUncreatableType<MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem", "MirSurfaceItem can't be instantiated from QML");
75+ qmlRegisterSingletonType<ApplicationManager>(uri, 0, 1, "ApplicationManager", applicationManagerSingleton);
76+ qmlRegisterSingletonType<SurfaceManager>(uri, 0, 1, "SurfaceManager", surfaceManagerSingleton);
77+ qmlRegisterSingletonType<SessionManager>(uri, 0, 1, "SessionManager", sessionManagerSingleton);
78+ qmlRegisterSingletonType<ApplicationTestInterface>(uri, 0, 1, "ApplicationTest", applicationTestInterface);
79+
80+ qRegisterMetaType<MirSurfaceItem::Type>("MirSurfaceItem::Type");
81+ qRegisterMetaType<MirSurfaceItem::State>("MirSurfaceItem::State");
51}
82}
52
83
53void FakeUnityApplicationQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
84void FakeUnityApplicationQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
@@ -55,4 +86,6 @@ void FakeUnityApplicationQmlPlugin::initializeEngine(QQmlEngine *engine, const c
55 QQmlExtensionPlugin::initializeEngine(engine, uri);
86 QQmlExtensionPlugin::initializeEngine(engine, uri);
56
87
57 engine->addImageProvider(QLatin1String("application"), new ApplicationScreenshotProvider(ApplicationManager::singleton()));
88 engine->addImageProvider(QLatin1String("application"), new ApplicationScreenshotProvider(ApplicationManager::singleton()));
89+ // make sure we initialise our test interface.
90+ applicationTestInterface(engine, nullptr);
58}
91}
tests/mocks/Unity/Indicators/Indicators.qmltypes+20
@@ -159,6 +159,26 @@ Module {
159 Property { name: "sourceModel"; type: "QAbstractItemModel"; isPointer: true }
159 Property { name: "sourceModel"; type: "QAbstractItemModel"; isPointer: true }
160 }
160 }
161 Component { name: "QIdentityProxyModel"; prototype: "QAbstractProxyModel" }
161 Component { name: "QIdentityProxyModel"; prototype: "QAbstractProxyModel" }
162+ Component {
163+ name: "UnityMenuModelCache"
164+ prototype: "QObject"
165+ exports: ["Unity.Indicators/UnityMenuModelCache 0.1"]
166+ isCreatable: false
167+ isSingleton: true
168+ exportMetaObjectRevisions: [0]
169+ Method {
170+ name: "model"
171+ type: "UnityMenuModel*"
172+ Parameter { name: "bus"; type: "QByteArray" }
173+ Parameter { name: "path"; type: "QByteArray" }
174+ Parameter { name: "actions"; type: "QVariantMap" }
175+ }
176+ Method {
177+ name: "contains"
178+ type: "bool"
179+ Parameter { name: "path"; type: "QByteArray" }
180+ }
181+ }
162 Component {
182 Component {
163 name: "UnityMenuModelStack"
183 name: "UnityMenuModelStack"
164 prototype: "QObject"
184 prototype: "QObject"
tests/mocks/Unity/Unity.qmltypes+30−2
@@ -36,6 +36,10 @@ Module {
36 prototype: "unity::shell::scopes::PreviewModelInterface"
36 prototype: "unity::shell::scopes::PreviewModelInterface"
37 exports: ["Unity/FakePreviewModel 0.2"]
37 exports: ["Unity/FakePreviewModel 0.2"]
38 exportMetaObjectRevisions: [0]
38 exportMetaObjectRevisions: [0]
39+ Method {
40+ name: "setLoaded"
41+ Parameter { type: "bool" }
42+ }
39 }
43 }
40 Component {
44 Component {
41 name: "PreviewStack"
45 name: "PreviewStack"
@@ -59,9 +63,9 @@ Module {
59 Component {
63 Component {
60 name: "ResultsModel"
64 name: "ResultsModel"
61 prototype: "unity::shell::scopes::ResultsModelInterface"
65 prototype: "unity::shell::scopes::ResultsModelInterface"
62− exports: ["Unity/ResultsModel 0.2"]
66+ exports: ["Unity/FakeResultsModel 0.2", "Unity/ResultsModel 0.2"]
63 isCreatable: false
67 isCreatable: false
64− exportMetaObjectRevisions: [0]
68+ exportMetaObjectRevisions: [0, 0]
65 }
69 }
66 Component {
70 Component {
67 name: "Scope"
71 name: "Scope"
@@ -134,7 +138,13 @@ Module {
134 }
138 }
135 Method { name: "clear" }
139 Method { name: "clear" }
136 Method { name: "load" }
140 Method { name: "load" }
141+ Method {
142+ name: "getScopeFromAll"
143+ type: "Scope*"
144+ Parameter { name: "scope_id"; type: "string" }
145+ }
137 }
146 }
147+ Component { name: "SettingsModel"; prototype: "unity::shell::scopes::SettingsModelInterface" }
138 Component {
148 Component {
139 name: "unity::shell::scopes::CategoriesInterface"
149 name: "unity::shell::scopes::CategoriesInterface"
140 prototype: "QAbstractListModel"
150 prototype: "QAbstractListModel"
@@ -402,4 +412,22 @@ Module {
402 Parameter { name: "scopeId"; type: "string" }
412 Parameter { name: "scopeId"; type: "string" }
403 }
413 }
404 }
414 }
415+ Component {
416+ name: "unity::shell::scopes::SettingsModelInterface"
417+ prototype: "QAbstractListModel"
418+ exports: ["Unity/SettingsModel 0.2"]
419+ isCreatable: false
420+ exportMetaObjectRevisions: [0]
421+ Enum {
422+ name: "Roles"
423+ values: {
424+ "RoleSettingId": 0,
425+ "RoleDisplayName": 1,
426+ "RoleType": 2,
427+ "RoleProperties": 3,
428+ "RoleValue": 4
429+ }
430+ }
431+ Property { name: "count"; type: "int"; isReadonly: true }
432+ }
405}
433}
tests/qmltests/CMakeLists.txt+1
@@ -86,3 +86,4 @@ add_qml_test(Stages ApplicationWindow ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINAR
86add_qml_test(Stages PhoneStage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
86add_qml_test(Stages PhoneStage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
87add_qml_test(Stages SpreadDelegate ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
87add_qml_test(Stages SpreadDelegate ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
88add_qml_test(Stages SurfaceContainer ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
88add_qml_test(Stages SurfaceContainer ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
89+add_qml_test(Stages SessionContainer ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
tests/qmltests/Panel/tst_ActiveCallHint.qml+1−1
@@ -97,7 +97,7 @@ Item {
97 var application = ApplicationManager.startApplication("dialer-app");
97 var application = ApplicationManager.startApplication("dialer-app");
98 ApplicationManager.focusApplication("dialer-app");
98 ApplicationManager.focusApplication("dialer-app");
99 tryCompare(ApplicationManager, "focusedApplicationId", "dialer-app");
99 tryCompare(ApplicationManager, "focusedApplicationId", "dialer-app");
100− tryCompare(application, "state", ApplicationInfo.Running);
100+ tryCompare(application, "state", ApplicationInfoInterface.Running);
101
101
102 if (!data.focused) { ApplicationManager.unfocusCurrentApplication(); }
102 if (!data.focused) { ApplicationManager.unfocusCurrentApplication(); }
103 }
103 }
tests/qmltests/Stages/RecursingChildSessionControl.qmlnew file+142
@@ -0,0 +1,142 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.1
18+import QtQuick.Layouts 1.1
19+import Ubuntu.Components 0.1
20+import Unity.Application 0.1
21+
22+ColumnLayout {
23+ id: root
24+
25+ property var session
26+ property var childSessions: session ? session.childSessions : 0
27+ property bool removable: false
28+ property alias surfaceCheckbox: _surfaceCheckbox
29+
30+ property var screenshotIds: [ "gallery", "map", "facebook", "camera", "browser", "music", "twitter"]
31+
32+ onSessionChanged: {
33+ if (!session) surfaceCheckbox.checked = false;
34+ }
35+
36+ Column {
37+ id: column
38+ Layout.fillWidth: true
39+ visible: repeater.count
40+ spacing: units.gu(1)
41+
42+ Repeater {
43+ id: repeater
44+ model: root.childSessions
45+ delegate: Rectangle {
46+ border {
47+ color: "black"
48+ width: 1
49+ }
50+ anchors {
51+ left: column.left
52+ right: column.right
53+ leftMargin: units.gu(1)
54+ rightMargin: units.gu(1)
55+ }
56+ height: loader.height
57+
58+ Rectangle {
59+ anchors.fill: parent
60+ color: Qt.rgba(Math.random(), Math.random(), Math.random(), 0.4 )
61+ }
62+
63+ Loader {
64+ id: loader
65+ visible: status == Loader.Ready
66+ source: Qt.resolvedUrl("RecursingChildSessionControl.qml")
67+
68+ anchors {
69+ left: parent.left
70+ right: parent.right
71+ }
72+
73+ onLoaded: {
74+ item.session = modelData;
75+ item.removable = true;
76+ }
77+ }
78+ }
79+ }
80+ }
81+
82+ ColumnLayout {
83+ Layout.fillWidth: true
84+ spacing: units.gu(1)
85+
86+ RowLayout {
87+ Layout.fillWidth: true
88+
89+ CheckBox {
90+ id: _surfaceCheckbox;
91+ checked: false;
92+ enabled: root.session
93+ onCheckedChanged: {
94+ if (checked) {
95+ root.session.createSurface();
96+ } else if (root.session.surface) {
97+ ApplicationTest.removeSurface(root.session.surface);
98+ }
99+ }
100+
101+ Connections {
102+ target: root.session ? root.session : null
103+ onSurfaceChanged: {
104+ surfaceCheckbox.checked = root.session.surface !== null
105+ }
106+ }
107+ }
108+
109+ Label {
110+ text: "Surface"
111+ anchors.verticalCenter: parent.verticalCenter
112+ }
113+ }
114+
115+ RowLayout {
116+ id: buttonLayout
117+
118+ Button {
119+ enabled: root.session
120+ text: removable ? "Remove" : "Release"
121+ onClicked: {
122+ if (removable) {
123+ // release the surface first. simulates mir app closing
124+ if (root.session.surface) ApplicationTest.removeSurface(root.session.surface);
125+ ApplicationTest.removeSession(root.session);
126+ } else {
127+ root.session.release();
128+ }
129+ }
130+ }
131+
132+ Button {
133+ enabled: root.session !== null
134+ text: "Add Child"
135+ onClicked: {
136+ var screenshot = Math.round(Math.random()*100 % (screenshotIds.length-1));
137+ var session = ApplicationTest.addChildSession(root.session, root.screenshotIds[screenshot]);
138+ }
139+ }
140+ }
141+ }
142+}
tests/qmltests/Stages/tst_ApplicationWindow.qml+99−47
@@ -14,7 +14,8 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−import QtQuick 2.0
17+import QtQuick 2.1
18+import QtQuick.Layouts 1.1
18import QtTest 1.0
19import QtTest 1.0
19import Unity.Test 0.1 as UT
20import Unity.Test 0.1 as UT
20import ".."
21import ".."
@@ -32,14 +33,15 @@ Rectangle {
32 Component.onCompleted: {
33 Component.onCompleted: {
33 root.fakeApplication = ApplicationManager.add("gallery-app");
34 root.fakeApplication = ApplicationManager.add("gallery-app");
34 root.fakeApplication.manualSurfaceCreation = true;
35 root.fakeApplication.manualSurfaceCreation = true;
35− root.fakeApplication.setState(ApplicationInfo.Starting);
36+ root.fakeApplication.setState(ApplicationInfoInterface.Starting);
36 }
37 }
37 property QtObject fakeApplication: null
38 property QtObject fakeApplication: null
39+ readonly property var fakeSession: fakeApplication ? fakeApplication.session : null
38
40
39 Connections {
41 Connections {
40 target: fakeApplication
42 target: fakeApplication
41− onSurfaceChanged: {
43+ onSessionChanged: {
42− surfaceCheckbox.checked = fakeApplication.surface !== null;
44+ sessionCheckbox.checked = fakeApplication.session !== null
43 }
45 }
44 }
46 }
45
47
@@ -50,15 +52,20 @@ Rectangle {
50 application: fakeApplication
52 application: fakeApplication
51 }
53 }
52 }
54 }
53− Loader {
55+ FocusScope {
54− id: applicationWindowLoader
56+ id: appFocus
55 anchors {
57 anchors {
56 top: parent.top
58 top: parent.top
57 bottom: parent.bottom
59 bottom: parent.bottom
58 left: parent.left
60 left: parent.left
59 }
61 }
60 width: units.gu(40)
62 width: units.gu(40)
63+
64+ Loader {
65+ id: applicationWindowLoader
66+ anchors.fill: parent
61− sourceComponent: applicationWindowComponent
67+ sourceComponent: applicationWindowComponent
68+ }
62 }
69 }
63
70
64 Rectangle {
71 Rectangle {
@@ -66,30 +73,55 @@ Rectangle {
66 anchors {
73 anchors {
67 top: parent.top
74 top: parent.top
68 bottom: parent.bottom
75 bottom: parent.bottom
69− left: applicationWindowLoader.right
76+ left: appFocus.right
70 right: parent.right
77 right: parent.right
71 }
78 }
72
79
73− Column {
80+ ColumnLayout {
74 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
81 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
75 spacing: units.gu(1)
82 spacing: units.gu(1)
76− Row {
83+
77− anchors { left: parent.left; right: parent.right }
84+ RowLayout {
85+ Layout.fillWidth: true
86+
78 CheckBox {
87 CheckBox {
79− id: surfaceCheckbox; checked: false
88+ id: sessionCheckbox; checked: false
80 onCheckedChanged: {
89 onCheckedChanged: {
81 if (applicationWindowLoader.status !== Loader.Ready)
90 if (applicationWindowLoader.status !== Loader.Ready)
82 return;
91 return;
83
92
84− if (checked && !fakeApplication.surface) {
93+ if (checked && !fakeApplication.session) {
85− fakeApplication.createSurface();
94+ fakeApplication.createSession();
86− } else if (!checked && fakeApplication.surface) {
95+ } else if (!checked && fakeApplication.session) {
87− fakeApplication.surface.release();
96+ fakeApplication.session.release();
88 }
97 }
89 }
98 }
90 }
99 }
91− Label { text: "Surface" }
100+ Label {
101+ text: "Session"
102+ anchors.verticalCenter: parent.verticalCenter
103+ }
92 }
104 }
105+
106+ Rectangle {
107+ border {
108+ color: "black"
109+ width: 1
110+ }
111+ anchors {
112+ left: parent.left
113+ right: parent.right
114+ }
115+ Layout.preferredHeight: sessionControl.height
116+
117+ RecursingChildSessionControl {
118+ id: sessionControl
119+ anchors { left: parent.left; right: parent.right; }
120+
121+ session: fakeSession
122+ }
123+ }
124+
93 ListItem.ItemSelector {
125 ListItem.ItemSelector {
94 id: appStateSelector
126 id: appStateSelector
95 anchors { left: parent.left; right: parent.right }
127 anchors { left: parent.left; right: parent.right }
@@ -100,13 +132,13 @@ Rectangle {
100 "Stopped"]
132 "Stopped"]
101 property int selectedApplicationState: {
133 property int selectedApplicationState: {
102 if (model[selectedIndex] === "Starting") {
134 if (model[selectedIndex] === "Starting") {
103− return ApplicationInfo.Starting;
135+ return ApplicationInfoInterface.Starting;
104 } else if (model[selectedIndex] === "Running") {
136 } else if (model[selectedIndex] === "Running") {
105− return ApplicationInfo.Running;
137+ return ApplicationInfoInterface.Running;
106 } else if (model[selectedIndex] === "Suspended") {
138 } else if (model[selectedIndex] === "Suspended") {
107− return ApplicationInfo.Suspended;
139+ return ApplicationInfoInterface.Suspended;
108 } else {
140 } else {
109− return ApplicationInfo.Stopped;
141+ return ApplicationInfoInterface.Stopped;
110 }
142 }
111 }
143 }
112 onSelectedApplicationStateChanged: {
144 onSelectedApplicationStateChanged: {
@@ -114,6 +146,7 @@ Rectangle {
114 fakeApplication.setState(selectedApplicationState);
146 fakeApplication.setState(selectedApplicationState);
115 }
147 }
116 }
148 }
149+
117 }
150 }
118 }
151 }
119
152
@@ -123,10 +156,10 @@ Rectangle {
123 when: windowShown
156 when: windowShown
124
157
125 // just to make them shorter
158 // just to make them shorter
126− property int appStarting: ApplicationInfo.Starting
159+ property int appStarting: ApplicationInfoInterface.Starting
127− property int appRunning: ApplicationInfo.Running
160+ property int appRunning: ApplicationInfoInterface.Running
128− property int appSuspended: ApplicationInfo.Suspended
161+ property int appSuspended: ApplicationInfoInterface.Suspended
129− property int appStopped: ApplicationInfo.Stopped
162+ property int appStopped: ApplicationInfoInterface.Stopped
130
163
131 function setApplicationState(appState) {
164 function setApplicationState(appState) {
132 switch (appState) {
165 switch (appState) {
@@ -170,6 +203,14 @@ Rectangle {
170 findInterestingApplicationWindowChildren();
203 findInterestingApplicationWindowChildren();
171 }
204 }
172
205
206+ function initSession() {
207+ sessionCheckbox.checked = true;
208+ sessionControl.surfaceCheckbox.checked = true;
209+ }
210+ function cleanupSession() {
211+ sessionCheckbox.checked = false;
212+ }
213+
173 function cleanup() {
214 function cleanup() {
174 forgetApplicationWindowChildren();
215 forgetApplicationWindowChildren();
175
216
@@ -177,10 +218,10 @@ Rectangle {
177 applicationWindowLoader.active = false;
218 applicationWindowLoader.active = false;
178
219
179 appStateSelector.selectedIndex = 0;
220 appStateSelector.selectedIndex = 0;
180− surfaceCheckbox.checked = false;
221+ cleanupSession();
181
222
182− if (fakeApplication.surface)
223+ if (fakeApplication.session)
183− fakeApplication.surface.release();
224+ fakeApplication.session.release();
184
225
185 applicationWindowLoader.active = true;
226 applicationWindowLoader.active = true;
186 }
227 }
@@ -197,7 +238,7 @@ Rectangle {
197 verify(stateGroup.state === "splashScreen");
238 verify(stateGroup.state === "splashScreen");
198
239
199 if (data.swapInitOrder) {
240 if (data.swapInitOrder) {
200− surfaceCheckbox.checked = true;
241+ initSession();
201 } else {
242 } else {
202 setApplicationState(appRunning);
243 setApplicationState(appRunning);
203 }
244 }
@@ -207,14 +248,14 @@ Rectangle {
207 if (data.swapInitOrder) {
248 if (data.swapInitOrder) {
208 setApplicationState(appRunning);
249 setApplicationState(appRunning);
209 } else {
250 } else {
210− surfaceCheckbox.checked = true;
251+ initSession();
211 }
252 }
212
253
213 tryCompare(stateGroup, "state", "surface");
254 tryCompare(stateGroup, "state", "surface");
214 }
255 }
215
256
216 function test_suspendedAppShowsSurface() {
257 function test_suspendedAppShowsSurface() {
217− surfaceCheckbox.checked = true;
258+ initSession();
218 setApplicationState(appRunning);
259 setApplicationState(appRunning);
219
260
220 tryCompare(stateGroup, "state", "surface");
261 tryCompare(stateGroup, "state", "surface");
@@ -228,7 +269,7 @@ Rectangle {
228 }
269 }
229
270
230 function test_killedAppShowsScreenshot() {
271 function test_killedAppShowsScreenshot() {
231− surfaceCheckbox.checked = true;
272+ initSession();
232 setApplicationState(appRunning);
273 setApplicationState(appRunning);
233 tryCompare(stateGroup, "state", "surface");
274 tryCompare(stateGroup, "state", "surface");
234
275
@@ -241,13 +282,13 @@ Rectangle {
241 setApplicationState(appStopped);
282 setApplicationState(appStopped);
242
283
243 tryCompare(stateGroup, "state", "screenshot");
284 tryCompare(stateGroup, "state", "screenshot");
244− tryCompare(fakeApplication, "surface", null);
285+ tryCompare(fakeApplication, "session", null);
245 }
286 }
246
287
247 function test_restartApp() {
288 function test_restartApp() {
248 var screenshotImage = findChild(applicationWindowLoader.item, "screenshotImage");
289 var screenshotImage = findChild(applicationWindowLoader.item, "screenshotImage");
249
290
250− surfaceCheckbox.checked = true;
291+ initSession();
251 setApplicationState(appRunning);
292 setApplicationState(appRunning);
252 tryCompare(stateGroup, "state", "surface");
293 tryCompare(stateGroup, "state", "surface");
253 waitUntilTransitionsEnd();
294 waitUntilTransitionsEnd();
@@ -259,28 +300,28 @@ Rectangle {
259
300
260 tryCompare(stateGroup, "state", "screenshot");
301 tryCompare(stateGroup, "state", "screenshot");
261 waitUntilTransitionsEnd();
302 waitUntilTransitionsEnd();
262− tryCompare(fakeApplication, "surface", null);
303+ tryCompare(fakeApplication, "session", null);
263
304
264 // and restart it
305 // and restart it
265 setApplicationState(appStarting);
306 setApplicationState(appStarting);
266
307
267 waitUntilTransitionsEnd();
308 waitUntilTransitionsEnd();
268 verify(stateGroup.state === "screenshot");
309 verify(stateGroup.state === "screenshot");
269− verify(fakeApplication.surface === null);
310+ verify(fakeSession === null);
270
311
271 setApplicationState(appRunning);
312 setApplicationState(appRunning);
272
313
273 waitUntilTransitionsEnd();
314 waitUntilTransitionsEnd();
274 verify(stateGroup.state === "screenshot");
315 verify(stateGroup.state === "screenshot");
275
316
276− surfaceCheckbox.checked = true;
317+ initSession();
277
318
278 tryCompare(stateGroup, "state", "surface");
319 tryCompare(stateGroup, "state", "surface");
279 tryCompare(screenshotImage, "status", Image.Null);
320 tryCompare(screenshotImage, "status", Image.Null);
280 }
321 }
281
322
282 function test_appCrashed() {
323 function test_appCrashed() {
283− surfaceCheckbox.checked = true;
324+ initSession();
284 setApplicationState(appRunning);
325 setApplicationState(appRunning);
285 tryCompare(stateGroup, "state", "surface");
326 tryCompare(stateGroup, "state", "surface");
286 waitUntilTransitionsEnd();
327 waitUntilTransitionsEnd();
@@ -289,39 +330,39 @@ Rectangle {
289 setApplicationState(appStopped);
330 setApplicationState(appStopped);
290
331
291 tryCompare(stateGroup, "state", "screenshot");
332 tryCompare(stateGroup, "state", "screenshot");
292− tryCompare(fakeApplication, "surface", null);
333+ tryCompare(fakeApplication, "session", null);
293 }
334 }
294
335
295 function test_keepSurfaceWhileInvisible() {
336 function test_keepSurfaceWhileInvisible() {
296− surfaceCheckbox.checked = true;
337+ initSession();
297 setApplicationState(appRunning);
338 setApplicationState(appRunning);
298 tryCompare(stateGroup, "state", "surface");
339 tryCompare(stateGroup, "state", "surface");
299 waitUntilTransitionsEnd();
340 waitUntilTransitionsEnd();
300− verify(fakeApplication.surface !== null);
341+ verify(fakeSession.surface !== null);
301
342
302 applicationWindowLoader.item.visible = false;
343 applicationWindowLoader.item.visible = false;
303
344
304 waitUntilTransitionsEnd();
345 waitUntilTransitionsEnd();
305 verify(stateGroup.state === "surface");
346 verify(stateGroup.state === "surface");
306− verify(fakeApplication.surface !== null);
347+ verify(fakeSession.surface !== null);
307
348
308 applicationWindowLoader.item.visible = true;
349 applicationWindowLoader.item.visible = true;
309
350
310 waitUntilTransitionsEnd();
351 waitUntilTransitionsEnd();
311 verify(stateGroup.state === "surface");
352 verify(stateGroup.state === "surface");
312− verify(fakeApplication.surface !== null);
353+ verify(fakeSession.surface !== null);
313 }
354 }
314
355
315 function test_touchesReachSurfaceWhenItsShown() {
356 function test_touchesReachSurfaceWhenItsShown() {
316 setApplicationState(appRunning);
357 setApplicationState(appRunning);
317− surfaceCheckbox.checked = true;
358+ initSession();
318
359
319 tryCompare(stateGroup, "state", "surface");
360 tryCompare(stateGroup, "state", "surface");
320
361
321 waitUntilTransitionsEnd();
362 waitUntilTransitionsEnd();
322
363
323 // Because doing stuff in C++ is a PITA we keep the counter in the interal qml impl.
364 // Because doing stuff in C++ is a PITA we keep the counter in the interal qml impl.
324− var fakeSurface = findChild(fakeApplication.surface, "fakeSurfaceQML");
365+ var fakeSurface = findChild(fakeSession.surface, "fakeSurfaceQML");
325 fakeSurface.touchPressCount = 0;
366 fakeSurface.touchPressCount = 0;
326 fakeSurface.touchReleaseCount = 0;
367 fakeSurface.touchReleaseCount = 0;
327
368
@@ -333,14 +374,25 @@ Rectangle {
333 }
374 }
334
375
335 function test_showNothingOnSuddenSurfaceLoss() {
376 function test_showNothingOnSuddenSurfaceLoss() {
336− surfaceCheckbox.checked = true;
377+ initSession();
337 setApplicationState(appRunning);
378 setApplicationState(appRunning);
338 tryCompare(stateGroup, "state", "surface");
379 tryCompare(stateGroup, "state", "surface");
339 waitUntilTransitionsEnd();
380 waitUntilTransitionsEnd();
340
381
341− surfaceCheckbox.checked = false;
382+ cleanupSession();
342
383
343 verify(stateGroup.state === "void");
384 verify(stateGroup.state === "void");
344 }
385 }
386+
387+ // should be forcing active focus when interactive changes,
388+ // which will cause a FocusScope higher in the object hierarchy tp be given the focus
389+ function test_forceActiveFocusFollowsInterative() {
390+ fakeApplication.createSession();
391+ applicationWindowLoader.item.interactive = false;
392+ applicationWindowLoader.item.interactive = true;
393+ fakeSession.createSurface();
394+
395+ compare(appFocus.focus, true);
396+ }
345 }
397 }
346}
398}
tests/qmltests/Stages/tst_PhoneStage.qml+1−1
@@ -64,7 +64,7 @@ Item {
64 anchors { left: parent.left; right: parent.right }
64 anchors { left: parent.left; right: parent.right }
65 text: "Stop Selected"
65 text: "Stop Selected"
66 onClicked: {
66 onClicked: {
67− ApplicationManager.get(appList.selectedAppIndex).setState(ApplicationInfo.Stopped);
67+ ApplicationManager.get(appList.selectedAppIndex).setState(ApplicationInfoInterface.Stopped);
68 }
68 }
69 }
69 }
70 }
70 }
tests/qmltests/Stages/tst_SessionContainer.qmlnew file+267
@@ -0,0 +1,267 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.1
18+import QtQuick.Layouts 1.1
19+import QtTest 1.0
20+import Unity.Test 0.1 as UT
21+import Ubuntu.Components 0.1
22+import Unity.Application 0.1
23+import "../../../qml/Stages"
24+
25+Rectangle {
26+ color: "red"
27+ id: root
28+ width: units.gu(80)
29+ height: units.gu(70)
30+
31+ Connections {
32+ target: sessionContainerLoader.status === Loader.Ready ? sessionContainerLoader.item : null
33+ onSessionChanged: {
34+ sessionCheckbox.checked = sessionContainerLoader.item.session !== null
35+ }
36+ }
37+
38+ Component {
39+ id: sessionContainerComponent
40+
41+ SessionContainer {
42+ id: sessionContainer
43+ anchors.fill: parent
44+ }
45+ }
46+
47+ Loader {
48+ id: sessionContainerLoader
49+ anchors {
50+ top: parent.top
51+ bottom: parent.bottom
52+ left: parent.left
53+ }
54+ width: units.gu(40)
55+ sourceComponent: sessionContainerComponent
56+ }
57+
58+ Rectangle {
59+ color: "white"
60+ anchors {
61+ top: parent.top
62+ bottom: parent.bottom
63+ left: sessionContainerLoader.right
64+ right: parent.right
65+ }
66+
67+ ColumnLayout {
68+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
69+ spacing: units.gu(1)
70+
71+ RowLayout {
72+ Layout.fillWidth: true
73+
74+ CheckBox {
75+ id: sessionCheckbox;
76+ checked: false;
77+ onCheckedChanged: {
78+ if (sessionContainerLoader.status !== Loader.Ready)
79+ return;
80+
81+ if (checked) {
82+ var fakeSession = SessionManager.createSession("music-player", Qt.resolvedUrl("../Dash/artwork/music-player-design.png"));
83+ sessionContainerLoader.item.session = fakeSession;
84+ fakeSession.createSurface();
85+ } else {
86+ sessionContainerLoader.item.session.release();
87+ }
88+ }
89+ }
90+
91+ Label {
92+ text: "session"
93+ anchors.verticalCenter: parent.verticalCenter
94+ }
95+ }
96+
97+ Rectangle {
98+ border {
99+ color: "black"
100+ width: 1
101+ }
102+ anchors {
103+ left: parent.left
104+ right: parent.right
105+ }
106+ Layout.preferredHeight: sessionChildrenControl.height
107+
108+ RecursingChildSessionControl {
109+ id: sessionChildrenControl
110+ anchors { left: parent.left; right: parent.right; }
111+
112+ session: sessionContainerLoader.item ? sessionContainerLoader.item.session : null
113+ }
114+ }
115+ }
116+ }
117+
118+ SignalSpy {
119+ id: sessionSpy
120+ target: SessionManager
121+ signalName: "sessionStopping"
122+ }
123+
124+ UT.UnityTestCase {
125+ id: testCase
126+ name: "SessionContainer"
127+
128+ function init() {
129+ // reload our test subject to get it in a fresh state once again
130+ sessionContainerLoader.active = false;
131+ sessionCheckbox.checked = false;
132+ sessionContainerLoader.active = true;
133+
134+ tryCompare(sessionContainerLoader.item, "session", null);
135+ sessionSpy.clear();
136+ }
137+
138+ when: windowShown
139+
140+ function test_addChildSession_data() {
141+ return [ { tag: "count=1", count: 1 },
142+ { tag: "count=4", count: 4 } ];
143+ }
144+
145+ function test_addChildSession(data) {
146+ sessionCheckbox.checked = true;
147+ var sessionContainer = sessionContainerLoader.item;
148+ compare(sessionContainer.childSessions.count(), 0);
149+
150+ var i;
151+ var sessions = [];
152+ for (i = 0; i < data.count; i++) {
153+ var session = ApplicationTest.addChildSession(sessionContainer.session,
154+ "gallery");
155+ session.createSurface();
156+ sessionContainer.session.addChildSession(session);
157+ compare(sessionContainer.childSessions.count(), i+1);
158+
159+ sessions.push(session);
160+ }
161+
162+ for (i = data.count-1; i >= 0; i--) {
163+ ApplicationTest.removeSession(sessions[i]);
164+ tryCompareFunction(function() { return sessionContainer.childSessions.count(); }, i);
165+ }
166+ tryCompare(sessionSpy, "count", data.count);
167+ }
168+
169+ function test_nestedChildSessions_data() {
170+ return [ { tag: "depth=2", depth: 2 },
171+ { tag: "depth=8", depth: 8 }
172+ ];
173+ }
174+
175+ function test_nestedChildSessions(data) {
176+ sessionCheckbox.checked = true;
177+ var sessionContainer = sessionContainerLoader.item;
178+ compare(sessionContainer.childSessions.count(), 0);
179+
180+ var i;
181+ var sessions = [];
182+ var lastSession = sessionContainer.session;
183+ var delegate;
184+ var container = sessionContainer;
185+ for (i = 0; i < data.depth; i++) {
186+ var session = ApplicationTest.addChildSession(lastSession,
187+ "gallery");
188+ session.createSurface();
189+ lastSession.addChildSession(session);
190+ compare(container.childSessions.count(), 1);
191+ sessions.push(session);
192+
193+ delegate = findChild(container, "childDelegate0");
194+ container = findChild(delegate, "sessionContainer");
195+ lastSession = session;
196+ }
197+
198+ for (i = data.depth-1; i >= 0; i--) {
199+ ApplicationTest.removeSession(sessions[i]);
200+ }
201+
202+ tryCompareFunction(function() { return sessionContainer.childSessions.count(); }, 0);
203+ tryCompare(sessionSpy, "count", data.depth);
204+ }
205+
206+ function test_childrenAdjustForParentSize() {
207+ sessionCheckbox.checked = true;
208+ var sessionContainer = sessionContainerLoader.item;
209+
210+ var session = ApplicationTest.addChildSession(sessionContainer.session,
211+ "gallery");
212+ session.createSurface();
213+ sessionContainer.session.addChildSession(session);
214+
215+ var delegate = findChild(sessionContainer, "childDelegate0");
216+ var childContainer = findChild(delegate, "sessionContainer");
217+
218+ tryCompareFunction(function() { return childContainer.height === sessionContainer.height; }, true);
219+ tryCompareFunction(function() { return childContainer.width === sessionContainer.width; }, true);
220+ tryCompareFunction(function() { return childContainer.x === 0; }, true);
221+ tryCompareFunction(function() { return childContainer.y === 0; }, true);
222+
223+ sessionContainer.anchors.margins = units.gu(2);
224+
225+ tryCompareFunction(function() { return childContainer.height === sessionContainer.height; }, true);
226+ tryCompareFunction(function() { return childContainer.width === sessionContainer.width; }, true);
227+ tryCompareFunction(function() { return childContainer.x === 0; }, true);
228+ tryCompareFunction(function() { return childContainer.y === 0; }, true);
229+ }
230+
231+ function isContainerAnimating(container) {
232+ var animation = findInvisibleChild(container, "sessionAnimation");
233+ if (!animation) return false;
234+
235+ var animating = false;
236+ for (var i = 0; i < animation.transitions.length; ++i) {
237+ if (animation.transitions[i].running) {
238+ return true;
239+ }
240+ }
241+ return false;
242+ }
243+
244+ function test_childrenAnimate() {
245+ sessionCheckbox.checked = true;
246+ var sessionContainer = sessionContainerLoader.item;
247+
248+ var session = ApplicationTest.addChildSession(sessionContainer.session,
249+ "gallery");
250+
251+ var delegate = findChild(sessionContainer, "childDelegate0");
252+ var childContainer = findChild(delegate, "sessionContainer");
253+
254+ // wait for animation to begin
255+ tryCompareFunction(function() { return isContainerAnimating(childContainer); }, true);
256+ // wait for animation to end
257+ tryCompareFunction(function() { return isContainerAnimating(childContainer); }, false);
258+
259+ ApplicationTest.removeSession(session);
260+
261+ // wait for animation to begin
262+ tryCompareFunction(function() { return isContainerAnimating(childContainer); }, true);
263+ // wait for animation to end
264+ tryCompareFunction(function() { return isContainerAnimating(childContainer); }, false);
265+ }
266+ }
267+}
tests/qmltests/Stages/tst_SurfaceContainer.qml+28−43
@@ -28,43 +28,6 @@ Rectangle {
28 width: units.gu(70)
28 width: units.gu(70)
29 height: units.gu(70)
29 height: units.gu(70)
30
30
31− Component {
32− id: fakeSurfaceComponent
33− Rectangle {
34− color: "green"
35−
36− Rectangle {
37− color: "blue"
38− anchors.fill: parent
39− anchors.margins: units.gu(2)
40− Text {
41− anchors.fill: parent
42− text: "Surface"
43− color: "green"
44− font.bold: true
45− fontSizeMode: Text.Fit
46− minimumPixelSize: 10; font.pixelSize: 200
47− verticalAlignment: Text.AlignVCenter
48− }
49− }
50−
51− width: units.gu(1)
52− height: units.gu(1)
53−
54− property int type: MirSurfaceItem.Normal
55− property int state: MirSurfaceItem.Restored
56− property string name: "Fake Surface"
57− property Item parentSurface: null
58− property list<Item> childSurfaces
59− function release() {}
60− signal removed();
61− }
62− }
63−
64− Item {
65− id: tempSurfaceHolder
66− }
67−
68 Component {
31 Component {
69 id: surfaceContainerComponent
32 id: surfaceContainerComponent
70 SurfaceContainer {
33 SurfaceContainer {
@@ -98,19 +61,20 @@ Rectangle {
98 Row {
61 Row {
99 anchors { left: parent.left; right: parent.right }
62 anchors { left: parent.left; right: parent.right }
100 CheckBox {
63 CheckBox {
101− id: surfaceCheckbox; checked: false;
64+ id: surfaceCheckbox;
65+ checked: false;
102 onCheckedChanged: {
66 onCheckedChanged: {
103 if (surfaceContainerLoader.status !== Loader.Ready)
67 if (surfaceContainerLoader.status !== Loader.Ready)
104 return;
68 return;
105
69
106 if (checked) {
70 if (checked) {
107− var fakeSurface = fakeSurfaceComponent.createObject(tempSurfaceHolder);
71+ var fakeSurface = SurfaceManager.createSurface("fake-surface",
72+ MirSurfaceItem.Normal,
73+ MirSurfaceItem.Restored,
74+ Qt.resolvedUrl("../Dash/artwork/music-player-design.png"));
108 surfaceContainerLoader.item.surface = fakeSurface;
75 surfaceContainerLoader.item.surface = fakeSurface;
109 } else {
76 } else {
110− var fakeSurface = surfaceContainerLoader.item.surface;
77+ ApplicationTest.removeSurface(surfaceContainerLoader.item.surface);
111− surfaceContainerLoader.item.surface = null;
112− fakeSurface.parent = null;
113− fakeSurface.destroy();
114 }
78 }
115 }
79 }
116 }
80 }
@@ -124,6 +88,12 @@ Rectangle {
124 }
88 }
125 }
89 }
126
90
91+ SignalSpy {
92+ id: surfaceSpy
93+ target: SurfaceManager
94+ signalName: "surfaceDestroyed"
95+ }
96+
127 UT.UnityTestCase {
97 UT.UnityTestCase {
128 id: testCase
98 id: testCase
129 name: "SurfaceContainer"
99 name: "SurfaceContainer"
@@ -134,6 +104,9 @@ Rectangle {
134 surfaceContainerLoader.active = false;
104 surfaceContainerLoader.active = false;
135 surfaceCheckbox.checked = false;
105 surfaceCheckbox.checked = false;
136 surfaceContainerLoader.active = true;
106 surfaceContainerLoader.active = true;
107+
108+ tryCompare(surfaceContainerLoader.item, "surface", null);
109+ surfaceSpy.clear();
137 }
110 }
138
111
139 /*
112 /*
@@ -150,5 +123,17 @@ Rectangle {
150 compare(fakeSurface.width, surfaceContainerLoader.item.width);
123 compare(fakeSurface.width, surfaceContainerLoader.item.width);
151 compare(fakeSurface.height, surfaceContainerLoader.item.height);
124 compare(fakeSurface.height, surfaceContainerLoader.item.height);
152 }
125 }
126+
127+ function test_animateRemoval() {
128+ surfaceCheckbox.checked = true;
129+ var surfaceContainer = surfaceContainerLoader.item;
130+
131+ verify(surfaceContainer.surface !== null);
132+
133+ ApplicationTest.removeSurface(surfaceContainer.surface);
134+
135+ compare(surfaceContainer.state, "zombie");
136+ tryCompare(surfaceContainer, "surface", null);
137+ }
153 }
138 }
154}
139}
tests/qmltests/tst_Shell.qml+9−9
@@ -144,7 +144,7 @@ Item {
144 verify(mainAppId != "");
144 verify(mainAppId != "");
145 var mainApp = ApplicationManager.findApplication(mainAppId);
145 var mainApp = ApplicationManager.findApplication(mainAppId);
146 verify(mainApp);
146 verify(mainApp);
147− tryCompare(mainApp, "state", ApplicationInfo.Running);
147+ tryCompare(mainApp, "state", ApplicationInfoInterface.Running);
148
148
149 // Try to suspend while proximity is engaged...
149 // Try to suspend while proximity is engaged...
150 Powerd.displayPowerStateChange(Powerd.Off, Powerd.Proximity);
150 Powerd.displayPowerStateChange(Powerd.Off, Powerd.Proximity);
@@ -157,7 +157,7 @@ Item {
157 tryCompare(greeter, "showProgress", 1);
157 tryCompare(greeter, "showProgress", 1);
158
158
159 tryCompare(ApplicationManager, "suspended", true);
159 tryCompare(ApplicationManager, "suspended", true);
160− compare(mainApp.state, ApplicationInfo.Suspended);
160+ compare(mainApp.state, ApplicationInfoInterface.Suspended);
161
161
162 // And wake up
162 // And wake up
163 Powerd.displayPowerStateChange(Powerd.On, 0);
163 Powerd.displayPowerStateChange(Powerd.On, 0);
@@ -166,7 +166,7 @@ Item {
166 // Swipe away greeter to focus app
166 // Swipe away greeter to focus app
167 swipeAwayGreeter();
167 swipeAwayGreeter();
168 tryCompare(ApplicationManager, "suspended", false);
168 tryCompare(ApplicationManager, "suspended", false);
169− compare(mainApp.state, ApplicationInfo.Running);
169+ compare(mainApp.state, ApplicationInfoInterface.Running);
170 tryCompare(ApplicationManager, "focusedApplicationId", mainAppId);
170 tryCompare(ApplicationManager, "focusedApplicationId", mainAppId);
171 }
171 }
172
172
@@ -237,9 +237,9 @@ Item {
237 function test_surfaceLosesFocusWhilePanelIsOpen() {
237 function test_surfaceLosesFocusWhilePanelIsOpen() {
238 var app = ApplicationManager.startApplication("dialer-app");
238 var app = ApplicationManager.startApplication("dialer-app");
239 // wait until the app is fully loaded (ie, real surface replaces splash screen)
239 // wait until the app is fully loaded (ie, real surface replaces splash screen)
240− tryCompareFunction(function() { return app.surface != null }, true);
240+ tryCompareFunction(function() { return app.session !== null && app.session.surface !== null }, true);
241
241
242− tryCompare(app.surface, "focus", true);
242+ tryCompare(app.session.surface, "focus", true);
243
243
244 // Drag the indicators panel half-open
244 // Drag the indicators panel half-open
245 var touchX = shell.width / 2;
245 var touchX = shell.width / 2;
@@ -250,7 +250,7 @@ Item {
250 true /* beginTouch */, false /* endTouch */);
250 true /* beginTouch */, false /* endTouch */);
251 verify(indicators.partiallyOpened);
251 verify(indicators.partiallyOpened);
252
252
253− tryCompare(app.surface, "focus", false);
253+ tryCompare(app.session.surface, "focus", false);
254
254
255 // And finish getting it open
255 // And finish getting it open
256 touchFlick(indicators,
256 touchFlick(indicators,
@@ -259,11 +259,11 @@ Item {
259 false /* beginTouch */, true /* endTouch */);
259 false /* beginTouch */, true /* endTouch */);
260 tryCompare(indicators, "fullyOpened", true);
260 tryCompare(indicators, "fullyOpened", true);
261
261
262− tryCompare(app.surface, "focus", false);
262+ tryCompare(app.session.surface, "focus", false);
263
263
264 dragToCloseIndicatorsPanel();
264 dragToCloseIndicatorsPanel();
265
265
266− tryCompare(app.surface, "focus", true);
266+ tryCompare(app.session.surface, "focus", true);
267 }
267 }
268
268
269 // Wait for the whole UI to settle down
269 // Wait for the whole UI to settle down
@@ -361,7 +361,7 @@ Item {
361
361
362 var app = ApplicationManager.startApplication("dialer-app");
362 var app = ApplicationManager.startApplication("dialer-app");
363 // wait until the app is fully loaded (ie, real surface replaces splash screen)
363 // wait until the app is fully loaded (ie, real surface replaces splash screen)
364− tryCompareFunction(function() { return app.surface != null }, true);
364+ tryCompareFunction(function() { return app.session !== null && app.session.surface !== null }, true);
365
365
366 // Minimize the application we just launched
366 // Minimize the application we just launched
367 swipeFromLeftEdge(units.gu(26) + 1);
367 swipeFromLeftEdge(units.gu(26) + 1);