on 3ebd113 help sign in
174 lines 4.3 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_children;
59 if (m_surface) {
60 if (m_surface->viewCount() == 0) {
61 delete m_surface;
62 } else {
63 m_surface->setLive(false);
64 }
65 }
68void Session::release()
70// qDebug() << "Session::release " << name();
71 deleteLater();
74void Session::setApplication(ApplicationInfo* application)
76 if (m_application == application)
77 return;
79 m_application = application;
80 Q_EMIT applicationChanged(application);
83void Session::setSurface(MirSurface* surface)
85// qDebug() << "Session::setSurface - session=" << name() << "surface=" << surface;
86 if (m_surface == surface)
87 return;
89 if (m_surface) {
90 disconnect(m_surface, nullptr, this, nullptr);
91 }
93 m_surface = surface;
95 if (m_surface) {
96 connect(m_surface, &QObject::destroyed, this, &Session::onSurfaceDestroyed);
97 }
99 Q_EMIT surfaceChanged(m_surface);
102void Session::onSurfaceDestroyed()
104 m_surface = nullptr;
105 Q_EMIT surfaceChanged(nullptr);
108void Session::setScreenshot(const QUrl& screenshot)
110 if (screenshot != m_screenshot) {
111 m_screenshot = screenshot;
112 if (m_surface) {
113 m_surface->setScreenshotUrl(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 Mir::NormalType,
141 m_application && m_application->fullscreen() ? Mir::FullscreenState :
142 Mir::MaximizedState,
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;