X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=app%2Fdbus.cpp;h=3c298a059262e4f37afd8b62ec6ee505b92400f6;hb=refs%2Ftags%2F3.99.1;hp=4c307a7ae1df9212903ee3108400dc5edd8720bf;hpb=ba7c74937dfbe12ab2ef2419c934a3fc6b51c711;p=apps%2Fmediaplayer.git diff --git a/app/dbus.cpp b/app/dbus.cpp index 4c307a7..3c298a0 100644 --- a/app/dbus.cpp +++ b/app/dbus.cpp @@ -28,11 +28,26 @@ DbusService::DbusService(QObject *parent) : QObject(parent) bool DbusService::enableLMS() { QDBusConnection session_bus = QDBusConnection::sessionBus(); + QDBusConnection system_bus = QDBusConnection::systemBus(); + bool ret; if (!session_bus.isConnected()) return false; - return session_bus.connect(QString("org.lightmediascanner"), QString("/org/lightmediascanner/Scanner1"), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(lmsUpdate(QString,QVariantMap,QStringList))); + if (!system_bus.isConnected()) + return false; + + ret = session_bus.connect(QString("org.lightmediascanner"), QString("/org/lightmediascanner/Scanner1"), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(lmsUpdate(QString,QVariantMap,QStringList))); + if (!ret) + return false; + + /* Only subscribe to DeviceRemoved events, since we need lms scan to complete on insert */ + return system_bus.connect(QString("org.freedesktop.UDisks"), QString("/org/freedesktop/UDisks"), "org.freedesktop.UDisks", "DeviceRemoved", this, SLOT(mediaRemoved(QDBusObjectPath))); +} + +void DbusService::mediaRemoved(const QDBusObjectPath&) +{ + emit stopPlayback(); } #if defined(HAVE_LIGHTMEDIASCANNER) @@ -83,6 +98,9 @@ bool DbusService::enableBluetooth() if (!system_bus.isConnected()) return false; + if (deviceConnected(system_bus)) + initialBluetoothData(system_bus); + ret = system_bus.connect(QString("org.bluez"), QString("/"), interface, "InterfacesAdded", this, SLOT(newBluetoothDevice(QDBusObjectPath,QVariantMap))); if (!ret) @@ -108,6 +126,93 @@ bool DbusService::checkIfPlayer(const QString& path) const return false; } +bool DbusService::deviceConnected(const QDBusConnection& system_bus) +{ + QDBusInterface interface("org.bluez", "/", "org.freedesktop.DBus.ObjectManager", system_bus); + QDBusMessage result = interface.call("GetManagedObjects"); + const QDBusArgument argument = result.arguments().at(0).value(); + bool ret = false; + + if (argument.currentType() != QDBusArgument::MapType) + return false; + + argument.beginMap(); + + while (!argument.atEnd()) { + QString key; + + argument.beginMapEntry(); + argument >> key; + argument.endMapEntry(); + + ret = checkIfPlayer(key); + + if (ret) { + newBluetoothDevice(QDBusObjectPath(key), QVariantMap()); + break; + } + } + + argument.endMap(); + + return ret; +} + +void DbusService::initialBluetoothData(const QDBusConnection& system_bus) +{ + QDBusInterface interface("org.bluez", getBluezPath(), "org.freedesktop.DBus.Properties", system_bus); + + QDBusMessage result = interface.call("GetAll", "org.bluez.MediaPlayer1"); + const QDBusArgument argument = result.arguments().at(0).value(); + QString status, artist, title; + int position = 0, duration = 0; + + if (argument.currentType() != QDBusArgument::MapType) + return; + + argument.beginMap(); + + while (!argument.atEnd()) { + QString key; + QVariant value; + + argument.beginMapEntry(); + argument >> key >> value; + + if (key == "Position") { + position = value.toInt(); + } else if (key == "Status") { + status = value.toString(); + } else if (key == "Track") { + const QDBusArgument argument1 = qvariant_cast(value); + QString key1; + QVariant value1; + + argument1.beginMap(); + + while (!argument1.atEnd()) { + argument1.beginMapEntry(); + argument1 >> key1 >> value1; + if (key1 == "Artist") + artist = value1.toString(); + else if (key1 == "Title") + title = value1.toString(); + else if (key1 == "Duration") + duration = value1.toInt(); + argument1.endMapEntry(); + } + argument1.endMap(); + } + argument.endMapEntry(); + } + argument.endMap(); + + emit processPlaylistHide(); + emit displayBluetoothMetadata(artist, title, duration); + emit updatePlayerStatus(status); + emit updatePosition(position); +} + void DbusService::newBluetoothDevice(const QDBusObjectPath& item, const QVariantMap&) { QString path = item.path();