From de81effb258c9c55af299ef48e79df4de941b391 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 12 Nov 2017 12:33:20 +0100 Subject: Make Bluetooth naming consistent Currently, on Linux, after selecting a Bluetooth device the name of the device is shown. On reopening the download dialog, on the other hand, the address is shown. In the device selection dialog both are shown. This patch changes the download dialog such that both, name and address, are shown. The bulk of the patch introduces the name of the device in the preferences and DCDeviceData. It has to be noted that DCDeviceData is an encapsulation of the libdivecomputer device_data_t. Nevertheless, the new Bluetooth-name field is, at the moment, not passed through to libdivecomputer. Signed-off-by: Berthold Stoeger --- desktop-widgets/btdeviceselectiondialog.cpp | 14 ++++++++++++++ desktop-widgets/btdeviceselectiondialog.h | 2 ++ desktop-widgets/configuredivecomputerdialog.cpp | 8 ++++++-- desktop-widgets/downloadfromdivecomputer.cpp | 16 +++++++--------- 4 files changed, 29 insertions(+), 11 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/btdeviceselectiondialog.cpp b/desktop-widgets/btdeviceselectiondialog.cpp index 1b43c8471..de3e383c5 100644 --- a/desktop-widgets/btdeviceselectiondialog.cpp +++ b/desktop-widgets/btdeviceselectiondialog.cpp @@ -466,6 +466,20 @@ QString BtDeviceSelectionDialog::getSelectedDeviceName() return QString(); } +QString BtDeviceSelectionDialog::getSelectedDeviceText() +{ + return formatDeviceText(getSelectedDeviceAddress(), getSelectedDeviceName()); +} + +QString BtDeviceSelectionDialog::formatDeviceText(const QString &address, const QString &name) +{ + if (address.isEmpty()) + return name; + if (name.isEmpty()) + return address; + return QString("%1 (%2)").arg(name, address); +} + void BtDeviceSelectionDialog::updateLocalDeviceInformation() { #if defined(Q_OS_WIN) diff --git a/desktop-widgets/btdeviceselectiondialog.h b/desktop-widgets/btdeviceselectiondialog.h index e883278ce..67d1ef0b9 100644 --- a/desktop-widgets/btdeviceselectiondialog.h +++ b/desktop-widgets/btdeviceselectiondialog.h @@ -59,6 +59,8 @@ public: ~BtDeviceSelectionDialog(); QString getSelectedDeviceAddress(); QString getSelectedDeviceName(); + QString getSelectedDeviceText(); + static QString formatDeviceText(const QString &address, const QString &name); private slots: void on_changeDeviceState_clicked(); diff --git a/desktop-widgets/configuredivecomputerdialog.cpp b/desktop-widgets/configuredivecomputerdialog.cpp index 24fe63c3e..dd9913da4 100644 --- a/desktop-widgets/configuredivecomputerdialog.cpp +++ b/desktop-widgets/configuredivecomputerdialog.cpp @@ -904,7 +904,9 @@ void ConfigureDiveComputerDialog::configError(QString err) void ConfigureDiveComputerDialog::getDeviceData() { - device_data.devname = strdup(ui.device->currentText().toUtf8().data()); + QString device = ui.bluetoothMode && btDeviceSelectionDialog ? + btDeviceSelectionDialog->getSelectedDeviceAddress() : ui.device->currentText(); + device_data.devname = strdup(device.toUtf8().data()); device_data.vendor = strdup(selected_vendor.toUtf8().data()); device_data.product = strdup(selected_product.toUtf8().data()); @@ -913,6 +915,8 @@ void ConfigureDiveComputerDialog::getDeviceData() auto dc = SettingsObjectWrapper::instance()->dive_computer_settings; dc->setDevice(device_data.devname); + if (ui.bluetoothMode && btDeviceSelectionDialog) + dc->setDeviceName(btDeviceSelectionDialog->getSelectedDeviceName()); } void ConfigureDiveComputerDialog::on_cancel_clicked() @@ -1488,7 +1492,7 @@ void ConfigureDiveComputerDialog::selectRemoteBluetoothDevice() void ConfigureDiveComputerDialog::bluetoothSelectionDialogIsFinished(int result) { if (result == QDialog::Accepted) { - ui.device->setCurrentText(btDeviceSelectionDialog->getSelectedDeviceAddress()); + ui.device->setCurrentText(btDeviceSelectionDialog->getSelectedDeviceText()); device_data.bluetooth_mode = true; ui.progressBar->setFormat("Connecting to device..."); diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index f4506fd4c..0dd98d35a 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -84,14 +84,13 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) : if (!dc->dc_product().isEmpty()) ui.product->setCurrentIndex(ui.product->findText(dc->dc_product())); } - if (!dc->dc_device().isEmpty()) - ui.device->setEditText(dc->dc_device()); updateState(INITIAL); ui.ok->setEnabled(false); ui.downloadCancelRetryButton->setEnabled(true); ui.downloadCancelRetryButton->setText(tr("Download")); + QString deviceText = dc->dc_device(); #if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_IO) ui.bluetoothMode->setText(tr("Choose Bluetooth download mode")); ui.bluetoothMode->setChecked(dc->downloadMode() == DC_TRANSPORT_BLUETOOTH); @@ -99,10 +98,14 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) : connect(ui.bluetoothMode, SIGNAL(stateChanged(int)), this, SLOT(enableBluetoothMode(int))); connect(ui.chooseBluetoothDevice, SIGNAL(clicked()), this, SLOT(selectRemoteBluetoothDevice())); ui.chooseBluetoothDevice->setEnabled(ui.bluetoothMode->isChecked()); + if (ui.bluetoothMode->isChecked()) + deviceText = BtDeviceSelectionDialog::formatDeviceText(dc->dc_device(), dc->dc_device_name()); #else ui.bluetoothMode->hide(); ui.chooseBluetoothDevice->hide(); #endif + if (!deviceText.isEmpty()) + ui.device->setEditText(deviceText); } void DownloadFromDCWidget::updateProgressBar() @@ -291,6 +294,7 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked() if (data->bluetoothMode() && btDeviceSelectionDialog != NULL) { // Get the selected device address data->setDevName(btDeviceSelectionDialog->getSelectedDeviceAddress()); + data->setDevBluetoothName(btDeviceSelectionDialog->getSelectedDeviceName()); } else // this breaks an "else if" across lines... not happy... #endif @@ -544,13 +548,7 @@ void DownloadFromDCWidget::bluetoothSelectionDialogIsFinished(int result) { if (result == QDialog::Accepted) { /* Make the selected Bluetooth device default */ - QString selectedDeviceName = btDeviceSelectionDialog->getSelectedDeviceName(); - - if (selectedDeviceName.isEmpty()) { - ui.device->setCurrentText(btDeviceSelectionDialog->getSelectedDeviceAddress()); - } else { - ui.device->setCurrentText(selectedDeviceName); - } + ui.device->setEditText(btDeviceSelectionDialog->getSelectedDeviceText()); } else if (result == QDialog::Rejected){ /* Disable Bluetooth download mode */ ui.bluetoothMode->setChecked(false); -- cgit v1.2.3-70-g09d2