summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-05-19 13:36:59 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-06-02 08:39:06 +0200
commitb28dbaf82f1140420f60d9f26a637f365fac9bbf (patch)
tree061669b0178da2956ccdb8b6ff66dad5f0ae4b0d /src/bluetooth/qbluetoothlocaldevice_bluez.cpp
parentf279b8569289c0c03dad77064c2fc3b1b97a47c4 (diff)
Bluez5: Simplify lookup of default adapter
Change-Id: I59aa5241d33191a8ca8cc167263b63b024f52754 Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth/qbluetoothlocaldevice_bluez.cpp')
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_bluez.cpp49
1 files changed, 6 insertions, 43 deletions
diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
index eb3dcf6e..2539dbb5 100644
--- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
@@ -775,51 +775,14 @@ void QBluetoothLocalDevicePrivate::initializeAdapterBluez5()
connect(managerBluez5, SIGNAL(InterfacesRemoved(QDBusObjectPath,QStringList)),
SLOT(InterfacesRemoved(QDBusObjectPath,QStringList)));
- QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects();
- reply.waitForFinished();
- if (reply.isError())
- return;
-
- typedef QPair<QString, QBluetoothAddress> AddressForPathType;
- QList<AddressForPathType> localAdapters;
-
- foreach (const QDBusObjectPath &path, reply.value().keys()) {
- const InterfaceList ifaceList = reply.value().value(path);
- foreach (const QString &iface, ifaceList.keys()) {
- if (iface == QStringLiteral("org.bluez.Adapter1")) {
- AddressForPathType pair;
- pair.first = path.path();
- pair.second = QBluetoothAddress(ifaceList.value(iface).value(
- QStringLiteral("Address")).toString());
- if (!pair.second.isNull())
- localAdapters.append(pair);
- break;
- }
- }
- }
-
- if (localAdapters.isEmpty())
+ bool ok = true;
+ const QString adapterPath = findAdapterForAddress(localAddress, &ok);
+ if (!ok || adapterPath.isEmpty())
return;
- if (localAddress.isNull()) {
- //concept of DefaultAdapter doesn't exist anymore.
- //we define the first adapter as default
- adapterBluez5 = new OrgBluezAdapter1Interface(QStringLiteral("org.bluez"),
- localAdapters.front().first,
- QDBusConnection::systemBus(), this);
- } else {
- foreach (const AddressForPathType &pair, localAdapters) {
- if (pair.second == localAddress) {
- adapterBluez5 = new OrgBluezAdapter1Interface(QStringLiteral("org.bluez"),
- pair.first,
- QDBusConnection::systemBus(), this);
- break;
- }
- }
-
- if (!adapterBluez5) //no match
- return;
- }
+ adapterBluez5 = new OrgBluezAdapter1Interface(QStringLiteral("org.bluez"),
+ adapterPath,
+ QDBusConnection::systemBus(), this);
if (adapterBluez5) {
//hook up propertiesChanged for current adapter