[pausemusic] Add option to not unpause music once call has finished.

This commit is contained in:
Tony Sesek 2020-05-20 21:44:33 +00:00 committed by Nicolas Fella
parent fbadf09fb5
commit 83a152f41f
4 changed files with 31 additions and 8 deletions

View file

@ -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->rad_talking, SIGNAL(toggled(bool)), this, SLOT(changed()));
connect(m_ui->check_pause, 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_mute, SIGNAL(toggled(bool)), this, SLOT(changed()));
connect(m_ui->check_resume, SIGNAL(toggled(bool)), this, SLOT(changed()));
} }
PauseMusicConfig::~PauseMusicConfig() PauseMusicConfig::~PauseMusicConfig()
@ -49,6 +50,7 @@ void PauseMusicConfig::defaults()
m_ui->rad_ringing->setChecked(true); m_ui->rad_ringing->setChecked(true);
m_ui->check_pause->setChecked(true); m_ui->check_pause->setChecked(true);
m_ui->check_mute->setChecked(false); m_ui->check_mute->setChecked(false);
m_ui->check_resume->setChecked(true);
Q_EMIT changed(true); Q_EMIT changed(true);
} }
@ -64,6 +66,9 @@ void PauseMusicConfig::load()
m_ui->check_pause->setChecked(pause); m_ui->check_pause->setChecked(pause);
m_ui->check_mute->setChecked(mute); m_ui->check_mute->setChecked(mute);
const bool autoResume = config()->get(QStringLiteral("actionResume"), true);
m_ui->check_resume->setChecked(autoResume);
Q_EMIT changed(false); Q_EMIT changed(false);
} }
@ -72,6 +77,7 @@ void PauseMusicConfig::save()
config()->set(QStringLiteral("conditionTalking"), m_ui->rad_talking->isChecked()); config()->set(QStringLiteral("conditionTalking"), m_ui->rad_talking->isChecked());
config()->set(QStringLiteral("actionPause"), m_ui->check_pause->isChecked()); config()->set(QStringLiteral("actionPause"), m_ui->check_pause->isChecked());
config()->set(QStringLiteral("actionMute"), m_ui->check_mute->isChecked()); config()->set(QStringLiteral("actionMute"), m_ui->check_mute->isChecked());
config()->set(QStringLiteral("actionResume"), m_ui->check_resume->isChecked());
KCModule::save(); KCModule::save();
Q_EMIT changed(false); Q_EMIT changed(false);
} }

View file

@ -75,6 +75,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="check_resume">
<property name="text">
<string>Automatically resume media when call has finished</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View file

@ -74,6 +74,8 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np)
bool pause = config()->get(QStringLiteral("actionPause"), false); bool pause = config()->get(QStringLiteral("actionPause"), false);
bool mute = config()->get(QStringLiteral("actionMute"), true); bool mute = config()->get(QStringLiteral("actionMute"), true);
const bool autoResume = config()->get(QStringLiteral("actionResume"), true);
if (pauseConditionFulfilled) { if (pauseConditionFulfilled) {
if (mute) { if (mute) {
@ -89,7 +91,9 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np)
if (mute) { if (mute) {
qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Unmuting system volume"; qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Unmuting system volume";
endpointVolume->SetMute(FALSE, &g_guidMyContext); if (autoResume) {
endpointVolume->SetMute(FALSE, &g_guidMyContext);
}
} }
if (pause) { if (pause) {
// TODO UNPAUSING // TODO UNPAUSING

View file

@ -58,6 +58,8 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np)
bool pause = config()->get(QStringLiteral("actionPause"), true); bool pause = config()->get(QStringLiteral("actionPause"), true);
bool mute = config()->get(QStringLiteral("actionMute"), false); bool mute = config()->get(QStringLiteral("actionMute"), false);
const bool autoResume = config()->get(QStringLiteral("actionResume"), true);
if (pauseConditionFulfilled) { if (pauseConditionFulfilled) {
if (mute) { if (mute) {
@ -98,19 +100,23 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np)
qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Unmuting system volume"; qCDebug(KDECONNECT_PLUGIN_PAUSEMUSIC) << "Unmuting system volume";
const auto sinks = PulseAudioQt::Context::instance()->sinks(); if (autoResume) {
for (const auto sink : sinks) { const auto sinks = PulseAudioQt::Context::instance()->sinks();
if (mutedSinks.contains(sink->name())) { for (const auto sink : sinks) {
sink->setMuted(false); if (mutedSinks.contains(sink->name())) {
sink->setMuted(false);
}
} }
} }
mutedSinks.clear(); mutedSinks.clear();
} }
if (pause && !pausedSources.empty()) { if (pause && !pausedSources.empty()) {
for (const QString& iface : qAsConst(pausedSources)) { if (autoResume) {
OrgMprisMediaPlayer2PlayerInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), DBusHelper::sessionBus()); for (const QString& iface : qAsConst(pausedSources)) {
mprisInterface.Play(); OrgMprisMediaPlayer2PlayerInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), DBusHelper::sessionBus());
mprisInterface.Play();
}
} }
pausedSources.clear(); pausedSources.clear();
} }