on daa5708 help sign in
unity8/tests/mocks/Unity/Application/ApplicationInfo.cpp
174 lines 4.4 kB history raw
1/*
2 * Copyright (C) 2013-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 "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_manualSurfaceCreation(false)
41ApplicationInfo::ApplicationInfo(QObject *parent)
42 : ApplicationInfoInterface(QString(), parent)
43 , m_stage(MainStage)
44 , m_state(Starting)
45 , m_focused(false)
46 , m_fullscreen(false)
47 , m_session(0)
48 , m_manualSurfaceCreation(false)
52ApplicationInfo::~ApplicationInfo()
54 delete m_session;
57void ApplicationInfo::createSession()
59 if (m_session || state() == ApplicationInfo::Stopped) { return; }
61 QUrl screenshotUrl = QString("file://%1").arg(m_screenshotFileName);
62 setSession(SessionManager::singleton()->createSession(appId(), screenshotUrl));
65void ApplicationInfo::setSession(Session* session)
67 qDebug() << "Application::setSession - appId=" << appId() << "session=" << session;
68 if (m_session == session)
69 return;
71 if (m_session) {
72 disconnect(this, 0, m_session, 0);
73 m_session->setApplication(nullptr);
74 m_session->setParent(nullptr);
75 Q_EMIT m_session->deregister();
76 }
78 m_session = session;
80 if (m_session) {
81 m_session->setApplication(this);
82 m_session->setParent(this);
83 SessionManager::singleton()->registerSession(m_session);
85 if (!m_manualSurfaceCreation) {
86 QTimer::singleShot(500, m_session, SLOT(createSurface()));
87 }
88 }
90 Q_EMIT sessionChanged(m_session);
93void ApplicationInfo::setIconId(const QString &iconId)
95 setIcon(QString("file://%1/graphics/applicationIcons/%2@18.png")
96 .arg(qmlDirectory())
97 .arg(iconId));
100void ApplicationInfo::setScreenshotId(const QString &screenshotId)
102 QString screenshotFileName = QString("%1/Dash/graphics/phone/screenshots/%2@12.png")
103 .arg(qmlDirectory())
104 .arg(screenshotId);
106 if (screenshotFileName != m_screenshotFileName) {
107 m_screenshotFileName = screenshotFileName;
109 QUrl screenshotUrl = QString("file://%1").arg(m_screenshotFileName);
110 if (m_session) {
111 m_session->setScreenshot(screenshotUrl);
112 }
113 }
116void ApplicationInfo::setName(const QString &value)
118 if (value != m_name) {
119 m_name = value;
120 Q_EMIT nameChanged(value);
121 }
124void ApplicationInfo::setIcon(const QUrl &value)
126 if (value != m_icon) {
127 m_icon = value;
128 Q_EMIT iconChanged(value);
129 }
132void ApplicationInfo::setStage(Stage value)
134 if (value != m_stage) {
135 m_stage = value;
136 Q_EMIT stageChanged(value);
137 }
140void ApplicationInfo::setState(State value)
142 if (value != m_state) {
143 m_state = value;
144 Q_EMIT stateChanged(value);
146 if (!m_manualSurfaceCreation && m_state == ApplicationInfo::Running) {
147 QTimer::singleShot(500, this, SLOT(createSession()));
148 }
149 }
152void ApplicationInfo::setFocused(bool value)
154 if (value != m_focused) {
155 m_focused = value;
156 Q_EMIT focusedChanged(value);
157 }
160void ApplicationInfo::setFullscreen(bool value)
162 if (value != m_fullscreen) {
163 m_fullscreen = value;
164 Q_EMIT fullscreenChanged(value);
165 }
168void ApplicationInfo::setManualSurfaceCreation(bool value)
170 if (value != m_manualSurfaceCreation) {
171 m_manualSurfaceCreation = value;
172 Q_EMIT manualSurfaceCreationChanged(value);
173 }