on xenial help sign in
mocks for qtmir
f4240f4Nick Dedekind
tests/mocks/Unity/Application/ApplicationInfo.cpp+59−20
@@ -15,6 +15,8 @@
15 */
15 */
16
16
17#include "ApplicationInfo.h"
17#include "ApplicationInfo.h"
18+#include "MirSurfaceItem.h"
19+#include "SurfaceManager.h"
18
20
19#include <QGuiApplication>
21#include <QGuiApplication>
20#include <QQuickItem>
22#include <QQuickItem>
@@ -22,31 +24,42 @@
22#include <QQmlComponent>
24#include <QQmlComponent>
23#include <QTimer>
25#include <QTimer>
24
26
27+
25ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
28ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
26 : ApplicationInfoInterface(appId, parent)
29 : ApplicationInfoInterface(appId, parent)
27− ,m_appId(appId)
30+ , m_appId(appId)
28− ,m_stage(MainStage)
31+ , m_stage(MainStage)
29− ,m_state(Starting)
32+ , m_state(Starting)
30− ,m_focused(false)
33+ , m_focused(false)
31− ,m_fullscreen(false)
34+ , m_fullscreen(false)
32− ,m_windowItem(0)
35+ , m_windowItem(0)
33− ,m_windowComponent(0)
36+ , m_windowComponent(0)
34− ,m_parentItem(0)
37+ , m_parentItem(0)
38+ , m_surface(0)
35{
39{
36− QTimer::singleShot(300, this, SLOT(setRunning()));
40+ connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged);
37}
41}
38
42
39ApplicationInfo::ApplicationInfo(QObject *parent)
43ApplicationInfo::ApplicationInfo(QObject *parent)
40 : ApplicationInfoInterface(QString(), parent)
44 : ApplicationInfoInterface(QString(), parent)
41− ,m_stage(MainStage)
45+ , m_stage(MainStage)
42− ,m_state(Starting)
46+ , m_state(Starting)
43− ,m_focused(false)
47+ , m_focused(false)
44− ,m_fullscreen(false)
48+ , m_fullscreen(false)
45− ,m_windowItem(0)
49+ , m_windowItem(0)
46− ,m_windowComponent(0)
50+ , m_windowComponent(0)
47− ,m_parentItem(0)
51+ , m_parentItem(0)
52+ , m_surface(0)
48{
53{
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+ }
50}
63}
51
64
52void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status status)
65void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status status)
@@ -55,10 +68,36 @@ void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status statu
55 doCreateWindowItem();
68 doCreateWindowItem();
56}
69}
57
70
58−void ApplicationInfo::setRunning()
71+void ApplicationInfo::onStateChanged(State state)
59{
72{
60− m_state = Running;
73+ if (state == ApplicationInfo::Running) {
61− Q_EMIT stateChanged();
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();
62}
101}
63
102
64void ApplicationInfo::createWindowComponent()
103void ApplicationInfo::createWindowComponent()
tests/mocks/Unity/Application/ApplicationInfo.h+21−7
@@ -19,8 +19,10 @@
19
19
20#include <QObject>
20#include <QObject>
21#include <QQmlComponent>
21#include <QQmlComponent>
22+#include <QDebug>
22
23
23class QQuickItem;
24class QQuickItem;
25+class MirSurfaceItem;
24
26
25// unity-api
27// unity-api
26#include <unity/shell/application/ApplicationInfoInterface.h>
28#include <unity/shell/application/ApplicationInfoInterface.h>
@@ -36,6 +38,7 @@ class ApplicationInfo : public ApplicationInfoInterface {
36
38
37 Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
39 Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
38 Q_PROPERTY(Stage stage READ stage WRITE setStage NOTIFY stageChanged)
40 Q_PROPERTY(Stage stage READ stage WRITE setStage NOTIFY stageChanged)
41+ Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
39
42
40 // Only exists in this fake implementation
43 // Only exists in this fake implementation
41
44
@@ -45,9 +48,10 @@ class ApplicationInfo : public ApplicationInfoInterface {
45 // QML component used to represent the application window
48 // QML component used to represent the application window
46 Q_PROPERTY(QString windowQml READ windowQml WRITE setWindowQml NOTIFY windowQmlChanged)
49 Q_PROPERTY(QString windowQml READ windowQml WRITE setWindowQml NOTIFY windowQmlChanged)
47
50
48− public:
51+public:
49 ApplicationInfo(QObject *parent = NULL);
52 ApplicationInfo(QObject *parent = NULL);
50 ApplicationInfo(const QString &appId, QObject *parent = NULL);
53 ApplicationInfo(const QString &appId, QObject *parent = NULL);
54+ ~ApplicationInfo();
51
55
52 #define IMPLEMENT_PROPERTY(name, Name, type) \
56 #define IMPLEMENT_PROPERTY(name, Name, type) \
53 public: \
57 public: \
@@ -56,11 +60,11 @@ class ApplicationInfo : public ApplicationInfoInterface {
56 { \
60 { \
57 if (m_##name != value) { \
61 if (m_##name != value) { \
58 m_##name = value; \
62 m_##name = value; \
59− Q_EMIT name##Changed(); \
63+ Q_EMIT name##Changed(value); \
60 } \
64 } \
61 } \
65 } \
62 Q_SIGNALS: \
66 Q_SIGNALS: \
63− void name##Changed(); \
67+ void name##Changed(const type&); \
64 private: \
68 private: \
65 type m_##name;
69 type m_##name;
66
70
@@ -78,21 +82,31 @@ class ApplicationInfo : public ApplicationInfoInterface {
78
82
79 #undef IMPLEMENT_PROPERTY
83 #undef IMPLEMENT_PROPERTY
80
84
85+public:
86+ MirSurfaceItem* surface() const { return m_surface; }
87+
88+Q_SIGNALS:
89+ void surfaceChanged(MirSurfaceItem*);
90+
81− public:
91+public:
82 void showWindow(QQuickItem *parent);
92 void showWindow(QQuickItem *parent);
83 void hideWindow();
93 void hideWindow();
84
94
85− private Q_SLOTS:
95+private Q_SLOTS:
86 void onWindowComponentStatusChanged(QQmlComponent::Status status);
96 void onWindowComponentStatusChanged(QQmlComponent::Status status);
87− void setRunning();
97+ void onStateChanged(State state);
98+
99+ void createSurface();
100+ void destroySurface();
88
101
89− private:
102+private:
90 void createWindowItem();
103 void createWindowItem();
91 void doCreateWindowItem();
104 void doCreateWindowItem();
92 void createWindowComponent();
105 void createWindowComponent();
93 QQuickItem *m_windowItem;
106 QQuickItem *m_windowItem;
94 QQmlComponent *m_windowComponent;
107 QQmlComponent *m_windowComponent;
95 QQuickItem *m_parentItem;
108 QQuickItem *m_parentItem;
109+ MirSurfaceItem* m_surface;
96};
110};
97
111
98Q_DECLARE_METATYPE(ApplicationInfo*)
112Q_DECLARE_METATYPE(ApplicationInfo*)
tests/mocks/Unity/Application/ApplicationManager.cpp+32−18
@@ -16,6 +16,7 @@
16
16
17#include "ApplicationManager.h"
17#include "ApplicationManager.h"
18#include "ApplicationInfo.h"
18#include "ApplicationInfo.h"
19+#include "MirSurfaceItem.h"
19
20
20#include <paths.h>
21#include <paths.h>
21
22
@@ -36,6 +37,9 @@ ApplicationManager::ApplicationManager(QObject *parent)
36 , m_sideStage(0)
37 , m_sideStage(0)
37 , m_rightMargin(0)
38 , m_rightMargin(0)
38{
39{
40+ m_roleNames.insert(RoleSurface, "surface");
41+ m_roleNames.insert(RoleFullscreen, "fullscreen");
42+
39 buildListOfAvailableApplications();
43 buildListOfAvailableApplications();
40}
44}
41
45
@@ -69,6 +73,10 @@ QVariant ApplicationManager::data(const QModelIndex& index, int role) const {
69 return app->focused();
73 return app->focused();
70 case RoleScreenshot:
74 case RoleScreenshot:
71 return app->screenshot();
75 return app->screenshot();
76+ case RoleSurface:
77+ return QVariant::fromValue(app->surface());
78+ case RoleFullscreen:
79+ return app->fullscreen();
72 default:
80 default:
73 return QVariant();
81 return QVariant();
74 }
82 }
@@ -89,6 +97,17 @@ ApplicationInfo *ApplicationManager::findApplication(const QString &appId) const
89 return nullptr;
97 return nullptr;
90}
98}
91
99
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+
92void ApplicationManager::add(ApplicationInfo *application) {
111void ApplicationManager::add(ApplicationInfo *application) {
93 if (!application) {
112 if (!application) {
94 return;
113 return;
@@ -100,6 +119,12 @@ void ApplicationManager::add(ApplicationInfo *application) {
100 Q_EMIT applicationAdded(application->appId());
119 Q_EMIT applicationAdded(application->appId());
101 Q_EMIT countChanged();
120 Q_EMIT countChanged();
102 Q_EMIT focusRequested(application->appId());
121 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+ });
103}
128}
104
129
105void ApplicationManager::remove(ApplicationInfo *application) {
130void ApplicationManager::remove(ApplicationInfo *application) {
@@ -111,6 +136,7 @@ void ApplicationManager::remove(ApplicationInfo *application) {
111 Q_EMIT applicationRemoved(application->appId());
136 Q_EMIT applicationRemoved(application->appId());
112 Q_EMIT countChanged();
137 Q_EMIT countChanged();
113 }
138 }
139+ disconnect(application, &ApplicationInfo::surfaceChanged, this, 0);
114}
140}
115
141
116void ApplicationManager::move(int from, int to) {
142void ApplicationManager::move(int from, int to) {
@@ -180,6 +206,7 @@ ApplicationInfo* ApplicationManager::startApplication(const QString &appId,
180 application->setStage(ApplicationInfo::MainStage);
206 application->setStage(ApplicationInfo::MainStage);
181 }
207 }
182 add(application);
208 add(application);
209+ application->setState(ApplicationInfo::Running);
183
210
184 return application;
211 return application;
185}
212}
@@ -193,6 +220,7 @@ bool ApplicationManager::stopApplication(const QString &appId)
193 if (application->appId() == focusedApplicationId()) {
220 if (application->appId() == focusedApplicationId()) {
194 unfocusCurrentApplication();
221 unfocusCurrentApplication();
195 }
222 }
223+ application->setState(ApplicationInfo::Stopped);
196 remove(application);
224 remove(application);
197 return true;
225 return true;
198}
226}
@@ -213,7 +241,7 @@ bool ApplicationManager::updateScreenshot(const QString &appId)
213 return false;
241 return false;
214 }
242 }
215
243
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()));
217 QModelIndex appIndex = index(idx);
245 QModelIndex appIndex = index(idx);
218 Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << RoleScreenshot);
246 Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << RoleScreenshot);
219 return true;
247 return true;
@@ -352,6 +380,9 @@ void ApplicationManager::generateQmlStrings(ApplicationInfo *application)
352 "}").arg(qmlDirectory())
380 "}").arg(qmlDirectory())
353 .arg(application->icon().toString());
381 .arg(application->icon().toString());
354 application->setImageQml(imageQml);
382 application->setImageQml(imageQml);
383+
384+ application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2.png").arg(qmlDirectory())
385+ .arg(application->icon().toString()));
355}
386}
356
387
357void ApplicationManager::buildListOfAvailableApplications()
388void ApplicationManager::buildListOfAvailableApplications()
@@ -363,7 +394,6 @@ void ApplicationManager::buildListOfAvailableApplications()
363 application->setName("Dialer");
394 application->setName("Dialer");
364 application->setIcon(QUrl("dialer"));
395 application->setIcon(QUrl("dialer"));
365 application->setStage(ApplicationInfo::SideStage);
396 application->setStage(ApplicationInfo::SideStage);
366− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
367 generateQmlStrings(application);
397 generateQmlStrings(application);
368 m_availableApplications.append(application);
398 m_availableApplications.append(application);
369
399
@@ -372,7 +402,6 @@ void ApplicationManager::buildListOfAvailableApplications()
372 application->setName("Camera");
402 application->setName("Camera");
373 application->setIcon(QUrl("camera"));
403 application->setIcon(QUrl("camera"));
374 application->setFullscreen(true);
404 application->setFullscreen(true);
375− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
376 generateQmlStrings(application);
405 generateQmlStrings(application);
377 m_availableApplications.append(application);
406 m_availableApplications.append(application);
378
407
@@ -380,7 +409,6 @@ void ApplicationManager::buildListOfAvailableApplications()
380 application->setAppId("gallery-app");
409 application->setAppId("gallery-app");
381 application->setName("Gallery");
410 application->setName("Gallery");
382 application->setIcon(QUrl("gallery"));
411 application->setIcon(QUrl("gallery"));
383− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
384 generateQmlStrings(application);
412 generateQmlStrings(application);
385 m_availableApplications.append(application);
413 m_availableApplications.append(application);
386
414
@@ -389,7 +417,6 @@ void ApplicationManager::buildListOfAvailableApplications()
389 application->setName("Facebook");
417 application->setName("Facebook");
390 application->setIcon(QUrl("facebook"));
418 application->setIcon(QUrl("facebook"));
391 application->setStage(ApplicationInfo::SideStage);
419 application->setStage(ApplicationInfo::SideStage);
392− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
393 generateQmlStrings(application);
420 generateQmlStrings(application);
394 m_availableApplications.append(application);
421 m_availableApplications.append(application);
395
422
@@ -398,7 +425,6 @@ void ApplicationManager::buildListOfAvailableApplications()
398 application->setFullscreen(true);
425 application->setFullscreen(true);
399 application->setName("Browser");
426 application->setName("Browser");
400 application->setIcon(QUrl("browser"));
427 application->setIcon(QUrl("browser"));
401− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
402 generateQmlStrings(application);
428 generateQmlStrings(application);
403 m_availableApplications.append(application);
429 m_availableApplications.append(application);
404
430
@@ -407,7 +433,6 @@ void ApplicationManager::buildListOfAvailableApplications()
407 application->setName("Twitter");
433 application->setName("Twitter");
408 application->setIcon(QUrl("twitter"));
434 application->setIcon(QUrl("twitter"));
409 application->setStage(ApplicationInfo::SideStage);
435 application->setStage(ApplicationInfo::SideStage);
410− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
411 generateQmlStrings(application);
436 generateQmlStrings(application);
412 m_availableApplications.append(application);
437 m_availableApplications.append(application);
413
438
@@ -415,7 +440,6 @@ void ApplicationManager::buildListOfAvailableApplications()
415 application->setAppId("gmail-webapp");
440 application->setAppId("gmail-webapp");
416 application->setName("GMail");
441 application->setName("GMail");
417 application->setIcon(QUrl("gmail"));
442 application->setIcon(QUrl("gmail"));
418− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
419 m_availableApplications.append(application);
443 m_availableApplications.append(application);
420
444
421 application = new ApplicationInfo(this);
445 application = new ApplicationInfo(this);
@@ -423,7 +447,6 @@ void ApplicationManager::buildListOfAvailableApplications()
423 application->setName("Weather");
447 application->setName("Weather");
424 application->setIcon(QUrl("weather"));
448 application->setIcon(QUrl("weather"));
425 application->setStage(ApplicationInfo::SideStage);
449 application->setStage(ApplicationInfo::SideStage);
426− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
427 generateQmlStrings(application);
450 generateQmlStrings(application);
428 m_availableApplications.append(application);
451 m_availableApplications.append(application);
429
452
@@ -432,7 +455,6 @@ void ApplicationManager::buildListOfAvailableApplications()
432 application->setName("Notepad");
455 application->setName("Notepad");
433 application->setIcon(QUrl("notepad"));
456 application->setIcon(QUrl("notepad"));
434 application->setStage(ApplicationInfo::SideStage);
457 application->setStage(ApplicationInfo::SideStage);
435− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
436 m_availableApplications.append(application);
458 m_availableApplications.append(application);
437
459
438 application = new ApplicationInfo(this);
460 application = new ApplicationInfo(this);
@@ -440,7 +462,6 @@ void ApplicationManager::buildListOfAvailableApplications()
440 application->setName("Calendar");
462 application->setName("Calendar");
441 application->setIcon(QUrl("calendar"));
463 application->setIcon(QUrl("calendar"));
442 application->setStage(ApplicationInfo::SideStage);
464 application->setStage(ApplicationInfo::SideStage);
443− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
444 m_availableApplications.append(application);
465 m_availableApplications.append(application);
445
466
446 application = new ApplicationInfo(this);
467 application = new ApplicationInfo(this);
@@ -448,21 +469,18 @@ void ApplicationManager::buildListOfAvailableApplications()
448 application->setName("Media Player");
469 application->setName("Media Player");
449 application->setIcon(QUrl("mediaplayer-app"));
470 application->setIcon(QUrl("mediaplayer-app"));
450 application->setFullscreen(true);
471 application->setFullscreen(true);
451− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
452 m_availableApplications.append(application);
472 m_availableApplications.append(application);
453
473
454 application = new ApplicationInfo(this);
474 application = new ApplicationInfo(this);
455 application->setAppId("evernote");
475 application->setAppId("evernote");
456 application->setName("Evernote");
476 application->setName("Evernote");
457 application->setIcon(QUrl("evernote"));
477 application->setIcon(QUrl("evernote"));
458− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
459 m_availableApplications.append(application);
478 m_availableApplications.append(application);
460
479
461 application = new ApplicationInfo(this);
480 application = new ApplicationInfo(this);
462 application->setAppId("map");
481 application->setAppId("map");
463 application->setName("Map");
482 application->setName("Map");
464 application->setIcon(QUrl("map"));
483 application->setIcon(QUrl("map"));
465− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
466 generateQmlStrings(application);
484 generateQmlStrings(application);
467 m_availableApplications.append(application);
485 m_availableApplications.append(application);
468
486
@@ -470,28 +488,24 @@ void ApplicationManager::buildListOfAvailableApplications()
470 application->setAppId("pinterest");
488 application->setAppId("pinterest");
471 application->setName("Pinterest");
489 application->setName("Pinterest");
472 application->setIcon(QUrl("pinterest"));
490 application->setIcon(QUrl("pinterest"));
473− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
474 m_availableApplications.append(application);
491 m_availableApplications.append(application);
475
492
476 application = new ApplicationInfo(this);
493 application = new ApplicationInfo(this);
477 application->setAppId("soundcloud");
494 application->setAppId("soundcloud");
478 application->setName("SoundCloud");
495 application->setName("SoundCloud");
479 application->setIcon(QUrl("soundcloud"));
496 application->setIcon(QUrl("soundcloud"));
480− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
481 m_availableApplications.append(application);
497 m_availableApplications.append(application);
482
498
483 application = new ApplicationInfo(this);
499 application = new ApplicationInfo(this);
484 application->setAppId("wikipedia");
500 application->setAppId("wikipedia");
485 application->setName("Wikipedia");
501 application->setName("Wikipedia");
486 application->setIcon(QUrl("wikipedia"));
502 application->setIcon(QUrl("wikipedia"));
487− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
488 m_availableApplications.append(application);
503 m_availableApplications.append(application);
489
504
490 application = new ApplicationInfo(this);
505 application = new ApplicationInfo(this);
491 application->setAppId("youtube");
506 application->setAppId("youtube");
492 application->setName("YouTube");
507 application->setName("YouTube");
493 application->setIcon(QUrl("youtube"));
508 application->setIcon(QUrl("youtube"));
494− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
495 m_availableApplications.append(application);
509 m_availableApplications.append(application);
496}
510}
497
511
tests/mocks/Unity/Application/ApplicationManager.h+6
@@ -53,6 +53,10 @@ class ApplicationManager : public ApplicationManagerInterface {
53 ApplicationManager(QObject *parent = NULL);
53 ApplicationManager(QObject *parent = NULL);
54 virtual ~ApplicationManager();
54 virtual ~ApplicationManager();
55
55
56+ enum MoreRoles {
57+ RoleSurface = RoleScreenshot+1,
58+ RoleFullscreen,
59+ };
56 enum Role {
60 enum Role {
57 Dash, Default, Indicators, Notifications, Greeter, Launcher, OnScreenKeyboard,
61 Dash, Default, Indicators, Notifications, Greeter, Launcher, OnScreenKeyboard,
58 ShutdownDialog
62 ShutdownDialog
@@ -108,6 +112,8 @@ class ApplicationManager : public ApplicationManagerInterface {
108 int rightMargin() const;
112 int rightMargin() const;
109 void setRightMargin(int rightMargin);
113 void setRightMargin(int rightMargin);
110
114
115+ QModelIndex findIndex(ApplicationInfo* application);
116+
111 Q_SIGNALS:
117 Q_SIGNALS:
112 void keyboardHeightChanged();
118 void keyboardHeightChanged();
113 void keyboardVisibleChanged();
119 void keyboardVisibleChanged();
tests/mocks/Unity/Application/CMakeLists.txt+2
@@ -6,6 +6,8 @@ set(FakeUnityApplicationQml_SOURCES
6 ApplicationImage.cpp
6 ApplicationImage.cpp
7 ApplicationManager.cpp
7 ApplicationManager.cpp
8 ApplicationScreenshotProvider.cpp
8 ApplicationScreenshotProvider.cpp
9+ MirSurfaceItem.cpp
10+ SurfaceManager.cpp
9 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
11 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
10 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
12 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
11)
13)
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 @@
19#include "ApplicationImage.h"
19#include "ApplicationImage.h"
20#include "ApplicationManager.h"
20#include "ApplicationManager.h"
21#include "ApplicationScreenshotProvider.h"
21#include "ApplicationScreenshotProvider.h"
22+#include "MirSurfaceItem.h"
23+#include "SurfaceManager.h"
22
24
23#include <qqml.h>
25#include <qqml.h>
24#include <QQmlEngine>
26#include <QQmlEngine>
@@ -34,14 +36,25 @@ static QObject* applicationManagerSingleton(QQmlEngine* engine, QJSEngine* scrip
34 return s_appManager;
36 return s_appManager;
35}
37}
36
38
39+static QObject* surfaceManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
40+ Q_UNUSED(engine);
41+ Q_UNUSED(scriptEngine);
42+ return SurfaceManager::singleton();
43+}
44+
37void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
45void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
38{
46{
47+ qRegisterMetaType<MirSurfaceItem*>("MirSurfaceItem*");
48+
39 qmlRegisterUncreatableType<unity::shell::application::ApplicationManagerInterface>(uri, 0, 1, "ApplicationManagerInterface", "Abstract interface. Cannot be created in QML");
49 qmlRegisterUncreatableType<unity::shell::application::ApplicationManagerInterface>(uri, 0, 1, "ApplicationManagerInterface", "Abstract interface. Cannot be created in QML");
40 qmlRegisterSingletonType<ApplicationManager>(uri, 0, 1, "ApplicationManager", applicationManagerSingleton);
50 qmlRegisterSingletonType<ApplicationManager>(uri, 0, 1, "ApplicationManager", applicationManagerSingleton);
51+ qmlRegisterSingletonType<SurfaceManager>(uri, 0, 1, "SurfaceManager", surfaceManagerSingleton);
41
52
42 qmlRegisterUncreatableType<unity::shell::application::ApplicationInfoInterface>(uri, 0, 1, "ApplicationInfoInterface", "Abstract interface. Cannot be created in QML");
53 qmlRegisterUncreatableType<unity::shell::application::ApplicationInfoInterface>(uri, 0, 1, "ApplicationInfoInterface", "Abstract interface. Cannot be created in QML");
43 qmlRegisterType<ApplicationInfo>(uri, 0, 1, "ApplicationInfo");
54 qmlRegisterType<ApplicationInfo>(uri, 0, 1, "ApplicationInfo");
44
55
56+ qmlRegisterUncreatableType<MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem", "MirSurfaceItem can't be instantiated from QML");
57+
45 qmlRegisterType<ApplicationImage>(uri, 0, 1, "ApplicationImage");
58 qmlRegisterType<ApplicationImage>(uri, 0, 1, "ApplicationImage");
46}
59}
47
60