| 1 | /* |
|---|---|
| 2 | * SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #include "kcolorschemewatcher.h" |
| 8 | |
| 9 | #if KGUIADDONS_BUILD_DEPRECATED_SINCE(6, 22) |
| 10 | |
| 11 | #include "kcolorschemewatcher_qt.h" |
| 12 | #include "kcolorschemewatcherbackend.h" |
| 13 | |
| 14 | #ifdef Q_OS_WINDOWS |
| 15 | #include "kcolorschemewatcher_win.h" |
| 16 | #endif |
| 17 | |
| 18 | #ifdef Q_OS_MACOS |
| 19 | #include "kcolorschemewatcher_mac.h" |
| 20 | #endif |
| 21 | |
| 22 | #ifdef QT_DBUS_LIB |
| 23 | #include "kcolorschemewatcher_xdg.h" |
| 24 | #endif |
| 25 | |
| 26 | class KColorSchemeWatcherPrivate |
| 27 | { |
| 28 | public: |
| 29 | std::unique_ptr<KColorSchemeWatcherBackend> backend; |
| 30 | |
| 31 | KColorSchemeWatcherPrivate() |
| 32 | { |
| 33 | #ifdef Q_OS_WINDOWS |
| 34 | backend = std::make_unique<KColorSchemeWatcherWin>(); |
| 35 | #elif defined(Q_OS_MACOS) |
| 36 | backend = std::make_unique<KColorSchemeWatcherMac>(); |
| 37 | #elif defined(QT_DBUS_LIB) |
| 38 | backend = std::make_unique<KColorSchemeWatcherXDG>(); |
| 39 | #else |
| 40 | backend = std::make_unique<KColorSchemeWatcherQt>(); |
| 41 | #endif |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | KColorSchemeWatcher::KColorSchemeWatcher(QObject *parent) |
| 46 | : QObject(parent) |
| 47 | , d(new KColorSchemeWatcherPrivate) |
| 48 | { |
| 49 | if (d->backend) { |
| 50 | connect(sender: d->backend.get(), signal: &KColorSchemeWatcherBackend::systemPreferenceChanged, context: this, slot: &KColorSchemeWatcher::systemPreferenceChanged); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | KColorSchemeWatcher::~KColorSchemeWatcher() |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | KColorSchemeWatcher::ColorPreference KColorSchemeWatcher::systemPreference() const |
| 59 | { |
| 60 | if (d->backend) { |
| 61 | return d->backend->systemPreference(); |
| 62 | } |
| 63 | |
| 64 | return NoPreference; |
| 65 | } |
| 66 | |
| 67 | #include "moc_kcolorschemewatcher.cpp" |
| 68 | |
| 69 | #endif |
| 70 |
