Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nicolas Fella <nicolas.fella@gmx.de>
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
*/
|
|
|
|
|
2018-11-20 00:14:17 +00:00
|
|
|
#include "systemvolumeplugin-pulse.h"
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
|
|
|
|
#include <KPluginFactory>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QProcess>
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
|
|
|
|
#include <core/device.h>
|
|
|
|
|
2020-05-26 17:55:47 +01:00
|
|
|
#include "plugin_systemvolume_debug.h"
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <PulseAudioQt/Context>
|
|
|
|
#include <PulseAudioQt/Sink>
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
|
2019-06-12 21:16:54 +01:00
|
|
|
K_PLUGIN_CLASS_WITH_JSON(SystemvolumePlugin, "kdeconnect_systemvolume.json")
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
SystemvolumePlugin::SystemvolumePlugin(QObject *parent, const QVariantList &args)
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
: KdeConnectPlugin(parent, args)
|
|
|
|
, sinksMap()
|
|
|
|
{
|
2022-09-10 22:23:52 +01:00
|
|
|
}
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
bool SystemvolumePlugin::receivePacket(const NetworkPacket &np)
|
|
|
|
{
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
if (!PulseAudioQt::Context::instance()->isValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (np.has(QStringLiteral("requestSinks"))) {
|
|
|
|
sendSinkList();
|
|
|
|
} else {
|
|
|
|
QString name = np.get<QString>(QStringLiteral("name"));
|
|
|
|
|
2020-04-29 04:45:25 +01:00
|
|
|
PulseAudioQt::Sink *sink = sinksMap.value(name);
|
|
|
|
if (sink) {
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
if (np.has(QStringLiteral("volume"))) {
|
2020-04-29 04:45:25 +01:00
|
|
|
int volume = np.get<int>(QStringLiteral("volume"));
|
|
|
|
sink->setVolume(volume);
|
|
|
|
sink->setMuted(false);
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
}
|
|
|
|
if (np.has(QStringLiteral("muted"))) {
|
2020-04-29 04:45:25 +01:00
|
|
|
sink->setMuted(np.get<bool>(QStringLiteral("muted")));
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
}
|
2020-11-23 15:19:01 +00:00
|
|
|
if (np.has(QStringLiteral("enabled"))) {
|
|
|
|
sink->setDefault(np.get<bool>(QStringLiteral("enabled")));
|
|
|
|
}
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
void SystemvolumePlugin::sendSinkList()
|
|
|
|
{
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
QJsonDocument document;
|
|
|
|
QJsonArray array;
|
|
|
|
|
|
|
|
sinksMap.clear();
|
|
|
|
|
2018-11-25 22:58:24 +00:00
|
|
|
const auto sinks = PulseAudioQt::Context::instance()->sinks();
|
2022-09-10 22:23:52 +01:00
|
|
|
for (PulseAudioQt::Sink *sink : sinks) {
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
sinksMap.insert(sink->name(), sink);
|
|
|
|
|
|
|
|
connect(sink, &PulseAudioQt::Sink::volumeChanged, this, [this, sink] {
|
|
|
|
NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME);
|
|
|
|
np.set<int>(QStringLiteral("volume"), sink->volume());
|
|
|
|
np.set<QString>(QStringLiteral("name"), sink->name());
|
|
|
|
sendPacket(np);
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(sink, &PulseAudioQt::Sink::mutedChanged, this, [this, sink] {
|
|
|
|
NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME);
|
|
|
|
np.set<bool>(QStringLiteral("muted"), sink->isMuted());
|
|
|
|
np.set<QString>(QStringLiteral("name"), sink->name());
|
|
|
|
sendPacket(np);
|
|
|
|
});
|
|
|
|
|
2020-11-23 15:17:30 +00:00
|
|
|
connect(sink, &PulseAudioQt::Sink::defaultChanged, this, [this, sink] {
|
|
|
|
NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME);
|
|
|
|
np.set<bool>(QStringLiteral("enabled"), sink->isDefault());
|
|
|
|
np.set<QString>(QStringLiteral("name"), sink->name());
|
|
|
|
sendPacket(np);
|
|
|
|
});
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
QJsonObject sinkObject{{QStringLiteral("name"), sink->name()},
|
|
|
|
{QStringLiteral("muted"), sink->isMuted()},
|
|
|
|
{QStringLiteral("description"), sink->description()},
|
|
|
|
{QStringLiteral("volume"), sink->volume()},
|
|
|
|
{QStringLiteral("maxVolume"), PulseAudioQt::normalVolume()},
|
|
|
|
{QStringLiteral("enabled"), sink->isDefault()}};
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
|
|
|
|
array.append(sinkObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.setArray(array);
|
|
|
|
|
|
|
|
NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME);
|
|
|
|
np.set<QJsonDocument>(QStringLiteral("sinkList"), document);
|
|
|
|
sendPacket(np);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemvolumePlugin::connected()
|
|
|
|
{
|
|
|
|
connect(PulseAudioQt::Context::instance(), &PulseAudioQt::Context::sinkAdded, this, [this] {
|
|
|
|
sendSinkList();
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(PulseAudioQt::Context::instance(), &PulseAudioQt::Context::sinkRemoved, this, [this] {
|
|
|
|
sendSinkList();
|
|
|
|
});
|
|
|
|
|
2018-11-25 22:58:24 +00:00
|
|
|
const auto sinks = PulseAudioQt::Context::instance()->sinks();
|
2022-09-10 22:23:52 +01:00
|
|
|
for (PulseAudioQt::Sink *sink : sinks) {
|
Add systemvolume plugin
Summary: This plugin allows controlling the system value from a remote device.
Test Plan: Apply Android patch, open up MPRIS Activity and play with the slider
Reviewers: #kde_connect, mtijink, albertvaka
Reviewed By: #kde_connect, albertvaka
Subscribers: kdeconnect, apol, zhigalin, albertvaka, davidedmundson, mtijink, #kde_connect
Tags: #kde_connect
Maniphest Tasks: T4659
Differential Revision: https://phabricator.kde.org/D7992
2018-07-27 07:39:46 +01:00
|
|
|
sinksMap.insert(sink->name(), sink);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 00:14:17 +00:00
|
|
|
#include "systemvolumeplugin-pulse.moc"
|