Commit e9f31abd authored by Albert Vaca Cintora's avatar Albert Vaca Cintora
Browse files

PauseMusic plugin can now mute system instead of pause

parent 4f710457
......@@ -40,6 +40,7 @@ PauseMusicConfig::PauseMusicConfig(QWidget *parent, const QVariantList& )
connect(m_ui->rad_ringing, SIGNAL(toggled(bool)), this, SLOT(changed()));
connect(m_ui->rad_talking, SIGNAL(toggled(bool)), this, SLOT(changed()));
connect(m_ui->check_mute, SIGNAL(toggled(bool)), this, SLOT(changed()));
}
PauseMusicConfig::~PauseMusicConfig()
......@@ -52,7 +53,7 @@ void PauseMusicConfig::defaults()
KCModule::defaults();
m_ui->rad_talking->setChecked(false);
m_ui->rad_ringing->setChecked(true);
m_ui->check_mute->setChecked(false);
Q_EMIT changed(true);
}
......@@ -63,7 +64,8 @@ void PauseMusicConfig::load()
bool talking = m_cfg->group("pause_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);
Q_EMIT changed(false);
}
......@@ -71,6 +73,7 @@ void PauseMusicConfig::load()
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());
KCModule::save();
Q_EMIT changed(false);
......
......@@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>252</width>
<height>175</height>
<width>406</width>
<height>155</height>
</rect>
</property>
<property name="windowTitle">
......@@ -46,6 +46,26 @@
</layout>
</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>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="check_mute">
<property name="text">
<string>Mute system instead of pause</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......
......@@ -34,10 +34,24 @@
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< PauseMusicPlugin >(); )
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_pausemusic", "kdeconnect_pausemusic") )
//TODO: Port this away from KMix to use only Pulseaudio
bool isKMixMuted() {
QDBusInterface kmixInterface("org.kde.kmix", "/Mixers", "org.kde.KMix.MixSet");
QString mixer = kmixInterface.property("currentMasterMixer").toString();
QString control = kmixInterface.property("currentMasterControl").toString();
mixer.replace(':','_');
control.replace(':','_');
QDBusInterface mixerInterface("org.kde.kmix", "/Mixers/"+mixer+"/"+control, "org.kde.KMix.Control");
if (mixerInterface.property("mute").toBool()) return true;
return (mixerInterface.property("volume").toInt() == 0);
}
PauseMusicPlugin::PauseMusicPlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args)
{
QDBusInterface kmixInterface("org.kde.kmix", "/kmix/KMixWindow/actions/mute", "org.qtproject.Qt.QAction");
}
bool PauseMusicPlugin::receivePackage(const NetworkPackage& np)
......@@ -57,33 +71,49 @@ bool PauseMusicPlugin::receivePackage(const NetworkPackage& np)
}
bool pauseConditionFulfilled = !np.get<bool>("isCancel");
bool use_mute = config->group("use_mute").readEntry("use_mute", false);
if (pauseConditionFulfilled) {
//Search for interfaces currently playing
QStringList interfaces = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
Q_FOREACH (const QString& iface, interfaces) {
if (iface.startsWith("org.mpris.MediaPlayer2")) {
QDBusInterface mprisInterface(iface, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player");
QString status = mprisInterface.property("PlaybackStatus").toString();
if (status == "Playing") {
if (!pausedSources.contains(iface)) {
pausedSources.insert(iface);
mprisInterface.asyncCall("Pause");
if (use_mute) {
QDBusInterface kmixInterface("org.kde.kmix", "/kmix/KMixWindow/actions/mute", "org.qtproject.Qt.QAction");
if (isKMixMuted()) {
pausedSources.insert("mute");
kmixInterface.call("trigger");
}
} else {
//Search for interfaces currently playing
QStringList interfaces = QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
Q_FOREACH (const QString& iface, interfaces) {
if (iface.startsWith("org.mpris.MediaPlayer2")) {
QDBusInterface mprisInterface(iface, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player");
QString status = mprisInterface.property("PlaybackStatus").toString();
if (status == "Playing") {
if (!pausedSources.contains(iface)) {
pausedSources.insert(iface);
mprisInterface.asyncCall("Pause");
}
}
}
}
}
} else {
Q_FOREACH (const QString& iface, pausedSources) {
QDBusInterface mprisInterface(iface, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player");
//Calling play does not work for Spotify
//mprisInterface->call(QDBus::Block,"Play");
//Workaround: Using playpause instead (checking first if it is already playing)
QString status = mprisInterface.property("PlaybackStatus").toString();
if (status == "Paused") mprisInterface.asyncCall("PlayPause");
//End of workaround
if (pausedSources.empty()) return false;
if (use_mute) {
QDBusInterface kmixInterface("org.kde.kmix", "/kmix/KMixWindow/actions/mute", "org.qtproject.Qt.QAction");
if (isKMixMuted()) kmixInterface.call("trigger");
} else {
Q_FOREACH (const QString& iface, pausedSources) {
QDBusInterface mprisInterface(iface, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player");
//Calling play does not work for Spotify
//mprisInterface->call(QDBus::Block,"Play");
//Workaround: Using playpause instead (checking first if it is already playing)
QString status = mprisInterface.property("PlaybackStatus").toString();
if (status == "Paused") mprisInterface.asyncCall("PlayPause");
//End of workaround
}
}
pausedSources.clear();
}
return true;
......
Supports Markdown
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