KDarkLightScheduleProvider Class

The KDarkLightScheduleProvider provides a convenient way to retrieve the schedule of the dark-light cycle. More...

Header: #include <KDarkLightScheduleProvider>
CMake: find_package(KNightTime REQUIRED)
target_link_libraries(mytarget PRIVATE KNightTime::KNightTime)
Inherits: QObject

Public Functions

KDarkLightScheduleProvider(const QString &state = QString(), QObject *parent = nullptr)
KDarkLightSchedule schedule() const
QString state() const

Signals

Detailed Description

Example usage:

auto stateConfig = KSharedConfig::openStateConfig();
auto provider = new KDarkLightScheduleProvider(stateConfig->group(QStringLiteral("DarkLightCycle")).readEntry(QStringLiteral("State")));
connect(provider, &KDarkLightScheduleProvider::scheduleChanged, [provider, stateConfig]() {
    stateConfig->group(QStringLiteral("DarkLightCycle")).writeEntry(QStringLiteral("State"), provider->state());
    stateConfig->sync();

    qDebug() << "next transition:" << provider->schedule().nextTransition(QDateTime::currentDateTime());
});

qDebug() << "next transition:" << provider->schedule().nextTransition(QDateTime::currentDateTime());

Member Function Documentation

[explicit] KDarkLightScheduleProvider::KDarkLightScheduleProvider(const QString &state = QString(), QObject *parent = nullptr)

Constructs the schedule provider. If a state string is specified, the previous schedule will be restored.

If no state string is given, the provider will use the default schedule until the current one is retrieved asynchronously. With the default schedule, morning lasts from 6:00AM to 6:30AM, and evening lasts from 6:00PM to 6:30PM.

KDarkLightSchedule KDarkLightScheduleProvider::schedule() const

Returns the schedule of the dark-light cycle.

[signal] void KDarkLightScheduleProvider::scheduleChanged()

This signal is emitted when the schedule is refreshed.

QString KDarkLightScheduleProvider::state() const

Returns the corresponding state string. The state string can be stored in a state config to restore the schedule after a reboot. It can be used to reduce the number of unnecessary animations at system startup.