Changeset View
Changeset View
Standalone View
Standalone View
libnotificationmanager/settings.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | * later version accepted by the membership of KDE e.V. (or its | ||||
9 | * successor approved by the membership of KDE e.V.), which shall | ||||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | * | ||||
12 | * This library is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | * Lesser General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Lesser General Public | ||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "settings.h" | ||||
22 | | ||||
23 | #include "config-notificationmanager.h" | ||||
24 | | ||||
25 | #include <QDebug> | ||||
26 | | ||||
27 | #include <KConfigWatcher> | ||||
28 | #include <KService> | ||||
29 | | ||||
30 | #include "server.h" | ||||
31 | #include "debug.h" | ||||
32 | | ||||
33 | // Settings | ||||
34 | #include "donotdisturbsettings.h" | ||||
35 | #include "notificationsettings.h" | ||||
36 | #include "jobsettings.h" | ||||
37 | #include "badgesettings.h" | ||||
38 | | ||||
39 | #ifdef HAVE_PULSEAUDIOQT | ||||
40 | #include <PulseAudioQt/Context> | ||||
41 | #include <PulseAudioQt/StreamRestore> | ||||
42 | | ||||
43 | using namespace PulseAudioQt; | ||||
44 | | ||||
45 | static const char *s_notificationStreamId = "sink-input-by-media-role:event"; | ||||
46 | #endif | ||||
47 | | ||||
48 | using namespace NotificationManager; | ||||
49 | | ||||
50 | class Q_DECL_HIDDEN Settings::Private | ||||
51 | { | ||||
52 | public: | ||||
53 | explicit Private(Settings *q); | ||||
54 | ~Private(); | ||||
55 | | ||||
56 | void setDirty(bool dirty); | ||||
57 | | ||||
58 | Settings::NotificationBehaviors groupBehavior(const KConfigGroup &group) const; | ||||
59 | void setGroupBehavior(KConfigGroup &group, const Settings::NotificationBehaviors &behavior); | ||||
60 | | ||||
61 | KConfigGroup servicesGroup() const; | ||||
62 | KConfigGroup applicationsGroup() const; | ||||
63 | | ||||
64 | QStringList behaviorMatchesList(const KConfigGroup &group, Settings::NotificationBehavior behavior, bool on) const; | ||||
65 | | ||||
66 | Settings *q; | ||||
67 | | ||||
68 | KSharedConfig::Ptr config; | ||||
69 | | ||||
70 | KConfigWatcher::Ptr watcher; | ||||
71 | QMetaObject::Connection watcherConnection; | ||||
72 | | ||||
73 | bool live = false; // set to true initially in constructor | ||||
74 | bool dirty = false; | ||||
75 | | ||||
76 | #ifdef HAVE_PULSEAUDIOQT | ||||
77 | QPointer<StreamRestore> notificationSounds; | ||||
78 | #endif | ||||
79 | | ||||
80 | }; | ||||
81 | | ||||
82 | Settings::Private::Private(Settings *q) | ||||
83 | : q(q) | ||||
84 | { | ||||
85 | | ||||
86 | #ifdef HAVE_PULSEAUDIOQT | ||||
87 | // Can there be multiple? | ||||
88 | const auto streamRestores = Context::instance()->streamRestores(); | ||||
89 | for (StreamRestore *restore : streamRestores) { | ||||
90 | if (restore->name() == QLatin1String(s_notificationStreamId)) { | ||||
91 | notificationSounds = restore; | ||||
92 | connect(notificationSounds.data(), &StreamRestore::mutedChanged, q, &Settings::notificationSoundsMutedChanged); | ||||
93 | break; | ||||
94 | } | ||||
95 | } | ||||
96 | | ||||
97 | QObject::connect(Context::instance(), &Context::streamRestoreAdded, q, [this, q](StreamRestore *restore) { | ||||
98 | if (restore->name() == QLatin1String(s_notificationStreamId)) { | ||||
99 | notificationSounds = restore; | ||||
100 | connect(notificationSounds.data(), &StreamRestore::mutedChanged, q, &Settings::notificationSoundsMutedChanged); | ||||
101 | } | ||||
102 | }); | ||||
103 | #endif | ||||
104 | | ||||
105 | } | ||||
106 | | ||||
107 | Settings::Private::~Private() = default; | ||||
108 | | ||||
109 | void Settings::Private::setDirty(bool dirty) | ||||
110 | { | ||||
111 | if (this->dirty != dirty) { | ||||
112 | this->dirty = dirty; | ||||
113 | emit q->dirtyChanged(); | ||||
114 | } | ||||
115 | } | ||||
116 | | ||||
117 | Settings::NotificationBehaviors Settings::Private::groupBehavior(const KConfigGroup &group) const | ||||
118 | { | ||||
119 | Settings::NotificationBehaviors behaviors; | ||||
120 | behaviors.setFlag(Settings::ShowPopups, group.readEntry("ShowPopups", true)); | ||||
121 | // show popups in dnd mode implies the show popups | ||||
122 | behaviors.setFlag(Settings::ShowPopupsInDoNotDisturbMode, behaviors.testFlag(Settings::ShowPopups) && group.readEntry("ShowPopupsInDndMode", false)); | ||||
123 | behaviors.setFlag(Settings::ShowInHistory, group.readEntry("ShowInHistory", true)); | ||||
124 | behaviors.setFlag(Settings::ShowBadges, group.readEntry("ShowBadges", true)); | ||||
125 | return behaviors; | ||||
126 | } | ||||
127 | | ||||
128 | void Settings::Private::setGroupBehavior(KConfigGroup &group, const Settings::NotificationBehaviors &behavior) | ||||
129 | { | ||||
130 | if (groupBehavior(group) == behavior) { | ||||
131 | return; | ||||
132 | } | ||||
133 | | ||||
134 | const bool showPopups = behavior.testFlag(Settings::ShowPopups); | ||||
135 | if (showPopups && !group.hasDefault("ShowPopups")) { | ||||
136 | group.revertToDefault("ShowPopups", KConfigBase::Notify); | ||||
137 | } else { | ||||
138 | group.writeEntry("ShowPopups", showPopups, KConfigBase::Notify); | ||||
139 | } | ||||
140 | | ||||
141 | const bool showPopupsInDndMode = behavior.testFlag(Settings::ShowPopupsInDoNotDisturbMode); | ||||
142 | if (!showPopupsInDndMode && !group.hasDefault("ShowPopups")) { | ||||
143 | group.revertToDefault("ShowPopupsInDndMode", KConfigBase::Notify); | ||||
144 | } else { | ||||
145 | group.writeEntry("ShowPopupsInDndMode", showPopupsInDndMode, KConfigBase::Notify); | ||||
146 | } | ||||
147 | | ||||
148 | const bool showInHistory = behavior.testFlag(Settings::ShowInHistory); | ||||
149 | if (showInHistory && !group.hasDefault("ShowInHistory")) { | ||||
150 | group.revertToDefault("ShowInHistory", KConfig::Notify); | ||||
151 | } else { | ||||
152 | group.writeEntry("ShowInHistory", showInHistory, KConfigBase::Notify); | ||||
153 | } | ||||
154 | | ||||
155 | const bool showBadges = behavior.testFlag(Settings::ShowBadges); | ||||
156 | if (showBadges && !group.hasDefault("ShowBadges")) { | ||||
157 | group.revertToDefault("ShowBadges", KConfigBase::Notify); | ||||
158 | } else { | ||||
159 | group.writeEntry("ShowBadges", showBadges, KConfigBase::Notify); | ||||
160 | } | ||||
161 | | ||||
162 | setDirty(true); | ||||
163 | } | ||||
164 | | ||||
165 | KConfigGroup Settings::Private::servicesGroup() const | ||||
166 | { | ||||
167 | return config->group("Services"); | ||||
168 | } | ||||
169 | | ||||
170 | KConfigGroup Settings::Private::applicationsGroup() const | ||||
171 | { | ||||
172 | return config->group("Applications"); | ||||
173 | } | ||||
174 | | ||||
175 | QStringList Settings::Private::behaviorMatchesList(const KConfigGroup &group, Settings::NotificationBehavior behavior, bool on) const | ||||
176 | { | ||||
177 | QStringList matches; | ||||
178 | | ||||
179 | const QStringList apps = group.groupList(); | ||||
180 | for (const QString &app : apps) { | ||||
181 | if (groupBehavior(group.group(app)).testFlag(behavior) == on) { | ||||
182 | matches.append(app); | ||||
183 | } | ||||
184 | } | ||||
185 | | ||||
186 | return matches; | ||||
187 | } | ||||
188 | | ||||
189 | Settings::Settings(QObject *parent) | ||||
190 | // FIXME static thing for config file name | ||||
191 | : Settings(KSharedConfig::openConfig(QStringLiteral("plasmanotifyrc")), parent) | ||||
192 | { | ||||
193 | | ||||
194 | } | ||||
195 | | ||||
196 | Settings::Settings(const KSharedConfig::Ptr &config, QObject *parent) | ||||
197 | : QObject(parent) | ||||
198 | , d(new Private(this)) | ||||
199 | { | ||||
200 | d->config = config; | ||||
201 | | ||||
202 | static bool s_settingsInited = false; | ||||
203 | if (!s_settingsInited) { | ||||
204 | DoNotDisturbSettings::instance(config); | ||||
205 | NotificationSettings::instance(config); | ||||
206 | JobSettings::instance(config); | ||||
207 | BadgeSettings::instance(config); | ||||
208 | s_settingsInited = true; | ||||
209 | } | ||||
210 | | ||||
211 | setLive(true); | ||||
212 | | ||||
213 | connect(&Server::self(), &Server::inhibitedChanged, | ||||
214 | this, &Settings::notificationsInhibitedByApplicationChanged); | ||||
215 | connect(&Server::self(), &Server::inhibitionApplicationsChanged, | ||||
216 | this, &Settings::notificationInhibitionApplicationsChanged); | ||||
217 | } | ||||
218 | | ||||
219 | Settings::~Settings() = default; | ||||
220 | | ||||
221 | Settings::NotificationBehaviors Settings::applicationBehavior(const QString &desktopEntry) const | ||||
222 | { | ||||
223 | return d->groupBehavior(d->applicationsGroup().group(desktopEntry)); | ||||
224 | } | ||||
225 | | ||||
226 | void Settings::setApplicationBehavior(const QString &desktopEntry, NotificationBehaviors behaviors) | ||||
227 | { | ||||
228 | KConfigGroup group(d->applicationsGroup().group(desktopEntry)); | ||||
229 | d->setGroupBehavior(group, behaviors); | ||||
230 | } | ||||
231 | | ||||
232 | Settings::NotificationBehaviors Settings::serviceBehavior(const QString ¬ifyRcName) const | ||||
233 | { | ||||
234 | return d->groupBehavior(d->servicesGroup().group(notifyRcName)); | ||||
235 | } | ||||
236 | | ||||
237 | void Settings::setServiceBehavior(const QString ¬ifyRcName, NotificationBehaviors behaviors) | ||||
238 | { | ||||
239 | KConfigGroup group(d->servicesGroup().group(notifyRcName)); | ||||
240 | d->setGroupBehavior(group, behaviors); | ||||
241 | } | ||||
242 | | ||||
243 | void Settings::registerKnownApplication(const QString &desktopEntry) | ||||
244 | { | ||||
245 | KService::Ptr service = KService::serviceByDesktopName(desktopEntry); | ||||
246 | if (!service) { | ||||
247 | qCDebug(NOTIFICATIONMANAGER) << "Application" << desktopEntry << "cannot be registered as seen application since there is no service for it"; | ||||
248 | return; | ||||
249 | } | ||||
250 | | ||||
251 | if (service->noDisplay()) { | ||||
252 | qCDebug(NOTIFICATIONMANAGER) << "Application" << desktopEntry << "will not be registered as seen application since it's marked as NoDisplay"; | ||||
253 | return; | ||||
254 | } | ||||
255 | | ||||
256 | if (knownApplications().contains(desktopEntry)) { | ||||
257 | return; | ||||
258 | } | ||||
259 | | ||||
260 | d->applicationsGroup().group(desktopEntry).writeEntry("Seen", true); | ||||
261 | | ||||
262 | emit knownApplicationsChanged(); | ||||
263 | } | ||||
264 | | ||||
265 | void Settings::forgetKnownApplication(const QString &desktopEntry) | ||||
266 | { | ||||
267 | if (!knownApplications().contains(desktopEntry)) { | ||||
268 | return; | ||||
269 | } | ||||
270 | | ||||
271 | // Only remove applications that were added through registerKnownApplication | ||||
272 | if (!d->applicationsGroup().group(desktopEntry).readEntry("Seen", false)) { | ||||
273 | qCDebug(NOTIFICATIONMANAGER) << "Application" << desktopEntry << "will not be removed from seen applications since it wasn't one."; | ||||
274 | return; | ||||
275 | } | ||||
276 | | ||||
277 | d->applicationsGroup().deleteGroup(desktopEntry); | ||||
278 | | ||||
279 | emit knownApplicationsChanged(); | ||||
280 | } | ||||
281 | | ||||
282 | void Settings::load() | ||||
283 | { | ||||
284 | DoNotDisturbSettings::self()->load(); | ||||
285 | NotificationSettings::self()->load(); | ||||
286 | JobSettings::self()->load(); | ||||
287 | BadgeSettings::self()->load(); | ||||
288 | emit settingsChanged(); | ||||
289 | d->setDirty(false); | ||||
290 | } | ||||
291 | | ||||
292 | void Settings::save() | ||||
293 | { | ||||
294 | DoNotDisturbSettings::self()->save(); | ||||
295 | NotificationSettings::self()->save(); | ||||
296 | JobSettings::self()->save(); | ||||
297 | BadgeSettings::self()->save(); | ||||
298 | | ||||
299 | d->config->sync(); | ||||
300 | d->setDirty(false); | ||||
301 | } | ||||
302 | | ||||
303 | void Settings::defaults() | ||||
304 | { | ||||
305 | DoNotDisturbSettings::self()->setDefaults(); | ||||
306 | NotificationSettings::self()->setDefaults(); | ||||
307 | JobSettings::self()->setDefaults(); | ||||
308 | BadgeSettings::self()->setDefaults(); | ||||
309 | } | ||||
310 | | ||||
311 | bool Settings::live() const | ||||
312 | { | ||||
313 | return d->live; | ||||
314 | } | ||||
315 | | ||||
316 | void Settings::setLive(bool live) | ||||
317 | { | ||||
318 | if (live == d->live) { | ||||
319 | return; | ||||
320 | } | ||||
321 | | ||||
322 | d->live = live; | ||||
323 | | ||||
324 | if (live) { | ||||
325 | d->watcher = KConfigWatcher::create(d->config); | ||||
326 | d->watcherConnection = connect(d->watcher.data(), &KConfigWatcher::configChanged, this, | ||||
327 | [this](const KConfigGroup &group, const QByteArrayList &names) { | ||||
328 | Q_UNUSED(names); | ||||
329 | | ||||
330 | if (group.name() == QLatin1String("DoNotDisturb")) { | ||||
331 | DoNotDisturbSettings::self()->load(); | ||||
332 | } else if (group.name() == QLatin1String("Notifications")) { | ||||
333 | NotificationSettings::self()->load(); | ||||
334 | } else if (group.name() == QLatin1String("Jobs")) { | ||||
335 | JobSettings::self()->load(); | ||||
336 | } else if (group.name() == QLatin1String("Badges")) { | ||||
337 | BadgeSettings::self()->load(); | ||||
338 | } | ||||
339 | | ||||
340 | emit settingsChanged(); | ||||
341 | }); | ||||
342 | } else { | ||||
343 | disconnect(d->watcherConnection); | ||||
344 | d->watcherConnection = QMetaObject::Connection(); | ||||
345 | d->watcher.reset(); | ||||
346 | } | ||||
347 | | ||||
348 | emit liveChanged(); | ||||
349 | } | ||||
350 | | ||||
351 | bool Settings::dirty() const | ||||
352 | { | ||||
353 | // KConfigSkeleton doesn't write into the KConfig until calling save() | ||||
354 | // so we need to track d->config->isDirty() manually | ||||
355 | return d->dirty; | ||||
356 | } | ||||
357 | | ||||
358 | bool Settings::keepCriticalAlwaysOnTop() const | ||||
359 | { | ||||
360 | return NotificationSettings::criticalAlwaysOnTop(); | ||||
361 | } | ||||
362 | | ||||
363 | void Settings::setKeepCriticalAlwaysOnTop(bool enable) | ||||
364 | { | ||||
365 | if (this->keepCriticalAlwaysOnTop() == enable) { | ||||
366 | return; | ||||
367 | } | ||||
368 | NotificationSettings::setCriticalAlwaysOnTop(enable); | ||||
369 | d->setDirty(true); | ||||
370 | } | ||||
371 | | ||||
372 | bool Settings::criticalPopupsInDoNotDisturbMode() const | ||||
373 | { | ||||
374 | return NotificationSettings::criticalInDndMode(); | ||||
375 | } | ||||
376 | | ||||
377 | void Settings::setCriticalPopupsInDoNotDisturbMode(bool enable) | ||||
378 | { | ||||
379 | if (this->criticalPopupsInDoNotDisturbMode() == enable) { | ||||
380 | return; | ||||
381 | } | ||||
382 | NotificationSettings::setCriticalInDndMode(enable); | ||||
383 | d->setDirty(true); | ||||
384 | } | ||||
385 | | ||||
386 | bool Settings::lowPriorityPopups() const | ||||
387 | { | ||||
388 | return NotificationSettings::lowPriorityPopups(); | ||||
389 | } | ||||
390 | | ||||
391 | void Settings::setLowPriorityPopups(bool enable) | ||||
392 | { | ||||
393 | if (this->lowPriorityPopups() == enable) { | ||||
394 | return; | ||||
395 | } | ||||
396 | NotificationSettings::setLowPriorityPopups(enable); | ||||
397 | d->setDirty(true); | ||||
398 | } | ||||
399 | | ||||
400 | bool Settings::lowPriorityHistory() const | ||||
401 | { | ||||
402 | return NotificationSettings::lowPriorityHistory(); | ||||
403 | } | ||||
404 | | ||||
405 | void Settings::setLowPriorityHistory(bool enable) | ||||
406 | { | ||||
407 | if (this->lowPriorityHistory() == enable) { | ||||
408 | return; | ||||
409 | } | ||||
410 | NotificationSettings::setLowPriorityHistory(enable); | ||||
411 | d->setDirty(true); | ||||
412 | } | ||||
413 | | ||||
414 | Settings::PopupPosition Settings::popupPosition() const | ||||
415 | { | ||||
416 | return NotificationSettings::popupPosition(); | ||||
417 | } | ||||
418 | | ||||
419 | void Settings::setPopupPosition(Settings::PopupPosition position) | ||||
420 | { | ||||
421 | if (this->popupPosition() == position) { | ||||
422 | return; | ||||
423 | } | ||||
424 | NotificationSettings::setPopupPosition(position); | ||||
425 | d->setDirty(true); | ||||
426 | } | ||||
427 | | ||||
428 | int Settings::popupTimeout() const | ||||
429 | { | ||||
430 | return NotificationSettings::popupTimeout(); | ||||
431 | } | ||||
432 | | ||||
433 | void Settings::setPopupTimeout(int timeout) | ||||
434 | { | ||||
435 | if (this->popupTimeout() == timeout) { | ||||
436 | return; | ||||
437 | } | ||||
438 | NotificationSettings::setPopupTimeout(timeout); | ||||
439 | d->setDirty(true); | ||||
440 | } | ||||
441 | | ||||
442 | void Settings::resetPopupTimeout() | ||||
443 | { | ||||
444 | setPopupTimeout(NotificationSettings::defaultPopupTimeoutValue()); | ||||
445 | } | ||||
446 | | ||||
447 | bool Settings::jobsInTaskManager() const | ||||
448 | { | ||||
449 | return JobSettings::inTaskManager(); | ||||
450 | } | ||||
451 | | ||||
452 | void Settings::setJobsInTaskManager(bool enable) | ||||
453 | { | ||||
454 | if (jobsInTaskManager() == enable) { | ||||
455 | return; | ||||
456 | } | ||||
457 | JobSettings::setInTaskManager(enable); | ||||
458 | d->setDirty(true); | ||||
459 | } | ||||
460 | | ||||
461 | bool Settings::jobsInNotifications() const | ||||
462 | { | ||||
463 | return JobSettings::inNotifications(); | ||||
464 | } | ||||
465 | void Settings::setJobsInNotifications(bool enable) | ||||
466 | { | ||||
467 | if (jobsInNotifications() == enable) { | ||||
468 | return; | ||||
469 | } | ||||
470 | JobSettings::setInNotifications(enable); | ||||
471 | d->setDirty(true); | ||||
472 | } | ||||
473 | | ||||
474 | bool Settings::permanentJobPopups() const | ||||
475 | { | ||||
476 | return JobSettings::permanentPopups(); | ||||
477 | } | ||||
478 | | ||||
479 | void Settings::setPermanentJobPopups(bool enable) | ||||
480 | { | ||||
481 | if (permanentJobPopups() == enable) { | ||||
482 | return; | ||||
483 | } | ||||
484 | JobSettings::setPermanentPopups(enable); | ||||
485 | d->setDirty(true); | ||||
486 | } | ||||
487 | | ||||
488 | bool Settings::badgesInTaskManager() const | ||||
489 | { | ||||
490 | return BadgeSettings::inTaskManager(); | ||||
491 | } | ||||
492 | | ||||
493 | void Settings::setBadgesInTaskManager(bool enable) | ||||
494 | { | ||||
495 | if (badgesInTaskManager() == enable) { | ||||
496 | return; | ||||
497 | } | ||||
498 | BadgeSettings::setInTaskManager(enable); | ||||
499 | d->setDirty(true); | ||||
500 | } | ||||
501 | | ||||
502 | QStringList Settings::knownApplications() const | ||||
503 | { | ||||
504 | return d->applicationsGroup().groupList(); | ||||
505 | } | ||||
506 | | ||||
507 | QStringList Settings::popupBlacklistedApplications() const | ||||
508 | { | ||||
509 | return d->behaviorMatchesList(d->applicationsGroup(), ShowPopups, false); | ||||
510 | } | ||||
511 | | ||||
512 | QStringList Settings::popupBlacklistedServices() const | ||||
513 | { | ||||
514 | return d->behaviorMatchesList(d->servicesGroup(), ShowPopups, false); | ||||
515 | } | ||||
516 | | ||||
517 | QStringList Settings::doNotDisturbPopupWhitelistedApplications() const | ||||
518 | { | ||||
519 | return d->behaviorMatchesList(d->applicationsGroup(), ShowPopupsInDoNotDisturbMode, true); | ||||
520 | } | ||||
521 | | ||||
522 | QStringList Settings::doNotDisturbPopupWhitelistedServices() const | ||||
523 | { | ||||
524 | return d->behaviorMatchesList(d->servicesGroup(), ShowPopupsInDoNotDisturbMode, true); | ||||
525 | } | ||||
526 | | ||||
527 | QStringList Settings::historyBlacklistedApplications() const | ||||
528 | { | ||||
529 | return d->behaviorMatchesList(d->applicationsGroup(), ShowInHistory, false); | ||||
530 | } | ||||
531 | | ||||
532 | QStringList Settings::historyBlacklistedServices() const | ||||
533 | { | ||||
534 | return d->behaviorMatchesList(d->servicesGroup(), ShowInHistory, false); | ||||
535 | } | ||||
536 | | ||||
537 | QDateTime Settings::notificationsInhibitedUntil() const | ||||
538 | { | ||||
539 | return DoNotDisturbSettings::until(); | ||||
540 | } | ||||
541 | | ||||
542 | void Settings::setNotificationsInhibitedUntil(const QDateTime &time) | ||||
543 | { | ||||
544 | DoNotDisturbSettings::setUntil(time); | ||||
545 | d->setDirty(true); | ||||
546 | } | ||||
547 | | ||||
548 | void Settings::resetNotificationsInhibitedUntil() | ||||
549 | { | ||||
550 | setNotificationsInhibitedUntil(QDateTime());// FIXME DoNotDisturbSettings::defaultUntilValue()); | ||||
551 | } | ||||
552 | | ||||
553 | bool Settings::notificationsInhibitedByApplication() const | ||||
554 | { | ||||
555 | return Server::self().inhibited(); | ||||
556 | } | ||||
557 | | ||||
558 | QStringList Settings::notificationInhibitionApplications() const | ||||
559 | { | ||||
560 | return Server::self().inhibitionApplications(); | ||||
561 | } | ||||
562 | | ||||
563 | QStringList Settings::notificationInhibitionReasons() const | ||||
564 | { | ||||
565 | return Server::self().inhibitionReasons(); | ||||
566 | } | ||||
567 | | ||||
568 | void Settings::revokeApplicationInhibitions() | ||||
569 | { | ||||
570 | Server::self().clearInhibitions(); | ||||
571 | } | ||||
572 | | ||||
573 | bool Settings::notificationSoundsInhibited() const | ||||
574 | { | ||||
575 | #ifdef HAVE_PULSEAUDIOQT | ||||
576 | return DoNotDisturbSettings::notificationSoundsMuted(); | ||||
577 | #else | ||||
578 | return false; | ||||
579 | #endif | ||||
580 | } | ||||
581 | | ||||
582 | bool Settings::notificationSoundsMuted() const | ||||
583 | { | ||||
584 | #ifdef HAVE_PULSEAUDIOQT | ||||
585 | return !d->notificationSounds.isNull() & d->notificationSounds->isMuted(); | ||||
586 | #else | ||||
587 | return false; | ||||
588 | #endif | ||||
589 | } | ||||
590 | | ||||
591 | void Settings::setNotificationSoundsMuted(bool muted) | ||||
592 | { | ||||
593 | #ifdef HAVE_PULSEAUDIOQT | ||||
594 | if (d->notificationSounds) { | ||||
595 | d->notificationSounds->setMuted(muted); | ||||
596 | } | ||||
597 | #else | ||||
598 | Q_UNUSED(muted); | ||||
599 | #endif | ||||
600 | } | ||||
601 | | ||||
602 | void Settings::setNotificationSoundsInhibited(bool inhibited) | ||||
603 | { | ||||
604 | if (inhibited == notificationSoundsInhibited()) { | ||||
605 | return; | ||||
606 | } | ||||
607 | | ||||
608 | #ifdef HAVE_PULSEAUDIOQT | ||||
609 | if (!d->notificationSounds) { | ||||
610 | qCInfo(NOTIFICATIONMANAGER) << "Cannot" << (inhibited ? "mute" : "unmute") << "notification sounds without appropriate stream restore"; | ||||
611 | return; | ||||
612 | } | ||||
613 | | ||||
614 | if (inhibited && d->notificationSounds->isMuted()) { | ||||
615 | // Already muted, don't write soundsMuted=true to avoid us unmuting them later | ||||
616 | qCDebug(NOTIFICATIONMANAGER) << "Not muting notification sounds as they already are"; | ||||
617 | return; | ||||
618 | } | ||||
619 | | ||||
620 | d->notificationSounds->setMuted(inhibited); | ||||
621 | | ||||
622 | DoNotDisturbSettings::setNotificationSoundsMuted(inhibited); | ||||
623 | d->setDirty(true); | ||||
624 | #endif | ||||
625 | } |