on f621663 help sign in
174 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;
82 Q_EMIT applicationChanged(application);
85void Session::setSurface(MirSurfaceItem* surface)
87 qDebug() << "Session::setSurface - session=" << name() << "surface=" << surface;
88 if (m_surface == surface)
89 return;
91 if (m_surface) {
92 m_surface->setSession(nullptr);
93 m_surface->setParent(nullptr);
94 Q_EMIT m_surface->deregister();
95 }
97 m_surface = surface;
99 if (m_surface) {
100 m_surface->setSession(this);
101 m_surface->setParent(this);
102 SurfaceManager::singleton()->registerSurface(m_surface);
103 }
105 Q_EMIT surfaceChanged(m_surface);
108void Session::setScreenshot(const QUrl& screenshot)
110 if (screenshot != m_screenshot) {
111 m_screenshot = screenshot;
112 if (m_surface) {
113 m_surface->setScreenshot(m_screenshot);
114 }
115 }
118void Session::setLive(bool live)
120 if (m_live != live) {
121 m_live = live;
122 Q_EMIT liveChanged(m_live);
123 }
126void Session::setParentSession(Session* session)
128 if (m_parentSession == session || session == this)
129 return;
131 m_parentSession = session;
132 Q_EMIT parentSessionChanged(session);
135void Session::createSurface()
137 if (m_surface) return;
139 setSurface(SurfaceManager::singleton()->createSurface(name(),
140 MirSurfaceItem::Normal,
141 m_application && m_application->fullscreen() ? MirSurfaceItem::Fullscreen :
142 MirSurfaceItem::Maximized,
143 m_screenshot));
146void Session::addChildSession(Session* session)
148 insertChildSession(m_children->rowCount(), session);
151void Session::insertChildSession(uint index, Session* session)
153 qDebug() << "Session::insertChildSession - " << session->name() << " to " << name() << " @ " << index;
155 session->setParentSession(this);
156 m_children->insert(index, session);
157 SessionManager::singleton()->registerSession(session);
160void Session::removeChildSession(Session* session)
162 qDebug() << "Session::removeChildSession - " << session->name() << " from " << name();
164 if (m_children->contains(session)) {
165 m_children->remove(session);
166 session->setParentSession(nullptr);
167 Q_EMIT session->deregister();
168 }
171SessionModel* Session::childSessions() const
173 return m_children;