Plasma-workspace

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

KDE's Doxygen guidelines are available online.