From cd00ce1a7128cf11fa59e7a03bec49ea69425f54 Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 13 Dec 2015 03:45:51 +0100 Subject: Establish an HFP connection using Bluez on Sailfish --- sapbtlistener.cc | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'sapbtlistener.cc') 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 +#include +#include +#include +#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 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 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() -- cgit v1.2.3