mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
BLE: on Mac/iOS use UUID instead of address
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5695ef956b
commit
e5b7fb74b4
1 changed files with 24 additions and 8 deletions
|
@ -3,6 +3,9 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include "core/btdiscovery.h"
|
||||||
|
|
||||||
|
#include <QBluetoothUuid>
|
||||||
|
|
||||||
#include "ui_btdeviceselectiondialog.h"
|
#include "ui_btdeviceselectiondialog.h"
|
||||||
#include "btdeviceselectiondialog.h"
|
#include "btdeviceselectiondialog.h"
|
||||||
|
@ -236,8 +239,16 @@ void BtDeviceSelectionDialog::addRemoteDevice(const QBluetoothDeviceInfo &remote
|
||||||
if (remoteDeviceInfo.address().isNull())
|
if (remoteDeviceInfo.address().isNull())
|
||||||
pairingColor = QColor(Qt::gray);
|
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(),
|
remoteDeviceInfo.address().toString(),
|
||||||
pairingStatusLabel);
|
pairingStatusLabel);
|
||||||
#endif
|
#endif
|
||||||
|
@ -255,11 +266,15 @@ void BtDeviceSelectionDialog::itemClicked(QListWidgetItem *item)
|
||||||
// By default we assume that the devices are paired
|
// By default we assume that the devices are paired
|
||||||
QBluetoothDeviceInfo remoteDeviceInfo = item->data(Qt::UserRole).value<QBluetoothDeviceInfo>();
|
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.")
|
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;
|
bool enableSaveButton = true;
|
||||||
|
|
||||||
#if !defined(Q_OS_WIN)
|
#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
|
// On other platforms than Windows we can obtain the pairing status so if the devices are not paired we disable the button
|
||||||
|
// 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());
|
QBluetoothLocalDevice::Pairing pairingStatus = localDevice->pairingStatus(remoteDeviceInfo.address());
|
||||||
|
|
||||||
if (pairingStatus == QBluetoothLocalDevice::Unpaired) {
|
if (pairingStatus == QBluetoothLocalDevice::Unpaired) {
|
||||||
|
@ -267,7 +282,8 @@ void BtDeviceSelectionDialog::itemClicked(QListWidgetItem *item)
|
||||||
.arg(remoteDeviceInfo.address().toString());
|
.arg(remoteDeviceInfo.address().toString());
|
||||||
enableSaveButton = false;
|
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.");
|
statusMessage = tr("A device needs a non-zero address for a connection.");
|
||||||
enableSaveButton = false;
|
enableSaveButton = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue