summaryrefslogtreecommitdiffstats
path: root/app/dbus.cpp
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2017-04-03 22:35:00 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2017-04-18 11:52:40 -0700
commitba7c74937dfbe12ab2ef2419c934a3fc6b51c711 (patch)
treeb2d3156533b207c6a52e96732b4f4c33a260fc6e /app/dbus.cpp
parent3aeb5e52f454b972a423d5e4a359e0e02adec248 (diff)
bluetooth: add a2dp metadata and avrcp controls
Add initial support for Bluetooth A2DP streams, and AVRCP player controls, and metadata. Bug-AGL: SPEC-486 SPEC-524 SPEC-525 Change-Id: Iac3095c517f07d7e65bf0bd5639d85bab2de7451 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'app/dbus.cpp')
-rw-r--r--app/dbus.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/app/dbus.cpp b/app/dbus.cpp
index c0bfcea..4c307a7 100644
--- a/app/dbus.cpp
+++ b/app/dbus.cpp
@@ -59,3 +59,115 @@ void DbusService::lmsUpdate(const QString&, const QVariantMap&, const QStringLis
{
}
#endif
+
+/*
+ * Bluetooth
+ */
+
+void DbusService::setBluezPath(const QString& path)
+{
+ this->bluezPath = path;
+}
+
+QString DbusService::getBluezPath() const
+{
+ return this->bluezPath;
+}
+
+bool DbusService::enableBluetooth()
+{
+ QDBusConnection system_bus = QDBusConnection::systemBus();
+ QString interface = "org.freedesktop.DBus.ObjectManager";
+ bool ret;
+
+ if (!system_bus.isConnected())
+ return false;
+
+ ret = system_bus.connect(QString("org.bluez"), QString("/"), interface, "InterfacesAdded", this, SLOT(newBluetoothDevice(QDBusObjectPath,QVariantMap)));
+
+ if (!ret)
+ return false;
+
+ ret = system_bus.connect(QString("org.bluez"), QString("/"), interface, "InterfacesRemoved", this, SLOT(removeBluetoothDevice(QDBusObjectPath,QStringList)));
+
+ /*
+ * Unregister InterfacesAdded on error condition
+ */
+ if (!ret)
+ system_bus.disconnect(QString("org.bluez"), QString("/"), interface, "InterfacesAdded", this, SLOT(newBluetoothDevice(QString,QVariantMap)));
+
+ return ret;
+}
+
+bool DbusService::checkIfPlayer(const QString& path) const
+{
+ QRegExp regex("^.*/player\\d$");
+ if (regex.exactMatch(path))
+ return true;
+
+ return false;
+}
+
+void DbusService::newBluetoothDevice(const QDBusObjectPath& item, const QVariantMap&)
+{
+ QString path = item.path();
+ if (!checkIfPlayer(path))
+ return;
+
+ if (!getBluezPath().isEmpty()) {
+ qWarning() << "Another Bluetooth Player already connected";
+ return;
+ }
+
+ emit processPlaylistHide();
+
+ QDBusConnection system_bus = QDBusConnection::systemBus();
+ system_bus.connect(QString("org.bluez"), path, "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(processBluetoothEvent(QString,QVariantMap,QStringList)));
+
+ setBluezPath(path);
+}
+
+void DbusService::removeBluetoothDevice(const QDBusObjectPath& item, const QStringList&)
+{
+ QString path = item.path();
+ if (!checkIfPlayer(path))
+ return;
+
+ if (getBluezPath().isEmpty()) {
+ qWarning() << "No Bluetooth Player connected";
+ return;
+ }
+
+ QDBusConnection system_bus = QDBusConnection::systemBus();
+ system_bus.disconnect(QString("org.bluez"), path, "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(processBluetoothEvent(QString,QVariantMap,QStringList)));
+
+ setBluezPath(QString());
+ emit processPlaylistShow();
+}
+
+void DbusService::processBluetoothEvent(const QString&, const QVariantMap& map, const QStringList&)
+{
+ if (map.contains("Track")) {
+ QVariantMap track;
+ map["Track"].value<QDBusArgument>() >> track;
+ emit displayBluetoothMetadata(track["Artist"].toString(), track["Title"].toString(), track["Duration"].toInt());
+ }
+
+ if (map.contains("Position"))
+ emit updatePosition(map["Position"].toInt());
+
+ if (map.contains("Status"))
+ emit updatePlayerStatus(map["Status"].toString());
+}
+
+void DbusService::processQMLEvent(const QString& state)
+{
+ QDBusInterface interface("org.bluez", getBluezPath(), "org.bluez.MediaPlayer1", QDBusConnection::systemBus());
+ interface.call(state);
+}
+
+long DbusService::getCurrentPosition()
+{
+ QDBusInterface interface("org.bluez", getBluezPath(), "org.bluez.MediaPlayer1", QDBusConnection::systemBus());
+ return interface.property("Position").toInt();
+}