Changeset View
Changeset View
Standalone View
Standalone View
src/kconfig_compiler/KConfigXmlParser.cpp
Show All 26 Lines | |||||
27 | 27 | | |||
28 | #include <QDomAttr> | 28 | #include <QDomAttr> | ||
29 | #include <QDomElement> | 29 | #include <QDomElement> | ||
30 | #include <QDomNode> | 30 | #include <QDomNode> | ||
31 | #include <QFile> | 31 | #include <QFile> | ||
32 | #include <QList> | 32 | #include <QList> | ||
33 | #include <QStringList> | 33 | #include <QStringList> | ||
34 | #include <QTextStream> | 34 | #include <QTextStream> | ||
35 | 35 | #include <iostream> | |||
36 | namespace | | |||
37 | { | | |||
38 | QTextStream cout(stdout); | | |||
39 | QTextStream cerr(stderr); | | |||
40 | } | | |||
41 | | ||||
42 | //TODO: Move preprocessDefault to Header / CPP implementation. | 36 | //TODO: Move preprocessDefault to Header / CPP implementation. | ||
43 | // it makes no sense for a parser to process those values and generate code. | 37 | // it makes no sense for a parser to process those values and generate code. | ||
44 | 38 | | |||
45 | static void preProcessDefault(QString &defaultValue, const QString &name, | 39 | static void preProcessDefault(QString &defaultValue, const QString &name, | ||
46 | const QString &type, | 40 | const QString &type, | ||
47 | const CfgEntry::Choices &choices, | 41 | const CfgEntry::Choices &choices, | ||
48 | QString &code, const KConfigParameters &cfg) | 42 | QString &code, const KConfigParameters &cfg) | ||
49 | { | 43 | { | ||
50 | if (type == QLatin1String("String") && !defaultValue.isEmpty()) { | 44 | if (type == QLatin1String("String") && !defaultValue.isEmpty()) { | ||
51 | defaultValue = literalString(defaultValue); | 45 | defaultValue = literalString(defaultValue); | ||
52 | 46 | | |||
53 | } else if (type == QLatin1String("Path") && !defaultValue.isEmpty()) { | 47 | } else if (type == QLatin1String("Path") && !defaultValue.isEmpty()) { | ||
54 | defaultValue = literalString(defaultValue); | 48 | defaultValue = literalString(defaultValue); | ||
55 | } else if (type == QLatin1String("Url") && !defaultValue.isEmpty()) { | 49 | } else if (type == QLatin1String("Url") && !defaultValue.isEmpty()) { | ||
56 | // Use fromUserInput in order to support absolute paths and absolute urls, like KDE4's KUrl(QString) did. | 50 | // Use fromUserInput in order to support absolute paths and absolute urls, like KDE4's KUrl(QString) did. | ||
57 | defaultValue = QLatin1String("QUrl::fromUserInput( ") + literalString(defaultValue) + QLatin1Char(')'); | 51 | defaultValue = QLatin1String("QUrl::fromUserInput( ") + literalString(defaultValue) + QLatin1Char(')'); | ||
58 | } else if ((type == QLatin1String("UrlList") || type == QLatin1String("StringList") || type == QLatin1String("PathList")) && !defaultValue.isEmpty()) { | 52 | } else if ((type == QLatin1String("UrlList") || type == QLatin1String("StringList") || type == QLatin1String("PathList")) && !defaultValue.isEmpty()) { | ||
59 | QTextStream cpp(&code, QIODevice::WriteOnly | QIODevice::Append); | 53 | QTextStream cpp(&code, QIODevice::WriteOnly | QIODevice::Append); | ||
60 | if (!code.isEmpty()) { | 54 | if (!code.isEmpty()) { | ||
61 | cpp << endl; | 55 | cpp << '\n'; | ||
62 | } | 56 | } | ||
63 | 57 | | |||
64 | if (type == QLatin1String("UrlList")) { | 58 | if (type == QLatin1String("UrlList")) { | ||
65 | cpp << " QList<QUrl> default" << name << ";" << endl; | 59 | cpp << " QList<QUrl> default" << name << ";\n"; | ||
66 | } else { | 60 | } else { | ||
67 | cpp << " QStringList default" << name << ";" << endl; | 61 | cpp << " QStringList default" << name << ";\n"; | ||
68 | } | 62 | } | ||
69 | const QStringList defaults = defaultValue.split(QLatin1Char(',')); | 63 | const QStringList defaults = defaultValue.split(QLatin1Char(',')); | ||
70 | QStringList::ConstIterator it; | 64 | QStringList::ConstIterator it; | ||
71 | for (it = defaults.constBegin(); it != defaults.constEnd(); ++it) { | 65 | for (it = defaults.constBegin(); it != defaults.constEnd(); ++it) { | ||
72 | cpp << " default" << name << ".append( "; | 66 | cpp << " default" << name << ".append( "; | ||
73 | if (type == QLatin1String("UrlList")) { | 67 | if (type == QLatin1String("UrlList")) { | ||
74 | cpp << "QUrl::fromUserInput("; | 68 | cpp << "QUrl::fromUserInput("; | ||
75 | } | 69 | } | ||
76 | cpp << "QString::fromUtf8( \"" << *it << "\" ) "; | 70 | cpp << "QString::fromUtf8( \"" << *it << "\" ) "; | ||
77 | if (type == QLatin1String("UrlList")) { | 71 | if (type == QLatin1String("UrlList")) { | ||
78 | cpp << ") "; | 72 | cpp << ") "; | ||
79 | } | 73 | } | ||
80 | cpp << ");" << endl; | 74 | cpp << ");\n"; | ||
81 | } | 75 | } | ||
82 | defaultValue = QLatin1String("default") + name; | 76 | defaultValue = QLatin1String("default") + name; | ||
83 | 77 | | |||
84 | } else if (type == QLatin1String("Color") && !defaultValue.isEmpty()) { | 78 | } else if (type == QLatin1String("Color") && !defaultValue.isEmpty()) { | ||
85 | const QRegularExpression colorRe(QRegularExpression::anchoredPattern( | 79 | const QRegularExpression colorRe(QRegularExpression::anchoredPattern( | ||
86 | QStringLiteral("\\d+,\\s*\\d+,\\s*\\d+(,\\s*\\d+)?"))); | 80 | QStringLiteral("\\d+,\\s*\\d+,\\s*\\d+(,\\s*\\d+)?"))); | ||
87 | 81 | | |||
88 | if (colorRe.match(defaultValue).hasMatch()) { | 82 | if (colorRe.match(defaultValue).hasMatch()) { | ||
Show All 13 Lines | 91 | if ((*it).name == defaultValue) { | |||
102 | } | 96 | } | ||
103 | break; | 97 | break; | ||
104 | } | 98 | } | ||
105 | } | 99 | } | ||
106 | 100 | | |||
107 | } else if (type == QLatin1String("IntList")) { | 101 | } else if (type == QLatin1String("IntList")) { | ||
108 | QTextStream cpp(&code, QIODevice::WriteOnly | QIODevice::Append); | 102 | QTextStream cpp(&code, QIODevice::WriteOnly | QIODevice::Append); | ||
109 | if (!code.isEmpty()) { | 103 | if (!code.isEmpty()) { | ||
110 | cpp << endl; | 104 | cpp << '\n'; | ||
111 | } | 105 | } | ||
112 | 106 | | |||
113 | cpp << " QList<int> default" << name << ";" << endl; | 107 | cpp << " QList<int> default" << name << ";\n"; | ||
114 | if (!defaultValue.isEmpty()) { | 108 | if (!defaultValue.isEmpty()) { | ||
115 | const QStringList defaults = defaultValue.split(QLatin1Char(',')); | 109 | const QStringList defaults = defaultValue.split(QLatin1Char(',')); | ||
116 | QStringList::ConstIterator it; | 110 | QStringList::ConstIterator it; | ||
117 | for (it = defaults.constBegin(); it != defaults.constEnd(); ++it) { | 111 | for (it = defaults.constBegin(); it != defaults.constEnd(); ++it) { | ||
118 | cpp << " default" << name << ".append( " << *it << " );" | 112 | cpp << " default" << name << ".append( " << *it << " );\n"; | ||
119 | << endl; | | |||
120 | } | 113 | } | ||
121 | } | 114 | } | ||
122 | defaultValue = QLatin1String("default") + name; | 115 | defaultValue = QLatin1String("default") + name; | ||
123 | } | 116 | } | ||
124 | } | 117 | } | ||
125 | 118 | | |||
126 | static QString dumpNode(const QDomNode &node) | 119 | static QString dumpNode(const QDomNode &node) | ||
127 | { | 120 | { | ||
Show All 9 Lines | |||||
137 | } | 130 | } | ||
138 | 131 | | |||
139 | void KConfigXmlParser::readParameterFromEntry(CfgEntry &readEntry, const QDomElement &e) | 132 | void KConfigXmlParser::readParameterFromEntry(CfgEntry &readEntry, const QDomElement &e) | ||
140 | { | 133 | { | ||
141 | readEntry.param = e.attribute(QStringLiteral("name")); | 134 | readEntry.param = e.attribute(QStringLiteral("name")); | ||
142 | readEntry.paramType = e.attribute(QStringLiteral("type")); | 135 | readEntry.paramType = e.attribute(QStringLiteral("type")); | ||
143 | 136 | | |||
144 | if (readEntry.param.isEmpty()) { | 137 | if (readEntry.param.isEmpty()) { | ||
145 | cerr << "Parameter must have a name: " << dumpNode(e) << endl; | 138 | std::cerr << "Parameter must have a name: " << qPrintable(dumpNode(e)) << std::endl; | ||
146 | exit (1); | 139 | exit (1); | ||
147 | } | 140 | } | ||
148 | 141 | | |||
149 | if (readEntry.paramType.isEmpty()) { | 142 | if (readEntry.paramType.isEmpty()) { | ||
150 | cerr << "Parameter must have a type: " << dumpNode(e) << endl; | 143 | std::cerr << "Parameter must have a type: " << qPrintable(dumpNode(e)) << std::endl; | ||
151 | exit(1); | 144 | exit(1); | ||
152 | } | 145 | } | ||
153 | 146 | | |||
154 | if ((readEntry.paramType == QLatin1String("Int")) || (readEntry.paramType == QLatin1String("UInt"))) { | 147 | if ((readEntry.paramType == QLatin1String("Int")) || (readEntry.paramType == QLatin1String("UInt"))) { | ||
155 | bool ok; | 148 | bool ok; | ||
156 | readEntry.paramMax = e.attribute(QStringLiteral("max")).toInt(&ok); | 149 | readEntry.paramMax = e.attribute(QStringLiteral("max")).toInt(&ok); | ||
157 | if (!ok) { | 150 | if (!ok) { | ||
158 | cerr << "Integer parameter must have a maximum (e.g. max=\"0\"): " << dumpNode(e) << endl; | 151 | std::cerr << "Integer parameter must have a maximum (e.g. max=\"0\"): " << qPrintable(dumpNode(e)) << std::endl; | ||
159 | exit(1); | 152 | exit(1); | ||
160 | } | 153 | } | ||
161 | } else if (readEntry.paramType == QLatin1String("Enum")) { | 154 | } else if (readEntry.paramType == QLatin1String("Enum")) { | ||
162 | for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) { | 155 | for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) { | ||
163 | if (e2.tagName() == QLatin1String("values")) { | 156 | if (e2.tagName() == QLatin1String("values")) { | ||
164 | for (QDomElement e3 = e2.firstChildElement(); !e3.isNull(); e3 = e3.nextSiblingElement()) { | 157 | for (QDomElement e3 = e2.firstChildElement(); !e3.isNull(); e3 = e3.nextSiblingElement()) { | ||
165 | if (e3.tagName() == QLatin1String("value")) { | 158 | if (e3.tagName() == QLatin1String("value")) { | ||
166 | readEntry.paramValues.append(e3.text()); | 159 | readEntry.paramValues.append(e3.text()); | ||
167 | } | 160 | } | ||
168 | } | 161 | } | ||
169 | break; | 162 | break; | ||
170 | } | 163 | } | ||
171 | } | 164 | } | ||
172 | if (readEntry.paramValues.isEmpty()) { | 165 | if (readEntry.paramValues.isEmpty()) { | ||
173 | cerr << "No values specified for parameter '" << readEntry.param << "'." << endl; | 166 | std::cerr << "No values specified for parameter '" << qPrintable(readEntry.param) << "'." << std::endl; | ||
174 | exit(1); | 167 | exit(1); | ||
175 | } | 168 | } | ||
176 | readEntry.paramMax = readEntry.paramValues.count() - 1; | 169 | readEntry.paramMax = readEntry.paramValues.count() - 1; | ||
177 | } else { | 170 | } else { | ||
178 | cerr << "Parameter '" << readEntry.param << "' has type " << readEntry.paramType | 171 | std::cerr << "Parameter '" << qPrintable(readEntry.param) << "' has type " << qPrintable(readEntry.paramType) | ||
179 | << " but must be of type int, uint or Enum." << endl; | 172 | << " but must be of type int, uint or Enum." << std::endl; | ||
180 | exit(1); | 173 | exit(1); | ||
181 | } | 174 | } | ||
182 | } | 175 | } | ||
183 | 176 | | |||
184 | bool KConfigXmlParser::hasDefaultCode(CfgEntry &readEntry, const QDomElement &element) | 177 | bool KConfigXmlParser::hasDefaultCode(CfgEntry &readEntry, const QDomElement &element) | ||
185 | { | 178 | { | ||
186 | for (QDomElement e = element.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) { | 179 | for (QDomElement e = element.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) { | ||
187 | if (e.attribute(QStringLiteral("param")).isEmpty()) { | 180 | if (e.attribute(QStringLiteral("param")).isEmpty()) { | ||
Show All 11 Lines | 191 | { | |||
199 | QList<CfgEntry::Choice> chlist; | 192 | QList<CfgEntry::Choice> chlist; | ||
200 | for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) { | 193 | for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) { | ||
201 | if (e2.tagName() != QLatin1String("choice")) { | 194 | if (e2.tagName() != QLatin1String("choice")) { | ||
202 | continue; | 195 | continue; | ||
203 | } | 196 | } | ||
204 | CfgEntry::Choice choice; | 197 | CfgEntry::Choice choice; | ||
205 | choice.name = e2.attribute(QStringLiteral("name")); | 198 | choice.name = e2.attribute(QStringLiteral("name")); | ||
206 | if (choice.name.isEmpty()) { | 199 | if (choice.name.isEmpty()) { | ||
207 | cerr << "Tag <choice> requires attribute 'name'." << endl; | 200 | std::cerr << "Tag <choice> requires attribute 'name'." << std::endl; | ||
208 | } | 201 | } | ||
209 | for (QDomElement e3 = e2.firstChildElement(); !e3.isNull(); e3 = e3.nextSiblingElement()) { | 202 | for (QDomElement e3 = e2.firstChildElement(); !e3.isNull(); e3 = e3.nextSiblingElement()) { | ||
210 | if (e3.tagName() == QLatin1String("label")) { | 203 | if (e3.tagName() == QLatin1String("label")) { | ||
211 | choice.label = e3.text(); | 204 | choice.label = e3.text(); | ||
212 | choice.context = e3.attribute(QStringLiteral("context")); | 205 | choice.context = e3.attribute(QStringLiteral("context")); | ||
213 | } | 206 | } | ||
214 | if (e3.tagName() == QLatin1String("tooltip")) { | 207 | if (e3.tagName() == QLatin1String("tooltip")) { | ||
215 | choice.toolTip = e3.text(); | 208 | choice.toolTip = e3.text(); | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 262 | if (cfg.generateProperties && (cfg.allMutators || cfg.mutators.contains(readEntry.name))) { | |||
273 | readEntry.signalList.append(s); | 266 | readEntry.signalList.append(s); | ||
274 | } | 267 | } | ||
275 | } | 268 | } | ||
276 | 269 | | |||
277 | void KConfigXmlParser::validateNameAndKey(CfgEntry &readEntry, const QDomElement &element) | 270 | void KConfigXmlParser::validateNameAndKey(CfgEntry &readEntry, const QDomElement &element) | ||
278 | { | 271 | { | ||
279 | bool nameIsEmpty = readEntry.name.isEmpty(); | 272 | bool nameIsEmpty = readEntry.name.isEmpty(); | ||
280 | if (nameIsEmpty && readEntry.key.isEmpty()) { | 273 | if (nameIsEmpty && readEntry.key.isEmpty()) { | ||
281 | cerr << "Entry must have a name or a key: " << dumpNode(element) << endl; | 274 | std::cerr << "Entry must have a name or a key: " << qPrintable(dumpNode(element)) << std::endl; | ||
282 | exit (1); | 275 | exit (1); | ||
283 | } | 276 | } | ||
284 | 277 | | |||
285 | if (readEntry.key.isEmpty()) { | 278 | if (readEntry.key.isEmpty()) { | ||
286 | readEntry.key = readEntry.name; | 279 | readEntry.key = readEntry.name; | ||
287 | } | 280 | } | ||
288 | 281 | | |||
289 | if (nameIsEmpty) { | 282 | if (nameIsEmpty) { | ||
290 | readEntry.name = readEntry.key; | 283 | readEntry.name = readEntry.key; | ||
291 | readEntry.name.remove(QLatin1Char(' ')); | 284 | readEntry.name.remove(QLatin1Char(' ')); | ||
292 | } else if (readEntry.name.contains(QLatin1Char(' '))) { | 285 | } else if (readEntry.name.contains(QLatin1Char(' '))) { | ||
293 | cout << "Entry '" << readEntry.name << "' contains spaces! <name> elements can not contain spaces!" << endl; | 286 | std::cout << "Entry '" << qPrintable(readEntry.name) << "' contains spaces! <name> elements can not contain spaces!" << std::endl; | ||
294 | readEntry.name.remove(QLatin1Char(' ')); | 287 | readEntry.name.remove(QLatin1Char(' ')); | ||
295 | } | 288 | } | ||
296 | 289 | | |||
297 | if (readEntry.name.contains(QStringLiteral("$("))) { | 290 | if (readEntry.name.contains(QStringLiteral("$("))) { | ||
298 | if (readEntry.param.isEmpty()) { | 291 | if (readEntry.param.isEmpty()) { | ||
299 | cerr << "Name may not be parameterized: " << readEntry.name << endl; | 292 | std::cerr << "Name may not be parameterized: " << qPrintable(readEntry.name) << std::endl; | ||
300 | exit (1); | 293 | exit (1); | ||
301 | } | 294 | } | ||
302 | } else { | 295 | } else { | ||
303 | if (!readEntry.param.isEmpty()) { | 296 | if (!readEntry.param.isEmpty()) { | ||
304 | cerr << "Name must contain '$(" << readEntry.param << ")': " << readEntry.name << endl; | 297 | std::cerr << "Name must contain '$(" << qPrintable(readEntry.param) << ")': " << qPrintable(readEntry.name) << std::endl; | ||
305 | exit (1); | 298 | exit (1); | ||
306 | } | 299 | } | ||
307 | } | 300 | } | ||
308 | } | 301 | } | ||
309 | 302 | | |||
310 | void KConfigXmlParser::readParamDefaultValues(CfgEntry &readEntry, const QDomElement &element) | 303 | void KConfigXmlParser::readParamDefaultValues(CfgEntry &readEntry, const QDomElement &element) | ||
311 | { | 304 | { | ||
312 | if (readEntry.param.isEmpty()) { | 305 | if (readEntry.param.isEmpty()) { | ||
Show All 18 Lines | 323 | if (index.isEmpty()) { | |||
331 | continue; | 324 | continue; | ||
332 | } | 325 | } | ||
333 | 326 | | |||
334 | bool ok; | 327 | bool ok; | ||
335 | int i = index.toInt(&ok); | 328 | int i = index.toInt(&ok); | ||
336 | if (!ok) { | 329 | if (!ok) { | ||
337 | i = readEntry.paramValues.indexOf(index); | 330 | i = readEntry.paramValues.indexOf(index); | ||
338 | if (i == -1) { | 331 | if (i == -1) { | ||
339 | cerr << "Index '" << index << "' for default value is unknown." << endl; | 332 | std::cerr << "Index '" << qPrintable(index) << "' for default value is unknown." << std::endl; | ||
340 | exit (1); | 333 | exit (1); | ||
341 | } | 334 | } | ||
342 | } | 335 | } | ||
343 | 336 | | |||
344 | if ((i < 0) || (i > readEntry.paramMax)) { | 337 | if ((i < 0) || (i > readEntry.paramMax)) { | ||
345 | cerr << "Index '" << i << "' for default value is out of range [0, " << readEntry.paramMax << "]." << endl; | 338 | std::cerr << "Index '" << i << "' for default value is out of range [0, " << readEntry.paramMax << "]." << std::endl; | ||
346 | exit (1); | 339 | exit (1); | ||
347 | } | 340 | } | ||
348 | 341 | | |||
349 | QString tmpDefaultValue = e.text(); | 342 | QString tmpDefaultValue = e.text(); | ||
350 | 343 | | |||
351 | if (e.attribute(QStringLiteral("code")) != QLatin1String("true")) { | 344 | if (e.attribute(QStringLiteral("code")) != QLatin1String("true")) { | ||
352 | preProcessDefault(tmpDefaultValue, readEntry.name, readEntry.type, readEntry.choices, readEntry.code, cfg); | 345 | preProcessDefault(tmpDefaultValue, readEntry.name, readEntry.type, readEntry.choices, readEntry.code, cfg); | ||
353 | } | 346 | } | ||
Show All 25 Lines | 353 | { | |||
379 | if (readEntry.type.isEmpty()) { | 372 | if (readEntry.type.isEmpty()) { | ||
380 | readEntry.type = QStringLiteral("String"); // XXX : implicit type might be bad | 373 | readEntry.type = QStringLiteral("String"); // XXX : implicit type might be bad | ||
381 | } | 374 | } | ||
382 | 375 | | |||
383 | readParamDefaultValues(readEntry, element); | 376 | readParamDefaultValues(readEntry, element); | ||
384 | 377 | | |||
385 | if (!mValidNameRegexp.match(readEntry.name).hasMatch()) { | 378 | if (!mValidNameRegexp.match(readEntry.name).hasMatch()) { | ||
386 | if (nameIsEmpty) | 379 | if (nameIsEmpty) | ||
387 | cerr << "The key '" << readEntry.key << "' can not be used as name for the entry because " | 380 | std::cerr << "The key '" << qPrintable(readEntry.key) << "' can not be used as name for the entry because " | ||
388 | "it is not a valid name. You need to specify a valid name for this entry." << endl; | 381 | "it is not a valid name. You need to specify a valid name for this entry." << std::endl; | ||
389 | else { | 382 | else { | ||
390 | cerr << "The name '" << readEntry.name << "' is not a valid name for an entry." << endl; | 383 | std::cerr << "The name '" << qPrintable(readEntry.name) << "' is not a valid name for an entry." << std::endl; | ||
391 | } | 384 | } | ||
392 | exit (1); | 385 | exit (1); | ||
393 | } | 386 | } | ||
394 | 387 | | |||
395 | if (mAllNames.contains(readEntry.name)) { | 388 | if (mAllNames.contains(readEntry.name)) { | ||
396 | if (nameIsEmpty) | 389 | if (nameIsEmpty) | ||
397 | cerr << "The key '" << readEntry.key << "' can not be used as name for the entry because " | 390 | std::cerr << "The key '" << qPrintable(readEntry.key) << "' can not be used as name for the entry because " | ||
398 | "it does not result in a unique name. You need to specify a unique name for this entry." << endl; | 391 | "it does not result in a unique name. You need to specify a unique name for this entry." << std::endl; | ||
399 | else { | 392 | else { | ||
400 | cerr << "The name '" << readEntry.name << "' is not unique." << endl; | 393 | std::cerr << "The name '" << qPrintable(readEntry.name) << "' is not unique." << std::endl; | ||
401 | } | 394 | } | ||
402 | exit (1); | 395 | exit (1); | ||
403 | } | 396 | } | ||
404 | 397 | | |||
405 | mAllNames.append(readEntry.name); | 398 | mAllNames.append(readEntry.name); | ||
406 | 399 | | |||
407 | if (!hasDefaultCode(readEntry, element)) { | 400 | if (!hasDefaultCode(readEntry, element)) { | ||
408 | // TODO: Move all the options to CfgEntry. | 401 | // TODO: Move all the options to CfgEntry. | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
452 | void KConfigXmlParser::start() | 445 | void KConfigXmlParser::start() | ||
453 | { | 446 | { | ||
454 | QFile input(mInputFileName); | 447 | QFile input(mInputFileName); | ||
455 | QDomDocument doc; | 448 | QDomDocument doc; | ||
456 | QString errorMsg; | 449 | QString errorMsg; | ||
457 | int errorRow; | 450 | int errorRow; | ||
458 | int errorCol; | 451 | int errorCol; | ||
459 | if (!doc.setContent(&input, &errorMsg, &errorRow, &errorCol)) { | 452 | if (!doc.setContent(&input, &errorMsg, &errorRow, &errorCol)) { | ||
460 | cerr << "Unable to load document." << endl; | 453 | std::cerr << "Unable to load document." << std::endl; | ||
461 | cerr << "Parse error in " << mInputFileName << ", line " << errorRow << ", col " << errorCol << ": " << errorMsg << endl; | 454 | std::cerr << "Parse error in " << qPrintable(mInputFileName) << ", line " << errorRow << ", col " << errorCol << ": " << qPrintable(errorMsg) << std::endl; | ||
462 | exit (1); | 455 | exit (1); | ||
463 | } | 456 | } | ||
464 | 457 | | |||
465 | QDomElement cfgElement = doc.documentElement(); | 458 | QDomElement cfgElement = doc.documentElement(); | ||
466 | if (cfgElement.isNull()) { | 459 | if (cfgElement.isNull()) { | ||
467 | cerr << "No document in kcfg file" << endl; | 460 | std::cerr << "No document in kcfg file" << std::endl; | ||
468 | exit (1); | 461 | exit (1); | ||
469 | } | 462 | } | ||
470 | 463 | | |||
471 | for (QDomElement element = cfgElement.firstChildElement(); !element.isNull(); element = element.nextSiblingElement()) { | 464 | for (QDomElement element = cfgElement.firstChildElement(); !element.isNull(); element = element.nextSiblingElement()) { | ||
472 | QString tag = element.tagName(); | 465 | QString tag = element.tagName(); | ||
473 | 466 | | |||
474 | if (tag == QLatin1String("include")) { | 467 | if (tag == QLatin1String("include")) { | ||
475 | readIncludeTag(element); | 468 | readIncludeTag(element); | ||
Show All 19 Lines | 487 | if (!includeFile.isEmpty()) { | |||
495 | mParseResult.includes.append(includeFile); | 488 | mParseResult.includes.append(includeFile); | ||
496 | } | 489 | } | ||
497 | } | 490 | } | ||
498 | 491 | | |||
499 | void KConfigXmlParser::readGroupTag(const QDomElement &e) | 492 | void KConfigXmlParser::readGroupTag(const QDomElement &e) | ||
500 | { | 493 | { | ||
501 | QString group = e.attribute(QStringLiteral("name")); | 494 | QString group = e.attribute(QStringLiteral("name")); | ||
502 | if (group.isEmpty()) { | 495 | if (group.isEmpty()) { | ||
503 | cerr << "Group without name" << endl; | 496 | std::cerr << "Group without name" << std::endl; | ||
504 | exit (1); | 497 | exit (1); | ||
505 | } | 498 | } | ||
506 | 499 | | |||
507 | for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) { | 500 | for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) { | ||
508 | if (e2.tagName() != QLatin1String("entry")) { | 501 | if (e2.tagName() != QLatin1String("entry")) { | ||
509 | continue; | 502 | continue; | ||
510 | } | 503 | } | ||
511 | CfgEntry *entry = parseEntry(group, e2); | 504 | CfgEntry *entry = parseEntry(group, e2); | ||
512 | if (entry) { | 505 | if (entry) { | ||
513 | mParseResult.entries.append(entry); | 506 | mParseResult.entries.append(entry); | ||
514 | } else { | 507 | } else { | ||
515 | cerr << "Can not parse entry." << endl; | 508 | std::cerr << "Can not parse entry." << std::endl; | ||
516 | exit (1); | 509 | exit (1); | ||
517 | } | 510 | } | ||
518 | } | 511 | } | ||
519 | } | 512 | } | ||
520 | 513 | | |||
521 | void KConfigXmlParser::readKcfgfileTag(const QDomElement &e) | 514 | void KConfigXmlParser::readKcfgfileTag(const QDomElement &e) | ||
522 | { | 515 | { | ||
523 | mParseResult.cfgFileName = e.attribute(QStringLiteral("name")); | 516 | mParseResult.cfgFileName = e.attribute(QStringLiteral("name")); | ||
Show All 10 Lines | 518 | for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) { | |||
534 | } | 527 | } | ||
535 | } | 528 | } | ||
536 | } | 529 | } | ||
537 | 530 | | |||
538 | void KConfigXmlParser::readSignalTag(const QDomElement &e) | 531 | void KConfigXmlParser::readSignalTag(const QDomElement &e) | ||
539 | { | 532 | { | ||
540 | QString signalName = e.attribute(QStringLiteral("name")); | 533 | QString signalName = e.attribute(QStringLiteral("name")); | ||
541 | if (signalName.isEmpty()) { | 534 | if (signalName.isEmpty()) { | ||
542 | cerr << "Signal without name." << endl; | 535 | std::cerr << "Signal without name." << std::endl; | ||
543 | exit (1); | 536 | exit (1); | ||
544 | } | 537 | } | ||
545 | Signal theSignal; | 538 | Signal theSignal; | ||
546 | theSignal.name = signalName; | 539 | theSignal.name = signalName; | ||
547 | 540 | | |||
548 | for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) { | 541 | for (QDomElement e2 = e.firstChildElement(); !e2.isNull(); e2 = e2.nextSiblingElement()) { | ||
549 | if (e2.tagName() == QLatin1String("argument")) { | 542 | if (e2.tagName() == QLatin1String("argument")) { | ||
550 | Param argument; | 543 | Param argument; | ||
551 | argument.type = e2.attribute(QStringLiteral("type")); | 544 | argument.type = e2.attribute(QStringLiteral("type")); | ||
552 | if (argument.type.isEmpty()) { | 545 | if (argument.type.isEmpty()) { | ||
553 | cerr << "Signal argument without type." << endl; | 546 | std::cerr << "Signal argument without type." << std::endl; | ||
554 | exit (1); | 547 | exit (1); | ||
555 | } | 548 | } | ||
556 | argument.name= e2.text(); | 549 | argument.name= e2.text(); | ||
557 | theSignal.arguments.append(argument); | 550 | theSignal.arguments.append(argument); | ||
558 | } else if (e2.tagName() == QLatin1String("label")) { | 551 | } else if (e2.tagName() == QLatin1String("label")) { | ||
559 | theSignal.label = e2.text(); | 552 | theSignal.label = e2.text(); | ||
560 | } | 553 | } | ||
561 | } | 554 | } | ||
562 | 555 | | |||
563 | mParseResult.signalList.append(theSignal); | 556 | mParseResult.signalList.append(theSignal); | ||
564 | } | 557 | } |