on bd9428e help sign in
172 lines 4.4 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 "Session.h"
18#include "ApplicationInfo.h"
19#include "SessionManager.h"
20#include "SurfaceManager.h"
22#include <QPainter>
23#include <QQmlEngine>
24#include <QTimer>
26Session::Session(const QString &name,
27 const QUrl& screenshot,
28 QObject *parent)
29 : QObject(parent)
30 , m_name(name)
31 , m_live(true)
32 , m_screenshot(screenshot)
33 , m_application(nullptr)
34 , m_surface(nullptr)
35 , m_parentSession(nullptr)
36 , m_children(new SessionModel(this))
38 qDebug() << "Session::Session() " << this->name();
40 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
43Session::~Session()
45 qDebug() << "Session::~Session() " << name();
47 QList<Session*> children(m_children->list());
48 for (Session* child : children) {
49 delete child;
50 }
51 if (m_parentSession) {
52 m_parentSession->removeChildSession(this);
53 }
54 if (m_application) {
55 m_application->setSession(nullptr);
56 }
57 delete m_surface;
58 delete m_children;
61void Session::release()
63 qDebug() << "Session::release " << name();
65 if (m_parentSession) {
66 m_parentSession->removeChildSession(this);
67 }
68 if (m_application) {
69 m_application->setSession(nullptr);
70 }
71 if (!parent()) {
72 deleteLater();
73 }
76void Session::setApplication(ApplicationInfo* application)
78 if (m_application == application)
79 return;
81 m_application = application;
84void Session::setSurface(MirSurfaceItem* surface)
86 qDebug() << "Session::setSurface - session=" << name() << "surface=" << surface;
87 if (m_surface == surface)
88 return;
90 if (m_surface) {
91 m_surface->setSession(nullptr);
92 m_surface->setParent(nullptr);
93 Q_EMIT m_surface->deregister();
94 }
96 m_surface = surface;
98 if (m_surface) {
99 m_surface->setSession(this);
100 m_surface->setParent(this);
101 SurfaceManager::singleton()->registerSurface(m_surface);
102 }
104 Q_EMIT surfaceChanged(m_surface);
107void Session::setScreenshot(const QUrl& screenshot)
109 if (screenshot != m_screenshot) {
110 m_screenshot = screenshot;
111 if (m_surface) {
112 m_surface->setScreenshot(m_screenshot);
113 }
114 }
117void Session::setLive(bool live)
119 if (m_live != live) {
120 m_live = live;
121 Q_EMIT liveChanged(m_live);
122 }
125void Session::setParentSession(Session* session)
127 if (m_parentSession == session || session == this)
128 return;
130 m_parentSession = session;
131 Q_EMIT parentSessionChanged(session);
134void Session::createSurface()
136 if (m_surface) return;
138 setSurface(SurfaceManager::singleton()->createSurface(name(),
139 MirSurfaceItem::Normal,
140 m_application && m_application->fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
141 m_screenshot));
144void Session::addChildSession(Session* session)
146 insertChildSession(m_children->rowCount(), session);
149void Session::insertChildSession(uint index, Session* session)
151 qDebug() << "Session::insertChildSession - " << session->name() << " to " << name() << " @ " << index;
153 session->setParentSession(this);
154 m_children->insert(index, session);
155 SessionManager::singleton()->registerSession(session);
158void Session::removeChildSession(Session* session)
160 qDebug() << "Session::removeChildSession - " << session->name() << " from " << name();
162 if (m_children->contains(session)) {
163 m_children->remove(session);
164 session->setParentSession(nullptr);
165 Q_EMIT session->deregister();
166 }
169SessionModel* Session::childSessions() const
171 return m_children;