summaryrefslogtreecommitdiffstats
path: root/src/modules/Unity/Application/session.h
blob: f80d36e4cba0f940e8271bd5028c7845fbfaf980 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Copyright (C) 2014-2015 Canonical, Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License version 3, as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SESSION_H
#define SESSION_H

// std
#include <memory>

// local
#include "session_interface.h"

// Qt
#include <QObject>
#include <QTimer>


namespace mir {
    namespace scene {
        class PromptSessionManager;
    }
}

namespace qtmir {

class Application;

class Session : public SessionInterface
{
    Q_OBJECT
public:
    explicit Session(const std::shared_ptr<mir::scene::Session>& session,
                     const std::shared_ptr<mir::scene::PromptSessionManager>& promptSessionManager,
                     QObject *parent = 0);
    virtual ~Session();

    Q_INVOKABLE void release() override;

    //getters
    QString name() const override;
    unity::shell::application::ApplicationInfoInterface* application() const override;
    MirSurfaceItemInterface* surface() const override;
    SessionInterface* parentSession() const override;
    State state() const override;
    bool fullscreen() const override;
    bool live() const override;

    void setApplication(unity::shell::application::ApplicationInfoInterface* item) override;
    void setSurface(MirSurfaceItemInterface* surface) override;

    void suspend() override;
    void resume() override;
    void stop() override;

    void addChildSession(SessionInterface* session) override;
    void insertChildSession(uint index, SessionInterface* session) override;
    void removeChildSession(SessionInterface* session) override;
    void foreachChildSession(std::function<void(SessionInterface* session)> f) const override;

    std::shared_ptr<mir::scene::Session> session() const override;

    std::shared_ptr<mir::scene::PromptSession> activePromptSession() const override;
    void foreachPromptSession(std::function<void(const std::shared_ptr<mir::scene::PromptSession>&)> f) const override;

    SessionModel* childSessions() const override;

    void setFullscreen(bool fullscreen) override;
    void setLive(const bool) override;
    void appendPromptSession(const std::shared_ptr<mir::scene::PromptSession>& session) override;
    void removePromptSession(const std::shared_ptr<mir::scene::PromptSession>& session) override;

public Q_SLOTS:
    // it's public to ease testing
    void doSuspend();

private Q_SLOTS:
    void updateFullscreenProperty();
    void onFirstSurfaceFrameDrawn();

private:
    void setParentSession(Session* session);
    void setState(State state);
    void doResume();

    void stopPromptSessions();

    std::shared_ptr<mir::scene::Session> m_session;
    Application* m_application;
    MirSurfaceItemInterface* m_surface;
    SessionInterface* m_parentSession;
    SessionModel* m_children;
    bool m_fullscreen;
    State m_state;
    bool m_live;
    QTimer* m_suspendTimer;
    QList<std::shared_ptr<mir::scene::PromptSession>> m_promptSessions;
    std::shared_ptr<mir::scene::PromptSessionManager> const m_promptSessionManager;
};

} // namespace qtmir

#endif // SESSION_H