From fb8646b309549a06c0532185707c8ca91a15a833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Patron?= Date: Fri, 11 Jun 2021 01:41:40 +0200 Subject: [PATCH] Expose LoopStatus and Shuffle control over mpris control plugin This allows us to read and write these to fields from KDE Connect client. --- plugins/mpriscontrol/mpriscontrolplugin.cpp | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/plugins/mpriscontrol/mpriscontrolplugin.cpp b/plugins/mpriscontrol/mpriscontrolplugin.cpp index a5deedc99..4a9313e59 100644 --- a/plugins/mpriscontrol/mpriscontrolplugin.cpp +++ b/plugins/mpriscontrol/mpriscontrolplugin.cpp @@ -160,6 +160,14 @@ void MprisControlPlugin::propertiesChanged(const QString& propertyInterface, con np.set(QStringLiteral("isPlaying"), playing); somethingToSend = true; } + if (properties.contains(QStringLiteral("LoopStatus"))) { + np.set(QStringLiteral("loopStatus"), properties[QStringLiteral("LoopStatus")]); + somethingToSend = true; + } + if (properties.contains(QStringLiteral("Shuffle"))) { + np.set(QStringLiteral("shuffle"), properties[QStringLiteral("Shuffle")].toBool()); + somethingToSend = true; + } if (properties.contains(QStringLiteral("CanPause"))) { np.set(QStringLiteral("canPause"), properties[QStringLiteral("CanPause")].toBool()); somethingToSend = true; @@ -281,6 +289,16 @@ bool MprisControlPlugin::receivePacket (const NetworkPacket& np) //TODO: Check for valid actions, currently we trust anything the other end sends us mprisInterface.call(action); } + if (np.has(QStringLiteral("setLoopStatus"))) { + const QString& loopStatus = np.get(QStringLiteral("setLoopStatus")); + qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Setting loopStatus" << loopStatus << "to" << serviceName; + mprisInterface.setLoopStatus(loopStatus); + } + if (np.has(QStringLiteral("setShuffle"))) { + bool shuffle = np.get(QStringLiteral("setShuffle")); + qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Setting shuffle" << shuffle << "to" << serviceName; + mprisInterface.setShuffle(shuffle); + } if (np.has(QStringLiteral("setVolume"))) { double volume = np.get(QStringLiteral("setVolume"))/100.f; qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Setting volume" << volume << "to" << serviceName; @@ -318,6 +336,18 @@ bool MprisControlPlugin::receivePacket (const NetworkPacket& np) answer.set(QStringLiteral("canGoPrevious"), mprisInterface.canGoPrevious()); answer.set(QStringLiteral("canSeek"), mprisInterface.canSeek()); + // LoopStatus is an optional field + if (mprisInterface.property("LoopStatus").isValid()) { + const QString& loopStatus = mprisInterface.loopStatus(); + answer.set(QStringLiteral("loopStatus"),loopStatus); + } + + // Shuffle is an optional field + if (mprisInterface.property("Shuffle").isValid()) { + bool shuffle = mprisInterface.shuffle(); + answer.set(QStringLiteral("shuffle"),shuffle); + } + somethingToSend = true; } if (np.get(QStringLiteral("requestVolume"))) {