on xenial help sign in
SpreadDelegate - properly transition between splash screen, surface and screenshot

- A new component, ApplicationWindow, was created to hold the splash+surface+screenshot logic originally in the SpreadDelegate. Now the responsibility of SpreadDelegate is just to do the vertical swipe to close the app. - qml tests were added for both SpreadDelegate and ApplicationWindow - Fixed UnityTestCase.tap()

commit64f3a3af417243e2412d07f8dd2505dcffd20f9c authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 11 Aug 2014, 10:37 (12 years ago) parent6ef3e1395bae9b
36 files changed+1288−687
debian/control+1−1 include/paths.h.in+8 qml/Dash/graphics/phone/screenshots/vkb_portrait.png qml/Stages/AppSurfaceContainer.qml−96 qml/Stages/ApplicationWindow.qml+229 qml/Stages/PhoneStage.qml+16−4 qml/Stages/SpreadDelegate.qml+34−58 qml/Stages/TabletStage.qml+1 qml/Stages/TransformedSpreadDelegate.qml+1−1 qml/Stages/TransformedTabletSpreadDelegate.qml+2−2 tests/mocks/Unity/Application/Application.qmltypes−19 tests/mocks/Unity/Application/ApplicationImage.cpp−123 tests/mocks/Unity/Application/ApplicationImage.h−79 tests/mocks/Unity/Application/ApplicationInfo.cpp+91−14 tests/mocks/Unity/Application/ApplicationInfo.h+44−43 tests/mocks/Unity/Application/ApplicationManager.cpp+69−70 tests/mocks/Unity/Application/ApplicationManager.h+6−2 tests/mocks/Unity/Application/CMakeLists.txt+1−3 tests/mocks/Unity/Application/InputFilterArea.qml−21 tests/mocks/Unity/Application/MirSurfaceItem.cpp+89−13 tests/mocks/Unity/Application/MirSurfaceItem.h+14−11 tests/mocks/Unity/Application/MirSurfaceItem.qml+46 tests/mocks/Unity/Application/OSKController.qml−20 tests/mocks/Unity/Application/SurfaceManager.cpp+14−3 tests/mocks/Unity/Application/SurfaceManager.h+1−2 tests/mocks/Unity/Application/VirtualKeyboard.cpp−55 tests/mocks/Unity/Application/VirtualKeyboard.h−35 tests/mocks/Unity/Application/VirtualKeyboard.qml+34 tests/mocks/Unity/Application/plugin.cpp−3 tests/mocks/Unity/Application/qmldir−3 tests/plugins/Unity/Launcher/launchermodeltest.cpp+3 tests/qmltests/CMakeLists.txt+2 tests/qmltests/Stages/tst_ApplicationWindow.qml+359 tests/qmltests/Stages/tst_PhoneStage.qml+33−4 tests/qmltests/Stages/tst_SpreadDelegate.qml+185 tests/utils/modules/Unity/Test/UnityTestCase.qml+5−2
debian/control+1−1
@@ -24,7 +24,7 @@ Build-Depends: cmake,
2424 libpulse-dev,
2525 libqmenumodel-dev (>= 0.2.8),
2626 libqt5xmlpatterns5-dev,
27− libunity-api-dev (>= 7.88),
27+ libunity-api-dev (>= 7.89),
2828 libusermetricsoutput1-dev,
2929 libxcb1-dev,
3030 pkg-config,
include/paths.h.in+8
@@ -80,6 +80,14 @@ inline QStringList fallbackImportPaths() {
8080 return paths;
8181}
8282
83+inline QString mockPluginsDir() {
84+ if (isRunningInstalled()) {
85+ return QString("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
86+ } else {
87+ return QString("@CMAKE_BINARY_DIR@/tests/mocks");
88+ }
89+}
90+
8391inline QStringList shellDataDirs() {
8492 QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
8593 if (!isRunningInstalled()) {
qml/Dash/graphics/phone/screenshots/vkb_portrait.png

Binary file not shown.

qml/Stages/AppSurfaceContainer.qmldeleted−96
@@ -1,96 +0,0 @@
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−SurfaceContainer {
21− id: container
22− property var promptSurfaces
23−
24− property bool appHasCreatedASurface: false
25−
26− onSurfaceChanged: {
27− if (surface) {
28− if (!appHasCreatedASurface) {
29− surface.visible = false; // hide until splash screen removed
30− appHasCreatedASurface = true;
31− }
32− }
33− }
34−
35− function revealSurface() {
36− surface.visible = true;
37− splashLoader.source = "";
38− }
39−
40− Timer { //FIXME - need to delay removing splash screen to allow surface resize to complete
41− id: surfaceRevealDelay
42− interval: 100
43− onTriggered: surfaceContainer.revealSurface()
44− }
45−
46− Loader {
47− z: 3
48− id: splashLoader
49− anchors.fill: parent
50− }
51−
52− Repeater {
53− model: container.promptSurfaces
54−
55− delegate: SurfaceContainer {
56− anchors {
57− fill: container
58− topMargin: container.surface.anchors.topMargin
59− rightMargin: container.surface.anchors.rightMargin
60− bottomMargin: container.surface.anchors.bottomMargin
61− leftMargin: container.surface.anchors.leftMargin
62− }
63−
64− z: 4 + index
65− surface: modelData
66−
67− Component.onCompleted: {
68− animateIn();
69− }
70− }
71− }
72−
73− StateGroup {
74− id: appSurfaceState
75− states: [
76− State {
77− name: "noSurfaceYet"
78− when: !surfaceContainer.appHasCreatedASurface
79− StateChangeScript {
80− script: { splashLoader.setSource("Splash.qml", { "name": model.name, "image": model.icon }); }
81− }
82− },
83− State {
84− name: "hasSurface"
85− when: surfaceContainer.appHasCreatedASurface && (surfaceContainer.surface !== null)
86− StateChangeScript { script: { surfaceRevealDelay.start(); } }
87− },
88− State {
89− name: "surfaceLostButAppStillAlive"
90− when: surfaceContainer.appHasCreatedASurface && (surfaceContainer.surface === null)
91− // TODO - use app snapshot
92− }
93− ]
94− state: "noSurfaceYet"
95− }
96−}
qml/Stages/ApplicationWindow.qmlnew file+229
@@ -0,0 +1,229 @@
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 Ubuntu.Components 1.1
19+import Unity.Application 0.1
20+
21+Item {
22+ id: root
23+
24+ // to be read from outside
25+ readonly property bool fullscreen: application ? application.fullscreen : false
26+
27+ // to be set from outside
28+ property bool interactive: true
29+ property QtObject application
30+
31+ // helpers so that we don't have to check for the existence of an application everywhere
32+ // (in order to avoid breaking qml binding due to a javascript exception)
33+ readonly property string name: application ? application.name : ""
34+ readonly property url icon: application ? application.icon : ""
35+ readonly property Item surface: application ? application.surface : null
36+ readonly property int applicationState: application ? application.state : -1
37+ readonly property var promptSurfaces: application ? application.promptSurfaces : null
38+
39+ property bool _needToTakeScreenshot:
40+ root.surface && root._surfaceInitialized && screenshotImage.status === Image.Null
41+ && root.applicationState === ApplicationInfo.Stopped
42+ on_NeedToTakeScreenshotChanged: {
43+ if (_needToTakeScreenshot) {
44+ application.updateScreenshot();
45+ }
46+ }
47+
48+ //FIXME - this is a hack to avoid the first few rendered frames as they
49+ // might show the UI accommodating due to surface resizes on startup.
50+ // Remove this when possible
51+ property bool _surfaceInitialized: false
52+ onSurfaceChanged: {
53+ if (surface) {
54+ _surfaceInitTimer.start();
55+ } else {
56+ _surfaceInitialized = false;
57+ }
58+ }
59+ Timer {
60+ id: _surfaceInitTimer
61+ interval: 100
62+ onTriggered: { if (root.surface) {root._surfaceInitialized = true;} }
63+ }
64+
65+ SurfaceContainer {
66+ id: surfaceContainer
67+ objectName: "surfaceContainer"
68+ anchors.fill: parent
69+ surface: root.surface
70+
71+ Binding {
72+ target: surface
73+ property: "enabled"
74+ value: root.interactive
75+ }
76+ Binding {
77+ target: surface
78+ property: "focus"
79+ value: root.interactive
80+ }
81+
82+ Connections {
83+ target: surface
84+ // FIXME: I would rather not need to do this, but currently it doesn't get
85+ // active focus without it and I don't know why.
86+ onFocusChanged: forceSurfaceActiveFocusIfReady();
87+ onParentChanged: forceSurfaceActiveFocusIfReady();
88+ onEnabledChanged: forceSurfaceActiveFocusIfReady();
89+ function forceSurfaceActiveFocusIfReady() {
90+ if (surface.focus && surface.parent === surfaceContainer && surface.enabled) {
91+ surface.forceActiveFocus();
92+ }
93+ }
94+ }
95+ }
96+
97+ Image {
98+ id: screenshotImage
99+ source: root.application ? root.application.screenshot : ""
100+ anchors.fill: parent
101+ }
102+
103+ Loader {
104+ id: splashLoader
105+ visible: active
106+ active: false
107+ anchors.fill: surfaceContainer
108+ sourceComponent: Component {
109+ Splash { name: root.name; image: root.icon }
110+ }
111+ }
112+
113+ Repeater {
114+ model: root.promptSurfaces
115+
116+ delegate: SurfaceContainer {
117+ anchors {
118+ fill: container
119+ }
120+
121+ surface: modelData
122+
123+ Component.onCompleted: {
124+ animateIn();
125+ }
126+ }
127+ }
128+
129+ StateGroup {
130+ objectName: "applicationWindowStateGroup"
131+ states: [
132+ State {
133+ name: "splashScreen"
134+ when:
135+ (!root.surface || !root._surfaceInitialized)
136+ &&
137+ screenshotImage.status !== Image.Ready
138+ },
139+ State {
140+ name: "surface"
141+ when:
142+ (root.surface && root._surfaceInitialized)
143+ &&
144+ (root.applicationState !== ApplicationInfo.Stopped
145+ || screenshotImage.status !== Image.Ready)
146+ },
147+ State {
148+ name: "screenshot"
149+ when:
150+ screenshotImage.status === Image.Ready
151+ &&
152+ (
153+ root.applicationState === ApplicationInfo.Stopped
154+ || !root.surface || !root._surfaceInitialized
155+ )
156+ }
157+ ]
158+
159+ // For testing purposes
160+ property bool transitioning: defaultToSplash.running
161+ || splashToSurface.running
162+ || surfaceToSplash.running
163+ || surfaceToScreenshot.running
164+ || screenshotToSurface.running
165+
166+ transitions: [
167+ Transition {
168+ id: defaultToSplash
169+ from: ""; to: "splashScreen"
170+ PropertyAction { target: splashLoader; property: "active"; value: true }
171+ },
172+ Transition {
173+ id: splashToSurface
174+ from: "splashScreen"; to: "surface"
175+ SequentialAnimation {
176+ PropertyAction { target: surfaceContainer
177+ property: "visible"; value: true }
178+ UbuntuNumberAnimation { target: splashLoader; property: "opacity";
179+ from: 1.0; to: 0.0
180+ duration: UbuntuAnimation.BriskDuration }
181+ PropertyAction { target: splashLoader; property: "active"; value: false }
182+ }
183+ },
184+ Transition {
185+ id: surfaceToSplash
186+ from: "surface"; to: "splashScreen"
187+ SequentialAnimation {
188+ PropertyAction { target: splashLoader; property: "active"; value: true }
189+ PropertyAction { target: surfaceContainer
190+ property: "visible"; value: true }
191+ UbuntuNumberAnimation { target: splashLoader; property: "opacity";
192+ from: 0.0; to: 1.0
193+ duration: UbuntuAnimation.BriskDuration }
194+ }
195+ },
196+ Transition {
197+ id: surfaceToScreenshot
198+ from: "surface"; to: "screenshot"
199+ SequentialAnimation {
200+ PropertyAction { target: screenshotImage
201+ property: "visible"; value: true }
202+ UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
203+ from: 0.0; to: 1.0
204+ duration: UbuntuAnimation.BriskDuration }
205+ PropertyAction { target: surfaceContainer
206+ property: "visible"; value: false }
207+ ScriptAction { script: { if (root.surface) { root.surface.release(); } } }
208+ }
209+ },
210+ Transition {
211+ id: screenshotToSurface
212+ from: "screenshot"; to: "surface"
213+ SequentialAnimation {
214+ PropertyAction { target: surfaceContainer
215+ property: "visible"; value: true }
216+ UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
217+ from: 1.0; to: 0.0
218+ duration: UbuntuAnimation.BriskDuration }
219+ PropertyAction { target: screenshotImage
220+ property: "visible"; value: false }
221+ ScriptAction { script: {
222+ if (root.application.screenshot) { root.application.discardScreenshot(); }
223+ } }
224+ }
225+ }
226+ ]
227+ }
228+
229+}
qml/Stages/PhoneStage.qml+16−4
@@ -110,7 +110,8 @@ Rectangle {
110110 id: spreadView
111111 objectName: "spreadView"
112112 anchors.fill: parent
113− interactive: (spreadDragArea.status == DirectionalDragArea.Recognized || phase > 1) && draggedIndex == -1
113+ interactive: (spreadDragArea.status == DirectionalDragArea.Recognized || phase > 1)
114+ && numDelegatesBeingDragged === 0
114115 contentWidth: spreadRow.width - shift
115116 contentX: -shift
116117
@@ -148,7 +149,7 @@ Rectangle {
148149 property int phase: 0
149150
150151 property int selectedIndex: -1
151− property int draggedIndex: -1
152+ property int numDelegatesBeingDragged: 0
152153 property int closingIndex: -1
153154
154155 property bool focusChanging: false
@@ -269,7 +270,7 @@ Rectangle {
269270 swipeToCloseEnabled: spreadView.interactive
270271 maximizedAppTopMargin: root.maximizedAppTopMargin
271272 dropShadow: spreadView.active ||
272− priv.focusedAppDelegate.x !== 0
273+ (priv.focusedAppDelegate && priv.focusedAppDelegate.x !== 0)
273274
274275 readonly property bool isDash: model.appId == "unity8-dash"
275276
@@ -290,6 +291,10 @@ Rectangle {
290291 // Otherwise line up for the spread
291292 return spreadView.width + (index - 1) * spreadView.tileDistance;
292293 }
294+
295+ application: ApplicationManager.get(index)
296+ closeable: !isDash
297+
293298 property real behavioredIndex: index
294299 Behavior on behavioredIndex {
295300 enabled: spreadView.closingIndex >= 0
@@ -372,8 +377,15 @@ Rectangle {
372377 }
373378 }
374379
380+ onDraggedChanged: {
381+ if (dragged) {
382+ spreadView.numDelegatesBeingDragged++;
383+ } else {
384+ spreadView.numDelegatesBeingDragged--;
385+ }
386+ }
387+
375388 onClosed: {
376− spreadView.draggedIndex = -1;
377389 spreadView.closingIndex = index;
378390 ApplicationManager.stopApplication(ApplicationManager.get(index).appId);
379391 }
qml/Stages/SpreadDelegate.qml+34−58
@@ -14,97 +14,71 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 *
1616 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
17−*/
17+ * Daniel d'Andrada <daniel.dandrada@canonical.com>
18+ */
1819
1920import QtQuick 2.0
20−import Unity.Application 0.1
2121import Ubuntu.Components 1.1
2222import "../Components"
2323
2424Item {
2525 id: root
2626
27+ // to be read from outside
28+ readonly property bool dragged: dragArea.moving
29+ signal clicked()
30+ signal closed()
31+
2732 // to be set from outside
2833 property bool interactive: true
2934 property bool dropShadow: true
3035 property real maximizedAppTopMargin
3136 property alias swipeToCloseEnabled: dragArea.enabled
37+ property bool closeable
38+ property alias application: appWindow.application
3239
33− readonly property bool isFullscreen: surface !== null && surfaceContainer.surface.anchors.topMargin == 0
34−
35− signal clicked()
36− signal closed()
37−
38− AppSurfaceContainer {
39− id: surfaceContainer
40− objectName: "surfaceContainer"
41− anchors.fill: parent
42− surface: model.surface
43− promptSurfaces: model.application.promptSurfaces
44−
45− Binding {
46− target: surfaceContainer.surface
47− property: "anchors.topMargin"
48− value: {
49− return surfaceContainer.surface.state === MirSurfaceItem.Fullscreen ? 0 : maximizedAppTopMargin;
50− }
51− }
52−
53− Binding {
54− target: surface
55− property: "enabled"
56− value: root.interactive
57− }
58− Binding {
59− target: surface
60− property: "focus"
61− value: root.interactive
62− }
40+ Item {
41+ objectName: "appWindowWithShadow"
6342
64− Connections {
65− target: surface
66− // FIXME: I would rather not need to do this, but currently it doesn't get
67− // active focus without it and I don't know why.
68− onFocusChanged: forceSurfaceActiveFocusIfReady();
69− onParentChanged: forceSurfaceActiveFocusIfReady();
70− onEnabledChanged: forceSurfaceActiveFocusIfReady();
71− function forceSurfaceActiveFocusIfReady() {
72− if (surface.focus && surface.parent === surfaceContainer && surface.enabled) {
73− surface.forceActiveFocus();
74− }
75− }
76− }
43+ x: 0
44+ y: dragArea.distance
45+ width: parent.width
46+ height: parent.height
7747
7848 BorderImage {
79− id: dropShadowImage
8049 anchors {
81− fill: parent
50+ fill: appWindow
8251 leftMargin: -units.gu(2)
8352 rightMargin: -units.gu(2)
8453 bottomMargin: -units.gu(2)
85− topMargin: -units.gu(2) + (root.isFullscreen ? 0 : maximizedAppTopMargin)
54+ topMargin: -units.gu(2)
8655 }
8756 source: "graphics/dropshadow.png"
8857 border { left: 50; right: 50; top: 50; bottom: 50 }
89− opacity: root.dropShadow ? .4 : 0
58+ opacity: root.dropShadow ? 1 : 0
9059 Behavior on opacity { UbuntuNumberAnimation {} }
9160 }
9261
93− transform: Translate {
94− y: dragArea.distance
62+ ApplicationWindow {
63+ id: appWindow
64+ anchors {
65+ fill: parent
66+ topMargin: appWindow.fullscreen ? 0 : maximizedAppTopMargin
67+ }
68+
69+ interactive: root.interactive
9570 }
9671 }
9772
9873 DraggingArea {
9974 id: dragArea
75+ objectName: "dragArea"
10076 anchors.fill: parent
10177
10278 property bool moving: false
10379 property real distance: 0
10480
105− onMovingChanged: {
106− spreadView.draggedIndex = moving ? index : -1
107− }
81+ readonly property real minSpeedToClose: units.gu(40)
10882
10983 onDragValueChanged: {
11084 if (!dragging) {
@@ -123,15 +97,15 @@ Item {
12397 }
12498
12599 onDragEnd: {
126− if (model.appId == "unity8-dash") {
100+ if (!root.closeable) {
127101 animation.animate("center")
128102 return;
129103 }
130104
131105 // velocity and distance values specified by design prototype
132− if ((dragVelocity < -units.gu(40) && distance < -units.gu(8)) || distance < -root.height / 2) {
106+ if ((dragVelocity < -minSpeedToClose && distance < -units.gu(8)) || distance < -root.height / 2) {
133107 animation.animate("up")
134− } else if ((dragVelocity > units.gu(40) && distance > units.gu(8)) || distance > root.height / 2) {
108+ } else if ((dragVelocity > minSpeedToClose && distance > units.gu(8)) || distance > root.height / 2) {
135109 animation.animate("down")
136110 } else {
137111 animation.animate("center")
@@ -140,6 +114,7 @@ Item {
140114
141115 UbuntuNumberAnimation {
142116 id: animation
117+ objectName: "closeAnimation"
143118 target: dragArea
144119 property: "distance"
145120 property bool requestClose: false
@@ -164,9 +139,10 @@ Item {
164139 onRunningChanged: {
165140 if (!running) {
166141 dragArea.moving = false;
167− dragArea.distance = 0;
168142 if (requestClose) {
169143 root.closed();
144+ } else {
145+ dragArea.distance = 0;
170146 }
171147 }
172148 }
qml/Stages/TabletStage.qml+1
@@ -475,6 +475,7 @@ Rectangle {
475475 swipeToCloseEnabled: spreadView.interactive
476476 maximizedAppTopMargin: root.maximizedAppTopMargin
477477 dragOffset: !isDash && model.appId == priv.mainStageAppId && root.inverseProgress > 0 ? root.inverseProgress : 0
478+ closeable: !isDash
478479
479480 readonly property bool isDash: model.appId == "unity8-dash"
480481
qml/Stages/TransformedSpreadDelegate.qml+1−1
@@ -309,7 +309,7 @@ SpreadDelegate {
309309 Scale {
310310 origin { x: 0; y: (spreadView.height * priv.scale) + maximizedAppTopMargin * 3 }
311311 xScale: 1
312− yScale: isFullscreen ? 1 - priv.topMarginProgress * maximizedAppTopMargin / spreadView.height : 1
312+ yScale: fullscreen ? 1 - priv.topMarginProgress * maximizedAppTopMargin / spreadView.height : 1
313313 },
314314 Translate {
315315 x: priv.xTranslate
qml/Stages/TransformedTabletSpreadDelegate.qml+2−2
@@ -137,7 +137,7 @@ SpreadDelegate {
137137 Behavior on xTranslate {
138138 enabled: !spreadView.active &&
139139 !snapAnimation.running &&
140− model.appId !== "unity8-dash" &&
140+ root.closeable &&
141141 !spreadView.sideStageDragging
142142 UbuntuNumberAnimation {
143143 duration: UbuntuAnimation.FastDuration
@@ -172,7 +172,7 @@ SpreadDelegate {
172172 }
173173 newTranslate += root.dragOffset;
174174 }
175− if (!spreadView.active && model.appId == "unity8-dash" && !root.active) {
175+ if (!spreadView.active && !root.closeable && !root.active) {
176176 newTranslate -= root.width;
177177 }
178178
tests/mocks/Unity/Application/Application.qmltypes−19
@@ -7,25 +7,6 @@ import QtQuick.tooling 1.1
77// 'qmlplugindump -notrelocatable Unity.Application 0.1 tests/mocks'
88
99Module {
10− Component {
11− name: "ApplicationImage"
12− defaultProperty: "data"
13− prototype: "QQuickItem"
14− exports: ["Unity.Application/ApplicationImage 0.1"]
15− exportMetaObjectRevisions: [0]
16− Enum {
17− name: "FillMode"
18− values: {
19− "Stretch": 0,
20− "PreserveAspectCrop": 1
21− }
22− }
23− Property { name: "source"; type: "ApplicationInfo"; isPointer: true }
24− Property { name: "fillMode"; type: "FillMode" }
25− Property { name: "ready"; type: "bool" }
26− Method { name: "scheduleUpdate" }
27− Method { name: "updateFromCache" }
28− }
2910 Component {
3011 name: "ApplicationInfo"
3112 prototype: "unity::shell::application::ApplicationInfoInterface"
tests/mocks/Unity/Application/ApplicationImage.cppdeleted−123
@@ -1,123 +0,0 @@
1−/*
2− * Copyright (C) 2013 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 "ApplicationImage.h"
18−#include "ApplicationInfo.h"
19−
20−#include <QQmlEngine>
21−#include <QQmlComponent>
22−#include <QQmlContext>
23−
24−ApplicationImage::ApplicationImage(QQuickItem* parent)
25− : QQuickItem(parent),
26− m_source(NULL),
27− m_fillMode(Stretch),
28− m_ready(false),
29− m_imageComponent(0),
30− m_imageItem(0)
31−{
32−}
33−
34−void ApplicationImage::setSource(ApplicationInfo* source)
35−{
36− if (m_source != source) {
37− if (m_source)
38− disconnect(m_source, &ApplicationInfo::imageQmlChanged,
39− this, &ApplicationImage::updateImage);
40−
41− m_source = source;
42−
43− if (m_source) {
44− connect(m_source, &ApplicationInfo::imageQmlChanged,
45− this, &ApplicationImage::updateImage);
46− }
47− updateImage();
48−
49− Q_EMIT sourceChanged();
50− }
51−}
52−
53−void ApplicationImage::setFillMode(FillMode newFillMode)
54−{
55− if (m_fillMode != newFillMode) {
56− m_fillMode = newFillMode;
57− Q_EMIT fillModeChanged();
58− }
59−}
60−
61−void ApplicationImage::setReady(bool value)
62−{
63− if (value != m_ready) {
64− m_ready = value;
65− Q_EMIT readyChanged();
66− }
67−}
68−
69−void ApplicationImage::destroyImage()
70−{
71− delete m_imageItem;
72− m_imageItem = 0;
73− delete m_imageComponent;
74− m_imageComponent = 0;
75− m_qmlUsed.clear();
76− setReady(false);
77−}
78−
79−void ApplicationImage::updateImage()
80−{
81− if (!m_source || m_source->imageQml().isEmpty()) {
82− destroyImage();
83− } else if (m_source->imageQml() != m_qmlUsed) {
84− destroyImage();
85− createImageItem();
86− }
87−}
88−
89−void ApplicationImage::createImageItem()
90−{
91−
92− if (!m_imageComponent)
93− createImageComponent();
94−
95− // only create the windowItem one the component is ready
96− if (!m_imageComponent->isReady()) {
97− connect(m_imageComponent, &QQmlComponent::statusChanged,
98− this, &ApplicationImage::onImageComponentStatusChanged);
99− } else {
100− doCreateImageItem();
101− }
102−
103−}
104−
105−void ApplicationImage::createImageComponent()
106−{
107− QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine();
108− m_imageComponent = new QQmlComponent(engine, this);
109− m_imageComponent->setData(m_source->imageQml().toLatin1(), QUrl());
110−}
111−
112−void ApplicationImage::doCreateImageItem()
113−{
114− m_imageItem = qobject_cast<QQuickItem *>(m_imageComponent->create());
115− m_imageItem->setParentItem(this);
116− setReady(true);
117−}
118−
119−void ApplicationImage::onImageComponentStatusChanged(QQmlComponent::Status status)
120−{
121− if (status == QQmlComponent::Ready && !m_imageItem)
122− doCreateImageItem();
123−}
tests/mocks/Unity/Application/ApplicationImage.hdeleted−79
@@ -1,79 +0,0 @@
1−/*
2− * Copyright (C) 2013 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 APPLICATION_IMAGE_H
18−#define APPLICATION_IMAGE_H
19−
20−#include <QQuickItem>
21−
22−class ApplicationInfo;
23−
24−/* Fake implementation of ApplicationImage
25−
26− That fake implementation is not made in QML just because we can only declare
27− enumerations in C++. We can't even make readonly properties to mimic an enum
28− because properties must begin with a lower case letter.
29−*/
30−class ApplicationImage : public QQuickItem {
31− Q_OBJECT
32− Q_ENUMS(FillMode)
33− Q_PROPERTY(ApplicationInfo* source READ source WRITE setSource NOTIFY sourceChanged)
34− Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
35− Q_PROPERTY(bool ready READ ready WRITE setReady NOTIFY readyChanged)
36−
37−public:
38− explicit ApplicationImage(QQuickItem* parent = 0);
39− virtual ~ApplicationImage() {}
40−
41− enum FillMode { Stretch, PreserveAspectCrop };
42−
43− ApplicationInfo* source() const { return m_source; }
44− void setSource(ApplicationInfo* source);
45−
46− FillMode fillMode() const { return m_fillMode; }
47− void setFillMode(FillMode);
48−
49− void setReady(bool value);
50− bool ready() const { return m_ready; }
51−
52− Q_INVOKABLE void scheduleUpdate() {}
53− Q_INVOKABLE void updateFromCache() {}
54−
55−Q_SIGNALS:
56− void sourceChanged();
57− void fillModeChanged();
58− void readyChanged();
59−
60−private Q_SLOTS:
61− void updateImage();
62− void onImageComponentStatusChanged(QQmlComponent::Status status);
63−
64−private:
65− void createImageItem();
66− void createImageComponent();
67− void doCreateImageItem();
68− void destroyImage();
69−
70− ApplicationInfo* m_source;
71− FillMode m_fillMode;
72− bool m_ready;
73− QQmlComponent *m_imageComponent;
74− QQuickItem* m_imageItem;
75− // the QML script used to create the current m_imageItem
76− QString m_qmlUsed;
77−};
78−
79−#endif // APPLICATION_IMAGE_H
tests/mocks/Unity/Application/ApplicationInfo.cpp+91−14
@@ -18,6 +18,9 @@
1818#include "MirSurfaceItem.h"
1919#include "SurfaceManager.h"
2020
21+// unity8
22+#include <paths.h>
23+
2124#include <QGuiApplication>
2225#include <QQuickItem>
2326#include <QQuickView>
@@ -31,10 +34,9 @@ ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
3134 , m_state(Starting)
3235 , m_focused(false)
3336 , m_fullscreen(false)
34− , m_parentItem(0)
3537 , m_surface(0)
38+ , m_parentItem(0)
3639{
37− connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged);
3840}
3941
4042ApplicationInfo::ApplicationInfo(QObject *parent)
@@ -43,10 +45,9 @@ ApplicationInfo::ApplicationInfo(QObject *parent)
4345 , m_state(Starting)
4446 , m_focused(false)
4547 , m_fullscreen(false)
46− , m_parentItem(0)
4748 , m_surface(0)
49+ , m_parentItem(0)
4850{
49− connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged);
5051}
5152
5253ApplicationInfo::~ApplicationInfo()
@@ -57,15 +58,6 @@ ApplicationInfo::~ApplicationInfo()
5758 }
5859}
5960
60−void ApplicationInfo::onStateChanged(State state)
61−{
62− if (state == ApplicationInfo::Running) {
63− QTimer::singleShot(1000, this, SLOT(createSurface()));
64− } else if (state == ApplicationInfo::Stopped) {
65− setSurface(nullptr);
66− }
67−}
68−
6961void ApplicationInfo::createSurface()
7062{
7163 if (m_surface || state() == ApplicationInfo::Stopped) return;
@@ -73,7 +65,7 @@ void ApplicationInfo::createSurface()
7365 setSurface(new MirSurfaceItem(name(),
7466 MirSurfaceItem::Normal,
7567 fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
76− screenshot()));
68+ m_screenshotUrl));
7769}
7870
7971void ApplicationInfo::setSurface(MirSurfaceItem* surface)
@@ -151,3 +143,88 @@ MirSurfaceItem* ApplicationInfo::promptSurfaceAt(QQmlListProperty<MirSurfaceItem
151143 return nullptr;
152144 return p->m_promptSurfaces[index];
153145}
146+
147+void ApplicationInfo::updateScreenshot()
148+{
149+ qDebug() << "ApplicationInfo::updateScreenshot()";
150+ setScreenshot(m_screenshotUrl);
151+}
152+
153+void ApplicationInfo::discardScreenshot()
154+{
155+ setScreenshot(QUrl());
156+}
157+
158+void ApplicationInfo::setIconId(const QString &iconId)
159+{
160+ setIcon(QString("file://%1/graphics/applicationIcons/%2@18.png")
161+ .arg(qmlDirectory())
162+ .arg(iconId));
163+}
164+
165+void ApplicationInfo::setScreenshotId(const QString &screenshotId)
166+{
167+ m_screenshotUrl = QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png")
168+ .arg(qmlDirectory())
169+ .arg(screenshotId);
170+}
171+
172+void ApplicationInfo::setName(const QString &value)
173+{
174+ if (value != m_name) {
175+ m_name = value;
176+ Q_EMIT nameChanged(value);
177+ }
178+}
179+
180+void ApplicationInfo::setIcon(const QUrl &value)
181+{
182+ if (value != m_icon) {
183+ m_icon = value;
184+ Q_EMIT iconChanged(value);
185+ }
186+}
187+
188+void ApplicationInfo::setStage(Stage value)
189+{
190+ if (value != m_stage) {
191+ m_stage = value;
192+ Q_EMIT stageChanged(value);
193+ }
194+}
195+
196+void ApplicationInfo::setState(State value)
197+{
198+ if (value != m_state) {
199+ m_state = value;
200+ Q_EMIT stateChanged(value);
201+
202+ if (m_state == ApplicationInfo::Running) {
203+ QTimer::singleShot(1000, this, SLOT(createSurface()));
204+ }
205+ }
206+}
207+
208+void ApplicationInfo::setFocused(bool value)
209+{
210+ if (value != m_focused) {
211+ m_focused = value;
212+ Q_EMIT focusedChanged(value);
213+ }
214+}
215+
216+void ApplicationInfo::setScreenshot(const QUrl &value)
217+{
218+ if (value != m_screenshot) {
219+ m_screenshot = value;
220+ Q_EMIT screenshotChanged(value);
221+ }
222+}
223+
224+void ApplicationInfo::setFullscreen(bool value)
225+{
226+ if (value != m_fullscreen) {
227+ m_fullscreen = value;
228+ Q_EMIT fullscreenChanged(value);
229+ }
230+}
tests/mocks/Unity/Application/ApplicationInfo.h+44−43
@@ -26,63 +26,52 @@ class MirSurfaceItem;
2626// unity-api
2727#include <unity/shell/application/ApplicationInfoInterface.h>
2828
29−// A pretty dumb file. Just a container for properties.
30−// Implemented in C++ instead of QML just because of the enumerations
31−// See QTBUG-14861
32−
3329using namespace unity::shell::application;
3430
3531class ApplicationInfo : public ApplicationInfoInterface {
3632 Q_OBJECT
3733
3834 Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
39− Q_PROPERTY(Stage stage READ stage WRITE setStage NOTIFY stageChanged)
4035 Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
4136 Q_PROPERTY(QQmlListProperty<MirSurfaceItem> promptSurfaces READ promptSurfaces NOTIFY promptSurfacesChanged DESIGNABLE false)
4237
4338 // Only exists in this fake implementation
4439
45− // QML component used to represent its image/screenhot
46− Q_PROPERTY(QString imageQml READ imageQml WRITE setImageQml NOTIFY imageQmlChanged)
47−
48− // QML component used to represent the application window
49− Q_PROPERTY(QString windowQml READ windowQml WRITE setWindowQml NOTIFY windowQmlChanged)
50−
5140public:
5241 ApplicationInfo(QObject *parent = NULL);
5342 ApplicationInfo(const QString &appId, QObject *parent = NULL);
5443 ~ApplicationInfo();
5544
56− #define IMPLEMENT_PROPERTY(name, Name, type) \
57− public: \
58− type name() const { return m_##name; } \
59− void set##Name(const type& value) \
60− { \
61− if (m_##name != value) { \
62− m_##name = value; \
63− Q_EMIT name##Changed(value); \
64− } \
65− } \
66− Q_SIGNALS: \
67− void name##Changed(const type&); \
68− private: \
69− type m_##name;
70−
71− IMPLEMENT_PROPERTY(appId, AppId, QString)
72− IMPLEMENT_PROPERTY(name, Name, QString)
73− IMPLEMENT_PROPERTY(comment, Comment, QString)
74− IMPLEMENT_PROPERTY(icon, Icon, QUrl)
75− IMPLEMENT_PROPERTY(stage, Stage, Stage)
76− IMPLEMENT_PROPERTY(state, State, State)
77− IMPLEMENT_PROPERTY(focused, Focused, bool)
78− IMPLEMENT_PROPERTY(fullscreen, Fullscreen, bool)
79− IMPLEMENT_PROPERTY(imageQml, ImageQml, QString)
80− IMPLEMENT_PROPERTY(windowQml, WindowQml, QString)
81− IMPLEMENT_PROPERTY(screenshot, Screenshot, QUrl)
82−
83− #undef IMPLEMENT_PROPERTY
45+ Q_INVOKABLE void updateScreenshot() override;
46+ Q_INVOKABLE void discardScreenshot() override;
47+
48+ void setIconId(const QString &iconId);
49+ void setScreenshotId(const QString &screenshotId);
50+
51+ void setAppId(const QString &value) { m_appId = value; }
52+ QString appId() const override { return m_appId; }
53+
54+ void setName(const QString &value);
55+ QString name() const override { return m_name; }
56+
57+ QString comment() const override { return QString(); }
58+
59+ QUrl icon() const override { return m_icon; }
60+
61+ void setStage(Stage value);
62+ Stage stage() const override { return m_stage; }
63+
64+ Q_INVOKABLE void setState(State value);
65+ State state() const override { return m_state; }
66+
67+ void setFocused(bool value);
68+ bool focused() const override { return m_focused; }
69+
70+ QUrl screenshot() const override { return m_screenshot; }
71+
72+ void setFullscreen(bool value);
73+ bool fullscreen() const { return m_fullscreen; }
8474
85−public:
8675 void setSurface(MirSurfaceItem* surface);
8776 MirSurfaceItem* surface() const { return m_surface; }
8877
@@ -95,18 +84,30 @@ public:
9584Q_SIGNALS:
9685 void surfaceChanged(MirSurfaceItem*);
9786 void promptSurfacesChanged();
87+ void fullscreenChanged(bool value);
9888
9989private Q_SLOTS:
100− void onStateChanged(State state);
101−
10290 void createSurface();
10391
10492private:
10593 static int promptSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop);
10694 static MirSurfaceItem* promptSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index);
95+ void setIcon(const QUrl &value);
96+ void setScreenshot(const QUrl &value);
97+
98+ QUrl m_screenshotUrl;
99+
100+ QString m_appId;
101+ QString m_name;
102+ QUrl m_icon;
103+ Stage m_stage;
104+ State m_state;
105+ bool m_focused;
106+ QUrl m_screenshot;
107+ bool m_fullscreen;
108+ MirSurfaceItem* m_surface;
107109
108110 QQuickItem *m_parentItem;
109− MirSurfaceItem* m_surface;
110111 QList<MirSurfaceItem*> m_promptSurfaces;
111112};
112113
tests/mocks/Unity/Application/ApplicationManager.cpp+69−70
@@ -55,14 +55,32 @@ ApplicationManager::ApplicationManager(QObject *parent)
5555
5656 buildListOfAvailableApplications();
5757
58− startApplication("unity8-dash");
59− focusApplication("unity8-dash");
58+ // polling to find out when the toplevel window has been created as there's
59+ // no signal telling us that
60+ connect(&m_windowCreatedTimer, &QTimer::timeout,
61+ this, &ApplicationManager::onWindowCreatedTimerTimeout);
62+ m_windowCreatedTimer.setSingleShot(false);
63+ m_windowCreatedTimer.start(200);
6064}
6165
6266ApplicationManager::~ApplicationManager()
6367{
6468}
6569
70+void ApplicationManager::onWindowCreatedTimerTimeout()
71+{
72+ if (QGuiApplication::topLevelWindows().count() > 0) {
73+ m_windowCreatedTimer.stop();
74+ onWindowCreated();
75+ }
76+}
77+
78+void ApplicationManager::onWindowCreated()
79+{
80+ startApplication("unity8-dash");
81+ focusApplication("unity8-dash");
82+}
83+
6684int ApplicationManager::rowCount(const QModelIndex& parent) const {
6785 return !parent.isValid() ? m_runningApplications.size() : 0;
6886}
@@ -143,6 +161,16 @@ void ApplicationManager::add(ApplicationInfo *application) {
143161 if (!appIndex.isValid()) return;
144162 Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleSurface);
145163 });
164+ connect(application, &ApplicationInfo::focusedChanged, this, [application, this]() {
165+ QModelIndex appIndex = findIndex(application);
166+ if (!appIndex.isValid()) return;
167+ Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleFocused);
168+ });
169+ connect(application, &ApplicationInfo::stateChanged, this, [application, this]() {
170+ QModelIndex appIndex = findIndex(application);
171+ if (!appIndex.isValid()) return;
172+ Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleState);
173+ });
146174}
147175
148176void ApplicationManager::remove(ApplicationInfo *application) {
@@ -155,7 +183,7 @@ void ApplicationManager::remove(ApplicationInfo *application) {
155183 Q_EMIT countChanged();
156184 if (isEmpty()) Q_EMIT emptyChanged(isEmpty());
157185 }
158− disconnect(application, &ApplicationInfo::surfaceChanged, this, 0);
186+ disconnect(application, 0, this, 0);
159187}
160188
161189void ApplicationManager::move(int from, int to) {
@@ -293,32 +321,18 @@ bool ApplicationManager::focusApplication(const QString &appId)
293321 if (application == nullptr)
294322 return false;
295323
296− if (application->stage() == ApplicationInfo::MainStage) {
297− // unfocus currently focused mainstage app
298− for (ApplicationInfo *app : m_runningApplications) {
299− if (app->focused() && app->stage() == ApplicationInfo::MainStage) {
300− app->setFocused(false);
301− app->setState(ApplicationInfo::Suspended);
302− }
303− }
304−
305− // focus this app
306− application->setFocused(true);
307− application->setState(ApplicationInfo::Running);
308− } else if (application->stage() == ApplicationInfo::SideStage) {
309− // unfocus currently focused sidestage app
310− for (ApplicationInfo *app : m_runningApplications) {
311− if (app->focused() && app->stage() == ApplicationInfo::SideStage) {
312− app->setFocused(false);
313− app->setState(ApplicationInfo::Suspended);
314− }
324+ // unfocus currently focused app
325+ for (ApplicationInfo *app : m_runningApplications) {
326+ if (app->focused()) {
327+ app->setFocused(false);
328+ app->setState(ApplicationInfo::Suspended);
315329 }
316−
317− // focus this app
318− application->setFocused(true);
319− application->setState(ApplicationInfo::Running);
320330 }
321331
332+ // focus this app
333+ application->setFocused(true);
334+ application->setState(ApplicationInfo::Running);
335+
322336 // move app to top of stack
323337 move(m_runningApplications.indexOf(application), 0);
324338 Q_EMIT focusedApplicationIdChanged();
@@ -341,12 +355,6 @@ void ApplicationManager::unfocusCurrentApplication()
341355 Q_EMIT focusedApplicationIdChanged();
342356}
343357
344−void ApplicationManager::generateQmlStrings(ApplicationInfo *application)
345−{
346− application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png").arg(qmlDirectory())
347− .arg(application->icon().toString()));
348−}
349−
350358void ApplicationManager::buildListOfAvailableApplications()
351359{
352360 ApplicationInfo *application;
@@ -354,128 +362,119 @@ void ApplicationManager::buildListOfAvailableApplications()
354362 application = new ApplicationInfo(this);
355363 application->setAppId("unity8-dash");
356364 application->setName("Unity 8 Mock Dash");
357− application->setIcon(QUrl("unity8-dash"));
365+ application->setScreenshotId("unity8-dash");
358366 application->setStage(ApplicationInfo::MainStage);
359− generateQmlStrings(application);
360367 m_availableApplications.append(application);
361368
362369 application = new ApplicationInfo(this);
363370 application->setAppId("dialer-app");
364371 application->setName("Dialer");
365− application->setIcon(QUrl("dialer"));
372+ application->setScreenshotId("dialer");
373+ application->setIconId("dialer-app");
366374 application->setStage(ApplicationInfo::SideStage);
367− generateQmlStrings(application);
368375 m_availableApplications.append(application);
369376
370377 application = new ApplicationInfo(this);
371378 application->setAppId("camera-app");
372379 application->setName("Camera");
373− application->setIcon(QUrl("camera"));
380+ application->setScreenshotId("camera");
381+ application->setIconId("camera");
374382 application->setFullscreen(true);
375− generateQmlStrings(application);
376383 m_availableApplications.append(application);
377384
378385 application = new ApplicationInfo(this);
379386 application->setAppId("gallery-app");
380387 application->setName("Gallery");
381− application->setIcon(QUrl("gallery"));
382− generateQmlStrings(application);
388+ application->setScreenshotId("gallery");
389+ application->setIconId("gallery");
383390 m_availableApplications.append(application);
384391
385392 application = new ApplicationInfo(this);
386393 application->setAppId("facebook-webapp");
387394 application->setName("Facebook");
388− application->setIcon(QUrl("facebook"));
395+ application->setScreenshotId("facebook");
396+ application->setIconId("facebook");
389397 application->setStage(ApplicationInfo::SideStage);
390− generateQmlStrings(application);
391398 m_availableApplications.append(application);
392399
393400 application = new ApplicationInfo(this);
394401 application->setAppId("webbrowser-app");
395402 application->setFullscreen(true);
396403 application->setName("Browser");
397− application->setIcon(QUrl("browser"));
398− generateQmlStrings(application);
404+ application->setScreenshotId("browser");
405+ application->setIconId("browser");
399406 m_availableApplications.append(application);
400407
401408 application = new ApplicationInfo(this);
402409 application->setAppId("twitter-webapp");
403410 application->setName("Twitter");
404− application->setIcon(QUrl("twitter"));
411+ application->setScreenshotId("twitter");
412+ application->setIconId("twitter");
405413 application->setStage(ApplicationInfo::SideStage);
406− generateQmlStrings(application);
414+ m_availableApplications.append(application);
415+
416+ application = new ApplicationInfo(this);
417+ application->setAppId("map");
418+ application->setName("Map");
419+ application->setIconId("map");
420+ application->setScreenshotId("map");
407421 m_availableApplications.append(application);
408422
409423 application = new ApplicationInfo(this);
410424 application->setAppId("gmail-webapp");
411425 application->setName("GMail");
412− application->setIcon(QUrl("gmail"));
426+ application->setIconId("gmail");
413427 m_availableApplications.append(application);
414428
415429 application = new ApplicationInfo(this);
416430 application->setAppId("ubuntu-weather-app");
417431 application->setName("Weather");
418− application->setIcon(QUrl("weather"));
432+ application->setIconId("weather");
419433 application->setStage(ApplicationInfo::SideStage);
420− generateQmlStrings(application);
421434 m_availableApplications.append(application);
422435
423436 application = new ApplicationInfo(this);
424437 application->setAppId("notes-app");
425438 application->setName("Notepad");
426− application->setIcon(QUrl("notepad"));
439+ application->setIconId("notepad");
427440 application->setStage(ApplicationInfo::SideStage);
428441 m_availableApplications.append(application);
429442
430443 application = new ApplicationInfo(this);
431444 application->setAppId("calendar-app");
432445 application->setName("Calendar");
433− application->setIcon(QUrl("calendar"));
446+ application->setIconId("calendar");
434447 application->setStage(ApplicationInfo::SideStage);
435448 m_availableApplications.append(application);
436449
437− application = new ApplicationInfo(this);
438− application->setAppId("mediaplayer-app");
439− application->setName("Media Player");
440− application->setIcon(QUrl("mediaplayer-app"));
441− application->setFullscreen(true);
442− m_availableApplications.append(application);
443−
444450 application = new ApplicationInfo(this);
445451 application->setAppId("evernote");
446452 application->setName("Evernote");
447− application->setIcon(QUrl("evernote"));
448− m_availableApplications.append(application);
449−
450− application = new ApplicationInfo(this);
451− application->setAppId("map");
452− application->setName("Map");
453− application->setIcon(QUrl("map"));
454− generateQmlStrings(application);
453+ application->setIconId("evernote");
455454 m_availableApplications.append(application);
456455
457456 application = new ApplicationInfo(this);
458457 application->setAppId("pinterest");
459458 application->setName("Pinterest");
460− application->setIcon(QUrl("pinterest"));
459+ application->setIconId("pinterest");
461460 m_availableApplications.append(application);
462461
463462 application = new ApplicationInfo(this);
464463 application->setAppId("soundcloud");
465464 application->setName("SoundCloud");
466− application->setIcon(QUrl("soundcloud"));
465+ application->setIconId("soundcloud");
467466 m_availableApplications.append(application);
468467
469468 application = new ApplicationInfo(this);
470469 application->setAppId("wikipedia");
471470 application->setName("Wikipedia");
472− application->setIcon(QUrl("wikipedia"));
471+ application->setIconId("wikipedia");
473472 m_availableApplications.append(application);
474473
475474 application = new ApplicationInfo(this);
476475 application->setAppId("youtube");
477476 application->setName("YouTube");
478− application->setIcon(QUrl("youtube"));
477+ application->setIconId("youtube");
479478 m_availableApplications.append(application);
480479}
481480
tests/mocks/Unity/Application/ApplicationManager.h+6−2
@@ -20,6 +20,7 @@
2020#include <QObject>
2121#include <QList>
2222#include <QStringList>
23+#include <QTimer>
2324#include "ApplicationInfo.h"
2425
2526// unity-api
@@ -115,15 +116,18 @@ class ApplicationManager : public ApplicationManagerInterface {
115116 void focusRequested(const QString &appId);
116117 void emptyChanged(bool empty);
117118
119+ private Q_SLOTS:
120+ void onWindowCreatedTimerTimeout();
121+
118122 private:
119123 void add(ApplicationInfo *application);
120124 void remove(ApplicationInfo* application);
121− void showApplicationWindow(ApplicationInfo *application);
122125 void buildListOfAvailableApplications();
123− void generateQmlStrings(ApplicationInfo *application);
126+ void onWindowCreated();
124127 bool m_suspended;
125128 QList<ApplicationInfo*> m_runningApplications;
126129 QList<ApplicationInfo*> m_availableApplications;
130+ QTimer m_windowCreatedTimer;
127131
128132 static ApplicationManager *the_application_manager;
129133};
tests/mocks/Unity/Application/CMakeLists.txt+1−3
@@ -1,15 +1,13 @@
1−pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application)
1+pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=3)
22
33set(FakeUnityApplicationQml_SOURCES
44 plugin.cpp
55 ApplicationDBusAdaptor.cpp
66 ApplicationInfo.cpp
7− ApplicationImage.cpp
87 ApplicationManager.cpp
98 ApplicationScreenshotProvider.cpp
109 MirSurfaceItem.cpp
1110 SurfaceManager.cpp
12− VirtualKeyboard.cpp
1311 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
1412 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
1513)
tests/mocks/Unity/Application/InputFilterArea.qmldeleted−21
@@ -1,21 +0,0 @@
1−/*
2− * Copyright (C) 2013 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−Item {
20− property bool blockInput: false
21−}
tests/mocks/Unity/Application/MirSurfaceItem.cpp+89−13
@@ -17,22 +17,30 @@
1717#include "MirSurfaceItem.h"
1818#include "ApplicationInfo.h"
1919
20−#include <QPainter>
20+#include <paths.h>
21+
22+#include <QGuiApplication>
23+#include <QQuickView>
24+#include <QQmlProperty>
2125#include <QQmlEngine>
26+#include <QString>
27+
28+#include <QDebug>
2229
2330MirSurfaceItem::MirSurfaceItem(const QString& name,
2431 MirSurfaceItem::Type type,
2532 MirSurfaceItem::State state,
2633 const QUrl& screenshot,
34+ const QString &qmlFilePath,
2735 QQuickItem *parent)
28− : QQuickPaintedItem(parent)
36+ : QQuickItem(parent)
2937 , m_application(nullptr)
3038 , m_name(name)
3139 , m_type(type)
3240 , m_state(state)
33− , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
3441 , m_parentSurface(nullptr)
35− , m_haveInputMethod(false)
42+ , m_qmlItem(nullptr)
43+ , m_screenshotUrl(screenshot)
3644{
3745 qDebug() << "MirSurfaceItem::MirSurfaceItem() " << this->name();
3846
@@ -40,10 +48,41 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
4048
4149 // The virtual keyboard (input method) has a big transparent area so that
4250 // content behind it show through
43− setFillColor(Qt::transparent);
51+ //setFillColor(Qt::transparent);
4452
4553 connect(this, &QQuickItem::focusChanged,
4654 this, &MirSurfaceItem::onFocusChanged);
55+
56+
57+ // The assumptions I make here really should hold.
58+ QQuickView *quickView =
59+ qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
60+
61+ QString qmlComponentFilePath;
62+ if (!qmlFilePath.isEmpty()) {
63+ qmlComponentFilePath.append(qmlFilePath);
64+ } else {
65+ qmlComponentFilePath = QString("%1/Unity/Application/MirSurfaceItem.qml")
66+ .arg(mockPluginsDir());
67+ }
68+
69+ m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlComponentFilePath);
70+
71+ switch (m_qmlContentComponent->status()) {
72+ case QQmlComponent::Ready:
73+ createQmlContentItem();
74+ break;
75+ case QQmlComponent::Loading:
76+ connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
77+ this, &MirSurfaceItem::onComponentStatusChanged);
78+ break;
79+ case QQmlComponent::Error:
80+ printComponentErrors();
81+ qFatal("MirSurfaceItem: failed to create content component.");
82+ break;
83+ default:
84+ qFatal("MirSurfaceItem: Unhandled component status");
85+ }
4786}
4887
4988MirSurfaceItem::~MirSurfaceItem()
@@ -61,10 +100,11 @@ MirSurfaceItem::~MirSurfaceItem()
61100 m_application->removeSurface(this);
62101}
63102
64−void MirSurfaceItem::paint(QPainter * painter)
103+void MirSurfaceItem::printComponentErrors()
65104{
66− if (!m_img.isNull()) {
67− painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
105+ QList<QQmlError> errors = m_qmlContentComponent->errors();
106+ for (int i = 0; i < errors.count(); ++i) {
107+ qDebug() << errors[i];
68108 }
69109}
70110
@@ -155,19 +195,24 @@ MirSurfaceItem* MirSurfaceItem::childSurfaceAt(QQmlListProperty<MirSurfaceItem>
155195}
156196
157197
158−void MirSurfaceItem::touchEvent(QTouchEvent * event)
198+void MirSurfaceItem::onQmlWantInputMethodChanged()
159199{
160− if (event->type() == QEvent::TouchBegin && hasFocus()) {
200+ QQmlProperty prop(m_qmlItem, "wantInputMethod");
201+ bool wantInputMethod = prop.read().toBool();
202+
203+ if (hasFocus() && wantInputMethod) {
161204 Q_EMIT inputMethodRequested();
162− m_haveInputMethod = true;
163205 }
164206}
165207
166208void MirSurfaceItem::onFocusChanged()
167209{
168− if (!hasFocus() && m_haveInputMethod) {
210+ QQmlProperty prop(m_qmlItem, "wantInputMethod");
211+ bool wantInputMethod = prop.read().toBool();
212+
213+ if (!hasFocus() && wantInputMethod) {
169214 Q_EMIT inputMethodDismissed();
170− m_haveInputMethod = false;
215+ prop.write(QVariant::fromValue(false));
171216 }
172217}
173218
@@ -178,3 +223,34 @@ void MirSurfaceItem::setState(MirSurfaceItem::State newState)
178223 Q_EMIT stateChanged(newState);
179224 }
180225}
226+
227+void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
228+{
229+ if (status == QQmlComponent::Ready) {
230+ createQmlContentItem();
231+ }
232+}
233+
234+void MirSurfaceItem::createQmlContentItem()
235+{
236+ m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
237+ m_qmlItem->setParentItem(this);
238+
239+ {
240+ QQmlProperty anchorsFill(m_qmlItem, "anchors.fill");
241+ anchorsFill.write(QVariant::fromValue(this));
242+ }
243+
244+ {
245+ QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
246+ screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
247+ }
248+
249+ {
250+ QQmlProperty prop(m_qmlItem, "wantInputMethod");
251+ if (prop.type() == QQmlProperty::Property) {
252+ bool ok = prop.connectNotifySignal(this, SLOT(onQmlWantInputMethodChanged()));
253+ if (!ok) qCritical("MirSurfaceItem: failed to connect to wantInputMethod notify signal");
254+ }
255+ }
256+}
tests/mocks/Unity/Application/MirSurfaceItem.h+14−11
@@ -17,12 +17,13 @@
1717#ifndef MIRSURFACEITEM_H
1818#define MIRSURFACEITEM_H
1919
20−#include <QQuickPaintedItem>
21−#include <QImage>
20+#include <QQuickItem>
21+#include <QQmlComponent>
22+#include <QUrl>
2223
2324class ApplicationInfo;
2425
25−class MirSurfaceItem : public QQuickPaintedItem
26+class MirSurfaceItem : public QQuickItem
2627{
2728 Q_OBJECT
2829 Q_ENUMS(Type)
@@ -59,6 +60,7 @@ public:
5960 Type type,
6061 State state,
6162 const QUrl& screenshot,
63+ const QString &qmlFilePath = QString(),
6264 QQuickItem *parent = 0);
6365 ~MirSurfaceItem();
6466
@@ -76,9 +78,6 @@ public:
7678 Q_INVOKABLE void setState(State newState);
7779 Q_INVOKABLE void release();
7880
79− void paint(QPainter * painter) override;
80− void touchEvent(QTouchEvent * event) override;
81−
8281Q_SIGNALS:
8382 void typeChanged(Type);
8483 void stateChanged(State);
@@ -93,9 +92,8 @@ Q_SIGNALS:
9392
9493private Q_SLOTS:
9594 void onFocusChanged();
96−
97−protected:
98− const QImage &screenshotImage() { return m_img; }
95+ void onComponentStatusChanged(QQmlComponent::Status status);
96+ void onQmlWantInputMethodChanged();
9997
10098private:
10199 void addChildSurface(MirSurfaceItem* surface);
@@ -105,15 +103,20 @@ private:
105103 static int childSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop);
106104 static MirSurfaceItem* childSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index);
107105
106+ void createQmlContentItem();
107+ void printComponentErrors();
108+
108109 ApplicationInfo* m_application;
109110 const QString m_name;
110111 const Type m_type;
111112 State m_state;
112− const QImage m_img;
113113
114114 MirSurfaceItem* m_parentSurface;
115115 QList<MirSurfaceItem*> m_children;
116− bool m_haveInputMethod;
116+
117+ QQmlComponent *m_qmlContentComponent;
118+ QQuickItem *m_qmlItem;
119+ QUrl m_screenshotUrl;
117120};
118121
119122Q_DECLARE_METATYPE(MirSurfaceItem*)
tests/mocks/Unity/Application/MirSurfaceItem.qmlnew file+46
@@ -0,0 +1,46 @@
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+
19+Rectangle {
20+ id: root
21+ color: "yellow"
22+
23+ property alias screenshotSource: screenshotImage.source
24+
25+ property bool wantInputMethod: false
26+
27+ Image {
28+ id: screenshotImage
29+ anchors.fill: parent
30+ }
31+
32+ Text {
33+ anchors.fill: parent
34+ text: "SURFACE"
35+ color: "yellow"
36+ font.bold: true
37+ fontSizeMode: Text.Fit
38+ minimumPixelSize: 10; font.pixelSize: 200
39+ verticalAlignment: Text.AlignVCenter
40+ }
41+
42+ MultiPointTouchArea {
43+ anchors.fill: parent
44+ onPressed: { root.wantInputMethod = true }
45+ }
46+}
tests/mocks/Unity/Application/OSKController.qmldeleted−20
@@ -1,20 +0,0 @@
1−/*
2− * Copyright (C) 2013 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−Item {
20−}
tests/mocks/Unity/Application/SurfaceManager.cpp+14−3
@@ -16,9 +16,8 @@
1616
1717#include "SurfaceManager.h"
1818
19+#include <paths.h>
1920#include "MirSurfaceItem.h"
20−#include "VirtualKeyboard.h"
21−
2221
2322SurfaceManager *SurfaceManager::the_surface_manager = nullptr;
2423
@@ -66,7 +65,19 @@ void SurfaceManager::hideInputMethod()
6665MirSurfaceItem *SurfaceManager::inputMethodSurface()
6766{
6867 if (!m_virtualKeyboard) {
69− m_virtualKeyboard = new VirtualKeyboard(MirSurfaceItem::Minimized);
68+
69+ QString screenshotPath = QString("file://%1/Dash/graphics/phone/screenshots/vkb_portrait.png")
70+ .arg(qmlDirectory());
71+
72+ QString qmlFilePath = QString("%1/Unity/Application/VirtualKeyboard.qml")
73+ .arg(mockPluginsDir());
74+
75+ m_virtualKeyboard = new MirSurfaceItem(
76+ "input-method",
77+ MirSurfaceItem::InputMethod,
78+ MirSurfaceItem::Minimized,
79+ screenshotPath,
80+ qmlFilePath);
7081 Q_EMIT surfaceCreated(m_virtualKeyboard);
7182 }
7283 return m_virtualKeyboard;
tests/mocks/Unity/Application/SurfaceManager.h+1−2
@@ -20,7 +20,6 @@
2020#include <QObject>
2121
2222class MirSurfaceItem;
23−class VirtualKeyboard;
2423
2524class SurfaceManager : public QObject
2625{
@@ -48,7 +47,7 @@ private Q_SLOTS:
4847
4948private:
5049 static SurfaceManager *the_surface_manager;
51− VirtualKeyboard *m_virtualKeyboard;
50+ MirSurfaceItem *m_virtualKeyboard;
5251};
5352
5453#endif // SURFACEMANAGER_H
tests/mocks/Unity/Application/VirtualKeyboard.cppdeleted−55
@@ -1,55 +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 "VirtualKeyboard.h"
18−
19−#include <paths.h>
20−
21−VirtualKeyboard::VirtualKeyboard(State state, QQuickItem *parent)
22− : MirSurfaceItem("input-method",
23− MirSurfaceItem::InputMethod,
24− state,
25− QString("file://%1/Dash/graphics/phone/screenshots/vkb_portrait.png").arg(qmlDirectory()),
26− parent)
27−{
28−}
29−
30−void VirtualKeyboard::touchEvent(QTouchEvent *event)
31−{
32− if (event->type() == QEvent::TouchBegin && !hasTouchInsideKeyboard(event)) {
33− event->ignore();
34− }
35−}
36−
37−bool VirtualKeyboard::hasTouchInsideKeyboard(QTouchEvent *event)
38−{
39− const QList<QTouchEvent::TouchPoint> &touchPoints = event->touchPoints();
40− for (int i = 0; i < touchPoints.count(); ++i) {
41− QPoint pos = touchPoints.at(i).pos().toPoint();
42−
43− // Map to image coords
44− int imageX = (int)( ( ((qreal)pos.x()) / width() ) * ((qreal)screenshotImage().size().width()) );
45− int imageY = (int)( ( ((qreal)pos.y()) / height() ) * ((qreal)screenshotImage().size().height()) );
46−
47− QRgb pixelHit = screenshotImage().pixel(imageX, imageY);
48−
49− // The keyboard depicted in the image is in its opaque part.
50− if (qAlpha(pixelHit) != 0) {
51− return true;
52− }
53− }
54− return false;
55−}
tests/mocks/Unity/Application/VirtualKeyboard.hdeleted−35
@@ -1,35 +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−#ifndef VIRTUALKEYBOARD_H
18−#define VIRTUALKEYBOARD_H
19−
20−#include "MirSurfaceItem.h"
21−
22−class VirtualKeyboard : public MirSurfaceItem
23−{
24− Q_OBJECT
25−public:
26− VirtualKeyboard(State state,
27− QQuickItem *parent = 0);
28−
29− void touchEvent(QTouchEvent * event) override;
30−
31−private:
32− bool hasTouchInsideKeyboard(QTouchEvent *event);
33−};
34−
35−#endif // VIRTUALKEYBOARD_H
tests/mocks/Unity/Application/VirtualKeyboard.qmlnew file+34
@@ -0,0 +1,34 @@
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+
19+Item {
20+
21+ property alias screenshotSource: screenshotImage.source
22+
23+ Image {
24+ id: screenshotImage
25+ height: width * 0.6
26+ anchors.bottom: parent.bottom
27+ anchors.left: parent.left
28+ anchors.right: parent.right
29+
30+ MultiPointTouchArea {
31+ anchors.fill: parent
32+ }
33+ }
34+}
tests/mocks/Unity/Application/plugin.cpp−3
@@ -16,7 +16,6 @@
1616
1717#include "plugin.h"
1818#include "ApplicationInfo.h"
19−#include "ApplicationImage.h"
2019#include "ApplicationManager.h"
2120#include "ApplicationScreenshotProvider.h"
2221#include "MirSurfaceItem.h"
@@ -49,8 +48,6 @@ void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
4948 qmlRegisterType<ApplicationInfo>(uri, 0, 1, "ApplicationInfo");
5049
5150 qmlRegisterUncreatableType<MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem", "MirSurfaceItem can't be instantiated from QML");
52−
53− qmlRegisterType<ApplicationImage>(uri, 0, 1, "ApplicationImage");
5451}
5552
5653void FakeUnityApplicationQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
tests/mocks/Unity/Application/qmldir−3
@@ -1,6 +1,3 @@
11module Unity.Application
22plugin FakeUnityApplicationQml
33typeinfo Application.qmltypes
4−
5−InputFilterArea 0.1 InputFilterArea.qml
6−OSKController 0.1 OSKController.qml
tests/plugins/Unity/Launcher/launchermodeltest.cpp+3
@@ -41,6 +41,9 @@ public:
4141 bool focused() const { return m_focused; }
4242 QUrl screenshot() const { return QUrl(); }
4343
44+ Q_INVOKABLE void updateScreenshot() override {}
45+ Q_INVOKABLE void discardScreenshot() override {}
46+
4447 // Methods used for mocking (not in the interface)
4548 void setFocused(bool focused) { m_focused = focused; Q_EMIT focusedChanged(focused); }
4649private:
tests/qmltests/CMakeLists.txt+2
@@ -74,4 +74,6 @@ add_qml_test(Panel/Indicators DefaultIndicatorPage ENVIRONMENT "LD_LIBRARY_PATH=
7474# These MenuItemFactory tests need the test/mocks/ to come before plugins/
7575add_qml_test(Panel/Indicators MenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
7676add_qml_test(Panel/Indicators MessageMenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
77+add_qml_test(Stages ApplicationWindow ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
7778add_qml_test(Stages PhoneStage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
79+add_qml_test(Stages SpreadDelegate ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
tests/qmltests/Stages/tst_ApplicationWindow.qmlnew file+359
@@ -0,0 +1,359 @@
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.0
18+import QtTest 1.0
19+import Unity.Test 0.1 as UT
20+import ".."
21+import "../../../qml/Stages"
22+import Ubuntu.Components 0.1
23+import Ubuntu.Components.ListItems 1.0 as ListItem
24+import Unity.Application 0.1
25+
26+Rectangle {
27+ color: "red"
28+ id: root
29+ width: units.gu(70)
30+ height: units.gu(70)
31+
32+ Component {
33+ id: fakeSurfaceComponent
34+ Image {
35+ source: "../../../qml/Dash/graphics/phone/screenshots/gallery@12.png"
36+ width: applicationWindowLoader.width
37+ height: applicationWindowLoader.height
38+
39+ property var application: fakeApplication
40+ property int touchPressCount: 0
41+ property int touchReleaseCount: 0
42+
43+ Text {
44+ anchors.fill: parent
45+ text: "SURFACE"
46+ color: "yellow"
47+ font.bold: true
48+ fontSizeMode: Text.Fit
49+ minimumPixelSize: 10; font.pixelSize: 200
50+ verticalAlignment: Text.AlignVCenter
51+ }
52+
53+ MultiPointTouchArea {
54+ anchors.fill: parent
55+ onPressed: { touchPressCount++; }
56+ onReleased: { touchReleaseCount++; }
57+ }
58+
59+ signal removed()
60+
61+ function release() {
62+ fakeApplication.surface = null;
63+ parent = null;
64+ removed();
65+ surfaceCheckbox.checked = false;
66+ }
67+ }
68+ }
69+
70+ QtObject {
71+ id: fakeApplication
72+ property url screenshot: ""
73+
74+ function updateScreenshot() {
75+ fakeScreenshotTimer.start();
76+ }
77+
78+ function discardScreenshot() {
79+ screenshot = "";
80+ }
81+
82+ property alias state: appStateSelector.selectedApplicationState
83+ property string name: "Gallery"
84+ property url icon: "../../../qml/graphics/applicationIcons/gallery.png"
85+ property var surface: null
86+ }
87+ Timer {
88+ id: fakeScreenshotTimer
89+ interval: 100
90+ onTriggered: {
91+ fakeApplication.screenshot = "../../../qml/Dash/graphics/phone/screenshots/gallery@12.png";
92+ }
93+ }
94+
95+ Component {
96+ id: applicationWindowComponent
97+ ApplicationWindow {
98+ anchors.fill: parent
99+ application: fakeApplication
100+ }
101+ }
102+ Loader {
103+ id: applicationWindowLoader
104+ anchors {
105+ top: parent.top
106+ bottom: parent.bottom
107+ left: parent.left
108+ }
109+ width: units.gu(40)
110+ sourceComponent: applicationWindowComponent
111+ }
112+
113+ Rectangle {
114+ color: "white"
115+ anchors {
116+ top: parent.top
117+ bottom: parent.bottom
118+ left: applicationWindowLoader.right
119+ right: parent.right
120+ }
121+
122+ Column {
123+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
124+ spacing: units.gu(1)
125+ Row {
126+ anchors { left: parent.left; right: parent.right }
127+ CheckBox {
128+ id: surfaceCheckbox; checked: false
129+ onCheckedChanged: {
130+ if (applicationWindowLoader.status !== Loader.Ready)
131+ return;
132+
133+ if (checked && !fakeApplication.surface) {
134+ fakeApplication.surface = fakeSurfaceComponent.createObject(null, {});
135+ } else if (!checked && fakeApplication.surface) {
136+ fakeApplication.surface.release();
137+ }
138+ }
139+ }
140+ Label { text: "Surface" }
141+ }
142+ ListItem.ItemSelector {
143+ id: appStateSelector
144+ anchors { left: parent.left; right: parent.right }
145+ text: "Application state"
146+ model: ["Starting",
147+ "Running",
148+ "Suspended",
149+ "Stopped"]
150+ property int selectedApplicationState: {
151+ if (model[selectedIndex] === "Starting") {
152+ return ApplicationInfo.Starting;
153+ } else if (model[selectedIndex] === "Running") {
154+ return ApplicationInfo.Running;
155+ } else if (model[selectedIndex] === "Suspended") {
156+ return ApplicationInfo.Suspended;
157+ } else {
158+ return ApplicationInfo.Stopped;
159+ }
160+ }
161+ }
162+ }
163+ }
164+
165+ UT.UnityTestCase {
166+ id: testCase
167+ name: "ApplicationWindow"
168+ when: windowShown
169+
170+ // just to make them shorter
171+ property int appStarting: ApplicationInfo.Starting
172+ property int appRunning: ApplicationInfo.Running
173+ property int appSuspended: ApplicationInfo.Suspended
174+ property int appStopped: ApplicationInfo.Stopped
175+
176+ function setApplicationState(appState) {
177+ switch (appState) {
178+ case appStarting:
179+ appStateSelector.selectedIndex = 0;
180+ break;
181+ case appRunning:
182+ appStateSelector.selectedIndex = 1;
183+ break;
184+ case appSuspended:
185+ appStateSelector.selectedIndex = 2;
186+ break;
187+ case appStopped:
188+ appStateSelector.selectedIndex = 3;
189+ break;
190+ }
191+ }
192+
193+ function cleanup() {
194+ // reload our test subject to get it in a fresh state once again
195+ applicationWindowLoader.active = false;
196+
197+ appStateSelector.selectedIndex = 0;
198+ surfaceCheckbox.checked = false;
199+
200+ fakeScreenshotTimer.stop();
201+ fakeApplication.screenshot = "";
202+ fakeApplication.surface = null;
203+
204+ applicationWindowLoader.active = true;
205+ }
206+
207+ function test_showSplashUntilAppFullyInit1() {
208+ var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
209+
210+ verify(stateGroup.state === "splashScreen");
211+
212+ setApplicationState(appRunning);
213+
214+ verify(stateGroup.state === "splashScreen");
215+
216+ surfaceCheckbox.checked = true;
217+
218+ tryCompare(stateGroup, "state", "surface");
219+ }
220+
221+ function test_showSplashUntilAppFullyInit2() {
222+ var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
223+
224+ verify(stateGroup.state === "splashScreen");
225+
226+ surfaceCheckbox.checked = true;
227+
228+ verify(stateGroup.state === "splashScreen");
229+
230+ setApplicationState(appRunning);
231+
232+ tryCompare(stateGroup, "state", "surface");
233+ }
234+
235+ function test_suspendedAppShowsSurface() {
236+ var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
237+
238+ surfaceCheckbox.checked = true;
239+ setApplicationState(appRunning);
240+ tryCompare(stateGroup, "state", "surface");
241+
242+ setApplicationState(appSuspended);
243+
244+ for (var i = 0; i < 10; ++i) {
245+ wait(50);
246+ verify(stateGroup.state === "surface");
247+ }
248+ }
249+
250+ function test_killedAppShowsScreenshot() {
251+ var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
252+
253+ surfaceCheckbox.checked = true;
254+ setApplicationState(appRunning);
255+ tryCompare(stateGroup, "state", "surface");
256+
257+ setApplicationState(appSuspended);
258+
259+ verify(stateGroup.state === "surface");
260+ verify(fakeApplication.surface !== null);
261+
262+ // kill it!
263+ setApplicationState(appStopped);
264+
265+ tryCompare(stateGroup, "state", "screenshot");
266+ tryCompare(fakeApplication, "surface", null);
267+ }
268+
269+ function test_restartApp() {
270+ var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
271+
272+ surfaceCheckbox.checked = true;
273+ setApplicationState(appRunning);
274+ tryCompare(stateGroup, "state", "surface");
275+
276+ setApplicationState(appSuspended);
277+
278+ // kill it
279+ setApplicationState(appStopped);
280+
281+ tryCompare(stateGroup, "state", "screenshot");
282+ tryCompare(fakeApplication, "surface", null);
283+
284+ // and restart it
285+ setApplicationState(appStarting);
286+
287+ wait(50);
288+ verify(fakeApplication.surface === null);
289+ tryCompare(stateGroup, "state", "screenshot");
290+
291+ setApplicationState(appRunning);
292+
293+ wait(50);
294+ tryCompare(stateGroup, "state", "screenshot");
295+
296+ surfaceCheckbox.checked = true;
297+
298+ tryCompare(stateGroup, "state", "surface");
299+ tryCompare(fakeApplication, "screenshot", "");
300+ }
301+
302+ function test_appCrashed() {
303+ var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
304+
305+ surfaceCheckbox.checked = true;
306+ setApplicationState(appRunning);
307+ tryCompare(stateGroup, "state", "surface");
308+
309+ // oh, it crashed...
310+ setApplicationState(appStopped);
311+
312+ tryCompare(stateGroup, "state", "screenshot");
313+ tryCompare(fakeApplication, "surface", null);
314+ }
315+
316+ function test_keepSurfaceWhileInvisible() {
317+ var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
318+
319+ surfaceCheckbox.checked = true;
320+ setApplicationState(appRunning);
321+ tryCompare(stateGroup, "state", "surface");
322+ verify(fakeApplication.surface !== null);
323+
324+ applicationWindowLoader.item.visible = false;
325+
326+ wait(50);
327+ verify(stateGroup.state === "surface");
328+ verify(fakeApplication.surface !== null);
329+
330+ applicationWindowLoader.item.visible = true;
331+
332+ wait(50);
333+ verify(stateGroup.state === "surface");
334+ verify(fakeApplication.surface !== null);
335+ }
336+
337+ function test_touchesReachSurfaceWhenItsShown() {
338+ var stateGroup = findInvisibleChild(applicationWindowLoader.item, "applicationWindowStateGroup");
339+
340+ setApplicationState(appRunning);
341+ surfaceCheckbox.checked = true;
342+
343+ tryCompare(stateGroup, "state", "surface");
344+
345+ // wait until any transition animation has finished
346+ tryCompare(stateGroup, "transitioning", false, 2000);
347+
348+ fakeApplication.surface.touchPressCount = 0;
349+ fakeApplication.surface.touchReleaseCount = 0;
350+
351+ tap(applicationWindowLoader.item,
352+ applicationWindowLoader.item.width / 2, applicationWindowLoader.item.height / 2);
353+
354+ verify(fakeApplication.surface.touchPressCount === 1);
355+ verify(fakeApplication.surface.touchReleaseCount === 1);
356+ }
357+ }
358+}
359+
tests/qmltests/Stages/tst_PhoneStage.qml+33−4
@@ -46,6 +46,7 @@ Item {
4646 anchors { fill: parent; leftMargin: phoneStage.width }
4747
4848 Column {
49+ id: buttons
4950 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
5051 spacing: units.gu(1)
5152 Button {
@@ -57,9 +58,33 @@ Item {
5758 }
5859 Button {
5960 anchors { left: parent.left; right: parent.right }
60− text: "Remove App"
61+ text: "Remove Selected"
6162 onClicked: {
62− ApplicationManager.stopApplication(ApplicationManager.get(0).appId)
63+ ApplicationManager.stopApplication(ApplicationManager.get(appList.selectedAppIndex).appId);
64+ }
65+ }
66+ Button {
67+ anchors { left: parent.left; right: parent.right }
68+ text: "Stop Selected"
69+ onClicked: {
70+ ApplicationManager.get(appList.selectedAppIndex).setState(ApplicationInfo.Stopped);
71+ }
72+ }
73+ }
74+ ListView {
75+ id: appList
76+ property int selectedAppIndex
77+ anchors { left: parent.left; right: parent.right; top: buttons.bottom; bottom: parent.bottom }
78+ boundsBehavior: Flickable.StopAtBounds
79+ model: ApplicationManager
80+ delegate: Rectangle {
81+ anchors { left: parent.left; right: parent.right }
82+ height: units.gu(2)
83+ color: appList.selectedAppIndex === model.index ? "red" : "white"
84+ Text { anchors.fill: parent; text: model.appId }
85+ MouseArea {
86+ anchors.fill: parent
87+ onPressed: { appList.selectedAppIndex = model.index; }
6388 }
6489 }
6590 }
@@ -84,7 +109,9 @@ Item {
84109 function goToSpread() {
85110 var spreadView = findChild(phoneStage, "spreadView");
86111
87− var startX = phoneStage.width;
112+ // Keep it inside the PhoneStage otherwise the controls on the right side will
113+ // capture the press thus the "- 2" on startX.
114+ var startX = phoneStage.width - 2;
88115 var startY = phoneStage.height / 2;
89116 var endY = startY;
90117 var endX = units.gu(2);
@@ -132,7 +159,9 @@ Item {
132159
133160 var spreadView = findChild(phoneStage, "spreadView");
134161
135− var startX = phoneStage.width;
162+ // Keep it inside the PhoneStage otherwise the controls on the right side will
163+ // capture the press thus the "- 2" on startX.
164+ var startX = phoneStage.width - 2;
136165 var startY = phoneStage.height / 2;
137166 var endY = startY;
138167 var endX = spreadView.width - (spreadView.width * spreadView[data.positionMarker]) - data.offset;
tests/qmltests/Stages/tst_SpreadDelegate.qmlnew file+185
@@ -0,0 +1,185 @@
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.0
18+import QtTest 1.0
19+import Unity.Test 0.1 as UT
20+import ".."
21+import "../../../qml/Stages"
22+import Ubuntu.Components 0.1
23+import Ubuntu.Components.ListItems 1.0 as ListItem
24+import Unity.Application 0.1
25+
26+Rectangle {
27+ color: "red"
28+ id: root
29+ width: units.gu(70)
30+ height: units.gu(70)
31+
32+ QtObject {
33+ id: fakeApplication
34+ property url screenshot: ""
35+
36+ function updateScreenshot() {}
37+ function discardScreenshot() {}
38+
39+ property int state: ApplicationInfo.Running
40+ property string name: "Gallery"
41+ property url icon: "../../../qml/graphics/applicationIcons/gallery.png"
42+
43+ property var surface: Image {
44+ source: "../../../qml/Dash/graphics/phone/screenshots/gallery@12.png"
45+ width: spreadDelegateLoader.width
46+ height: spreadDelegateLoader.height
47+
48+ property var application: fakeApplication
49+
50+ signal removed()
51+ function release() {}
52+ }
53+ }
54+
55+ Component {
56+ id: spreadDelegateComponent
57+ SpreadDelegate {
58+ anchors.fill: parent
59+ swipeToCloseEnabled: swipeToCloseCheckbox.checked
60+ closeable: closeableCheckbox.checked
61+ application: fakeApplication
62+ }
63+ }
64+ Loader {
65+ id: spreadDelegateLoader
66+ anchors {
67+ top: parent.top
68+ bottom: parent.bottom
69+ left: parent.left
70+ }
71+ width: units.gu(40)
72+ sourceComponent: spreadDelegateComponent
73+ }
74+
75+ Rectangle {
76+ color: "white"
77+ anchors {
78+ top: parent.top
79+ bottom: parent.bottom
80+ left: spreadDelegateLoader.right
81+ right: parent.right
82+ }
83+
84+ Column {
85+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
86+ spacing: units.gu(1)
87+ Row {
88+ anchors { left: parent.left; right: parent.right }
89+ CheckBox { id: swipeToCloseCheckbox; checked: false; }
90+ Label { text: "swipeToCloseEnabled" }
91+ }
92+ Row {
93+ anchors { left: parent.left; right: parent.right }
94+ CheckBox { id: closeableCheckbox; checked: false }
95+ Label { text: "closeable" }
96+ }
97+ }
98+ }
99+
100+ UT.UnityTestCase {
101+ id: testCase
102+ name: "SpreadDelegate"
103+ when: windowShown
104+
105+ SignalSpy {
106+ id: spyClosedSignal
107+ target: spreadDelegateLoader.item
108+ signalName: "closed"
109+ }
110+
111+ property var dragArea
112+
113+ function init() {
114+ dragArea = findInvisibleChild(spreadDelegateLoader.item, "dragArea");
115+ dragArea.__dateTime = fakeDateTime;
116+ }
117+
118+ function cleanup() {
119+ // reload our test subject to get it in a fresh state once again
120+ spreadDelegateLoader.active = false;
121+ spreadDelegateLoader.active = true;
122+
123+ spyClosedSignal.clear();
124+ }
125+
126+ function test_swipeToClose_data() {
127+ return [
128+ {tag: "swipeToClose=true closeable=true -> appWindow moves away",
129+ swipeToClose: true, closeable: true },
130+
131+ {tag: "swipeToClose=true closeable=alse -> appWindow bounces back",
132+ swipeToClose: true, closeable: false },
133+
134+ {tag: "swipeToClose=false -> appWindow stays put",
135+ swipeToClose: false, closeable: true },
136+ ]
137+ }
138+
139+ function test_swipeToClose(data) {
140+ var appWindowWithShadow = findChild(spreadDelegateLoader.item, "appWindowWithShadow");
141+
142+ verify(appWindowWithShadow.y === 0);
143+
144+ swipeToCloseCheckbox.checked = data.swipeToClose;
145+ closeableCheckbox.checked = data.closeable;
146+
147+ var dragDistance = spreadDelegateLoader.item.height / 2;
148+ var touchX = spreadDelegateLoader.item.width / 2;
149+ var fromY = spreadDelegateLoader.item.height / 2;
150+ var toY = fromY - dragDistance;
151+ touchFlick(spreadDelegateLoader.item,
152+ touchX /* fromX */, fromY, touchX /* toX */, toY,
153+ true /* beginTouch */, false /* endTouch */, dragArea.minSpeedToClose * 1.1 /* speed */);
154+
155+
156+ if (data.swipeToClose) {
157+ verify(appWindowWithShadow.y < 0);
158+ verify(Math.abs(Math.abs(appWindowWithShadow.y) - dragDistance) < units.gu(1));
159+
160+ touchRelease(spreadDelegateLoader.item, touchX, toY - units.gu(1));
161+
162+ waitForCloseAnimationToFinish();
163+
164+ if (data.closeable) {
165+ verify(spyClosedSignal.count === 1);
166+ } else {
167+ verify(spyClosedSignal.count === 0);
168+ tryCompare(appWindowWithShadow, "y", 0);
169+ }
170+
171+ } else {
172+ verify(appWindowWithShadow.y === 0);
173+
174+ touchRelease(spreadDelegateLoader.item, touchX, toY);
175+ }
176+ }
177+
178+ function waitForCloseAnimationToFinish() {
179+ var closeAnimation = findInvisibleChild(spreadDelegateLoader.item, "closeAnimation");
180+ wait(closeAnimation.duration * 1.5);
181+ tryCompare(closeAnimation, "running", false);
182+ }
183+
184+ }
185+}
tests/utils/modules/Unity/Test/UnityTestCase.qml+5−2
@@ -312,12 +312,15 @@ TestCase {
312312 }
313313
314314 function tap(item, x, y) {
315+ var root = fetchRootItem(item)
316+ var rootPoint = item.mapToItem(root, x, y)
317+
315318 var event = touchEvent()
316− event.press(0 /* touchId */, x, y)
319+ event.press(0 /* touchId */, rootPoint.x, rootPoint.y)
317320 event.commit()
318321
319322 event = touchEvent()
320− event.release(0 /* touchId */, x, y)
323+ event.release(0 /* touchId */, rootPoint.x, rootPoint.y)
321324 event.commit()
322325 }
323326