summaryrefslogtreecommitdiff
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
parent3340aa0ef68eb735c36185959c8dbd11178575bf (diff)
downloadsapd-cd00ce1a7128cf11fa59e7a03bec49ea69425f54.tar.gz
sapd-cd00ce1a7128cf11fa59e7a03bec49ea69425f54.zip
Establish an HFP connection using Bluez on Sailfish
-rw-r--r--rpm/sapd.yaml1
-rw-r--r--sapbtlistener.cc37
-rw-r--r--sapd.pro4
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()
diff --git a/sapd.pro b/sapd.pro
index d29aca3..829254f 100644
--- a/sapd.pro
+++ b/sapd.pro
@@ -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 \