File indexing completed on 2024-09-08 04:30:17
0001 /** 0002 * SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "remotesystemvolumeplugin.h" 0008 0009 #include <KLocalizedString> 0010 #include <KPluginFactory> 0011 0012 #include <QDBusConnection> 0013 #include <QDebug> 0014 #include <QJsonArray> 0015 #include <QJsonDocument> 0016 0017 #include <core/daemon.h> 0018 #include <core/device.h> 0019 0020 #include "plugin_remotesystemvolume_debug.h" 0021 0022 K_PLUGIN_CLASS_WITH_JSON(RemoteSystemVolumePlugin, "kdeconnect_remotesystemvolume.json") 0023 0024 void RemoteSystemVolumePlugin::receivePacket(const NetworkPacket &np) 0025 { 0026 if (np.has(QStringLiteral("sinkList"))) { 0027 QJsonDocument document(np.get<QJsonArray>(QStringLiteral("sinkList"))); 0028 m_sinks = document.toJson(); 0029 Q_EMIT sinksChanged(); 0030 } else { 0031 QString name = np.get<QString>(QStringLiteral("name")); 0032 0033 if (np.has(QStringLiteral("volume"))) { 0034 Q_EMIT volumeChanged(name, np.get<int>(QStringLiteral("volume"))); 0035 } 0036 0037 if (np.has(QStringLiteral("muted"))) { 0038 Q_EMIT mutedChanged(name, np.get<int>(QStringLiteral("muted"))); 0039 } 0040 } 0041 } 0042 0043 void RemoteSystemVolumePlugin::sendVolume(const QString &name, int volume) 0044 { 0045 NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME_REQUEST); 0046 np.set<QString>(QStringLiteral("name"), name); 0047 np.set<int>(QStringLiteral("volume"), volume); 0048 sendPacket(np); 0049 } 0050 0051 void RemoteSystemVolumePlugin::sendMuted(const QString &name, bool muted) 0052 { 0053 NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME_REQUEST); 0054 np.set<QString>(QStringLiteral("name"), name); 0055 np.set<bool>(QStringLiteral("muted"), muted); 0056 sendPacket(np); 0057 } 0058 0059 void RemoteSystemVolumePlugin::connected() 0060 { 0061 NetworkPacket np(PACKET_TYPE_SYSTEMVOLUME_REQUEST); 0062 np.set<bool>(QStringLiteral("requestSinks"), true); 0063 sendPacket(np); 0064 } 0065 0066 QByteArray RemoteSystemVolumePlugin::sinks() 0067 { 0068 return m_sinks; 0069 } 0070 0071 QString RemoteSystemVolumePlugin::dbusPath() const 0072 { 0073 return QLatin1String("/modules/kdeconnect/devices/%1/remotesystemvolume").arg(device()->id()); 0074 } 0075 0076 #include "moc_remotesystemvolumeplugin.cpp" 0077 #include "remotesystemvolumeplugin.moc"