File indexing completed on 2024-05-12 09:40:42

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 canSuspendThenHibernate READ canSuspendThenHibernate NOTIFY canSuspendThenHibernateChanged)
0026     Q_PROPERTY(bool canSwitchUser READ canSwitchUser NOTIFY canSwitchUserChanged)
0027     Q_PROPERTY(bool canLock READ canLock NOTIFY canLockChanged)
0028     Q_PROPERTY(bool canSaveSession READ canSaveSession NOTIFY canSaveSessionChanged)
0029 
0030 public:
0031     enum class State {
0032         /**
0033          * The backend is loading canXyz functions may not represent the true state
0034          */
0035         Loading,
0036         /**
0037          * All loaded
0038          */
0039         Ready,
0040         /**
0041          * Error creating a suitable backend, no actions will be available
0042          */
0043         Error,
0044     };
0045     Q_ENUM(State)
0046 
0047     enum class ConfirmationMode {
0048         /**
0049          * Obey the user's confirmation setting.
0050          */
0051         Default = -1,
0052         /**
0053          * Don't confirm, shutdown without asking.
0054          */
0055         Skip = 0,
0056         /**
0057          * Always confirm, ask even if the user turned it off.
0058          */
0059         ForcePrompt = 1,
0060     };
0061     Q_ENUM(ConfirmationMode)
0062 
0063     SessionManagement(QObject *parent = nullptr);
0064     ~SessionManagement() override = default;
0065 
0066     State state() const;
0067 
0068     bool canShutdown() const;
0069     bool canReboot() const;
0070     bool canLogout() const;
0071     bool canSuspend() const;
0072     bool canHybridSuspend() const;
0073     bool canHibernate() const;
0074     bool canSuspendThenHibernate() const;
0075     bool canSwitchUser() const;
0076     bool canLock() const;
0077     bool canSaveSession() const;
0078 
0079 public Q_SLOTS:
0080     /**
0081      * These requestX methods will either launch a prompt to shutdown or
0082      * The user may cancel it at any point in the process
0083      */
0084     void requestShutdown(ConfirmationMode = ConfirmationMode::Default);
0085     void requestReboot(ConfirmationMode = ConfirmationMode::Default);
0086     void requestLogout(ConfirmationMode = ConfirmationMode::Default);
0087 
0088     void suspend();
0089     void hybridSuspend();
0090     void hibernate();
0091     void suspendThenHibernate();
0092 
0093     void switchUser();
0094     void lock();
0095 
0096     void saveSession();
0097 
0098 Q_SIGNALS:
0099     void stateChanged();
0100     void canShutdownChanged();
0101     void canRebootChanged();
0102     void canLogoutChanged();
0103     void canSuspendChanged();
0104     void canHybridSuspendChanged();
0105     void canHibernateChanged();
0106     void canSuspendThenHibernateChanged();
0107     void canSwitchUserChanged();
0108     void canLockChanged();
0109     void canSaveSessionChanged();
0110 
0111     void aboutToSuspend();
0112     void resumingFromSuspend();
0113 
0114 private:
0115     void *d; // unused, just reserving the space in case we go ABI stable
0116 };