| 1 | /* |
|---|---|
| 2 | SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | */ |
| 6 | |
| 7 | #include "ksystemclockskewnotifier.h" |
| 8 | #include "ksystemclockskewnotifierengine_p.h" |
| 9 | |
| 10 | class KSystemClockSkewNotifierPrivate |
| 11 | { |
| 12 | public: |
| 13 | explicit KSystemClockSkewNotifierPrivate(KSystemClockSkewNotifier *notifier); |
| 14 | |
| 15 | void loadNotifierEngine(); |
| 16 | void unloadNotifierEngine(); |
| 17 | |
| 18 | KSystemClockSkewNotifier *notifier; |
| 19 | std::shared_ptr<KSystemClockSkewNotifierEngine> engine; |
| 20 | bool isActive = false; |
| 21 | }; |
| 22 | |
| 23 | KSystemClockSkewNotifierPrivate::KSystemClockSkewNotifierPrivate(KSystemClockSkewNotifier *notifier) |
| 24 | : notifier(notifier) |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | void KSystemClockSkewNotifierPrivate::loadNotifierEngine() |
| 29 | { |
| 30 | engine = KSystemClockSkewNotifierEngine::globalInstance(); |
| 31 | |
| 32 | if (engine) { |
| 33 | QObject::connect(sender: engine.get(), signal: &KSystemClockSkewNotifierEngine::skewed, context: notifier, slot: &KSystemClockSkewNotifier::skewed); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | void KSystemClockSkewNotifierPrivate::unloadNotifierEngine() |
| 38 | { |
| 39 | if (!engine) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | QObject::disconnect(sender: engine.get(), signal: &KSystemClockSkewNotifierEngine::skewed, receiver: notifier, slot: &KSystemClockSkewNotifier::skewed); |
| 44 | engine.reset(); |
| 45 | } |
| 46 | |
| 47 | KSystemClockSkewNotifier::KSystemClockSkewNotifier(QObject *parent) |
| 48 | : QObject(parent) |
| 49 | , d(std::make_unique<KSystemClockSkewNotifierPrivate>(args: this)) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | KSystemClockSkewNotifier::~KSystemClockSkewNotifier() |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | bool KSystemClockSkewNotifier::isActive() const |
| 58 | { |
| 59 | return d->isActive; |
| 60 | } |
| 61 | |
| 62 | void KSystemClockSkewNotifier::setActive(bool set) |
| 63 | { |
| 64 | if (d->isActive == set) { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | d->isActive = set; |
| 69 | |
| 70 | if (d->isActive) { |
| 71 | d->loadNotifierEngine(); |
| 72 | } else { |
| 73 | d->unloadNotifierEngine(); |
| 74 | } |
| 75 | |
| 76 | Q_EMIT activeChanged(); |
| 77 | } |
| 78 | |
| 79 | #include "moc_ksystemclockskewnotifier.cpp" |
| 80 |
