mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 23:23:23 +00:00
Desktop: Load the Dive Computer List in 'Configure Dive Computer' Dynamically.
Load the dive computer list in the 'Change Settings on Dive Computer' dialog dynamically. Also incorporate suggestions from https://github.com/subsurface/subsurface/pull/3925#issuecomment-1595784076. Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
parent
695c37499a
commit
4ac27e3c71
1 changed files with 19 additions and 18 deletions
|
@ -106,12 +106,15 @@ struct DiveComputerEntry {
|
||||||
bool fwUpgradePossible;
|
bool fwUpgradePossible;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::array<struct DiveComputerEntry, 4> supportedDiveComputers = {{
|
//WARNING: Do not edit this list or even just change its order without
|
||||||
|
// making corresponding changes to the `DiveComputerList` element
|
||||||
|
// in `configuredivecomputerdialog.ui` or this functionality will stop working.
|
||||||
|
static const DiveComputerEntry supportedDiveComputers[] = {
|
||||||
{ "Heinrichs Weikamp", "OSTC 2N", DC_TRANSPORT_SERIAL, true },
|
{ "Heinrichs Weikamp", "OSTC 2N", DC_TRANSPORT_SERIAL, true },
|
||||||
{ "Heinrichs Weikamp", "OSTC Plus", DC_TRANSPORT_BLUETOOTH, true },
|
{ "Heinrichs Weikamp", "OSTC Plus", DC_TRANSPORT_BLUETOOTH, true },
|
||||||
{ "Heinrichs Weikamp", "OSTC 4", DC_TRANSPORT_BLUETOOTH, true },
|
{ "Heinrichs Weikamp", "OSTC 4", DC_TRANSPORT_BLUETOOTH, true },
|
||||||
{ "Suunto", "Vyper", DC_TRANSPORT_SERIAL, false },
|
{ "Suunto", "Vyper", DC_TRANSPORT_SERIAL, false },
|
||||||
}};
|
};
|
||||||
|
|
||||||
ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDialog(parent),
|
ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDialog(parent),
|
||||||
config(0),
|
config(0),
|
||||||
|
@ -148,13 +151,11 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDia
|
||||||
fill_computer_list();
|
fill_computer_list();
|
||||||
|
|
||||||
unsigned int selectedDiveComputerIndex = 0;
|
unsigned int selectedDiveComputerIndex = 0;
|
||||||
for (unsigned i = 0; i < supportedDiveComputers.size(); ++i) {
|
const auto it = std::find_if(std::begin(supportedDiveComputers), std::end(supportedDiveComputers), [](const DiveComputerEntry &entry) {
|
||||||
if (supportedDiveComputers[i].vendor == qPrefDiveComputer::vendor() &&
|
return entry.vendor == qPrefDiveComputer::vendor() && entry.product == qPrefDiveComputer::product();
|
||||||
supportedDiveComputers[i].product == qPrefDiveComputer::product()) {
|
});
|
||||||
selectedDiveComputerIndex = i;
|
if (it != std::end(supportedDiveComputers)) {
|
||||||
|
selectedDiveComputerIndex = it - std::begin(supportedDiveComputers);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.DiveComputerList->setCurrentRow(selectedDiveComputerIndex);
|
ui.DiveComputerList->setCurrentRow(selectedDiveComputerIndex);
|
||||||
|
@ -947,9 +948,10 @@ void ConfigureDiveComputerDialog::getDeviceData()
|
||||||
}
|
}
|
||||||
device_data.devname = copy_qstring(device);
|
device_data.devname = copy_qstring(device);
|
||||||
|
|
||||||
unsigned int selectedDiveComputerIndex = ui.DiveComputerList->currentRow();
|
const DiveComputerEntry selectedDiveComputer = supportedDiveComputers[ui.DiveComputerList->currentRow()];
|
||||||
QString vendor = supportedDiveComputers[selectedDiveComputerIndex].vendor;
|
|
||||||
QString product = supportedDiveComputers[selectedDiveComputerIndex].product;
|
QString vendor = selectedDiveComputer.vendor;
|
||||||
|
QString product = selectedDiveComputer.product;
|
||||||
device_data.vendor = copy_qstring(vendor);
|
device_data.vendor = copy_qstring(vendor);
|
||||||
device_data.product = copy_qstring(product);
|
device_data.product = copy_qstring(product);
|
||||||
device_data.descriptor = descriptorLookup.value(vendor.toLower() + product.toLower());
|
device_data.descriptor = descriptorLookup.value(vendor.toLower() + product.toLower());
|
||||||
|
@ -1462,11 +1464,10 @@ void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked()
|
||||||
void ConfigureDiveComputerDialog::on_DiveComputerList_currentRowChanged(int currentRow)
|
void ConfigureDiveComputerDialog::on_DiveComputerList_currentRowChanged(int currentRow)
|
||||||
{
|
{
|
||||||
unsigned int transport = supportedDiveComputers[currentRow].transport;
|
unsigned int transport = supportedDiveComputers[currentRow].transport;
|
||||||
|
if (transport == DC_TRANSPORT_BLUETOOTH)
|
||||||
if (transport != DC_TRANSPORT_BLUETOOTH)
|
|
||||||
ui.connectBluetoothButton->setEnabled(false);
|
|
||||||
else
|
|
||||||
ui.connectBluetoothButton->setEnabled(true);
|
ui.connectBluetoothButton->setEnabled(true);
|
||||||
|
else
|
||||||
|
ui.connectBluetoothButton->setEnabled(false);
|
||||||
|
|
||||||
fill_device_list(transport);
|
fill_device_list(transport);
|
||||||
}
|
}
|
||||||
|
@ -1535,8 +1536,8 @@ void ConfigureDiveComputerDialog::dc_open()
|
||||||
ui.DiveComputerList->setEnabled(false);
|
ui.DiveComputerList->setEnabled(false);
|
||||||
ui.logToFile->setEnabled(false);
|
ui.logToFile->setEnabled(false);
|
||||||
|
|
||||||
unsigned int selectedDiveComputerIndex = ui.DiveComputerList->currentRow();
|
const DiveComputerEntry selectedDiveComputer = supportedDiveComputers[ui.DiveComputerList->currentRow()];
|
||||||
ui.updateFirmwareButton->setEnabled(supportedDiveComputers[selectedDiveComputerIndex].fwUpgradePossible);
|
ui.updateFirmwareButton->setEnabled(selectedDiveComputer.fwUpgradePossible);
|
||||||
ui.forceUpdateFirmware->setEnabled(supportedDiveComputers[selectedDiveComputerIndex].product == "OSTC 4");
|
ui.forceUpdateFirmware->setEnabled(supportedDiveComputers[selectedDiveComputerIndex].product == "OSTC 4");
|
||||||
|
|
||||||
ui.progressBar->setFormat(tr("Connected to device"));
|
ui.progressBar->setFormat(tr("Connected to device"));
|
||||||
|
|
Loading…
Add table
Reference in a new issue