Merge lp:~unity-team/unity-api/add-surfacemanager-and-item into lp:~unity-team/unity-api/qtMirCompositor
- add-surfacemanager-and-item
- Merge into qtMirCompositor
Status: | Needs review |
---|---|
Proposed branch: | lp:~unity-team/unity-api/add-surfacemanager-and-item |
Merge into: | lp:~unity-team/unity-api/qtMirCompositor |
Diff against target: |
937 lines (+819/-5) 14 files modified
include/unity/shell/application/ApplicationManagerInterface.h (+0/-1) include/unity/shell/application/SurfaceInterface.h (+136/-0) include/unity/shell/application/SurfaceItemInterface.h (+79/-0) include/unity/shell/application/SurfaceManagerInterface.h (+130/-0) test/qmltest/mocks/plugins/Unity/Application/CMakeLists.txt (+7/-1) test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurface.cpp (+50/-0) test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurface.h (+45/-0) test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceItem.cpp (+28/-0) test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceItem.h (+38/-0) test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceManager.cpp (+68/-0) test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceManager.h (+47/-0) test/qmltest/mocks/plugins/Unity/Application/TestApplicationPlugin.cpp (+22/-3) test/qmltest/unity/shell/CMakeLists.txt (+1/-0) test/qmltest/unity/shell/application/tst_Surface.qml (+168/-0) |
To merge this branch: | bzr merge lp:~unity-team/unity-api/add-surfacemanager-and-item |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity8 CI Bot | continuous-integration | Needs Fixing | |
Gerry Boland (community) | Needs Fixing | ||
Review via email: mp+217916@code.launchpad.net |
This proposal supersedes a proposal from 2014-04-08.
Commit message
Add support for Surfaces to Unity.Application api.
Description of the change
To be discussed...
Michael Zanetti (mzanetti) wrote : | # |
> On 01.05.2014 15:48, Michael Zanetti wrote:
> > + enum State {
> > + Unknown = mir_surface_
> > + Restored = mir_surface_
> > + Minimized = mir_surface_
> > + Maximized = mir_surface_
> > + VertMaximized = mir_surface_
> > + /* SemiMaximized = mir_surface_
> mircommon/
> > + Fullscreen = mir_surface_
> > + };
>
> We've been playing with the idea of expressing "stage-ness" with those
> (since we probably want to support sidestage on desktop). I understand
> Mir probably doesn't want explicit MainStage, SideStage, but maybe
> something could be discussed?
I haven't been part of that so I might not know all details, but seems to me that Stage-ness is more related to the whole application instead of a single surface. Or do we want to allow a single Application to paint to the Main and Side stage at the same time?
>
> > + void surfaceCreated(
> > + void surfaceDestroye
>
> Wouldn't those be redundant to row additions/removals? What's the use
> case here?
I've added them in ApplicationManager because its really nasty to figure which one has been added/removed without having knowledge of the QModelIndex. So I thought they'd be useful here too. They'll probably change to "surfaceAdded(
>
> > +protected:
> > + /// @cond
> > + QHash<int, QByteArray> m_roleNames;
>
> I know this is early, but didn't we decide that creating the hash
> dynamically in roleNames() is better, since there's no use for this
> member other than returning it from there (and only once in most cases)?
right... will change, thanks for the pointer.
- 130. By Michael Zanetti
-
some more work on the new surface api
- 131. By Michael Zanetti
-
Split SurfaceItem into SurfaceItem and Surface.
- 132. By Michael Zanetti
-
some cleanup and commenting
- 133. By Michael Zanetti
-
make tests work
- 134. By Michael Zanetti
-
also make use of setting the surface property
Gerry Boland (gerboland) wrote : | # |
+++ include/
+ Q_PROPERTY(QString appId READ appId CONSTANT)
Why not a pointer to the application?
Would be useful to be able to directly read Application info in QML with something like: "surface.
It will require care to ensure the Application isn't used if it is deleted though (since a SurfaceItem will have QML ownership, but Application C++ ownership).
I expect the Application has some properties that we easily want to monitor per-surface, examples that come to mind are stage, supportedStages, state, hasFrozen (if app not responding) and maybe focus.
Note every Surface must have an Application behind it, else we make our lives hard IMO.
+class UNITY_API SurfaceItemInte
Design is exactly what I had in mind.
I'm wondering though if instead of accessing the surface properties like:
"mySurfaceItem.
What do you think? It's syntactic sugar really...
+ * @brief Get a Surface item (using stack index).
Stack or list?
Nitpick:
+ while (!m_list.empty())
+ {
brace on same line.
Overall this API is plenty to get us moving.
One thing I note is that getting info on the application which generates a surface is easy, but getting the surfaces that an application generates is hard. I can't come up with a good reason why the latter is needed however, so for now let's leave it as it is.
Unity8 CI Bot (unity8-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:134
https:/
Executed test runs:
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Michał Sawicz (saviq) wrote : | # |
Text conflict in test/qmltest/
Text conflict in test/qmltest/
2 conflicts encountered.
Unmerged revisions
- 134. By Michael Zanetti
-
also make use of setting the surface property
- 133. By Michael Zanetti
-
make tests work
- 132. By Michael Zanetti
-
some cleanup and commenting
- 131. By Michael Zanetti
-
Split SurfaceItem into SurfaceItem and Surface.
- 130. By Michael Zanetti
-
some more work on the new surface api
- 129. By Michael Zanetti
-
some cleanup
- 128. By Michael Zanetti
-
add very first draft of SurfaceManagerI
nterface and SurfaceItemInte rface
Preview Diff
1 | === modified file 'include/unity/shell/application/ApplicationManagerInterface.h' |
2 | --- include/unity/shell/application/ApplicationManagerInterface.h 2014-03-10 12:40:25 +0000 |
3 | +++ include/unity/shell/application/ApplicationManagerInterface.h 2014-05-05 12:17:41 +0000 |
4 | @@ -82,7 +82,6 @@ |
5 | connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), SIGNAL(countChanged())); |
6 | connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), SIGNAL(countChanged())); |
7 | connect(this, SIGNAL(modelReset()), SIGNAL(countChanged())); |
8 | - connect(this, SIGNAL(layoutChanged()), SIGNAL(countChanged())); |
9 | } |
10 | /// @endcond |
11 | |
12 | |
13 | === added file 'include/unity/shell/application/SurfaceInterface.h' |
14 | --- include/unity/shell/application/SurfaceInterface.h 1970-01-01 00:00:00 +0000 |
15 | +++ include/unity/shell/application/SurfaceInterface.h 2014-05-05 12:17:41 +0000 |
16 | @@ -0,0 +1,136 @@ |
17 | +/* |
18 | + * Copyright (C) 2014 Canonical, Ltd. |
19 | + * |
20 | + * This program is free software: you can redistribute it and/or modify it under |
21 | + * the terms of the GNU Lesser General Public License version 3, as published by |
22 | + * the Free Software Foundation. |
23 | + * |
24 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
25 | + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
26 | + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
27 | + * Lesser General Public License for more details. |
28 | + * |
29 | + * You should have received a copy of the GNU Lesser General Public License |
30 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31 | + */ |
32 | + |
33 | +#ifndef SURFACEINTERFACE_H |
34 | +#define SURFACEINTERFACE_H |
35 | + |
36 | +#include <unity/SymbolExport.h> |
37 | + |
38 | +#include <QObject> |
39 | + |
40 | +namespace unity |
41 | +{ |
42 | +namespace shell |
43 | +{ |
44 | +namespace application |
45 | +{ |
46 | + |
47 | +class SurfaceManagerInterface; |
48 | +class ApplicationInfoInterface; |
49 | + |
50 | +/** |
51 | + * @brief A class that holds information about an application's surface |
52 | + * |
53 | + * The items hold all the information required for the visual representation |
54 | + * of a surface. |
55 | + */ |
56 | + |
57 | +class UNITY_API SurfaceInterface: public QObject |
58 | +{ |
59 | + Q_OBJECT |
60 | + Q_ENUMS(Type) |
61 | + Q_ENUMS(SurfaceState) |
62 | + |
63 | + /** |
64 | + * @brief The type of this surface. |
65 | + * |
66 | + * Gives information about the type of this surface. E.g. it is a normal window or a modal popup. |
67 | + */ |
68 | + Q_PROPERTY(Type type READ type NOTIFY typeChanged) |
69 | + |
70 | + /** |
71 | + * @brief The state of this surface. |
72 | + * |
73 | + * Holds information about the state of this surface. E.g. it is shown normally or minimized. |
74 | + */ |
75 | + Q_PROPERTY(SurfaceState surfaceState READ surfaceState NOTIFY surfaceStateChanged) |
76 | + |
77 | + /** |
78 | + * @brief The name of this surface. |
79 | + * |
80 | + * Holds the name of this surface. Can be used e.g. for the window title. |
81 | + */ |
82 | + Q_PROPERTY(QString name READ name NOTIFY nameChanged) |
83 | + |
84 | + /** |
85 | + * @brief The application this surface belongs to. |
86 | + * |
87 | + * A 1:n connection between surfaces and applications. A surface always refers to one |
88 | + * application, while an application might have many surfaces. |
89 | + */ |
90 | + Q_PROPERTY(QString appId READ appId CONSTANT) |
91 | + |
92 | +public: |
93 | + /** |
94 | + * @brief The type of a surface. |
95 | + * |
96 | + * This enum defines all possible values for Surface types. |
97 | + */ |
98 | + enum Type { |
99 | + TypeNormal, |
100 | + TypeUtility, |
101 | + TypeDialog, |
102 | + TypeOverlay, |
103 | + TypeFreestyle, |
104 | + TypePopover, |
105 | + TypeInputMethod, |
106 | + }; |
107 | + |
108 | + /** |
109 | + * @brief The state of a surface. |
110 | + * |
111 | + * This enum defines all possible values for Surface states. |
112 | + */ |
113 | + enum SurfaceState { |
114 | + SurfaceStateUnknown, |
115 | + SurfaceStateRestored, |
116 | + SurfaceStateMinimized, |
117 | + SurfaceStateMaximized, |
118 | + SurfaceStateVertMaximized, |
119 | + /* SurfaceStateSemiMaximized, // see mircommon/mir_toolbox/common.h*/ |
120 | + SurfaceStateFullscreen, |
121 | + }; |
122 | + |
123 | + /** |
124 | + * @brief Constructs a new Surface. |
125 | + * |
126 | + * Usually Surfaces are only created by the ApplicationManager and/or SurfaceManager. |
127 | + */ |
128 | + explicit SurfaceInterface(QObject *parent = 0): QObject(parent) {} |
129 | + virtual ~SurfaceInterface() {} |
130 | + |
131 | + /// @cond |
132 | + virtual QString appId() const = 0; |
133 | + virtual Type type() const = 0; |
134 | + virtual SurfaceState surfaceState() const = 0; |
135 | + virtual QString name() const = 0; |
136 | + /// @endcond |
137 | + |
138 | +Q_SIGNALS: |
139 | + /// @cond |
140 | + void typeChanged(); |
141 | + void surfaceStateChanged(); |
142 | + void nameChanged(); |
143 | + void appIdChanged(); |
144 | + void surfaceDestroyed(); |
145 | + /// @endcond |
146 | +}; |
147 | + |
148 | +} // namespace application |
149 | +} // namespace shell |
150 | +} // namespace unity |
151 | + |
152 | +#endif // SURFACEINTERFACE_H |
153 | |
154 | === added file 'include/unity/shell/application/SurfaceItemInterface.h' |
155 | --- include/unity/shell/application/SurfaceItemInterface.h 1970-01-01 00:00:00 +0000 |
156 | +++ include/unity/shell/application/SurfaceItemInterface.h 2014-05-05 12:17:41 +0000 |
157 | @@ -0,0 +1,79 @@ |
158 | +/* |
159 | + * Copyright (C) 2014 Canonical, Ltd. |
160 | + * |
161 | + * This program is free software: you can redistribute it and/or modify it under |
162 | + * the terms of the GNU Lesser General Public License version 3, as published by |
163 | + * the Free Software Foundation. |
164 | + * |
165 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
166 | + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
167 | + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
168 | + * Lesser General Public License for more details. |
169 | + * |
170 | + * You should have received a copy of the GNU Lesser General Public License |
171 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
172 | + */ |
173 | + |
174 | +#ifndef UNITY_SHELL_APPLICATION_SURFACEITEMINTERFACE_H |
175 | +#define UNITY_SHELL_APPLICATION_SURFACEITEMINTERFACE_H |
176 | + |
177 | +#include <unity/SymbolExport.h> |
178 | + |
179 | +#include "SurfaceInterface.h" |
180 | + |
181 | +#include <QQuickItem> |
182 | + |
183 | +namespace unity |
184 | +{ |
185 | +namespace shell |
186 | +{ |
187 | +namespace application |
188 | +{ |
189 | + |
190 | +class SurfaceManagerInterface; |
191 | +class Application; |
192 | + |
193 | +/** |
194 | + * @brief A class that paints a SurfaceInterface in QML. |
195 | + * |
196 | + * This class doesn't hold any data on its own but is used to paint a SurfaceInterface |
197 | + * in QML. SurfaceItems can be created and destroyed by the QML context as if they |
198 | + * were plain Rectangles. By assigning a SurfaceInterface to it, application |
199 | + * surfaces can be painted in the shell. |
200 | + */ |
201 | + |
202 | +class UNITY_API SurfaceItemInterface: public QQuickItem |
203 | +{ |
204 | + Q_OBJECT |
205 | + |
206 | + /** |
207 | + * @brief The surface that should be painted. |
208 | + * |
209 | + * Set this to the Surface you want to have painted by this SurfaceItem. |
210 | + */ |
211 | + Q_PROPERTY(unity::shell::application::SurfaceInterface* surface MEMBER m_surface NOTIFY surfaceChanged) |
212 | + |
213 | +public: |
214 | + |
215 | + /** |
216 | + * @brief Constructs a SurfaceItem. |
217 | + * |
218 | + * Usually SurfaceItems are created within QML. |
219 | + */ |
220 | + explicit SurfaceItemInterface(QQuickItem *parent = 0): QQuickItem(parent) {} |
221 | + virtual ~SurfaceItemInterface() {} |
222 | + |
223 | +Q_SIGNALS: |
224 | + /// @cond |
225 | + void surfaceChanged(); |
226 | + /// @endcond |
227 | + |
228 | +private: |
229 | + SurfaceInterface *m_surface; |
230 | +}; |
231 | + |
232 | +} // namespace application |
233 | +} // namespace shell |
234 | +} // namespace unity |
235 | + |
236 | +#endif // UNITY_SHELL_APPLICATION_SURFACEITEMINTERFACE_H |
237 | |
238 | === added file 'include/unity/shell/application/SurfaceManagerInterface.h' |
239 | --- include/unity/shell/application/SurfaceManagerInterface.h 1970-01-01 00:00:00 +0000 |
240 | +++ include/unity/shell/application/SurfaceManagerInterface.h 2014-05-05 12:17:41 +0000 |
241 | @@ -0,0 +1,130 @@ |
242 | +/* |
243 | + * Copyright (C) 2014 Canonical, Ltd. |
244 | + * |
245 | + * This program is free software: you can redistribute it and/or modify it under |
246 | + * the terms of the GNU Lesser General Public License version 3, as published by |
247 | + * the Free Software Foundation. |
248 | + * |
249 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
250 | + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
251 | + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
252 | + * Lesser General Public License for more details. |
253 | + * |
254 | + * You should have received a copy of the GNU Lesser General Public License |
255 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
256 | + */ |
257 | + |
258 | +#ifndef UNITY_SHELL_APPLICATION_SURFACEMANGERINTERFACE_H |
259 | +#define UNITY_SHELL_APPLICATION_SURFACEMANGERINTERFACE_H |
260 | + |
261 | +#include <unity/SymbolExport.h> |
262 | + |
263 | +#include <QAbstractListModel> |
264 | + |
265 | +namespace unity |
266 | +{ |
267 | +namespace shell |
268 | +{ |
269 | +namespace application |
270 | +{ |
271 | + |
272 | +class SurfaceInterface; |
273 | + |
274 | +/** |
275 | + * @brief The SurfaceManager is a model which holds all the available surfaces. |
276 | + * |
277 | + * This is the main class to interact with surfaces. |
278 | + */ |
279 | + |
280 | +class UNITY_API SurfaceManagerInterface : public QAbstractListModel |
281 | +{ |
282 | + Q_OBJECT |
283 | + Q_ENUMS(Roles) |
284 | + |
285 | + /** |
286 | + * @brief The count of the surfaces known to the manager. |
287 | + * |
288 | + * This is the same as rowCount, added in order to keep compatibility with QML ListModels. |
289 | + */ |
290 | + Q_PROPERTY(int count READ count NOTIFY countChanged) |
291 | + |
292 | +public: |
293 | + /** |
294 | + * @brief The Roles supported by the model |
295 | + * |
296 | + * See SurfaceInterface properties for details. |
297 | + */ |
298 | + enum Roles { |
299 | + RoleType, |
300 | + RoleSurfaceState, |
301 | + RoleName, |
302 | + RoleApplicationId |
303 | + }; |
304 | + |
305 | + virtual ~SurfaceManagerInterface() {} |
306 | + |
307 | + /// @cond |
308 | + virtual QHash<int, QByteArray> roleNames() const |
309 | + { |
310 | + QHash<int, QByteArray> roles; |
311 | + roles.insert(RoleType, "type"); |
312 | + roles.insert(RoleSurfaceState, "surfaceState"); |
313 | + roles.insert(RoleName, "name"); |
314 | + roles.insert(RoleApplicationId, "appId"); |
315 | + return roles; |
316 | + } |
317 | + |
318 | + int count() const { |
319 | + return rowCount(); |
320 | + } |
321 | + /// @endcond |
322 | + |
323 | + /** |
324 | + * @brief Get a Surface item (using stack index). |
325 | + * |
326 | + * Note: QML requires the full namespace in the return value. |
327 | + * |
328 | + * @param index the index of the item to get |
329 | + * @returns The item, or null if not found. |
330 | + */ |
331 | + Q_INVOKABLE virtual unity::shell::application::SurfaceInterface *get(int index) const = 0; |
332 | + |
333 | +protected: |
334 | + /// @cond |
335 | + SurfaceManagerInterface(QObject *parent = 0): |
336 | + QAbstractListModel(parent) |
337 | + { |
338 | + connect(this, &QAbstractListModel::rowsInserted, this, &SurfaceManagerInterface::countChanged); |
339 | + connect(this, &QAbstractListModel::rowsRemoved, this, &SurfaceManagerInterface::countChanged); |
340 | + connect(this, &QAbstractListModel::modelReset, this, &SurfaceManagerInterface::countChanged); |
341 | + } |
342 | + /// @endcond |
343 | + |
344 | +Q_SIGNALS: |
345 | + /// @cond |
346 | + void countChanged(); |
347 | + /// @endcond |
348 | + |
349 | + /** |
350 | + * @brief Indicates that a new surface has been created. |
351 | + * |
352 | + * This will be emitted when a new surface has been created and added |
353 | + * to the model. It is the same as the rowsInserted() but more QML friendly. |
354 | + */ |
355 | + void surfaceCreated(SurfaceInterface* surface); |
356 | + |
357 | + /** |
358 | + * @brief Indicates that a surface has been destroyed. |
359 | + * |
360 | + * This will be emitted when a surface has been destroyed and removed |
361 | + * from the model. It is the same as the rowsRemoved() but more QML friendly. |
362 | + */ |
363 | + void surfaceDestroyed(SurfaceInterface* surface); |
364 | + |
365 | +}; |
366 | + |
367 | +} // namespace application |
368 | +} // namespace shell |
369 | +} // namespace unity |
370 | + |
371 | +#endif // UNITY_SHELL_APPLICATION_SURFACEMANGERINTERFACE_H |
372 | |
373 | === modified file 'test/qmltest/mocks/plugins/Unity/Application/CMakeLists.txt' |
374 | --- test/qmltest/mocks/plugins/Unity/Application/CMakeLists.txt 2013-08-29 12:54:56 +0000 |
375 | +++ test/qmltest/mocks/plugins/Unity/Application/CMakeLists.txt 2014-05-05 12:17:41 +0000 |
376 | @@ -13,13 +13,19 @@ |
377 | set(ApplicationMocks_SOURCES |
378 | ${CMAKE_SOURCE_DIR}/include/unity/shell/application/ApplicationManagerInterface.h |
379 | ${CMAKE_SOURCE_DIR}/include/unity/shell/application/ApplicationInfoInterface.h |
380 | + ${CMAKE_SOURCE_DIR}/include/unity/shell/application/SurfaceManagerInterface.h |
381 | + ${CMAKE_SOURCE_DIR}/include/unity/shell/application/SurfaceItemInterface.h |
382 | + ${CMAKE_SOURCE_DIR}/include/unity/shell/application/SurfaceInterface.h |
383 | Mocks/MockApplicationManager.cpp |
384 | Mocks/MockApplicationInfo.cpp |
385 | + Mocks/MockSurfaceManager.cpp |
386 | + Mocks/MockSurfaceItem.cpp |
387 | + Mocks/MockSurface.cpp |
388 | ) |
389 | |
390 | add_library(ApplicationMocks SHARED ${ApplicationMocks_SOURCES}) |
391 | |
392 | -qt5_use_modules(ApplicationMocks Core) |
393 | +qt5_use_modules(ApplicationMocks Core Quick) |
394 | |
395 | set(TestApplicationPlugin_SOURCES |
396 | TestApplicationPlugin.cpp |
397 | |
398 | === added file 'test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurface.cpp' |
399 | --- test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurface.cpp 1970-01-01 00:00:00 +0000 |
400 | +++ test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurface.cpp 2014-05-05 12:17:41 +0000 |
401 | @@ -0,0 +1,50 @@ |
402 | +/* |
403 | + * Copyright 2014 Canonical Ltd. |
404 | + * |
405 | + * This program is free software; you can redistribute it and/or modify |
406 | + * it under the terms of the GNU Lesser General Public License as published by |
407 | + * the Free Software Foundation; version 3. |
408 | + * |
409 | + * This program is distributed in the hope that it will be useful, |
410 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
411 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
412 | + * GNU Lesser General Public License for more details. |
413 | + * |
414 | + * You should have received a copy of the GNU Lesser General Public License |
415 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
416 | + * |
417 | + * Authors: |
418 | + * Michael Zanetti <michael.zanetti@canonical.com> |
419 | + */ |
420 | + |
421 | +#include <Mocks/MockSurface.h> |
422 | + |
423 | +using namespace unity::shell::application; |
424 | + |
425 | +MockSurface::MockSurface(const QString &appId, const QString &name, QObject *parent): |
426 | + SurfaceInterface(parent), |
427 | + m_appId(appId), |
428 | + m_name(name) |
429 | +{ |
430 | + |
431 | +} |
432 | + |
433 | +QString MockSurface::appId() const |
434 | +{ |
435 | + return m_appId; |
436 | +} |
437 | + |
438 | +SurfaceInterface::Type MockSurface::type() const |
439 | +{ |
440 | + return SurfaceInterface::TypeNormal; |
441 | +} |
442 | + |
443 | +SurfaceInterface::SurfaceState MockSurface::surfaceState() const |
444 | +{ |
445 | + return SurfaceInterface::SurfaceStateRestored; |
446 | +} |
447 | + |
448 | +QString MockSurface::name() const |
449 | +{ |
450 | + return m_name; |
451 | +} |
452 | |
453 | === added file 'test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurface.h' |
454 | --- test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurface.h 1970-01-01 00:00:00 +0000 |
455 | +++ test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurface.h 2014-05-05 12:17:41 +0000 |
456 | @@ -0,0 +1,45 @@ |
457 | +/* |
458 | + * Copyright 2014 Canonical Ltd. |
459 | + * |
460 | + * This program is free software; you can redistribute it and/or modify |
461 | + * it under the terms of the GNU Lesser General Public License as published by |
462 | + * the Free Software Foundation; version 3. |
463 | + * |
464 | + * This program is distributed in the hope that it will be useful, |
465 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
466 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
467 | + * GNU Lesser General Public License for more details. |
468 | + * |
469 | + * You should have received a copy of the GNU Lesser General Public License |
470 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
471 | + * |
472 | + * Authors: |
473 | + * Michael Zanetti <michael.zanetti@canonical.com> |
474 | + */ |
475 | + |
476 | +#ifndef MOCKSURFACE_H |
477 | +#define MOCKSURFACE_H |
478 | + |
479 | +#include <SurfaceInterface.h> |
480 | + |
481 | +#include <QUrl> |
482 | + |
483 | +using namespace unity::shell::application; |
484 | + |
485 | +class UNITY_API MockSurface: public SurfaceInterface |
486 | +{ |
487 | + Q_OBJECT |
488 | +public: |
489 | + MockSurface(const QString &appId, const QString &name, QObject* parent = 0); |
490 | + |
491 | + QString appId() const override; |
492 | + SurfaceInterface::Type type() const override; |
493 | + SurfaceInterface::SurfaceState surfaceState() const override; |
494 | + QString name() const override; |
495 | + |
496 | +private: |
497 | + QString m_appId; |
498 | + QString m_name; |
499 | +}; |
500 | + |
501 | +#endif // MOCKSURFACE_H |
502 | |
503 | === added file 'test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceItem.cpp' |
504 | --- test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceItem.cpp 1970-01-01 00:00:00 +0000 |
505 | +++ test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceItem.cpp 2014-05-05 12:17:41 +0000 |
506 | @@ -0,0 +1,28 @@ |
507 | +/* |
508 | + * Copyright 2014 Canonical Ltd. |
509 | + * |
510 | + * This program is free software; you can redistribute it and/or modify |
511 | + * it under the terms of the GNU Lesser General Public License as published by |
512 | + * the Free Software Foundation; version 3. |
513 | + * |
514 | + * This program is distributed in the hope that it will be useful, |
515 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
516 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
517 | + * GNU Lesser General Public License for more details. |
518 | + * |
519 | + * You should have received a copy of the GNU Lesser General Public License |
520 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
521 | + * |
522 | + * Authors: |
523 | + * Michael Zanetti <michael.zanetti@canonical.com> |
524 | + */ |
525 | + |
526 | +#include <Mocks/MockSurfaceItem.h> |
527 | + |
528 | +using namespace unity::shell::application; |
529 | + |
530 | +MockSurfaceItem::MockSurfaceItem(QQuickItem *parent): |
531 | + SurfaceItemInterface(parent) |
532 | +{ |
533 | + |
534 | +} |
535 | |
536 | === added file 'test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceItem.h' |
537 | --- test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceItem.h 1970-01-01 00:00:00 +0000 |
538 | +++ test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceItem.h 2014-05-05 12:17:41 +0000 |
539 | @@ -0,0 +1,38 @@ |
540 | +/* |
541 | + * Copyright 2014 Canonical Ltd. |
542 | + * |
543 | + * This program is free software; you can redistribute it and/or modify |
544 | + * it under the terms of the GNU Lesser General Public License as published by |
545 | + * the Free Software Foundation; version 3. |
546 | + * |
547 | + * This program is distributed in the hope that it will be useful, |
548 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
549 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
550 | + * GNU Lesser General Public License for more details. |
551 | + * |
552 | + * You should have received a copy of the GNU Lesser General Public License |
553 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
554 | + * |
555 | + * Authors: |
556 | + * Michael Zanetti <michael.zanetti@canonical.com> |
557 | + */ |
558 | + |
559 | +#ifndef MOCKSURFACEITEM_H |
560 | +#define MOCKSURFACEITEM_H |
561 | + |
562 | +#include <SurfaceItemInterface.h> |
563 | + |
564 | +#include <QUrl> |
565 | + |
566 | +using namespace unity::shell::application; |
567 | + |
568 | +class UNITY_API MockSurfaceItem: public SurfaceItemInterface |
569 | +{ |
570 | + Q_OBJECT |
571 | +public: |
572 | + MockSurfaceItem(QQuickItem* parent = 0); |
573 | + |
574 | +private: |
575 | +}; |
576 | + |
577 | +#endif // MOCKSURFACEITEM_H |
578 | |
579 | === added file 'test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceManager.cpp' |
580 | --- test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceManager.cpp 1970-01-01 00:00:00 +0000 |
581 | +++ test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceManager.cpp 2014-05-05 12:17:41 +0000 |
582 | @@ -0,0 +1,68 @@ |
583 | +/* |
584 | + * Copyright 2014 Canonical Ltd. |
585 | + * |
586 | + * This program is free software; you can redistribute it and/or modify |
587 | + * it under the terms of the GNU Lesser General Public License as published by |
588 | + * the Free Software Foundation; version 3. |
589 | + * |
590 | + * This program is distributed in the hope that it will be useful, |
591 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
592 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
593 | + * GNU Lesser General Public License for more details. |
594 | + * |
595 | + * You should have received a copy of the GNU Lesser General Public License |
596 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
597 | + * |
598 | + * Authors: |
599 | + * Michael Zanetti <michael.zanetti@canonical.com> |
600 | + */ |
601 | + |
602 | +#include <Mocks/MockSurfaceManager.h> |
603 | +#include <Mocks/MockSurface.h> |
604 | + |
605 | +using namespace unity::shell::application; |
606 | + |
607 | +MockSurfaceManager::MockSurfaceManager(QObject* parent): SurfaceManagerInterface(parent) |
608 | +{ |
609 | + MockSurface *item = new MockSurface("dialer-app", "surface1", this); |
610 | + m_list.append(item); |
611 | +} |
612 | + |
613 | +MockSurfaceManager::~MockSurfaceManager() |
614 | +{ |
615 | + while (!m_list.empty()) |
616 | + { |
617 | + m_list.takeFirst()->deleteLater(); |
618 | + } |
619 | +} |
620 | + |
621 | +// cppcheck-suppress unusedFunction |
622 | +int MockSurfaceManager::rowCount(const QModelIndex& parent) const |
623 | +{ |
624 | + Q_UNUSED(parent) |
625 | + return m_list.count(); |
626 | +} |
627 | + |
628 | +QVariant MockSurfaceManager::data(const QModelIndex& index, int role) const |
629 | +{ |
630 | + switch (role) { |
631 | + case RoleApplicationId: |
632 | + return m_list.at(index.row())->appId(); |
633 | + case RoleName: |
634 | + return m_list.at(index.row())->name(); |
635 | + case RoleType: |
636 | + return m_list.at(index.row())->type(); |
637 | + case RoleSurfaceState: |
638 | + return m_list.at(index.row())->surfaceState(); |
639 | + } |
640 | + |
641 | + return QVariant(); |
642 | +} |
643 | + |
644 | +SurfaceInterface *MockSurfaceManager::get(int index) const |
645 | +{ |
646 | + if (m_list.count() > index) { |
647 | + return m_list.at(index); |
648 | + } |
649 | + return nullptr; |
650 | +} |
651 | |
652 | === added file 'test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceManager.h' |
653 | --- test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceManager.h 1970-01-01 00:00:00 +0000 |
654 | +++ test/qmltest/mocks/plugins/Unity/Application/Mocks/MockSurfaceManager.h 2014-05-05 12:17:41 +0000 |
655 | @@ -0,0 +1,47 @@ |
656 | +/* |
657 | + * Copyright 2014 Canonical Ltd. |
658 | + * |
659 | + * This program is free software; you can redistribute it and/or modify |
660 | + * it under the terms of the GNU Lesser General Public License as published by |
661 | + * the Free Software Foundation; version 3. |
662 | + * |
663 | + * This program is distributed in the hope that it will be useful, |
664 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
665 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
666 | + * GNU Lesser General Public License for more details. |
667 | + * |
668 | + * You should have received a copy of the GNU Lesser General Public License |
669 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
670 | + * |
671 | + * Authors: |
672 | + * Michael Zanetti <michael.zanetti@canonical.com> |
673 | + */ |
674 | + |
675 | +#ifndef MOCKSURFACEMANAGER_H |
676 | +#define MOCKSURFACEMANAGER_H |
677 | + |
678 | +#include <SurfaceManagerInterface.h> |
679 | + |
680 | +using namespace unity::shell::application; |
681 | + |
682 | +class MockSurface; |
683 | + |
684 | +class UNITY_API MockSurfaceManager: public SurfaceManagerInterface |
685 | +{ |
686 | + Q_OBJECT |
687 | + |
688 | +public: |
689 | + MockSurfaceManager(QObject* parent = 0); |
690 | + ~MockSurfaceManager(); |
691 | + |
692 | + int rowCount(const QModelIndex& parent) const override; |
693 | + |
694 | + QVariant data(const QModelIndex& index, int role) const override; |
695 | + |
696 | + Q_INVOKABLE unity::shell::application::SurfaceInterface* get(int index) const override; |
697 | + |
698 | +private: |
699 | + QList<MockSurface*> m_list; |
700 | +}; |
701 | + |
702 | +#endif // MOCKSURFACEMANAGER_H |
703 | |
704 | === modified file 'test/qmltest/mocks/plugins/Unity/Application/TestApplicationPlugin.cpp' |
705 | --- test/qmltest/mocks/plugins/Unity/Application/TestApplicationPlugin.cpp 2013-08-29 12:54:56 +0000 |
706 | +++ test/qmltest/mocks/plugins/Unity/Application/TestApplicationPlugin.cpp 2014-05-05 12:17:41 +0000 |
707 | @@ -20,26 +20,45 @@ |
708 | #include <TestApplicationPlugin.h> |
709 | #include <Mocks/MockApplicationManager.h> |
710 | #include <Mocks/MockApplicationInfo.h> |
711 | +#include <Mocks/MockSurfaceManager.h> |
712 | +#include <Mocks/MockSurfaceItem.h> |
713 | +#include <Mocks/MockSurface.h> |
714 | |
715 | #include <ApplicationManagerInterface.h> |
716 | #include <ApplicationInfoInterface.h> |
717 | +#include <SurfaceManagerInterface.h> |
718 | +#include <SurfaceItemInterface.h> |
719 | +#include <SurfaceInterface.h> |
720 | |
721 | #include <QtQml/qqml.h> |
722 | |
723 | using namespace unity::shell::application; |
724 | |
725 | -static QObject* modelProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */) |
726 | +static QObject* applicationManagerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */) |
727 | { |
728 | return new MockApplicationManager(); |
729 | } |
730 | |
731 | +static QObject* surfaceManagerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */) |
732 | +{ |
733 | + return new MockSurfaceManager(); |
734 | +} |
735 | + |
736 | // cppcheck-suppress unusedFunction |
737 | void TestApplicationPlugin::registerTypes(const char* uri) |
738 | { |
739 | // @uri Unity.Application |
740 | qmlRegisterUncreatableType<ApplicationManagerInterface>(uri, 0, 1, "ApplicationManagerInterface", "Interface for the ApplicationManager"); |
741 | - qmlRegisterUncreatableType<ApplicationInfoInterface>(uri, 0, 1, "ApplicationInfoInterface", "Interface for the ApplicationInfo"); |
742 | + qmlRegisterUncreatableType<ApplicationInfoInterface>(uri, 0, 1, "ApplicationInfoInterface", "Interface for ApplicationInfo"); |
743 | |
744 | - qmlRegisterSingletonType<MockApplicationManager>(uri, 0, 1, "ApplicationManager", modelProvider); |
745 | + qmlRegisterSingletonType<MockApplicationManager>(uri, 0, 1, "ApplicationManager", applicationManagerProvider); |
746 | qmlRegisterUncreatableType<MockApplicationInfo>(uri, 0, 1, "ApplicationInfo", "Can't create ApplicationInfos in QML. Get them from the ApplicationManager"); |
747 | + |
748 | + qmlRegisterUncreatableType<SurfaceManagerInterface>(uri, 0, 1, "SurfaceManagerInterface", "Interface for the SurfaceManager"); |
749 | + qmlRegisterUncreatableType<SurfaceItemInterface>(uri, 0, 1, "SurfaceItemInterface", "Interface for SurfaceItem"); |
750 | + qmlRegisterUncreatableType<SurfaceInterface>(uri, 0, 1, "SurfaceInterface", "Interface for Surface"); |
751 | + |
752 | + qmlRegisterSingletonType<MockSurfaceManager>(uri, 0, 1, "SurfaceManager", surfaceManagerProvider); |
753 | + qmlRegisterUncreatableType<MockSurface>(uri, 0, 1, "Surface", "Can't create Surfaces in QML. Get them from the SurfaceManager"); |
754 | + qmlRegisterType<MockSurfaceItem>(uri, 0, 1, "SurfaceItem"); |
755 | } |
756 | |
757 | === modified file 'test/qmltest/unity/shell/CMakeLists.txt' |
758 | --- test/qmltest/unity/shell/CMakeLists.txt 2013-08-29 11:33:59 +0000 |
759 | +++ test/qmltest/unity/shell/CMakeLists.txt 2014-05-05 12:17:41 +0000 |
760 | @@ -9,3 +9,4 @@ |
761 | add_qml_test(notifications Notifications) |
762 | add_qml_test(launcher Launcher) |
763 | add_qml_test(application Application) |
764 | +add_qml_test(application Surface) |
765 | |
766 | === added file 'test/qmltest/unity/shell/application/tst_Surface.qml' |
767 | --- test/qmltest/unity/shell/application/tst_Surface.qml 1970-01-01 00:00:00 +0000 |
768 | +++ test/qmltest/unity/shell/application/tst_Surface.qml 2014-05-05 12:17:41 +0000 |
769 | @@ -0,0 +1,168 @@ |
770 | +/* |
771 | + * Copyright 2014 Canonical Ltd. |
772 | + * |
773 | + * This program is free software; you can redistribute it and/or modify |
774 | + * it under the terms of the GNU Lesser General Public License as published by |
775 | + * the Free Software Foundation; version 3. |
776 | + * |
777 | + * This program is distributed in the hope that it will be useful, |
778 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
779 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
780 | + * GNU Lesser General Public License for more details. |
781 | + * |
782 | + * You should have received a copy of the GNU Lesser General Public License |
783 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
784 | + * |
785 | + * Authors: |
786 | + * Michael Zanetti <michael.zanetti@canonical.com> |
787 | + */ |
788 | + |
789 | +import QtQuick 2.0 |
790 | +import QtTest 1.0 |
791 | +import TestUtil 0.1 |
792 | +import Unity.Application 0.1 |
793 | + |
794 | +Item { |
795 | + |
796 | + SignalSpy { |
797 | + id: signalSpy |
798 | + } |
799 | + |
800 | + Verifier { |
801 | + id: checkModelVerifier |
802 | + |
803 | + property var model: SurfaceManager |
804 | + |
805 | + function test_model_data() { |
806 | + return [ |
807 | + { tag: "SurfaceManager[object]", type: "object" }, |
808 | + { tag: "SurfaceManager[SurfaceManagerInterface]", type: "unity::shell::application::SurfaceManagerInterface" }, |
809 | + ]; |
810 | + } |
811 | + |
812 | + function test_model(data) { |
813 | + object = model; |
814 | + name = "SurfaceManager" |
815 | + |
816 | + verifyData(data); |
817 | + } |
818 | + } |
819 | + |
820 | + Verifier { |
821 | + when: checkModelVerifier.completed |
822 | + |
823 | + Repeater { |
824 | + id: repeater |
825 | + model: SurfaceManager |
826 | + delegate: Item { |
827 | + property var roles: model |
828 | + } |
829 | + } |
830 | + |
831 | + SurfaceItem { |
832 | + id: surfaceItem |
833 | + surface: SurfaceManager.get(0) |
834 | + } |
835 | + |
836 | + /* make sure all the required roles are exposed on SurfaceManager */ |
837 | + function test_model_roles_enum_data() { |
838 | + return [ |
839 | + { enum: "RoleType" }, |
840 | + { enum: "RoleSurfaceState" }, |
841 | + { enum: "RoleName" }, |
842 | + { enum: "RoleApplicationId" }, |
843 | + ]; |
844 | + } |
845 | + |
846 | + function test_model_roles_enum(data) { |
847 | + name = "SurfaceManager" |
848 | + object = SurfaceManager |
849 | + |
850 | + verifyData(data); |
851 | + } |
852 | + |
853 | + function test_model_roles_data() { |
854 | + return [ |
855 | + { tag: "SurfaceManager.roles[appId]", role: "appId", type: "string" }, |
856 | + { tag: "SurfaceManager.roles[name]", role: "name", type: "string" }, |
857 | + { tag: "SurfaceManager.roles[type]", role: "type", type: "number" }, |
858 | + { tag: "SurfaceManager.roles[surfaceState]", role: "surfaceState", type: "number" }, |
859 | + ]; |
860 | + } |
861 | + |
862 | + function test_model_roles(data) { |
863 | + name = "SurfaceManager" |
864 | + try { |
865 | + object = repeater.itemAt(0).roles; |
866 | + } catch(err) { |
867 | + object = undefined; |
868 | + } |
869 | + |
870 | + verifyData(data); |
871 | + } |
872 | + |
873 | + function test_model_methods_data() { |
874 | + return [ |
875 | + { tag: "SurfaceManager.methods[surfaceCreated]", method: "surfaceCreated" }, |
876 | + { tag: "SurfaceManager.methods[surfaceDestroyed]", method: "surfaceDestroyed" }, |
877 | + ]; |
878 | + } |
879 | + |
880 | + function test_model_methods(data) { |
881 | + name = "SurfaceManager"; |
882 | + object = SurfaceManager; |
883 | + verifyData(data); |
884 | + } |
885 | + |
886 | + function test_model_properties_data() { |
887 | + return [ |
888 | + { tag: "SurfaceManager.count", property: "count", type: "number" }, |
889 | + ]; |
890 | + } |
891 | + |
892 | + function test_model_properties(data) { |
893 | + name = "SurfaceManager"; |
894 | + object = SurfaceManager; |
895 | + verifyData(data); |
896 | + } |
897 | + |
898 | + function test_surface_properties_data() { |
899 | + return [ |
900 | + { tag: "Surface.properties[type]", constant: "type", type: "number" }, |
901 | + { tag: "Surface.properties[surfaceState]", property: "surfaceState", type: "number" }, |
902 | + { tag: "Surface.properties[name]", property: "name", type: "string" }, |
903 | + { tag: "Surface.properties[appId]", property: "appId", type: "string" }, |
904 | + ]; |
905 | + } |
906 | + |
907 | + function test_surface_properties(data) { |
908 | + name = "Surface" |
909 | + try { |
910 | + object = SurfaceManager.get(0) |
911 | + } catch(err) { |
912 | + object = undefined; |
913 | + print(err) |
914 | + } |
915 | + |
916 | + verifyData(data) |
917 | + } |
918 | + |
919 | + function test_surfaceitem_properties_data() { |
920 | + return [ |
921 | + { tag: "SurfaceItem.properties[surface]", property: "surface", type: "object" }, |
922 | + ]; |
923 | + } |
924 | + |
925 | + function test_surfaceitem_properties(data) { |
926 | + name = "SurfaceItem" |
927 | + try { |
928 | + object = surfaceItem; |
929 | + } catch(err) { |
930 | + object = undefined; |
931 | + print(err) |
932 | + } |
933 | + |
934 | + verifyData(data) |
935 | + } |
936 | + } |
937 | +} |
On 01.05.2014 15:48, Michael Zanetti wrote: state_unknown, state_restored, state_minimized , state_maximized , state_vertmaxim ized, state_semimaxim ized, // see mircommon/ mir_toolbox/ common. h*/ state_fullscree n,
> + enum State {
> + Unknown = mir_surface_
> + Restored = mir_surface_
> + Minimized = mir_surface_
> + Maximized = mir_surface_
> + VertMaximized = mir_surface_
> + /* SemiMaximized = mir_surface_
> + Fullscreen = mir_surface_
> + };
We've been playing with the idea of expressing "stage-ness" with those
(since we probably want to support sidestage on desktop). I understand
Mir probably doesn't want explicit MainStage, SideStage, but maybe
something could be discussed?
> + void surfaceCreated( SurfaceItemInte rface* surface); d(SurfaceItemIn terface* surface);
> + void surfaceDestroye
Wouldn't those be redundant to row additions/removals? What's the use
case here?
> +protected:
> + /// @cond
> + QHash<int, QByteArray> m_roleNames;
I know this is early, but didn't we decide that creating the hash
dynamically in roleNames() is better, since there's no use for this
member other than returning it from there (and only once in most cases)?