mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +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)
|
||||
{
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue