diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 70ccfb293..219d395b4 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -20,7 +20,6 @@ if(NOT SAILFISHOS) add_subdirectory(sms) add_subdirectory(runcommand) if(NOT WIN32) - add_subdirectory(pausemusic) add_subdirectory(screensaver-inhibit) add_subdirectory(sftp) endif() @@ -38,6 +37,10 @@ if(SAILFISHOS OR EXPERIMENTALAPP_ENABLED) add_subdirectory(remotesystemvolume) endif() +if(KF5PulseAudioQt_FOUND AND NOT WIN32) + add_subdirectory(pausemusic) +endif() + if(KF5PulseAudioQt_FOUND OR WIN32) add_subdirectory(systemvolume) endif() diff --git a/plugins/pausemusic/CMakeLists.txt b/plugins/pausemusic/CMakeLists.txt index e67ced7f3..8e5695586 100644 --- a/plugins/pausemusic/CMakeLists.txt +++ b/plugins/pausemusic/CMakeLists.txt @@ -6,6 +6,7 @@ target_link_libraries(kdeconnect_pausemusic kdeconnectcore Qt5::Core Qt5::DBus + KF5::PulseAudioQt ) ####################################### diff --git a/plugins/pausemusic/pausemusicplugin.cpp b/plugins/pausemusic/pausemusicplugin.cpp index 31196e0f3..7aa13b0e3 100644 --- a/plugins/pausemusic/pausemusicplugin.cpp +++ b/plugins/pausemusic/pausemusicplugin.cpp @@ -25,10 +25,10 @@ #include #include #include -#include -#include #include +#include +#include //In older Qt released, qAsConst isnt available #include "qtcompat_p.h" @@ -39,7 +39,7 @@ Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_PAUSEMUSIC, "kdeconnect.plugin.pausemusic") PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args) : KdeConnectPlugin(parent, args) - , muted(false) + , mutedSinks() {} bool PauseMusicPlugin::receivePacket(const NetworkPacket& np) @@ -65,8 +65,13 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np) if (mute) { qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Muting system volume"; - QProcess::startDetached("pactl set-sink-mute @DEFAULT_SINK@ 1"); - muted = true; + const auto sinks = PulseAudioQt::Context::instance()->sinks(); + for (const auto sink : sinks) { + if (!sink->isMuted()) { + sink->setMuted(true); + mutedSinks.insert(sink->name()); + } + } } if (pause) { @@ -92,12 +97,17 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np) } else { - if (mute && muted) { + if (mute) { qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Unmuting system volume"; - QProcess::startDetached("pactl set-sink-mute @DEFAULT_SINK@ 0"); - muted = false; + const auto sinks = PulseAudioQt::Context::instance()->sinks(); + for (const auto sink : sinks) { + if (mutedSinks.contains(sink->name())) { + sink->setMuted(false); + } + } + mutedSinks.clear(); } if (pause && !pausedSources.empty()) { diff --git a/plugins/pausemusic/pausemusicplugin.h b/plugins/pausemusic/pausemusicplugin.h index 29dcd6ea3..7457b6005 100644 --- a/plugins/pausemusic/pausemusicplugin.h +++ b/plugins/pausemusic/pausemusicplugin.h @@ -44,7 +44,7 @@ public: private: QSet pausedSources; - bool muted; + QSet mutedSinks; };