File indexing completed on 2024-05-05 05:38:32
0001 /* 0002 SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@privat.broulik.de> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #pragma once 0008 0009 #include <QObject> 0010 0011 #include <KSharedConfig> 0012 0013 #include <QDateTime> 0014 #include <QString> 0015 #include <memory> 0016 0017 #include <qqmlregistration.h> 0018 0019 #include "notificationmanager_export.h" 0020 0021 namespace NotificationManager 0022 { 0023 /** 0024 * @short Notification settings and state 0025 * 0026 * This class encapsulates all global settings related to notifications 0027 * as well as do not disturb mode and other state. 0028 * 0029 * This class can be used by applications to alter their behavior 0030 * depending on user's notification preferences. 0031 * 0032 * @author Kai Uwe Broulik <kde@privat.broulik.de> 0033 **/ 0034 class NOTIFICATIONMANAGER_EXPORT Settings : public QObject 0035 { 0036 Q_OBJECT 0037 QML_ELEMENT 0038 0039 /** 0040 * Whether to show critical notification popups in do not disturb mode. 0041 */ 0042 Q_PROPERTY(bool criticalPopupsInDoNotDisturbMode READ criticalPopupsInDoNotDisturbMode WRITE setCriticalPopupsInDoNotDisturbMode NOTIFY settingsChanged) 0043 /** 0044 * Whether to keep normal notifications always on top. 0045 */ 0046 Q_PROPERTY(bool keepNormalAlwaysOnTop READ keepNormalAlwaysOnTop WRITE setKeepNormalAlwaysOnTop NOTIFY settingsChanged) 0047 /** 0048 * Whether to show popups for low priority notifications. 0049 */ 0050 Q_PROPERTY(bool lowPriorityPopups READ lowPriorityPopups WRITE setLowPriorityPopups NOTIFY settingsChanged) 0051 /** 0052 * Whether to add low priority notifications to the history. 0053 */ 0054 Q_PROPERTY(bool lowPriorityHistory READ lowPriorityHistory WRITE setLowPriorityHistory NOTIFY settingsChanged) 0055 0056 /** 0057 * The notification popup position on screen. 0058 * CloseToWidget means they should be positioned closely to where the plasmoid is located on screen. 0059 */ 0060 Q_PROPERTY(PopupPosition popupPosition READ popupPosition WRITE setPopupPosition NOTIFY settingsChanged) 0061 0062 /** 0063 * The default timeout for notification popups that do not have an explicit timeout set, 0064 * in milliseconds. Default is 5000ms (5 seconds). 0065 */ 0066 Q_PROPERTY(int popupTimeout READ popupTimeout WRITE setPopupTimeout RESET resetPopupTimeout NOTIFY settingsChanged) 0067 0068 /** 0069 * Whether to show application jobs as notifications 0070 */ 0071 Q_PROPERTY(bool jobsInNotifications READ jobsInNotifications WRITE setJobsInNotifications /*RESET resetJobsPopup*/ NOTIFY settingsChanged) 0072 /** 0073 * Whether application jobs stay visible for the whole duration of the job 0074 */ 0075 Q_PROPERTY(bool permanentJobPopups READ permanentJobPopups WRITE setPermanentJobPopups /*RESET resetAutoHideJobsPopup*/ NOTIFY settingsChanged) 0076 0077 /** 0078 * Whether to show notification badges (numbers in circles) in task manager 0079 */ 0080 Q_PROPERTY(bool badgesInTaskManager READ badgesInTaskManager WRITE setBadgesInTaskManager NOTIFY settingsChanged) 0081 0082 /** 0083 * A list of desktop entries of applications that have been seen sending a notification. 0084 */ 0085 Q_PROPERTY(QStringList knownApplications READ knownApplications NOTIFY knownApplicationsChanged) 0086 0087 /** 0088 * A list of desktop entries of applications for which no popups should be shown. 0089 */ 0090 Q_PROPERTY(QStringList popupBlacklistedApplications READ popupBlacklistedApplications NOTIFY settingsChanged) 0091 /** 0092 * A list of notifyrc names of services for which no popups should be shown. 0093 */ 0094 Q_PROPERTY(QStringList popupBlacklistedServices READ popupBlacklistedServices NOTIFY settingsChanged) 0095 0096 /** 0097 * A list of desktop entries of applications for which a popup should be shown even in do not disturb mode. 0098 */ 0099 Q_PROPERTY(QStringList doNotDisturbPopupWhitelistedApplications READ doNotDisturbPopupWhitelistedApplications NOTIFY settingsChanged) 0100 /** 0101 * A list of notifyrc names of services for which a popup should be shown even in do not disturb mode. 0102 */ 0103 Q_PROPERTY(QStringList doNotDisturbPopupWhitelistedServices READ doNotDisturbPopupWhitelistedServices NOTIFY settingsChanged) 0104 0105 /** 0106 * A list of desktop entries of applications which shouldn't be shown in the history. 0107 */ 0108 Q_PROPERTY(QStringList historyBlacklistedApplications READ historyBlacklistedApplications NOTIFY settingsChanged) 0109 /** 0110 * A list of notifyrc names of services which shouldn't be shown in the history. 0111 */ 0112 Q_PROPERTY(QStringList historyBlacklistedServices READ historyBlacklistedServices NOTIFY settingsChanged) 0113 0114 /** 0115 * A list of desktop entries of applications which shouldn't show badges in task manager. 0116 */ 0117 Q_PROPERTY(QStringList badgeBlacklistedApplications READ badgeBlacklistedApplications NOTIFY settingsChanged) 0118 0119 /** 0120 * The date until which do not disturb mode is enabled. 0121 * 0122 * When invalid or in the past, do not disturb mode should be considered disabled. 0123 * Do not disturb mode is considered active when this property points to a date 0124 * in the future OR notificationsInhibitedByApplication is true. 0125 */ 0126 Q_PROPERTY(QDateTime notificationsInhibitedUntil READ notificationsInhibitedUntil WRITE setNotificationsInhibitedUntil RESET 0127 resetNotificationsInhibitedUntil NOTIFY settingsChanged) 0128 0129 /** 0130 * Whether an application currently requested do not disturb mode. 0131 * 0132 * Do not disturb mode is considered active when this property is true OR 0133 * notificationsInhibitedUntil points to a date in the future. 0134 * 0135 * @sa revokeApplicationInhibitions 0136 */ 0137 Q_PROPERTY(bool notificationsInhibitedByApplication READ notificationsInhibitedByApplication NOTIFY notificationsInhibitedByApplicationChanged) 0138 0139 Q_PROPERTY(QStringList notificationInhibitionApplications READ notificationInhibitionApplications NOTIFY notificationInhibitionApplicationsChanged) 0140 0141 Q_PROPERTY(QStringList notificationInhibitionReasons READ notificationInhibitionReasons NOTIFY notificationInhibitionApplicationsChanged) 0142 0143 /** 0144 * Whether to enable do not disturb mode when screens are mirrored/overlapping 0145 * 0146 * @since 5.17 0147 */ 0148 Q_PROPERTY(bool inhibitNotificationsWhenScreensMirrored READ inhibitNotificationsWhenScreensMirrored WRITE setInhibitNotificationsWhenScreensMirrored NOTIFY 0149 settingsChanged) 0150 0151 /** 0152 * Whether there currently are mirrored/overlapping screens 0153 * 0154 * This property is only updated when @c inhibitNotificationsWhenScreensMirrored 0155 * is set to true, otherwise it is always false. 0156 * You can assign false to this property if you want to temporarily revoke automatic do not disturb 0157 * mode when screens are mirrored until the screen configuration changes. 0158 * 0159 * @since 5.17 0160 */ 0161 Q_PROPERTY(bool screensMirrored READ screensMirrored WRITE setScreensMirrored NOTIFY screensMirroredChanged) 0162 0163 /** 0164 * Whether to enable do not disturb mode while screen sharing 0165 * 0166 * @since 5.22 0167 */ 0168 Q_PROPERTY(bool inhibitNotificationsWhenScreenSharing READ inhibitNotificationsWhenScreenSharing WRITE setInhibitNotificationsWhenScreenSharing NOTIFY 0169 settingsChanged) 0170 0171 /** 0172 * Whether notification sounds should be disabled 0173 * 0174 * This does not reflect the actual mute state of the Notification Sounds 0175 * stream but only remembers what value was assigned to this property. 0176 * 0177 * This way you can tell whether to unmute notification sounds or not, in case 0178 * the user had them explicitly muted previously. 0179 * 0180 * @note This does not actually mute or unmute the actual sound stream, 0181 * you need to do this yourself using e.g. PulseAudio. 0182 */ 0183 Q_PROPERTY(bool notificationSoundsInhibited READ notificationSoundsInhibited WRITE setNotificationSoundsInhibited NOTIFY settingsChanged) 0184 0185 /** 0186 * Whether to update the properties immediately when they are changed on disk 0187 * 0188 * This can be undesirable for a settings dialog where outside changes 0189 * should not suddenly cause the UI to change. 0190 * 0191 * Default is true. 0192 */ 0193 Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged) 0194 0195 /** 0196 * Whether the settings have changed and need to be saved 0197 * 0198 * @sa save() 0199 */ 0200 Q_PROPERTY(bool dirty READ dirty NOTIFY dirtyChanged) 0201 0202 public: 0203 explicit Settings(QObject *parent = nullptr); 0204 /** 0205 * @deprecated 0206 */ 0207 Settings(const KSharedConfig::Ptr &config, QObject *parent = nullptr); 0208 ~Settings() override; 0209 0210 enum PopupPosition { 0211 CloseToWidget = 0, 0212 TopLeft, 0213 TopCenter, 0214 TopRight, 0215 BottomLeft, 0216 BottomCenter, 0217 BottomRight, 0218 }; 0219 Q_ENUM(PopupPosition) 0220 0221 enum NotificationBehavior { 0222 ShowPopups = 1 << 1, 0223 ShowPopupsInDoNotDisturbMode = 1 << 2, 0224 ShowInHistory = 1 << 3, 0225 ShowBadges = 1 << 4, 0226 }; 0227 Q_ENUM(NotificationBehavior) 0228 Q_DECLARE_FLAGS(NotificationBehaviors, NotificationBehavior) 0229 Q_FLAG(NotificationBehaviors) 0230 0231 Q_INVOKABLE NotificationBehaviors applicationBehavior(const QString &desktopEntry) const; 0232 Q_INVOKABLE void setApplicationBehavior(const QString &desktopEntry, NotificationBehaviors behaviors); 0233 0234 Q_INVOKABLE NotificationBehaviors serviceBehavior(const QString &desktopEntry) const; 0235 Q_INVOKABLE void setServiceBehavior(const QString &desktopEntry, NotificationBehaviors behaviors); 0236 0237 Q_INVOKABLE void registerKnownApplication(const QString &desktopEntry); 0238 Q_INVOKABLE void forgetKnownApplication(const QString &desktopEntry); 0239 0240 Q_INVOKABLE void load(); 0241 Q_INVOKABLE void save(); 0242 Q_INVOKABLE void defaults(); 0243 0244 bool live() const; 0245 void setLive(bool live); 0246 0247 bool dirty() const; 0248 0249 bool criticalPopupsInDoNotDisturbMode() const; 0250 void setCriticalPopupsInDoNotDisturbMode(bool enable); 0251 0252 bool keepNormalAlwaysOnTop() const; 0253 void setKeepNormalAlwaysOnTop(bool enable); 0254 0255 bool lowPriorityPopups() const; 0256 void setLowPriorityPopups(bool enable); 0257 0258 bool lowPriorityHistory() const; 0259 void setLowPriorityHistory(bool enable); 0260 0261 PopupPosition popupPosition() const; 0262 void setPopupPosition(PopupPosition popupPosition); 0263 0264 int popupTimeout() const; 0265 void setPopupTimeout(int popupTimeout); 0266 void resetPopupTimeout(); 0267 0268 bool jobsInNotifications() const; 0269 void setJobsInNotifications(bool enable); 0270 0271 bool permanentJobPopups() const; 0272 void setPermanentJobPopups(bool enable); 0273 0274 bool badgesInTaskManager() const; 0275 void setBadgesInTaskManager(bool enable); 0276 0277 QStringList knownApplications() const; 0278 0279 QStringList popupBlacklistedApplications() const; 0280 QStringList popupBlacklistedServices() const; 0281 0282 QStringList doNotDisturbPopupWhitelistedApplications() const; 0283 QStringList doNotDisturbPopupWhitelistedServices() const; 0284 0285 QStringList historyBlacklistedApplications() const; 0286 QStringList historyBlacklistedServices() const; 0287 0288 QStringList badgeBlacklistedApplications() const; 0289 0290 QDateTime notificationsInhibitedUntil() const; 0291 void setNotificationsInhibitedUntil(const QDateTime &time); 0292 void resetNotificationsInhibitedUntil(); 0293 0294 bool notificationsInhibitedByApplication() const; 0295 QStringList notificationInhibitionApplications() const; 0296 QStringList notificationInhibitionReasons() const; 0297 0298 bool inhibitNotificationsWhenScreensMirrored() const; 0299 void setInhibitNotificationsWhenScreensMirrored(bool mirrored); 0300 0301 bool screensMirrored() const; 0302 void setScreensMirrored(bool enable); 0303 0304 bool inhibitNotificationsWhenScreenSharing() const; 0305 void setInhibitNotificationsWhenScreenSharing(bool inhibit); 0306 0307 bool notificationSoundsInhibited() const; 0308 void setNotificationSoundsInhibited(bool inhibited); 0309 0310 /** 0311 * Revoke application notification inhibitions. 0312 * 0313 * @note Applications are not notified of the fact that their 0314 * inhibition might have been taken away. 0315 */ 0316 Q_INVOKABLE void revokeApplicationInhibitions(); 0317 0318 Q_SIGNALS: 0319 void settingsChanged(); 0320 0321 void liveChanged(); 0322 void dirtyChanged(); 0323 0324 void knownApplicationsChanged(); 0325 0326 void notificationsInhibitedByApplicationChanged(bool notificationsInhibitedByApplication); 0327 void notificationInhibitionApplicationsChanged(); 0328 0329 void screensMirroredChanged(); 0330 0331 private: 0332 class Private; 0333 std::unique_ptr<Private> d; 0334 }; 0335 0336 } // namespace NotificationManager 0337 0338 Q_DECLARE_OPERATORS_FOR_FLAGS(NotificationManager::Settings::NotificationBehaviors)