diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -20,6 +20,7 @@ add_subdirectory(mousepad) add_subdirectory(screensaver-inhibit) add_subdirectory(sftp) + add_subdirectory(systemvolume) endif() if(EXPERIMENTALAPP_ENABLED) add_subdirectory(remotecommands) diff --git a/plugins/systemvolume/CMakeLists.txt b/plugins/systemvolume/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/plugins/systemvolume/CMakeLists.txt @@ -0,0 +1,9 @@ +set(kdeconnect_systemvolume_SRCS + systemvolumeplugin.cpp +) + +kdeconnect_add_plugin(kdeconnect_systemvolume JSON kdeconnect_systemvolume.json SOURCES ${kdeconnect_systemvolume_SRCS}) + +target_link_libraries(kdeconnect_systemvolume + kdeconnectcore +) diff --git a/plugins/systemvolume/README b/plugins/systemvolume/README new file mode 100644 --- /dev/null +++ b/plugins/systemvolume/README @@ -0,0 +1 @@ +This plugin allows to control the system volume. diff --git a/plugins/systemvolume/kdeconnect_systemvolume.json b/plugins/systemvolume/kdeconnect_systemvolume.json new file mode 100644 --- /dev/null +++ b/plugins/systemvolume/kdeconnect_systemvolume.json @@ -0,0 +1,28 @@ +{ + "Encoding": "UTF-8", + "KPlugin": { + "Authors": [ + { + "Email": "nicolas.fella@gmx.de", + "Name": "Nicolas Fella" + } + ], + "Description": "Control the system volume from your phone", + "EnabledByDefault": true, + "Icon": "audio-volume-high", + "Id": "kdeconnect_systemvolume", + "License": "GPL", + "Name": "System volume", + "ServiceTypes": [ + "KdeConnect/Plugin" + ], + "Version": "0.1", + "Website": "http://albertvaka.wordpress.com" + }, + "X-KdeConnect-OutgoingPackageType": [ + "kdeconnect.systemvolume" + ], + "X-KdeConnect-SupportedPackageType": [ + "kdeconnect.systemvolume" + ] +} diff --git a/plugins/systemvolume/systemvolumeplugin.h b/plugins/systemvolume/systemvolumeplugin.h new file mode 100644 --- /dev/null +++ b/plugins/systemvolume/systemvolumeplugin.h @@ -0,0 +1,45 @@ +/** + * Copyright 2017 Nicolas Fella + * + * 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 SYSTEMVOLUMEPLUGIN_H +#define SYSTEMVOLUMEPLUGIN_H + +#include + +#include + +#define PACKAGE_TYPE_SYSTEMVOLUME QStringLiteral("kdeconnect.systemvolume") + +class Q_DECL_EXPORT SystemvolumePlugin + : public KdeConnectPlugin +{ + Q_OBJECT + +public: + explicit SystemvolumePlugin(QObject* parent, const QVariantList& args); + ~SystemvolumePlugin() override; + + bool receivePackage(const NetworkPackage& np) override; + void connected() override {} + void setSystemVolume(int volume); + +}; + +#endif diff --git a/plugins/systemvolume/systemvolumeplugin.cpp b/plugins/systemvolume/systemvolumeplugin.cpp new file mode 100644 --- /dev/null +++ b/plugins/systemvolume/systemvolumeplugin.cpp @@ -0,0 +1,69 @@ +/** + * Copyright 2017 Nicolas Fella + * + * 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 "systemvolumeplugin.h" + +#include + +#include +#include +#include + +#include + +K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_systemvolume.json", registerPlugin< SystemvolumePlugin >(); ) + +Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_SYSTEMVOLUME, "kdeconnect.plugin.systemvolume") + +SystemvolumePlugin::SystemvolumePlugin(QObject* parent, const QVariantList& args) + : KdeConnectPlugin(parent, args) +{} + +SystemvolumePlugin::~SystemvolumePlugin() +{} + +bool SystemvolumePlugin::receivePackage(const NetworkPackage& np) +{ + if (np.type() == PACKAGE_TYPE_SYSTEMVOLUME) { + + if (np.get(QStringLiteral("request"))) { + //TODO Send current system volume +// NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_SYSTEMVOLUME); +// np->set(QStringLiteral("request", false)); + } else { + qCDebug(KDECONNECT_PLUGIN_SYSTEMVOLUME) << "sedding volume"; + setSystemVolume(np.get("volume")); + } + return true; + } + + return true; +} + +void SystemvolumePlugin::setSystemVolume(int volume) +{ + int vol = (volume*65536)/100; + QString command = QStringLiteral("pactl set-sink-volume @DEFAULT_SINK@ ")+QString::number(vol); + QProcess::startDetached(command); +} + + +#include "systemvolumeplugin.moc" +