KConfig

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

KDE's Doxygen guidelines are available online.