[pausemusic] Port to PulseAudioQt

This commit is contained in:
Nicolas Fella 2019-04-28 19:31:39 +00:00
parent b04dcde70e
commit 3f4f475991
4 changed files with 24 additions and 10 deletions

View file

@ -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()

View file

@ -6,6 +6,7 @@ target_link_libraries(kdeconnect_pausemusic
kdeconnectcore
Qt5::Core
Qt5::DBus
KF5::PulseAudioQt
)
#######################################

View file

@ -25,10 +25,10 @@
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QDBusReply>
#include <QDebug>
#include <QProcess>
#include <KPluginFactory>
#include <PulseAudioQt/Context>
#include <PulseAudioQt/Sink>
//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()) {

View file

@ -44,7 +44,7 @@ public:
private:
QSet<QString> pausedSources;
bool muted;
QSet<QString> mutedSinks;
};