From a42df06dbfc9d55d74ee416d14ab79a8606f34f7 Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Sat, 12 Sep 2015 22:37:34 +0200 Subject: Lift dis- and connect out from config operations When working with ostc's via bluetooth, they will reboot and exit bluetooth mode when you send the disconnect command. Thats kinda inconvenient when you would like to read your settings, change something and write it back, you need to start bluetooth mode on your device twice. Signed-off-by: Anton Lundin Signed-off-by: Dirk Hohndel --- qt-ui/configuredivecomputerdialog.cpp | 64 +++++++++++++++++++++++++++-------- qt-ui/configuredivecomputerdialog.h | 4 +++ qt-ui/configuredivecomputerdialog.ui | 31 ++++++++++++++++- 3 files changed, 84 insertions(+), 15 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp index aa8c6cf36..537b23121 100644 --- a/qt-ui/configuredivecomputerdialog.cpp +++ b/qt-ui/configuredivecomputerdialog.cpp @@ -131,6 +131,8 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDia ui.chooseLogFile->setEnabled(ui.logToFile->isChecked()); connect(ui.chooseLogFile, SIGNAL(clicked()), this, SLOT(pickLogFile())); connect(ui.logToFile, SIGNAL(stateChanged(int)), this, SLOT(checkLogFile(int))); + connect(ui.connectButton, SIGNAL(clicked()), this, SLOT(dc_open())); + connect(ui.disconnectButton, SIGNAL(clicked()), this, SLOT(dc_close())); memset(&device_data, 0, sizeof(device_data)); fill_computer_list(); @@ -302,15 +304,20 @@ void OstcFirmwareCheck::saveOstcFirmware(QNetworkReply *reply) connect(config, SIGNAL(message(QString)), dialog, SLOT(setLabelText(QString))); connect(config, SIGNAL(error(QString)), dialog, SLOT(setLabelText(QString))); connect(config, SIGNAL(progress(int)), dialog, SLOT(setValue(int))); + connect(dialog, SIGNAL(finished(int)), config, SLOT(dc_close())); + config->dc_open(&devData); config->startFirmwareUpdate(storeFirmware, &devData); } ConfigureDiveComputerDialog::~ConfigureDiveComputerDialog() { + delete config; } void ConfigureDiveComputerDialog::closeEvent(QCloseEvent *event) { + dc_close(); + QSettings settings; settings.beginGroup("ConfigureDiveComputerDialog"); settings.beginGroup("ostc3GasTable"); @@ -710,7 +717,6 @@ void ConfigureDiveComputerDialog::readSettings() ui.progressBar->setFormat("%p%"); ui.progressBar->setTextVisible(true); - getDeviceData(); config->readSettings(&device_data); } @@ -720,7 +726,6 @@ void ConfigureDiveComputerDialog::resetSettings() ui.progressBar->setFormat("%p%"); ui.progressBar->setTextVisible(true); - getDeviceData(); config->resetSettings(&device_data); } @@ -758,7 +763,6 @@ void ConfigureDiveComputerDialog::on_saveSettingsPushButton_clicked() ui.progressBar->setTextVisible(true); populateDeviceDetails(); - getDeviceData(); config->saveDeviceDetails(deviceDetails, &device_data); } @@ -1067,7 +1071,6 @@ void ConfigureDiveComputerDialog::on_backupButton_clicked() filename, tr("Backup files (*.xml)")); if (!backupPath.isEmpty()) { populateDeviceDetails(); - getDeviceData(); if (!config->saveXMLBackup(backupPath, deviceDetails, &device_data)) { QMessageBox::critical(this, tr("XML backup error"), tr("An error occurred while saving the backup file.\n%1") @@ -1094,8 +1097,6 @@ void ConfigureDiveComputerDialog::on_restoreBackupButton_clicked() .arg(config->lastError)); } else { reloadValues(); - //getDeviceData(); - //config->saveDeviceDetails(deviceDetails, &device_data); QMessageBox::information(this, tr("Restore succeeded"), tr("Your settings have been restored successfully.")); } @@ -1114,7 +1115,6 @@ void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked() ui.progressBar->setFormat("%p%"); ui.progressBar->setTextVisible(true); - getDeviceData(); config->startFirmwareUpdate(firmwarePath, &device_data); } } @@ -1122,25 +1122,21 @@ void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked() void ConfigureDiveComputerDialog::on_DiveComputerList_currentRowChanged(int currentRow) { - // Disable the buttons to do operations on this data - ui.saveSettingsPushButton->setEnabled(false); - ui.backupButton->setEnabled(false); - switch (currentRow) { case 0: selected_vendor = "Heinrichs Weikamp"; selected_product = "OSTC 3"; - ui.updateFirmwareButton->setEnabled(true); + fw_upgrade_possible = true; break; case 1: selected_vendor = "Suunto"; selected_product = "Vyper"; - ui.updateFirmwareButton->setEnabled(false); + fw_upgrade_possible = false; break; case 2: selected_vendor = "Heinrichs Weikamp"; selected_product = "OSTC 2N"; - ui.updateFirmwareButton->setEnabled(true); + fw_upgrade_possible = true; break; default: /* Not Supported */ @@ -1176,3 +1172,43 @@ void ConfigureDiveComputerDialog::pickLogFile() logfile_name = strdup(logFile.toUtf8().data()); } } + +void ConfigureDiveComputerDialog::dc_open() +{ + getDeviceData(); + + QString err = config->dc_open(&device_data); + + if (err != "") + return ui.progressBar->setFormat(err); + + ui.retrieveDetails->setEnabled(true); + ui.resetButton->setEnabled(true); + ui.updateFirmwareButton->setEnabled(true); + ui.disconnectButton->setEnabled(true); + ui.restoreBackupButton->setEnabled(true); + ui.connectButton->setEnabled(false); + ui.DiveComputerList->setEnabled(false); + ui.logToFile->setEnabled(false); + if (fw_upgrade_possible) + ui.updateFirmwareButton->setEnabled(true); + ui.progressBar->setFormat("Connected to device"); +} + +void ConfigureDiveComputerDialog::dc_close() +{ + config->dc_close(&device_data); + + ui.retrieveDetails->setEnabled(false); + ui.resetButton->setEnabled(false); + ui.updateFirmwareButton->setEnabled(false); + ui.disconnectButton->setEnabled(false); + ui.connectButton->setEnabled(true); + ui.backupButton->setEnabled(false); + ui.saveSettingsPushButton->setEnabled(false); + ui.restoreBackupButton->setEnabled(false); + ui.DiveComputerList->setEnabled(true); + ui.logToFile->setEnabled(true); + ui.updateFirmwareButton->setEnabled(false); + ui.progressBar->setFormat("Disonnected from device"); +} diff --git a/qt-ui/configuredivecomputerdialog.h b/qt-ui/configuredivecomputerdialog.h index 19bab0a5b..d11726873 100644 --- a/qt-ui/configuredivecomputerdialog.h +++ b/qt-ui/configuredivecomputerdialog.h @@ -81,6 +81,9 @@ slots: void on_DiveComputerList_currentRowChanged(int currentRow); + void dc_open(); + void dc_close(); + private: Ui::ConfigureDiveComputerDialog ui; @@ -108,6 +111,7 @@ private: QString selected_vendor; QString selected_product; + bool fw_upgrade_possible; }; class OstcFirmwareCheck : QObject { diff --git a/qt-ui/configuredivecomputerdialog.ui b/qt-ui/configuredivecomputerdialog.ui index a0a0a2eac..edc24e29e 100644 --- a/qt-ui/configuredivecomputerdialog.ui +++ b/qt-ui/configuredivecomputerdialog.ui @@ -30,6 +30,12 @@ + + + 0 + 0 + + true @@ -42,6 +48,23 @@ + + + + Connect + + + + + + + false + + + Disconnect + + + @@ -50,6 +73,9 @@ + + false + Retrieve available details @@ -96,6 +122,9 @@ + + false + Restore backup @@ -595,7 +624,7 @@ - true + false Reset device to default settings -- cgit v1.2.3-70-g09d2