on c1bec30 help sign in
unity8/tests/mocks/Unity/Application/ApplicationInfo.cpp
215 lines 5.7 kB history raw
1/*
2 * Copyright (C) 2013-2015 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 "Session.h"
19#include "SessionManager.h"
21#include <paths.h>
23#include <QGuiApplication>
24#include <QQuickItem>
25#include <QQuickView>
26#include <QQmlComponent>
27#include <QTimer>
29ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
30 : ApplicationInfoInterface(appId, parent)
31 , m_appId(appId)
32 , m_stage(MainStage)
33 , m_state(Starting)
34 , m_focused(false)
35 , m_fullscreen(false)
36 , m_session(0)
37 , m_supportedOrientations(Qt::PortraitOrientation |
38 Qt::LandscapeOrientation |
39 Qt::InvertedPortraitOrientation |
40 Qt::InvertedLandscapeOrientation)
41 , m_rotatesWindowContents(false)
42 , m_manualSurfaceCreation(false)
46ApplicationInfo::ApplicationInfo(QObject *parent)
47 : ApplicationInfoInterface(QString(), parent)
48 , m_stage(MainStage)
49 , m_state(Starting)
50 , m_focused(false)
51 , m_fullscreen(false)
52 , m_session(0)
53 , m_supportedOrientations(Qt::PortraitOrientation |
54 Qt::LandscapeOrientation |
55 Qt::InvertedPortraitOrientation |
56 Qt::InvertedLandscapeOrientation)
57 , m_rotatesWindowContents(false)
58 , m_manualSurfaceCreation(false)
62ApplicationInfo::~ApplicationInfo()
64 delete m_session;
67void ApplicationInfo::createSession()
69 if (m_session || state() == ApplicationInfo::Stopped) { return; }
71 QUrl screenshotUrl = QString("file://%1").arg(m_screenshotFileName);
72 setSession(SessionManager::singleton()->createSession(appId(), screenshotUrl));
75void ApplicationInfo::setSession(Session* session)
77 qDebug() << "Application::setSession - appId=" << appId() << "session=" << session;
78 if (m_session == session)
79 return;
81 if (m_session) {
82 disconnect(this, 0, m_session, 0);
83 m_session->setApplication(nullptr);
84 m_session->setParent(nullptr);
85 Q_EMIT m_session->deregister();
86 }
88 m_session = session;
90 if (m_session) {
91 m_session->setApplication(this);
92 m_session->setParent(this);
93 SessionManager::singleton()->registerSession(m_session);
95 if (!m_manualSurfaceCreation) {
96 QTimer::singleShot(500, m_session, SLOT(createSurface()));
97 }
98 }
100 Q_EMIT sessionChanged(m_session);
103void ApplicationInfo::setIconId(const QString &iconId)
105 setIcon(QString("file://%1/graphics/applicationIcons/%2@18.png")
106 .arg(qmlDirectory())
107 .arg(iconId));
110void ApplicationInfo::setScreenshotId(const QString &screenshotId)
112 QString screenshotFileName;
114 if (screenshotId.endsWith(".svg")) {
115 screenshotFileName = QString("%1/Dash/graphics/phone/screenshots/%2")
116 .arg(qmlDirectory())
117 .arg(screenshotId);
118 } else {
119 screenshotFileName = QString("%1/Dash/graphics/phone/screenshots/%2@12.png")
120 .arg(qmlDirectory())
121 .arg(screenshotId);
122 }
124 if (screenshotFileName != m_screenshotFileName) {
125 m_screenshotFileName = screenshotFileName;
127 QUrl screenshotUrl = QString("file://%1").arg(m_screenshotFileName);
128 if (m_session) {
129 m_session->setScreenshot(screenshotUrl);
130 }
131 }
134void ApplicationInfo::setName(const QString &value)
136 if (value != m_name) {
137 m_name = value;
138 Q_EMIT nameChanged(value);
139 }
142void ApplicationInfo::setIcon(const QUrl &value)
144 if (value != m_icon) {
145 m_icon = value;
146 Q_EMIT iconChanged(value);
147 }
150void ApplicationInfo::setStage(Stage value)
152 if (value != m_stage) {
153 m_stage = value;
154 Q_EMIT stageChanged(value);
155 }
158void ApplicationInfo::setState(State value)
160 if (value != m_state) {
161 m_state = value;
162 Q_EMIT stateChanged(value);
164 if (!m_manualSurfaceCreation && m_state == ApplicationInfo::Running) {
165 QTimer::singleShot(500, this, SLOT(createSession()));
166 } else if (m_state == ApplicationInfo::Stopped) {
167 delete m_session;
168 m_session = nullptr;
169 }
170 }
173void ApplicationInfo::setFocused(bool value)
175 if (value != m_focused) {
176 m_focused = value;
177 Q_EMIT focusedChanged(value);
178 }
181void ApplicationInfo::setFullscreen(bool value)
183 if (value != m_fullscreen) {
184 m_fullscreen = value;
185 Q_EMIT fullscreenChanged(value);
186 }
189void ApplicationInfo::setManualSurfaceCreation(bool value)
191 if (value != m_manualSurfaceCreation) {
192 m_manualSurfaceCreation = value;
193 Q_EMIT manualSurfaceCreationChanged(value);
194 }
197Qt::ScreenOrientations ApplicationInfo::supportedOrientations() const
199 return m_supportedOrientations;
202void ApplicationInfo::setSupportedOrientations(Qt::ScreenOrientations orientations)
204 m_supportedOrientations = orientations;
207bool ApplicationInfo::rotatesWindowContents() const
209 return m_rotatesWindowContents;
212void ApplicationInfo::setRotatesWindowContents(bool value)
214 m_rotatesWindowContents = value;