File indexing completed on 2024-11-10 04:57:03

0001 /*
0002     SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "clockskewnotifier.h"
0008 #include "clockskewnotifierengine_p.h"
0009 
0010 namespace KWin
0011 {
0012 
0013 class ClockSkewNotifier::Private
0014 {
0015 public:
0016     void loadNotifierEngine();
0017     void unloadNotifierEngine();
0018 
0019     ClockSkewNotifier *notifier = nullptr;
0020     ClockSkewNotifierEngine *engine = nullptr;
0021     bool isActive = false;
0022 };
0023 
0024 void ClockSkewNotifier::Private::loadNotifierEngine()
0025 {
0026     engine = ClockSkewNotifierEngine::create(notifier);
0027 
0028     if (engine) {
0029         QObject::connect(engine, &ClockSkewNotifierEngine::clockSkewed, notifier, &ClockSkewNotifier::clockSkewed);
0030     }
0031 }
0032 
0033 void ClockSkewNotifier::Private::unloadNotifierEngine()
0034 {
0035     if (!engine) {
0036         return;
0037     }
0038 
0039     QObject::disconnect(engine, &ClockSkewNotifierEngine::clockSkewed, notifier, &ClockSkewNotifier::clockSkewed);
0040     engine->deleteLater();
0041 
0042     engine = nullptr;
0043 }
0044 
0045 ClockSkewNotifier::ClockSkewNotifier(QObject *parent)
0046     : QObject(parent)
0047     , d(new Private)
0048 {
0049     d->notifier = this;
0050 }
0051 
0052 ClockSkewNotifier::~ClockSkewNotifier()
0053 {
0054 }
0055 
0056 bool ClockSkewNotifier::isActive() const
0057 {
0058     return d->isActive;
0059 }
0060 
0061 void ClockSkewNotifier::setActive(bool set)
0062 {
0063     if (d->isActive == set) {
0064         return;
0065     }
0066 
0067     d->isActive = set;
0068 
0069     if (d->isActive) {
0070         d->loadNotifierEngine();
0071     } else {
0072         d->unloadNotifierEngine();
0073     }
0074 
0075     Q_EMIT activeChanged();
0076 }
0077 
0078 } // namespace KWin
0079 
0080 #include "moc_clockskewnotifier.cpp"