mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Desktop: Use Persisted Device Information for Dive Computer Configuration.
Use the dive computer / device information that was persisted when previously downloading dives or configuring the dive computer in the dive computer configuration dialog. Also rename 'Connect with bluetooth' and 'Cancel' buttons in the dialog to make them more consistent with what they do. Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
parent
35d88fa6ce
commit
700bba7e30
4 changed files with 102 additions and 63 deletions
|
@ -1,3 +1,4 @@
|
|||
desktop: use persisted device information for the dive computer configuration
|
||||
export: fix bug resulting in invalid CSV for '""' in 'CSV summary dive details'
|
||||
desktop: add support for multiple tanks to the profile ruler
|
||||
export: change format produced by 'CSV summary dive details' from TSV (tab separated) to CSV
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
// For fill_computer_list, descriptorLookup
|
||||
#include "core/downloadfromdcthread.h"
|
||||
|
||||
#include <array>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkReply>
|
||||
|
@ -98,6 +99,32 @@ void GasTypeComboBoxItemDelegate::setModelData(QWidget *editor, QAbstractItemMod
|
|||
QStyledItemDelegate::setModelData(editor, model, index);
|
||||
}
|
||||
|
||||
class DiveComputerEntry
|
||||
{
|
||||
public:
|
||||
DiveComputerEntry(QString vendor, QString product, unsigned int transport, bool fwUpgradePossible) :
|
||||
vendorInt(vendor), productInt(product), transportInt(transport), fwUpgradePossibleInt(fwUpgradePossible) {}
|
||||
|
||||
QString vendor() const { return vendorInt; }
|
||||
QString product() const { return productInt; }
|
||||
|
||||
unsigned int transport() const { return transportInt; }
|
||||
bool fwUpgradePossible() const { return fwUpgradePossibleInt; }
|
||||
private:
|
||||
QString vendorInt;
|
||||
QString productInt;
|
||||
|
||||
unsigned int transportInt;
|
||||
bool fwUpgradePossibleInt;
|
||||
};
|
||||
|
||||
static std::array<DiveComputerEntry, 4> supportedDiveComputers = {
|
||||
DiveComputerEntry("Heinrichs Weikamp", "OSTC 2N", DC_TRANSPORT_SERIAL, true),
|
||||
DiveComputerEntry("Heinrichs Weikamp", "OSTC Plus", DC_TRANSPORT_BLUETOOTH, true),
|
||||
DiveComputerEntry("Heinrichs Weikamp", "OSTC 4", DC_TRANSPORT_BLUETOOTH, true),
|
||||
DiveComputerEntry("Suunto", "Vyper", DC_TRANSPORT_SERIAL, false),
|
||||
};
|
||||
|
||||
ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDialog(parent),
|
||||
config(0),
|
||||
#ifdef BT_SUPPORT
|
||||
|
@ -124,18 +151,37 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDia
|
|||
connect(ui.connectButton, &QPushButton::clicked, this, &ConfigureDiveComputerDialog::dc_open);
|
||||
connect(ui.disconnectButton, &QPushButton::clicked, this, &ConfigureDiveComputerDialog::dc_close);
|
||||
#ifdef BT_SUPPORT
|
||||
connect(ui.bluetoothMode, &QPushButton::clicked, this, &ConfigureDiveComputerDialog::selectRemoteBluetoothDevice);
|
||||
connect(ui.connectBluetoothButton, &QPushButton::clicked, this, &ConfigureDiveComputerDialog::selectRemoteBluetoothDevice);
|
||||
#else
|
||||
ui.bluetoothMode->setVisible(false);
|
||||
ui.connectBluetoothButton->setVisible(false);
|
||||
#endif
|
||||
|
||||
memset(&device_data, 0, sizeof(device_data));
|
||||
fill_computer_list();
|
||||
if (!qPrefDiveComputer::device().isEmpty())
|
||||
ui.device->setEditText(qPrefDiveComputer::device());
|
||||
|
||||
ui.DiveComputerList->setCurrentRow(0);
|
||||
on_DiveComputerList_currentRowChanged(0);
|
||||
unsigned int selectedDiveComputerIndex = 0;
|
||||
for (unsigned i = 0; i < supportedDiveComputers.size(); ++i) {
|
||||
if (supportedDiveComputers[i].vendor() == qPrefDiveComputer::vendor() &&
|
||||
supportedDiveComputers[i].product() == qPrefDiveComputer::product()) {
|
||||
selectedDiveComputerIndex = i;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ui.DiveComputerList->setCurrentRow(selectedDiveComputerIndex);
|
||||
on_DiveComputerList_currentRowChanged(selectedDiveComputerIndex);
|
||||
|
||||
QString deviceText = qPrefDiveComputer::device();
|
||||
if (!deviceText.isEmpty()) {
|
||||
#if defined(BT_SUPPORT)
|
||||
if (isBluetoothAddress(deviceText)) {
|
||||
deviceText = BtDeviceSelectionDialog::formatDeviceText(deviceText, qPrefDiveComputer::device_name());
|
||||
}
|
||||
#endif
|
||||
|
||||
ui.device->setEditText(deviceText);
|
||||
}
|
||||
|
||||
ui.ostc3GasTable->setItemDelegateForColumn(1, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT));
|
||||
ui.ostc3GasTable->setItemDelegateForColumn(2, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT));
|
||||
|
@ -399,10 +445,13 @@ static void fillDeviceList(const char *name, void *data)
|
|||
void ConfigureDiveComputerDialog::fill_device_list(unsigned int transport)
|
||||
{
|
||||
int deviceIndex;
|
||||
QString device = ui.device->currentText();
|
||||
ui.device->clear();
|
||||
deviceIndex = enumerate_devices(fillDeviceList, ui.device, transport);
|
||||
if (deviceIndex >= 0)
|
||||
ui.device->setCurrentIndex(deviceIndex);
|
||||
else
|
||||
ui.device->setCurrentText(device);
|
||||
}
|
||||
|
||||
void ConfigureDiveComputerDialog::populateDeviceDetails()
|
||||
|
@ -896,29 +945,32 @@ void ConfigureDiveComputerDialog::configError(QString err)
|
|||
|
||||
void ConfigureDiveComputerDialog::getDeviceData()
|
||||
{
|
||||
#ifdef BT_SUPPORT
|
||||
QString device = ui.bluetoothMode && btDeviceSelectionDialog ?
|
||||
btDeviceSelectionDialog->getSelectedDeviceAddress() :
|
||||
ui.device->currentText();
|
||||
#else
|
||||
QString device = ui.device->currentText();
|
||||
#ifdef BT_SUPPORT
|
||||
if (isBluetoothAddress(device)) {
|
||||
QString name;
|
||||
device = copy_qstring(extractBluetoothNameAddress(device, name));
|
||||
device_data.btname = copy_qstring(name);
|
||||
device_data.bluetooth_mode = true;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
device_data.bluetooth_mode = false;
|
||||
}
|
||||
device_data.devname = copy_qstring(device);
|
||||
device_data.vendor = copy_qstring(selected_vendor);
|
||||
device_data.product = copy_qstring(selected_product);
|
||||
|
||||
device_data.descriptor = descriptorLookup.value(selected_vendor.toLower() + selected_product.toLower());
|
||||
unsigned int selectedDiveComputerIndex = ui.DiveComputerList->currentRow();
|
||||
QString vendor = supportedDiveComputers[selectedDiveComputerIndex].vendor();
|
||||
QString product = supportedDiveComputers[selectedDiveComputerIndex].product();
|
||||
device_data.vendor = copy_qstring(vendor);
|
||||
device_data.product = copy_qstring(product);
|
||||
device_data.descriptor = descriptorLookup.value(vendor.toLower() + product.toLower());
|
||||
|
||||
device_data.diveid = 0;
|
||||
memset(&device_data.devinfo, 0, sizeof(device_data.devinfo));
|
||||
|
||||
qPrefDiveComputer::set_device(device_data.devname);
|
||||
#ifdef BT_SUPPORT
|
||||
if (ui.bluetoothMode && btDeviceSelectionDialog)
|
||||
qPrefDiveComputer::set_device_name(btDeviceSelectionDialog->getSelectedDeviceName());
|
||||
#endif
|
||||
}
|
||||
|
||||
void ConfigureDiveComputerDialog::on_cancel_clicked()
|
||||
void ConfigureDiveComputerDialog::on_close_clicked()
|
||||
{
|
||||
this->close();
|
||||
}
|
||||
|
@ -1421,31 +1473,14 @@ void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked()
|
|||
|
||||
void ConfigureDiveComputerDialog::on_DiveComputerList_currentRowChanged(int currentRow)
|
||||
{
|
||||
switch (currentRow) {
|
||||
case 0:
|
||||
selected_vendor = "Heinrichs Weikamp";
|
||||
selected_product = "OSTC 2N";
|
||||
fw_upgrade_possible = true;
|
||||
break;
|
||||
case 1:
|
||||
selected_vendor = "Heinrichs Weikamp";
|
||||
selected_product = "OSTC Plus";
|
||||
fw_upgrade_possible = true;
|
||||
break;
|
||||
case 2:
|
||||
selected_vendor = "Heinrichs Weikamp";
|
||||
selected_product = "OSTC 4";
|
||||
fw_upgrade_possible = true;
|
||||
break;
|
||||
case 3:
|
||||
selected_vendor = "Suunto";
|
||||
selected_product = "Vyper";
|
||||
fw_upgrade_possible = false;
|
||||
default:
|
||||
/* Not Supported */
|
||||
return;
|
||||
}
|
||||
fill_device_list(DC_TRANSPORT_SERIAL);
|
||||
unsigned int transport = supportedDiveComputers[currentRow].transport();
|
||||
|
||||
if (transport != DC_TRANSPORT_BLUETOOTH)
|
||||
ui.connectBluetoothButton->setEnabled(false);
|
||||
else
|
||||
ui.connectBluetoothButton->setEnabled(true);
|
||||
|
||||
fill_device_list(transport);
|
||||
}
|
||||
|
||||
void ConfigureDiveComputerDialog::checkLogFile(int state)
|
||||
|
@ -1485,10 +1520,9 @@ void ConfigureDiveComputerDialog::selectRemoteBluetoothDevice()
|
|||
void ConfigureDiveComputerDialog::bluetoothSelectionDialogIsFinished(int result)
|
||||
{
|
||||
if (result == QDialog::Accepted) {
|
||||
ui.device->setCurrentText(btDeviceSelectionDialog->getSelectedDeviceText());
|
||||
device_data.bluetooth_mode = true;
|
||||
|
||||
ui.device->setEditText(btDeviceSelectionDialog->getSelectedDeviceText());
|
||||
ui.progressBar->setFormat(tr("Connecting to device..."));
|
||||
|
||||
dc_open();
|
||||
}
|
||||
}
|
||||
|
@ -1509,12 +1543,20 @@ void ConfigureDiveComputerDialog::dc_open()
|
|||
ui.disconnectButton->setEnabled(true);
|
||||
ui.restoreBackupButton->setEnabled(true);
|
||||
ui.connectButton->setEnabled(false);
|
||||
ui.bluetoothMode->setEnabled(false);
|
||||
ui.connectBluetoothButton->setEnabled(false);
|
||||
ui.DiveComputerList->setEnabled(false);
|
||||
ui.logToFile->setEnabled(false);
|
||||
ui.updateFirmwareButton->setEnabled(fw_upgrade_possible);
|
||||
ui.forceUpdateFirmware->setEnabled(selected_product == "OSTC 4");
|
||||
|
||||
unsigned int selectedDiveComputerIndex = ui.DiveComputerList->currentRow();
|
||||
ui.updateFirmwareButton->setEnabled(supportedDiveComputers[selectedDiveComputerIndex].fwUpgradePossible());
|
||||
ui.forceUpdateFirmware->setEnabled(supportedDiveComputers[selectedDiveComputerIndex].product() == "OSTC 4");
|
||||
|
||||
ui.progressBar->setFormat(tr("Connected to device"));
|
||||
|
||||
qPrefDiveComputer::set_device(device_data.devname);
|
||||
qPrefDiveComputer::set_device_name(device_data.btname);
|
||||
qPrefDiveComputer::set_vendor(device_data.vendor);
|
||||
qPrefDiveComputer::set_product(device_data.product);
|
||||
}
|
||||
|
||||
void ConfigureDiveComputerDialog::dc_close()
|
||||
|
@ -1526,7 +1568,7 @@ void ConfigureDiveComputerDialog::dc_close()
|
|||
ui.resetButton_4->setEnabled(false);
|
||||
ui.disconnectButton->setEnabled(false);
|
||||
ui.connectButton->setEnabled(true);
|
||||
ui.bluetoothMode->setEnabled(true);
|
||||
ui.connectBluetoothButton->setEnabled(true);
|
||||
ui.backupButton->setEnabled(false);
|
||||
ui.saveSettingsPushButton->setEnabled(false);
|
||||
ui.restoreBackupButton->setEnabled(false);
|
||||
|
|
|
@ -72,7 +72,7 @@ slots:
|
|||
void resetSettings();
|
||||
void configMessage(QString msg);
|
||||
void configError(QString err);
|
||||
void on_cancel_clicked();
|
||||
void on_close_clicked();
|
||||
void on_saveSettingsPushButton_clicked();
|
||||
void deviceDetailsReceived(DeviceDetails *newDeviceDetails);
|
||||
void reloadValues();
|
||||
|
@ -115,10 +115,6 @@ private:
|
|||
void reloadValuesSuuntoVyper();
|
||||
void reloadValuesOSTC4();
|
||||
|
||||
QString selected_vendor;
|
||||
QString selected_product;
|
||||
bool fw_upgrade_possible;
|
||||
|
||||
#ifdef BT_SUPPORT
|
||||
BtDeviceSelectionDialog *btDeviceSelectionDialog;
|
||||
#endif
|
||||
|
|
|
@ -42,9 +42,9 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="bluetoothMode">
|
||||
<widget class="QPushButton" name="connectBluetoothButton">
|
||||
<property name="text">
|
||||
<string>Connect via Bluetooth</string>
|
||||
<string>Select Bluetooth Device</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -182,9 +182,9 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancel">
|
||||
<widget class="QPushButton" name="close">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -3972,7 +3972,7 @@
|
|||
<tabstop>saveSettingsPushButton</tabstop>
|
||||
<tabstop>backupButton</tabstop>
|
||||
<tabstop>restoreBackupButton</tabstop>
|
||||
<tabstop>cancel</tabstop>
|
||||
<tabstop>close</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../subsurface.qrc"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue