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 QStringList path = setting.split(
'/', Qt::SkipEmptyParts);
165 QString name = path.front();
168 QDomNode child =
current.namedItem(name);
182 return FindNode(path, child, create);
187 QDomNode node =
FindNode(setting,
false);
192 textNode = node.firstChild().toText();
193 if (!textNode.isNull())
195 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Got \"%1\" for \"%2\"").arg(textNode.nodeValue(), setting));
197 return textNode.nodeValue();
201 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Using default for \"%1\"").arg(setting));
207 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Setting \"%1\" to \"%2\"").arg(setting, value));
209 QDomNode node =
FindNode(setting,
true);
215 if (node.hasChildNodes())
218 textNode = node.firstChild().toText();
219 textNode.setNodeValue(value);
223 textNode =
m_config.createTextNode(value);
224 node.appendChild(textNode);
231 LOG(VB_GENERAL, LOG_DEBUG, QString(
"clearing %1").arg(setting));
232 QDomNode node =
FindNode(setting,
false);
235 QDomNode parent = node.parentNode();
236 parent.removeChild(node);
237 while (parent.childNodes().count() == 0)
239 QDomNode next_parent = parent.parentNode();
240 next_parent.removeChild(parent);
241 parent = next_parent;