diff --git a/plugins/mpriscontrol/mpriscontrolplugin.cpp b/plugins/mpriscontrol/mpriscontrolplugin.cpp index e543e7ae8..d5dc1ebaa 100644 --- a/plugins/mpriscontrol/mpriscontrolplugin.cpp +++ b/plugins/mpriscontrol/mpriscontrolplugin.cpp @@ -42,21 +42,33 @@ MprisControlPlugin::MprisControlPlugin(QObject* parent, const QVariantList& args : KdeConnectPlugin(parent, args) , prevVolume(-1) { - m_watcher = new QDBusServiceWatcher("org.mpris.MediaPlayer2", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); + m_watcher = new QDBusServiceWatcher(QString(), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, this, &MprisControlPlugin::addPlayer); connect(m_watcher, &QDBusServiceWatcher::serviceUnregistered, this, &MprisControlPlugin::removePlayer); //Add existing interfaces - QStringList interfaces = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); - Q_FOREACH (const QString& iface, interfaces) { - if (iface.startsWith("org.mpris.MediaPlayer2")) { - addPlayer(iface); - } + QStringList services = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); + Q_FOREACH (const QString& service, services) { + addService(service); } - } +void MprisControlPlugin::addService(const QString& service) +{ + if (service.startsWith(QLatin1String("org.mpris.MediaPlayer2"))) { + addPlayer(service); + } +} + +void MprisControlPlugin::removeService(const QString& service) +{ + if (service.startsWith(QLatin1String("org.mpris.MediaPlayer2"))) { + removePlayer(service); + } +} + + void MprisControlPlugin::addPlayer(const QString& service) { QDBusInterface mprisInterface(service, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2"); diff --git a/plugins/mpriscontrol/mpriscontrolplugin.h b/plugins/mpriscontrol/mpriscontrolplugin.h index de5f301b1..e7839eba9 100644 --- a/plugins/mpriscontrol/mpriscontrolplugin.h +++ b/plugins/mpriscontrol/mpriscontrolplugin.h @@ -49,6 +49,9 @@ private Q_SLOTS: void seeked(qlonglong); private: + void addService(const QString& service); + void removeService(const QString& service); + void addPlayer(const QString& ifaceName); void removePlayer(const QString& ifaceName); void sendPlayerList();