Plasma-workspace

sessionmanagement.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 "kworkspace_export.h"
10#include <QObject>
11
12/**
13 * Public facing API for SessionManagement
14 */
15class KWORKSPACE_EXPORT SessionManagement : public QObject
16{
17 Q_OBJECT
18 Q_PROPERTY(State state READ state NOTIFY stateChanged)
19
20 Q_PROPERTY(bool canShutdown READ canShutdown NOTIFY canShutdownChanged)
21 Q_PROPERTY(bool canReboot READ canReboot NOTIFY canRebootChanged)
22 Q_PROPERTY(bool canLogout READ canLogout NOTIFY canLogoutChanged)
23 Q_PROPERTY(bool canSuspend READ canSuspend NOTIFY canSuspendChanged)
24 Q_PROPERTY(bool canHibernate READ canHibernate NOTIFY canHibernateChanged)
25 Q_PROPERTY(bool canSuspendThenHibernate READ canSuspendThenHibernate NOTIFY canSuspendThenHibernateChanged)
26 Q_PROPERTY(bool canSwitchUser READ canSwitchUser NOTIFY canSwitchUserChanged)
27 Q_PROPERTY(bool canLock READ canLock NOTIFY canLockChanged)
28 Q_PROPERTY(bool canSaveSession READ canSaveSession NOTIFY canSaveSessionChanged)
29
30public:
31 enum class State {
32 /**
33 * The backend is loading canXyz functions may not represent the true state
34 */
35 Loading,
36 /**
37 * All loaded
38 */
39 Ready,
40 /**
41 * Error creating a suitable backend, no actions will be available
42 */
43 Error,
44 };
46
47 enum class ConfirmationMode {
48 /**
49 * Obey the user's confirmation setting.
50 */
51 Default = -1,
52 /**
53 * Don't confirm, shutdown without asking.
54 */
55 Skip = 0,
56 /**
57 * Always confirm, ask even if the user turned it off.
58 */
59 ForcePrompt = 1,
60 };
61 Q_ENUM(ConfirmationMode)
62
63 explicit SessionManagement(QObject *parent = nullptr);
64 ~SessionManagement() override = default;
65
66 State state() const;
67
68 bool canShutdown() const;
69 bool canReboot() const;
70 bool canLogout() const;
71 bool canSuspend() const;
72 bool canHybridSuspend() const;
73 bool canHibernate() const;
74 bool canSuspendThenHibernate() const;
75 bool canSwitchUser() const;
76 bool canLock() const;
77 bool canSaveSession() const;
78
79public Q_SLOTS:
80 /**
81 * These requestX methods will either launch a prompt to shutdown or
82 * The user may cancel it at any point in the process
83 */
84 void requestShutdown(ConfirmationMode = ConfirmationMode::Default);
85 void requestReboot(ConfirmationMode = ConfirmationMode::Default);
86 void requestLogout(ConfirmationMode = ConfirmationMode::Default);
87
88 /**
89 * ...And this one will always show the prompt with all options, irrespective
90 * of whether it's ordinarily configured to appear or not
91 */
92 void requestLogoutPrompt();
93
94 void suspend();
95 void hybridSuspend();
96 void hibernate();
97 void suspendThenHibernate();
98
99 void switchUser();
100 void lock();
101
102 void saveSession();
103
105 void stateChanged();
106 void canShutdownChanged();
107 void canRebootChanged();
108 void canLogoutChanged();
109 void canSuspendChanged();
110 void canHybridSuspendChanged();
111 void canHibernateChanged();
112 void canSuspendThenHibernateChanged();
113 void canSwitchUserChanged();
114 void canLockChanged();
115 void canSaveSessionChanged();
116
117 void aboutToSuspend();
118 void resumingFromSuspend();
119
120private:
121 void *d; // unused, just reserving the space in case we go ABI stable
122};
Public facing API for SessionManagement.
void suspend()
Q_ENUM(...)
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.