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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2017-11-12 12:33:20 +01:00 committed by Dirk Hohndel
parent 0d023068b3
commit de81effb25
9 changed files with 69 additions and 11 deletions

View file

@ -56,6 +56,7 @@ void DownloadThread::run()
dcs->setVendor(internalData->vendor); dcs->setVendor(internalData->vendor);
dcs->setProduct(internalData->product); dcs->setProduct(internalData->product);
dcs->setDevice(internalData->devname); dcs->setDevice(internalData->devname);
dcs->setDeviceName(m_data->devBluetoothName());
} }
static void fill_supported_mobile_list() static void fill_supported_mobile_list()
@ -239,6 +240,11 @@ QString DCDeviceData::devName() const
return data.devname; return data.devname;
} }
QString DCDeviceData::devBluetoothName() const
{
return m_devBluetoothName;
}
QString DCDeviceData::descriptor() const QString DCDeviceData::descriptor() const
{ {
return ""; return "";
@ -284,6 +290,11 @@ void DCDeviceData::setDevName(const QString& devName)
data.devname = strdup(qPrintable(devName)); data.devname = strdup(qPrintable(devName));
} }
void DCDeviceData::setDevBluetoothName(const QString& name)
{
m_devBluetoothName = name;
}
void DCDeviceData::setBluetoothMode(bool mode) void DCDeviceData::setBluetoothMode(bool mode)
{ {
data.bluetooth_mode = mode; data.bluetooth_mode = mode;

View file

@ -19,6 +19,7 @@ class DCDeviceData : public QObject {
Q_PROPERTY(QString product READ product WRITE setProduct) Q_PROPERTY(QString product READ product WRITE setProduct)
Q_PROPERTY(bool bluetoothMode READ bluetoothMode WRITE setBluetoothMode) Q_PROPERTY(bool bluetoothMode READ bluetoothMode WRITE setBluetoothMode)
Q_PROPERTY(QString devName READ devName WRITE setDevName) Q_PROPERTY(QString devName READ devName WRITE setDevName)
Q_PROPERTY(QString devBluetoothName READ devBluetoothName WRITE setDevBluetoothName)
Q_PROPERTY(QString descriptor READ descriptor) Q_PROPERTY(QString descriptor READ descriptor)
Q_PROPERTY(bool forceDownload READ forceDownload WRITE setForceDownload) Q_PROPERTY(bool forceDownload READ forceDownload WRITE setForceDownload)
Q_PROPERTY(bool createNewTrip READ createNewTrip WRITE setCreateNewTrip) Q_PROPERTY(bool createNewTrip READ createNewTrip WRITE setCreateNewTrip)
@ -34,6 +35,7 @@ public:
QString vendor() const; QString vendor() const;
QString product() const; QString product() const;
QString devName() const; QString devName() const;
QString devBluetoothName() const;
QString descriptor() const; QString descriptor() const;
bool bluetoothMode() const; bool bluetoothMode() const;
bool forceDownload() const; bool forceDownload() const;
@ -57,6 +59,7 @@ public slots:
void setVendor(const QString& vendor); void setVendor(const QString& vendor);
void setProduct(const QString& product); void setProduct(const QString& product);
void setDevName(const QString& devName); void setDevName(const QString& devName);
void setDevBluetoothName(const QString& devBluetoothName);
void setBluetoothMode(bool mode); void setBluetoothMode(bool mode);
void setForceDownload(bool force); void setForceDownload(bool force);
void setCreateNewTrip(bool create); void setCreateNewTrip(bool create);
@ -67,6 +70,9 @@ public slots:
private: private:
static DCDeviceData *m_instance; static DCDeviceData *m_instance;
device_data_t data; device_data_t data;
// Bluetooth name is managed outside of libdivecomputer
QString m_devBluetoothName;
}; };
class DownloadThread : public QThread { class DownloadThread : public QThread {

View file

@ -54,6 +54,7 @@ typedef struct {
char *vendor; char *vendor;
char *product; char *product;
char *device; char *device;
char *device_name;
int download_mode; int download_mode;
} dive_computer_prefs_t; } dive_computer_prefs_t;

View file

@ -29,6 +29,11 @@ QString DiveComputerSettings::dc_device() const
return prefs.dive_computer.device; return prefs.dive_computer.device;
} }
QString DiveComputerSettings::dc_device_name() const
{
return prefs.dive_computer.device_name;
}
int DiveComputerSettings::downloadMode() const int DiveComputerSettings::downloadMode() const
{ {
return prefs.dive_computer.download_mode; return prefs.dive_computer.download_mode;
@ -70,6 +75,18 @@ void DiveComputerSettings::setDevice(const QString& device)
prefs.dive_computer.device = copy_string(qPrintable(device)); prefs.dive_computer.device = copy_string(qPrintable(device));
} }
void DiveComputerSettings::setDeviceName(const QString& device_name)
{
if (device_name == prefs.dive_computer.device_name)
return;
QSettings s;
s.beginGroup(group);
s.setValue("dive_computer_device_name", device_name);
free(prefs.dive_computer.device_name);
prefs.dive_computer.device_name = copy_string(qPrintable(device_name));
}
void DiveComputerSettings::setDownloadMode(int mode) void DiveComputerSettings::setDownloadMode(int mode)
{ {
if (mode == prefs.dive_computer.download_mode) if (mode == prefs.dive_computer.download_mode)
@ -2333,6 +2350,7 @@ void SettingsObjectWrapper::load()
GET_TXT("dive_computer_vendor",dive_computer.vendor); GET_TXT("dive_computer_vendor",dive_computer.vendor);
GET_TXT("dive_computer_product", dive_computer.product); GET_TXT("dive_computer_product", dive_computer.product);
GET_TXT("dive_computer_device", dive_computer.device); GET_TXT("dive_computer_device", dive_computer.device);
GET_TXT("dive_computer_device_name", dive_computer.device_name);
GET_INT("dive_computer_download_mode", dive_computer.download_mode); GET_INT("dive_computer_download_mode", dive_computer.download_mode);
s.endGroup(); s.endGroup();

View file

@ -18,24 +18,28 @@ class DiveComputerSettings : public QObject {
Q_PROPERTY(QString vendor READ dc_vendor WRITE setVendor NOTIFY vendorChanged) Q_PROPERTY(QString vendor READ dc_vendor WRITE setVendor NOTIFY vendorChanged)
Q_PROPERTY(QString product READ dc_product WRITE setProduct NOTIFY productChanged) Q_PROPERTY(QString product READ dc_product WRITE setProduct NOTIFY productChanged)
Q_PROPERTY(QString device READ dc_device WRITE setDevice NOTIFY deviceChanged) Q_PROPERTY(QString device READ dc_device WRITE setDevice NOTIFY deviceChanged)
Q_PROPERTY(QString device_name READ dc_device_name WRITE setDeviceName NOTIFY deviceNameChanged)
Q_PROPERTY(int download_mode READ downloadMode WRITE setDownloadMode NOTIFY downloadModeChanged) Q_PROPERTY(int download_mode READ downloadMode WRITE setDownloadMode NOTIFY downloadModeChanged)
public: public:
DiveComputerSettings(QObject *parent); DiveComputerSettings(QObject *parent);
QString dc_vendor() const; QString dc_vendor() const;
QString dc_product() const; QString dc_product() const;
QString dc_device() const; QString dc_device() const;
QString dc_device_name() const;
int downloadMode() const; int downloadMode() const;
public slots: public slots:
void setVendor(const QString& vendor); void setVendor(const QString& vendor);
void setProduct(const QString& product); void setProduct(const QString& product);
void setDevice(const QString& device); void setDevice(const QString& device);
void setDeviceName(const QString& device_name);
void setDownloadMode(int mode); void setDownloadMode(int mode);
signals: signals:
void vendorChanged(const QString& vendor); void vendorChanged(const QString& vendor);
void productChanged(const QString& product); void productChanged(const QString& product);
void deviceChanged(const QString& device); void deviceChanged(const QString& device);
void deviceNameChanged(const QString& device_name);
void downloadModeChanged(int mode); void downloadModeChanged(int mode);
private: private:
const QString group = QStringLiteral("DiveComputer"); const QString group = QStringLiteral("DiveComputer");

View file

@ -466,6 +466,20 @@ QString BtDeviceSelectionDialog::getSelectedDeviceName()
return QString(); 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() void BtDeviceSelectionDialog::updateLocalDeviceInformation()
{ {
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)

View file

@ -59,6 +59,8 @@ public:
~BtDeviceSelectionDialog(); ~BtDeviceSelectionDialog();
QString getSelectedDeviceAddress(); QString getSelectedDeviceAddress();
QString getSelectedDeviceName(); QString getSelectedDeviceName();
QString getSelectedDeviceText();
static QString formatDeviceText(const QString &address, const QString &name);
private slots: private slots:
void on_changeDeviceState_clicked(); void on_changeDeviceState_clicked();

View file

@ -904,7 +904,9 @@ void ConfigureDiveComputerDialog::configError(QString err)
void ConfigureDiveComputerDialog::getDeviceData() 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.vendor = strdup(selected_vendor.toUtf8().data());
device_data.product = strdup(selected_product.toUtf8().data()); device_data.product = strdup(selected_product.toUtf8().data());
@ -913,6 +915,8 @@ void ConfigureDiveComputerDialog::getDeviceData()
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings; auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
dc->setDevice(device_data.devname); dc->setDevice(device_data.devname);
if (ui.bluetoothMode && btDeviceSelectionDialog)
dc->setDeviceName(btDeviceSelectionDialog->getSelectedDeviceName());
} }
void ConfigureDiveComputerDialog::on_cancel_clicked() void ConfigureDiveComputerDialog::on_cancel_clicked()
@ -1488,7 +1492,7 @@ void ConfigureDiveComputerDialog::selectRemoteBluetoothDevice()
void ConfigureDiveComputerDialog::bluetoothSelectionDialogIsFinished(int result) void ConfigureDiveComputerDialog::bluetoothSelectionDialogIsFinished(int result)
{ {
if (result == QDialog::Accepted) { if (result == QDialog::Accepted) {
ui.device->setCurrentText(btDeviceSelectionDialog->getSelectedDeviceAddress()); ui.device->setCurrentText(btDeviceSelectionDialog->getSelectedDeviceText());
device_data.bluetooth_mode = true; device_data.bluetooth_mode = true;
ui.progressBar->setFormat("Connecting to device..."); ui.progressBar->setFormat("Connecting to device...");

View file

@ -84,14 +84,13 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
if (!dc->dc_product().isEmpty()) if (!dc->dc_product().isEmpty())
ui.product->setCurrentIndex(ui.product->findText(dc->dc_product())); ui.product->setCurrentIndex(ui.product->findText(dc->dc_product()));
} }
if (!dc->dc_device().isEmpty())
ui.device->setEditText(dc->dc_device());
updateState(INITIAL); updateState(INITIAL);
ui.ok->setEnabled(false); ui.ok->setEnabled(false);
ui.downloadCancelRetryButton->setEnabled(true); ui.downloadCancelRetryButton->setEnabled(true);
ui.downloadCancelRetryButton->setText(tr("Download")); ui.downloadCancelRetryButton->setText(tr("Download"));
QString deviceText = dc->dc_device();
#if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_IO) #if defined(BT_SUPPORT) && defined(SSRF_CUSTOM_IO)
ui.bluetoothMode->setText(tr("Choose Bluetooth download mode")); ui.bluetoothMode->setText(tr("Choose Bluetooth download mode"));
ui.bluetoothMode->setChecked(dc->downloadMode() == DC_TRANSPORT_BLUETOOTH); 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.bluetoothMode, SIGNAL(stateChanged(int)), this, SLOT(enableBluetoothMode(int)));
connect(ui.chooseBluetoothDevice, SIGNAL(clicked()), this, SLOT(selectRemoteBluetoothDevice())); connect(ui.chooseBluetoothDevice, SIGNAL(clicked()), this, SLOT(selectRemoteBluetoothDevice()));
ui.chooseBluetoothDevice->setEnabled(ui.bluetoothMode->isChecked()); ui.chooseBluetoothDevice->setEnabled(ui.bluetoothMode->isChecked());
if (ui.bluetoothMode->isChecked())
deviceText = BtDeviceSelectionDialog::formatDeviceText(dc->dc_device(), dc->dc_device_name());
#else #else
ui.bluetoothMode->hide(); ui.bluetoothMode->hide();
ui.chooseBluetoothDevice->hide(); ui.chooseBluetoothDevice->hide();
#endif #endif
if (!deviceText.isEmpty())
ui.device->setEditText(deviceText);
} }
void DownloadFromDCWidget::updateProgressBar() void DownloadFromDCWidget::updateProgressBar()
@ -291,6 +294,7 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
if (data->bluetoothMode() && btDeviceSelectionDialog != NULL) { if (data->bluetoothMode() && btDeviceSelectionDialog != NULL) {
// Get the selected device address // Get the selected device address
data->setDevName(btDeviceSelectionDialog->getSelectedDeviceAddress()); data->setDevName(btDeviceSelectionDialog->getSelectedDeviceAddress());
data->setDevBluetoothName(btDeviceSelectionDialog->getSelectedDeviceName());
} else } else
// this breaks an "else if" across lines... not happy... // this breaks an "else if" across lines... not happy...
#endif #endif
@ -544,13 +548,7 @@ void DownloadFromDCWidget::bluetoothSelectionDialogIsFinished(int result)
{ {
if (result == QDialog::Accepted) { if (result == QDialog::Accepted) {
/* Make the selected Bluetooth device default */ /* Make the selected Bluetooth device default */
QString selectedDeviceName = btDeviceSelectionDialog->getSelectedDeviceName(); ui.device->setEditText(btDeviceSelectionDialog->getSelectedDeviceText());
if (selectedDeviceName.isEmpty()) {
ui.device->setCurrentText(btDeviceSelectionDialog->getSelectedDeviceAddress());
} else {
ui.device->setCurrentText(selectedDeviceName);
}
} else if (result == QDialog::Rejected){ } else if (result == QDialog::Rejected){
/* Disable Bluetooth download mode */ /* Disable Bluetooth download mode */
ui.bluetoothMode->setChecked(false); ui.bluetoothMode->setChecked(false);