Commit 07e0b6fc authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Added separate options to mute and/or pause players during a call.

Bug: 338951
parent 5cf6fe82
......@@ -53,6 +53,7 @@ void PauseMusicConfig::defaults()
KCModule::defaults();
m_ui->rad_talking->setChecked(false);
m_ui->rad_ringing->setChecked(true);
m_ui->check_pause->setChecked(true);
m_ui->check_mute->setChecked(false);
Q_EMIT changed(true);
}
......@@ -61,19 +62,23 @@ void PauseMusicConfig::defaults()
void PauseMusicConfig::load()
{
KCModule::load();
bool talking = m_cfg->group("pause_condition").readEntry("talking_only", false);
bool talking = m_cfg->group("condition").readEntry("talking_only", false);
m_ui->rad_talking->setChecked(talking);
m_ui->rad_ringing->setChecked(!talking);
bool use_mute = m_cfg->group("use_mute").readEntry("use_mute", false);
m_ui->check_mute->setChecked(use_mute);
bool pause = m_cfg->group("actions").readEntry("pause", true);
bool mute = m_cfg->group("actions").readEntry("mute", false);
m_ui->check_pause->setChecked(pause);
m_ui->check_mute->setChecked(mute);
Q_EMIT changed(false);
}
void PauseMusicConfig::save()
{
m_cfg->group("pause_condition").writeEntry("talking_only", m_ui->rad_talking->isChecked());
m_cfg->group("use_mute").writeEntry("use_mute", m_ui->check_mute->isChecked());
m_cfg->group("condition").writeEntry("talking_only", m_ui->rad_talking->isChecked());
m_cfg->group("actions").writeEntry("pause", m_ui->check_pause->isChecked());
m_cfg->group("actions").writeEntry("mute", m_ui->check_mute->isChecked());
KCModule::save();
Q_EMIT changed(false);
......
......@@ -9,14 +9,17 @@
<rect>
<x>0</x>
<y>0</y>
<width>406</width>
<height>155</height>
<width>368</width>
<height>241</height>
</rect>
</property>
<property name="windowTitle">
<string>Pause music plugin</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>20</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
......@@ -26,7 +29,7 @@
</sizepolicy>
</property>
<property name="title">
<string>Pause condition</string>
<string>Condition</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
......@@ -47,23 +50,32 @@
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="check_mute">
<property name="text">
<string>Mute system instead of pause</string>
<property name="title">
<string>Actions</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="check_pause">
<property name="text">
<string>Pause media players</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_mute">
<property name="text">
<string>Mute system sound</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
......
......@@ -59,6 +59,7 @@ int PauseMusicPlugin::isKMixMuted() {
PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args)
, muted(false)
{
QDBusInterface kmixInterface("org.kde.kmix", "/kmix/KMixWindow/actions/mute", "org.qtproject.Qt.QAction");
}
......@@ -67,7 +68,7 @@ bool PauseMusicPlugin::receivePackage(const NetworkPackage& np)
{
//FIXME: There should be a better way to listen to changes in the config file instead of reading the value each time
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnect/plugins/pausemusic");
bool pauseOnlyWhenTalking = config->group("pause_condition").readEntry("talking_only", false);
bool pauseOnlyWhenTalking = config->group("condition").readEntry("talking_only", false);
if (pauseOnlyWhenTalking) {
if (np.get<QString>("event") != "talking") {
......@@ -80,16 +81,21 @@ bool PauseMusicPlugin::receivePackage(const NetworkPackage& np)
}
bool pauseConditionFulfilled = !np.get<bool>("isCancel");
bool use_mute = config->group("use_mute").readEntry("use_mute", false);
bool pause = config->group("actions").readEntry("pause", true);
bool mute = config->group("actions").readEntry("mute", false);
if (pauseConditionFulfilled) {
if (use_mute) {
if (mute) {
QDBusInterface kmixInterface("org.kde.kmix", "/kmix/KMixWindow/actions/mute", "org.qtproject.Qt.QAction");
if (isKMixMuted() == 0) {
pausedSources.insert("mute"); //Fake source
muted = true;
kmixInterface.call("trigger");
}
} else {
}
if (pause) {
//Search for interfaces currently playing
QStringList interfaces = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
Q_FOREACH (const QString& iface, interfaces) {
......@@ -109,14 +115,18 @@ bool PauseMusicPlugin::receivePackage(const NetworkPackage& np)
}
}
}
} else {
if (pausedSources.empty()) return false;
if (use_mute) {
if (mute && muted) {
QDBusInterface kmixInterface("org.kde.kmix", "/kmix/KMixWindow/actions/mute", "org.qtproject.Qt.QAction");
if (isKMixMuted() > 0) {
kmixInterface.call("trigger");
}
} else {
muted = false;
}
if (pause && !pausedSources.empty()) {
Q_FOREACH (const QString& iface, pausedSources) {
QDBusInterface mprisInterface(iface, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player");
//Calling play does not work for Spotify
......@@ -126,8 +136,8 @@ bool PauseMusicPlugin::receivePackage(const NetworkPackage& np)
mprisInterface.asyncCall("PlayPause");
//End of workaround
}
pausedSources.clear();
}
pausedSources.clear();
}
......
......@@ -46,6 +46,7 @@ public Q_SLOTS:
private:
QSet<QString> pausedSources;
bool muted;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment