mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Use QXmlStreamReader for xml restore
This patch changes reading of OSTC 3 settings backup xml from libxml to QXmlStreamReader to match the use of QXmlStreamWriter in the xml saving. Signed-off-by: Joseph W. Joshua <joejoshw@gmail.com> Signed-off-by: Thiago Macieira <thiago@macieira.org>
This commit is contained in:
parent
a9b55d7f0d
commit
4cc60ea940
1 changed files with 190 additions and 214 deletions
|
@ -201,41 +201,21 @@ bool ConfigureDiveComputer::saveXMLBackup(QString fileName, DeviceDetails *detai
|
||||||
|
|
||||||
bool ConfigureDiveComputer::restoreXMLBackup(QString fileName, DeviceDetails *details, QString errorText)
|
bool ConfigureDiveComputer::restoreXMLBackup(QString fileName, DeviceDetails *details, QString errorText)
|
||||||
{
|
{
|
||||||
xmlDocPtr doc;
|
QFile file(fileName);
|
||||||
xmlNodePtr node;
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
xmlChar *key;
|
errorText = tr("Could not open backup file: %1").arg(file.errorString());
|
||||||
|
|
||||||
doc = xmlParseFile(fileName.toUtf8().data());
|
|
||||||
|
|
||||||
if (doc == NULL) {
|
|
||||||
errorText = tr("Could not read the backup file.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
node = xmlDocGetRootElement(doc);
|
QString xml = file.readAll();
|
||||||
if (node == NULL) {
|
|
||||||
errorText = tr("The specified file is invalid.");
|
|
||||||
xmlFreeDoc(doc);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xmlStrcmp(node->name, (const xmlChar *) "DiveComputerSettingsBackup")) {
|
QXmlStreamReader reader(xml);
|
||||||
errorText = tr("The specified file does not contain a valid backup.");
|
while (!reader.atEnd()) {
|
||||||
xmlFreeDoc(doc);
|
if (reader.isStartElement()) {
|
||||||
return false;
|
QString settingName = reader.name().toString();
|
||||||
}
|
reader.readNext();
|
||||||
|
QString keyString = reader.text().toString();
|
||||||
|
|
||||||
xmlNodePtr child = node->children;
|
|
||||||
|
|
||||||
while (child != NULL) {
|
|
||||||
QString nodeName = (char *)child->name;
|
|
||||||
if (nodeName == "Settings") {
|
|
||||||
xmlNodePtr settingNode = child->children;
|
|
||||||
while (settingNode != NULL) {
|
|
||||||
QString settingName = (char *)settingNode->name;
|
|
||||||
key = xmlNodeListGetString(doc, settingNode->xmlChildrenNode, 1);
|
|
||||||
QString keyString = (char *)key;
|
|
||||||
if (settingName != "text") {
|
|
||||||
if (settingName == "CustomText")
|
if (settingName == "CustomText")
|
||||||
details->setCustomText(keyString);
|
details->setCustomText(keyString);
|
||||||
|
|
||||||
|
@ -415,11 +395,7 @@ bool ConfigureDiveComputer::restoreXMLBackup(QString fileName, DeviceDetails *de
|
||||||
if (settingName == "CompassGain")
|
if (settingName == "CompassGain")
|
||||||
details->setCompassGain(keyString.toInt());
|
details->setCompassGain(keyString.toInt());
|
||||||
}
|
}
|
||||||
|
reader.readNext();
|
||||||
settingNode = settingNode->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
child = child->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue