21 #include <QTextStream>
39 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Loading %1").arg(pathName));
46 if (!
file.open(QIODevice::ReadOnly))
60 LOG(VB_GENERAL, LOG_ERR,
61 QString(
"Error parsing: %1 at line: %2 column: %3")
62 .arg(pathName, QString::number(line), QString::number(column)));
64 LOG(VB_GENERAL, LOG_ERR, QString(
"Error Msg: %1").arg(
error));
87 QString backupName = pathName +
".old";
89 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Saving %1").arg(pathName));
91 QFile
file(pathName +
".new");
96 if (!directory.exists() && !directory.mkdir(
m_path))
98 LOG(VB_GENERAL, LOG_ERR, QString(
"Could not create %1").arg(
m_path));
103 if (!
file.open(QIODevice::WriteOnly | QIODevice::Truncate))
105 LOG(VB_GENERAL, LOG_ERR, QString(
"Could not open settings file %1 for writing").arg(
file.fileName()));
110 QTextStream ts(&
file);
119 if (QFile::exists(pathName))
121 if (QFile::exists(backupName) && !QFile::remove(backupName))
123 LOG(VB_GENERAL, LOG_ERR, QString(
"Failed to remove '%1', cannot backup current settings").arg(backupName));
125 success = QFile::rename(pathName, backupName);
130 success =
file.rename(pathName);
133 if (QFile::exists(backupName) && !QFile::remove(backupName))
135 LOG(VB_GENERAL, LOG_WARNING, QString(
"Failed to remove '%1'").arg(backupName));
138 else if (QFile::exists(backupName) && !QFile::rename(backupName, pathName))
140 LOG(VB_GENERAL, LOG_ERR, QString(
"Failed to rename (restore) '%1").arg(backupName));
146 LOG(VB_GENERAL, LOG_ERR, QString(
"Could not save settings file %1").arg(pathName));
154 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
155 QStringList path = setting.split(
'/', QString::SkipEmptyParts);
157 QStringList path = setting.split(
'/', Qt::SkipEmptyParts);
171 QString name = path.front();
174 QDomNode child =
current.namedItem(name);
188 return FindNode(path, child, create);
193 QDomNode node =
FindNode(setting,
false);
196 if (!node.isNull() && !(textNode = node.firstChild().toText()).isNull())
198 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Got \"%1\" for \"%2\"").arg(textNode.nodeValue(), setting));
200 return textNode.nodeValue();
203 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Using default for \"%1\"").arg(setting));
209 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Setting \"%1\" to \"%2\"").arg(setting, value));
211 QDomNode node =
FindNode(setting,
true);
217 if (node.hasChildNodes())
220 textNode = node.firstChild().toText();
221 textNode.setNodeValue(value);
225 textNode =
m_config.createTextNode(value);
226 node.appendChild(textNode);
233 LOG(VB_GENERAL, LOG_DEBUG, QString(
"clearing %1").arg(setting));
234 QDomNode node =
FindNode(setting,
false);
237 QDomNode parent = node.parentNode();
238 parent.removeChild(node);
239 while (parent.childNodes().count() == 0)
241 QDomNode next_parent = parent.parentNode();
242 next_parent.removeChild(parent);
243 parent = next_parent;