21 #include <QTextStream>
31 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Loading %1").arg(pathName));
38 if (!
file.open(QIODevice::ReadOnly))
52 LOG(VB_GENERAL, LOG_ERR,
53 QString(
"Error parsing: %1 at line: %2 column: %3")
54 .arg(pathName, QString::number(line), QString::number(column)));
56 LOG(VB_GENERAL, LOG_ERR, QString(
"Error Msg: %1").arg(
error));
79 QString backupName = pathName +
".old";
81 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Saving %1").arg(pathName));
83 QFile
file(pathName +
".new");
88 if (!directory.exists() && !directory.mkdir(
m_path))
90 LOG(VB_GENERAL, LOG_ERR, QString(
"Could not create %1").arg(
m_path));
95 if (!
file.open(QIODevice::WriteOnly | QIODevice::Truncate))
97 LOG(VB_GENERAL, LOG_ERR, QString(
"Could not open settings file %1 for writing").arg(
file.fileName()));
102 QTextStream ts(&
file);
111 if (QFile::exists(pathName))
113 if (QFile::exists(backupName) && !QFile::remove(backupName))
115 LOG(VB_GENERAL, LOG_ERR, QString(
"Failed to remove '%1', cannot backup current settings").arg(backupName));
117 success = QFile::rename(pathName, backupName);
122 success =
file.rename(pathName);
125 if (QFile::exists(backupName) && !QFile::remove(backupName))
127 LOG(VB_GENERAL, LOG_WARNING, QString(
"Failed to remove '%1'").arg(backupName));
130 else if (QFile::exists(backupName) && !QFile::rename(backupName, pathName))
132 LOG(VB_GENERAL, LOG_ERR, QString(
"Failed to rename (restore) '%1").arg(backupName));
138 LOG(VB_GENERAL, LOG_ERR, QString(
"Could not save settings file %1").arg(pathName));
146 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
147 QStringList path = setting.split(
'/', QString::SkipEmptyParts);
149 QStringList path = setting.split(
'/', Qt::SkipEmptyParts);
163 QString name = path.front();
166 QDomNode child =
current.namedItem(name);
180 return FindNode(path, child, create);
185 QDomNode node =
FindNode(setting,
false);
188 if (!node.isNull() && !(textNode = node.firstChild().toText()).isNull())
190 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Got \"%1\" for \"%2\"").arg(textNode.nodeValue(), setting));
192 return textNode.nodeValue();
195 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Using default for \"%1\"").arg(setting));
201 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Setting \"%1\" to \"%2\"").arg(setting, value));
203 QDomNode node =
FindNode(setting,
true);
209 if (node.hasChildNodes())
212 textNode = node.firstChild().toText();
213 textNode.setNodeValue(value);
217 textNode =
m_config.createTextNode(value);
218 node.appendChild(textNode);
225 LOG(VB_GENERAL, LOG_DEBUG, QString(
"clearing %1").arg(setting));
226 QDomNode node =
FindNode(setting,
false);
229 QDomNode parent = node.parentNode();
230 parent.removeChild(node);
231 while (parent.childNodes().count() == 0)
233 QDomNode next_parent = parent.parentNode();
234 next_parent.removeChild(parent);
235 parent = next_parent;