File indexing completed on 2024-04-28 16:54:32
0001 /* 0002 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "kworkspace_export.h" 0010 #include <QObject> 0011 0012 /** 0013 * Public facing API for SessionManagement 0014 */ 0015 class KWORKSPACE_EXPORT SessionManagement : public QObject 0016 { 0017 Q_OBJECT 0018 Q_PROPERTY(State state READ state NOTIFY stateChanged) 0019 0020 Q_PROPERTY(bool canShutdown READ canShutdown NOTIFY canShutdownChanged) 0021 Q_PROPERTY(bool canReboot READ canReboot NOTIFY canRebootChanged) 0022 Q_PROPERTY(bool canLogout READ canLogout NOTIFY canLogoutChanged) 0023 Q_PROPERTY(bool canSuspend READ canSuspend NOTIFY canSuspendChanged) 0024 Q_PROPERTY(bool canHibernate READ canHibernate NOTIFY canHibernateChanged) 0025 Q_PROPERTY(bool canSwitchUser READ canSwitchUser NOTIFY canSwitchUserChanged) 0026 Q_PROPERTY(bool canLock READ canLock NOTIFY canLockChanged) 0027 Q_PROPERTY(bool canSaveSession READ canSaveSession NOTIFY canSaveSessionChanged) 0028 0029 public: 0030 enum class State { 0031 /** 0032 * The backend is loading canXyz functions may not represent the true state 0033 */ 0034 Loading, 0035 /** 0036 * All loaded 0037 */ 0038 Ready, 0039 /** 0040 * Error creating a suitable backend, no actions will be available 0041 */ 0042 Error, 0043 }; 0044 Q_ENUM(State) 0045 0046 enum class ConfirmationMode { 0047 /** 0048 * Obey the user's confirmation setting. 0049 */ 0050 Default = -1, 0051 /** 0052 * Don't confirm, shutdown without asking. 0053 */ 0054 Skip = 0, 0055 /** 0056 * Always confirm, ask even if the user turned it off. 0057 */ 0058 ForcePrompt = 1, 0059 }; 0060 Q_ENUM(ConfirmationMode) 0061 0062 SessionManagement(QObject *parent = nullptr); 0063 ~SessionManagement() override = default; 0064 0065 State state() const; 0066 0067 bool canShutdown() const; 0068 bool canReboot() const; 0069 bool canLogout() const; 0070 bool canSuspend() const; 0071 bool canHybridSuspend() const; 0072 bool canHibernate() const; 0073 bool canSwitchUser() const; 0074 bool canLock() const; 0075 bool canSaveSession() const; 0076 0077 public Q_SLOTS: 0078 /** 0079 * These requestX methods will either launch a prompt to shutdown or 0080 * The user may cancel it at any point in the process 0081 */ 0082 void requestShutdown(ConfirmationMode = ConfirmationMode::Default); 0083 void requestReboot(ConfirmationMode = ConfirmationMode::Default); 0084 void requestLogout(ConfirmationMode = ConfirmationMode::Default); 0085 0086 void suspend(); 0087 void hybridSuspend(); 0088 void hibernate(); 0089 0090 void switchUser(); 0091 void lock(); 0092 0093 void saveSession(); 0094 0095 Q_SIGNALS: 0096 void stateChanged(); 0097 void canShutdownChanged(); 0098 void canRebootChanged(); 0099 void canLogoutChanged(); 0100 void canSuspendChanged(); 0101 void canHybridSuspendChanged(); 0102 void canHibernateChanged(); 0103 void canSwitchUserChanged(); 0104 void canLockChanged(); 0105 void canSaveSessionChanged(); 0106 0107 void aboutToSuspend(); 0108 void resumingFromSuspend(); 0109 0110 private: 0111 void *d; // unused, just reserving the space in case we go ABI stable 0112 };