mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
3534e29ae2
commit
e54d7d9178
5 changed files with 90 additions and 11 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue