Changeset View
Changeset View
Standalone View
Standalone View
libnotificationmanager/settings.cpp
Show All 20 Lines | |||||
21 | #include "settings.h" | 21 | #include "settings.h" | ||
22 | 22 | | |||
23 | #include <QDebug> | 23 | #include <QDebug> | ||
24 | 24 | | |||
25 | #include <KConfigWatcher> | 25 | #include <KConfigWatcher> | ||
26 | #include <KService> | 26 | #include <KService> | ||
27 | 27 | | |||
28 | #include "server.h" | 28 | #include "server.h" | ||
29 | #include "mirroredscreenstracker_p.h" | ||||
29 | #include "debug.h" | 30 | #include "debug.h" | ||
30 | 31 | | |||
31 | // Settings | 32 | // Settings | ||
32 | #include "donotdisturbsettings.h" | 33 | #include "donotdisturbsettings.h" | ||
33 | #include "notificationsettings.h" | 34 | #include "notificationsettings.h" | ||
34 | #include "jobsettings.h" | 35 | #include "jobsettings.h" | ||
35 | #include "badgesettings.h" | 36 | #include "badgesettings.h" | ||
36 | 37 | | |||
Show All 17 Lines | 42 | public: | |||
54 | 55 | | |||
55 | Settings *q; | 56 | Settings *q; | ||
56 | 57 | | |||
57 | KSharedConfig::Ptr config; | 58 | KSharedConfig::Ptr config; | ||
58 | 59 | | |||
59 | KConfigWatcher::Ptr watcher; | 60 | KConfigWatcher::Ptr watcher; | ||
60 | QMetaObject::Connection watcherConnection; | 61 | QMetaObject::Connection watcherConnection; | ||
61 | 62 | | |||
63 | MirroredScreensTracker::Ptr mirroredScreensTracker; | ||||
64 | | ||||
62 | bool live = false; // set to true initially in constructor | 65 | bool live = false; // set to true initially in constructor | ||
63 | bool dirty = false; | 66 | bool dirty = false; | ||
64 | 67 | | |||
65 | }; | 68 | }; | ||
66 | 69 | | |||
67 | Settings::Private::Private(Settings *q) | 70 | Settings::Private::Private(Settings *q) | ||
68 | : q(q) | 71 | : q(q) | ||
69 | { | 72 | { | ||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Line(s) | 168 | { | |||
175 | } | 178 | } | ||
176 | 179 | | |||
177 | setLive(true); | 180 | setLive(true); | ||
178 | 181 | | |||
179 | connect(&Server::self(), &Server::inhibitedChanged, | 182 | connect(&Server::self(), &Server::inhibitedChanged, | ||
180 | this, &Settings::notificationsInhibitedByApplicationChanged); | 183 | this, &Settings::notificationsInhibitedByApplicationChanged); | ||
181 | connect(&Server::self(), &Server::inhibitionApplicationsChanged, | 184 | connect(&Server::self(), &Server::inhibitionApplicationsChanged, | ||
182 | this, &Settings::notificationInhibitionApplicationsChanged); | 185 | this, &Settings::notificationInhibitionApplicationsChanged); | ||
186 | | ||||
187 | if (DoNotDisturbSettings::whenScreensMirrored()) { | ||||
188 | d->mirroredScreensTracker = MirroredScreensTracker::createTracker(); | ||||
189 | connect(d->mirroredScreensTracker.data(), &MirroredScreensTracker::screensMirroredChanged, this, &Settings::screensMirroredChanged); | ||||
190 | } | ||||
183 | } | 191 | } | ||
184 | 192 | | |||
185 | Settings::~Settings() | 193 | Settings::~Settings() | ||
186 | { | 194 | { | ||
187 | d->config->markAsClean(); | 195 | d->config->markAsClean(); | ||
188 | } | 196 | } | ||
189 | 197 | | |||
190 | Settings::NotificationBehaviors Settings::applicationBehavior(const QString &desktopEntry) const | 198 | Settings::NotificationBehaviors Settings::applicationBehavior(const QString &desktopEntry) const | ||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Line(s) | 296 | { | |||
295 | if (live) { | 303 | if (live) { | ||
296 | d->watcher = KConfigWatcher::create(d->config); | 304 | d->watcher = KConfigWatcher::create(d->config); | ||
297 | d->watcherConnection = connect(d->watcher.data(), &KConfigWatcher::configChanged, this, | 305 | d->watcherConnection = connect(d->watcher.data(), &KConfigWatcher::configChanged, this, | ||
298 | [this](const KConfigGroup &group, const QByteArrayList &names) { | 306 | [this](const KConfigGroup &group, const QByteArrayList &names) { | ||
299 | Q_UNUSED(names); | 307 | Q_UNUSED(names); | ||
300 | 308 | | |||
301 | if (group.name() == QLatin1String("DoNotDisturb")) { | 309 | if (group.name() == QLatin1String("DoNotDisturb")) { | ||
302 | DoNotDisturbSettings::self()->load(); | 310 | DoNotDisturbSettings::self()->load(); | ||
311 | | ||||
312 | bool emitScreensMirroredChanged = false; | ||||
313 | if (DoNotDisturbSettings::whenScreensMirrored()) { | ||||
314 | if (!d->mirroredScreensTracker) { | ||||
315 | d->mirroredScreensTracker = MirroredScreensTracker::createTracker(); | ||||
316 | emitScreensMirroredChanged = d->mirroredScreensTracker->screensMirrored(); | ||||
317 | connect(d->mirroredScreensTracker.data(), &MirroredScreensTracker::screensMirroredChanged, this, &Settings::screensMirroredChanged); | ||||
318 | } | ||||
319 | } else if (d->mirroredScreensTracker) { | ||||
320 | emitScreensMirroredChanged = d->mirroredScreensTracker->screensMirrored(); | ||||
321 | d->mirroredScreensTracker.reset(); | ||||
322 | } | ||||
323 | | ||||
324 | if (emitScreensMirroredChanged) { | ||||
325 | emit screensMirroredChanged(); | ||||
326 | } | ||||
303 | } else if (group.name() == QLatin1String("Notifications")) { | 327 | } else if (group.name() == QLatin1String("Notifications")) { | ||
304 | NotificationSettings::self()->load(); | 328 | NotificationSettings::self()->load(); | ||
305 | } else if (group.name() == QLatin1String("Jobs")) { | 329 | } else if (group.name() == QLatin1String("Jobs")) { | ||
306 | JobSettings::self()->load(); | 330 | JobSettings::self()->load(); | ||
307 | } else if (group.name() == QLatin1String("Badges")) { | 331 | } else if (group.name() == QLatin1String("Badges")) { | ||
308 | BadgeSettings::self()->load(); | 332 | BadgeSettings::self()->load(); | ||
309 | } | 333 | } | ||
310 | 334 | | |||
▲ Show 20 Lines • Show All 225 Lines • ▼ Show 20 Line(s) | 559 | { | |||
536 | return Server::self().inhibitionApplications(); | 560 | return Server::self().inhibitionApplications(); | ||
537 | } | 561 | } | ||
538 | 562 | | |||
539 | QStringList Settings::notificationInhibitionReasons() const | 563 | QStringList Settings::notificationInhibitionReasons() const | ||
540 | { | 564 | { | ||
541 | return Server::self().inhibitionReasons(); | 565 | return Server::self().inhibitionReasons(); | ||
542 | } | 566 | } | ||
543 | 567 | | |||
568 | bool Settings::inhibitNotificationsWhenScreensMirrored() const | ||||
569 | { | ||||
570 | return DoNotDisturbSettings::whenScreensMirrored(); | ||||
571 | } | ||||
572 | | ||||
573 | void Settings::setInhibitNotificationsWhenScreensMirrored(bool inhibit) | ||||
574 | { | ||||
575 | if (inhibit == inhibitNotificationsWhenScreensMirrored()) { | ||||
576 | return; | ||||
577 | } | ||||
578 | | ||||
579 | DoNotDisturbSettings::setWhenScreensMirrored(inhibit); | ||||
580 | d->setDirty(true); | ||||
581 | } | ||||
582 | | ||||
583 | bool Settings::screensMirrored() const | ||||
584 | { | ||||
585 | return d->mirroredScreensTracker && d->mirroredScreensTracker->screensMirrored(); | ||||
586 | } | ||||
587 | | ||||
588 | void Settings::setScreensMirrored(bool mirrored) | ||||
589 | { | ||||
590 | if (mirrored) { | ||||
591 | qCWarning(NOTIFICATIONMANAGER) << "Cannot forcefully set screens mirrored"; | ||||
592 | return; | ||||
593 | } | ||||
594 | | ||||
595 | if (d->mirroredScreensTracker) { | ||||
596 | d->mirroredScreensTracker->setScreensMirrored(mirrored); | ||||
597 | } | ||||
598 | } | ||||
599 | | ||||
544 | void Settings::revokeApplicationInhibitions() | 600 | void Settings::revokeApplicationInhibitions() | ||
545 | { | 601 | { | ||
546 | Server::self().clearInhibitions(); | 602 | Server::self().clearInhibitions(); | ||
547 | } | 603 | } | ||
548 | 604 | | |||
549 | bool Settings::notificationSoundsInhibited() const | 605 | bool Settings::notificationSoundsInhibited() const | ||
550 | { | 606 | { | ||
551 | return DoNotDisturbSettings::notificationSoundsMuted(); | 607 | return DoNotDisturbSettings::notificationSoundsMuted(); | ||
Show All 11 Lines |