File indexing completed on 2024-04-28 15:29:09

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2006 Aaron Seigo <aseigo@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KDELIBS_KNOTIFICATIONRESTRICTIONS_H
0009 #define KDELIBS_KNOTIFICATIONRESTRICTIONS_H
0010 
0011 #include <knotifications_export.h>
0012 
0013 #include <QObject>
0014 
0015 #include <memory>
0016 
0017 /**
0018  * @class KNotificationRestrictions knotificationrestrictions.h KNotificationRestrictions
0019  *
0020  * KNotificationRestrictions provides a simple mechanism to avoid disruptions
0021  * during full screen presentations or other use cases where the screensaver or
0022  * desktop notifications are inappropriate.
0023  *
0024  * Using KNotificationRestrictions is quite straightforward: create an instance
0025  * of KNotificationRestrictions, passing in the set of or'd flags representing
0026  * the services that should be prevented from interrupting the user. When done
0027  * (for instance when the presentation is complete) simply delete the
0028  * KNotificationRestrictions object.
0029  *
0030  * Example: to ensure the screensaver does not turn on during a presentation:
0031  * @code
0032  * void MyApp::doPresentation()
0033  * {
0034  *   KNotificationRestrictions restrict(KNotificationRestrictions::ScreenSaver);
0035  *   // show presentation
0036  * }
0037  * @endcode
0038  */
0039 class KNOTIFICATIONS_EXPORT KNotificationRestrictions : public QObject
0040 {
0041     Q_OBJECT
0042 
0043 public:
0044     /**
0045      * @enum Service
0046      * @see Services
0047      */
0048     enum Service {
0049         /**
0050          * The baseline "don't disable anything" value.
0051          */
0052         NoServices = 0,
0053         /**
0054          * Causes the screensaver to be prevented from automatically
0055          * turning on.
0056          */
0057         ScreenSaver = 1,
0058         /**
0059          * Causes instant messaging and email notifications to not appear.
0060          *
0061          * @note <b>not implemented yet</b>
0062          */
0063         MessagingPopups = 2,
0064         /**
0065          * Causes non-critical desktop messages to be suppressed.
0066          *
0067          * @note <b>not implemented yet</b>
0068          */
0069         Notifications = 4,
0070         /**
0071          * Causes all desktop notifications, including critical ones
0072          * (such as as "battery low" warnings) to be suppressed.
0073          *
0074          * @note <b>not implemented yet</b>
0075          */
0076         CriticalNotifications = 8,
0077         NonCriticalServices = ScreenSaver | MessagingPopups | Notifications,
0078         AllServices = NonCriticalServices | CriticalNotifications,
0079     };
0080     /**
0081      * Stores a combination of #Service values.
0082      */
0083     Q_DECLARE_FLAGS(Services, Service)
0084 
0085     /**
0086      * Constructs a new service for restrict some services.
0087      *
0088      * @param control the services to be restricted
0089      * @param parent the parent of this object
0090      */
0091     explicit KNotificationRestrictions(Services control = NonCriticalServices, QObject *parent = nullptr);
0092     ~KNotificationRestrictions() override;
0093 
0094     /**
0095      * Constructs a new service for restrict some services.
0096      *
0097      * @param control the services to be restricted
0098      * @param reason the reason for restriction
0099      * @param parent the parent of this object
0100      */
0101     // TODO KF6 make reason optional
0102     explicit KNotificationRestrictions(Services control, const QString &reason, QObject *parent = nullptr);
0103 
0104 private:
0105     class Private;
0106     std::unique_ptr<Private> const d;
0107 
0108     Q_PRIVATE_SLOT(d, void screensaverFakeKeyEvent())
0109 };
0110 
0111 Q_DECLARE_OPERATORS_FOR_FLAGS(KNotificationRestrictions::Services)
0112 #endif