| 307 | } |
| 308 | |
| 309 | QVector<SourceFileTemplate::ConfigOptionGroup> SourceFileTemplate::customOptions(TemplateRenderer* renderer) const |
| 310 | { |
| 311 | Q_D(const SourceFileTemplate); |
| 312 | |
| 313 | Q_ASSERT(isValid()); |
| 314 | |
| 315 | KConfig templateConfig(d->descriptionFileName); |
| 316 | KConfigGroup cg(&templateConfig, QStringLiteral("General")); |
| 317 | const KArchiveEntry* entry = d->archive->directory()->entry(cg.readEntry("OptionsFile", "options.kcfg")); |
| 318 | |
| 319 | QVector<ConfigOptionGroup> optionGroups; |
| 320 | |
| 321 | if (!entry->isFile()) { |
| 322 | return optionGroups; |
| 323 | } |
| 324 | const auto* file = static_cast<const KArchiveFile*>(entry); |
| 325 | |
| 326 | /* |
| 327 | * Copied from kconfig_compiler.kcfg |
| 328 | */ |
| 329 | QDomDocument doc; |
| 330 | QString errorMsg; |
| 331 | int errorRow; |
| 332 | int errorCol; |
| 333 | if (!doc.setContent(file->data(), &errorMsg, &errorRow, &errorCol)) { |
| 334 | qCDebug(LANGUAGE) << "Unable to load document."; |
| 335 | qCDebug(LANGUAGE) << "Parse error in line " << errorRow << ", col " << errorCol << ": " << errorMsg; |
| 336 | return optionGroups; |
| 337 | } |
| 338 | |
| 339 | QDomElement cfgElement = doc.documentElement(); |
| 340 | if (cfgElement.isNull()) { |
| 341 | qCDebug(LANGUAGE) << "No document in kcfg file"; |
| 342 | return optionGroups; |
| 343 | } |
| 344 | |
| 345 | QDomNodeList groups = cfgElement.elementsByTagName(QStringLiteral("group")); |
| 346 | optionGroups.reserve(groups.size()); |
| 347 | for (int i = 0; i < groups.size(); ++i) { |
| 348 | QDomElement group = groups.at(i).toElement(); |
| 349 | ConfigOptionGroup optionGroup; |
| 350 | optionGroup.name = group.attribute(QStringLiteral("name")); |
| 351 | |
| 352 | QDomNodeList entries = group.elementsByTagName(QStringLiteral("entry")); |
| 353 | optionGroup.options.reserve(entries.size()); |
| 354 | for (int j = 0; j < entries.size(); ++j) { |
| 355 | QDomElement entry = entries.at(j).toElement(); |
| 356 | optionGroup.options << d->readEntry(entry, renderer); |
| 357 | } |
| 358 | |
| 359 | optionGroups << optionGroup; |
| 360 | } |
| 361 | |
| 362 | return optionGroups; |
| 363 | } |
| 364 | |
| 365 | void SourceFileTemplate::addAdditionalSearchLocation(const QString& location) |
| 366 | { |