on xenial help sign in
Fixed up AppManager mock for qtmir surfaces.

Approved by: Daniel d'Andrada

commiteb31fa22f54164aec19a942dc8996a78436e1749 authorNick Dedekind <nicholas.dedekind@gmail.com> dateFri 18 Jul 2014, 16:05 (12 years ago) parenta3a1c15832b730
10 files changed+301−50
tests/mocks/Unity/Application/ApplicationInfo.cpp+59−21 tests/mocks/Unity/Application/ApplicationInfo.h+21−8 tests/mocks/Unity/Application/ApplicationManager.cpp+32−19 tests/mocks/Unity/Application/ApplicationManager.h+7−1 tests/mocks/Unity/Application/CMakeLists.txt+2 tests/mocks/Unity/Application/MirSurfaceItem.cpp+40 tests/mocks/Unity/Application/MirSurfaceItem.h+84 tests/mocks/Unity/Application/SurfaceManager.cpp+16 tests/mocks/Unity/Application/SurfaceManager.h+26 tests/mocks/Unity/Application/plugin.cpp+14−1
tests/mocks/Unity/Application/ApplicationInfo.cpp+59−21
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -15,6 +15,8 @@
1515 */
1616
1717#include "ApplicationInfo.h"
18+#include "MirSurfaceItem.h"
19+#include "SurfaceManager.h"
1820
1921#include <QGuiApplication>
2022#include <QQuickItem>
@@ -24,29 +26,39 @@
2426
2527ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
2628 : ApplicationInfoInterface(appId, parent)
27− ,m_appId(appId)
28− ,m_stage(MainStage)
29− ,m_state(Starting)
30− ,m_focused(false)
31− ,m_fullscreen(false)
32− ,m_windowItem(0)
33− ,m_windowComponent(0)
34− ,m_parentItem(0)
29+ , m_appId(appId)
30+ , m_stage(MainStage)
31+ , m_state(Starting)
32+ , m_focused(false)
33+ , m_fullscreen(false)
34+ , m_windowItem(0)
35+ , m_windowComponent(0)
36+ , m_parentItem(0)
37+ , m_surface(0)
3538{
36− QTimer::singleShot(300, this, SLOT(setRunning()));
39+ connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged);
3740}
3841
3942ApplicationInfo::ApplicationInfo(QObject *parent)
4043 : 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)
44+ , m_stage(MainStage)
45+ , m_state(Starting)
46+ , m_focused(false)
47+ , m_fullscreen(false)
48+ , m_windowItem(0)
49+ , m_windowComponent(0)
50+ , m_parentItem(0)
51+ , m_surface(0)
4852{
49− QTimer::singleShot(300, this, SLOT(setRunning()));
53+ connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged);
54+}
55+
56+ApplicationInfo::~ApplicationInfo()
57+{
58+ if (m_surface) {
59+ Q_EMIT SurfaceManager::singleton()->surfaceDestroyed(m_surface);
60+ m_surface->deleteLater();
61+ }
5062}
5163
5264void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status status)
@@ -55,10 +67,36 @@ void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status statu
5567 doCreateWindowItem();
5668}
5769
58−void ApplicationInfo::setRunning()
70+void ApplicationInfo::onStateChanged(State state)
71+{
72+ if (state == ApplicationInfo::Running) {
73+ QTimer::singleShot(1000, this, SLOT(createSurface()));
74+ } else if (state == ApplicationInfo::Stopped) {
75+ destroySurface();
76+ }
77+}
78+
79+void ApplicationInfo::createSurface()
80+{
81+ if (m_surface || state() == ApplicationInfo::Stopped) return;
82+
83+ m_surface = new MirSurfaceItem(name(),
84+ MirSurfaceItem::Normal,
85+ fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
86+ screenshot());
87+ Q_EMIT surfaceChanged(m_surface);
88+ Q_EMIT SurfaceManager::singleton()->surfaceCreated(m_surface);
89+}
90+
91+void ApplicationInfo::destroySurface()
5992{
60− m_state = Running;
61− Q_EMIT stateChanged();
93+ if (!m_surface) return;
94+ MirSurfaceItem* oldSurface = m_surface;
95+ m_surface = nullptr;
96+
97+ Q_EMIT surfaceChanged(nullptr);
98+ Q_EMIT SurfaceManager::singleton()->surfaceDestroyed(oldSurface);
99+ oldSurface->deleteLater();
62100}
63101
64102void ApplicationInfo::createWindowComponent()
tests/mocks/Unity/Application/ApplicationInfo.h+21−8
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
2121#include <QQmlComponent>
2222
2323class QQuickItem;
24+class MirSurfaceItem;
2425
2526// unity-api
2627#include <unity/shell/application/ApplicationInfoInterface.h>
@@ -36,6 +37,7 @@ class ApplicationInfo : public ApplicationInfoInterface {
3637
3738 Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
3839 Q_PROPERTY(Stage stage READ stage WRITE setStage NOTIFY stageChanged)
40+ Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
3941
4042 // Only exists in this fake implementation
4143
@@ -45,9 +47,10 @@ class ApplicationInfo : public ApplicationInfoInterface {
4547 // QML component used to represent the application window
4648 Q_PROPERTY(QString windowQml READ windowQml WRITE setWindowQml NOTIFY windowQmlChanged)
4749
48− public:
50+public:
4951 ApplicationInfo(QObject *parent = NULL);
5052 ApplicationInfo(const QString &appId, QObject *parent = NULL);
53+ ~ApplicationInfo();
5154
5255 #define IMPLEMENT_PROPERTY(name, Name, type) \
5356 public: \
@@ -56,11 +59,11 @@ class ApplicationInfo : public ApplicationInfoInterface {
5659 { \
5760 if (m_##name != value) { \
5861 m_##name = value; \
59− Q_EMIT name##Changed(); \
62+ Q_EMIT name##Changed(value); \
6063 } \
6164 } \
6265 Q_SIGNALS: \
63− void name##Changed(); \
66+ void name##Changed(const type&); \
6467 private: \
6568 type m_##name;
6669
@@ -78,21 +81,31 @@ class ApplicationInfo : public ApplicationInfoInterface {
7881
7982 #undef IMPLEMENT_PROPERTY
8083
81− public:
84+public:
85+ MirSurfaceItem* surface() const { return m_surface; }
86+
87+Q_SIGNALS:
88+ void surfaceChanged(MirSurfaceItem*);
89+
90+public:
8291 void showWindow(QQuickItem *parent);
8392 void hideWindow();
8493
85− private Q_SLOTS:
94+private Q_SLOTS:
8695 void onWindowComponentStatusChanged(QQmlComponent::Status status);
87− void setRunning();
96+ void onStateChanged(State state);
97+
98+ void createSurface();
99+ void destroySurface();
88100
89− private:
101+private:
90102 void createWindowItem();
91103 void doCreateWindowItem();
92104 void createWindowComponent();
93105 QQuickItem *m_windowItem;
94106 QQmlComponent *m_windowComponent;
95107 QQuickItem *m_parentItem;
108+ MirSurfaceItem* m_surface;
96109};
97110
98111Q_DECLARE_METATYPE(ApplicationInfo*)
tests/mocks/Unity/Application/ApplicationManager.cpp+32−19
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -16,6 +16,7 @@
1616
1717#include "ApplicationManager.h"
1818#include "ApplicationInfo.h"
19+#include "MirSurfaceItem.h"
1920
2021#include <paths.h>
2122
@@ -36,6 +37,9 @@ ApplicationManager::ApplicationManager(QObject *parent)
3637 , m_sideStage(0)
3738 , m_rightMargin(0)
3839{
40+ m_roleNames.insert(RoleSurface, "surface");
41+ m_roleNames.insert(RoleFullscreen, "fullscreen");
42+
3943 buildListOfAvailableApplications();
4044}
4145
@@ -69,6 +73,10 @@ QVariant ApplicationManager::data(const QModelIndex& index, int role) const {
6973 return app->focused();
7074 case RoleScreenshot:
7175 return app->screenshot();
76+ case RoleSurface:
77+ return QVariant::fromValue(app->surface());
78+ case RoleFullscreen:
79+ return app->fullscreen();
7280 default:
7381 return QVariant();
7482 }
@@ -89,6 +97,17 @@ ApplicationInfo *ApplicationManager::findApplication(const QString &appId) const
8997 return nullptr;
9098}
9199
100+QModelIndex ApplicationManager::findIndex(ApplicationInfo* application)
101+{
102+ for (int i = 0; i < m_runningApplications.size(); ++i) {
103+ if (m_runningApplications.at(i) == application) {
104+ return index(i);
105+ }
106+ }
107+
108+ return QModelIndex();
109+}
110+
92111void ApplicationManager::add(ApplicationInfo *application) {
93112 if (!application) {
94113 return;
@@ -100,6 +119,12 @@ void ApplicationManager::add(ApplicationInfo *application) {
100119 Q_EMIT applicationAdded(application->appId());
101120 Q_EMIT countChanged();
102121 Q_EMIT focusRequested(application->appId());
122+
123+ connect(application, &ApplicationInfo::surfaceChanged, this, [application, this]() {
124+ QModelIndex appIndex = findIndex(application);
125+ if (!appIndex.isValid()) return;
126+ Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleSurface);
127+ });
103128}
104129
105130void ApplicationManager::remove(ApplicationInfo *application) {
@@ -111,6 +136,7 @@ void ApplicationManager::remove(ApplicationInfo *application) {
111136 Q_EMIT applicationRemoved(application->appId());
112137 Q_EMIT countChanged();
113138 }
139+ disconnect(application, &ApplicationInfo::surfaceChanged, this, 0);
114140}
115141
116142void ApplicationManager::move(int from, int to) {
@@ -180,6 +206,7 @@ ApplicationInfo* ApplicationManager::startApplication(const QString &appId,
180206 application->setStage(ApplicationInfo::MainStage);
181207 }
182208 add(application);
209+ application->setState(ApplicationInfo::Running);
183210
184211 return application;
185212}
@@ -193,6 +220,7 @@ bool ApplicationManager::stopApplication(const QString &appId)
193220 if (application->appId() == focusedApplicationId()) {
194221 unfocusCurrentApplication();
195222 }
223+ application->setState(ApplicationInfo::Stopped);
196224 remove(application);
197225 return true;
198226}
@@ -213,7 +241,6 @@ bool ApplicationManager::updateScreenshot(const QString &appId)
213241 return false;
214242 }
215243
216− application->setScreenshot(QString("image://application/%1/%2").arg(appId).arg(QDateTime::currentMSecsSinceEpoch()));
217244 QModelIndex appIndex = index(idx);
218245 Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << RoleScreenshot);
219246 return true;
@@ -352,6 +379,9 @@ void ApplicationManager::generateQmlStrings(ApplicationInfo *application)
352379 "}").arg(qmlDirectory())
353380 .arg(application->icon().toString());
354381 application->setImageQml(imageQml);
382+
383+ application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png").arg(qmlDirectory())
384+ .arg(application->icon().toString()));
355385}
356386
357387void ApplicationManager::buildListOfAvailableApplications()
@@ -363,7 +393,6 @@ void ApplicationManager::buildListOfAvailableApplications()
363393 application->setName("Dialer");
364394 application->setIcon(QUrl("dialer"));
365395 application->setStage(ApplicationInfo::SideStage);
366− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
367396 generateQmlStrings(application);
368397 m_availableApplications.append(application);
369398
@@ -372,7 +401,6 @@ void ApplicationManager::buildListOfAvailableApplications()
372401 application->setName("Camera");
373402 application->setIcon(QUrl("camera"));
374403 application->setFullscreen(true);
375− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
376404 generateQmlStrings(application);
377405 m_availableApplications.append(application);
378406
@@ -380,7 +408,6 @@ void ApplicationManager::buildListOfAvailableApplications()
380408 application->setAppId("gallery-app");
381409 application->setName("Gallery");
382410 application->setIcon(QUrl("gallery"));
383− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
384411 generateQmlStrings(application);
385412 m_availableApplications.append(application);
386413
@@ -389,7 +416,6 @@ void ApplicationManager::buildListOfAvailableApplications()
389416 application->setName("Facebook");
390417 application->setIcon(QUrl("facebook"));
391418 application->setStage(ApplicationInfo::SideStage);
392− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
393419 generateQmlStrings(application);
394420 m_availableApplications.append(application);
395421
@@ -398,7 +424,6 @@ void ApplicationManager::buildListOfAvailableApplications()
398424 application->setFullscreen(true);
399425 application->setName("Browser");
400426 application->setIcon(QUrl("browser"));
401− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
402427 generateQmlStrings(application);
403428 m_availableApplications.append(application);
404429
@@ -407,7 +432,6 @@ void ApplicationManager::buildListOfAvailableApplications()
407432 application->setName("Twitter");
408433 application->setIcon(QUrl("twitter"));
409434 application->setStage(ApplicationInfo::SideStage);
410− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
411435 generateQmlStrings(application);
412436 m_availableApplications.append(application);
413437
@@ -415,7 +439,6 @@ void ApplicationManager::buildListOfAvailableApplications()
415439 application->setAppId("gmail-webapp");
416440 application->setName("GMail");
417441 application->setIcon(QUrl("gmail"));
418− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
419442 m_availableApplications.append(application);
420443
421444 application = new ApplicationInfo(this);
@@ -423,7 +446,6 @@ void ApplicationManager::buildListOfAvailableApplications()
423446 application->setName("Weather");
424447 application->setIcon(QUrl("weather"));
425448 application->setStage(ApplicationInfo::SideStage);
426− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
427449 generateQmlStrings(application);
428450 m_availableApplications.append(application);
429451
@@ -432,7 +454,6 @@ void ApplicationManager::buildListOfAvailableApplications()
432454 application->setName("Notepad");
433455 application->setIcon(QUrl("notepad"));
434456 application->setStage(ApplicationInfo::SideStage);
435− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
436457 m_availableApplications.append(application);
437458
438459 application = new ApplicationInfo(this);
@@ -440,7 +461,6 @@ void ApplicationManager::buildListOfAvailableApplications()
440461 application->setName("Calendar");
441462 application->setIcon(QUrl("calendar"));
442463 application->setStage(ApplicationInfo::SideStage);
443− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
444464 m_availableApplications.append(application);
445465
446466 application = new ApplicationInfo(this);
@@ -448,21 +468,18 @@ void ApplicationManager::buildListOfAvailableApplications()
448468 application->setName("Media Player");
449469 application->setIcon(QUrl("mediaplayer-app"));
450470 application->setFullscreen(true);
451− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
452471 m_availableApplications.append(application);
453472
454473 application = new ApplicationInfo(this);
455474 application->setAppId("evernote");
456475 application->setName("Evernote");
457476 application->setIcon(QUrl("evernote"));
458− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
459477 m_availableApplications.append(application);
460478
461479 application = new ApplicationInfo(this);
462480 application->setAppId("map");
463481 application->setName("Map");
464482 application->setIcon(QUrl("map"));
465− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
466483 generateQmlStrings(application);
467484 m_availableApplications.append(application);
468485
@@ -470,28 +487,24 @@ void ApplicationManager::buildListOfAvailableApplications()
470487 application->setAppId("pinterest");
471488 application->setName("Pinterest");
472489 application->setIcon(QUrl("pinterest"));
473− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
474490 m_availableApplications.append(application);
475491
476492 application = new ApplicationInfo(this);
477493 application->setAppId("soundcloud");
478494 application->setName("SoundCloud");
479495 application->setIcon(QUrl("soundcloud"));
480− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
481496 m_availableApplications.append(application);
482497
483498 application = new ApplicationInfo(this);
484499 application->setAppId("wikipedia");
485500 application->setName("Wikipedia");
486501 application->setIcon(QUrl("wikipedia"));
487− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
488502 m_availableApplications.append(application);
489503
490504 application = new ApplicationInfo(this);
491505 application->setAppId("youtube");
492506 application->setName("YouTube");
493507 application->setIcon(QUrl("youtube"));
494− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
495508 m_availableApplications.append(application);
496509}
497510
tests/mocks/Unity/Application/ApplicationManager.h+7−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -53,6 +53,10 @@ class ApplicationManager : public ApplicationManagerInterface {
5353 ApplicationManager(QObject *parent = NULL);
5454 virtual ~ApplicationManager();
5555
56+ enum MoreRoles {
57+ RoleSurface = RoleScreenshot+1,
58+ RoleFullscreen,
59+ };
5660 enum Role {
5761 Dash, Default, Indicators, Notifications, Greeter, Launcher, OnScreenKeyboard,
5862 ShutdownDialog
@@ -108,6 +112,8 @@ class ApplicationManager : public ApplicationManagerInterface {
108112 int rightMargin() const;
109113 void setRightMargin(int rightMargin);
110114
115+ QModelIndex findIndex(ApplicationInfo* application);
116+
111117 Q_SIGNALS:
112118 void keyboardHeightChanged();
113119 void keyboardVisibleChanged();
tests/mocks/Unity/Application/CMakeLists.txt+2
@@ -6,6 +6,8 @@ set(FakeUnityApplicationQml_SOURCES
66 ApplicationImage.cpp
77 ApplicationManager.cpp
88 ApplicationScreenshotProvider.cpp
9+ MirSurfaceItem.cpp
10+ SurfaceManager.cpp
911 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
1012 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
1113)
tests/mocks/Unity/Application/MirSurfaceItem.cppnew file+40
@@ -0,0 +1,40 @@
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 "MirSurfaceItem.h"
18+
19+#include <QPainter>
20+
21+MirSurfaceItem::MirSurfaceItem(const QString& name,
22+ MirSurfaceItem::Type type,
23+ MirSurfaceItem::State state,
24+ const QUrl& screenshot,
25+ QQuickItem *parent)
26+ : QQuickPaintedItem(parent)
27+ , m_name(name)
28+ , m_type(type)
29+ , m_state(state)
30+ , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
31+{
32+ setFillColor(Qt::white);
33+}
34+
35+void MirSurfaceItem::paint(QPainter * painter)
36+{
37+ if (!m_img.isNull()) {
38+ painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
39+ }
40+}
tests/mocks/Unity/Application/MirSurfaceItem.hnew file+84
@@ -0,0 +1,84 @@
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 MIRSURFACEITEM_H
18+#define MIRSURFACEITEM_H
19+
20+#include <QQuickPaintedItem>
21+#include <QImage>
22+
23+class MirSurfaceItem : public QQuickPaintedItem
24+{
25+ Q_OBJECT
26+ Q_ENUMS(Type)
27+ Q_ENUMS(State)
28+
29+ Q_PROPERTY(Type type READ type NOTIFY typeChanged)
30+ Q_PROPERTY(State state READ state NOTIFY stateChanged)
31+ Q_PROPERTY(QString name READ name NOTIFY nameChanged)
32+
33+public:
34+ enum Type {
35+ Normal,
36+ Utility,
37+ Dialog,
38+ Overlay,
39+ Freestyle,
40+ Popover,
41+ InputMethod,
42+ };
43+
44+ enum State {
45+ Unknown,
46+ Restored,
47+ Minimized,
48+ Maximized,
49+ VertMaximized,
50+ /* SemiMaximized, */
51+ Fullscreen,
52+ };
53+
54+ explicit MirSurfaceItem(const QString& name,
55+ Type type,
56+ State state,
57+ const QUrl& screenshot,
58+ QQuickItem *parent = 0);
59+
60+ //getters
61+ Type type() const { return m_type; }
62+ State state() const { return m_state; }
63+ QString name() const { return m_name; }
64+
65+ Q_INVOKABLE void release() {}
66+
67+ void paint(QPainter * painter) override;
68+
69+Q_SIGNALS:
70+ void typeChanged(Type);
71+ void stateChanged(State);
72+ void nameChanged(QString);
73+
74+private:
75+
76+ const QString m_name;
77+ const Type m_type;
78+ const State m_state;
79+ const QImage m_img;
80+};
81+
82+Q_DECLARE_METATYPE(MirSurfaceItem*)
83+
84+#endif // MIRSURFACEITEM_H
tests/mocks/Unity/Application/SurfaceManager.cppnew file+16
@@ -0,0 +1,16 @@
1+#include "SurfaceManager.h"
2+
3+SurfaceManager *SurfaceManager::the_surface_manager = nullptr;
4+
5+SurfaceManager *SurfaceManager::singleton()
6+{
7+ if (!the_surface_manager) {
8+ the_surface_manager = new SurfaceManager();
9+ }
10+ return the_surface_manager;
11+}
12+
13+SurfaceManager::SurfaceManager(QObject *parent) :
14+ QObject(parent)
15+{
16+}
tests/mocks/Unity/Application/SurfaceManager.hnew file+26
@@ -0,0 +1,26 @@
1+#ifndef SURFACEMANAGER_H
2+#define SURFACEMANAGER_H
3+
4+#include <QObject>
5+
6+class MirSurfaceItem;
7+
8+class SurfaceManager : public QObject
9+{
10+ Q_OBJECT
11+public:
12+ explicit SurfaceManager(QObject *parent = 0);
13+
14+ static SurfaceManager *singleton();
15+
16+Q_SIGNALS:
17+ void countChanged();
18+ void surfaceCreated(MirSurfaceItem *surface);
19+ void surfaceDestroyed(MirSurfaceItem *surface);
20+
21+private:
22+ static SurfaceManager *the_surface_manager;
23+
24+};
25+
26+#endif // SURFACEMANAGER_H
tests/mocks/Unity/Application/plugin.cpp+14−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2014 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@
1919#include "ApplicationImage.h"
2020#include "ApplicationManager.h"
2121#include "ApplicationScreenshotProvider.h"
22+#include "MirSurfaceItem.h"
23+#include "SurfaceManager.h"
2224
2325#include <qqml.h>
2426#include <QQmlEngine>
@@ -34,14 +36,25 @@ static QObject* applicationManagerSingleton(QQmlEngine* engine, QJSEngine* scrip
3436 return s_appManager;
3537}
3638
39+static QObject* surfaceManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
40+ Q_UNUSED(engine);
41+ Q_UNUSED(scriptEngine);
42+ return SurfaceManager::singleton();
43+}
44+
3745void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
3846{
47+ qRegisterMetaType<MirSurfaceItem*>("MirSurfaceItem*");
48+
3949 qmlRegisterUncreatableType<unity::shell::application::ApplicationManagerInterface>(uri, 0, 1, "ApplicationManagerInterface", "Abstract interface. Cannot be created in QML");
4050 qmlRegisterSingletonType<ApplicationManager>(uri, 0, 1, "ApplicationManager", applicationManagerSingleton);
51+ qmlRegisterSingletonType<SurfaceManager>(uri, 0, 1, "SurfaceManager", surfaceManagerSingleton);
4152
4253 qmlRegisterUncreatableType<unity::shell::application::ApplicationInfoInterface>(uri, 0, 1, "ApplicationInfoInterface", "Abstract interface. Cannot be created in QML");
4354 qmlRegisterType<ApplicationInfo>(uri, 0, 1, "ApplicationInfo");
4455
56+ qmlRegisterUncreatableType<MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem", "MirSurfaceItem can't be instantiated from QML");
57+
4558 qmlRegisterType<ApplicationImage>(uri, 0, 1, "ApplicationImage");
4659}
4760