Fix warning, don't use discouraged API

We used to have the following warning: "Connecting to deprecated signal
QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)"

Port away from it as recommended in Qt documentation.

REVIEW: 123637
This commit is contained in:
Aleix Pol 2015-05-05 01:40:04 +02:00
parent 11996f56ca
commit d7e06c5fb2
2 changed files with 7 additions and 23 deletions

View file

@ -26,6 +26,7 @@
#include <qdbusconnectioninterface.h>
#include <QDBusReply>
#include <QDBusMessage>
#include <QDBusServiceWatcher>
#include <KPluginFactory>
@ -39,12 +40,12 @@ Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_MPRIS, "kdeconnect.plugin.mpris")
MprisControlPlugin::MprisControlPlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args)
, prevVolume(-1)
{
prevVolume = -1;
m_watcher = new QDBusServiceWatcher("org.mpris.MediaPlayer2", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this);
//Detect new interfaces
connect(QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
this, SLOT(serviceOwnerChanged(QString,QString,QString)));
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();
@ -56,24 +57,6 @@ MprisControlPlugin::MprisControlPlugin(QObject* parent, const QVariantList& args
}
void MprisControlPlugin::serviceOwnerChanged(const QString &name,
const QString &oldOwner,
const QString &newOwner)
{
Q_UNUSED(oldOwner);
if (name.startsWith("org.mpris.MediaPlayer2")) {
qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Mpris (un)registered in bus" << name << oldOwner << newOwner;
if (oldOwner.isEmpty()) {
addPlayer(name);
} else if (newOwner.isEmpty()) {
removePlayer(name);
}
}
}
void MprisControlPlugin::addPlayer(const QString& service)
{
QDBusInterface mprisInterface(service, "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2");

View file

@ -24,6 +24,7 @@
#include <QString>
#include <QHash>
#include <QLoggingCategory>
#include <QDBusServiceWatcher>
#include <core/kdeconnectplugin.h>
@ -44,7 +45,6 @@ public Q_SLOTS:
virtual void connected() { }
private Q_SLOTS:
void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
void propertiesChanged(const QString& propertyInterface, const QVariantMap& properties);
void seeked(qlonglong);
@ -55,6 +55,7 @@ private:
QHash<QString, QString> playerList;
int prevVolume;
QDBusServiceWatcher* m_watcher;
};