diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2017-09-16 20:18:12 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-09-17 09:56:28 -0700 |
commit | e5b7fb74b498679ceceff2f6fa1c707b27f17ed9 (patch) | |
tree | 665cfae5bfc0b8b0d79dc41aa4f247579dc32bf4 /desktop-widgets/btdeviceselectiondialog.cpp | |
parent | 5695ef956b9395dbe924b097a96359c5acacb53f (diff) | |
download | subsurface-e5b7fb74b498679ceceff2f6fa1c707b27f17ed9.tar.gz |
BLE: on Mac/iOS use UUID instead of address
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets/btdeviceselectiondialog.cpp')
-rw-r--r-- | desktop-widgets/btdeviceselectiondialog.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/desktop-widgets/btdeviceselectiondialog.cpp b/desktop-widgets/btdeviceselectiondialog.cpp index 049246703..eb05c4f42 100644 --- a/desktop-widgets/btdeviceselectiondialog.cpp +++ b/desktop-widgets/btdeviceselectiondialog.cpp @@ -3,6 +3,9 @@ #include <QDebug> #include <QMessageBox> #include <QMenu> +#include "core/btdiscovery.h" + +#include <QBluetoothUuid> #include "ui_btdeviceselectiondialog.h" #include "btdeviceselectiondialog.h" @@ -236,8 +239,16 @@ void BtDeviceSelectionDialog::addRemoteDevice(const QBluetoothDeviceInfo &remote if (remoteDeviceInfo.address().isNull()) pairingColor = QColor(Qt::gray); + QString deviceLabel; - QString deviceLabel = tr("%1 (%2) [State: %3]").arg(remoteDeviceInfo.name(), +#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) + if (!remoteDeviceInfo.deviceUuid().isNull()) { + // we have only a Uuid, no address, so show that and reset the pairing color + deviceLabel = QString("%1 (%2)").arg(remoteDeviceInfo.name(),remoteDeviceInfo.deviceUuid().toString()); + pairingColor = QColor(Qt::white); + } else +#endif + deviceLabel = tr("%1 (%2) [State: %3]").arg(remoteDeviceInfo.name(), remoteDeviceInfo.address().toString(), pairingStatusLabel); #endif @@ -255,19 +266,24 @@ void BtDeviceSelectionDialog::itemClicked(QListWidgetItem *item) // By default we assume that the devices are paired QBluetoothDeviceInfo remoteDeviceInfo = item->data(Qt::UserRole).value<QBluetoothDeviceInfo>(); QString statusMessage = tr("The device %1 can be used for connection. You can press the Save button.") - .arg(remoteDeviceInfo.address().toString()); + .arg(remoteDeviceInfo.address().isNull() ? + remoteDeviceInfo.deviceUuid().toString() : + remoteDeviceInfo.address().toString()); bool enableSaveButton = true; #if !defined(Q_OS_WIN) // On other platforms than Windows we can obtain the pairing status so if the devices are not paired we disable the button - QBluetoothLocalDevice::Pairing pairingStatus = localDevice->pairingStatus(remoteDeviceInfo.address()); - - if (pairingStatus == QBluetoothLocalDevice::Unpaired) { - statusMessage = tr("The device %1 must be paired in order to be used. Please use the context menu for pairing options.") - .arg(remoteDeviceInfo.address().toString()); - enableSaveButton = false; + // except on MacOS for those devices that only give us a Uuid and not and address (as we have no pairing status for those, either) + if (!remoteDeviceInfo.address().isNull()) { + QBluetoothLocalDevice::Pairing pairingStatus = localDevice->pairingStatus(remoteDeviceInfo.address()); + + if (pairingStatus == QBluetoothLocalDevice::Unpaired) { + statusMessage = tr("The device %1 must be paired in order to be used. Please use the context menu for pairing options.") + .arg(remoteDeviceInfo.address().toString()); + enableSaveButton = false; + } } - if (remoteDeviceInfo.address().isNull()) { + if (remoteDeviceInfo.address().isNull() && remoteDeviceInfo.deviceUuid().isNull()) { statusMessage = tr("A device needs a non-zero address for a connection."); enableSaveButton = false; } |