diff options
-rw-r--r-- | qt-ui/configuredivecomputer.cpp | 32 | ||||
-rw-r--r-- | qt-ui/configuredivecomputer.h | 2 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerdialog.cpp | 46 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerdialog.h | 3 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerdialog.ui | 18 |
5 files changed, 90 insertions, 11 deletions
diff --git a/qt-ui/configuredivecomputer.cpp b/qt-ui/configuredivecomputer.cpp index ad431eefe..0d602c8e8 100644 --- a/qt-ui/configuredivecomputer.cpp +++ b/qt-ui/configuredivecomputer.cpp @@ -1,6 +1,8 @@ #include "configuredivecomputer.h" #include "libdivecomputer/hw.h" #include <QDebug> +#include <QFile> + ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) : QObject(parent), readThread(0), @@ -42,6 +44,36 @@ void ConfigureDiveComputer::saveDeviceDetails(DeviceDetails *details, device_dat writeThread->start(); } +bool ConfigureDiveComputer::saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data, QString errorText) +{ + QString xml = ""; + QString vendor = data->vendor; + QString product = data->product; + xml += "<backup>"; + xml += "\n<divecomputer vendor='" + vendor + + "' model = '" + product + "'" + + " />"; + xml += "\n<settings>"; + xml += "\n<setting name='CustomText' value = '" + details->customText() + "' />"; + xml += "\n<setting name='Brightness' value = '" + QString::number(details->brightness()) + "' />"; + xml += "\n<setting name='Language' value = '" + QString::number(details->language()) + "' />"; + xml += "\n<setting name='DateFormat' value = '" + QString::number(details->dateFormat()) + "' />"; + xml += "\n</settings>"; + xml += "\n</backup>"; + QFile file(fileName); + if (!file.open(QIODevice::WriteOnly)) { + errorText = tr("Could not save the backup file %1. Error Message: %2") + .arg(fileName, file.errorString()); + return false; + } + //file open successful. write data and save. + QTextStream out(&file); + out << xml; + + file.close(); + return true; +} + void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState) { currentState = newState; diff --git a/qt-ui/configuredivecomputer.h b/qt-ui/configuredivecomputer.h index f21f02910..ca072e148 100644 --- a/qt-ui/configuredivecomputer.h +++ b/qt-ui/configuredivecomputer.h @@ -30,7 +30,7 @@ public: device_data_t *m_data; void saveDeviceDetails(DeviceDetails *details, device_data_t *data); void fetchDeviceDetails(); - + bool saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data, QString errorText); signals: void message(QString msg); void error(QString err); 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) + ); + } + } +} diff --git a/qt-ui/configuredivecomputerdialog.h b/qt-ui/configuredivecomputerdialog.h index e8c941fcf..7312deec7 100644 --- a/qt-ui/configuredivecomputerdialog.h +++ b/qt-ui/configuredivecomputerdialog.h @@ -31,6 +31,8 @@ private slots: void on_saveSettingsPushButton_clicked(); void deviceDetailsReceived(DeviceDetails *newDeviceDetails); void reloadValues(); + void on_backupButton_clicked(); + private: Ui::ConfigureDiveComputerDialog *ui; @@ -48,6 +50,7 @@ private: void fill_device_list(int dc_type); DeviceDetails *deviceDetails; + void populateDeviceDetails(); }; #endif // CONFIGUREDIVECOMPUTERDIALOG_H diff --git a/qt-ui/configuredivecomputerdialog.ui b/qt-ui/configuredivecomputerdialog.ui index 580f86159..4fb731a3c 100644 --- a/qt-ui/configuredivecomputerdialog.ui +++ b/qt-ui/configuredivecomputerdialog.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>364</width> - <height>416</height> + <width>472</width> + <height>472</height> </rect> </property> <property name="windowTitle"> @@ -89,6 +89,20 @@ </property> </spacer> </item> + <item> + <widget class="QPushButton" name="backupButton"> + <property name="text"> + <string>Backup</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="restoreBackupButton"> + <property name="text"> + <string>Restore Backup</string> + </property> + </widget> + </item> </layout> </item> <item> |