summaryrefslogtreecommitdiff
path: root/sapbtlistener.cc
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2015-12-13 03:45:51 +0100
committerJavier <dev.git@javispedro.com>2015-12-13 03:45:51 +0100
commitcd00ce1a7128cf11fa59e7a03bec49ea69425f54 (patch)
tree06a15130bf6f083d2e0afc85b656b5027b43ffb0 /sapbtlistener.cc
parent3340aa0ef68eb735c36185959c8dbd11178575bf (diff)
downloadsapd-cd00ce1a7128cf11fa59e7a03bec49ea69425f54.tar.gz
sapd-cd00ce1a7128cf11fa59e7a03bec49ea69425f54.zip
Establish an HFP connection using Bluez on Sailfish
Diffstat (limited to 'sapbtlistener.cc')
-rw-r--r--sapbtlistener.cc37
1 files changed, 32 insertions, 5 deletions
diff --git a/sapbtlistener.cc b/sapbtlistener.cc
index 40c7ac6..2265516 100644
--- a/sapbtlistener.cc
+++ b/sapbtlistener.cc
@@ -4,6 +4,12 @@
#include "sapbtlistener.h"
#include "sapbtpeer.h"
+#ifdef SAILFISH
+#include <bluez-qt5/bluemanager.h>
+#include <bluez-qt5/blueadapter.h>
+#include <bluez-qt5/bluedevice.h>
+#include <bluez-qt5/headset.h>
+#endif
#ifdef DESKTOP
#include "hfpag.h"
#endif
@@ -111,17 +117,38 @@ void SAPBTListener::nudge(const QBluetoothAddress &address)
qDebug() << "Nudging" << address.toString();
+ // First, set up HFP/Headset connection to watch
+#if SAILFISH
+ QDBusConnection bus = QDBusConnection::systemBus();
+ OrgBluezManagerInterface manager("org.bluez", "/", bus);
+ QDBusReply<QDBusObjectPath> defaultAdapter = manager.DefaultAdapter();
+ if (!defaultAdapter.isValid()) {
+ qWarning() << "Could not get default Bluez adapter:" << defaultAdapter.error().message();
+ }
+ OrgBluezAdapterInterface adapter("org.bluez", defaultAdapter.value().path(), bus);
+ QList<QDBusObjectPath> list = adapter.ListDevices();
+ foreach (QDBusObjectPath item, list) {
+ OrgBluezDeviceInterface device("org.bluez", item.path(), bus);
+ QVariantMap properties = device.GetProperties();
+ QBluetoothAddress devAddress(properties["Address"].toString());
+ qDebug() << "Found bluez device with address" << devAddress.toString();
+ if (devAddress == address) {
+ OrgBluezHeadsetInterface headset("org.bluez", item.path(), bus);
+ qDebug() << "Creating HFP connection to" << devAddress.toString();
+ headset.Connect();
+ }
+ }
+#elif DESKTOP
+ new HfpAg(address, this);
+#endif
+
+ // After that, start normal connection.
#if SAILFISH
// For some reason, using UUIDs here fails on SailfishOS
socket->connectToService(address, 1);
#else
socket->connectToService(address, SAProtocol::nudgeServiceUuid);
#endif
-
-#if DESKTOP
- // At the same time set up and HFP connection to the watch.
- new HfpAg(address, this);
-#endif
}
void SAPBTListener::acceptConnection()