on xenial help sign in
Fixed up AppManager mock for qtmir surfaces.
eb31fa2Nick Dedekind
tests/mocks/Unity/Application/ApplicationInfo.cpp+59−21
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2014 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -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>
@@ -24,29 +26,39 @@
24
26
25ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
27ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
26 : ApplicationInfoInterface(appId, parent)
28 : ApplicationInfoInterface(appId, parent)
27− ,m_appId(appId)
29+ , m_appId(appId)
28− ,m_stage(MainStage)
30+ , m_stage(MainStage)
29− ,m_state(Starting)
31+ , m_state(Starting)
30− ,m_focused(false)
32+ , m_focused(false)
31− ,m_fullscreen(false)
33+ , m_fullscreen(false)
32− ,m_windowItem(0)
34+ , m_windowItem(0)
33− ,m_windowComponent(0)
35+ , m_windowComponent(0)
34− ,m_parentItem(0)
36+ , m_parentItem(0)
37+ , m_surface(0)
35{
38{
36− QTimer::singleShot(300, this, SLOT(setRunning()));
39+ connect(this, &ApplicationInfo::stateChanged, this, &ApplicationInfo::onStateChanged);
37}
40}
38
41
39ApplicationInfo::ApplicationInfo(QObject *parent)
42ApplicationInfo::ApplicationInfo(QObject *parent)
40 : ApplicationInfoInterface(QString(), parent)
43 : ApplicationInfoInterface(QString(), parent)
41− ,m_stage(MainStage)
44+ , m_stage(MainStage)
42− ,m_state(Starting)
45+ , m_state(Starting)
43− ,m_focused(false)
46+ , m_focused(false)
44− ,m_fullscreen(false)
47+ , m_fullscreen(false)
45− ,m_windowItem(0)
48+ , m_windowItem(0)
46− ,m_windowComponent(0)
49+ , m_windowComponent(0)
47− ,m_parentItem(0)
50+ , m_parentItem(0)
51+ , m_surface(0)
48{
52{
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+ }
50}
62}
51
63
52void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status status)
64void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status status)
@@ -55,10 +67,36 @@ void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status statu
55 doCreateWindowItem();
67 doCreateWindowItem();
56}
68}
57
69
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()
59{
92{
60− m_state = Running;
93+ if (!m_surface) return;
61− Q_EMIT stateChanged();
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();
62}
100}
63
101
64void ApplicationInfo::createWindowComponent()
102void ApplicationInfo::createWindowComponent()
tests/mocks/Unity/Application/ApplicationInfo.h+21−8
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2014 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
21#include <QQmlComponent>
21#include <QQmlComponent>
22
22
23class QQuickItem;
23class QQuickItem;
24+class MirSurfaceItem;
24
25
25// unity-api
26// unity-api
26#include <unity/shell/application/ApplicationInfoInterface.h>
27#include <unity/shell/application/ApplicationInfoInterface.h>
@@ -36,6 +37,7 @@ class ApplicationInfo : public ApplicationInfoInterface {
36
37
37 Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
38 Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
38 Q_PROPERTY(Stage stage READ stage WRITE setStage NOTIFY stageChanged)
39 Q_PROPERTY(Stage stage READ stage WRITE setStage NOTIFY stageChanged)
40+ Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
39
41
40 // Only exists in this fake implementation
42 // Only exists in this fake implementation
41
43
@@ -45,9 +47,10 @@ class ApplicationInfo : public ApplicationInfoInterface {
45 // QML component used to represent the application window
47 // QML component used to represent the application window
46 Q_PROPERTY(QString windowQml READ windowQml WRITE setWindowQml NOTIFY windowQmlChanged)
48 Q_PROPERTY(QString windowQml READ windowQml WRITE setWindowQml NOTIFY windowQmlChanged)
47
49
48− public:
50+public:
49 ApplicationInfo(QObject *parent = NULL);
51 ApplicationInfo(QObject *parent = NULL);
50 ApplicationInfo(const QString &appId, QObject *parent = NULL);
52 ApplicationInfo(const QString &appId, QObject *parent = NULL);
53+ ~ApplicationInfo();
51
54
52 #define IMPLEMENT_PROPERTY(name, Name, type) \
55 #define IMPLEMENT_PROPERTY(name, Name, type) \
53 public: \
56 public: \
@@ -56,11 +59,11 @@ class ApplicationInfo : public ApplicationInfoInterface {
56 { \
59 { \
57 if (m_##name != value) { \
60 if (m_##name != value) { \
58 m_##name = value; \
61 m_##name = value; \
59− Q_EMIT name##Changed(); \
62+ Q_EMIT name##Changed(value); \
60 } \
63 } \
61 } \
64 } \
62 Q_SIGNALS: \
65 Q_SIGNALS: \
63− void name##Changed(); \
66+ void name##Changed(const type&); \
64 private: \
67 private: \
65 type m_##name;
68 type m_##name;
66
69
@@ -78,21 +81,31 @@ class ApplicationInfo : public ApplicationInfoInterface {
78
81
79 #undef IMPLEMENT_PROPERTY
82 #undef IMPLEMENT_PROPERTY
80
83
84+public:
85+ MirSurfaceItem* surface() const { return m_surface; }
86+
87+Q_SIGNALS:
88+ void surfaceChanged(MirSurfaceItem*);
89+
81− public:
90+public:
82 void showWindow(QQuickItem *parent);
91 void showWindow(QQuickItem *parent);
83 void hideWindow();
92 void hideWindow();
84
93
85− private Q_SLOTS:
94+private Q_SLOTS:
86 void onWindowComponentStatusChanged(QQmlComponent::Status status);
95 void onWindowComponentStatusChanged(QQmlComponent::Status status);
87− void setRunning();
96+ void onStateChanged(State state);
97+
98+ void createSurface();
99+ void destroySurface();
88
100
89− private:
101+private:
90 void createWindowItem();
102 void createWindowItem();
91 void doCreateWindowItem();
103 void doCreateWindowItem();
92 void createWindowComponent();
104 void createWindowComponent();
93 QQuickItem *m_windowItem;
105 QQuickItem *m_windowItem;
94 QQmlComponent *m_windowComponent;
106 QQmlComponent *m_windowComponent;
95 QQuickItem *m_parentItem;
107 QQuickItem *m_parentItem;
108+ MirSurfaceItem* m_surface;
96};
109};
97
110
98Q_DECLARE_METATYPE(ApplicationInfo*)
111Q_DECLARE_METATYPE(ApplicationInfo*)
tests/mocks/Unity/Application/ApplicationManager.cpp+32−19
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2014 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -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,6 @@ 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()));
217 QModelIndex appIndex = index(idx);
244 QModelIndex appIndex = index(idx);
218 Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << RoleScreenshot);
245 Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << RoleScreenshot);
219 return true;
246 return true;
@@ -352,6 +379,9 @@ void ApplicationManager::generateQmlStrings(ApplicationInfo *application)
352 "}").arg(qmlDirectory())
379 "}").arg(qmlDirectory())
353 .arg(application->icon().toString());
380 .arg(application->icon().toString());
354 application->setImageQml(imageQml);
381 application->setImageQml(imageQml);
382+
383+ application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png").arg(qmlDirectory())
384+ .arg(application->icon().toString()));
355}
385}
356
386
357void ApplicationManager::buildListOfAvailableApplications()
387void ApplicationManager::buildListOfAvailableApplications()
@@ -363,7 +393,6 @@ void ApplicationManager::buildListOfAvailableApplications()
363 application->setName("Dialer");
393 application->setName("Dialer");
364 application->setIcon(QUrl("dialer"));
394 application->setIcon(QUrl("dialer"));
365 application->setStage(ApplicationInfo::SideStage);
395 application->setStage(ApplicationInfo::SideStage);
366− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
367 generateQmlStrings(application);
396 generateQmlStrings(application);
368 m_availableApplications.append(application);
397 m_availableApplications.append(application);
369
398
@@ -372,7 +401,6 @@ void ApplicationManager::buildListOfAvailableApplications()
372 application->setName("Camera");
401 application->setName("Camera");
373 application->setIcon(QUrl("camera"));
402 application->setIcon(QUrl("camera"));
374 application->setFullscreen(true);
403 application->setFullscreen(true);
375− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
376 generateQmlStrings(application);
404 generateQmlStrings(application);
377 m_availableApplications.append(application);
405 m_availableApplications.append(application);
378
406
@@ -380,7 +408,6 @@ void ApplicationManager::buildListOfAvailableApplications()
380 application->setAppId("gallery-app");
408 application->setAppId("gallery-app");
381 application->setName("Gallery");
409 application->setName("Gallery");
382 application->setIcon(QUrl("gallery"));
410 application->setIcon(QUrl("gallery"));
383− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
384 generateQmlStrings(application);
411 generateQmlStrings(application);
385 m_availableApplications.append(application);
412 m_availableApplications.append(application);
386
413
@@ -389,7 +416,6 @@ void ApplicationManager::buildListOfAvailableApplications()
389 application->setName("Facebook");
416 application->setName("Facebook");
390 application->setIcon(QUrl("facebook"));
417 application->setIcon(QUrl("facebook"));
391 application->setStage(ApplicationInfo::SideStage);
418 application->setStage(ApplicationInfo::SideStage);
392− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
393 generateQmlStrings(application);
419 generateQmlStrings(application);
394 m_availableApplications.append(application);
420 m_availableApplications.append(application);
395
421
@@ -398,7 +424,6 @@ void ApplicationManager::buildListOfAvailableApplications()
398 application->setFullscreen(true);
424 application->setFullscreen(true);
399 application->setName("Browser");
425 application->setName("Browser");
400 application->setIcon(QUrl("browser"));
426 application->setIcon(QUrl("browser"));
401− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
402 generateQmlStrings(application);
427 generateQmlStrings(application);
403 m_availableApplications.append(application);
428 m_availableApplications.append(application);
404
429
@@ -407,7 +432,6 @@ void ApplicationManager::buildListOfAvailableApplications()
407 application->setName("Twitter");
432 application->setName("Twitter");
408 application->setIcon(QUrl("twitter"));
433 application->setIcon(QUrl("twitter"));
409 application->setStage(ApplicationInfo::SideStage);
434 application->setStage(ApplicationInfo::SideStage);
410− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
411 generateQmlStrings(application);
435 generateQmlStrings(application);
412 m_availableApplications.append(application);
436 m_availableApplications.append(application);
413
437
@@ -415,7 +439,6 @@ void ApplicationManager::buildListOfAvailableApplications()
415 application->setAppId("gmail-webapp");
439 application->setAppId("gmail-webapp");
416 application->setName("GMail");
440 application->setName("GMail");
417 application->setIcon(QUrl("gmail"));
441 application->setIcon(QUrl("gmail"));
418− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
419 m_availableApplications.append(application);
442 m_availableApplications.append(application);
420
443
421 application = new ApplicationInfo(this);
444 application = new ApplicationInfo(this);
@@ -423,7 +446,6 @@ void ApplicationManager::buildListOfAvailableApplications()
423 application->setName("Weather");
446 application->setName("Weather");
424 application->setIcon(QUrl("weather"));
447 application->setIcon(QUrl("weather"));
425 application->setStage(ApplicationInfo::SideStage);
448 application->setStage(ApplicationInfo::SideStage);
426− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
427 generateQmlStrings(application);
449 generateQmlStrings(application);
428 m_availableApplications.append(application);
450 m_availableApplications.append(application);
429
451
@@ -432,7 +454,6 @@ void ApplicationManager::buildListOfAvailableApplications()
432 application->setName("Notepad");
454 application->setName("Notepad");
433 application->setIcon(QUrl("notepad"));
455 application->setIcon(QUrl("notepad"));
434 application->setStage(ApplicationInfo::SideStage);
456 application->setStage(ApplicationInfo::SideStage);
435− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
436 m_availableApplications.append(application);
457 m_availableApplications.append(application);
437
458
438 application = new ApplicationInfo(this);
459 application = new ApplicationInfo(this);
@@ -440,7 +461,6 @@ void ApplicationManager::buildListOfAvailableApplications()
440 application->setName("Calendar");
461 application->setName("Calendar");
441 application->setIcon(QUrl("calendar"));
462 application->setIcon(QUrl("calendar"));
442 application->setStage(ApplicationInfo::SideStage);
463 application->setStage(ApplicationInfo::SideStage);
443− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
444 m_availableApplications.append(application);
464 m_availableApplications.append(application);
445
465
446 application = new ApplicationInfo(this);
466 application = new ApplicationInfo(this);
@@ -448,21 +468,18 @@ void ApplicationManager::buildListOfAvailableApplications()
448 application->setName("Media Player");
468 application->setName("Media Player");
449 application->setIcon(QUrl("mediaplayer-app"));
469 application->setIcon(QUrl("mediaplayer-app"));
450 application->setFullscreen(true);
470 application->setFullscreen(true);
451− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
452 m_availableApplications.append(application);
471 m_availableApplications.append(application);
453
472
454 application = new ApplicationInfo(this);
473 application = new ApplicationInfo(this);
455 application->setAppId("evernote");
474 application->setAppId("evernote");
456 application->setName("Evernote");
475 application->setName("Evernote");
457 application->setIcon(QUrl("evernote"));
476 application->setIcon(QUrl("evernote"));
458− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
459 m_availableApplications.append(application);
477 m_availableApplications.append(application);
460
478
461 application = new ApplicationInfo(this);
479 application = new ApplicationInfo(this);
462 application->setAppId("map");
480 application->setAppId("map");
463 application->setName("Map");
481 application->setName("Map");
464 application->setIcon(QUrl("map"));
482 application->setIcon(QUrl("map"));
465− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
466 generateQmlStrings(application);
483 generateQmlStrings(application);
467 m_availableApplications.append(application);
484 m_availableApplications.append(application);
468
485
@@ -470,28 +487,24 @@ void ApplicationManager::buildListOfAvailableApplications()
470 application->setAppId("pinterest");
487 application->setAppId("pinterest");
471 application->setName("Pinterest");
488 application->setName("Pinterest");
472 application->setIcon(QUrl("pinterest"));
489 application->setIcon(QUrl("pinterest"));
473− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
474 m_availableApplications.append(application);
490 m_availableApplications.append(application);
475
491
476 application = new ApplicationInfo(this);
492 application = new ApplicationInfo(this);
477 application->setAppId("soundcloud");
493 application->setAppId("soundcloud");
478 application->setName("SoundCloud");
494 application->setName("SoundCloud");
479 application->setIcon(QUrl("soundcloud"));
495 application->setIcon(QUrl("soundcloud"));
480− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
481 m_availableApplications.append(application);
496 m_availableApplications.append(application);
482
497
483 application = new ApplicationInfo(this);
498 application = new ApplicationInfo(this);
484 application->setAppId("wikipedia");
499 application->setAppId("wikipedia");
485 application->setName("Wikipedia");
500 application->setName("Wikipedia");
486 application->setIcon(QUrl("wikipedia"));
501 application->setIcon(QUrl("wikipedia"));
487− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
488 m_availableApplications.append(application);
502 m_availableApplications.append(application);
489
503
490 application = new ApplicationInfo(this);
504 application = new ApplicationInfo(this);
491 application->setAppId("youtube");
505 application->setAppId("youtube");
492 application->setName("YouTube");
506 application->setName("YouTube");
493 application->setIcon(QUrl("youtube"));
507 application->setIcon(QUrl("youtube"));
494− application->setScreenshot(QString("image://application/%1/%2").arg(application->appId()).arg(QDateTime::currentMSecsSinceEpoch()));
495 m_availableApplications.append(application);
508 m_availableApplications.append(application);
496}
509}
497
510
tests/mocks/Unity/Application/ApplicationManager.h+7−1
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2014 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -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+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 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2014 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -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