2014-05-29 15:54:19 +00:00
|
|
|
#include "configuredivecomputerdialog.h"
|
|
|
|
#include "ui_configuredivecomputerdialog.h"
|
|
|
|
|
2014-05-29 16:16:34 +00:00
|
|
|
#include "../divecomputer.h"
|
|
|
|
#include "../libdivecomputer.h"
|
|
|
|
#include "../helpers.h"
|
|
|
|
#include "../display.h"
|
|
|
|
#include "../divelist.h"
|
2014-05-30 06:56:27 +00:00
|
|
|
#include "configuredivecomputer.h"
|
2014-06-10 16:19:28 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
2014-05-29 16:16:34 +00:00
|
|
|
struct product {
|
|
|
|
const char *product;
|
|
|
|
dc_descriptor_t *descriptor;
|
|
|
|
struct product *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vendor {
|
|
|
|
const char *vendor;
|
|
|
|
struct product *productlist;
|
|
|
|
struct vendor *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mydescriptor {
|
|
|
|
const char *vendor;
|
|
|
|
const char *product;
|
|
|
|
dc_family_t type;
|
|
|
|
unsigned int model;
|
|
|
|
};
|
|
|
|
|
2014-05-29 15:54:19 +00:00
|
|
|
ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
2014-05-29 16:16:34 +00:00
|
|
|
ui(new Ui::ConfigureDiveComputerDialog),
|
2014-05-30 06:56:27 +00:00
|
|
|
config(0),
|
2014-05-29 16:16:34 +00:00
|
|
|
vendorModel(0),
|
2014-06-10 12:03:26 +00:00
|
|
|
productModel(0),
|
|
|
|
deviceDetails(0)
|
2014-05-29 15:54:19 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-05-29 16:16:34 +00:00
|
|
|
|
2014-06-10 12:03:26 +00:00
|
|
|
deviceDetails = new DeviceDetails(this);
|
2014-05-30 06:56:27 +00:00
|
|
|
config = new ConfigureDiveComputer(this);
|
|
|
|
connect (config, SIGNAL(error(QString)), this, SLOT(configError(QString)));
|
|
|
|
connect (config, SIGNAL(message(QString)), this, SLOT(configMessage(QString)));
|
2014-06-10 12:03:26 +00:00
|
|
|
connect (config, SIGNAL(readFinished()), this, SLOT(deviceReadFinished()));
|
2014-06-10 15:25:25 +00:00
|
|
|
connect (config, SIGNAL(deviceDetailsChanged(DeviceDetails*)),
|
|
|
|
this, SLOT(deviceDetailsReceived(DeviceDetails*)));
|
2014-05-30 06:56:27 +00:00
|
|
|
|
2014-05-29 16:16:34 +00:00
|
|
|
fill_computer_list();
|
|
|
|
|
|
|
|
vendorModel = new QStringListModel(vendorList);
|
|
|
|
ui->vendor->setModel(vendorModel);
|
|
|
|
if (default_dive_computer_vendor) {
|
|
|
|
ui->vendor->setCurrentIndex(ui->vendor->findText(default_dive_computer_vendor));
|
|
|
|
productModel = new QStringListModel(productList[default_dive_computer_vendor]);
|
|
|
|
ui->product->setModel(productModel);
|
|
|
|
if (default_dive_computer_product)
|
|
|
|
ui->product->setCurrentIndex(ui->product->findText(default_dive_computer_product));
|
|
|
|
}
|
|
|
|
if (default_dive_computer_device)
|
|
|
|
ui->device->setEditText(default_dive_computer_device);
|
2014-05-30 06:56:27 +00:00
|
|
|
|
|
|
|
memset(&device_data, 0, sizeof(device_data));
|
|
|
|
|
|
|
|
connect (ui->retrieveDetails, SIGNAL(clicked()), this, SLOT(readSettings()));
|
2014-05-29 15:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigureDiveComputerDialog::~ConfigureDiveComputerDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2014-05-29 16:16:34 +00:00
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::fill_computer_list()
|
|
|
|
{
|
|
|
|
dc_iterator_t *iterator = NULL;
|
|
|
|
dc_descriptor_t *descriptor = NULL;
|
|
|
|
|
|
|
|
struct mydescriptor *mydescriptor;
|
|
|
|
|
|
|
|
QStringList computer;
|
|
|
|
dc_descriptor_iterator(&iterator);
|
|
|
|
while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) {
|
|
|
|
const char *vendor = dc_descriptor_get_vendor(descriptor);
|
|
|
|
const char *product = dc_descriptor_get_product(descriptor);
|
|
|
|
|
|
|
|
if (!vendorList.contains(vendor))
|
|
|
|
vendorList.append(vendor);
|
|
|
|
|
|
|
|
if (!productList[vendor].contains(product))
|
|
|
|
productList[vendor].push_back(product);
|
|
|
|
|
|
|
|
descriptorLookup[QString(vendor) + QString(product)] = descriptor;
|
|
|
|
}
|
|
|
|
dc_iterator_free(iterator);
|
|
|
|
|
|
|
|
mydescriptor = (struct mydescriptor *)malloc(sizeof(struct mydescriptor));
|
|
|
|
mydescriptor->vendor = "Uemis";
|
|
|
|
mydescriptor->product = "Zurich";
|
|
|
|
mydescriptor->type = DC_FAMILY_NULL;
|
|
|
|
mydescriptor->model = 0;
|
|
|
|
|
|
|
|
if (!vendorList.contains("Uemis"))
|
|
|
|
vendorList.append("Uemis");
|
|
|
|
|
|
|
|
if (!productList["Uemis"].contains("Zurich"))
|
|
|
|
productList["Uemis"].push_back("Zurich");
|
|
|
|
|
|
|
|
descriptorLookup["UemisZurich"] = (dc_descriptor_t *)mydescriptor;
|
|
|
|
|
|
|
|
qSort(vendorList);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fillDeviceList(const char *name, void *data)
|
|
|
|
{
|
|
|
|
QComboBox *comboBox = (QComboBox *)data;
|
|
|
|
comboBox->addItem(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::fill_device_list(int dc_type)
|
|
|
|
{
|
|
|
|
int deviceIndex;
|
|
|
|
ui->device->clear();
|
|
|
|
deviceIndex = enumerate_devices(fillDeviceList, ui->device, dc_type);
|
|
|
|
if (deviceIndex >= 0)
|
|
|
|
ui->device->setCurrentIndex(deviceIndex);
|
|
|
|
}
|
|
|
|
|
2014-06-10 16:19:28 +00:00
|
|
|
void ConfigureDiveComputerDialog::populateDeviceDetails()
|
|
|
|
{
|
2014-06-11 08:09:01 +00:00
|
|
|
deviceDetails->setCustomText(ui->customTextLlineEdit->text());
|
|
|
|
deviceDetails->setLastDeco(ui->lastDecoSpinBox->value());
|
2014-06-10 16:19:28 +00:00
|
|
|
deviceDetails->setBrightness(ui->brightnessComboBox->currentIndex());
|
2014-06-11 08:09:01 +00:00
|
|
|
deviceDetails->setUnits(ui->unitsComboBox->currentIndex());
|
|
|
|
deviceDetails->setSamplingRate(ui->samplingRateComboBox->currentIndex());
|
|
|
|
deviceDetails->setSalinity(ui->salinitySpinBox->value());
|
|
|
|
deviceDetails->setDiveModeColor(ui->diveModeColour->currentIndex());
|
2014-06-10 16:19:28 +00:00
|
|
|
deviceDetails->setLanguage(ui->languageComboBox->currentIndex());
|
|
|
|
deviceDetails->setDateFormat(ui->dateFormatComboBox->currentIndex());
|
2014-06-11 08:09:01 +00:00
|
|
|
deviceDetails->setCompassGain(ui->compassGainComboBox->currentIndex());
|
2014-06-10 16:19:28 +00:00
|
|
|
deviceDetails->setSyncTime(ui->dateTimeSyncCheckBox->isChecked());
|
|
|
|
}
|
|
|
|
|
2014-05-29 16:16:34 +00:00
|
|
|
void ConfigureDiveComputerDialog::on_vendor_currentIndexChanged(const QString &vendor)
|
|
|
|
{
|
|
|
|
int dcType = DC_TYPE_SERIAL;
|
|
|
|
QAbstractItemModel *currentModel = ui->product->model();
|
|
|
|
if (!currentModel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
productModel = new QStringListModel(productList[vendor]);
|
|
|
|
ui->product->setModel(productModel);
|
|
|
|
|
|
|
|
if (vendor == QString("Uemis"))
|
|
|
|
dcType = DC_TYPE_UEMIS;
|
|
|
|
fill_device_list(dcType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::on_product_currentIndexChanged(const QString &product)
|
|
|
|
{
|
|
|
|
dc_descriptor_t *descriptor = NULL;
|
|
|
|
descriptor = descriptorLookup[ui->vendor->currentText() + product];
|
|
|
|
|
|
|
|
// call dc_descriptor_get_transport to see if the dc_transport_t is DC_TRANSPORT_SERIAL
|
|
|
|
if (dc_descriptor_get_transport(descriptor) == DC_TRANSPORT_SERIAL) {
|
|
|
|
// if the dc_transport_t is DC_TRANSPORT_SERIAL, then enable the device node box.
|
|
|
|
ui->device->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
// otherwise disable the device node box
|
|
|
|
ui->device->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 06:56:27 +00:00
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::readSettings()
|
|
|
|
{
|
|
|
|
ui->statusLabel->clear();
|
|
|
|
ui->errorLabel->clear();
|
|
|
|
|
|
|
|
getDeviceData();
|
2014-06-10 15:25:25 +00:00
|
|
|
config->readSettings(&device_data);
|
2014-05-30 06:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::configMessage(QString msg)
|
|
|
|
{
|
|
|
|
ui->statusLabel->setText(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::configError(QString err)
|
|
|
|
{
|
|
|
|
ui->errorLabel->setText(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::getDeviceData()
|
|
|
|
{
|
|
|
|
device_data.devname = strdup(ui->device->currentText().toUtf8().data());
|
|
|
|
device_data.vendor = strdup(ui->vendor->currentText().toUtf8().data());
|
|
|
|
device_data.product = strdup(ui->product->currentText().toUtf8().data());
|
|
|
|
|
|
|
|
device_data.descriptor = descriptorLookup[ui->vendor->currentText() + ui->product->currentText()];
|
|
|
|
device_data.deviceid = device_data.diveid = 0;
|
|
|
|
|
|
|
|
set_default_dive_computer(device_data.vendor, device_data.product);
|
|
|
|
set_default_dive_computer_device(device_data.devname);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::on_cancel_clicked()
|
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
2014-05-30 07:49:58 +00:00
|
|
|
|
2014-06-10 12:03:26 +00:00
|
|
|
void ConfigureDiveComputerDialog::deviceReadFinished()
|
2014-05-30 07:49:58 +00:00
|
|
|
{
|
2014-06-10 15:25:25 +00:00
|
|
|
|
2014-05-30 07:49:58 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 12:03:26 +00:00
|
|
|
void ConfigureDiveComputerDialog::on_saveSettingsPushButton_clicked()
|
2014-05-30 07:49:58 +00:00
|
|
|
{
|
2014-06-10 16:19:28 +00:00
|
|
|
populateDeviceDetails();
|
2014-06-10 15:25:25 +00:00
|
|
|
getDeviceData();
|
|
|
|
config->saveDeviceDetails(deviceDetails, &device_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::deviceDetailsReceived(DeviceDetails *newDeviceDetails)
|
|
|
|
{
|
|
|
|
deviceDetails = newDeviceDetails;
|
|
|
|
reloadValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::reloadValues()
|
|
|
|
{
|
|
|
|
ui->serialNoLineEdit->setText(deviceDetails->serialNo());
|
|
|
|
ui->firmwareVersionLineEdit->setText(deviceDetails->firmwareVersion());
|
|
|
|
ui->customTextLlineEdit->setText(deviceDetails->customText());
|
2014-06-11 08:09:01 +00:00
|
|
|
ui->lastDecoSpinBox->setValue(deviceDetails->lastDeco());
|
2014-06-10 15:25:25 +00:00
|
|
|
ui->brightnessComboBox->setCurrentIndex(deviceDetails->brightness());
|
2014-06-11 08:09:01 +00:00
|
|
|
ui->unitsComboBox->setCurrentIndex(deviceDetails->units());
|
|
|
|
ui->samplingRateComboBox->setCurrentIndex(deviceDetails->samplingRate());
|
|
|
|
ui->salinitySpinBox->setValue(deviceDetails->salinity());
|
|
|
|
ui->diveModeColour->setCurrentIndex(deviceDetails->diveModeColor());
|
2014-06-10 15:25:25 +00:00
|
|
|
ui->languageComboBox->setCurrentIndex(deviceDetails->language());
|
|
|
|
ui->dateFormatComboBox->setCurrentIndex(deviceDetails->dateFormat());
|
2014-06-11 08:09:01 +00:00
|
|
|
ui->compassGainComboBox->setCurrentIndex(deviceDetails->compassGain());
|
2014-05-30 07:49:58 +00:00
|
|
|
}
|
2014-06-07 18:56:44 +00:00
|
|
|
|
2014-06-10 16:19:28 +00:00
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::on_backupButton_clicked()
|
|
|
|
{
|
|
|
|
QString filename = existing_filename ?: prefs.default_filename;
|
|
|
|
QFileInfo fi(filename);
|
|
|
|
filename = fi.absolutePath().append(QDir::separator()).append("Backup.xml");
|
|
|
|
QString backupPath = QFileDialog::getSaveFileName(this, tr("Backup Dive Computer Settings"),
|
|
|
|
filename, tr("Backup files (*.xml)")
|
|
|
|
);
|
|
|
|
if (!backupPath.isEmpty()) {
|
|
|
|
populateDeviceDetails();
|
|
|
|
getDeviceData();
|
|
|
|
QString errorText = "";
|
|
|
|
if (!config->saveXMLBackup(backupPath, deviceDetails, &device_data, errorText)) {
|
|
|
|
QMessageBox::critical(this, tr("XML Backup Error"),
|
2014-06-11 06:37:27 +00:00
|
|
|
tr("An error occurred while saving the backup file.\n%1")
|
2014-06-10 16:19:28 +00:00
|
|
|
.arg(errorText)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
QMessageBox::information(this, tr("Backup succeeded"),
|
|
|
|
tr("Your settings have been saved to: %1")
|
|
|
|
.arg(filename)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-11 06:37:27 +00:00
|
|
|
|
|
|
|
void ConfigureDiveComputerDialog::on_restoreBackupButton_clicked()
|
|
|
|
{
|
|
|
|
QString filename = existing_filename ?: prefs.default_filename;
|
|
|
|
QFileInfo fi(filename);
|
|
|
|
filename = fi.absolutePath().append(QDir::separator()).append("Backup.xml");
|
|
|
|
QString restorePath = QFileDialog::getOpenFileName(this, tr("Restore Dive Computer Settings"),
|
|
|
|
filename, tr("Backup files (*.xml)")
|
|
|
|
);
|
|
|
|
if (!restorePath.isEmpty()) {
|
|
|
|
QString errorText = "";
|
|
|
|
if (!config->restoreXMLBackup(restorePath, deviceDetails, errorText)) {
|
|
|
|
QMessageBox::critical(this, tr("XML Restore Error"),
|
|
|
|
tr("An error occurred while restoring the backup file.\n%1")
|
|
|
|
.arg(errorText)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
reloadValues();
|
|
|
|
//getDeviceData();
|
|
|
|
//config->saveDeviceDetails(deviceDetails, &device_data);
|
|
|
|
QMessageBox::information(this, tr("Restore succeeded"),
|
|
|
|
tr("Your settings have been restored successfully.")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|