From 83a152f41f306c44fa9e1cb90b0406c5ec3a7d20 Mon Sep 17 00:00:00 2001 From: Tony Sesek Date: Wed, 20 May 2020 21:44:33 +0000 Subject: [PATCH] [pausemusic] Add option to not unpause music once call has finished. --- plugins/pausemusic/pausemusic_config.cpp | 6 ++++++ plugins/pausemusic/pausemusic_config.ui | 7 +++++++ plugins/pausemusic/pausemusicplugin-win.cpp | 6 +++++- plugins/pausemusic/pausemusicplugin.cpp | 20 +++++++++++++------- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/plugins/pausemusic/pausemusic_config.cpp b/plugins/pausemusic/pausemusic_config.cpp index cf8f61cfd..7fa6c3db3 100644 --- a/plugins/pausemusic/pausemusic_config.cpp +++ b/plugins/pausemusic/pausemusic_config.cpp @@ -35,6 +35,7 @@ PauseMusicConfig::PauseMusicConfig(QWidget* parent, const QVariantList& args) connect(m_ui->rad_talking, SIGNAL(toggled(bool)), this, SLOT(changed())); connect(m_ui->check_pause, SIGNAL(toggled(bool)), this, SLOT(changed())); connect(m_ui->check_mute, SIGNAL(toggled(bool)), this, SLOT(changed())); + connect(m_ui->check_resume, SIGNAL(toggled(bool)), this, SLOT(changed())); } PauseMusicConfig::~PauseMusicConfig() @@ -49,6 +50,7 @@ void PauseMusicConfig::defaults() m_ui->rad_ringing->setChecked(true); m_ui->check_pause->setChecked(true); m_ui->check_mute->setChecked(false); + m_ui->check_resume->setChecked(true); Q_EMIT changed(true); } @@ -64,6 +66,9 @@ void PauseMusicConfig::load() m_ui->check_pause->setChecked(pause); m_ui->check_mute->setChecked(mute); + const bool autoResume = config()->get(QStringLiteral("actionResume"), true); + m_ui->check_resume->setChecked(autoResume); + Q_EMIT changed(false); } @@ -72,6 +77,7 @@ void PauseMusicConfig::save() config()->set(QStringLiteral("conditionTalking"), m_ui->rad_talking->isChecked()); config()->set(QStringLiteral("actionPause"), m_ui->check_pause->isChecked()); config()->set(QStringLiteral("actionMute"), m_ui->check_mute->isChecked()); + config()->set(QStringLiteral("actionResume"), m_ui->check_resume->isChecked()); KCModule::save(); Q_EMIT changed(false); } diff --git a/plugins/pausemusic/pausemusic_config.ui b/plugins/pausemusic/pausemusic_config.ui index 04d870bb4..3a999f072 100644 --- a/plugins/pausemusic/pausemusic_config.ui +++ b/plugins/pausemusic/pausemusic_config.ui @@ -75,6 +75,13 @@ + + + + Automatically resume media when call has finished + + + diff --git a/plugins/pausemusic/pausemusicplugin-win.cpp b/plugins/pausemusic/pausemusicplugin-win.cpp index 37e7f9672..2bc41580c 100644 --- a/plugins/pausemusic/pausemusicplugin-win.cpp +++ b/plugins/pausemusic/pausemusicplugin-win.cpp @@ -74,6 +74,8 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np) bool pause = config()->get(QStringLiteral("actionPause"), false); bool mute = config()->get(QStringLiteral("actionMute"), true); + const bool autoResume = config()->get(QStringLiteral("actionResume"), true); + if (pauseConditionFulfilled) { if (mute) { @@ -89,7 +91,9 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np) if (mute) { qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Unmuting system volume"; - endpointVolume->SetMute(FALSE, &g_guidMyContext); + if (autoResume) { + endpointVolume->SetMute(FALSE, &g_guidMyContext); + } } if (pause) { // TODO UNPAUSING diff --git a/plugins/pausemusic/pausemusicplugin.cpp b/plugins/pausemusic/pausemusicplugin.cpp index e71e38bee..1e8d6ef9e 100644 --- a/plugins/pausemusic/pausemusicplugin.cpp +++ b/plugins/pausemusic/pausemusicplugin.cpp @@ -58,6 +58,8 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np) bool pause = config()->get(QStringLiteral("actionPause"), true); bool mute = config()->get(QStringLiteral("actionMute"), false); + const bool autoResume = config()->get(QStringLiteral("actionResume"), true); + if (pauseConditionFulfilled) { if (mute) { @@ -98,19 +100,23 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np) qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Unmuting system volume"; - const auto sinks = PulseAudioQt::Context::instance()->sinks(); - for (const auto sink : sinks) { - if (mutedSinks.contains(sink->name())) { - sink->setMuted(false); + if (autoResume) { + 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()) { - for (const QString& iface : qAsConst(pausedSources)) { - OrgMprisMediaPlayer2PlayerInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), DBusHelper::sessionBus()); - mprisInterface.Play(); + if (autoResume) { + for (const QString& iface : qAsConst(pausedSources)) { + OrgMprisMediaPlayer2PlayerInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), DBusHelper::sessionBus()); + mprisInterface.Play(); + } } pausedSources.clear(); }