diff options
author | Joseph W. Joshua <joejoshw@gmail.com> | 2014-06-10 19:19:28 +0300 |
---|---|---|
committer | Thiago Macieira <thiago@macieira.org> | 2014-08-13 10:48:14 -0700 |
commit | e54d7d9178fc159f068587a59244340bec068efb (patch) | |
tree | fe0398971e8b7686b0762f1a58cc63361bc81b40 /qt-ui/configuredivecomputerdialog.cpp | |
parent | 3534e29ae2165aab491c2e0cdecd667dd8cf50e8 (diff) | |
download | subsurface-e54d7d9178fc159f068587a59244340bec068efb.tar.gz |
Backup basic settings as XML
This patch enables XML backup. We can now save the settings
to an XML file. Currently this backs up just the basic stuff
such as custom text, language and brightness.
Signed-off-by: Joseph W. Joshua <joejoshw@gmail.com>
Signed-off-by: Thiago Macieira <thiago@macieira.org>
Diffstat (limited to 'qt-ui/configuredivecomputerdialog.cpp')
-rw-r--r-- | qt-ui/configuredivecomputerdialog.cpp | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp index 973243af7..71960b6f2 100644 --- a/qt-ui/configuredivecomputerdialog.cpp +++ b/qt-ui/configuredivecomputerdialog.cpp @@ -7,9 +7,8 @@ #include "../display.h" #include "../divelist.h" #include "configuredivecomputer.h" -#include <QInputDialog> -#include <QDebug> - +#include <QFileDialog> +#include <QMessageBox> struct product { const char *product; dc_descriptor_t *descriptor; @@ -126,6 +125,15 @@ void ConfigureDiveComputerDialog::fill_device_list(int dc_type) ui->device->setCurrentIndex(deviceIndex); } +void ConfigureDiveComputerDialog::populateDeviceDetails() +{ + deviceDetails->setBrightness(ui->brightnessComboBox->currentIndex()); + deviceDetails->setLanguage(ui->languageComboBox->currentIndex()); + deviceDetails->setDateFormat(ui->dateFormatComboBox->currentIndex()); + deviceDetails->setCustomText(ui->customTextLlineEdit->text()); + deviceDetails->setSyncTime(ui->dateTimeSyncCheckBox->isChecked()); +} + void ConfigureDiveComputerDialog::on_vendor_currentIndexChanged(const QString &vendor) { int dcType = DC_TYPE_SERIAL; @@ -200,11 +208,7 @@ void ConfigureDiveComputerDialog::deviceReadFinished() void ConfigureDiveComputerDialog::on_saveSettingsPushButton_clicked() { - deviceDetails->setBrightness(ui->brightnessComboBox->currentIndex()); - deviceDetails->setLanguage(ui->languageComboBox->currentIndex()); - deviceDetails->setDateFormat(ui->dateFormatComboBox->currentIndex()); - deviceDetails->setCustomText(ui->customTextLlineEdit->text()); - deviceDetails->setSyncTime(ui->dateTimeSyncCheckBox->isChecked()); + populateDeviceDetails(); getDeviceData(); config->saveDeviceDetails(deviceDetails, &device_data); } @@ -225,3 +229,29 @@ void ConfigureDiveComputerDialog::reloadValues() ui->dateFormatComboBox->setCurrentIndex(deviceDetails->dateFormat()); } + +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"), + tr("An eror occurred while saving the backup file.\n%1") + .arg(errorText) + ); + } else { + QMessageBox::information(this, tr("Backup succeeded"), + tr("Your settings have been saved to: %1") + .arg(filename) + ); + } + } +} |