on xenial help sign in
mocks for qtmir
commitf4240f4e6ff9304f3f126ffe386d5a2606a33b90 authorNick Dedekind <nicholas.dedekind@gmail.com> dateFri 18 Jul 2014, 13:30 (12 years ago) parent753f7df
10 files changed+328−45
tests/mocks/Unity/Application/ApplicationInfo.cpp+59−20 tests/mocks/Unity/Application/ApplicationInfo.h+21−7 tests/mocks/Unity/Application/ApplicationManager.cpp+32−18 tests/mocks/Unity/Application/ApplicationManager.h+6 tests/mocks/Unity/Application/CMakeLists.txt+2 tests/mocks/Unity/Application/MirSurfaceItem.cpp+61 tests/mocks/Unity/Application/MirSurfaceItem.h+92 tests/mocks/Unity/Application/SurfaceManager.cpp+16 tests/mocks/Unity/Application/SurfaceManager.h+26 tests/mocks/Unity/Application/plugin.cpp+13
tests/mocks/Unity/Application/ApplicationInfo.cpp+59−20
@@ -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>
@@ -22,31 +24,42 @@
2224#include <QQmlComponent>
2325#include <QTimer>
2426
27+
2528ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
2629 : 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)
30+ , m_appId(appId)
31+ , m_stage(MainStage)
32+ , m_state(Starting)
33+ , m_focused(false)
34+ , m_fullscreen(false)
35+ , m_windowItem(0)
36+ , m_windowComponent(0)
37+ , m_parentItem(0)
38+ , m_surface(0)
3539{
36− QTimer::singleShot(300, this, SLOT(setRunning()));
40+ connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged);
3741}
3842
3943ApplicationInfo::ApplicationInfo(QObject *parent)
4044 : 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)
45+ , m_stage(MainStage)
46+ , m_state(Starting)
47+ , m_focused(false)
48+ , m_fullscreen(false)
49+ , m_windowItem(0)
50+ , m_windowComponent(0)
51+ , m_parentItem(0)
52+ , m_surface(0)
4853{
49− QTimer::singleShot(300, this, SLOT(setRunning()));
54+ connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged);
55+}
56+
57+ApplicationInfo::~ApplicationInfo()
58+{
59+ if (m_surface) {
60+ Q_EMIT SurfaceManager::singleton()->surfaceDestroyed(m_surface);
61+ m_surface->deleteLater();
62+ }
5063}
5164
5265void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status status)
@@ -55,10 +68,36 @@ void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status statu
5568 doCreateWindowItem();
5669}
5770
58−void ApplicationInfo::setRunning()
71+void ApplicationInfo::onStateChanged(State state)
5972{
60− m_state = Running;
61− Q_EMIT stateChanged();
73+ if (state == ApplicationInfo::Running) {
74+ QTimer::singleShot(1000, this, SLOT(createSurface()));
75+ } else if (state == ApplicationInfo::Stopped) {
76+ destroySurface();
77+ }
78+}
79+
80+void ApplicationInfo::createSurface()
81+{
82+ if (m_surface || state() == ApplicationInfo::Stopped) return;
83+
84+ m_surface = new MirSurfaceItem(name(),
85+ MirSurfaceItem::Normal,
86+ fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
87+ imageQml());
88+ Q_EMIT surfaceChanged(m_surface);
89+ Q_EMIT SurfaceManager::singleton()->surfaceCreated(m_surface);
90+}
91+
92+void ApplicationInfo::destroySurface()
93+{
94+ if (!m_surface) return;
95+ MirSurfaceItem* oldSurface = m_surface;
96+ m_surface = nullptr;
97+
98+ Q_EMIT surfaceChanged(nullptr);
99+ Q_EMIT SurfaceManager::singleton()->surfaceDestroyed(oldSurface);
100+ oldSurface->deleteLater();
62101}
63102
64103void ApplicationInfo::createWindowComponent()
tests/mocks/Unity/Application/ApplicationInfo.h+21−7
@@ -19,8 +19,10 @@
1919
2020#include <QObject>
2121#include <QQmlComponent>
22+#include <QDebug>
2223
2324class QQuickItem;
25+class MirSurfaceItem;
2426
2527// unity-api
2628#include <unity/shell/application/ApplicationInfoInterface.h>
@@ -36,6 +38,7 @@ class ApplicationInfo : public ApplicationInfoInterface {
3638
3739 Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
3840 Q_PROPERTY(Stage stage READ stage WRITE setStage NOTIFY stageChanged)
41+ Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
3942
4043 // Only exists in this fake implementation
4144
@@ -45,9 +48,10 @@ class ApplicationInfo : public ApplicationInfoInterface {
4548 // QML component used to represent the application window
4649 Q_PROPERTY(QString windowQml READ windowQml WRITE setWindowQml NOTIFY windowQmlChanged)
4750
48− public:
51+public:
4952 ApplicationInfo(QObject *parent = NULL);
5053 ApplicationInfo(const QString &appId, QObject *parent = NULL);
54+ ~ApplicationInfo();
5155
5256 #define IMPLEMENT_PROPERTY(name, Name, type) \
5357 public: \
@@ -56,11 +60,11 @@ class ApplicationInfo : public ApplicationInfoInterface {
5660 { \
5761 if (m_##name != value) { \
5862 m_##name = value; \
59− Q_EMIT name##Changed(); \
63+ Q_EMIT name##Changed(value); \
6064 } \
6165 } \
6266 Q_SIGNALS: \
63− void name##Changed(); \
67+ void name##Changed(const type&); \
6468 private: \
6569 type m_##name;
6670
@@ -78,21 +82,31 @@ class ApplicationInfo : public ApplicationInfoInterface {
7882
7983 #undef IMPLEMENT_PROPERTY
8084
81− public:
85+public:
86+ MirSurfaceItem* surface() const { return m_surface; }
87+
88+Q_SIGNALS:
89+ void surfaceChanged(MirSurfaceItem*);
90+
91+public:
8292 void showWindow(QQuickItem *parent);
8393 void hideWindow();
8494
85− private Q_SLOTS:
95+private Q_SLOTS:
8696 void onWindowComponentStatusChanged(QQmlComponent::Status status);
87− void setRunning();
97+ void onStateChanged(State state);
98+
99+ void createSurface();
100+ void destroySurface();
88101
89− private:
102+private:
90103 void createWindowItem();
91104 void doCreateWindowItem();
92105 void createWindowComponent();
93106 QQuickItem *m_windowItem;
94107 QQmlComponent *m_windowComponent;
95108 QQuickItem *m_parentItem;
109+ MirSurfaceItem* m_surface;
96110};
97111
98112Q_DECLARE_METATYPE(ApplicationInfo*)
tests/mocks/Unity/Application/ApplicationManager.cpp+32−18
@@ -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,7 @@ bool ApplicationManager::updateScreenshot(const QString &appId)
213241 return false;
214242 }
215243
216− application->setScreenshot(QString("image://application/%1/%2").arg(appId).arg(QDateTime::currentMSecsSinceEpoch()));
244+// application->setScreenshot(QString("image://application/%1/%2").arg(appId).arg(QDateTime::currentMSecsSinceEpoch()));
217245 QModelIndex appIndex = index(idx);
218246 Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << RoleScreenshot);
219247 return true;
@@ -352,6 +380,9 @@ void ApplicationManager::generateQmlStrings(ApplicationInfo *application)
352380 "}").arg(qmlDirectory())
353381 .arg(application->icon().toString());
354382 application->setImageQml(imageQml);
383+
384+ application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2.png").arg(qmlDirectory())
385+ .arg(application->icon().toString()));
355386}
356387
357388void ApplicationManager::buildListOfAvailableApplications()
@@ -363,7 +394,6 @@ void ApplicationManager::buildListOfAvailableApplications()
363394 application->setName("Dialer");
364395 application->setIcon(QUrl("dialer"));
365396 application->setStage(ApplicationInfo::SideStage);
366− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
367397 generateQmlStrings(application);
368398 m_availableApplications.append(application);
369399
@@ -372,7 +402,6 @@ void ApplicationManager::buildListOfAvailableApplications()
372402 application->setName("Camera");
373403 application->setIcon(QUrl("camera"));
374404 application->setFullscreen(true);
375− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
376405 generateQmlStrings(application);
377406 m_availableApplications.append(application);
378407
@@ -380,7 +409,6 @@ void ApplicationManager::buildListOfAvailableApplications()
380409 application->setAppId("gallery-app");
381410 application->setName("Gallery");
382411 application->setIcon(QUrl("gallery"));
383− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
384412 generateQmlStrings(application);
385413 m_availableApplications.append(application);
386414
@@ -389,7 +417,6 @@ void ApplicationManager::buildListOfAvailableApplications()
389417 application->setName("Facebook");
390418 application->setIcon(QUrl("facebook"));
391419 application->setStage(ApplicationInfo::SideStage);
392− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
393420 generateQmlStrings(application);
394421 m_availableApplications.append(application);
395422
@@ -398,7 +425,6 @@ void ApplicationManager::buildListOfAvailableApplications()
398425 application->setFullscreen(true);
399426 application->setName("Browser");
400427 application->setIcon(QUrl("browser"));
401− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
402428 generateQmlStrings(application);
403429 m_availableApplications.append(application);
404430
@@ -407,7 +433,6 @@ void ApplicationManager::buildListOfAvailableApplications()
407433 application->setName("Twitter");
408434 application->setIcon(QUrl("twitter"));
409435 application->setStage(ApplicationInfo::SideStage);
410− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
411436 generateQmlStrings(application);
412437 m_availableApplications.append(application);
413438
@@ -415,7 +440,6 @@ void ApplicationManager::buildListOfAvailableApplications()
415440 application->setAppId("gmail-webapp");
416441 application->setName("GMail");
417442 application->setIcon(QUrl("gmail"));
418− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
419443 m_availableApplications.append(application);
420444
421445 application = new ApplicationInfo(this);
@@ -423,7 +447,6 @@ void ApplicationManager::buildListOfAvailableApplications()
423447 application->setName("Weather");
424448 application->setIcon(QUrl("weather"));
425449 application->setStage(ApplicationInfo::SideStage);
426− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
427450 generateQmlStrings(application);
428451 m_availableApplications.append(application);
429452
@@ -432,7 +455,6 @@ void ApplicationManager::buildListOfAvailableApplications()
432455 application->setName("Notepad");
433456 application->setIcon(QUrl("notepad"));
434457 application->setStage(ApplicationInfo::SideStage);
435− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
436458 m_availableApplications.append(application);
437459
438460 application = new ApplicationInfo(this);
@@ -440,7 +462,6 @@ void ApplicationManager::buildListOfAvailableApplications()
440462 application->setName("Calendar");
441463 application->setIcon(QUrl("calendar"));
442464 application->setStage(ApplicationInfo::SideStage);
443− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
444465 m_availableApplications.append(application);
445466
446467 application = new ApplicationInfo(this);
@@ -448,21 +469,18 @@ void ApplicationManager::buildListOfAvailableApplications()
448469 application->setName("Media Player");
449470 application->setIcon(QUrl("mediaplayer-app"));
450471 application->setFullscreen(true);
451− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
452472 m_availableApplications.append(application);
453473
454474 application = new ApplicationInfo(this);
455475 application->setAppId("evernote");
456476 application->setName("Evernote");
457477 application->setIcon(QUrl("evernote"));
458− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
459478 m_availableApplications.append(application);
460479
461480 application = new ApplicationInfo(this);
462481 application->setAppId("map");
463482 application->setName("Map");
464483 application->setIcon(QUrl("map"));
465− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
466484 generateQmlStrings(application);
467485 m_availableApplications.append(application);
468486
@@ -470,28 +488,24 @@ void ApplicationManager::buildListOfAvailableApplications()
470488 application->setAppId("pinterest");
471489 application->setName("Pinterest");
472490 application->setIcon(QUrl("pinterest"));
473− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
474491 m_availableApplications.append(application);
475492
476493 application = new ApplicationInfo(this);
477494 application->setAppId("soundcloud");
478495 application->setName("SoundCloud");
479496 application->setIcon(QUrl("soundcloud"));
480− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
481497 m_availableApplications.append(application);
482498
483499 application = new ApplicationInfo(this);
484500 application->setAppId("wikipedia");
485501 application->setName("Wikipedia");
486502 application->setIcon(QUrl("wikipedia"));
487− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
488503 m_availableApplications.append(application);
489504
490505 application = new ApplicationInfo(this);
491506 application->setAppId("youtube");
492507 application->setName("YouTube");
493508 application->setIcon(QUrl("youtube"));
494− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
495509 m_availableApplications.append(application);
496510}
497511
tests/mocks/Unity/Application/ApplicationManager.h+6
@@ -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+61
@@ -0,0 +1,61 @@
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 <QQmlEngine>
20+#include <QQmlComponent>
21+#include <QQmlContext>
22+#include <QTimer>
23+
24+MirSurfaceItem::MirSurfaceItem(const QString& name,
25+ MirSurfaceItem::Type type,
26+ MirSurfaceItem::State state,
27+ const QString& imageQml,
28+ QQuickItem *parent)
29+ : QQuickItem(parent)
30+ , m_name(name)
31+ , m_type(type)
32+ , m_state(state)
33+ , m_imageQml(imageQml)
34+ , m_imageComponent(nullptr)
35+ , m_imageItem(nullptr)
36+{
37+}
38+
39+void MirSurfaceItem::itemChange(ItemChange change, const ItemChangeData & value)
40+{
41+ QQuickItem::itemChange(change, value);
42+
43+ Q_UNUSED(value)
44+ if (change == QQuickItem::ItemParentHasChanged) {
45+ createImage();
46+ }
47+}
48+
49+void MirSurfaceItem::createImage()
50+{
51+ if (!m_imageComponent) {
52+ QQmlContext* context = QQmlEngine::contextForObject(parentItem());
53+ if (!context) return;
54+ m_imageComponent = new QQmlComponent(context->engine(), this);
55+ m_imageComponent->setData(m_imageQml.toUtf8(), QUrl());
56+ }
57+ if (!m_imageItem) {
58+ m_imageItem = qobject_cast<QQuickItem *>(m_imageComponent->create());
59+ if (m_imageItem) m_imageItem->setParentItem(this);
60+ }
61+}
tests/mocks/Unity/Application/MirSurfaceItem.hnew file+92
@@ -0,0 +1,92 @@
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 <QQuickItem>
21+
22+class QQmlComponent;
23+
24+class MirSurfaceItem : public QQuickItem
25+{
26+ Q_OBJECT
27+ Q_ENUMS(Type)
28+ Q_ENUMS(State)
29+
30+ Q_PROPERTY(Type type READ type NOTIFY typeChanged)
31+ Q_PROPERTY(State state READ state NOTIFY stateChanged)
32+ Q_PROPERTY(QString name READ name NOTIFY nameChanged)
33+
34+public:
35+ enum Type {
36+ Normal,
37+ Utility,
38+ Dialog,
39+ Overlay,
40+ Freestyle,
41+ Popover,
42+ InputMethod,
43+ };
44+
45+ enum State {
46+ Unknown,
47+ Restored,
48+ Minimized,
49+ Maximized,
50+ VertMaximized,
51+ /* SemiMaximized, */
52+ Fullscreen,
53+ };
54+
55+ explicit MirSurfaceItem(const QString& name,
56+ Type type,
57+ State state,
58+ QString const& imageQml,
59+ QQuickItem *parent = 0);
60+
61+ //getters
62+ Type type() const { return m_type; }
63+ State state() const { return m_state; }
64+ QString name() const { return m_name; }
65+
66+ Q_INVOKABLE void release() {}
67+
68+Q_SIGNALS:
69+ void typeChanged(Type);
70+ void stateChanged(State);
71+ void nameChanged(QString);
72+
73+protected:
74+ void itemChange(ItemChange change, const ItemChangeData& value) override;
75+
76+private Q_SLOTS:
77+ void createImage();
78+
79+private:
80+
81+ const QString m_name;
82+ const Type m_type;
83+ const State m_state;
84+ const QString m_imageQml;
85+
86+ QQmlComponent *m_imageComponent;
87+ QQuickItem* m_imageItem;
88+};
89+
90+Q_DECLARE_METATYPE(MirSurfaceItem*)
91+
92+#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+13
@@ -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