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:
Joseph W. Joshua 2014-07-22 19:38:30 +03:00 committed by Thiago Macieira
parent a9b55d7f0d
commit 4cc60ea940

View file

@ -201,41 +201,21 @@ bool ConfigureDiveComputer::saveXMLBackup(QString fileName, DeviceDetails *detai
bool ConfigureDiveComputer::restoreXMLBackup(QString fileName, DeviceDetails *details, QString errorText)
{
xmlDocPtr doc;
xmlNodePtr node;
xmlChar *key;
doc = xmlParseFile(fileName.toUtf8().data());
if (doc == NULL) {
errorText = tr("Could not read the backup file.");
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
errorText = tr("Could not open backup file: %1").arg(file.errorString());
return false;
}
node = xmlDocGetRootElement(doc);
if (node == NULL) {
errorText = tr("The specified file is invalid.");
xmlFreeDoc(doc);
return false;
}
QString xml = file.readAll();
if (xmlStrcmp(node->name, (const xmlChar *) "DiveComputerSettingsBackup")) {
errorText = tr("The specified file does not contain a valid backup.");
xmlFreeDoc(doc);
return false;
}
QXmlStreamReader reader(xml);
while (!reader.atEnd()) {
if (reader.isStartElement()) {
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")
details->setCustomText(keyString);
@ -415,11 +395,7 @@ bool ConfigureDiveComputer::restoreXMLBackup(QString fileName, DeviceDetails *de
if (settingName == "CompassGain")
details->setCompassGain(keyString.toInt());
}
settingNode = settingNode->next;
}
}
child = child->next;
reader.readNext();
}
return true;