21 #include <QTextStream>
39 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Loading %1").arg(pathName));
46 if (!
file.open(QIODevice::ReadOnly))
51 #if QT_VERSION < QT_VERSION_CHECK(6,5,0)
61 LOG(VB_GENERAL, LOG_ERR,
62 QString(
"Error parsing: %1 at line: %2 column: %3")
63 .arg(pathName, QString::number(line), QString::number(column)));
65 LOG(VB_GENERAL, LOG_ERR, QString(
"Error Msg: %1").arg(
error));
75 LOG(VB_GENERAL, LOG_ERR,
76 QString(
"Error parsing: %1 at line: %2 column: %3")
77 .arg(pathName, QString::number(parseresult.errorLine),
78 QString::number(parseresult.errorColumn)));
80 LOG(VB_GENERAL, LOG_ERR, QString(
"Error Msg: %1").arg(parseresult.errorMessage));
104 QString backupName = pathName +
".old";
106 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Saving %1").arg(pathName));
108 QFile
file(pathName +
".new");
113 if (!directory.exists() && !directory.mkdir(
m_path))
115 LOG(VB_GENERAL, LOG_ERR, QString(
"Could not create %1").arg(
m_path));
120 if (!
file.open(QIODevice::WriteOnly | QIODevice::Truncate))
122 LOG(VB_GENERAL, LOG_ERR, QString(
"Could not open settings file %1 for writing").arg(
file.fileName()));
127 QTextStream ts(&
file);
140 LOG(VB_GENERAL, LOG_ERR, QString(
"Failed to remove '%1', cannot backup current settings").arg(backupName));
142 success = QFile::rename(pathName, backupName);
147 success =
file.rename(pathName);
152 LOG(VB_GENERAL, LOG_WARNING, QString(
"Failed to remove '%1'").arg(backupName));
155 else if (
QFile::exists(backupName) && !QFile::rename(backupName, pathName))
157 LOG(VB_GENERAL, LOG_ERR, QString(
"Failed to rename (restore) '%1").arg(backupName));
163 LOG(VB_GENERAL, LOG_ERR, QString(
"Could not save settings file %1").arg(pathName));
171 QStringList path = setting.split(
'/', Qt::SkipEmptyParts);
182 QString name = path.front();
185 QDomNode child =
current.namedItem(name);
199 return FindNode(path, child, create);
204 QDomNode node =
FindNode(setting,
false);
209 textNode = node.firstChild().toText();
210 if (!textNode.isNull())
212 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Got \"%1\" for \"%2\"").arg(textNode.nodeValue(), setting));
214 return textNode.nodeValue();
218 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Using default for \"%1\"").arg(setting));
224 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Setting \"%1\" to \"%2\"").arg(setting, value));
226 QDomNode node =
FindNode(setting,
true);
232 if (node.hasChildNodes())
235 textNode = node.firstChild().toText();
236 textNode.setNodeValue(value);
240 textNode =
m_config.createTextNode(value);
241 node.appendChild(textNode);
248 LOG(VB_GENERAL, LOG_DEBUG, QString(
"clearing %1").arg(setting));
249 QDomNode node =
FindNode(setting,
false);
252 QDomNode parent = node.parentNode();
253 parent.removeChild(node);
254 while (parent.childNodes().count() == 0)
256 QDomNode next_parent = parent.parentNode();
257 next_parent.removeChild(parent);
258 parent = next_parent;