From e5b7fb74b498679ceceff2f6fa1c707b27f17ed9 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 16 Sep 2017 20:18:12 -0700 Subject: BLE: on Mac/iOS use UUID instead of address Signed-off-by: Dirk Hohndel --- desktop-widgets/btdeviceselectiondialog.cpp | 34 +++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'desktop-widgets') 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 #include #include +#include "core/btdiscovery.h" + +#include #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(); 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; } -- cgit v1.2.3-70-g09d2 From 26e610c3f409e771c4e0e7ba955db7f4155b8825 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 16 Sep 2017 20:21:46 -0700 Subject: BLE: create controller from QBtDeviceInfo Creating it from an address is a) deprecated and b) impossible on Mac or iOS. Signed-off-by: Dirk Hohndel --- core/qt-ble.cpp | 6 +++--- desktop-widgets/btdeviceselectiondialog.cpp | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'desktop-widgets') diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index 9867528c8..eca615fbe 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -16,6 +16,7 @@ #include "libdivecomputer.h" #include "core/qt-ble.h" +#include "core/btdiscovery.h" #if defined(SSRF_CUSTOM_IO) @@ -287,12 +288,11 @@ dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *d if (!strncmp(devaddr, "LE:", 3)) devaddr += 3; - QBluetoothAddress remoteDeviceAddress(devaddr); - // HACK ALERT! Qt 5.9 needs this for proper Bluez operation qputenv("QT_DEFAULT_CENTRAL_SERVICES", "1"); - QLowEnergyController *controller = new QLowEnergyController(remoteDeviceAddress); + QBluetoothDeviceInfo remoteDevice = getBtDeviceInfo(devaddr); + QLowEnergyController *controller = QLowEnergyController::createCentral(remoteDevice); qDebug() << "qt_ble_open(" << devaddr << ")"; diff --git a/desktop-widgets/btdeviceselectiondialog.cpp b/desktop-widgets/btdeviceselectiondialog.cpp index eb05c4f42..cf70daa3f 100644 --- a/desktop-widgets/btdeviceselectiondialog.cpp +++ b/desktop-widgets/btdeviceselectiondialog.cpp @@ -152,7 +152,9 @@ void BtDeviceSelectionDialog::on_save_clicked() // Save the selected device selectedRemoteDeviceInfo = QSharedPointer(new QBluetoothDeviceInfo(remoteDeviceInfo)); - + QString address = remoteDeviceInfo.address().isNull() ? remoteDeviceInfo.deviceUuid().toString() : + remoteDeviceInfo.address().toString(); + saveBtDeviceInfo(address.toUtf8().constData(), remoteDeviceInfo); if (remoteDeviceDiscoveryAgent->isActive()) { // Stop the SDP agent if the clear button is pressed and enable the Scan button remoteDeviceDiscoveryAgent->stop(); -- cgit v1.2.3-70-g09d2 From 605400a029160f9089840e65977ecebecba4b2f2 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 17 Sep 2017 14:49:37 -0700 Subject: DC download: don't clear message if no dives downloaded Otherwise the text telling the user that no new dives were found will be deleted right away. Signed-off-by: Dirk Hohndel --- desktop-widgets/downloadfromdivecomputer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index 74501dcdb..2601c6f19 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -165,7 +165,8 @@ void DownloadFromDCWidget::updateState(states state) markChildrenAsEnabled(); progress_bar_text = ""; } else { - progress_bar_text = ""; + if (downloadTable.nr != 0) + progress_bar_text = ""; ui.progressBar->setValue(100); markChildrenAsEnabled(); } -- cgit v1.2.3-70-g09d2 From d03fabd3732adb13e3229f4faa2883f45e15aa21 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 17 Sep 2017 15:02:11 -0700 Subject: DC download: better message at beginning of download Especially on BT/BLE devices, where there is a longer negotiation phase at the beginning of the download, this seems more user friendly. Signed-off-by: Dirk Hohndel --- desktop-widgets/downloadfromdivecomputer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index 2601c6f19..5eaee68b7 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -113,7 +113,10 @@ void DownloadFromDCWidget::updateProgressBar() if (!same_string(progress_bar_text , "")) { ui.progressBar->setFormat(progress_bar_text); } else { - ui.progressBar->setFormat("%p%"); + if (IS_FP_SAME(progress_bar_fraction, 0.0)) + ui.progressBar->setFormat(tr("Connecting to dive computer")); + else + ui.progressBar->setFormat("%p%"); } ui.progressBar->setValue(lrint(progress_bar_fraction * 100)); free(last_text); -- cgit v1.2.3-70-g09d2 From 49fe120d9530682cf539d562c4ffcae3e195b9ab Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 17 Sep 2017 15:04:14 -0700 Subject: DC download: show info messages on Mac For some reason the progress bar on macOS doesn't show the progress text. This creates a label below the progress bar and shows the text there instead. Signed-off-by: Dirk Hohndel --- desktop-widgets/downloadfromdivecomputer.cpp | 33 ++++++++++++++++++++++++++-- desktop-widgets/downloadfromdivecomputer.ui | 7 ++++++ 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index 5eaee68b7..424cf277a 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -112,11 +112,24 @@ void DownloadFromDCWidget::updateProgressBar() } if (!same_string(progress_bar_text , "")) { ui.progressBar->setFormat(progress_bar_text); +#if defined(Q_OS_MAC) + // on mac the progress bar doesn't show its text + ui.progressText->setText(progress_bar_text); +#endif } else { - if (IS_FP_SAME(progress_bar_fraction, 0.0)) + if (IS_FP_SAME(progress_bar_fraction, 0.0)) { ui.progressBar->setFormat(tr("Connecting to dive computer")); - else +#if defined(Q_OS_MAC) + // on mac the progress bar doesn't show its text + ui.progressText->setText(tr("Connecting to dive computer")); +#endif + } else { ui.progressBar->setFormat("%p%"); +#if defined(Q_OS_MAC) + // on mac the progress bar doesn't show its text + ui.progressText->setText(QString("%1%").arg(lrint(progress_bar_fraction * 100))); +#endif + } } ui.progressBar->setValue(lrint(progress_bar_fraction * 100)); free(last_text); @@ -134,6 +147,10 @@ void DownloadFromDCWidget::updateState(states state) markChildrenAsEnabled(); timer->stop(); progress_bar_text = ""; +#if defined(Q_OS_MAC) + // on mac we show the text in a label + ui.progressText->setText(progress_bar_text); +#endif } // tries to cancel an on going download @@ -156,6 +173,10 @@ void DownloadFromDCWidget::updateState(states state) ui.progressBar->hide(); markChildrenAsEnabled(); progress_bar_text = ""; +#if defined(Q_OS_MAC) + // on mac we show the text in a label + ui.progressText->setText(progress_bar_text); +#endif } // DOWNLOAD is finally done, but we don't know if there was an error as libdivecomputer doesn't pass @@ -173,6 +194,10 @@ void DownloadFromDCWidget::updateState(states state) ui.progressBar->setValue(100); markChildrenAsEnabled(); } +#if defined(Q_OS_MAC) + // on mac we show the text in a label + ui.progressText->setText(progress_bar_text); +#endif } // DOWNLOAD is started. @@ -192,6 +217,10 @@ void DownloadFromDCWidget::updateState(states state) markChildrenAsEnabled(); progress_bar_text = ""; ui.progressBar->hide(); +#if defined(Q_OS_MAC) + // on mac we show the text in a label + ui.progressText->setText(progress_bar_text); +#endif } // properly updating the widget state diff --git a/desktop-widgets/downloadfromdivecomputer.ui b/desktop-widgets/downloadfromdivecomputer.ui index b1f152034..10d654b46 100644 --- a/desktop-widgets/downloadfromdivecomputer.ui +++ b/desktop-widgets/downloadfromdivecomputer.ui @@ -189,6 +189,13 @@ + + + + + + + -- cgit v1.2.3-70-g09d2