61 QDomElement parent = doc.documentElement();
62 QDomElement menuBar = parent.namedItem(QStringLiteral(
"MenuBar")).toElement();
63 QDomElement insertAfter = menuBar;
64 if (menuBar.isNull()) {
65 insertAfter = parent.firstChildElement();
67 Q_FOREACH (
const QDomElement &e, toolBars) {
68 QDomNode result = parent.insertAfter(e, insertAfter);
69 Q_ASSERT(!result.isNull());
81 QDomElement actionPropElement = doc.documentElement().namedItem(QStringLiteral(
"ActionProperties")).toElement();
83 if (actionPropElement.isNull()) {
87 QDomNode n = actionPropElement.firstChild();
89 QDomElement e = n.toElement();
95 if (e.tagName().compare(QStringLiteral(
"action"), Qt::CaseInsensitive) != 0) {
99 const QString actionName = e.attribute(QStringLiteral(
"name"));
100 if (actionName.isEmpty()) {
104 QMap<QString, QMap<QString, QString> >::Iterator propIt = properties.find(actionName);
105 if (propIt == properties.end()) {
106 propIt = properties.insert(actionName, QMap<QString, QString>());
109 const QDomNamedNodeMap attributes = e.attributes();
110 const uint attributeslength = attributes.length();
112 for (
uint i = 0; i < attributeslength; ++i) {
113 const QDomAttr attr = attributes.item(i).toAttr();
119 const QString name = attr.name();
121 if (name == QStringLiteral(
"name") || name.isEmpty()) {
125 (*propIt)[ name ] = attr.value();
136 QDomElement actionPropElement = doc.documentElement().namedItem(QStringLiteral(
"ActionProperties")).toElement();
138 if (actionPropElement.isNull()) {
139 actionPropElement = doc.createElement(QStringLiteral(
"ActionProperties"));
140 doc.documentElement().appendChild(actionPropElement);
146 QDomNode actionNode = actionPropElement.firstChild();
147 while (!actionNode.isNull()) {
148 if (properties.contains(actionNode.toElement().attribute(QStringLiteral(
"name")))) {
149 QDomNode nextNode = actionNode.nextSibling();
150 actionPropElement.removeChild(actionNode);
151 actionNode = nextNode;
153 actionNode = actionNode.nextSibling();
157 ActionPropertiesMap::ConstIterator it = properties.begin();
158 const ActionPropertiesMap::ConstIterator end = properties.end();
159 for (; it != end; ++it) {
160 QDomElement action = doc.createElement(QStringLiteral(
"Action"));
161 action.setAttribute(QStringLiteral(
"name"), it.key());
162 actionPropElement.appendChild(action);
164 const QMap<QString, QString> attributes = (*it);
165 QMap<QString, QString>::ConstIterator attrIt = attributes.begin();
166 const QMap<QString, QString>::ConstIterator attrEnd = attributes.end();
167 for (; attrIt != attrEnd; ++attrIt) {
168 action.setAttribute(attrIt.key(), attrIt.value());
175 enum { ST_START, ST_AFTER_OPEN, ST_AFTER_GUI,
176 ST_EXPECT_VERSION, ST_VERSION_NUM
178 const int length = xml.length();
179 for (
int pos = 0; pos <
length; pos++) {
182 if (xml[pos] == QLatin1Char(
'<')) {
183 state = ST_AFTER_OPEN;
186 case ST_AFTER_OPEN: {
188 const int guipos = xml.indexOf(QStringLiteral(
"gui"), pos, Qt::CaseInsensitive);
194 state = ST_AFTER_GUI;
198 state = ST_EXPECT_VERSION;
200 case ST_EXPECT_VERSION: {
201 const int verpos = xml.indexOf(QStringLiteral(
"version"), pos, Qt::CaseInsensitive);
206 while (xml.at(pos).isSpace()) {
209 if (xml.at(pos++) != QLatin1Char(
'=')) {
212 while (xml.at(pos).isSpace()) {
216 state = ST_VERSION_NUM;
219 case ST_VERSION_NUM: {
221 for (endpos = pos; endpos <
length; endpos++) {
222 const ushort ch = xml[endpos].unicode();
223 if (ch >= QLatin1Char(
'0') && ch <= QLatin1Char(
'9')) {
226 if (ch == QLatin1Char(
'"')) {
233 if (endpos != pos && endpos <
length) {
234 const QString matchCandidate = xml.mid(pos, endpos - pos);
235 return matchCandidate;
238 state = ST_EXPECT_VERSION;
249 Q_ASSERT(!files.isEmpty());
251 if (files.count() == 1) {
260 Q_FOREACH (
const QString &file, files) {
264 allDocuments.append(d);
268 uint bestVersion = 0;
272 for (; docIt != docEnd; ++docIt) {
274 if (versionStr.isEmpty()) {
280 uint version = versionStr.toUInt(&ok);
286 if (version > bestVersion) {
289 bestVersion = version;
293 if (best != docEnd) {
294 if (best != allDocuments.begin()) {
297 if ((*local).file.startsWith(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation))) {
299 QDomDocument localDocument;
300 localDocument.setContent((*local).data);
312 if (!properties.isEmpty() || !toolbars.isEmpty()) {
315 QDomDocument document;
316 document.setContent((*best).data);
319 if (!toolbars.isEmpty()) {
328 (*local).data = document.toString();
333 QFile f((*local).file);
334 if (f.open(QIODevice::WriteOnly)) {
335 const QByteArray utf8data = (*local).data.toUtf8();
336 f.write(utf8data.constData(), utf8data.length());
341 const QString f = (*local).file;
342 const QString backup = f + QStringLiteral(
".backup");
343 QFile::rename(f, backup);
347 m_doc = (*best).data;
351 m_doc = allDocuments.first().data;
352 m_file = allDocuments.first().file;