on xenial help sign in
drop all the unity-mir style code in MockApplicationManager.
f7f7063Michael Zanetti
tests/mocks/Unity/Application/ApplicationInfo.cpp−62
@@ -31,8 +31,6 @@ ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
31 , m_state(Starting)
31 , m_state(Starting)
32 , m_focused(false)
32 , m_focused(false)
33 , m_fullscreen(false)
33 , m_fullscreen(false)
34− , m_windowItem(0)
35− , m_windowComponent(0)
36 , m_parentItem(0)
34 , m_parentItem(0)
37 , m_surface(0)
35 , m_surface(0)
38{
36{
@@ -45,8 +43,6 @@ ApplicationInfo::ApplicationInfo(QObject *parent)
45 , m_state(Starting)
43 , m_state(Starting)
46 , m_focused(false)
44 , m_focused(false)
47 , m_fullscreen(false)
45 , m_fullscreen(false)
48− , m_windowItem(0)
49− , m_windowComponent(0)
50 , m_parentItem(0)
46 , m_parentItem(0)
51 , m_surface(0)
47 , m_surface(0)
52{
48{
@@ -61,12 +57,6 @@ ApplicationInfo::~ApplicationInfo()
61 }
57 }
62}
58}
63
59
64−void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status status)
65−{
66− if (status == QQmlComponent::Ready && !m_windowItem)
67− doCreateWindowItem();
68−}
69−
70void ApplicationInfo::onStateChanged(State state)
60void ApplicationInfo::onStateChanged(State state)
71{
61{
72 if (state == ApplicationInfo::Running) {
62 if (state == ApplicationInfo::Running) {
@@ -108,55 +98,3 @@ void ApplicationInfo::setSurface(MirSurfaceItem* surface)
108 Q_EMIT surfaceChanged(m_surface);
98 Q_EMIT surfaceChanged(m_surface);
109 SurfaceManager::singleton()->registerSurface(m_surface);
99 SurfaceManager::singleton()->registerSurface(m_surface);
110}
100}
111−
112−void ApplicationInfo::createWindowComponent()
113−{
114− // The assumptions I make here really should hold.
115− QQuickView *quickView =
116− qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
117−
118− QQmlEngine *engine = quickView->engine();
119−
120− m_windowComponent = new QQmlComponent(engine, this);
121− m_windowComponent->setData(m_windowQml.toLatin1(), QUrl());
122−}
123−
124−void ApplicationInfo::doCreateWindowItem()
125−{
126− m_windowItem = qobject_cast<QQuickItem *>(m_windowComponent->create());
127− m_windowItem->setParentItem(m_parentItem);
128−}
129−
130−void ApplicationInfo::createWindowItem()
131−{
132− if (!m_windowComponent)
133− createWindowComponent();
134−
135− // only create the windowItem once the component is ready
136− if (!m_windowComponent->isReady()) {
137− connect(m_windowComponent, &QQmlComponent::statusChanged,
138− this, &ApplicationInfo::onWindowComponentStatusChanged);
139− } else {
140− doCreateWindowItem();
141− }
142−}
143−
144−void ApplicationInfo::showWindow(QQuickItem *parent)
145−{
146− m_parentItem = parent;
147−
148− if (!m_windowItem)
149− createWindowItem();
150−
151− if (m_windowItem) {
152− m_windowItem->setVisible(true);
153− }
154−}
155−
156−void ApplicationInfo::hideWindow()
157−{
158− if (!m_windowItem)
159− return;
160−
161− m_windowItem->setVisible(false);
162−}
tests/mocks/Unity/Application/ApplicationInfo.h−10
@@ -88,22 +88,12 @@ public:
88Q_SIGNALS:
88Q_SIGNALS:
89 void surfaceChanged(MirSurfaceItem*);
89 void surfaceChanged(MirSurfaceItem*);
90
90
91−public:
92− void showWindow(QQuickItem *parent);
93− void hideWindow();
94−
95private Q_SLOTS:
91private Q_SLOTS:
96− void onWindowComponentStatusChanged(QQmlComponent::Status status);
97 void onStateChanged(State state);
92 void onStateChanged(State state);
98
93
99 void createSurface();
94 void createSurface();
100
95
101private:
96private:
102− void createWindowItem();
103− void doCreateWindowItem();
104− void createWindowComponent();
105− QQuickItem *m_windowItem;
106− QQmlComponent *m_windowComponent;
107 QQuickItem *m_parentItem;
97 QQuickItem *m_parentItem;
108 MirSurfaceItem* m_surface;
98 MirSurfaceItem* m_surface;
109};
99};
tests/mocks/Unity/Application/ApplicationManager.cpp−141
@@ -48,11 +48,6 @@ ApplicationManager *ApplicationManager::singleton()
48ApplicationManager::ApplicationManager(QObject *parent)
48ApplicationManager::ApplicationManager(QObject *parent)
49 : ApplicationManagerInterface(parent)
49 : ApplicationManagerInterface(parent)
50 , m_suspended(false)
50 , m_suspended(false)
51− , m_mainStageComponent(0)
52− , m_mainStage(0)
53− , m_sideStageComponent(0)
54− , m_sideStage(0)
55− , m_rightMargin(0)
56{
51{
57 m_roleNames.insert(RoleSurface, "surface");
52 m_roleNames.insert(RoleSurface, "surface");
58 m_roleNames.insert(RoleFullscreen, "fullscreen");
53 m_roleNames.insert(RoleFullscreen, "fullscreen");
@@ -300,39 +295,25 @@ bool ApplicationManager::focusApplication(const QString &appId)
300 for (ApplicationInfo *app : m_runningApplications) {
295 for (ApplicationInfo *app : m_runningApplications) {
301 if (app->focused() && app->stage() == ApplicationInfo::MainStage) {
296 if (app->focused() && app->stage() == ApplicationInfo::MainStage) {
302 app->setFocused(false);
297 app->setFocused(false);
303− app->hideWindow();
304 app->setState(ApplicationInfo::Suspended);
298 app->setState(ApplicationInfo::Suspended);
305 }
299 }
306 }
300 }
307
301
308 // focus this app
302 // focus this app
309 application->setFocused(true);
303 application->setFocused(true);
310− if (!m_mainStage)
311− createMainStage();
312 application->setState(ApplicationInfo::Running);
304 application->setState(ApplicationInfo::Running);
313− application->showWindow(m_mainStage);
314− m_mainStage->setZ(-1000);
315− if (m_sideStage)
316− m_sideStage->setZ(-2000);
317 } else if (application->stage() == ApplicationInfo::SideStage) {
305 } else if (application->stage() == ApplicationInfo::SideStage) {
318 // unfocus currently focused sidestage app
306 // unfocus currently focused sidestage app
319 for (ApplicationInfo *app : m_runningApplications) {
307 for (ApplicationInfo *app : m_runningApplications) {
320 if (app->focused() && app->stage() == ApplicationInfo::SideStage) {
308 if (app->focused() && app->stage() == ApplicationInfo::SideStage) {
321 app->setFocused(false);
309 app->setFocused(false);
322− app->hideWindow();
323 app->setState(ApplicationInfo::Suspended);
310 app->setState(ApplicationInfo::Suspended);
324 }
311 }
325 }
312 }
326
313
327 // focus this app
314 // focus this app
328 application->setFocused(true);
315 application->setFocused(true);
329− if (!m_sideStage)
330− createSideStage();
331 application->setState(ApplicationInfo::Running);
316 application->setState(ApplicationInfo::Running);
332− application->showWindow(m_sideStage);
333− m_sideStage->setZ(-1000);
334− if (m_mainStage)
335− m_mainStage->setZ(-2000);
336 }
317 }
337
318
338 // move app to top of stack
319 // move app to top of stack
@@ -354,7 +335,6 @@ void ApplicationManager::unfocusCurrentApplication()
354{
335{
355 for (ApplicationInfo *app : m_runningApplications) {
336 for (ApplicationInfo *app : m_runningApplications) {
356 if (app->focused()) {
337 if (app->focused()) {
357− app->hideWindow();
358 app->setFocused(false);
338 app->setFocused(false);
359 }
339 }
360 }
340 }
@@ -363,42 +343,6 @@ void ApplicationManager::unfocusCurrentApplication()
363
343
364void ApplicationManager::generateQmlStrings(ApplicationInfo *application)
344void ApplicationManager::generateQmlStrings(ApplicationInfo *application)
365{
345{
366− // TODO: Is there a better way of solving this fullscreen vs. regular
367− // application height?
368− QString topMargin;
369− if (application->fullscreen()) {
370− topMargin.append("0");
371− } else {
372− // Taken from Panel.panelHeight
373− topMargin.append("units.gu(3) + units.dp(2)");
374− }
375−
376− QString windowQml = QString(
377− "import QtQuick 2.0\n"
378− "Image {\n"
379− " anchors.fill: parent\n"
380− " anchors.topMargin: %1\n"
381− " anchors.rightMargin: %2\n"
382− " source: \"file://%3/Dash/graphics/phone/screenshots/%4.png\"\n"
383− " smooth: true\n"
384− " fillMode: Image.PreserveAspectCrop\n"
385− "}").arg(topMargin)
386− .arg(m_rightMargin)
387− .arg(qmlDirectory())
388− .arg(application->icon().toString());
389− application->setWindowQml(windowQml);
390−
391− QString imageQml = QString(
392− "import QtQuick 2.0\n"
393− "Image {\n"
394− " anchors.fill: parent\n"
395− " source: \"file://%1/Dash/graphics/phone/screenshots/%2.png\"\n"
396− " smooth: true\n"
397− " fillMode: Image.PreserveAspectCrop\n"
398− "}").arg(qmlDirectory())
399− .arg(application->icon().toString());
400− application->setImageQml(imageQml);
401−
402 application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png").arg(qmlDirectory())
346 application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png").arg(qmlDirectory())
403 .arg(application->icon().toString()));
347 .arg(application->icon().toString()));
404}
348}
@@ -535,78 +479,6 @@ void ApplicationManager::buildListOfAvailableApplications()
535 m_availableApplications.append(application);
479 m_availableApplications.append(application);
536}
480}
537
481
538−void ApplicationManager::createMainStageComponent()
539−{
540− // The assumptions I make here really should hold.
541− QQuickView *quickView =
542− qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
543−
544− QQmlEngine *engine = quickView->engine();
545−
546− m_mainStageComponent = new QQmlComponent(engine, this);
547− QString mainStageQml =
548− "import QtQuick 2.0\n"
549− "Rectangle {\n"
550− " anchors.fill: parent\n"
551− " color: 'black'\n"
552− " z: -2000\n"
553− "}\n";
554− m_mainStageComponent->setData(mainStageQml.toLatin1(), QUrl());
555−}
556−
557−void ApplicationManager::createMainStage()
558−{
559− if (!m_mainStageComponent)
560− createMainStageComponent();
561−
562− // The assumptions I make here really should hold.
563− QQuickView *quickView =
564− qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
565−
566− QQuickItem *shell = quickView->rootObject();
567−
568− m_mainStage = qobject_cast<QQuickItem *>(m_mainStageComponent->create());
569− m_mainStage->setParentItem(shell);
570−}
571−
572−void ApplicationManager::createSideStageComponent()
573−{
574− // The assumptions I make here really should hold.
575− QQuickView *quickView =
576− qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
577−
578− QQmlEngine *engine = quickView->engine();
579−
580− m_sideStageComponent = new QQmlComponent(engine, this);
581− QString sideStageQml =
582− "import QtQuick 2.0\n"
583− "import Ubuntu.Components 0.1\n"
584− "Item {\n"
585− " width: units.gu(40)\n" // from SideStage in Shell.qml
586− " anchors.top: parent.top\n"
587− " anchors.bottom: parent.bottom\n"
588− " anchors.right: parent.right\n"
589− " z: -1000\n"
590− "}\n";
591− m_sideStageComponent->setData(sideStageQml.toLatin1(), QUrl());
592−}
593−
594−void ApplicationManager::createSideStage()
595−{
596− if (!m_sideStageComponent)
597− createSideStageComponent();
598−
599− // The assumptions I make here really should hold.
600− QQuickView *quickView =
601− qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
602−
603− QQuickItem *shell = quickView->rootObject();
604−
605− m_sideStage = qobject_cast<QQuickItem *>(m_sideStageComponent->create());
606− m_sideStage->setParentItem(shell);
607− m_sideStage->setFlag(QQuickItem::ItemHasContents, false);
608−}
609−
610QStringList ApplicationManager::availableApplications()
482QStringList ApplicationManager::availableApplications()
611{
483{
612 QStringList appIds;
484 QStringList appIds;
@@ -616,19 +488,6 @@ QStringList ApplicationManager::availableApplications()
616 return appIds;
488 return appIds;
617}
489}
618
490
619−int ApplicationManager::rightMargin() const
620−{
621− return m_rightMargin;
622−}
623−
624−void ApplicationManager::setRightMargin(int rightMargin)
625−{
626− m_rightMargin = rightMargin;
627− Q_FOREACH(ApplicationInfo *app, m_availableApplications) {
628− generateQmlStrings(app);
629− }
630−}
631−
632bool ApplicationManager::isEmpty() const
491bool ApplicationManager::isEmpty() const
633{
492{
634 return m_runningApplications.isEmpty();
493 return m_runningApplications.isEmpty();
tests/mocks/Unity/Application/ApplicationManager.h−16
@@ -44,10 +44,6 @@ class ApplicationManager : public ApplicationManagerInterface {
44
44
45 Q_PROPERTY(bool fake READ fake CONSTANT)
45 Q_PROPERTY(bool fake READ fake CONSTANT)
46
46
47− // Only for testing
48− // This can be used to place some controls to right, like make tryPhoneStage for example
49− Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin)
50−
51 public:
47 public:
52 ApplicationManager(QObject *parent = NULL);
48 ApplicationManager(QObject *parent = NULL);
53 virtual ~ApplicationManager();
49 virtual ~ApplicationManager();
@@ -108,8 +104,6 @@ class ApplicationManager : public ApplicationManagerInterface {
108
104
109 // Only for testing
105 // Only for testing
110 Q_INVOKABLE QStringList availableApplications();
106 Q_INVOKABLE QStringList availableApplications();
111− int rightMargin() const;
112− void setRightMargin(int rightMargin);
113
107
114 QModelIndex findIndex(ApplicationInfo* application);
108 QModelIndex findIndex(ApplicationInfo* application);
115
109
@@ -126,19 +120,9 @@ class ApplicationManager : public ApplicationManagerInterface {
126 void showApplicationWindow(ApplicationInfo *application);
120 void showApplicationWindow(ApplicationInfo *application);
127 void buildListOfAvailableApplications();
121 void buildListOfAvailableApplications();
128 void generateQmlStrings(ApplicationInfo *application);
122 void generateQmlStrings(ApplicationInfo *application);
129− void createMainStageComponent();
130− void createMainStage();
131− void createSideStageComponent();
132− void createSideStage();
133 bool m_suspended;
123 bool m_suspended;
134 QList<ApplicationInfo*> m_runningApplications;
124 QList<ApplicationInfo*> m_runningApplications;
135 QList<ApplicationInfo*> m_availableApplications;
125 QList<ApplicationInfo*> m_availableApplications;
136− QQmlComponent *m_mainStageComponent;
137− QQuickItem *m_mainStage;
138− QQmlComponent *m_sideStageComponent;
139− QQuickItem *m_sideStage;
140−
141− int m_rightMargin;
142
126
143 static ApplicationManager *the_application_manager;
127 static ApplicationManager *the_application_manager;
144};
128};
tests/mocks/Unity/Application/ApplicationScreenshotProvider.cpp+1−1
@@ -64,7 +64,7 @@ QImage ApplicationScreenshotProvider::requestImage(const QString &imageId, QSize
64 Q_FOREACH (QWindow *win, unity->allWindows()) {
64 Q_FOREACH (QWindow *win, unity->allWindows()) {
65 QQuickWindow *quickWin = qobject_cast<QQuickWindow*>(win);
65 QQuickWindow *quickWin = qobject_cast<QQuickWindow*>(win);
66 if (quickWin) {
66 if (quickWin) {
67− image = image.scaledToWidth(quickWin->width() - m_appManager->rightMargin());
67+ image = image.scaledToWidth(quickWin->width());
68 break;
68 break;
69 }
69 }
70 }
70 }