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/configuredivecomputer.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/configuredivecomputer.cpp')
-rw-r--r-- | qt-ui/configuredivecomputer.cpp | 32 |
1 files changed, 32 insertions, 0 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; |