on 2917119 help sign in
unity8/tests/mocks/Unity/Application/ApplicationTestInterface.cpp
99 lines 3.6 kB history raw
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 */
17#include "ApplicationInfo.h"
18#include "ApplicationTestInterface.h"
19#include "ApplicationManager.h"
20#include "SurfaceManager.h"
21#include "MirSurfaceItem.h"
22#include "MirSurfaceItemModel.h"
24quint32 nextId = 0;
26ApplicationTestInterface::ApplicationTestInterface(QObject* parent)
27 : QDBusAbstractAdaptor(parent)
29 QDBusConnection connection = QDBusConnection::sessionBus();
30 connection.registerService("com.canonical.Unity8");
31 connection.registerObject("/com/canonical/Unity8/Mocks", parent);
34quint32 ApplicationTestInterface::addPromptSurface(const QString &appId, const QString &surfaceImage)
36 qDebug() << "ApplicationTestInterface::addPromptSurface to " << appId;
38 ApplicationInfo* application = ApplicationManager::singleton()->findApplication(appId);
39 if (!application) {
40 qDebug() << "ApplicationTestInterface::addPromptSurface - No application found for " << appId;
41 return 0;
42 }
43 quint32 surfaceId = ++nextId;
44 MirSurfaceItem* surface = SurfaceManager::singleton()->createSurface(
45 QString("%1-Prompt%2").arg(appId)
46 .arg(surfaceId),
47 MirSurfaceItem::Normal,
48 MirSurfaceItem::Maximized,
49 QUrl(surfaceImage));
50 m_childItems[surfaceId] = surface;
51 application->addPromptSurface(surface);
53 return surfaceId;
56quint32 ApplicationTestInterface::addChildSurface(const QString& appId, const quint32 existingSurfaceId, const QString& surfaceImage)
58 qDebug() << "ApplicationTestInterface::addChildSurface to " << appId;
60 ApplicationInfo* application = ApplicationManager::singleton()->findApplication(appId);
61 if (!application) {
62 qDebug() << "ApplicationTestInterface::addChildSurface - No application found for " << appId;
63 return 0;
64 }
66 MirSurfaceItem* parentSurface = nullptr;
67 if (m_childItems.contains(existingSurfaceId)) {
68 parentSurface = m_childItems[existingSurfaceId];
69 } else if (application->surface()) {
70 parentSurface = application->surface();
71 } else {
72 qDebug() << "ApplicationTestInterface::addChildSurface - No surface for " << appId << ":" << existingSurfaceId;
73 return 0;
74 }
76 quint32 surfaceId = ++nextId;
77 MirSurfaceItem* surface = SurfaceManager::singleton()->createSurface(
78 QString("%1-Child%2").arg(parentSurface->name())
79 .arg(surfaceId),
80 MirSurfaceItem::Normal,
81 MirSurfaceItem::Maximized,
82 QUrl(surfaceImage));
83 parentSurface->addChildSurface(surface);
84 m_childItems[surfaceId] = surface;
86 return surfaceId;
89void ApplicationTestInterface::removeSurface(int surfaceId)
91 qDebug() << "ApplicationTestInterface::removeSurface - " << surfaceId;
93 if (!m_childItems.contains(surfaceId)) {
94 qDebug() << "ApplicationTestInterface::removeSurface - No added surface for " << surfaceId;
95 return;
96 }
97 MirSurfaceItem* surface = m_childItems.take(surfaceId);
98 Q_EMIT surface->removed();