Merge lp:~nick-dedekind/unity8/mirCompositor-appMocks into lp:~unity-team/unity8/mirCompositor
- mirCompositor-appMocks
- Merge into mirCompositor
Proposed by
Nick Dedekind
Status: | Merged |
---|---|
Merged at revision: | 1067 |
Proposed branch: | lp:~nick-dedekind/unity8/mirCompositor-appMocks |
Merge into: | lp:~unity-team/unity8/mirCompositor |
Diff against target: |
692 lines (+299/-48) 10 files modified
tests/mocks/Unity/Application/ApplicationInfo.cpp (+60/-22) tests/mocks/Unity/Application/ApplicationInfo.h (+21/-8) tests/mocks/Unity/Application/ApplicationManager.cpp (+31/-18) tests/mocks/Unity/Application/ApplicationManager.h (+6/-0) tests/mocks/Unity/Application/CMakeLists.txt (+2/-0) tests/mocks/Unity/Application/MirSurfaceItem.cpp (+40/-0) tests/mocks/Unity/Application/MirSurfaceItem.h (+84/-0) tests/mocks/Unity/Application/SurfaceManager.cpp (+16/-0) tests/mocks/Unity/Application/SurfaceManager.h (+26/-0) tests/mocks/Unity/Application/plugin.cpp (+13/-0) |
To merge this branch: | bzr merge lp:~nick-dedekind/unity8/mirCompositor-appMocks |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel d'Andrada (community) | Approve | ||
Review via email: mp+227317@code.launchpad.net |
Commit message
Fixed up AppManager mock for qtmir surfaces.
Description of the change
Fixed up AppManager mock for qtmir surfaces.
To post a comment you must log in.
- 1060. By Nick Dedekind
-
removed qdebug
- 1061. By Nick Dedekind
-
whitespace
Revision history for this message
Daniel d'Andrada (dandrader) wrote : | # |
Revision history for this message
Daniel d'Andrada (dandrader) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'tests/mocks/Unity/Application/ApplicationInfo.cpp' |
2 | --- tests/mocks/Unity/Application/ApplicationInfo.cpp 2014-03-20 10:02:52 +0000 |
3 | +++ tests/mocks/Unity/Application/ApplicationInfo.cpp 2014-07-18 16:28:08 +0000 |
4 | @@ -15,6 +15,8 @@ |
5 | */ |
6 | |
7 | #include "ApplicationInfo.h" |
8 | +#include "MirSurfaceItem.h" |
9 | +#include "SurfaceManager.h" |
10 | |
11 | #include <QGuiApplication> |
12 | #include <QQuickItem> |
13 | @@ -24,29 +26,39 @@ |
14 | |
15 | ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent) |
16 | : ApplicationInfoInterface(appId, parent) |
17 | - ,m_appId(appId) |
18 | - ,m_stage(MainStage) |
19 | - ,m_state(Starting) |
20 | - ,m_focused(false) |
21 | - ,m_fullscreen(false) |
22 | - ,m_windowItem(0) |
23 | - ,m_windowComponent(0) |
24 | - ,m_parentItem(0) |
25 | + , m_appId(appId) |
26 | + , m_stage(MainStage) |
27 | + , m_state(Starting) |
28 | + , m_focused(false) |
29 | + , m_fullscreen(false) |
30 | + , m_windowItem(0) |
31 | + , m_windowComponent(0) |
32 | + , m_parentItem(0) |
33 | + , m_surface(0) |
34 | { |
35 | - QTimer::singleShot(300, this, SLOT(setRunning())); |
36 | + connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged); |
37 | } |
38 | |
39 | ApplicationInfo::ApplicationInfo(QObject *parent) |
40 | : ApplicationInfoInterface(QString(), parent) |
41 | - ,m_stage(MainStage) |
42 | - ,m_state(Starting) |
43 | - ,m_focused(false) |
44 | - ,m_fullscreen(false) |
45 | - ,m_windowItem(0) |
46 | - ,m_windowComponent(0) |
47 | - ,m_parentItem(0) |
48 | -{ |
49 | - QTimer::singleShot(300, this, SLOT(setRunning())); |
50 | + , m_stage(MainStage) |
51 | + , m_state(Starting) |
52 | + , m_focused(false) |
53 | + , m_fullscreen(false) |
54 | + , m_windowItem(0) |
55 | + , m_windowComponent(0) |
56 | + , m_parentItem(0) |
57 | + , m_surface(0) |
58 | +{ |
59 | + connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged); |
60 | +} |
61 | + |
62 | +ApplicationInfo::~ApplicationInfo() |
63 | +{ |
64 | + if (m_surface) { |
65 | + Q_EMIT SurfaceManager::singleton()->surfaceDestroyed(m_surface); |
66 | + m_surface->deleteLater(); |
67 | + } |
68 | } |
69 | |
70 | void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status status) |
71 | @@ -55,10 +67,36 @@ |
72 | doCreateWindowItem(); |
73 | } |
74 | |
75 | -void ApplicationInfo::setRunning() |
76 | -{ |
77 | - m_state = Running; |
78 | - Q_EMIT stateChanged(); |
79 | +void ApplicationInfo::onStateChanged(State state) |
80 | +{ |
81 | + if (state == ApplicationInfo::Running) { |
82 | + QTimer::singleShot(1000, this, SLOT(createSurface())); |
83 | + } else if (state == ApplicationInfo::Stopped) { |
84 | + destroySurface(); |
85 | + } |
86 | +} |
87 | + |
88 | +void ApplicationInfo::createSurface() |
89 | +{ |
90 | + if (m_surface || state() == ApplicationInfo::Stopped) return; |
91 | + |
92 | + m_surface = new MirSurfaceItem(name(), |
93 | + MirSurfaceItem::Normal, |
94 | + fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized, |
95 | + screenshot()); |
96 | + Q_EMIT surfaceChanged(m_surface); |
97 | + Q_EMIT SurfaceManager::singleton()->surfaceCreated(m_surface); |
98 | +} |
99 | + |
100 | +void ApplicationInfo::destroySurface() |
101 | +{ |
102 | + if (!m_surface) return; |
103 | + MirSurfaceItem* oldSurface = m_surface; |
104 | + m_surface = nullptr; |
105 | + |
106 | + Q_EMIT surfaceChanged(nullptr); |
107 | + Q_EMIT SurfaceManager::singleton()->surfaceDestroyed(oldSurface); |
108 | + oldSurface->deleteLater(); |
109 | } |
110 | |
111 | void ApplicationInfo::createWindowComponent() |
112 | |
113 | === modified file 'tests/mocks/Unity/Application/ApplicationInfo.h' |
114 | --- tests/mocks/Unity/Application/ApplicationInfo.h 2014-03-20 10:02:52 +0000 |
115 | +++ tests/mocks/Unity/Application/ApplicationInfo.h 2014-07-18 16:28:08 +0000 |
116 | @@ -21,6 +21,7 @@ |
117 | #include <QQmlComponent> |
118 | |
119 | class QQuickItem; |
120 | +class MirSurfaceItem; |
121 | |
122 | // unity-api |
123 | #include <unity/shell/application/ApplicationInfoInterface.h> |
124 | @@ -36,6 +37,7 @@ |
125 | |
126 | Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged) |
127 | Q_PROPERTY(Stage stage READ stage WRITE setStage NOTIFY stageChanged) |
128 | + Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged) |
129 | |
130 | // Only exists in this fake implementation |
131 | |
132 | @@ -45,9 +47,10 @@ |
133 | // QML component used to represent the application window |
134 | Q_PROPERTY(QString windowQml READ windowQml WRITE setWindowQml NOTIFY windowQmlChanged) |
135 | |
136 | - public: |
137 | +public: |
138 | ApplicationInfo(QObject *parent = NULL); |
139 | ApplicationInfo(const QString &appId, QObject *parent = NULL); |
140 | + ~ApplicationInfo(); |
141 | |
142 | #define IMPLEMENT_PROPERTY(name, Name, type) \ |
143 | public: \ |
144 | @@ -56,11 +59,11 @@ |
145 | { \ |
146 | if (m_##name != value) { \ |
147 | m_##name = value; \ |
148 | - Q_EMIT name##Changed(); \ |
149 | + Q_EMIT name##Changed(value); \ |
150 | } \ |
151 | } \ |
152 | Q_SIGNALS: \ |
153 | - void name##Changed(); \ |
154 | + void name##Changed(const type&); \ |
155 | private: \ |
156 | type m_##name; |
157 | |
158 | @@ -78,21 +81,31 @@ |
159 | |
160 | #undef IMPLEMENT_PROPERTY |
161 | |
162 | - public: |
163 | +public: |
164 | + MirSurfaceItem* surface() const { return m_surface; } |
165 | + |
166 | +Q_SIGNALS: |
167 | + void surfaceChanged(MirSurfaceItem*); |
168 | + |
169 | +public: |
170 | void showWindow(QQuickItem *parent); |
171 | void hideWindow(); |
172 | |
173 | - private Q_SLOTS: |
174 | +private Q_SLOTS: |
175 | void onWindowComponentStatusChanged(QQmlComponent::Status status); |
176 | - void setRunning(); |
177 | - |
178 | - private: |
179 | + void onStateChanged(State state); |
180 | + |
181 | + void createSurface(); |
182 | + void destroySurface(); |
183 | + |
184 | +private: |
185 | void createWindowItem(); |
186 | void doCreateWindowItem(); |
187 | void createWindowComponent(); |
188 | QQuickItem *m_windowItem; |
189 | QQmlComponent *m_windowComponent; |
190 | QQuickItem *m_parentItem; |
191 | + MirSurfaceItem* m_surface; |
192 | }; |
193 | |
194 | Q_DECLARE_METATYPE(ApplicationInfo*) |
195 | |
196 | === modified file 'tests/mocks/Unity/Application/ApplicationManager.cpp' |
197 | --- tests/mocks/Unity/Application/ApplicationManager.cpp 2014-07-10 09:27:19 +0000 |
198 | +++ tests/mocks/Unity/Application/ApplicationManager.cpp 2014-07-18 16:28:08 +0000 |
199 | @@ -16,6 +16,7 @@ |
200 | |
201 | #include "ApplicationManager.h" |
202 | #include "ApplicationInfo.h" |
203 | +#include "MirSurfaceItem.h" |
204 | |
205 | #include <paths.h> |
206 | |
207 | @@ -36,6 +37,9 @@ |
208 | , m_sideStage(0) |
209 | , m_rightMargin(0) |
210 | { |
211 | + m_roleNames.insert(RoleSurface, "surface"); |
212 | + m_roleNames.insert(RoleFullscreen, "fullscreen"); |
213 | + |
214 | buildListOfAvailableApplications(); |
215 | } |
216 | |
217 | @@ -69,6 +73,10 @@ |
218 | return app->focused(); |
219 | case RoleScreenshot: |
220 | return app->screenshot(); |
221 | + case RoleSurface: |
222 | + return QVariant::fromValue(app->surface()); |
223 | + case RoleFullscreen: |
224 | + return app->fullscreen(); |
225 | default: |
226 | return QVariant(); |
227 | } |
228 | @@ -89,6 +97,17 @@ |
229 | return nullptr; |
230 | } |
231 | |
232 | +QModelIndex ApplicationManager::findIndex(ApplicationInfo* application) |
233 | +{ |
234 | + for (int i = 0; i < m_runningApplications.size(); ++i) { |
235 | + if (m_runningApplications.at(i) == application) { |
236 | + return index(i); |
237 | + } |
238 | + } |
239 | + |
240 | + return QModelIndex(); |
241 | +} |
242 | + |
243 | void ApplicationManager::add(ApplicationInfo *application) { |
244 | if (!application) { |
245 | return; |
246 | @@ -100,6 +119,12 @@ |
247 | Q_EMIT applicationAdded(application->appId()); |
248 | Q_EMIT countChanged(); |
249 | Q_EMIT focusRequested(application->appId()); |
250 | + |
251 | + connect(application, &ApplicationInfo::surfaceChanged, this, [application, this]() { |
252 | + QModelIndex appIndex = findIndex(application); |
253 | + if (!appIndex.isValid()) return; |
254 | + Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleSurface); |
255 | + }); |
256 | } |
257 | |
258 | void ApplicationManager::remove(ApplicationInfo *application) { |
259 | @@ -111,6 +136,7 @@ |
260 | Q_EMIT applicationRemoved(application->appId()); |
261 | Q_EMIT countChanged(); |
262 | } |
263 | + disconnect(application, &ApplicationInfo::surfaceChanged, this, 0); |
264 | } |
265 | |
266 | void ApplicationManager::move(int from, int to) { |
267 | @@ -180,6 +206,7 @@ |
268 | application->setStage(ApplicationInfo::MainStage); |
269 | } |
270 | add(application); |
271 | + application->setState(ApplicationInfo::Running); |
272 | |
273 | return application; |
274 | } |
275 | @@ -193,6 +220,7 @@ |
276 | if (application->appId() == focusedApplicationId()) { |
277 | unfocusCurrentApplication(); |
278 | } |
279 | + application->setState(ApplicationInfo::Stopped); |
280 | remove(application); |
281 | return true; |
282 | } |
283 | @@ -213,7 +241,6 @@ |
284 | return false; |
285 | } |
286 | |
287 | - application->setScreenshot(QString("image://application/%1/%2").arg(appId).arg(QDateTime::currentMSecsSinceEpoch())); |
288 | QModelIndex appIndex = index(idx); |
289 | Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << RoleScreenshot); |
290 | return true; |
291 | @@ -352,6 +379,9 @@ |
292 | "}").arg(qmlDirectory()) |
293 | .arg(application->icon().toString()); |
294 | application->setImageQml(imageQml); |
295 | + |
296 | + application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png").arg(qmlDirectory()) |
297 | + .arg(application->icon().toString())); |
298 | } |
299 | |
300 | void ApplicationManager::buildListOfAvailableApplications() |
301 | @@ -363,7 +393,6 @@ |
302 | application->setName("Dialer"); |
303 | application->setIcon(QUrl("dialer")); |
304 | application->setStage(ApplicationInfo::SideStage); |
305 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
306 | generateQmlStrings(application); |
307 | m_availableApplications.append(application); |
308 | |
309 | @@ -372,7 +401,6 @@ |
310 | application->setName("Camera"); |
311 | application->setIcon(QUrl("camera")); |
312 | application->setFullscreen(true); |
313 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
314 | generateQmlStrings(application); |
315 | m_availableApplications.append(application); |
316 | |
317 | @@ -380,7 +408,6 @@ |
318 | application->setAppId("gallery-app"); |
319 | application->setName("Gallery"); |
320 | application->setIcon(QUrl("gallery")); |
321 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
322 | generateQmlStrings(application); |
323 | m_availableApplications.append(application); |
324 | |
325 | @@ -389,7 +416,6 @@ |
326 | application->setName("Facebook"); |
327 | application->setIcon(QUrl("facebook")); |
328 | application->setStage(ApplicationInfo::SideStage); |
329 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
330 | generateQmlStrings(application); |
331 | m_availableApplications.append(application); |
332 | |
333 | @@ -398,7 +424,6 @@ |
334 | application->setFullscreen(true); |
335 | application->setName("Browser"); |
336 | application->setIcon(QUrl("browser")); |
337 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
338 | generateQmlStrings(application); |
339 | m_availableApplications.append(application); |
340 | |
341 | @@ -407,7 +432,6 @@ |
342 | application->setName("Twitter"); |
343 | application->setIcon(QUrl("twitter")); |
344 | application->setStage(ApplicationInfo::SideStage); |
345 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
346 | generateQmlStrings(application); |
347 | m_availableApplications.append(application); |
348 | |
349 | @@ -415,7 +439,6 @@ |
350 | application->setAppId("gmail-webapp"); |
351 | application->setName("GMail"); |
352 | application->setIcon(QUrl("gmail")); |
353 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
354 | m_availableApplications.append(application); |
355 | |
356 | application = new ApplicationInfo(this); |
357 | @@ -423,7 +446,6 @@ |
358 | application->setName("Weather"); |
359 | application->setIcon(QUrl("weather")); |
360 | application->setStage(ApplicationInfo::SideStage); |
361 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
362 | generateQmlStrings(application); |
363 | m_availableApplications.append(application); |
364 | |
365 | @@ -432,7 +454,6 @@ |
366 | application->setName("Notepad"); |
367 | application->setIcon(QUrl("notepad")); |
368 | application->setStage(ApplicationInfo::SideStage); |
369 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
370 | m_availableApplications.append(application); |
371 | |
372 | application = new ApplicationInfo(this); |
373 | @@ -440,7 +461,6 @@ |
374 | application->setName("Calendar"); |
375 | application->setIcon(QUrl("calendar")); |
376 | application->setStage(ApplicationInfo::SideStage); |
377 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
378 | m_availableApplications.append(application); |
379 | |
380 | application = new ApplicationInfo(this); |
381 | @@ -448,21 +468,18 @@ |
382 | application->setName("Media Player"); |
383 | application->setIcon(QUrl("mediaplayer-app")); |
384 | application->setFullscreen(true); |
385 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
386 | m_availableApplications.append(application); |
387 | |
388 | application = new ApplicationInfo(this); |
389 | application->setAppId("evernote"); |
390 | application->setName("Evernote"); |
391 | application->setIcon(QUrl("evernote")); |
392 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
393 | m_availableApplications.append(application); |
394 | |
395 | application = new ApplicationInfo(this); |
396 | application->setAppId("map"); |
397 | application->setName("Map"); |
398 | application->setIcon(QUrl("map")); |
399 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
400 | generateQmlStrings(application); |
401 | m_availableApplications.append(application); |
402 | |
403 | @@ -470,28 +487,24 @@ |
404 | application->setAppId("pinterest"); |
405 | application->setName("Pinterest"); |
406 | application->setIcon(QUrl("pinterest")); |
407 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
408 | m_availableApplications.append(application); |
409 | |
410 | application = new ApplicationInfo(this); |
411 | application->setAppId("soundcloud"); |
412 | application->setName("SoundCloud"); |
413 | application->setIcon(QUrl("soundcloud")); |
414 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
415 | m_availableApplications.append(application); |
416 | |
417 | application = new ApplicationInfo(this); |
418 | application->setAppId("wikipedia"); |
419 | application->setName("Wikipedia"); |
420 | application->setIcon(QUrl("wikipedia")); |
421 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
422 | m_availableApplications.append(application); |
423 | |
424 | application = new ApplicationInfo(this); |
425 | application->setAppId("youtube"); |
426 | application->setName("YouTube"); |
427 | application->setIcon(QUrl("youtube")); |
428 | - application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch())); |
429 | m_availableApplications.append(application); |
430 | } |
431 | |
432 | |
433 | === modified file 'tests/mocks/Unity/Application/ApplicationManager.h' |
434 | --- tests/mocks/Unity/Application/ApplicationManager.h 2014-03-11 11:14:10 +0000 |
435 | +++ tests/mocks/Unity/Application/ApplicationManager.h 2014-07-18 16:28:08 +0000 |
436 | @@ -53,6 +53,10 @@ |
437 | ApplicationManager(QObject *parent = NULL); |
438 | virtual ~ApplicationManager(); |
439 | |
440 | + enum MoreRoles { |
441 | + RoleSurface = RoleScreenshot+1, |
442 | + RoleFullscreen, |
443 | + }; |
444 | enum Role { |
445 | Dash, Default, Indicators, Notifications, Greeter, Launcher, OnScreenKeyboard, |
446 | ShutdownDialog |
447 | @@ -108,6 +112,8 @@ |
448 | int rightMargin() const; |
449 | void setRightMargin(int rightMargin); |
450 | |
451 | + QModelIndex findIndex(ApplicationInfo* application); |
452 | + |
453 | Q_SIGNALS: |
454 | void keyboardHeightChanged(); |
455 | void keyboardVisibleChanged(); |
456 | |
457 | === modified file 'tests/mocks/Unity/Application/CMakeLists.txt' |
458 | --- tests/mocks/Unity/Application/CMakeLists.txt 2014-06-26 08:26:58 +0000 |
459 | +++ tests/mocks/Unity/Application/CMakeLists.txt 2014-07-18 16:28:08 +0000 |
460 | @@ -6,6 +6,8 @@ |
461 | ApplicationImage.cpp |
462 | ApplicationManager.cpp |
463 | ApplicationScreenshotProvider.cpp |
464 | + MirSurfaceItem.cpp |
465 | + SurfaceManager.cpp |
466 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h |
467 | ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h |
468 | ) |
469 | |
470 | === added file 'tests/mocks/Unity/Application/MirSurfaceItem.cpp' |
471 | --- tests/mocks/Unity/Application/MirSurfaceItem.cpp 1970-01-01 00:00:00 +0000 |
472 | +++ tests/mocks/Unity/Application/MirSurfaceItem.cpp 2014-07-18 16:28:08 +0000 |
473 | @@ -0,0 +1,40 @@ |
474 | +/* |
475 | + * Copyright (C) 2014 Canonical, Ltd. |
476 | + * |
477 | + * This program is free software; you can redistribute it and/or modify |
478 | + * it under the terms of the GNU General Public License as published by |
479 | + * the Free Software Foundation; version 3. |
480 | + * |
481 | + * This program is distributed in the hope that it will be useful, |
482 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
483 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
484 | + * GNU General Public License for more details. |
485 | + * |
486 | + * You should have received a copy of the GNU General Public License |
487 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
488 | + */ |
489 | + |
490 | +#include "MirSurfaceItem.h" |
491 | + |
492 | +#include <QPainter> |
493 | + |
494 | +MirSurfaceItem::MirSurfaceItem(const QString& name, |
495 | + MirSurfaceItem::Type type, |
496 | + MirSurfaceItem::State state, |
497 | + const QUrl& screenshot, |
498 | + QQuickItem *parent) |
499 | + : QQuickPaintedItem(parent) |
500 | + , m_name(name) |
501 | + , m_type(type) |
502 | + , m_state(state) |
503 | + , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString()) |
504 | +{ |
505 | + setFillColor(Qt::white); |
506 | +} |
507 | + |
508 | +void MirSurfaceItem::paint(QPainter * painter) |
509 | +{ |
510 | + if (!m_img.isNull()) { |
511 | + painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size())); |
512 | + } |
513 | +} |
514 | |
515 | === added file 'tests/mocks/Unity/Application/MirSurfaceItem.h' |
516 | --- tests/mocks/Unity/Application/MirSurfaceItem.h 1970-01-01 00:00:00 +0000 |
517 | +++ tests/mocks/Unity/Application/MirSurfaceItem.h 2014-07-18 16:28:08 +0000 |
518 | @@ -0,0 +1,84 @@ |
519 | +/* |
520 | + * Copyright (C) 2014 Canonical, Ltd. |
521 | + * |
522 | + * This program is free software; you can redistribute it and/or modify |
523 | + * it under the terms of the GNU General Public License as published by |
524 | + * the Free Software Foundation; version 3. |
525 | + * |
526 | + * This program is distributed in the hope that it will be useful, |
527 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
528 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
529 | + * GNU General Public License for more details. |
530 | + * |
531 | + * You should have received a copy of the GNU General Public License |
532 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
533 | + */ |
534 | + |
535 | +#ifndef MIRSURFACEITEM_H |
536 | +#define MIRSURFACEITEM_H |
537 | + |
538 | +#include <QQuickPaintedItem> |
539 | +#include <QImage> |
540 | + |
541 | +class MirSurfaceItem : public QQuickPaintedItem |
542 | +{ |
543 | + Q_OBJECT |
544 | + Q_ENUMS(Type) |
545 | + Q_ENUMS(State) |
546 | + |
547 | + Q_PROPERTY(Type type READ type NOTIFY typeChanged) |
548 | + Q_PROPERTY(State state READ state NOTIFY stateChanged) |
549 | + Q_PROPERTY(QString name READ name NOTIFY nameChanged) |
550 | + |
551 | +public: |
552 | + enum Type { |
553 | + Normal, |
554 | + Utility, |
555 | + Dialog, |
556 | + Overlay, |
557 | + Freestyle, |
558 | + Popover, |
559 | + InputMethod, |
560 | + }; |
561 | + |
562 | + enum State { |
563 | + Unknown, |
564 | + Restored, |
565 | + Minimized, |
566 | + Maximized, |
567 | + VertMaximized, |
568 | + /* SemiMaximized, */ |
569 | + Fullscreen, |
570 | + }; |
571 | + |
572 | + explicit MirSurfaceItem(const QString& name, |
573 | + Type type, |
574 | + State state, |
575 | + const QUrl& screenshot, |
576 | + QQuickItem *parent = 0); |
577 | + |
578 | + //getters |
579 | + Type type() const { return m_type; } |
580 | + State state() const { return m_state; } |
581 | + QString name() const { return m_name; } |
582 | + |
583 | + Q_INVOKABLE void release() {} |
584 | + |
585 | + void paint(QPainter * painter) override; |
586 | + |
587 | +Q_SIGNALS: |
588 | + void typeChanged(Type); |
589 | + void stateChanged(State); |
590 | + void nameChanged(QString); |
591 | + |
592 | +private: |
593 | + |
594 | + const QString m_name; |
595 | + const Type m_type; |
596 | + const State m_state; |
597 | + const QImage m_img; |
598 | +}; |
599 | + |
600 | +Q_DECLARE_METATYPE(MirSurfaceItem*) |
601 | + |
602 | +#endif // MIRSURFACEITEM_H |
603 | |
604 | === added file 'tests/mocks/Unity/Application/SurfaceManager.cpp' |
605 | --- tests/mocks/Unity/Application/SurfaceManager.cpp 1970-01-01 00:00:00 +0000 |
606 | +++ tests/mocks/Unity/Application/SurfaceManager.cpp 2014-07-18 16:28:08 +0000 |
607 | @@ -0,0 +1,16 @@ |
608 | +#include "SurfaceManager.h" |
609 | + |
610 | +SurfaceManager *SurfaceManager::the_surface_manager = nullptr; |
611 | + |
612 | +SurfaceManager *SurfaceManager::singleton() |
613 | +{ |
614 | + if (!the_surface_manager) { |
615 | + the_surface_manager = new SurfaceManager(); |
616 | + } |
617 | + return the_surface_manager; |
618 | +} |
619 | + |
620 | +SurfaceManager::SurfaceManager(QObject *parent) : |
621 | + QObject(parent) |
622 | +{ |
623 | +} |
624 | |
625 | === added file 'tests/mocks/Unity/Application/SurfaceManager.h' |
626 | --- tests/mocks/Unity/Application/SurfaceManager.h 1970-01-01 00:00:00 +0000 |
627 | +++ tests/mocks/Unity/Application/SurfaceManager.h 2014-07-18 16:28:08 +0000 |
628 | @@ -0,0 +1,26 @@ |
629 | +#ifndef SURFACEMANAGER_H |
630 | +#define SURFACEMANAGER_H |
631 | + |
632 | +#include <QObject> |
633 | + |
634 | +class MirSurfaceItem; |
635 | + |
636 | +class SurfaceManager : public QObject |
637 | +{ |
638 | + Q_OBJECT |
639 | +public: |
640 | + explicit SurfaceManager(QObject *parent = 0); |
641 | + |
642 | + static SurfaceManager *singleton(); |
643 | + |
644 | +Q_SIGNALS: |
645 | + void countChanged(); |
646 | + void surfaceCreated(MirSurfaceItem *surface); |
647 | + void surfaceDestroyed(MirSurfaceItem *surface); |
648 | + |
649 | +private: |
650 | + static SurfaceManager *the_surface_manager; |
651 | + |
652 | +}; |
653 | + |
654 | +#endif // SURFACEMANAGER_H |
655 | |
656 | === modified file 'tests/mocks/Unity/Application/plugin.cpp' |
657 | --- tests/mocks/Unity/Application/plugin.cpp 2014-01-20 11:34:59 +0000 |
658 | +++ tests/mocks/Unity/Application/plugin.cpp 2014-07-18 16:28:08 +0000 |
659 | @@ -19,6 +19,8 @@ |
660 | #include "ApplicationImage.h" |
661 | #include "ApplicationManager.h" |
662 | #include "ApplicationScreenshotProvider.h" |
663 | +#include "MirSurfaceItem.h" |
664 | +#include "SurfaceManager.h" |
665 | |
666 | #include <qqml.h> |
667 | #include <QQmlEngine> |
668 | @@ -34,14 +36,25 @@ |
669 | return s_appManager; |
670 | } |
671 | |
672 | +static QObject* surfaceManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) { |
673 | + Q_UNUSED(engine); |
674 | + Q_UNUSED(scriptEngine); |
675 | + return SurfaceManager::singleton(); |
676 | +} |
677 | + |
678 | void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri) |
679 | { |
680 | + qRegisterMetaType<MirSurfaceItem*>("MirSurfaceItem*"); |
681 | + |
682 | qmlRegisterUncreatableType<unity::shell::application::ApplicationManagerInterface>(uri, 0, 1, "ApplicationManagerInterface", "Abstract interface. Cannot be created in QML"); |
683 | qmlRegisterSingletonType<ApplicationManager>(uri, 0, 1, "ApplicationManager", applicationManagerSingleton); |
684 | + qmlRegisterSingletonType<SurfaceManager>(uri, 0, 1, "SurfaceManager", surfaceManagerSingleton); |
685 | |
686 | qmlRegisterUncreatableType<unity::shell::application::ApplicationInfoInterface>(uri, 0, 1, "ApplicationInfoInterface", "Abstract interface. Cannot be created in QML"); |
687 | qmlRegisterType<ApplicationInfo>(uri, 0, 1, "ApplicationInfo"); |
688 | |
689 | + qmlRegisterUncreatableType<MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem", "MirSurfaceItem can't be instantiated from QML"); |
690 | + |
691 | qmlRegisterType<ApplicationImage>(uri, 0, 1, "ApplicationImage"); |
692 | } |
693 |
Would be nice to update the copyright year of the files you changed, like tests/mocks/ Unity/Applicati on/ApplicationI nfo.h