diff options
author | Javier <dev.git@javispedro.com> | 2015-12-13 03:45:51 +0100 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2015-12-13 03:45:51 +0100 |
commit | cd00ce1a7128cf11fa59e7a03bec49ea69425f54 (patch) | |
tree | 06a15130bf6f083d2e0afc85b656b5027b43ffb0 | |
parent | 3340aa0ef68eb735c36185959c8dbd11178575bf (diff) | |
download | sapd-cd00ce1a7128cf11fa59e7a03bec49ea69425f54.tar.gz sapd-cd00ce1a7128cf11fa59e7a03bec49ea69425f54.zip |
Establish an HFP connection using Bluez on Sailfish
-rw-r--r-- | rpm/sapd.yaml | 1 | ||||
-rw-r--r-- | sapbtlistener.cc | 37 | ||||
-rw-r--r-- | sapd.pro | 4 |
3 files changed, 35 insertions, 7 deletions
diff --git a/rpm/sapd.yaml b/rpm/sapd.yaml index 59681f6..c7798eb 100644 --- a/rpm/sapd.yaml +++ b/rpm/sapd.yaml @@ -20,6 +20,7 @@ PkgConfigBR: - openssl - dbus-1 - timed-qt5 + - bluez-qt5 PkgBR: # Workaround current sailfish qt5connectivity packaging bug 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() @@ -6,10 +6,10 @@ CONFIG += console c++11 CONFIG += link_pkgconfig PKGCONFIG += openssl -exists(/usr/lib/libsailfishapp.so) { +exists(/usr/lib/pkgconfig/sailfishapp.pc) { # Building for Jolla Sailfish, Qt5, Bluez4(?) DEFINES += SAILFISH - PKGCONFIG += dbus-1 timed-qt5 + PKGCONFIG += dbus-1 timed-qt5 bluez-qt5 SOURCES += libwatchfish/notificationmonitor.cpp libwatchfish/notification.cpp \ libwatchfish/walltimemonitor.cpp HEADERS += libwatchfish/notificationmonitor.h libwatchfish/notificationmonitor_p.h libwatchfish/notification.h \ |