source: subsurface/desktop-widgets/configuredivecomputerdialog.cpp @ 4cbf64b

Last change on this file since 4cbf64b was 4cbf64b, checked in by Dirk Hohndel <dirk@…>, 8 months ago

Wire up a skeleton for configure OSTC 4

Signed-off-by: Anton Lundin <glance@…>

  • Property mode set to 100644
File size: 56.3 KB
Line 
1// SPDX-License-Identifier: GPL-2.0
2#include "desktop-widgets/configuredivecomputerdialog.h"
3
4#include "core/helpers.h"
5#include "desktop-widgets/mainwindow.h"
6#include "core/display.h"
7#include "core/subsurface-qt/SettingsObjectWrapper.h"
8
9#include <QFileDialog>
10#include <QMessageBox>
11#include <QSettings>
12#include <QNetworkReply>
13#include <QProgressDialog>
14
15struct product {
16        const char *product;
17        dc_descriptor_t *descriptor;
18        struct product *next;
19};
20
21struct vendor {
22        const char *vendor;
23        struct product *productlist;
24        struct vendor *next;
25};
26
27struct mydescriptor {
28        const char *vendor;
29        const char *product;
30        dc_family_t type;
31        unsigned int model;
32};
33
34GasSpinBoxItemDelegate::GasSpinBoxItemDelegate(QObject *parent, column_type type) : QStyledItemDelegate(parent), type(type)
35{
36}
37GasSpinBoxItemDelegate::~GasSpinBoxItemDelegate()
38{
39}
40
41QWidget *GasSpinBoxItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
42{
43        Q_UNUSED(option)
44        Q_UNUSED(index)
45        // Create the spinbox and give it it's settings
46        QSpinBox *sb = new QSpinBox(parent);
47        if (type == PERCENT) {
48                sb->setMinimum(0);
49                sb->setMaximum(100);
50                sb->setSuffix("%");
51        } else if (type == DEPTH) {
52                sb->setMinimum(0);
53                sb->setMaximum(255);
54                sb->setSuffix(" m");
55        } else if (type == SETPOINT) {
56                sb->setMinimum(0);
57                sb->setMaximum(255);
58                sb->setSuffix(" cbar");
59        }
60        return sb;
61}
62
63void GasSpinBoxItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
64{
65        if (QSpinBox *sb = qobject_cast<QSpinBox *>(editor))
66                sb->setValue(index.data(Qt::EditRole).toInt());
67        else
68                QStyledItemDelegate::setEditorData(editor, index);
69}
70
71
72void GasSpinBoxItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
73{
74        if (QSpinBox *sb = qobject_cast<QSpinBox *>(editor))
75                model->setData(index, sb->value(), Qt::EditRole);
76        else
77                QStyledItemDelegate::setModelData(editor, model, index);
78}
79
80GasTypeComboBoxItemDelegate::GasTypeComboBoxItemDelegate(QObject *parent, computer_type type) : QStyledItemDelegate(parent), type(type)
81{
82}
83GasTypeComboBoxItemDelegate::~GasTypeComboBoxItemDelegate()
84{
85}
86
87QWidget *GasTypeComboBoxItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
88{
89        Q_UNUSED(option)
90        Q_UNUSED(index)
91        // Create the combobox and populate it
92        QComboBox *cb = new QComboBox(parent);
93        cb->addItem(QString("Disabled"));
94        if (type == OSTC3) {
95                cb->addItem(QString("First"));
96                cb->addItem(QString("Travel"));
97                cb->addItem(QString("Deco"));
98        } else if (type == OSTC) {
99                cb->addItem(QString("Active"));
100                cb->addItem(QString("First"));
101        }
102        return cb;
103}
104
105void GasTypeComboBoxItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
106{
107        if (QComboBox *cb = qobject_cast<QComboBox *>(editor))
108                cb->setCurrentIndex(index.data(Qt::EditRole).toInt());
109        else
110                QStyledItemDelegate::setEditorData(editor, index);
111}
112
113
114void GasTypeComboBoxItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
115{
116        if (QComboBox *cb = qobject_cast<QComboBox *>(editor))
117                model->setData(index, cb->currentIndex(), Qt::EditRole);
118        else
119                QStyledItemDelegate::setModelData(editor, model, index);
120}
121
122ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDialog(parent),
123        config(0),
124#ifdef BT_SUPPORT
125        deviceDetails(0),
126        btDeviceSelectionDialog(0)
127#else
128        deviceDetails(0)
129#endif
130{
131        ui.setupUi(this);
132
133        deviceDetails = new DeviceDetails(this);
134        config = new ConfigureDiveComputer();
135        connect(config, SIGNAL(progress(int)), ui.progressBar, SLOT(setValue(int)));
136        connect(config, SIGNAL(error(QString)), this, SLOT(configError(QString)));
137        connect(config, SIGNAL(message(QString)), this, SLOT(configMessage(QString)));
138        connect(config, SIGNAL(deviceDetailsChanged(DeviceDetails *)),
139                this, SLOT(deviceDetailsReceived(DeviceDetails *)));
140        connect(ui.retrieveDetails, SIGNAL(clicked()), this, SLOT(readSettings()));
141        connect(ui.resetButton, SIGNAL(clicked()), this, SLOT(resetSettings()));
142        ui.chooseLogFile->setEnabled(ui.logToFile->isChecked());
143        connect(ui.chooseLogFile, SIGNAL(clicked()), this, SLOT(pickLogFile()));
144        connect(ui.logToFile, SIGNAL(stateChanged(int)), this, SLOT(checkLogFile(int)));
145        connect(ui.connectButton, SIGNAL(clicked()), this, SLOT(dc_open()));
146        connect(ui.disconnectButton, SIGNAL(clicked()), this, SLOT(dc_close()));
147#ifdef BT_SUPPORT
148        connect(ui.bluetoothMode, SIGNAL(clicked(bool)), this, SLOT(selectRemoteBluetoothDevice()));
149#else
150        ui.bluetoothMode->setVisible(false);
151#endif
152
153        memset(&device_data, 0, sizeof(device_data));
154        fill_computer_list();
155        auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
156        if (!dc->dc_device().isEmpty())
157                ui.device->setEditText(dc->dc_device());
158
159        ui.DiveComputerList->setCurrentRow(0);
160        on_DiveComputerList_currentRowChanged(0);
161
162        ui.ostc3GasTable->setItemDelegateForColumn(1, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT));
163        ui.ostc3GasTable->setItemDelegateForColumn(2, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT));
164        ui.ostc3GasTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC3));
165        ui.ostc3GasTable->setItemDelegateForColumn(4, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH));
166        ui.ostc3DilTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC3));
167        ui.ostc3DilTable->setItemDelegateForColumn(4, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH));
168        ui.ostc3SetPointTable->setItemDelegateForColumn(1, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::SETPOINT));
169        ui.ostc3SetPointTable->setItemDelegateForColumn(2, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH));
170        ui.ostcGasTable->setItemDelegateForColumn(1, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT));
171        ui.ostcGasTable->setItemDelegateForColumn(2, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT));
172        ui.ostcGasTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC));
173        ui.ostcGasTable->setItemDelegateForColumn(4, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH));
174        ui.ostcDilTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC));
175        ui.ostcDilTable->setItemDelegateForColumn(4, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH));
176        ui.ostcSetPointTable->setItemDelegateForColumn(1, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::SETPOINT));
177        ui.ostcSetPointTable->setItemDelegateForColumn(2, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH));
178        ui.ostc4GasTable->setItemDelegateForColumn(1, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT));
179        ui.ostc4GasTable->setItemDelegateForColumn(2, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT));
180        ui.ostc4GasTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC3));
181        ui.ostc4GasTable->setItemDelegateForColumn(4, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH));
182        ui.ostc4DilTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC3));
183        ui.ostc4DilTable->setItemDelegateForColumn(4, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH));
184        ui.ostc4SetPointTable->setItemDelegateForColumn(1, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::SETPOINT));
185        ui.ostc4SetPointTable->setItemDelegateForColumn(2, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH));
186
187        QSettings settings;
188        settings.beginGroup("ConfigureDiveComputerDialog");
189        settings.beginGroup("ostc3GasTable");
190        for (int i = 0; i < ui.ostc3GasTable->columnCount(); i++) {
191                QVariant width = settings.value(QString("colwidth%1").arg(i));
192                if (width.isValid())
193                        ui.ostc3GasTable->setColumnWidth(i, width.toInt());
194        }
195        settings.endGroup();
196        settings.beginGroup("ostc3DilTable");
197        for (int i = 0; i < ui.ostc3DilTable->columnCount(); i++) {
198                QVariant width = settings.value(QString("colwidth%1").arg(i));
199                if (width.isValid())
200                        ui.ostc3DilTable->setColumnWidth(i, width.toInt());
201        }
202        settings.endGroup();
203        settings.beginGroup("ostc3SetPointTable");
204        for (int i = 0; i < ui.ostc3SetPointTable->columnCount(); i++) {
205                QVariant width = settings.value(QString("colwidth%1").arg(i));
206                if (width.isValid())
207                        ui.ostc3SetPointTable->setColumnWidth(i, width.toInt());
208        }
209        settings.endGroup();
210
211        settings.beginGroup("ostcGasTable");
212        for (int i = 0; i < ui.ostcGasTable->columnCount(); i++) {
213                QVariant width = settings.value(QString("colwidth%1").arg(i));
214                if (width.isValid())
215                        ui.ostcGasTable->setColumnWidth(i, width.toInt());
216        }
217        settings.endGroup();
218        settings.beginGroup("ostcDilTable");
219        for (int i = 0; i < ui.ostcDilTable->columnCount(); i++) {
220                QVariant width = settings.value(QString("colwidth%1").arg(i));
221                if (width.isValid())
222                        ui.ostcDilTable->setColumnWidth(i, width.toInt());
223        }
224        settings.endGroup();
225        settings.beginGroup("ostcSetPointTable");
226        for (int i = 0; i < ui.ostcSetPointTable->columnCount(); i++) {
227                QVariant width = settings.value(QString("colwidth%1").arg(i));
228                if (width.isValid())
229                        ui.ostcSetPointTable->setColumnWidth(i, width.toInt());
230        }
231        settings.endGroup();
232        settings.beginGroup("ostc4GasTable");
233        for (int i = 0; i < ui.ostc4GasTable->columnCount(); i++) {
234                QVariant width = settings.value(QString("colwidth%1").arg(i));
235                if (width.isValid())
236                        ui.ostc4GasTable->setColumnWidth(i, width.toInt());
237        }
238        settings.endGroup();
239        settings.beginGroup("ostc4DilTable");
240        for (int i = 0; i < ui.ostc4DilTable->columnCount(); i++) {
241                QVariant width = settings.value(QString("colwidth%1").arg(i));
242                if (width.isValid())
243                        ui.ostc4DilTable->setColumnWidth(i, width.toInt());
244        }
245        settings.endGroup();
246        settings.beginGroup("ostc4SetPointTable");
247        for (int i = 0; i < ui.ostc4SetPointTable->columnCount(); i++) {
248                QVariant width = settings.value(QString("colwidth%1").arg(i));
249                if (width.isValid())
250                        ui.ostc4SetPointTable->setColumnWidth(i, width.toInt());
251        }
252        settings.endGroup();
253        settings.endGroup();
254}
255
256OstcFirmwareCheck::OstcFirmwareCheck(QString product) : parent(0)
257{
258        QUrl url;
259        memset(&devData, 1, sizeof(devData));
260        if (product == "OSTC 3" || product == "OSTC 3+" || product == "OSTC Cr") {
261                url = QUrl("http://www.heinrichsweikamp.net/autofirmware/ostc3_changelog.txt");
262                latestFirmwareHexFile = QString("http://www.heinrichsweikamp.net/autofirmware/ostc3_firmware.hex");
263        } else if (product == "OSTC Sport") {
264                url = QUrl("http://www.heinrichsweikamp.net/autofirmware/ostc_sport_changelog.txt");
265                latestFirmwareHexFile = QString("http://www.heinrichsweikamp.net/autofirmware/ostc_sport_firmware.hex");
266        } else if (product == "OSTC 4") {
267                url = QUrl("http://www.heinrichsweikamp.net/autofirmware/ostc4_changelog.txt");
268                latestFirmwareHexFile = QString("http://www.heinrichsweikamp.net/autofirmware/ostc4_firmware.bin");
269        } else { // not one of the known dive computers
270                return;
271        }
272        connect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(parseOstcFwVersion(QNetworkReply *)));
273        QNetworkRequest download(url);
274        manager.get(download);
275}
276
277void OstcFirmwareCheck::parseOstcFwVersion(QNetworkReply *reply)
278{
279        QString parse = reply->readAll();
280        int firstOpenBracket = parse.indexOf('[');
281        int firstCloseBracket = parse.indexOf(']');
282        latestFirmwareAvailable = parse.mid(firstOpenBracket + 1, firstCloseBracket - firstOpenBracket - 1);
283        disconnect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(parseOstcFwVersion(QNetworkReply *)));
284}
285
286void OstcFirmwareCheck::checkLatest(QWidget *_parent, device_data_t *data)
287{
288        devData = *data;
289        parent = _parent;
290        // If we didn't find a current firmware version stop this hole thing here.
291        if (latestFirmwareAvailable.isEmpty())
292                return;
293
294        // libdivecomputer gives us the firmware on device as an integer
295        // for the OSTC that means highbyte.lowbyte is the version number
296        // For OSTC 4's its stored as XXXX XYYY YYZZ ZZZB, -> X.Y.Z beta?
297
298        int firmwareOnDevice = devData.libdc_firmware;
299        QString firmwareOnDeviceString;
300        // Convert the latestFirmwareAvailable to a integear we can compare with
301        QStringList fwParts = latestFirmwareAvailable.split(".");
302        int latestFirmwareAvailableNumber;
303
304        if (strcmp(data->product, "OSTC 4") == 0) {
305                unsigned char X, Y, Z, beta;
306                X = (firmwareOnDevice & 0xF800) >> 11;
307                Y = (firmwareOnDevice & 0x07C0) >> 6;
308                Z = (firmwareOnDevice & 0x003E) >> 1;
309                beta = firmwareOnDevice & 0x0001;
310                firmwareOnDeviceString = QString("%1.%2.%3%4").arg(X).arg(Y).arg(Z).arg(beta?" beta":"");
311                latestFirmwareAvailableNumber = (fwParts[0].toInt() << 11) + (fwParts[1].toInt() << 6) + (fwParts[2].toInt() << 1);
312        } else { // OSTC 3, Sport, Cr
313                firmwareOnDeviceString = QString("%1.%2").arg(firmwareOnDevice / 256).arg(firmwareOnDevice % 256);
314                latestFirmwareAvailableNumber = fwParts[0].toInt() * 256 + fwParts[1].toInt();
315        }
316
317        if (latestFirmwareAvailableNumber > firmwareOnDevice) {
318                QMessageBox response(parent);
319                QString message = tr("You should update the firmware on your dive computer: you have version %1 but the latest stable version is %2")
320                                          .arg(firmwareOnDeviceString)
321                                          .arg(latestFirmwareAvailable);
322                message += tr("\n\nIf your device uses Bluetooth, do the same preparations as for a logbook download before continuing with the update");
323                response.addButton(tr("Not now"), QMessageBox::RejectRole);
324                response.addButton(tr("Update firmware"), QMessageBox::AcceptRole);
325                response.setText(message);
326                response.setWindowTitle(tr("Firmware upgrade notice"));
327                response.setIcon(QMessageBox::Question);
328                response.setWindowModality(Qt::WindowModal);
329                int ret = response.exec();
330                if (ret == QMessageBox::Accepted)
331                        upgradeFirmware();
332        }
333}
334
335void OstcFirmwareCheck::upgradeFirmware()
336{
337        // start download of latestFirmwareHexFile
338        QString saveFileName = latestFirmwareHexFile;
339        saveFileName.replace("http://www.heinrichsweikamp.net/autofirmware/", "");
340        saveFileName.replace("firmware", latestFirmwareAvailable);
341        QString filename = existing_filename ?: prefs.default_filename;
342        QFileInfo fi(filename);
343        filename = fi.absolutePath().append(QDir::separator()).append(saveFileName);
344        storeFirmware = QFileDialog::getSaveFileName(parent, tr("Save the downloaded firmware as"),
345                                                     filename, tr("Firmware files (*.hex *.bin)"));
346        if (storeFirmware.isEmpty())
347                return;
348
349        connect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(saveOstcFirmware(QNetworkReply *)));
350        QNetworkRequest download(latestFirmwareHexFile);
351        manager.get(download);
352}
353
354void OstcFirmwareCheck::saveOstcFirmware(QNetworkReply *reply)
355{
356        // firmware is downloaded
357        // call config->startFirmwareUpdate() with that file and the device data
358
359        QByteArray firmwareData = reply->readAll();
360        QFile file(storeFirmware);
361        file.open(QIODevice::WriteOnly);
362        file.write(firmwareData);
363        file.close();
364        QProgressDialog *dialog = new QProgressDialog("Updating firmware", "", 0, 100);
365        dialog->setCancelButton(0);
366        dialog->setAutoClose(true);
367        ConfigureDiveComputer *config = new ConfigureDiveComputer();
368        connect(config, SIGNAL(message(QString)), dialog, SLOT(setLabelText(QString)));
369        connect(config, SIGNAL(error(QString)), dialog, SLOT(setLabelText(QString)));
370        connect(config, SIGNAL(progress(int)), dialog, SLOT(setValue(int)));
371        connect(dialog, SIGNAL(finished(int)), config, SLOT(dc_close()));
372        config->dc_open(&devData);
373        config->startFirmwareUpdate(storeFirmware, &devData);
374}
375
376ConfigureDiveComputerDialog::~ConfigureDiveComputerDialog()
377{
378        delete config;
379}
380
381void ConfigureDiveComputerDialog::closeEvent(QCloseEvent *event)
382{
383        Q_UNUSED(event)
384        dc_close();
385
386        QSettings settings;
387        settings.beginGroup("ConfigureDiveComputerDialog");
388        settings.beginGroup("ostc3GasTable");
389        for (int i = 0; i < ui.ostc3GasTable->columnCount(); i++)
390                settings.setValue(QString("colwidth%1").arg(i), ui.ostc3GasTable->columnWidth(i));
391        settings.endGroup();
392        settings.beginGroup("ostc3DilTable");
393        for (int i = 0; i < ui.ostc3DilTable->columnCount(); i++)
394                settings.setValue(QString("colwidth%1").arg(i), ui.ostc3DilTable->columnWidth(i));
395        settings.endGroup();
396        settings.beginGroup("ostc3SetPointTable");
397        for (int i = 0; i < ui.ostc3SetPointTable->columnCount(); i++)
398                settings.setValue(QString("colwidth%1").arg(i), ui.ostc3SetPointTable->columnWidth(i));
399        settings.endGroup();
400
401        settings.beginGroup("ostcGasTable");
402        for (int i = 0; i < ui.ostcGasTable->columnCount(); i++)
403                settings.setValue(QString("colwidth%1").arg(i), ui.ostcGasTable->columnWidth(i));
404        settings.endGroup();
405        settings.beginGroup("ostcDilTable");
406        for (int i = 0; i < ui.ostcDilTable->columnCount(); i++)
407                settings.setValue(QString("colwidth%1").arg(i), ui.ostcDilTable->columnWidth(i));
408        settings.endGroup();
409        settings.beginGroup("ostcSetPointTable");
410        for (int i = 0; i < ui.ostcSetPointTable->columnCount(); i++)
411                settings.setValue(QString("colwidth%1").arg(i), ui.ostcSetPointTable->columnWidth(i));
412        settings.endGroup();
413        settings.endGroup();
414}
415
416
417static void fillDeviceList(const char *name, void *data)
418{
419        QComboBox *comboBox = (QComboBox *)data;
420        comboBox->addItem(name);
421}
422
423void ConfigureDiveComputerDialog::fill_device_list(int dc_type)
424{
425        int deviceIndex;
426        ui.device->clear();
427        deviceIndex = enumerate_devices(fillDeviceList, ui.device, dc_type);
428        if (deviceIndex >= 0)
429                ui.device->setCurrentIndex(deviceIndex);
430}
431
432void ConfigureDiveComputerDialog::fill_computer_list()
433{
434        dc_iterator_t *iterator = NULL;
435        dc_descriptor_t *descriptor = NULL;
436
437        struct mydescriptor *mydescriptor;
438
439        dc_descriptor_iterator(&iterator);
440        while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) {
441                const char *vendor = dc_descriptor_get_vendor(descriptor);
442                const char *product = dc_descriptor_get_product(descriptor);
443
444                if (!vendorList.contains(vendor))
445                        vendorList.append(vendor);
446
447                if (!productList[vendor].contains(product))
448                        productList[vendor].push_back(product);
449
450                descriptorLookup[QString(vendor) + QString(product)] = descriptor;
451        }
452        dc_iterator_free(iterator);
453
454        mydescriptor = (struct mydescriptor *)malloc(sizeof(struct mydescriptor));
455        mydescriptor->vendor = "Uemis";
456        mydescriptor->product = "Zurich";
457        mydescriptor->type = DC_FAMILY_NULL;
458        mydescriptor->model = 0;
459
460        if (!vendorList.contains("Uemis"))
461                vendorList.append("Uemis");
462
463        if (!productList["Uemis"].contains("Zurich"))
464                productList["Uemis"].push_back("Zurich");
465
466        descriptorLookup["UemisZurich"] = (dc_descriptor_t *)mydescriptor;
467
468        qSort(vendorList);
469}
470
471void ConfigureDiveComputerDialog::populateDeviceDetails()
472{
473        switch (ui.dcStackedWidget->currentIndex()) {
474        case 0:
475                populateDeviceDetailsOSTC3();
476                break;
477        case 1:
478                populateDeviceDetailsSuuntoVyper();
479                break;
480        case 2:
481                populateDeviceDetailsOSTC();
482                break;
483        case 3:
484                populateDeviceDetailsOSTC4();
485                break;
486        }
487}
488
489#define GET_INT_FROM(_field, _default) ((_field) != NULL) ? (_field)->data(Qt::EditRole).toInt() : (_default)
490
491void ConfigureDiveComputerDialog::populateDeviceDetailsOSTC3()
492{
493        deviceDetails->customText = ui.customTextLlineEdit->text();
494        deviceDetails->diveMode = ui.diveModeComboBox->currentIndex();
495        deviceDetails->saturation = ui.saturationSpinBox->value();
496        deviceDetails->desaturation = ui.desaturationSpinBox->value();
497        deviceDetails->lastDeco = ui.lastDecoSpinBox->value();
498        deviceDetails->brightness = ui.brightnessComboBox->currentIndex();
499        deviceDetails->units = ui.unitsComboBox->currentIndex();
500        deviceDetails->samplingRate = ui.samplingRateComboBox->currentIndex();
501        deviceDetails->salinity = ui.salinitySpinBox->value();
502        deviceDetails->diveModeColor = ui.diveModeColour->currentIndex();
503        deviceDetails->language = ui.languageComboBox->currentIndex();
504        deviceDetails->dateFormat = ui.dateFormatComboBox->currentIndex();
505        deviceDetails->compassGain = ui.compassGainComboBox->currentIndex();
506        deviceDetails->syncTime = ui.dateTimeSyncCheckBox->isChecked();
507        deviceDetails->safetyStop = ui.safetyStopCheckBox->isChecked();
508        deviceDetails->gfHigh = ui.gfHighSpinBox->value();
509        deviceDetails->gfLow = ui.gfLowSpinBox->value();
510        deviceDetails->pressureSensorOffset = ui.pressureSensorOffsetSpinBox->value();
511        deviceDetails->ppO2Min = ui.ppO2MinSpinBox->value();
512        deviceDetails->ppO2Max = ui.ppO2MaxSpinBox->value();
513        deviceDetails->futureTTS = ui.futureTTSSpinBox->value();
514        deviceDetails->ccrMode = ui.ccrModeComboBox->currentIndex();
515        deviceDetails->decoType = ui.decoTypeComboBox->currentIndex();
516        deviceDetails->aGFSelectable = ui.aGFSelectableCheckBox->isChecked();
517        deviceDetails->aGFHigh = ui.aGFHighSpinBox->value();
518        deviceDetails->aGFLow = ui.aGFLowSpinBox->value();
519        deviceDetails->calibrationGas = ui.calibrationGasSpinBox->value();
520        deviceDetails->flipScreen = ui.flipScreenCheckBox->isChecked();
521        deviceDetails->setPointFallback = ui.setPointFallbackCheckBox->isChecked();
522        deviceDetails->leftButtonSensitivity = ui.leftButtonSensitivity->value();
523        deviceDetails->rightButtonSensitivity = ui.rightButtonSensitivity->value();
524        deviceDetails->bottomGasConsumption = ui.bottomGasConsumption->value();
525        deviceDetails->decoGasConsumption = ui.decoGasConsumption->value();
526        deviceDetails->modWarning = ui.modWarning->isChecked();
527        deviceDetails->dynamicAscendRate = ui.dynamicAscendRate->isChecked();
528        deviceDetails->graphicalSpeedIndicator = ui.graphicalSpeedIndicator->isChecked();
529        deviceDetails->alwaysShowppO2 = ui.alwaysShowppO2->isChecked();
530        deviceDetails->tempSensorOffset = lrint(ui.tempSensorOffsetDoubleSpinBox->value() * 10);
531        deviceDetails->safetyStopLength = ui.safetyStopLengthSpinBox->value();
532        deviceDetails->safetyStopStartDepth = lrint(ui.safetyStopStartDepthDoubleSpinBox->value() * 10);
533        deviceDetails->safetyStopEndDepth = lrint(ui.safetyStopEndDepthDoubleSpinBox->value() * 10);
534        deviceDetails->safetyStopResetDepth = lrint(ui.safetyStopResetDepthDoubleSpinBox->value() * 10);
535
536        //set gas values
537        gas gas1;
538        gas gas2;
539        gas gas3;
540        gas gas4;
541        gas gas5;
542
543        gas1.oxygen = GET_INT_FROM(ui.ostc3GasTable->item(0, 1), 21);
544        gas1.helium = GET_INT_FROM(ui.ostc3GasTable->item(0, 2), 0);
545        gas1.type = GET_INT_FROM(ui.ostc3GasTable->item(0, 3), 0);
546        gas1.depth = GET_INT_FROM(ui.ostc3GasTable->item(0, 4), 0);
547
548        gas2.oxygen = GET_INT_FROM(ui.ostc3GasTable->item(1, 1), 21);
549        gas2.helium = GET_INT_FROM(ui.ostc3GasTable->item(1, 2), 0);
550        gas2.type = GET_INT_FROM(ui.ostc3GasTable->item(1, 3), 0);
551        gas2.depth = GET_INT_FROM(ui.ostc3GasTable->item(1, 4), 0);
552
553        gas3.oxygen = GET_INT_FROM(ui.ostc3GasTable->item(2, 1), 21);
554        gas3.helium = GET_INT_FROM(ui.ostc3GasTable->item(2, 2), 0);
555        gas3.type = GET_INT_FROM(ui.ostc3GasTable->item(2, 3), 0);
556        gas3.depth = GET_INT_FROM(ui.ostc3GasTable->item(2, 4), 0);
557
558        gas4.oxygen = GET_INT_FROM(ui.ostc3GasTable->item(3, 1), 21);
559        gas4.helium = GET_INT_FROM(ui.ostc3GasTable->item(3, 2), 0);
560        gas4.type = GET_INT_FROM(ui.ostc3GasTable->item(3, 3), 0);
561        gas4.depth = GET_INT_FROM(ui.ostc3GasTable->item(3, 4), 0);
562
563        gas5.oxygen = GET_INT_FROM(ui.ostc3GasTable->item(4, 1), 21);
564        gas5.helium = GET_INT_FROM(ui.ostc3GasTable->item(4, 2), 0);
565        gas5.type = GET_INT_FROM(ui.ostc3GasTable->item(4, 3), 0);
566        gas5.depth = GET_INT_FROM(ui.ostc3GasTable->item(4, 4), 0);
567
568        deviceDetails->gas1 = gas1;
569        deviceDetails->gas2 = gas2;
570        deviceDetails->gas3 = gas3;
571        deviceDetails->gas4 = gas4;
572        deviceDetails->gas5 = gas5;
573
574        //set dil values
575        gas dil1;
576        gas dil2;
577        gas dil3;
578        gas dil4;
579        gas dil5;
580
581        dil1.oxygen = GET_INT_FROM(ui.ostc3DilTable->item(0, 1), 21);
582        dil1.helium = GET_INT_FROM(ui.ostc3DilTable->item(0, 2), 0);
583        dil1.type = GET_INT_FROM(ui.ostc3DilTable->item(0, 3), 0);
584        dil1.depth = GET_INT_FROM(ui.ostc3DilTable->item(0, 4), 0);
585
586        dil2.oxygen = GET_INT_FROM(ui.ostc3DilTable->item(1, 1), 21);
587        dil2.helium = GET_INT_FROM(ui.ostc3DilTable->item(1, 2), 0);
588        dil2.type = GET_INT_FROM(ui.ostc3DilTable->item(1, 3), 0);
589        dil2.depth = GET_INT_FROM(ui.ostc3DilTable->item(1, 4), 0);
590
591        dil3.oxygen = GET_INT_FROM(ui.ostc3DilTable->item(2, 1), 21);
592        dil3.helium = GET_INT_FROM(ui.ostc3DilTable->item(2, 2), 0);
593        dil3.type = GET_INT_FROM(ui.ostc3DilTable->item(2, 3), 0);
594        dil3.depth = GET_INT_FROM(ui.ostc3DilTable->item(2, 4), 0);
595
596        dil4.oxygen = GET_INT_FROM(ui.ostc3DilTable->item(3, 1), 21);
597        dil4.helium = GET_INT_FROM(ui.ostc3DilTable->item(3, 2), 0);
598        dil4.type = GET_INT_FROM(ui.ostc3DilTable->item(3, 3), 0);
599        dil4.depth = GET_INT_FROM(ui.ostc3DilTable->item(3, 4), 0);
600
601        dil5.oxygen = GET_INT_FROM(ui.ostc3DilTable->item(4, 1), 21);
602        dil5.helium = GET_INT_FROM(ui.ostc3DilTable->item(4, 2), 0);
603        dil5.type = GET_INT_FROM(ui.ostc3DilTable->item(4, 3), 0);
604        dil5.depth = GET_INT_FROM(ui.ostc3DilTable->item(4, 4), 0);
605
606        deviceDetails->dil1 = dil1;
607        deviceDetails->dil2 = dil2;
608        deviceDetails->dil3 = dil3;
609        deviceDetails->dil4 = dil4;
610        deviceDetails->dil5 = dil5;
611
612        //set setpoint details
613        setpoint sp1;
614        setpoint sp2;
615        setpoint sp3;
616        setpoint sp4;
617        setpoint sp5;
618
619        sp1.sp = GET_INT_FROM(ui.ostc3SetPointTable->item(0, 1), 70);
620        sp1.depth = GET_INT_FROM(ui.ostc3SetPointTable->item(0, 2), 0);
621
622        sp2.sp = GET_INT_FROM(ui.ostc3SetPointTable->item(1, 1), 90);
623        sp2.depth = GET_INT_FROM(ui.ostc3SetPointTable->item(1, 2), 20);
624
625        sp3.sp = GET_INT_FROM(ui.ostc3SetPointTable->item(2, 1), 100);
626        sp3.depth = GET_INT_FROM(ui.ostc3SetPointTable->item(2, 2), 33);
627
628        sp4.sp = GET_INT_FROM(ui.ostc3SetPointTable->item(3, 1), 120);
629        sp4.depth = GET_INT_FROM(ui.ostc3SetPointTable->item(3, 2), 50);
630
631        sp5.sp = GET_INT_FROM(ui.ostc3SetPointTable->item(4, 1), 140);
632        sp5.depth = GET_INT_FROM(ui.ostc3SetPointTable->item(4, 2), 70);
633
634        deviceDetails->sp1 = sp1;
635        deviceDetails->sp2 = sp2;
636        deviceDetails->sp3 = sp3;
637        deviceDetails->sp4 = sp4;
638        deviceDetails->sp5 = sp5;
639}
640
641void ConfigureDiveComputerDialog::populateDeviceDetailsOSTC()
642{
643        deviceDetails->customText = ui.customTextLlineEdit_3->text();
644        deviceDetails->saturation = ui.saturationSpinBox_3->value();
645        deviceDetails->desaturation = ui.desaturationSpinBox_3->value();
646        deviceDetails->lastDeco = ui.lastDecoSpinBox_3->value();
647        deviceDetails->samplingRate = ui.samplingRateSpinBox_3->value();
648        deviceDetails->salinity = lrint(ui.salinityDoubleSpinBox_3->value() * 100);
649        deviceDetails->dateFormat = ui.dateFormatComboBox_3->currentIndex();
650        deviceDetails->syncTime = ui.dateTimeSyncCheckBox_3->isChecked();
651        deviceDetails->safetyStop = ui.safetyStopCheckBox_3->isChecked();
652        deviceDetails->gfHigh = ui.gfHighSpinBox_3->value();
653        deviceDetails->gfLow = ui.gfLowSpinBox_3->value();
654        deviceDetails->ppO2Min = ui.ppO2MinSpinBox_3->value();
655        deviceDetails->ppO2Max = ui.ppO2MaxSpinBox_3->value();
656        deviceDetails->futureTTS = ui.futureTTSSpinBox_3->value();
657        deviceDetails->decoType = ui.decoTypeComboBox_3->currentIndex();
658        deviceDetails->aGFSelectable = ui.aGFSelectableCheckBox_3->isChecked();
659        deviceDetails->aGFHigh = ui.aGFHighSpinBox_3->value();
660        deviceDetails->aGFLow = ui.aGFLowSpinBox_3->value();
661        deviceDetails->bottomGasConsumption = ui.bottomGasConsumption_3->value();
662        deviceDetails->decoGasConsumption = ui.decoGasConsumption_3->value();
663        deviceDetails->graphicalSpeedIndicator = ui.graphicalSpeedIndicator_3->isChecked();
664        deviceDetails->safetyStopLength = ui.safetyStopLengthSpinBox_3->value();
665        deviceDetails->safetyStopStartDepth = lrint(ui.safetyStopStartDepthDoubleSpinBox_3->value() * 10);
666        deviceDetails->safetyStopEndDepth = lrint(ui.safetyStopEndDepthDoubleSpinBox_3->value() * 10);
667        deviceDetails->safetyStopResetDepth = lrint(ui.safetyStopResetDepthDoubleSpinBox_3->value() * 10);
668
669        //set gas values
670        gas gas1;
671        gas gas2;
672        gas gas3;
673        gas gas4;
674        gas gas5;
675
676        gas1.oxygen = GET_INT_FROM(ui.ostcGasTable->item(0, 1), 21);
677        gas1.helium = GET_INT_FROM(ui.ostcGasTable->item(0, 2), 0);
678        gas1.type = GET_INT_FROM(ui.ostcGasTable->item(0, 3), 0);
679        gas1.depth = GET_INT_FROM(ui.ostcGasTable->item(0, 4), 0);
680
681        gas2.oxygen = GET_INT_FROM(ui.ostcGasTable->item(1, 1), 21);
682        gas2.helium = GET_INT_FROM(ui.ostcGasTable->item(1, 2), 0);
683        gas2.type = GET_INT_FROM(ui.ostcGasTable->item(1, 3), 0);
684        gas2.depth = GET_INT_FROM(ui.ostcGasTable->item(1, 4), 0);
685
686        gas3.oxygen = GET_INT_FROM(ui.ostcGasTable->item(2, 1), 21);
687        gas3.helium = GET_INT_FROM(ui.ostcGasTable->item(2, 2), 0);
688        gas3.type = GET_INT_FROM(ui.ostcGasTable->item(2, 3), 0);
689        gas3.depth = GET_INT_FROM(ui.ostcGasTable->item(2, 4), 0);
690
691        gas4.oxygen = GET_INT_FROM(ui.ostcGasTable->item(3, 1), 21);
692        gas4.helium = GET_INT_FROM(ui.ostcGasTable->item(3, 2), 0);
693        gas4.type = GET_INT_FROM(ui.ostcGasTable->item(3, 3), 0);
694        gas4.depth = GET_INT_FROM(ui.ostcGasTable->item(3, 4), 0);
695
696        gas5.oxygen = GET_INT_FROM(ui.ostcGasTable->item(4, 1), 21);
697        gas5.helium = GET_INT_FROM(ui.ostcGasTable->item(4, 2), 0);
698        gas5.type = GET_INT_FROM(ui.ostcGasTable->item(4, 3), 0);
699        gas5.depth = GET_INT_FROM(ui.ostcGasTable->item(4, 4), 0);
700
701        deviceDetails->gas1 = gas1;
702        deviceDetails->gas2 = gas2;
703        deviceDetails->gas3 = gas3;
704        deviceDetails->gas4 = gas4;
705        deviceDetails->gas5 = gas5;
706
707        //set dil values
708        gas dil1;
709        gas dil2;
710        gas dil3;
711        gas dil4;
712        gas dil5;
713
714        dil1.oxygen = GET_INT_FROM(ui.ostcDilTable->item(0, 1), 21);
715        dil1.helium = GET_INT_FROM(ui.ostcDilTable->item(0, 2), 0);
716        dil1.type = GET_INT_FROM(ui.ostcDilTable->item(0, 3), 0);
717        dil1.depth = GET_INT_FROM(ui.ostcDilTable->item(0, 4), 0);
718
719        dil2.oxygen = GET_INT_FROM(ui.ostcDilTable->item(1, 1), 21);
720        dil2.helium = GET_INT_FROM(ui.ostcDilTable->item(1, 2), 0);
721        dil2.type = GET_INT_FROM(ui.ostcDilTable->item(1, 3), 0);
722        dil2.depth = GET_INT_FROM(ui.ostcDilTable->item(1, 4), 0);
723
724        dil3.oxygen = GET_INT_FROM(ui.ostcDilTable->item(2, 1), 21);
725        dil3.helium = GET_INT_FROM(ui.ostcDilTable->item(2, 2), 0);
726        dil3.type = GET_INT_FROM(ui.ostcDilTable->item(2, 3), 0);
727        dil3.depth = GET_INT_FROM(ui.ostcDilTable->item(2, 4), 0);
728
729        dil4.oxygen = GET_INT_FROM(ui.ostcDilTable->item(3, 1), 21);
730        dil4.helium = GET_INT_FROM(ui.ostcDilTable->item(3, 2), 0);
731        dil4.type = GET_INT_FROM(ui.ostcDilTable->item(3, 3), 0);
732        dil4.depth = GET_INT_FROM(ui.ostcDilTable->item(3, 4), 0);
733
734        dil5.oxygen = GET_INT_FROM(ui.ostcDilTable->item(4, 1), 21);
735        dil5.helium = GET_INT_FROM(ui.ostcDilTable->item(4, 2), 0);
736        dil5.type = GET_INT_FROM(ui.ostcDilTable->item(4, 3), 0);
737        dil5.depth = GET_INT_FROM(ui.ostcDilTable->item(4, 4), 0);
738
739        deviceDetails->dil1 = dil1;
740        deviceDetails->dil2 = dil2;
741        deviceDetails->dil3 = dil3;
742        deviceDetails->dil4 = dil4;
743        deviceDetails->dil5 = dil5;
744
745        //set setpoint details
746        setpoint sp1;
747        setpoint sp2;
748        setpoint sp3;
749        setpoint sp4;
750        setpoint sp5;
751
752        sp1.sp = GET_INT_FROM(ui.ostcSetPointTable->item(0, 1), 70);
753        sp1.depth = GET_INT_FROM(ui.ostcSetPointTable->item(0, 2), 0);
754
755        sp2.sp = GET_INT_FROM(ui.ostcSetPointTable->item(1, 1), 90);
756        sp2.depth = GET_INT_FROM(ui.ostcSetPointTable->item(1, 2), 20);
757
758        sp3.sp = GET_INT_FROM(ui.ostcSetPointTable->item(2, 1), 100);
759        sp3.depth = GET_INT_FROM(ui.ostcSetPointTable->item(2, 2), 33);
760
761        sp4.sp = GET_INT_FROM(ui.ostcSetPointTable->item(3, 1), 120);
762        sp4.depth = GET_INT_FROM(ui.ostcSetPointTable->item(3, 2), 50);
763
764        sp5.sp = GET_INT_FROM(ui.ostcSetPointTable->item(4, 1), 140);
765        sp5.depth = GET_INT_FROM(ui.ostcSetPointTable->item(4, 2), 70);
766
767        deviceDetails->sp1 = sp1;
768        deviceDetails->sp2 = sp2;
769        deviceDetails->sp3 = sp3;
770        deviceDetails->sp4 = sp4;
771        deviceDetails->sp5 = sp5;
772}
773
774void ConfigureDiveComputerDialog::populateDeviceDetailsSuuntoVyper()
775{
776        deviceDetails->customText = ui.customTextLlineEdit_1->text();
777        deviceDetails->samplingRate = ui.samplingRateComboBox_1->currentIndex() == 3 ? 60 : (ui.samplingRateComboBox_1->currentIndex() + 1) * 10;
778        deviceDetails->altitude = ui.altitudeRangeComboBox->currentIndex();
779        deviceDetails->personalSafety = ui.personalSafetyComboBox->currentIndex();
780        deviceDetails->timeFormat = ui.timeFormatComboBox->currentIndex();
781        deviceDetails->units = ui.unitsComboBox_1->currentIndex();
782        deviceDetails->diveMode = ui.diveModeComboBox_1->currentIndex();
783        deviceDetails->lightEnabled = ui.lightCheckBox->isChecked();
784        deviceDetails->light = ui.lightSpinBox->value();
785        deviceDetails->alarmDepthEnabled = ui.alarmDepthCheckBox->isChecked();
786        deviceDetails->alarmDepth = units_to_depth(ui.alarmDepthDoubleSpinBox->value()).mm;
787        deviceDetails->alarmTimeEnabled = ui.alarmTimeCheckBox->isChecked();
788        deviceDetails->alarmTime = ui.alarmTimeSpinBox->value();
789}
790
791void ConfigureDiveComputerDialog::populateDeviceDetailsOSTC4()
792{
793}
794
795void ConfigureDiveComputerDialog::readSettings()
796{
797        ui.progressBar->setValue(0);
798        ui.progressBar->setFormat("%p%");
799        ui.progressBar->setTextVisible(true);
800        // Fw update is no longer a option, needs to be done on a untouched device
801        ui.updateFirmwareButton->setEnabled(false);
802
803        config->readSettings(&device_data);
804}
805
806void ConfigureDiveComputerDialog::resetSettings()
807{
808        ui.progressBar->setValue(0);
809        ui.progressBar->setFormat("%p%");
810        ui.progressBar->setTextVisible(true);
811
812        config->resetSettings(&device_data);
813}
814
815void ConfigureDiveComputerDialog::configMessage(QString msg)
816{
817        ui.progressBar->setFormat(msg);
818}
819
820void ConfigureDiveComputerDialog::configError(QString err)
821{
822        ui.progressBar->setFormat("Error: " + err);
823}
824
825void ConfigureDiveComputerDialog::getDeviceData()
826{
827        device_data.devname = strdup(ui.device->currentText().toUtf8().data());
828        device_data.vendor = strdup(selected_vendor.toUtf8().data());
829        device_data.product = strdup(selected_product.toUtf8().data());
830
831        device_data.descriptor = descriptorLookup[selected_vendor + selected_product];
832        device_data.deviceid = device_data.diveid = 0;
833
834        auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
835        dc->setDevice(device_data.devname);
836}
837
838void ConfigureDiveComputerDialog::on_cancel_clicked()
839{
840        this->close();
841}
842
843void ConfigureDiveComputerDialog::on_saveSettingsPushButton_clicked()
844{
845        ui.progressBar->setValue(0);
846        ui.progressBar->setFormat("%p%");
847        ui.progressBar->setTextVisible(true);
848
849        populateDeviceDetails();
850        config->saveDeviceDetails(deviceDetails, &device_data);
851}
852
853void ConfigureDiveComputerDialog::deviceDetailsReceived(DeviceDetails *newDeviceDetails)
854{
855        deviceDetails = newDeviceDetails;
856        reloadValues();
857}
858
859void ConfigureDiveComputerDialog::reloadValues()
860{
861        // Enable the buttons to do operations on this data
862        ui.saveSettingsPushButton->setEnabled(true);
863        ui.backupButton->setEnabled(true);
864
865        switch (ui.dcStackedWidget->currentIndex()) {
866        case 0:
867                reloadValuesOSTC3();
868                break;
869        case 1:
870                reloadValuesSuuntoVyper();
871                break;
872        case 2:
873                reloadValuesOSTC();
874                break;
875        case 3:
876                reloadValuesOSTC4();
877                break;
878        }
879}
880
881void ConfigureDiveComputerDialog::reloadValuesOSTC3()
882{
883        ui.serialNoLineEdit->setText(deviceDetails->serialNo);
884        ui.firmwareVersionLineEdit->setText(deviceDetails->firmwareVersion);
885        ui.customTextLlineEdit->setText(deviceDetails->customText);
886        ui.modelLineEdit->setText(deviceDetails->model);
887        ui.diveModeComboBox->setCurrentIndex(deviceDetails->diveMode);
888        ui.saturationSpinBox->setValue(deviceDetails->saturation);
889        ui.desaturationSpinBox->setValue(deviceDetails->desaturation);
890        ui.lastDecoSpinBox->setValue(deviceDetails->lastDeco);
891        ui.brightnessComboBox->setCurrentIndex(deviceDetails->brightness);
892        ui.unitsComboBox->setCurrentIndex(deviceDetails->units);
893        ui.samplingRateComboBox->setCurrentIndex(deviceDetails->samplingRate);
894        ui.salinitySpinBox->setValue(deviceDetails->salinity);
895        ui.diveModeColour->setCurrentIndex(deviceDetails->diveModeColor);
896        ui.languageComboBox->setCurrentIndex(deviceDetails->language);
897        ui.dateFormatComboBox->setCurrentIndex(deviceDetails->dateFormat);
898        ui.compassGainComboBox->setCurrentIndex(deviceDetails->compassGain);
899        ui.safetyStopCheckBox->setChecked(deviceDetails->safetyStop);
900        ui.gfHighSpinBox->setValue(deviceDetails->gfHigh);
901        ui.gfLowSpinBox->setValue(deviceDetails->gfLow);
902        ui.pressureSensorOffsetSpinBox->setValue(deviceDetails->pressureSensorOffset);
903        ui.ppO2MinSpinBox->setValue(deviceDetails->ppO2Min);
904        ui.ppO2MaxSpinBox->setValue(deviceDetails->ppO2Max);
905        ui.futureTTSSpinBox->setValue(deviceDetails->futureTTS);
906        ui.ccrModeComboBox->setCurrentIndex(deviceDetails->ccrMode);
907        ui.decoTypeComboBox->setCurrentIndex(deviceDetails->decoType);
908        ui.aGFSelectableCheckBox->setChecked(deviceDetails->aGFSelectable);
909        ui.aGFHighSpinBox->setValue(deviceDetails->aGFHigh);
910        ui.aGFLowSpinBox->setValue(deviceDetails->aGFLow);
911        ui.calibrationGasSpinBox->setValue(deviceDetails->calibrationGas);
912        ui.flipScreenCheckBox->setChecked(deviceDetails->flipScreen);
913        ui.setPointFallbackCheckBox->setChecked(deviceDetails->setPointFallback);
914        ui.leftButtonSensitivity->setValue(deviceDetails->leftButtonSensitivity);
915        ui.rightButtonSensitivity->setValue(deviceDetails->rightButtonSensitivity);
916        ui.bottomGasConsumption->setValue(deviceDetails->bottomGasConsumption);
917        ui.decoGasConsumption->setValue(deviceDetails->decoGasConsumption);
918        ui.modWarning->setChecked(deviceDetails->modWarning);
919        ui.dynamicAscendRate->setChecked(deviceDetails->dynamicAscendRate);
920        ui.graphicalSpeedIndicator->setChecked(deviceDetails->graphicalSpeedIndicator);
921        ui.alwaysShowppO2->setChecked(deviceDetails->alwaysShowppO2);
922        ui.tempSensorOffsetDoubleSpinBox->setValue((double)deviceDetails->tempSensorOffset / 10.0);
923        ui.safetyStopLengthSpinBox->setValue(deviceDetails->safetyStopLength);
924        ui.safetyStopStartDepthDoubleSpinBox->setValue(deviceDetails->safetyStopStartDepth / 10.0);
925        ui.safetyStopEndDepthDoubleSpinBox->setValue(deviceDetails->safetyStopEndDepth / 10.0);
926        ui.safetyStopResetDepthDoubleSpinBox->setValue(deviceDetails->safetyStopResetDepth / 10.0);
927
928        //load gas 1 values
929        ui.ostc3GasTable->setItem(0, 1, new QTableWidgetItem(QString::number(deviceDetails->gas1.oxygen)));
930        ui.ostc3GasTable->setItem(0, 2, new QTableWidgetItem(QString::number(deviceDetails->gas1.helium)));
931        ui.ostc3GasTable->setItem(0, 3, new QTableWidgetItem(QString::number(deviceDetails->gas1.type)));
932        ui.ostc3GasTable->setItem(0, 4, new QTableWidgetItem(QString::number(deviceDetails->gas1.depth)));
933
934        //load gas 2 values
935        ui.ostc3GasTable->setItem(1, 1, new QTableWidgetItem(QString::number(deviceDetails->gas2.oxygen)));
936        ui.ostc3GasTable->setItem(1, 2, new QTableWidgetItem(QString::number(deviceDetails->gas2.helium)));
937        ui.ostc3GasTable->setItem(1, 3, new QTableWidgetItem(QString::number(deviceDetails->gas2.type)));
938        ui.ostc3GasTable->setItem(1, 4, new QTableWidgetItem(QString::number(deviceDetails->gas2.depth)));
939
940        //load gas 3 values
941        ui.ostc3GasTable->setItem(2, 1, new QTableWidgetItem(QString::number(deviceDetails->gas3.oxygen)));
942        ui.ostc3GasTable->setItem(2, 2, new QTableWidgetItem(QString::number(deviceDetails->gas3.helium)));
943        ui.ostc3GasTable->setItem(2, 3, new QTableWidgetItem(QString::number(deviceDetails->gas3.type)));
944        ui.ostc3GasTable->setItem(2, 4, new QTableWidgetItem(QString::number(deviceDetails->gas3.depth)));
945
946        //load gas 4 values
947        ui.ostc3GasTable->setItem(3, 1, new QTableWidgetItem(QString::number(deviceDetails->gas4.oxygen)));
948        ui.ostc3GasTable->setItem(3, 2, new QTableWidgetItem(QString::number(deviceDetails->gas4.helium)));
949        ui.ostc3GasTable->setItem(3, 3, new QTableWidgetItem(QString::number(deviceDetails->gas4.type)));
950        ui.ostc3GasTable->setItem(3, 4, new QTableWidgetItem(QString::number(deviceDetails->gas4.depth)));
951
952        //load gas 5 values
953        ui.ostc3GasTable->setItem(4, 1, new QTableWidgetItem(QString::number(deviceDetails->gas5.oxygen)));
954        ui.ostc3GasTable->setItem(4, 2, new QTableWidgetItem(QString::number(deviceDetails->gas5.helium)));
955        ui.ostc3GasTable->setItem(4, 3, new QTableWidgetItem(QString::number(deviceDetails->gas5.type)));
956        ui.ostc3GasTable->setItem(4, 4, new QTableWidgetItem(QString::number(deviceDetails->gas5.depth)));
957
958        //load dil 1 values
959        ui.ostc3DilTable->setItem(0, 1, new QTableWidgetItem(QString::number(deviceDetails->dil1.oxygen)));
960        ui.ostc3DilTable->setItem(0, 2, new QTableWidgetItem(QString::number(deviceDetails->dil1.helium)));
961        ui.ostc3DilTable->setItem(0, 3, new QTableWidgetItem(QString::number(deviceDetails->dil1.type)));
962        ui.ostc3DilTable->setItem(0, 4, new QTableWidgetItem(QString::number(deviceDetails->dil1.depth)));
963
964        //load dil 2 values
965        ui.ostc3DilTable->setItem(1, 1, new QTableWidgetItem(QString::number(deviceDetails->dil2.oxygen)));
966        ui.ostc3DilTable->setItem(1, 2, new QTableWidgetItem(QString::number(deviceDetails->dil2.helium)));
967        ui.ostc3DilTable->setItem(1, 3, new QTableWidgetItem(QString::number(deviceDetails->dil2.type)));
968        ui.ostc3DilTable->setItem(1, 4, new QTableWidgetItem(QString::number(deviceDetails->dil2.depth)));
969
970        //load dil 3 values
971        ui.ostc3DilTable->setItem(2, 1, new QTableWidgetItem(QString::number(deviceDetails->dil3.oxygen)));
972        ui.ostc3DilTable->setItem(2, 2, new QTableWidgetItem(QString::number(deviceDetails->dil3.helium)));
973        ui.ostc3DilTable->setItem(2, 3, new QTableWidgetItem(QString::number(deviceDetails->dil3.type)));
974        ui.ostc3DilTable->setItem(2, 4, new QTableWidgetItem(QString::number(deviceDetails->dil3.depth)));
975
976        //load dil 4 values
977        ui.ostc3DilTable->setItem(3, 1, new QTableWidgetItem(QString::number(deviceDetails->dil4.oxygen)));
978        ui.ostc3DilTable->setItem(3, 2, new QTableWidgetItem(QString::number(deviceDetails->dil4.helium)));
979        ui.ostc3DilTable->setItem(3, 3, new QTableWidgetItem(QString::number(deviceDetails->dil4.type)));
980        ui.ostc3DilTable->setItem(3, 4, new QTableWidgetItem(QString::number(deviceDetails->dil4.depth)));
981
982        //load dil 5 values
983        ui.ostc3DilTable->setItem(4, 1, new QTableWidgetItem(QString::number(deviceDetails->dil5.oxygen)));
984        ui.ostc3DilTable->setItem(4, 2, new QTableWidgetItem(QString::number(deviceDetails->dil5.helium)));
985        ui.ostc3DilTable->setItem(4, 3, new QTableWidgetItem(QString::number(deviceDetails->dil5.type)));
986        ui.ostc3DilTable->setItem(4, 4, new QTableWidgetItem(QString::number(deviceDetails->dil5.depth)));
987
988        //load setpoint 1 values
989        ui.ostc3SetPointTable->setItem(0, 1, new QTableWidgetItem(QString::number(deviceDetails->sp1.sp)));
990        ui.ostc3SetPointTable->setItem(0, 2, new QTableWidgetItem(QString::number(deviceDetails->sp1.depth)));
991
992        //load setpoint 2 values
993        ui.ostc3SetPointTable->setItem(1, 1, new QTableWidgetItem(QString::number(deviceDetails->sp2.sp)));
994        ui.ostc3SetPointTable->setItem(1, 2, new QTableWidgetItem(QString::number(deviceDetails->sp2.depth)));
995
996        //load setpoint 3 values
997        ui.ostc3SetPointTable->setItem(2, 1, new QTableWidgetItem(QString::number(deviceDetails->sp3.sp)));
998        ui.ostc3SetPointTable->setItem(2, 2, new QTableWidgetItem(QString::number(deviceDetails->sp3.depth)));
999
1000        //load setpoint 4 values
1001        ui.ostc3SetPointTable->setItem(3, 1, new QTableWidgetItem(QString::number(deviceDetails->sp4.sp)));
1002        ui.ostc3SetPointTable->setItem(3, 2, new QTableWidgetItem(QString::number(deviceDetails->sp4.depth)));
1003
1004        //load setpoint 5 values
1005        ui.ostc3SetPointTable->setItem(4, 1, new QTableWidgetItem(QString::number(deviceDetails->sp5.sp)));
1006        ui.ostc3SetPointTable->setItem(4, 2, new QTableWidgetItem(QString::number(deviceDetails->sp5.depth)));
1007}
1008
1009void ConfigureDiveComputerDialog::reloadValuesOSTC()
1010{
1011        /*
1012# Not in OSTC
1013setBrightness
1014setCalibrationGas
1015setCompassGain
1016setDiveMode - Bult into setDecoType
1017setDiveModeColor - Lots of different colors
1018setFlipScreen
1019setLanguage
1020setPressureSensorOffset
1021setUnits
1022setSetPointFallback
1023setCcrMode
1024# Not in OSTC3
1025setNumberOfDives
1026*/
1027        ui.serialNoLineEdit_3->setText(deviceDetails->serialNo);
1028        ui.firmwareVersionLineEdit_3->setText(deviceDetails->firmwareVersion);
1029        ui.customTextLlineEdit_3->setText(deviceDetails->customText);
1030        ui.saturationSpinBox_3->setValue(deviceDetails->saturation);
1031        ui.desaturationSpinBox_3->setValue(deviceDetails->desaturation);
1032        ui.lastDecoSpinBox_3->setValue(deviceDetails->lastDeco);
1033        ui.samplingRateSpinBox_3->setValue(deviceDetails->samplingRate);
1034        ui.salinityDoubleSpinBox_3->setValue((double)deviceDetails->salinity / 100.0);
1035        ui.dateFormatComboBox_3->setCurrentIndex(deviceDetails->dateFormat);
1036        ui.safetyStopCheckBox_3->setChecked(deviceDetails->safetyStop);
1037        ui.gfHighSpinBox_3->setValue(deviceDetails->gfHigh);
1038        ui.gfLowSpinBox_3->setValue(deviceDetails->gfLow);
1039        ui.ppO2MinSpinBox_3->setValue(deviceDetails->ppO2Min);
1040        ui.ppO2MaxSpinBox_3->setValue(deviceDetails->ppO2Max);
1041        ui.futureTTSSpinBox_3->setValue(deviceDetails->futureTTS);
1042        ui.decoTypeComboBox_3->setCurrentIndex(deviceDetails->decoType);
1043        ui.aGFSelectableCheckBox_3->setChecked(deviceDetails->aGFSelectable);
1044        ui.aGFHighSpinBox_3->setValue(deviceDetails->aGFHigh);
1045        ui.aGFLowSpinBox_3->setValue(deviceDetails->aGFLow);
1046        ui.numberOfDivesSpinBox_3->setValue(deviceDetails->numberOfDives);
1047        ui.bottomGasConsumption_3->setValue(deviceDetails->bottomGasConsumption);
1048        ui.decoGasConsumption_3->setValue(deviceDetails->decoGasConsumption);
1049        ui.graphicalSpeedIndicator_3->setChecked(deviceDetails->graphicalSpeedIndicator);
1050        ui.safetyStopLengthSpinBox_3->setValue(deviceDetails->safetyStopLength);
1051        ui.safetyStopStartDepthDoubleSpinBox_3->setValue(deviceDetails->safetyStopStartDepth / 10.0);
1052        ui.safetyStopEndDepthDoubleSpinBox_3->setValue(deviceDetails->safetyStopEndDepth / 10.0);
1053        ui.safetyStopResetDepthDoubleSpinBox_3->setValue(deviceDetails->safetyStopResetDepth / 10.0);
1054
1055        //load gas 1 values
1056        ui.ostcGasTable->setItem(0, 1, new QTableWidgetItem(QString::number(deviceDetails->gas1.oxygen)));
1057        ui.ostcGasTable->setItem(0, 2, new QTableWidgetItem(QString::number(deviceDetails->gas1.helium)));
1058        ui.ostcGasTable->setItem(0, 3, new QTableWidgetItem(QString::number(deviceDetails->gas1.type)));
1059        ui.ostcGasTable->setItem(0, 4, new QTableWidgetItem(QString::number(deviceDetails->gas1.depth)));
1060
1061        //load gas 2 values
1062        ui.ostcGasTable->setItem(1, 1, new QTableWidgetItem(QString::number(deviceDetails->gas2.oxygen)));
1063        ui.ostcGasTable->setItem(1, 2, new QTableWidgetItem(QString::number(deviceDetails->gas2.helium)));
1064        ui.ostcGasTable->setItem(1, 3, new QTableWidgetItem(QString::number(deviceDetails->gas2.type)));
1065        ui.ostcGasTable->setItem(1, 4, new QTableWidgetItem(QString::number(deviceDetails->gas2.depth)));
1066
1067        //load gas 3 values
1068        ui.ostcGasTable->setItem(2, 1, new QTableWidgetItem(QString::number(deviceDetails->gas3.oxygen)));
1069        ui.ostcGasTable->setItem(2, 2, new QTableWidgetItem(QString::number(deviceDetails->gas3.helium)));
1070        ui.ostcGasTable->setItem(2, 3, new QTableWidgetItem(QString::number(deviceDetails->gas3.type)));
1071        ui.ostcGasTable->setItem(2, 4, new QTableWidgetItem(QString::number(deviceDetails->gas3.depth)));
1072
1073        //load gas 4 values
1074        ui.ostcGasTable->setItem(3, 1, new QTableWidgetItem(QString::number(deviceDetails->gas4.oxygen)));
1075        ui.ostcGasTable->setItem(3, 2, new QTableWidgetItem(QString::number(deviceDetails->gas4.helium)));
1076        ui.ostcGasTable->setItem(3, 3, new QTableWidgetItem(QString::number(deviceDetails->gas4.type)));
1077        ui.ostcGasTable->setItem(3, 4, new QTableWidgetItem(QString::number(deviceDetails->gas4.depth)));
1078
1079        //load gas 5 values
1080        ui.ostcGasTable->setItem(4, 1, new QTableWidgetItem(QString::number(deviceDetails->gas5.oxygen)));
1081        ui.ostcGasTable->setItem(4, 2, new QTableWidgetItem(QString::number(deviceDetails->gas5.helium)));
1082        ui.ostcGasTable->setItem(4, 3, new QTableWidgetItem(QString::number(deviceDetails->gas5.type)));
1083        ui.ostcGasTable->setItem(4, 4, new QTableWidgetItem(QString::number(deviceDetails->gas5.depth)));
1084
1085        //load dil 1 values
1086        ui.ostcDilTable->setItem(0, 1, new QTableWidgetItem(QString::number(deviceDetails->dil1.oxygen)));
1087        ui.ostcDilTable->setItem(0, 2, new QTableWidgetItem(QString::number(deviceDetails->dil1.helium)));
1088        ui.ostcDilTable->setItem(0, 3, new QTableWidgetItem(QString::number(deviceDetails->dil1.type)));
1089        ui.ostcDilTable->setItem(0, 4, new QTableWidgetItem(QString::number(deviceDetails->dil1.depth)));
1090
1091        //load dil 2 values
1092        ui.ostcDilTable->setItem(1, 1, new QTableWidgetItem(QString::number(deviceDetails->dil2.oxygen)));
1093        ui.ostcDilTable->setItem(1, 2, new QTableWidgetItem(QString::number(deviceDetails->dil2.helium)));
1094        ui.ostcDilTable->setItem(1, 3, new QTableWidgetItem(QString::number(deviceDetails->dil2.type)));
1095        ui.ostcDilTable->setItem(1, 4, new QTableWidgetItem(QString::number(deviceDetails->dil2.depth)));
1096
1097        //load dil 3 values
1098        ui.ostcDilTable->setItem(2, 1, new QTableWidgetItem(QString::number(deviceDetails->dil3.oxygen)));
1099        ui.ostcDilTable->setItem(2, 2, new QTableWidgetItem(QString::number(deviceDetails->dil3.helium)));
1100        ui.ostcDilTable->setItem(2, 3, new QTableWidgetItem(QString::number(deviceDetails->dil3.type)));
1101        ui.ostcDilTable->setItem(2, 4, new QTableWidgetItem(QString::number(deviceDetails->dil3.depth)));
1102
1103        //load dil 4 values
1104        ui.ostcDilTable->setItem(3, 1, new QTableWidgetItem(QString::number(deviceDetails->dil4.oxygen)));
1105        ui.ostcDilTable->setItem(3, 2, new QTableWidgetItem(QString::number(deviceDetails->dil4.helium)));
1106        ui.ostcDilTable->setItem(3, 3, new QTableWidgetItem(QString::number(deviceDetails->dil4.type)));
1107        ui.ostcDilTable->setItem(3, 4, new QTableWidgetItem(QString::number(deviceDetails->dil4.depth)));
1108
1109        //load dil 5 values
1110        ui.ostcDilTable->setItem(4, 1, new QTableWidgetItem(QString::number(deviceDetails->dil5.oxygen)));
1111        ui.ostcDilTable->setItem(4, 2, new QTableWidgetItem(QString::number(deviceDetails->dil5.helium)));
1112        ui.ostcDilTable->setItem(4, 3, new QTableWidgetItem(QString::number(deviceDetails->dil5.type)));
1113        ui.ostcDilTable->setItem(4, 4, new QTableWidgetItem(QString::number(deviceDetails->dil5.depth)));
1114
1115        //load setpoint 1 values
1116        ui.ostcSetPointTable->setItem(0, 1, new QTableWidgetItem(QString::number(deviceDetails->sp1.sp)));
1117        ui.ostcSetPointTable->setItem(0, 2, new QTableWidgetItem(QString::number(deviceDetails->sp1.depth)));
1118
1119        //load setpoint 2 values
1120        ui.ostcSetPointTable->setItem(1, 1, new QTableWidgetItem(QString::number(deviceDetails->sp2.sp)));
1121        ui.ostcSetPointTable->setItem(1, 2, new QTableWidgetItem(QString::number(deviceDetails->sp2.depth)));
1122
1123        //load setpoint 3 values
1124        ui.ostcSetPointTable->setItem(2, 1, new QTableWidgetItem(QString::number(deviceDetails->sp3.sp)));
1125        ui.ostcSetPointTable->setItem(2, 2, new QTableWidgetItem(QString::number(deviceDetails->sp3.depth)));
1126
1127        //load setpoint 4 values
1128        ui.ostcSetPointTable->setItem(3, 1, new QTableWidgetItem(QString::number(deviceDetails->sp4.sp)));
1129        ui.ostcSetPointTable->setItem(3, 2, new QTableWidgetItem(QString::number(deviceDetails->sp4.depth)));
1130
1131        //load setpoint 5 values
1132        ui.ostcSetPointTable->setItem(4, 1, new QTableWidgetItem(QString::number(deviceDetails->sp5.sp)));
1133        ui.ostcSetPointTable->setItem(4, 2, new QTableWidgetItem(QString::number(deviceDetails->sp5.depth)));
1134}
1135
1136void ConfigureDiveComputerDialog::reloadValuesSuuntoVyper()
1137{
1138        const char *depth_unit;
1139        ui.maxDepthDoubleSpinBox->setValue(get_depth_units(deviceDetails->maxDepth, NULL, &depth_unit));
1140        ui.maxDepthDoubleSpinBox->setSuffix(depth_unit);
1141        ui.totalTimeSpinBox->setValue(deviceDetails->totalTime);
1142        ui.numberOfDivesSpinBox->setValue(deviceDetails->numberOfDives);
1143        ui.modelLineEdit_1->setText(deviceDetails->model);
1144        ui.firmwareVersionLineEdit_1->setText(deviceDetails->firmwareVersion);
1145        ui.serialNoLineEdit_1->setText(deviceDetails->serialNo);
1146        ui.customTextLlineEdit_1->setText(deviceDetails->customText);
1147        ui.samplingRateComboBox_1->setCurrentIndex(deviceDetails->samplingRate == 60 ? 3 : (deviceDetails->samplingRate / 10) - 1);
1148        ui.altitudeRangeComboBox->setCurrentIndex(deviceDetails->altitude);
1149        ui.personalSafetyComboBox->setCurrentIndex(deviceDetails->personalSafety);
1150        ui.timeFormatComboBox->setCurrentIndex(deviceDetails->timeFormat);
1151        ui.unitsComboBox_1->setCurrentIndex(deviceDetails->units);
1152        ui.diveModeComboBox_1->setCurrentIndex(deviceDetails->diveMode);
1153        ui.lightCheckBox->setChecked(deviceDetails->lightEnabled);
1154        ui.lightSpinBox->setValue(deviceDetails->light);
1155        ui.alarmDepthCheckBox->setChecked(deviceDetails->alarmDepthEnabled);
1156        ui.alarmDepthDoubleSpinBox->setValue(get_depth_units(deviceDetails->alarmDepth, NULL, &depth_unit));
1157        ui.alarmDepthDoubleSpinBox->setSuffix(depth_unit);
1158        ui.alarmTimeCheckBox->setChecked(deviceDetails->alarmTimeEnabled);
1159        ui.alarmTimeSpinBox->setValue(deviceDetails->alarmTime);
1160}
1161
1162void ConfigureDiveComputerDialog::reloadValuesOSTC4()
1163{
1164}
1165
1166void ConfigureDiveComputerDialog::on_backupButton_clicked()
1167{
1168        QString filename = existing_filename ?: prefs.default_filename;
1169        QFileInfo fi(filename);
1170        filename = fi.absolutePath().append(QDir::separator()).append("Backup.xml");
1171        QString backupPath = QFileDialog::getSaveFileName(this, tr("Backup dive computer settings"),
1172                                                          filename, tr("Backup files (*.xml)"));
1173        if (!backupPath.isEmpty()) {
1174                populateDeviceDetails();
1175                if (!config->saveXMLBackup(backupPath, deviceDetails, &device_data)) {
1176                        QMessageBox::critical(this, tr("XML backup error"),
1177                                              tr("An error occurred while saving the backup file.\n%1")
1178                                                      .arg(config->lastError));
1179                } else {
1180                        QMessageBox::information(this, tr("Backup succeeded"),
1181                                                 tr("Your settings have been saved to: %1")
1182                                                         .arg(backupPath));
1183                }
1184        }
1185}
1186
1187void ConfigureDiveComputerDialog::on_restoreBackupButton_clicked()
1188{
1189        QString filename = existing_filename ?: prefs.default_filename;
1190        QFileInfo fi(filename);
1191        filename = fi.absolutePath().append(QDir::separator()).append("Backup.xml");
1192        QString restorePath = QFileDialog::getOpenFileName(this, tr("Restore dive computer settings"),
1193                                                           filename, tr("Backup files (*.xml)"));
1194        if (!restorePath.isEmpty()) {
1195                // Fw update is no longer a option, needs to be done on a untouched device
1196                ui.updateFirmwareButton->setEnabled(false);
1197                if (!config->restoreXMLBackup(restorePath, deviceDetails)) {
1198                        QMessageBox::critical(this, tr("XML restore error"),
1199                                              tr("An error occurred while restoring the backup file.\n%1")
1200                                                      .arg(config->lastError));
1201                } else {
1202                        reloadValues();
1203                        QMessageBox::information(this, tr("Restore succeeded"),
1204                                                 tr("Your settings have been restored successfully."));
1205                }
1206        }
1207}
1208
1209void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked()
1210{
1211        QString filename = existing_filename ?: prefs.default_filename;
1212        QFileInfo fi(filename);
1213        filename = fi.absolutePath();
1214        QString firmwarePath = QFileDialog::getOpenFileName(this, tr("Select firmware file"),
1215                                                            filename, tr("All files (*.*)"));
1216        if (!firmwarePath.isEmpty()) {
1217                ui.progressBar->setValue(0);
1218                ui.progressBar->setFormat("%p%");
1219                ui.progressBar->setTextVisible(true);
1220
1221                config->startFirmwareUpdate(firmwarePath, &device_data);
1222        }
1223}
1224
1225
1226void ConfigureDiveComputerDialog::on_DiveComputerList_currentRowChanged(int currentRow)
1227{
1228        switch (currentRow) {
1229        case 0:
1230                selected_vendor = "Heinrichs Weikamp";
1231                selected_product = "OSTC 3";
1232                fw_upgrade_possible = true;
1233                break;
1234        case 1:
1235                selected_vendor = "Suunto";
1236                selected_product = "Vyper";
1237                fw_upgrade_possible = false;
1238                break;
1239        case 2:
1240                selected_vendor = "Heinrichs Weikamp";
1241                selected_product = "OSTC 2N";
1242                fw_upgrade_possible = true;
1243                break;
1244        case 3:
1245                selected_vendor = "Heinrichs Weikamp";
1246                selected_product = "OSTC 4";
1247                fw_upgrade_possible = true;
1248        default:
1249                /* Not Supported */
1250                return;
1251        }
1252
1253        int dcType = DC_TYPE_SERIAL;
1254
1255
1256        if (selected_vendor == QString("Uemis"))
1257                dcType = DC_TYPE_UEMIS;
1258        fill_device_list(dcType);
1259}
1260
1261void ConfigureDiveComputerDialog::checkLogFile(int state)
1262{
1263        ui.chooseLogFile->setEnabled(state == Qt::Checked);
1264        device_data.libdc_log = (state == Qt::Checked);
1265        if (state == Qt::Checked && logFile.isEmpty()) {
1266                pickLogFile();
1267        }
1268}
1269
1270void ConfigureDiveComputerDialog::pickLogFile()
1271{
1272        QString filename = existing_filename ?: prefs.default_filename;
1273        QFileInfo fi(filename);
1274        filename = fi.absolutePath().append(QDir::separator()).append("subsurface.log");
1275        logFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer download logfile"),
1276                                               filename, tr("Log files (*.log)"));
1277        if (!logFile.isEmpty()) {
1278                free(logfile_name);
1279                logfile_name = strdup(logFile.toUtf8().data());
1280        }
1281}
1282
1283#ifdef BT_SUPPORT
1284void ConfigureDiveComputerDialog::selectRemoteBluetoothDevice()
1285{
1286        if (!btDeviceSelectionDialog) {
1287                btDeviceSelectionDialog = new BtDeviceSelectionDialog(this);
1288                connect(btDeviceSelectionDialog, SIGNAL(finished(int)),
1289                        this, SLOT(bluetoothSelectionDialogIsFinished(int)));
1290        }
1291
1292        btDeviceSelectionDialog->show();
1293}
1294
1295void ConfigureDiveComputerDialog::bluetoothSelectionDialogIsFinished(int result)
1296{
1297        if (result == QDialog::Accepted) {
1298                ui.device->setCurrentText(btDeviceSelectionDialog->getSelectedDeviceAddress());
1299                device_data.bluetooth_mode = true;
1300
1301                ui.progressBar->setFormat("Connecting to device...");
1302                dc_open();
1303        }
1304}
1305#endif
1306
1307void ConfigureDiveComputerDialog::dc_open()
1308{
1309        getDeviceData();
1310
1311        QString err = config->dc_open(&device_data);
1312
1313        if (err != "")
1314                return ui.progressBar->setFormat(err);
1315
1316        ui.retrieveDetails->setEnabled(true);
1317        ui.resetButton->setEnabled(true);
1318        ui.updateFirmwareButton->setEnabled(true);
1319        ui.disconnectButton->setEnabled(true);
1320        ui.restoreBackupButton->setEnabled(true);
1321        ui.connectButton->setEnabled(false);
1322        ui.bluetoothMode->setEnabled(false);
1323        ui.DiveComputerList->setEnabled(false);
1324        ui.logToFile->setEnabled(false);
1325        if (fw_upgrade_possible)
1326                ui.updateFirmwareButton->setEnabled(true);
1327        ui.progressBar->setFormat("Connected to device");
1328}
1329
1330void ConfigureDiveComputerDialog::dc_close()
1331{
1332        config->dc_close(&device_data);
1333
1334        ui.retrieveDetails->setEnabled(false);
1335        ui.resetButton->setEnabled(false);
1336        ui.updateFirmwareButton->setEnabled(false);
1337        ui.disconnectButton->setEnabled(false);
1338        ui.connectButton->setEnabled(true);
1339        ui.bluetoothMode->setEnabled(true);
1340        ui.backupButton->setEnabled(false);
1341        ui.saveSettingsPushButton->setEnabled(false);
1342        ui.restoreBackupButton->setEnabled(false);
1343        ui.DiveComputerList->setEnabled(true);
1344        ui.logToFile->setEnabled(true);
1345        ui.updateFirmwareButton->setEnabled(false);
1346        ui.progressBar->setFormat("Disconnected from device");
1347        ui.progressBar->setValue(0);
1348}
Note: See TracBrowser for help on using the repository browser.