File indexing completed on 2024-04-28 05:35:36

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     /**
0089      * ...And this one will always show the prompt with all options, irrespective
0090      * of whether it's ordinarily configured to appear or not
0091      */
0092     void requestLogoutPrompt();
0093 
0094     void suspend();
0095     void hybridSuspend();
0096     void hibernate();
0097     void suspendThenHibernate();
0098 
0099     void switchUser();
0100     void lock();
0101 
0102     void saveSession();
0103 
0104 Q_SIGNALS:
0105     void stateChanged();
0106     void canShutdownChanged();
0107     void canRebootChanged();
0108     void canLogoutChanged();
0109     void canSuspendChanged();
0110     void canHybridSuspendChanged();
0111     void canHibernateChanged();
0112     void canSuspendThenHibernateChanged();
0113     void canSwitchUserChanged();
0114     void canLockChanged();
0115     void canSaveSessionChanged();
0116 
0117     void aboutToSuspend();
0118     void resumingFromSuspend();
0119 
0120 private:
0121     void *d; // unused, just reserving the space in case we go ABI stable
0122 };