Plasma-workspace

settings.h
1/*
2 SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@privat.broulik.de>
3 SPDX-FileCopyrightText: 2024 Kristen McWilliam <kmcwilliampublic@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#pragma once
9
10#include <QObject>
11
12#include <KSharedConfig>
13
14#include <QDateTime>
15#include <QString>
16#include <memory>
17
18#include <qqmlregistration.h>
19
20#include "notificationmanager_export.h"
21
22namespace NotificationManager
23{
24/**
25 * @short Notification settings and state
26 *
27 * This class encapsulates all global settings related to notifications
28 * as well as do not disturb mode and other state.
29 *
30 * This class can be used by applications to alter their behavior
31 * depending on user's notification preferences.
32 *
33 * @author Kai Uwe Broulik <kde@privat.broulik.de>
34 **/
35class NOTIFICATIONMANAGER_EXPORT Settings : public QObject
36{
38 QML_ELEMENT
39
40 /**
41 * Whether to show critical notification popups in do not disturb mode.
42 */
43 Q_PROPERTY(bool criticalPopupsInDoNotDisturbMode READ criticalPopupsInDoNotDisturbMode WRITE setCriticalPopupsInDoNotDisturbMode NOTIFY settingsChanged)
44 /**
45 * Whether to show popups for low priority notifications.
46 */
47 Q_PROPERTY(bool lowPriorityPopups READ lowPriorityPopups WRITE setLowPriorityPopups NOTIFY settingsChanged)
48 /**
49 * Whether to add low priority notifications to the history.
50 */
51 Q_PROPERTY(bool lowPriorityHistory READ lowPriorityHistory WRITE setLowPriorityHistory NOTIFY settingsChanged)
52
53 /**
54 * The notification popup position on screen.
55 * CloseToWidget means they should be positioned closely to where the plasmoid is located on screen.
56 */
57 Q_PROPERTY(PopupPosition popupPosition READ popupPosition WRITE setPopupPosition NOTIFY settingsChanged)
58
59 /**
60 * The default timeout for notification popups that do not have an explicit timeout set,
61 * in milliseconds. Default is 5000ms (5 seconds).
62 */
63 Q_PROPERTY(int popupTimeout READ popupTimeout WRITE setPopupTimeout RESET resetPopupTimeout NOTIFY settingsChanged)
64
65 /**
66 * Whether to show application jobs as notifications
67 */
68 Q_PROPERTY(bool jobsInNotifications READ jobsInNotifications WRITE setJobsInNotifications /*RESET resetJobsPopup*/ NOTIFY settingsChanged)
69 /**
70 * Whether application jobs stay visible for the whole duration of the job
71 */
72 Q_PROPERTY(bool permanentJobPopups READ permanentJobPopups WRITE setPermanentJobPopups /*RESET resetAutoHideJobsPopup*/ NOTIFY settingsChanged)
73
74 /**
75 * Whether to show notification badges (numbers in circles) in task manager
76 */
77 Q_PROPERTY(bool badgesInTaskManager READ badgesInTaskManager WRITE setBadgesInTaskManager NOTIFY settingsChanged)
78
79 /**
80 * A list of desktop entries of applications that have been seen sending a notification.
81 */
82 Q_PROPERTY(QStringList knownApplications READ knownApplications NOTIFY knownApplicationsChanged)
83
84 /**
85 * A list of desktop entries of applications for which no popups should be shown.
86 */
88 /**
89 * A list of notifyrc names of services for which no popups should be shown.
90 */
92
93 /**
94 * A list of desktop entries of applications for which a popup should be shown even in do not disturb mode.
95 */
97 /**
98 * A list of notifyrc names of services for which a popup should be shown even in do not disturb mode.
99 */
101
102 /**
103 * A list of desktop entries of applications which shouldn't be shown in the history.
104 */
106 /**
107 * A list of notifyrc names of services which shouldn't be shown in the history.
108 */
110
111 /**
112 * A list of desktop entries of applications which shouldn't show badges in task manager.
113 */
115
116 /**
117 * The date until which do not disturb mode is enabled.
118 *
119 * When invalid or in the past, do not disturb mode should be considered disabled.
120 * Do not disturb mode is considered active when this property points to a date
121 * in the future OR notificationsInhibitedByApplication is true.
122 */
123 Q_PROPERTY(QDateTime notificationsInhibitedUntil READ notificationsInhibitedUntil WRITE setNotificationsInhibitedUntil RESET
124 resetNotificationsInhibitedUntil NOTIFY settingsChanged)
125
126 /**
127 * Whether an application currently requested do not disturb mode.
128 *
129 * Do not disturb mode is considered active when this property is true OR
130 * notificationsInhibitedUntil points to a date in the future.
131 *
132 * @sa revokeApplicationInhibitions
133 */
134 Q_PROPERTY(bool notificationsInhibitedByApplication READ notificationsInhibitedByApplication NOTIFY notificationsInhibitedByApplicationChanged)
135
136 Q_PROPERTY(QStringList notificationInhibitionApplications READ notificationInhibitionApplications NOTIFY notificationInhibitionApplicationsChanged)
137
138 Q_PROPERTY(QStringList notificationInhibitionReasons READ notificationInhibitionReasons NOTIFY notificationInhibitionApplicationsChanged)
139
140 /**
141 * Whether to enable do not disturb mode when screens are mirrored/overlapping
142 *
143 * @since 5.17
144 */
145 Q_PROPERTY(bool inhibitNotificationsWhenScreensMirrored READ inhibitNotificationsWhenScreensMirrored WRITE setInhibitNotificationsWhenScreensMirrored NOTIFY
146 settingsChanged)
147
148 /**
149 * Whether there currently are mirrored/overlapping screens
150 *
151 * This property is only updated when @c inhibitNotificationsWhenScreensMirrored
152 * is set to true, otherwise it is always false.
153 * You can assign false to this property if you want to temporarily revoke automatic do not disturb
154 * mode when screens are mirrored until the screen configuration changes.
155 *
156 * @since 5.17
157 */
158 Q_PROPERTY(bool screensMirrored READ screensMirrored WRITE setScreensMirrored NOTIFY screensMirroredChanged)
159
160 /**
161 * Whether to enable do not disturb mode while screen sharing
162 *
163 * @since 5.22
164 */
165 Q_PROPERTY(bool inhibitNotificationsWhenScreenSharing READ inhibitNotificationsWhenScreenSharing WRITE setInhibitNotificationsWhenScreenSharing NOTIFY
166 settingsChanged)
167
168 /**
169 * Whether to enable do not disturb mode when a fullscreen window is focused
170 *
171 * @since 6.4
172 */
174 bool inhibitNotificationsWhenFullscreen READ inhibitNotificationsWhenFullscreen WRITE setInhibitNotificationsWhenFullscreen NOTIFY settingsChanged)
175
176 /**
177 * Whether a fullscreen window is currently focused
178 *
179 * This property is only updated when @c inhibitNotificationsWhenFullscreen
180 * is set to true, otherwise it is always false.
181 * You can assign false to this property if you want to temporarily revoke automatic do not disturb
182 * mode when a fullscreen window is focused until the window is no longer fullscreen.
183 *
184 * @since 6.4
185 */
186 Q_PROPERTY(bool fullscreenFocused READ fullscreenFocused WRITE setFullscreenFocused NOTIFY fullscreenFocusedChanged)
187
188 /**
189 * Whether notification sounds should be disabled
190 *
191 * This does not reflect the actual mute state of the Notification Sounds
192 * stream but only remembers what value was assigned to this property.
193 *
194 * This way you can tell whether to unmute notification sounds or not, in case
195 * the user had them explicitly muted previously.
196 *
197 * @note This does not actually mute or unmute the actual sound stream,
198 * you need to do this yourself using e.g. PulseAudio.
199 */
200 Q_PROPERTY(bool notificationSoundsInhibited READ notificationSoundsInhibited WRITE setNotificationSoundsInhibited NOTIFY settingsChanged)
201
202 /**
203 * Whether to update the properties immediately when they are changed on disk
204 *
205 * This can be undesirable for a settings dialog where outside changes
206 * should not suddenly cause the UI to change.
207 *
208 * Default is true.
209 */
210 Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged)
211
212 /**
213 * Whether the settings have changed and need to be saved
214 *
215 * @sa save()
216 */
217 Q_PROPERTY(bool dirty READ dirty NOTIFY dirtyChanged)
218
219public:
220 explicit Settings(QObject *parent = nullptr);
221 /**
222 * @deprecated
223 */
224 Settings(const KSharedConfig::Ptr &config, QObject *parent = nullptr);
225 ~Settings() override;
226
227 enum PopupPosition {
228 CloseToWidget = 0,
229 TopLeft,
230 TopCenter,
231 TopRight,
232 BottomLeft,
233 BottomCenter,
234 BottomRight,
235 };
236 Q_ENUM(PopupPosition)
237
238 enum NotificationBehavior {
239 ShowPopups = 1 << 1,
240 ShowPopupsInDoNotDisturbMode = 1 << 2,
241 ShowInHistory = 1 << 3,
242 ShowBadges = 1 << 4,
243 };
244 Q_ENUM(NotificationBehavior)
245 Q_DECLARE_FLAGS(NotificationBehaviors, NotificationBehavior)
246 Q_FLAG(NotificationBehaviors)
247
248 Q_INVOKABLE NotificationBehaviors applicationBehavior(const QString &desktopEntry) const;
249 Q_INVOKABLE void setApplicationBehavior(const QString &desktopEntry, NotificationBehaviors behaviors);
250
251 Q_INVOKABLE NotificationBehaviors serviceBehavior(const QString &desktopEntry) const;
252 Q_INVOKABLE void setServiceBehavior(const QString &desktopEntry, NotificationBehaviors behaviors);
253
254 Q_INVOKABLE void registerKnownApplication(const QString &desktopEntry);
255 Q_INVOKABLE void forgetKnownApplication(const QString &desktopEntry);
256
257 Q_INVOKABLE void load();
258 Q_INVOKABLE void save();
259 Q_INVOKABLE void defaults();
260
261 bool live() const;
262 void setLive(bool live);
263
264 bool dirty() const;
265
266 bool criticalPopupsInDoNotDisturbMode() const;
267 void setCriticalPopupsInDoNotDisturbMode(bool enable);
268
269 bool lowPriorityPopups() const;
270 void setLowPriorityPopups(bool enable);
271
272 bool lowPriorityHistory() const;
273 void setLowPriorityHistory(bool enable);
274
275 PopupPosition popupPosition() const;
276 void setPopupPosition(PopupPosition popupPosition);
277
278 int popupTimeout() const;
279 void setPopupTimeout(int popupTimeout);
280 void resetPopupTimeout();
281
282 bool jobsInNotifications() const;
283 void setJobsInNotifications(bool enable);
284
285 bool permanentJobPopups() const;
286 void setPermanentJobPopups(bool enable);
287
288 bool badgesInTaskManager() const;
289 void setBadgesInTaskManager(bool enable);
290
291 QStringList knownApplications() const;
292
293 QStringList popupBlacklistedApplications() const;
294 QStringList popupBlacklistedServices() const;
295
296 QStringList doNotDisturbPopupWhitelistedApplications() const;
297 QStringList doNotDisturbPopupWhitelistedServices() const;
298
299 QStringList historyBlacklistedApplications() const;
300 QStringList historyBlacklistedServices() const;
301
302 QStringList badgeBlacklistedApplications() const;
303
304 QDateTime notificationsInhibitedUntil() const;
305 void setNotificationsInhibitedUntil(const QDateTime &time);
306 void resetNotificationsInhibitedUntil();
307
308 bool notificationsInhibitedByApplication() const;
309 QStringList notificationInhibitionApplications() const;
310 QStringList notificationInhibitionReasons() const;
311
312 bool inhibitNotificationsWhenScreensMirrored() const;
313 void setInhibitNotificationsWhenScreensMirrored(bool mirrored);
314
315 bool screensMirrored() const;
316 void setScreensMirrored(bool enable);
317
318 bool inhibitNotificationsWhenScreenSharing() const;
319 void setInhibitNotificationsWhenScreenSharing(bool inhibit);
320
321 bool inhibitNotificationsWhenFullscreen() const;
322 void setInhibitNotificationsWhenFullscreen(bool inhibit);
323
324 bool fullscreenFocused() const;
325 void setFullscreenFocused(bool focused);
326
327 bool notificationSoundsInhibited() const;
328 void setNotificationSoundsInhibited(bool inhibited);
329
330 /**
331 * Revoke application notification inhibitions.
332 *
333 * @note Applications are not notified of the fact that their
334 * inhibition might have been taken away.
335 */
336 Q_INVOKABLE void revokeApplicationInhibitions();
337
338Q_SIGNALS:
339 void settingsChanged();
340
341 void liveChanged();
342 void dirtyChanged();
343
344 void knownApplicationsChanged();
345
346 void notificationsInhibitedByApplicationChanged(bool notificationsInhibitedByApplication);
347 void notificationInhibitionApplicationsChanged();
348
349 void screensMirroredChanged();
350
351 void fullscreenFocusedChanged();
352
353private:
354 class Private;
355 std::unique_ptr<Private> d;
356};
357
358} // namespace NotificationManager
359
360Q_DECLARE_OPERATORS_FOR_FLAGS(NotificationManager::Settings::NotificationBehaviors)
QStringList popupBlacklistedApplications
A list of desktop entries of applications for which no popups should be shown.
Definition settings.h:87
bool notificationsInhibitedByApplication
Whether an application currently requested do not disturb mode.
Definition settings.h:134
bool screensMirrored
Whether there currently are mirrored/overlapping screens.
Definition settings.h:158
bool inhibitNotificationsWhenScreensMirrored
Whether to enable do not disturb mode when screens are mirrored/overlapping.
Definition settings.h:146
bool jobsInNotifications
Whether to show application jobs as notifications.
Definition settings.h:68
QStringList badgeBlacklistedApplications
A list of desktop entries of applications which shouldn't show badges in task manager.
Definition settings.h:114
bool dirty
Whether the settings have changed and need to be saved.
Definition settings.h:217
QStringList doNotDisturbPopupWhitelistedServices
A list of notifyrc names of services for which a popup should be shown even in do not disturb mode.
Definition settings.h:100
QML_ELEMENTbool criticalPopupsInDoNotDisturbMode
Whether to show critical notification popups in do not disturb mode.
Definition settings.h:43
bool notificationSoundsInhibited
Whether notification sounds should be disabled.
Definition settings.h:200
QDateTime notificationsInhibitedUntil
The date until which do not disturb mode is enabled.
Definition settings.h:124
int popupTimeout
The default timeout for notification popups that do not have an explicit timeout set,...
Definition settings.h:63
QStringList historyBlacklistedApplications
A list of desktop entries of applications which shouldn't be shown in the history.
Definition settings.h:105
QStringList knownApplications
A list of desktop entries of applications that have been seen sending a notification.
Definition settings.h:82
bool lowPriorityHistory
Whether to add low priority notifications to the history.
Definition settings.h:51
bool live
Whether to update the properties immediately when they are changed on disk.
Definition settings.h:210
QStringList popupBlacklistedServices
A list of notifyrc names of services for which no popups should be shown.
Definition settings.h:91
QStringList historyBlacklistedServices
A list of notifyrc names of services which shouldn't be shown in the history.
Definition settings.h:109
PopupPosition popupPosition
The notification popup position on screen.
Definition settings.h:57
bool inhibitNotificationsWhenFullscreen
Whether to enable do not disturb mode when a fullscreen window is focused.
Definition settings.h:174
QStringList doNotDisturbPopupWhitelistedApplications
A list of desktop entries of applications for which a popup should be shown even in do not disturb mo...
Definition settings.h:96
bool inhibitNotificationsWhenScreenSharing
Whether to enable do not disturb mode while screen sharing.
Definition settings.h:166
bool badgesInTaskManager
Whether to show notification badges (numbers in circles) in task manager.
Definition settings.h:77
bool fullscreenFocused
Whether a fullscreen window is currently focused.
Definition settings.h:186
bool permanentJobPopups
Whether application jobs stay visible for the whole duration of the job.
Definition settings.h:72
bool lowPriorityPopups
Whether to show popups for low priority notifications.
Definition settings.h:47
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 11:59:36 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.