kwin/plugins/nightcolor/clockskewnotifier.cpp
Vlad Zahorodnii bdfb946267 Convert Night Color into a plugin
Night Color adjusts the color temperature based on the current time in
your location. It's not a generic color correction module per se.

We need a central component that can be used by both night color and
colord integration to tweak gamma ramps and which will be able to
resolve conflicts between the two. The Night Color manager cannot be
such a thing because of its very specific usecase.

This change converts Night Color into a plugin to prepare some space for
such a component.

The tricky part is that the dbus api of Night Color has "ColorCorrect"
in its name. I'm afraid we cannot do that much about it without breaking
API compatibility.
2020-11-27 18:55:01 +00:00

78 lines
1.5 KiB
C++

/*
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "clockskewnotifier.h"
#include "clockskewnotifierengine_p.h"
namespace KWin
{
class ClockSkewNotifier::Private
{
public:
void loadNotifierEngine();
void unloadNotifierEngine();
ClockSkewNotifier *notifier = nullptr;
ClockSkewNotifierEngine *engine = nullptr;
bool isActive = false;
};
void ClockSkewNotifier::Private::loadNotifierEngine()
{
engine = ClockSkewNotifierEngine::create(notifier);
if (engine) {
QObject::connect(engine, &ClockSkewNotifierEngine::clockSkewed, notifier, &ClockSkewNotifier::clockSkewed);
}
}
void ClockSkewNotifier::Private::unloadNotifierEngine()
{
if (!engine) {
return;
}
QObject::disconnect(engine, &ClockSkewNotifierEngine::clockSkewed, notifier, &ClockSkewNotifier::clockSkewed);
engine->deleteLater();
engine = nullptr;
}
ClockSkewNotifier::ClockSkewNotifier(QObject *parent)
: QObject(parent)
, d(new Private)
{
d->notifier = this;
}
ClockSkewNotifier::~ClockSkewNotifier()
{
}
bool ClockSkewNotifier::isActive() const
{
return d->isActive;
}
void ClockSkewNotifier::setActive(bool set)
{
if (d->isActive == set) {
return;
}
d->isActive = set;
if (d->isActive) {
d->loadNotifierEngine();
} else {
d->unloadNotifierEngine();
}
emit activeChanged();
}
} // namespace KWin