[pausemusic] Port to PulseAudioQt
This commit is contained in:
parent
b04dcde70e
commit
3f4f475991
4 changed files with 24 additions and 10 deletions
|
@ -20,7 +20,6 @@ if(NOT SAILFISHOS)
|
||||||
add_subdirectory(sms)
|
add_subdirectory(sms)
|
||||||
add_subdirectory(runcommand)
|
add_subdirectory(runcommand)
|
||||||
if(NOT WIN32)
|
if(NOT WIN32)
|
||||||
add_subdirectory(pausemusic)
|
|
||||||
add_subdirectory(screensaver-inhibit)
|
add_subdirectory(screensaver-inhibit)
|
||||||
add_subdirectory(sftp)
|
add_subdirectory(sftp)
|
||||||
endif()
|
endif()
|
||||||
|
@ -38,6 +37,10 @@ if(SAILFISHOS OR EXPERIMENTALAPP_ENABLED)
|
||||||
add_subdirectory(remotesystemvolume)
|
add_subdirectory(remotesystemvolume)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(KF5PulseAudioQt_FOUND AND NOT WIN32)
|
||||||
|
add_subdirectory(pausemusic)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(KF5PulseAudioQt_FOUND OR WIN32)
|
if(KF5PulseAudioQt_FOUND OR WIN32)
|
||||||
add_subdirectory(systemvolume)
|
add_subdirectory(systemvolume)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -6,6 +6,7 @@ target_link_libraries(kdeconnect_pausemusic
|
||||||
kdeconnectcore
|
kdeconnectcore
|
||||||
Qt5::Core
|
Qt5::Core
|
||||||
Qt5::DBus
|
Qt5::DBus
|
||||||
|
KF5::PulseAudioQt
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
|
|
|
@ -25,10 +25,10 @@
|
||||||
#include <QDBusConnectionInterface>
|
#include <QDBusConnectionInterface>
|
||||||
#include <QDBusMessage>
|
#include <QDBusMessage>
|
||||||
#include <QDBusReply>
|
#include <QDBusReply>
|
||||||
#include <QDebug>
|
|
||||||
#include <QProcess>
|
|
||||||
|
|
||||||
#include <KPluginFactory>
|
#include <KPluginFactory>
|
||||||
|
#include <PulseAudioQt/Context>
|
||||||
|
#include <PulseAudioQt/Sink>
|
||||||
|
|
||||||
//In older Qt released, qAsConst isnt available
|
//In older Qt released, qAsConst isnt available
|
||||||
#include "qtcompat_p.h"
|
#include "qtcompat_p.h"
|
||||||
|
@ -39,7 +39,7 @@ Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_PAUSEMUSIC, "kdeconnect.plugin.pausemusic")
|
||||||
|
|
||||||
PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args)
|
PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args)
|
||||||
: KdeConnectPlugin(parent, args)
|
: KdeConnectPlugin(parent, args)
|
||||||
, muted(false)
|
, mutedSinks()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool PauseMusicPlugin::receivePacket(const NetworkPacket& np)
|
bool PauseMusicPlugin::receivePacket(const NetworkPacket& np)
|
||||||
|
@ -65,8 +65,13 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np)
|
||||||
|
|
||||||
if (mute) {
|
if (mute) {
|
||||||
qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Muting system volume";
|
qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Muting system volume";
|
||||||
QProcess::startDetached("pactl set-sink-mute @DEFAULT_SINK@ 1");
|
const auto sinks = PulseAudioQt::Context::instance()->sinks();
|
||||||
muted = true;
|
for (const auto sink : sinks) {
|
||||||
|
if (!sink->isMuted()) {
|
||||||
|
sink->setMuted(true);
|
||||||
|
mutedSinks.insert(sink->name());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pause) {
|
if (pause) {
|
||||||
|
@ -92,12 +97,17 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (mute && muted) {
|
if (mute) {
|
||||||
|
|
||||||
qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Unmuting system volume";
|
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()) {
|
if (pause && !pausedSources.empty()) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSet<QString> pausedSources;
|
QSet<QString> pausedSources;
|
||||||
bool muted;
|
QSet<QString> mutedSinks;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue