diff --git a/applets/CMakeLists.txt b/applets/CMakeLists.txt --- a/applets/CMakeLists.txt +++ b/applets/CMakeLists.txt @@ -16,6 +16,7 @@ add_subdirectory(fuzzy-clock) add_subdirectory(grouping) add_subdirectory(mediaframe) +add_subdirectory(nightcolor) add_subdirectory(notes) add_subdirectory(quicklaunch) add_subdirectory(quickshare) diff --git a/applets/nightcolor/CMakeLists.txt b/applets/nightcolor/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/applets/nightcolor/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(plugin) + +plasma_install_package(package org.kde.plasma.nightcolorcontrol) diff --git a/applets/nightcolor/Messages.sh b/applets/nightcolor/Messages.sh new file mode 100644 --- /dev/null +++ b/applets/nightcolor/Messages.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +$XGETTEXT `find . -name \*.qml` -o $podir/plasma_applet_org.kde.plasma.nightcolorcontrol.pot diff --git a/applets/nightcolor/package/contents/ui/main.qml b/applets/nightcolor/package/contents/ui/main.qml new file mode 100644 --- /dev/null +++ b/applets/nightcolor/package/contents/ui/main.qml @@ -0,0 +1,108 @@ +/* + * Copyright 2019 Vlad Zahorodnii + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.5 + +import org.kde.kquickcontrolsaddons 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.plasmoid 2.0 + +import org.kde.plasma.private.nightcolorcontrol 1.0 + +Item { + id: root + + Plasmoid.icon: monitor.running ? 'redshift-status-on' : 'redshift-status-off' + + Plasmoid.status: { + // Display the applet in the system tray when Night Color is active. + if (monitor.enabled && monitor.targetTemperature != 6500) { + return PlasmaCore.Types.ActiveStatus; + } + if (inhibitor.state != Inhibitor.Uninhibited) { + return PlasmaCore.Types.ActiveStatus; + } + return PlasmaCore.Types.PassiveStatus; + } + + Plasmoid.toolTipMainText: i18n('Night Color Control') + Plasmoid.toolTipSubText: { + if (inhibitor.state == Inhibitor.Inhibited) { + return i18n("Night Color is inhibited"); + } + if (!monitor.available) { + return i18n("Night Color is unavailable"); + } + if (!monitor.enabled) { + return i18n("Night Color is disabled"); + } + if (!monitor.running) { + return i18n("Night Color is not running"); + } + return i18n('Night Color is active (%1K)', monitor.currentTemperature); + } + + Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation + + Plasmoid.compactRepresentation: PlasmaCore.IconItem { + active: compactMouseArea.containsMouse + source: plasmoid.icon + + MouseArea { + id: compactMouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: toggleInhibition() + } + } + + Plasmoid.onActivated: toggleInhibition() + + function toggleInhibition() { + if (!monitor.available) { + return; + } + switch (inhibitor.state) { + case Inhibitor.Inhibiting: + case Inhibitor.Inhibited: + inhibitor.uninhibit(); + break; + case Inhibitor.Uninhibiting: + case Inhibitor.Uninhibited: + inhibitor.inhibit(); + break; + } + } + + function action_KCMNightColor() { + KCMShell.open("kcm_nightcolor"); + } + + Inhibitor { + id: inhibitor + } + Monitor { + id: monitor + } + + Component.onCompleted: { + if (KCMShell.authorize("kcm_nightcolor.desktop").length > 0) { + plasmoid.setAction("KCMNightColor", i18n("Configure Night Color..."), "configure"); + } + plasmoid.removeAction("configure"); + } +} diff --git a/applets/nightcolor/package/metadata.desktop b/applets/nightcolor/package/metadata.desktop new file mode 100644 --- /dev/null +++ b/applets/nightcolor/package/metadata.desktop @@ -0,0 +1,21 @@ +[Desktop Entry] +Name=Night Color Control +Comment=Plasmoid for controlling Night Color +Icon=preferences-desktop-display-nightcolor + +Type=Service +X-KDE-ServiceTypes=Plasma/Applet +X-KDE-PluginInfo-Author=Vlad Zahorodnii +X-KDE-PluginInfo-Category=Graphics +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-Email=vladzzag@gmail.com +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-PluginInfo-License=GPL-2.0+ +X-KDE-PluginInfo-Name=org.kde.plasma.nightcolorcontrol +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=plasma.kde.org + +X-Plasma-API=declarativeappletscript +X-Plasma-MainScript=ui/main.qml +X-Plasma-NotificationArea=true +X-Plasma-NotificationAreaCategory=SystemServices diff --git a/applets/nightcolor/plugin/CMakeLists.txt b/applets/nightcolor/plugin/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/applets/nightcolor/plugin/CMakeLists.txt @@ -0,0 +1,16 @@ +set(nightcolorcontrolplugin_SOURCES + inhibitor.cpp + monitor.cpp + plugin.cpp +) + +add_library(nightcolorcontrolplugin SHARED ${nightcolorcontrolplugin_SOURCES}) +target_link_libraries(nightcolorcontrolplugin + Qt5::Core + Qt5::DBus + Qt5::Gui + Qt5::Qml +) + +install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/nightcolorcontrol) +install(TARGETS nightcolorcontrolplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/nightcolorcontrol) diff --git a/applets/nightcolor/plugin/inhibitor.h b/applets/nightcolor/plugin/inhibitor.h new file mode 100644 --- /dev/null +++ b/applets/nightcolor/plugin/inhibitor.h @@ -0,0 +1,85 @@ +/* + * Copyright 2019 Vlad Zahorodnii + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +/** + * The Inhibitor class provides a convenient way to temporarily disable Night Color. + */ +class Inhibitor : public QObject +{ + Q_OBJECT + /** + * This property holds a value to indicate the current state of the inhibitor. + */ + Q_PROPERTY(State state READ state NOTIFY stateChanged) + +public: + explicit Inhibitor(QObject *parent = nullptr); + ~Inhibitor() override; + + /** + * This enum type is used to specify the state of the inhibitor. + */ + enum State { + Inhibiting, ///< Night Color is being inhibited. + Inhibited, ///< Night Color is inhibited. + Uninhibiting, ///< Night Color is being uninhibited. + Uninhibited, ///< Night Color is uninhibited. + }; + Q_ENUM(State) + + /** + * Returns the current state of the inhibitor. + */ + State state() const; + +public Q_SLOTS: + /** + * Attempts to temporarily disable Night Color. + * + * After calling this method, the inhibitor will enter the Inhibiting state. + * Eventually, the inhibitor will enter the Inhibited state when the inhibition + * request has been processed successfully by the Night Color manager. + * + * This method does nothing if the inhibitor is in the Inhibited state. + */ + void inhibit(); + + /** + * Attempts to undo the previous call to inhibit() method. + * + * After calling this method, the inhibitor will enter the Uninhibiting state. + * Eventually, the inhibitor will enter the Uninhibited state when the uninhibition + * request has been processed by the Night Color manager. + * + * This method does nothing if the inhibitor is in the Uninhibited state. + */ + void uninhibit(); + +Q_SIGNALS: + /** + * Emitted whenever the state of the inhibitor has changed. + */ + void stateChanged(); + +private: + class Private; + QScopedPointer d; +}; diff --git a/applets/nightcolor/plugin/inhibitor.cpp b/applets/nightcolor/plugin/inhibitor.cpp new file mode 100644 --- /dev/null +++ b/applets/nightcolor/plugin/inhibitor.cpp @@ -0,0 +1,141 @@ +/* + * Copyright 2019 Vlad Zahorodnii + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "inhibitor.h" + +#include +#include +#include +#include +#include + +Q_LOGGING_CATEGORY(NIGHTCOLOR_CONTROL, "org.kde.plasma.nightcolorcontrol") + +static const QString s_serviceName = QStringLiteral("org.kde.KWin"); +static const QString s_path = QStringLiteral("/ColorCorrect"); +static const QString s_interface = QStringLiteral("org.kde.kwin.ColorCorrect"); + +class Inhibitor::Private +{ +public: + uint cookie = 0; + State state = Uninhibited; + bool pendingUninhibit = false; +}; + +Inhibitor::Inhibitor(QObject *parent) + : QObject(parent) + , d(new Private) +{ +} + +Inhibitor::~Inhibitor() +{ + uninhibit(); +} + +Inhibitor::State Inhibitor::state() const +{ + return d->state; +} + +void Inhibitor::inhibit() +{ + if (d->state == Inhibited) { + return; + } + + d->pendingUninhibit = false; + + if (d->state == Inhibiting) { + return; + } + + QDBusMessage message = QDBusMessage::createMethodCall(s_serviceName, + s_path, + s_interface, + QStringLiteral("inhibit")); + + QDBusPendingReply cookie = QDBusConnection::sessionBus().asyncCall(message); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(cookie, this); + + connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *self) { + const bool wasPendingUninhibit = d->pendingUninhibit; + d->pendingUninhibit = false; + + const QDBusPendingReply reply = *self; + self->deleteLater(); + + if (reply.isError()) { + qCWarning(NIGHTCOLOR_CONTROL()) << "Could not inhibit Night Color:" << reply.error().message(); + d->state = Uninhibited; + emit stateChanged(); + return; + } + + d->cookie = reply.value(); + d->state = Inhibited; + emit stateChanged(); + + if (wasPendingUninhibit) { + uninhibit(); + } + }); + + d->state = Inhibiting; + emit stateChanged(); +} + +void Inhibitor::uninhibit() +{ + if (d->state == Uninhibiting || d->state == Uninhibited) { + return; + } + + if (d->state == Inhibiting) { + d->pendingUninhibit = true; + return; + } + + QDBusMessage message = QDBusMessage::createMethodCall(s_serviceName, + s_path, + s_interface, + QStringLiteral("uninhibit")); + message.setArguments({ d->cookie }); + + QDBusPendingReply reply = QDBusConnection::sessionBus().asyncCall(message); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + + connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *self) { + self->deleteLater(); + + if (d->state != Uninhibiting) { + return; + } + + const QDBusPendingReply reply = *self; + if (reply.isError()) { + qCWarning(NIGHTCOLOR_CONTROL) << "Could not uninhibit Night Color:" << reply.error().message(); + } + + d->state = Uninhibited; + emit stateChanged(); + }); + + d->state = Uninhibiting; + emit stateChanged(); +} diff --git a/applets/nightcolor/plugin/monitor.h b/applets/nightcolor/plugin/monitor.h new file mode 100644 --- /dev/null +++ b/applets/nightcolor/plugin/monitor.h @@ -0,0 +1,113 @@ +/* + * Copyright 2019 Vlad Zahorodnii + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +class MonitorPrivate; + +/** + * The Monitor provides a way for monitoring the state of Night Color. + */ +class Monitor : public QObject +{ + Q_OBJECT + + /** + * This property holds a value to indicate if Night Color is available. + */ + Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged) + + /** + * This property holds a value to indicate if Night Color is enabled. + */ + Q_PROPERTY(bool enabled READ isEnabled NOTIFY enabledChanged) + + /** + * This property holds a value to indicate if Night Color is running. + */ + Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged) + + /** + * This property holds a value to indicate currently applied color temperature. + */ + Q_PROPERTY(int currentTemperature READ currentTemperature NOTIFY currentTemperatureChanged) + + /** + * This property holds a value to indicate currently applied color temperature. + */ + Q_PROPERTY(int targetTemperature READ targetTemperature NOTIFY targetTemperatureChanged) + +public: + explicit Monitor(QObject *parent = nullptr); + ~Monitor() override; + + /** + * Returns @c true if Night Color is available; otherwise @c false. + */ + bool isAvailable() const; + + /** + * Returns @c true if Night Color is enabled; otherwise @c false. + */ + bool isEnabled() const; + + /** + * Returns @c true if Night Color is running; otherwise @c false. + */ + bool isRunning() const; + + /** + * Returns currently applied screen color temperature. + */ + int currentTemperature() const; + + /** + * Returns currently applied screen color temperature. + */ + int targetTemperature() const; + +Q_SIGNALS: + /** + * This signal is emitted when Night Color becomes (un)available. + */ + void availableChanged(); + + /** + * Emitted whenever Night Color is enabled or disabled. + */ + void enabledChanged(); + + /** + * Emitted whenever Night Color starts or stops running. + */ + void runningChanged(); + + /** + * Emitted whenever the current screen color temperature has changed. + */ + void currentTemperatureChanged(); + + /** + * Emitted whenever the current screen color temperature has changed. + */ + void targetTemperatureChanged(); + +private: + MonitorPrivate *d; +}; diff --git a/applets/nightcolor/plugin/monitor.cpp b/applets/nightcolor/plugin/monitor.cpp new file mode 100644 --- /dev/null +++ b/applets/nightcolor/plugin/monitor.cpp @@ -0,0 +1,238 @@ +/* + * Copyright 2019 Vlad Zahorodnii + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "monitor.h" +#include "monitor_p.h" + +#include +#include +#include +#include +#include + +static const QString s_serviceName = QStringLiteral("org.kde.KWin"); +static const QString s_nightColorPath = QStringLiteral("/ColorCorrect"); +static const QString s_nightColorInterface = QStringLiteral("org.kde.kwin.ColorCorrect"); +static const QString s_propertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); + +MonitorPrivate::MonitorPrivate(QObject *parent) + : QObject(parent) +{ + QDBusServiceWatcher *watcher = new QDBusServiceWatcher(s_serviceName, + QDBusConnection::sessionBus(), + QDBusServiceWatcher::WatchForOwnerChange, + this); + connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &MonitorPrivate::handleServiceRegistered); + connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, &MonitorPrivate::handleServiceUnregistered); + + handleServiceRegistered(); +} + +MonitorPrivate::~MonitorPrivate() +{ +} + +void MonitorPrivate::handleServiceRegistered() +{ + QDBusConnection bus = QDBusConnection::sessionBus(); + + const bool connected = bus.connect(s_serviceName, s_nightColorPath, s_propertiesInterface, + QStringLiteral("PropertiesChanged"), + this, SLOT(handlePropertiesChanged(QString,QVariantMap,QStringList))); + if (!connected) { + return; + } + + QDBusMessage message = QDBusMessage::createMethodCall(s_serviceName, + s_nightColorPath, + s_propertiesInterface, + QStringLiteral("GetAll")); + message.setArguments({ s_nightColorInterface }); + + QDBusPendingReply properties = bus.asyncCall(message); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(properties, this); + + connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *self) { + self->deleteLater(); + + const QDBusPendingReply properties = *self; + if (properties.isError()) { + return; + } + + updateProperties(properties.value()); + }); +} + +void MonitorPrivate::handleServiceUnregistered() +{ + QDBusConnection bus = QDBusConnection::sessionBus(); + + bus.disconnect(s_serviceName, s_nightColorPath, s_propertiesInterface, + QStringLiteral("PropertiesChanged"), + this, SLOT(handlePropertiesChanged(QString,QVariantMap,QStringList))); + + setAvailable(false); +} + +void MonitorPrivate::handlePropertiesChanged(const QString &interfaceName, + const QVariantMap &changedProperties, + const QStringList &invalidatedProperties) +{ + Q_UNUSED(interfaceName) + Q_UNUSED(invalidatedProperties) + + updateProperties(changedProperties); +} + +int MonitorPrivate::currentTemperature() const +{ + return m_currentTemperature; +} + +int MonitorPrivate::targetTemperature() const +{ + return m_targetTemperature; +} + +void MonitorPrivate::updateProperties(const QVariantMap &properties) +{ + const QVariant available = properties.value(QStringLiteral("available")); + if (available.isValid()) { + setAvailable(available.toBool()); + } + + const QVariant enabled = properties.value(QStringLiteral("enabled")); + if (enabled.isValid()) { + setEnabled(enabled.toBool()); + } + + const QVariant running = properties.value(QStringLiteral("running")); + if (running.isValid()) { + setRunning(running.toBool()); + } + + const QVariant currentTemperature = properties.value(QStringLiteral("currentTemperature")); + if (currentTemperature.isValid()) { + setCurrentTemperature(currentTemperature.toInt()); + } + + const QVariant targetTemperature = properties.value(QStringLiteral("targetTemperature")); + if (targetTemperature.isValid()) { + setTargetTemperature(targetTemperature.toInt()); + } +} + +void MonitorPrivate::setCurrentTemperature(int temperature) +{ + if (m_currentTemperature == temperature) { + return; + } + m_currentTemperature = temperature; + emit currentTemperatureChanged(); +} + +void MonitorPrivate::setTargetTemperature(int temperature) +{ + if (m_targetTemperature == temperature) { + return; + } + m_targetTemperature = temperature; + emit targetTemperatureChanged(); +} + +bool MonitorPrivate::isAvailable() const +{ + return m_isAvailable; +} + +void MonitorPrivate::setAvailable(bool available) +{ + if (m_isAvailable == available) { + return; + } + m_isAvailable = available; + emit availableChanged(); +} + +bool MonitorPrivate::isEnabled() const +{ + return m_isEnabled; +} + +void MonitorPrivate::setEnabled(bool enabled) +{ + if (m_isEnabled == enabled) { + return; + } + m_isEnabled = enabled; + emit enabledChanged(); +} + +bool MonitorPrivate::isRunning() const +{ + return m_isRunning; +} + +void MonitorPrivate::setRunning(bool running) +{ + if (m_isRunning == running) { + return; + } + m_isRunning = running; + emit runningChanged(); +} + +Monitor::Monitor(QObject *parent) + : QObject(parent) + , d(new MonitorPrivate(this)) +{ + connect(d, &MonitorPrivate::availableChanged, this, &Monitor::availableChanged); + connect(d, &MonitorPrivate::enabledChanged, this, &Monitor::enabledChanged); + connect(d, &MonitorPrivate::runningChanged, this, &Monitor::runningChanged); + connect(d, &MonitorPrivate::currentTemperatureChanged, this, &Monitor::currentTemperatureChanged); + connect(d, &MonitorPrivate::targetTemperatureChanged, this, &Monitor::targetTemperatureChanged); +} + +Monitor::~Monitor() +{ +} + +bool Monitor::isAvailable() const +{ + return d->isAvailable(); +} + +bool Monitor::isEnabled() const +{ + return d->isEnabled(); +} + +bool Monitor::isRunning() const +{ + return d->isRunning(); +} + +int Monitor::currentTemperature() const +{ + return d->currentTemperature(); +} + +int Monitor::targetTemperature() const +{ + return d->targetTemperature(); +} diff --git a/applets/nightcolor/plugin/monitor_p.h b/applets/nightcolor/plugin/monitor_p.h new file mode 100644 --- /dev/null +++ b/applets/nightcolor/plugin/monitor_p.h @@ -0,0 +1,63 @@ +/* + * Copyright 2019 Vlad Zahorodnii + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +class MonitorPrivate : public QObject +{ + Q_OBJECT + +public: + explicit MonitorPrivate(QObject *parent = nullptr); + ~MonitorPrivate() override; + + int currentTemperature() const; + int targetTemperature() const; + bool isAvailable() const; + bool isEnabled() const; + bool isRunning() const; + +Q_SIGNALS: + void currentTemperatureChanged(); + void targetTemperatureChanged(); + void availableChanged(); + void enabledChanged(); + void runningChanged(); + +private Q_SLOTS: + void handleServiceRegistered(); + void handleServiceUnregistered(); + void handlePropertiesChanged(const QString &interfaceName, + const QVariantMap &changedProperties, + const QStringList &invalidatedProperties); + +private: + void updateProperties(const QVariantMap &properties); + void setCurrentTemperature(int temperature); + void setTargetTemperature(int temperature); + void setAvailable(bool available); + void setEnabled(bool enabled); + void setRunning(bool running); + + int m_currentTemperature = 0; + int m_targetTemperature = 0; + bool m_isAvailable = false; + bool m_isEnabled = false; + bool m_isRunning = false; +}; diff --git a/applets/nightcolor/plugin/plugin.h b/applets/nightcolor/plugin/plugin.h new file mode 100644 --- /dev/null +++ b/applets/nightcolor/plugin/plugin.h @@ -0,0 +1,29 @@ +/* + * Copyright 2019 Vlad Zahorodnii + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +class NightColorControlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) override; +}; diff --git a/applets/nightcolor/plugin/plugin.cpp b/applets/nightcolor/plugin/plugin.cpp new file mode 100644 --- /dev/null +++ b/applets/nightcolor/plugin/plugin.cpp @@ -0,0 +1,29 @@ +/* + * Copyright 2019 Vlad Zahorodnii + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "plugin.h" +#include "inhibitor.h" +#include "monitor.h" + +#include + +void NightColorControlPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.private.nightcolorcontrol")); + qmlRegisterType(uri, 1, 0, "Inhibitor"); + qmlRegisterType(uri, 1, 0, "Monitor"); +} diff --git a/applets/nightcolor/plugin/qmldir b/applets/nightcolor/plugin/qmldir new file mode 100644 --- /dev/null +++ b/applets/nightcolor/plugin/qmldir @@ -0,0 +1,2 @@ +module org.kde.plasma.private.nightcolorcontrol +plugin nightcolorcontrolplugin