2018-11-07 19:54:00 +00:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de>
|
2018-11-07 19:54:00 +00: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
|
2018-11-07 19:54:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "remotesystemvolumeplugin.h"
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KPluginFactory>
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QDebug>
|
2018-11-07 19:54:00 +00:00
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
|
|
|
#include <core/daemon.h>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <core/device.h>
|
2018-11-07 19:54:00 +00:00
|
|
|
|
2020-05-26 17:55:47 +01:00
|
|
|
#include "plugin_remotesystemvolume_debug.h"
|
2018-11-07 19:54:00 +00:00
|
|
|
|
2020-05-26 17:55:47 +01:00
|
|
|
K_PLUGIN_CLASS_WITH_JSON(RemoteSystemVolumePlugin, "kdeconnect_remotesystemvolume.json")
|
2018-11-07 19:54:00 +00:00
|
|
|
|
2023-07-31 08:25:45 +01:00
|
|
|
void RemoteSystemVolumePlugin::receivePacket(const NetworkPacket &np)
|
2018-11-07 19:54:00 +00:00
|
|
|
{
|
|
|
|
if (np.has(QStringLiteral("sinkList"))) {
|
|
|
|
QJsonDocument document(np.get<QJsonArray>(QStringLiteral("sinkList")));
|
|
|
|
m_sinks = document.toJson();
|
|
|
|
Q_EMIT sinksChanged();
|
|
|
|
} else {
|
|
|
|
QString name = np.get<QString>(QStringLiteral("name"));
|
|
|
|
|
|
|
|
if (np.has(QStringLiteral("volume"))) {
|
|
|
|
Q_EMIT volumeChanged(name, np.get<int>(QStringLiteral("volume")));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (np.has(QStringLiteral("muted"))) {
|
|
|
|
Q_EMIT mutedChanged(name, np.get<int>(QStringLiteral("muted")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
void RemoteSystemVolumePlugin::sendVolume(const QString &name, int volume)
|
2018-11-07 19:54:00 +00:00
|
|
|
{
|
|
|
|
NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME_REQUEST);
|
|
|
|
np.set<QString>(QStringLiteral("name"), name);
|
|
|
|
np.set<int>(QStringLiteral("volume"), volume);
|
|
|
|
sendPacket(np);
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
void RemoteSystemVolumePlugin::sendMuted(const QString &name, bool muted)
|
2018-11-07 19:54:00 +00:00
|
|
|
{
|
|
|
|
NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME_REQUEST);
|
|
|
|
np.set<QString>(QStringLiteral("name"), name);
|
|
|
|
np.set<bool>(QStringLiteral("muted"), muted);
|
|
|
|
sendPacket(np);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteSystemVolumePlugin::connected()
|
|
|
|
{
|
|
|
|
NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME_REQUEST);
|
|
|
|
np.set<bool>(QStringLiteral("requestSinks"), true);
|
|
|
|
sendPacket(np);
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray RemoteSystemVolumePlugin::sinks()
|
|
|
|
{
|
|
|
|
return m_sinks;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RemoteSystemVolumePlugin::dbusPath() const
|
|
|
|
{
|
2023-08-12 12:26:05 +01:00
|
|
|
return QLatin1String("/modules/kdeconnect/devices/%1/remotesystemvolume").arg(device()->id());
|
2018-11-07 19:54:00 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:15:11 +01:00
|
|
|
#include "moc_remotesystemvolumeplugin.cpp"
|
2018-11-07 19:54:00 +00:00
|
|
|
#include "remotesystemvolumeplugin.moc"
|