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
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
RemoteSystemVolumePlugin::RemoteSystemVolumePlugin(QObject *parent, const QVariantList &args)
|
2018-11-07 19:54:00 +00:00
|
|
|
: KdeConnectPlugin(parent, args)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoteSystemVolumePlugin::~RemoteSystemVolumePlugin()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
bool 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")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2019-06-10 15:40:28 +01:00
|
|
|
return QStringLiteral("/modules/kdeconnect/devices/") + device()->id() + QStringLiteral("/remotesystemvolume");
|
2018-11-07 19:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "remotesystemvolumeplugin.moc"
|