Plasma-workspace

sessionmanagementbackend.h
1/*
2 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <KConfigWatcher>
10#include <QObject>
11
12#include "kworkspace_export.h"
13#include "sessionmanagement.h"
14
15class OrgFreedesktopLogin1ManagerInterface;
16
17/**
18 * Performs direct system actions that could kill the session
19 *
20 * Semi-internal. Symbols exported, but not the header
21 * To be used only by the daemon that performs logout (currently ksmserver)
22 *
23 * All other users should go via the public SessionManagement that prompts and logs out properly.
24 */
25class KWORKSPACE_EXPORT SessionBackend : public QObject
26{
27 Q_OBJECT
28public:
29 static SessionBackend *self();
30 virtual SessionManagement::State state() const = 0;
31
32 virtual void shutdown() = 0;
33 virtual void reboot() = 0;
34 virtual void suspend() = 0;
35 virtual void hybridSuspend() = 0;
36 virtual void hibernate() = 0;
37 virtual void suspendThenHibernate() = 0;
38
39 virtual bool canShutdown() const = 0;
40 virtual bool canReboot() const = 0;
41 virtual bool canSuspend() const = 0;
42 virtual bool canHybridSuspend() const = 0;
43 virtual bool canHibernate() const = 0;
44 virtual bool canSuspendThenHibernate() const = 0;
45
46 virtual bool canSwitchUser() const;
47
48 bool confirmLogout() const;
49
51 void stateChanged();
52 void canShutdownChanged();
53 void canRebootChanged();
54 void canSuspendChanged();
55 void canHybridSuspendChanged();
56 void canHibernateChanged();
57 void canSuspendThenHibernateChanged();
58
59 void aboutToSuspend();
60 void resumingFromSuspend();
61
62protected:
64 ~SessionBackend() override = default;
65
66private:
67 KConfigWatcher::Ptr m_kserverConfig;
68};
69
70/*
71 * This class wraps both Logind and CK2
72 * Abstraction for that is handled in OrgFreedesktopLogin1ManagerInterface
73 */
74class LogindSessionBackend : public SessionBackend
75{
77public:
78 static bool exists();
79 LogindSessionBackend();
80
81 SessionManagement::State state() const override;
82 void shutdown() override;
83 void reboot() override;
84 void suspend() override;
85 void hybridSuspend() override;
86 void hibernate() override;
87 void suspendThenHibernate() override;
88 bool canShutdown() const override;
89 bool canReboot() const override;
90 bool canSuspend() const override;
91 bool canHybridSuspend() const override;
92 bool canHibernate() const override;
93 bool canSuspendThenHibernate() const override;
94 bool canSwitchUser() const override;
95
96private:
97 OrgFreedesktopLogin1ManagerInterface *m_login1;
99 bool m_canShutdown = false;
100 bool m_canReboot = false;
101 bool m_canSuspend = false;
102 bool m_canHybridSuspend = false;
103 bool m_canHibernate = false;
104 bool m_canSuspendThenHibernate = false;
105 uint m_pendingJobs = 0;
106};
107
108class DummySessionBackend : public SessionBackend
109{
111public:
112 DummySessionBackend();
113
114 SessionManagement::State state() const override
115 {
117 }
118 void shutdown() override
119 {
120 }
121 void reboot() override
122 {
123 }
124 void suspend() override
125 {
126 }
127 void hybridSuspend() override
128 {
129 }
130 void hibernate() override
131 {
132 }
133 void suspendThenHibernate() override
134 {
135 }
136 bool canShutdown() const override
137 {
138 return false;
139 }
140 bool canReboot() const override
141 {
142 return false;
143 }
144 bool canSuspend() const override
145 {
146 return false;
147 }
148 bool canHybridSuspend() const override
149 {
150 return false;
151 }
152 bool canHibernate() const override
153 {
154 return false;
155 }
156 bool canSuspendThenHibernate() const override
157 {
158 return false;
159 }
160};
161
162class TestSessionBackend : public SessionBackend
163{
165public:
166 TestSessionBackend();
167
168 SessionManagement::State state() const override
169 {
171 }
172 void shutdown() override;
173 void reboot() override;
174 void suspend() override;
175 void hybridSuspend() override;
176 void hibernate() override;
177 void suspendThenHibernate() override;
178
179 bool canShutdown() const override
180 {
181 return true;
182 }
183 bool canReboot() const override
184 {
185 return true;
186 }
187 bool canSuspend() const override
188 {
189 return true;
190 }
191 bool canHybridSuspend() const override
192 {
193 return true;
194 }
195 bool canHibernate() const override
196 {
197 return true;
198 }
199 bool canSuspendThenHibernate() const override
200 {
201 return true;
202 }
203};
Performs direct system actions that could kill the session.
@ Loading
The backend is loading canXyz functions may not represent the true state.
@ Error
Error creating a suitable backend, no actions will be available.
void suspend()
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.