diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt --- a/interfaces/CMakeLists.txt +++ b/interfaces/CMakeLists.txt @@ -44,6 +44,7 @@ geninterface(${CMAKE_SOURCE_DIR}/plugins/lockdevice/lockdeviceplugin.h lockdeviceinterface) geninterface(${CMAKE_SOURCE_DIR}/plugins/remotecommands/remotecommandsplugin.h remotecommandsinterface) geninterface(${CMAKE_SOURCE_DIR}/plugins/remotekeyboard/remotekeyboardplugin.h remotekeyboardinterface) +geninterface(${CMAKE_SOURCE_DIR}/plugins/remotebrightness/remotebrightnessplugin.h remotebrightnessinterface) geninterface(${CMAKE_SOURCE_DIR}/plugins/telephony/telephonyplugin.h telephonyinterface) diff --git a/interfaces/dbusinterfaces.h b/interfaces/dbusinterfaces.h --- a/interfaces/dbusinterfaces.h +++ b/interfaces/dbusinterfaces.h @@ -35,6 +35,7 @@ #include "interfaces/lockdeviceinterface.h" #include "interfaces/remotecommandsinterface.h" #include "interfaces/remotekeyboardinterface.h" +#include "interfaces/remotebrightnessinterface.h" #include "interfaces/telephonyinterface.h" /** @@ -197,6 +198,24 @@ void remoteStateChanged(bool state); }; +class KDECONNECTINTERFACES_EXPORT RemoteBrightnessDbusInterface + : public OrgKdeKdeconnectDeviceRemotebrightnessInterface +{ + Q_OBJECT + Q_PROPERTY(int brightness READ remoteBrightness NOTIFY brightnessChanged) + Q_PROPERTY(int brightnessMin READ remoteBrightnessMin NOTIFY brightnessMinChanged) + Q_PROPERTY(int brightnessMax READ remoteBrightnessMax NOTIFY brightnessMaxChanged) + Q_PROPERTY(int brightnessSteps READ remoteBrightnessSteps NOTIFY brightnessStepsChanged) +public: + explicit RemoteBrightnessDbusInterface(const QString& deviceId, QObject* parent = nullptr); + ~RemoteBrightnessDbusInterface() override; +Q_SIGNALS: + void brightnessChanged(); + void brightnessMinChanged(); + void brightnessMaxChanged(); + void brightnessStepsChanged(); +}; + class KDECONNECTINTERFACES_EXPORT TelephonyDbusInterface : public OrgKdeKdeconnectDeviceTelephonyInterface { diff --git a/interfaces/dbusinterfaces.cpp b/interfaces/dbusinterfaces.cpp --- a/interfaces/dbusinterfaces.cpp +++ b/interfaces/dbusinterfaces.cpp @@ -165,6 +165,22 @@ RemoteKeyboardDbusInterface::~RemoteKeyboardDbusInterface() = default; +RemoteBrightnessDbusInterface::RemoteBrightnessDbusInterface(const QString& deviceId, QObject* parent): + OrgKdeKdeconnectDeviceRemotebrightnessInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/remotebrightness", QDBusConnection::sessionBus(), parent) +{ + // map signals onto some with Q_PROPERTY matching signature + connect(this, &OrgKdeKdeconnectDeviceRemotebrightnessInterface::remoteBrightnessChanged, + this, &RemoteBrightnessDbusInterface::brightnessChanged); + connect(this, &OrgKdeKdeconnectDeviceRemotebrightnessInterface::remoteBrightnessMinChanged, + this, &RemoteBrightnessDbusInterface::brightnessMinChanged); + connect(this, &OrgKdeKdeconnectDeviceRemotebrightnessInterface::remoteBrightnessMaxChanged, + this, &RemoteBrightnessDbusInterface::brightnessMaxChanged); + connect(this, &OrgKdeKdeconnectDeviceRemotebrightnessInterface::remoteBrightnessStepsChanged, + this, &RemoteBrightnessDbusInterface::brightnessStepsChanged); +} + +RemoteBrightnessDbusInterface::~RemoteBrightnessDbusInterface() = default; + TelephonyDbusInterface::TelephonyDbusInterface(const QString& deviceId, QObject* parent): OrgKdeKdeconnectDeviceTelephonyInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + deviceId + "/telephony", QDBusConnection::sessionBus(), parent) { diff --git a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp --- a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp +++ b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp @@ -53,6 +53,11 @@ return new RemoteKeyboardDbusInterface(deviceId.toString()); } +QObject* createRemoteBrightnessInterface(const QVariant& deviceId) +{ + return new RemoteBrightnessDbusInterface(deviceId.toString()); +} + QObject* createSftpInterface(const QVariant& deviceId) { return new SftpDbusInterface(deviceId.toString()); @@ -94,6 +99,7 @@ qmlRegisterUncreatableType(uri, 1, 0, "LockDeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess")); qmlRegisterUncreatableType(uri, 1, 0, "FindMyPhoneDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess")); qmlRegisterUncreatableType(uri, 1, 0, "RemoteKeyboardDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess")); + qmlRegisterUncreatableType(uri, 1, 0, "RemoteBrightnessDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess")); qmlRegisterUncreatableType(uri, 1, 0, "DeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfacess")); qmlRegisterSingletonType(uri, 1, 0, "DaemonDbusInterface", [](QQmlEngine*, QJSEngine*) -> QObject* { @@ -121,6 +127,9 @@ engine->rootContext()->setContextProperty(QStringLiteral("RemoteKeyboardDbusInterfaceFactory") , new ObjectFactory(engine, createRemoteKeyboardInterface)); + engine->rootContext()->setContextProperty(QStringLiteral("RemoteBrightnessDbusInterfaceFactory") + , new ObjectFactory(engine, createRemoteBrightnessInterface)); + engine->rootContext()->setContextProperty(QStringLiteral("MprisDbusInterfaceFactory") , new ObjectFactory(engine, createMprisInterface)); diff --git a/plasmoid/package/contents/ui/DeviceDelegate.qml b/plasmoid/package/contents/ui/DeviceDelegate.qml --- a/plasmoid/package/contents/ui/DeviceDelegate.qml +++ b/plasmoid/package/contents/ui/DeviceDelegate.qml @@ -30,6 +30,15 @@ id: root readonly property QtObject device: DeviceDbusInterfaceFactory.create(model.deviceId) + RemoteBrightness { + id: remoteBrightness + device: root.device + + onBrightnessChanged: { + remoteBrightnessControl.updateFromeRemote(brightness); + } + } + RemoteKeyboard { id: remoteKeyboard device: root.device @@ -150,6 +159,58 @@ width: parent.width } + //RemoteBritghness + PlasmaComponents.ListItem { + visible: remoteBrightness.available + width: parent.width + + Row { + width: parent.width + spacing: 5 + + PlasmaComponents.Label { + id: remoteBrightnessLabel + text: i18n("Remote Brightness") + } + + PlasmaComponents.Slider { + id: remoteBrightnessControl + + property bool updatingFromRemote: false + property int pendingUpdateFromRemote: -1 + + function updateFromeRemote(brightness) { + if (pressed) { + pendingUpdateFromRemote = brightness; + } else { + updatingFromRemote = true; + value = brightness; + updatingFromRemote = false; + } + } + + width: parent.width - 5 - remoteBrightnessLabel.width + minimumValue: remoteBrightness.brightnessMin + maximumValue: remoteBrightness.brightnessMax + stepSize: 1 + onValueChanged: { + if (!updatingFromRemote) { + remoteBrightness.setBrightness(value); + } + } + onPressedChanged: { + if (!pressed && pendingUpdateFromRemote !== -1) { + updatingFromRemote = true; + value = pendingUpdateFromRemote; + pendingUpdateFromRemote = -1; + updatingFromRemote = false; + } + } + } + } + } + + //RemoteKeyboard PlasmaComponents.ListItem { visible: remoteKeyboardInput.available diff --git a/plasmoid/package/contents/ui/RemoteBrightness.qml b/plasmoid/package/contents/ui/RemoteBrightness.qml new file mode 100644 --- /dev/null +++ b/plasmoid/package/contents/ui/RemoteBrightness.qml @@ -0,0 +1,61 @@ +/** + * Copyright 2018 Friedrich W. H. Kossebau + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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.1 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.kdeconnect 1.0 + +QtObject { + + id: root + + property alias device: checker.device + readonly property alias available: checker.available + + readonly property PluginChecker pluginChecker: PluginChecker { + id: checker + pluginName: "remotebrightness" + } + + readonly property int brightnessMin: available ? remoteBrightness.brightnessMin : 0 + readonly property int brightnessMax: available ? remoteBrightness.brightnessMax : 0 + + property variant remoteBrightness: null + + signal brightnessChanged(int brightness) + + function setBrightness(brightness) { + if (remoteBrightness) { + remoteBrightness.setRemoteBrightness(brightness); + } + } + + onAvailableChanged: { + if (available) { + remoteBrightness = RemoteBrightnessDbusInterfaceFactory.create(device.id()); + remoteBrightness.brightnessChanged.connect(function() { + root.brightnessChanged(remoteBrightness.brightness); + }); + } else { + remoteBrightness = null + } + } +} diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -10,6 +10,7 @@ add_subdirectory(battery) add_subdirectory(findmyphone) add_subdirectory(remotekeyboard) +add_subdirectory(remotebrightness) if(WIN32) add_subdirectory(mousepad_windows) else() @@ -20,6 +21,7 @@ add_subdirectory(mousepad) add_subdirectory(screensaver-inhibit) add_subdirectory(sftp) + add_subdirectory(brightness) endif() if(EXPERIMENTALAPP_ENABLED) add_subdirectory(remotecommands) diff --git a/plugins/brightness/CMakeLists.txt b/plugins/brightness/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/plugins/brightness/CMakeLists.txt @@ -0,0 +1,13 @@ +set(kdeconnect_brightness_SRCS + brightnessplugin.cpp +) + +qt5_add_dbus_interface(kdeconnect_brightness_SRCS org.kde.Solid.PowerManagement.Actions.BrightnessControl.xml brightnesscontroldbusinterface) + +kdeconnect_add_plugin(kdeconnect_brightness JSON kdeconnect_brightness.json SOURCES ${kdeconnect_brightness_SRCS}) + +target_link_libraries(kdeconnect_brightness + kdeconnectcore + Qt5::DBus + KF5::I18n +) diff --git a/plugins/brightness/README b/plugins/brightness/README new file mode 100644 --- /dev/null +++ b/plugins/brightness/README @@ -0,0 +1,2 @@ + +TODO diff --git a/plugins/brightness/brightnessplugin.h b/plugins/brightness/brightnessplugin.h new file mode 100644 --- /dev/null +++ b/plugins/brightness/brightnessplugin.h @@ -0,0 +1,58 @@ +/** + * Copyright 2018 Friedrich W. H. Kossebau + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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 . + */ + +#ifndef BRIGHTNESSPLUGIN_H +#define BRIGHTNESSPLUGIN_H + +#include + +class OrgKdeSolidPowerManagementActionsBrightnessControlInterface; + +#define PACKET_TYPE_BRIGHTNESS QStringLiteral("kdeconnect.brightness") + +// TODO: support also redshift/nightshift modes +// investigate about per-screen brightness +class Q_DECL_EXPORT BrightnessPlugin + : public KdeConnectPlugin +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.brightness") + +public: + explicit BrightnessPlugin(QObject* parent, const QVariantList& args); + ~BrightnessPlugin() override; + + bool receivePacket(const NetworkPacket& np) override; + void connected() override; + + QString dbusPath() const override; + +private: + void onLocalBrightnessChanged(int brightness); + void onLocalBrightnessMaxChanged(int brightnessMax); + + int brightnessMinForBrightnessMax(int brightnessMax) const; + OrgKdeSolidPowerManagementActionsBrightnessControlInterface* iface(); + +private: + OrgKdeSolidPowerManagementActionsBrightnessControlInterface* m_iface; +}; + +#endif diff --git a/plugins/brightness/brightnessplugin.cpp b/plugins/brightness/brightnessplugin.cpp new file mode 100644 --- /dev/null +++ b/plugins/brightness/brightnessplugin.cpp @@ -0,0 +1,123 @@ +/** + * Copyright 2018 Friedrich W. H. Kossebau + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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 "brightnessplugin.h" + +// plugin +#include +#include +// KF +#include +#include +// Qt +#include +#include +#include + +K_PLUGIN_FACTORY_WITH_JSON(KdeConnectPluginFactory, "kdeconnect_brightness.json", registerPlugin(); ) + +Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_BRIGHTNESS, "kdeconnect.plugin.brightness") + + +BrightnessPlugin::BrightnessPlugin(QObject* parent, const QVariantList& args) + : KdeConnectPlugin(parent, args) + , m_iface(nullptr) +{ +} + +BrightnessPlugin::~BrightnessPlugin() +{ +} + +void BrightnessPlugin::connected() +{ +} + +bool BrightnessPlugin::receivePacket(const NetworkPacket& np) +{ + if (np.has(QStringLiteral("setBrightness"))) { + const int newBrightness = np.get(QStringLiteral("setBrightness")); + const int brightnessMax = iface()->brightnessMax(); + if ((brightnessMinForBrightnessMax(brightnessMax) <= newBrightness) && (newBrightness <= brightnessMax)) { + iface()->setBrightness(newBrightness); + } + } + if (np.has(QStringLiteral("requestBrightness"))) { + NetworkPacket np(PACKET_TYPE_BRIGHTNESS); + np.set(QStringLiteral("brightness"), iface()->brightness()); + // TODO: given these values belong together and are not expected to change individually, + // should they rather be messaged as a combined struct (also internally)? + np.set(QStringLiteral("brightnessMin"), brightnessMinForBrightnessMax(iface()->brightnessMax())); + np.set(QStringLiteral("brightnessMax"), iface()->brightnessMax()); + np.set(QStringLiteral("brightnessSteps"), iface()->brightnessSteps()); + sendPacket(np); + } + + return true; +} + +QString BrightnessPlugin::dbusPath() const +{ + return "/modules/kdeconnect/devices/" + device()->id() + "/brightness"; +} + +void BrightnessPlugin::onLocalBrightnessChanged(int brightness) +{ + NetworkPacket np(PACKET_TYPE_BRIGHTNESS); + np.set(QStringLiteral("brightness"), brightness); + sendPacket(np); +} + +void BrightnessPlugin::onLocalBrightnessMaxChanged(int brightnessMax) +{ + NetworkPacket np(PACKET_TYPE_BRIGHTNESS); + np.set(QStringLiteral("brightnessMin"), brightnessMinForBrightnessMax(brightnessMax)); + np.set(QStringLiteral("brightnessMax"), brightnessMax); + sendPacket(np); +} + +int BrightnessPlugin::brightnessMinForBrightnessMax(int brightnessMax) const +{ + // Don't allow the slider to turn off the screen + // Please see https://git.reviewboard.kde.org/r/122505/ for more information + return brightnessMax > 100 ? 1 : 0; +} + +OrgKdeSolidPowerManagementActionsBrightnessControlInterface* BrightnessPlugin::iface() +{ + if (!m_iface) { + m_iface = new OrgKdeSolidPowerManagementActionsBrightnessControlInterface( + QStringLiteral("org.kde.Solid.PowerManagement"), + QStringLiteral("/org/kde/Solid/PowerManagement/Actions/BrightnessControl"), + QDBusConnection::sessionBus(), this); + // TODO: how do we know no-one is interested in further updates? + connect(m_iface, &OrgKdeSolidPowerManagementActionsBrightnessControlInterface::brightnessChanged, + this, &BrightnessPlugin::onLocalBrightnessChanged); + connect(m_iface, &OrgKdeSolidPowerManagementActionsBrightnessControlInterface::brightnessMaxChanged, + this, &BrightnessPlugin::onLocalBrightnessMaxChanged); + if (!m_iface->isValid()) { + qCWarning(KDECONNECT_PLUGIN_BRIGHTNESS) << "Couldn't connect to the PowerManagement interface"; + } + } + + return m_iface; +} + +#include "brightnessplugin.moc" diff --git a/plugins/brightness/kdeconnect_brightness.json b/plugins/brightness/kdeconnect_brightness.json new file mode 100644 --- /dev/null +++ b/plugins/brightness/kdeconnect_brightness.json @@ -0,0 +1,26 @@ +{ + "KPlugin": { + "Authors": [ + { + "Email": "kossebau@kde.org", + "Name": "Friedrich W. H. Kossebau" + } + ], + "Name": "Brightness", + "Description": "Report brightness of screen", + "EnabledByDefault": true, + "Icon": "contrast", + "Id": "kdeconnect_brightness", + "License": "GPL", + "ServiceTypes": [ + "KdeConnect/Plugin" + ], + "Version": "0.1" + }, + "X-KdeConnect-OutgoingPacketType": [ + "kdeconnect.brightness" + ], + "X-KdeConnect-SupportedPacketType": [ + "kdeconnect.brightness.request" + ] +} diff --git a/plugins/brightness/org.kde.Solid.PowerManagement.Actions.BrightnessControl.xml b/plugins/brightness/org.kde.Solid.PowerManagement.Actions.BrightnessControl.xml new file mode 100644 --- /dev/null +++ b/plugins/brightness/org.kde.Solid.PowerManagement.Actions.BrightnessControl.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/remotebrightness/CMakeLists.txt b/plugins/remotebrightness/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/plugins/remotebrightness/CMakeLists.txt @@ -0,0 +1,11 @@ +set(kdeconnect_remotebrightness_SRCS + remotebrightnessplugin.cpp +) + +kdeconnect_add_plugin(kdeconnect_remotebrightness JSON kdeconnect_remotebrightness.json SOURCES ${kdeconnect_remotebrightness_SRCS}) + +target_link_libraries(kdeconnect_remotebrightness + kdeconnectcore + Qt5::DBus + KF5::I18n +) diff --git a/plugins/remotebrightness/README b/plugins/remotebrightness/README new file mode 100644 --- /dev/null +++ b/plugins/remotebrightness/README @@ -0,0 +1,2 @@ + +TODO diff --git a/plugins/remotebrightness/kdeconnect_remotebrightness.json b/plugins/remotebrightness/kdeconnect_remotebrightness.json new file mode 100644 --- /dev/null +++ b/plugins/remotebrightness/kdeconnect_remotebrightness.json @@ -0,0 +1,26 @@ +{ + "KPlugin": { + "Authors": [ + { + "Email": "kossebau@kde.org", + "Name": "Friedrich W. H. Kossebau" + } + ], + "Name": "Remote brightness", + "Description": "Control brightness of remote screen", + "EnabledByDefault": true, + "Icon": "contrast", + "Id": "kdeconnect_remotebrightness", + "License": "GPL", + "ServiceTypes": [ + "KdeConnect/Plugin" + ], + "Version": "0.1" + }, + "X-KdeConnect-OutgoingPacketType": [ + "kdeconnect.brightness.request" + ], + "X-KdeConnect-SupportedPacketType": [ + "kdeconnect.brightness" + ] +} diff --git a/plugins/remotebrightness/remotebrightnessplugin.h b/plugins/remotebrightness/remotebrightnessplugin.h new file mode 100644 --- /dev/null +++ b/plugins/remotebrightness/remotebrightnessplugin.h @@ -0,0 +1,66 @@ +/** + * Copyright 2018 Friedrich W. H. Kossebau + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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 . + */ + +#ifndef REMOTEBRIGHTNESSPLUGIN_H +#define REMOTEBRIGHTNESSPLUGIN_H + +#include + +#define PACKET_TYPE_BRIGHTNESS_REQUEST QStringLiteral("kdeconnect.brightness.request") + +// TODO: support also redshift/nightshift modes +// look into seeing this exposed as Plasma "system" property, so it is covered in the general brightmess control +// investigate about per-screen brightness +class Q_DECL_EXPORT RemoteBrightnessPlugin + : public KdeConnectPlugin +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.remotebrightness") + +public: + explicit RemoteBrightnessPlugin(QObject* parent, const QVariantList& args); + ~RemoteBrightnessPlugin() override; + + bool receivePacket(const NetworkPacket& np) override; + void connected() override; + + QString dbusPath() const override; + +public: + Q_SCRIPTABLE int remoteBrightness() const; + Q_SCRIPTABLE int remoteBrightnessMin() const; + Q_SCRIPTABLE int remoteBrightnessMax() const; + Q_SCRIPTABLE int remoteBrightnessSteps() const; + Q_SCRIPTABLE void setRemoteBrightness(int brightness); + +Q_SIGNALS: + Q_SCRIPTABLE void remoteBrightnessChanged(int brightness); + Q_SCRIPTABLE void remoteBrightnessMinChanged(int brightnessMin); + Q_SCRIPTABLE void remoteBrightnessMaxChanged(int brightnessMax); + Q_SCRIPTABLE void remoteBrightnessStepsChanged(int brightnessSteps); + +private: + int m_remoteBrightness; + int m_remoteBrightnessMin; + int m_remoteBrightnessMax; + int m_remoteBrightnessSteps; +}; + +#endif diff --git a/plugins/remotebrightness/remotebrightnessplugin.cpp b/plugins/remotebrightness/remotebrightnessplugin.cpp new file mode 100644 --- /dev/null +++ b/plugins/remotebrightness/remotebrightnessplugin.cpp @@ -0,0 +1,126 @@ +/** + * Copyright 2018 Friedrich W. H. Kossebau + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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 "remotebrightnessplugin.h" + +// plugin +#include +// KF +#include +#include +// Qt +#include +#include + +K_PLUGIN_FACTORY_WITH_JSON(KdeConnectPluginFactory, "kdeconnect_remotebrightness.json", + registerPlugin(); ) + +Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_BRIGHTNESS, "kdeconnect.plugin.remotebrightness") + + +RemoteBrightnessPlugin::RemoteBrightnessPlugin(QObject* parent, const QVariantList& args) + : KdeConnectPlugin(parent, args) + , m_remoteBrightness(0) + , m_remoteBrightnessMin(0) + , m_remoteBrightnessMax(0) + , m_remoteBrightnessSteps(1) +{ +} + +RemoteBrightnessPlugin::~RemoteBrightnessPlugin() +{ +} + +void RemoteBrightnessPlugin::connected() +{ + NetworkPacket np(PACKET_TYPE_BRIGHTNESS_REQUEST); + np.set(QStringLiteral("requestBrightness"), true); + sendPacket(np); +} + +bool RemoteBrightnessPlugin::receivePacket(const NetworkPacket& np) +{ + // change notification? + if (np.has(QStringLiteral("brightnessMin"))) { + const int brightnessMin = np.get(QStringLiteral("brightnessMin")); + if (m_remoteBrightnessMin != brightnessMin) { + m_remoteBrightnessMin = brightnessMin; + Q_EMIT remoteBrightnessMinChanged(brightnessMin); + } + } + if (np.has(QStringLiteral("brightnessMax"))) { + const int brightnessMax = np.get(QStringLiteral("brightnessMax")); + if (m_remoteBrightnessMax != brightnessMax) { + m_remoteBrightnessMax = brightnessMax; + Q_EMIT remoteBrightnessMaxChanged(brightnessMax); + } + } + if (np.has(QStringLiteral("brightnessSteps"))) { + const int brightnessSteps = np.get(QStringLiteral("brightnessSteps")); + if (m_remoteBrightnessSteps != brightnessSteps) { + m_remoteBrightnessSteps = brightnessSteps; + Q_EMIT remoteBrightnessStepsChanged(brightnessSteps); + } + } + if (np.has(QStringLiteral("brightness"))) { + const int brightness = np.get(QStringLiteral("brightness")); + if (m_remoteBrightness != brightness) { + m_remoteBrightness = brightness; + Q_EMIT remoteBrightnessChanged(brightness); + } + } + + return true; +} + +QString RemoteBrightnessPlugin::dbusPath() const +{ + return "/modules/kdeconnect/devices/" + device()->id() + "/remotebrightness"; +} + +int RemoteBrightnessPlugin::remoteBrightness() const +{ + return m_remoteBrightness; +} + +int RemoteBrightnessPlugin::remoteBrightnessMax() const +{ + return m_remoteBrightnessMax; +} + +int RemoteBrightnessPlugin::remoteBrightnessMin() const +{ + return m_remoteBrightnessMin; +} + +int RemoteBrightnessPlugin::remoteBrightnessSteps() const +{ + return m_remoteBrightnessSteps; +} + +void RemoteBrightnessPlugin::setRemoteBrightness(int brightness) +{ + // TODO: check range here and discard, or leave to receiver? + NetworkPacket np(PACKET_TYPE_BRIGHTNESS_REQUEST); + np.set(QStringLiteral("setBrightness"), brightness); + sendPacket(np); +} + +#include "remotebrightnessplugin.moc"