on 3ecd374 help sign in
unity8/tests/mocks/Unity/Application/ApplicationInfo.cpp
169 lines 4.2 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_manualSessionCreation(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_manualSessionCreation(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 }
77 m_session = session;
79 if (m_session) {
80 m_session->setApplication(this);
81 m_session->setParent(this);
82 }
84 Q_EMIT sessionChanged(m_session);
87void ApplicationInfo::setIconId(const QString &iconId)
89 setIcon(QString("file://%1/graphics/applicationIcons/%2@18.png")
90 .arg(qmlDirectory())
91 .arg(iconId));
94void ApplicationInfo::setScreenshotId(const QString &screenshotId)
96 QString screenshotFileName = QString("%1/Dash/graphics/phone/screenshots/%2@12.png")
97 .arg(qmlDirectory())
98 .arg(screenshotId);
100 if (screenshotFileName != m_screenshotFileName) {
101 m_screenshotFileName = screenshotFileName;
103 QUrl screenshotUrl = QString("file://%1").arg(m_screenshotFileName);
104 if (m_session) {
105 m_session->setScreenshot(screenshotUrl);
106 }
107 }
110void ApplicationInfo::setName(const QString &value)
112 if (value != m_name) {
113 m_name = value;
114 Q_EMIT nameChanged(value);
115 }
118void ApplicationInfo::setIcon(const QUrl &value)
120 if (value != m_icon) {
121 m_icon = value;
122 Q_EMIT iconChanged(value);
123 }
126void ApplicationInfo::setStage(Stage value)
128 if (value != m_stage) {
129 m_stage = value;
130 Q_EMIT stageChanged(value);
131 }
134void ApplicationInfo::setState(State value)
136 if (value != m_state) {
137 m_state = value;
138 Q_EMIT stateChanged(value);
140 if (!m_manualSessionCreation && m_state == ApplicationInfo::Running) {
142 QTimer::singleShot(500, this, SLOT(createSession()));
143 }
144 }
147void ApplicationInfo::setFocused(bool value)
149 if (value != m_focused) {
150 m_focused = value;
151 Q_EMIT focusedChanged(value);
152 }
155void ApplicationInfo::setFullscreen(bool value)
157 if (value != m_fullscreen) {
158 m_fullscreen = value;
159 Q_EMIT fullscreenChanged(value);
160 }
163void ApplicationInfo::setManualSessionCreation(bool value)
165 if (value != m_manualSessionCreation) {
166 m_manualSessionCreation = value;
167 Q_EMIT manualSessionCreationChanged(value);
168 }