1/*
2 This file is part of the KDE libraries.
3
4 SPDX-FileCopyrightText: 2003 Cornelius Schumacher <schumacher@kde.org>
5 SPDX-FileCopyrightText: 2003 Waldo Bastian <bastian@kde.org>
6 SPDX-FileCopyrightText: 2003 Zack Rusin <zack@kde.org>
7 SPDX-FileCopyrightText: 2006 Michaƫl Larouche <michael.larouche@kdemail.net>
8 SPDX-FileCopyrightText: 2008 Allen Winter <winter@kde.org>
9 SPDX-FileCopyrightText: 2020 Tomaz Cananbrava <tcanabrava@kde.org>
10
11 SPDX-License-Identifier: LGPL-2.0-or-later
12*/
13
14#include "KConfigParameters.h"
15
16#include <QDebug>
17#include <QFileInfo>
18
19#include <iostream>
20
21KConfigParameters::KConfigParameters(const QString &codegenFilename)
22{
23 if (!codegenFilename.endsWith(s: QLatin1String(".kcfgc"))) {
24 std::cerr << "Codegen options file must have extension .kcfgc" << std::endl;
25 exit(status: 1);
26 }
27
28 baseName = QFileInfo(codegenFilename).fileName();
29 baseName = baseName.left(n: baseName.length() - 6);
30
31 // Configure the compiler with some settings
32 QSettings codegenConfig(codegenFilename, QSettings::IniFormat);
33
34 nameSpace = codegenConfig.value(QStringLiteral("NameSpace")).toString();
35 className = codegenConfig.value(QStringLiteral("ClassName")).toString();
36 if (className.isEmpty()) {
37 std::cerr << "Class name missing" << std::endl;
38 exit(status: 1);
39 }
40 inherits = codegenConfig.value(QStringLiteral("Inherits")).toString();
41 if (inherits.isEmpty()) {
42 inherits = QStringLiteral("KConfigSkeleton");
43 }
44 visibility = codegenConfig.value(QStringLiteral("Visibility")).toString();
45 if (!visibility.isEmpty()) {
46 visibility += QLatin1Char(' ');
47 }
48 parentInConstructor = codegenConfig.value(QStringLiteral("ParentInConstructor"), defaultValue: false).toBool();
49 forceStringFilename = codegenConfig.value(QStringLiteral("ForceStringFilename"), defaultValue: false).toBool();
50 singleton = codegenConfig.value(QStringLiteral("Singleton"), defaultValue: false).toBool();
51 staticAccessors = singleton;
52 customAddons = codegenConfig.value(QStringLiteral("CustomAdditions"), defaultValue: false).toBool();
53 memberVariables = codegenConfig.value(QStringLiteral("MemberVariables")).toString();
54 dpointer = (memberVariables == QLatin1String("dpointer"));
55 headerIncludes = codegenConfig.value(QStringLiteral("IncludeFiles"), defaultValue: QStringList()).toStringList();
56 sourceIncludes = codegenConfig.value(QStringLiteral("SourceIncludeFiles"), defaultValue: QStringList()).toStringList();
57 mutators = codegenConfig.value(QStringLiteral("Mutators"), defaultValue: QStringList()).toStringList();
58 allMutators = ((mutators.count() == 1) && (mutators.at(i: 0).toLower() == QLatin1String("true")));
59 itemAccessors = codegenConfig.value(QStringLiteral("ItemAccessors"), defaultValue: false).toBool();
60 setUserTexts = codegenConfig.value(QStringLiteral("SetUserTexts"), defaultValue: false).toBool();
61 defaultGetters = codegenConfig.value(QStringLiteral("DefaultValueGetters"), defaultValue: QStringList()).toStringList();
62 allDefaultGetters = (defaultGetters.count() == 1) && (defaultGetters.at(i: 0).toLower() == QLatin1String("true"));
63 notifiers = codegenConfig.value(QStringLiteral("Notifiers"), defaultValue: QStringList()).toStringList();
64 allNotifiers = ((notifiers.count() == 1) && (notifiers.at(i: 0).toLower() == QLatin1String("true")));
65 globalEnums = codegenConfig.value(QStringLiteral("GlobalEnums"), defaultValue: false).toBool();
66 useEnumTypes = codegenConfig.value(QStringLiteral("UseEnumTypes"), defaultValue: false).toBool();
67 const QString trString = codegenConfig.value(QStringLiteral("TranslationSystem")).toString().toLower();
68 generateProperties = codegenConfig.value(QStringLiteral("GenerateProperties"), defaultValue: false).toBool();
69 if (trString == QLatin1String("kde")) {
70 translationSystem = KdeTranslation;
71 translationDomain = codegenConfig.value(QStringLiteral("TranslationDomain")).toString();
72 } else {
73 if (!trString.isEmpty() && trString != QLatin1String("qt")) {
74 std::cerr << "Unknown translation system, falling back to Qt tr()" << std::endl;
75 }
76 translationSystem = QtTranslation;
77 }
78 qCategoryLoggingName = codegenConfig.value(QStringLiteral("CategoryLoggingName"), defaultValue: QString()).toString();
79 headerExtension = codegenConfig.value(QStringLiteral("HeaderExtension"), QStringLiteral("h")).toString();
80}
81

source code of kconfig/src/kconfig_compiler/KConfigParameters.cpp