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#ifndef KCONFIGCOMMONSTRUCTS_H
15#define KCONFIGCOMMONSTRUCTS_H
16
17#include <QList>
18#include <QString>
19
20#include "KConfigParameters.h"
21
22struct Param {
23 QString name;
24 QString type;
25};
26
27struct Signal {
28 QString name;
29 QString label;
30 QList<Param> arguments;
31 bool modify = false;
32};
33
34class CfgEntry
35{
36public:
37 struct Choice {
38 QString name;
39 QString context;
40 QString label;
41 QString toolTip;
42 QString whatsThis;
43 QString val;
44
45 QString value() const
46 {
47 return !val.isEmpty() ? val : name;
48 }
49 };
50 class Choices
51 {
52 public:
53 Choices()
54 {
55 }
56 Choices(const QList<Choice> &d, const QString &n, const QString &p)
57 : prefix(p)
58 , choices(d)
59 , mName(n)
60 {
61 int i = n.indexOf(s: QLatin1String("::"));
62 if (i >= 0) {
63 mExternalQual = n.left(n: i + 2);
64 }
65 }
66 QString prefix;
67 QList<Choice> choices;
68 const QString &name() const
69 {
70 return mName;
71 }
72 const QString &externalQualifier() const
73 {
74 return mExternalQual;
75 }
76 bool external() const
77 {
78 return !mExternalQual.isEmpty();
79 }
80
81 private:
82 QString mName;
83 QString mExternalQual;
84 };
85
86public:
87 QString group;
88 QString parentGroup;
89 QString type;
90 QString key;
91 QString name;
92 QString labelContext;
93 QString label;
94 QString toolTipContext;
95 QString toolTip;
96 QString whatsThisContext;
97 QString whatsThis;
98 QString code;
99 QString defaultValue;
100 QString param;
101 QString paramName;
102 QString paramType;
103 Choices choices;
104 QList<Signal> signalList;
105 QStringList paramValues;
106 QStringList paramDefaultValues;
107 int paramMax;
108 bool hidden;
109 QString min;
110 QString max;
111};
112
113struct ParseResult {
114 QString cfgFileName;
115 bool cfgFileNameArg = false;
116 bool cfgStateConfig = false;
117 QList<Param> parameters;
118 QList<Signal> signalList;
119 QStringList includes;
120 QList<CfgEntry *> entries;
121 bool hasNonModifySignals = false;
122};
123
124// TODO: Move those methods
125QString enumName(const QString &n);
126QString enumName(const QString &n, const CfgEntry::Choices &c);
127QString param(const QString &t);
128QString cppType(const QString &t);
129QString itemType(const QString &type);
130QString changeSignalName(const QString &n);
131
132QString enumType(const CfgEntry *e, bool globalEnums);
133
134QString getDefaultFunction(const QString &n, const QString &className = QString());
135QString setFunction(const QString &n, const QString &className = QString());
136QString getFunction(const QString &n, const QString &className = QString());
137QString immutableFunction(const QString &n, const QString &className = QString());
138
139QString itemAccessorBody(const CfgEntry *e, const KConfigParameters &cfg);
140QString signalEnumName(const QString &signalName);
141
142bool isUnsigned(const QString &type);
143
144// returns the name of an member variable
145// use itemPath to know the full path
146// like using d-> in case of dpointer
147QString varName(const QString &n, const KConfigParameters &cfg);
148
149QString varPath(const QString &n, const KConfigParameters &cfg);
150
151// returns the name of an item variable
152// use itemPath to know the full path
153// like using d-> in case of dpointer
154QString itemVar(const CfgEntry *e, const KConfigParameters &cfg);
155
156// returns the name of the local inner item if there is one
157// (before wrapping with KConfigCompilerSignallingItem)
158// Otherwise return itemVar()
159QString innerItemVar(const CfgEntry *e, const KConfigParameters &cfg);
160
161QString itemPath(const CfgEntry *e, const KConfigParameters &cfg);
162
163QString filenameOnly(const QString &path);
164
165QString itemDeclaration(const CfgEntry *e, const KConfigParameters &cfg);
166
167QString translatedString(const KConfigParameters &cfg,
168 const QString &string,
169 const QString &context = QString(),
170 const QString &param = QString(),
171 const QString &paramValue = QString());
172
173// TODO: Sanitize those functions.
174QString newItem(const CfgEntry *entry, const QString &key, const QString &defaultValue, const KConfigParameters &cfg, const QString &param = QString());
175
176QString newInnerItem(const CfgEntry *entry, const QString &key, const QString &defaultValue, const KConfigParameters &cfg, const QString &param = QString());
177
178QString userTextsFunctions(const CfgEntry *e, const KConfigParameters &cfg, QString itemVarStr = QString(), const QString &i = QString());
179
180QString paramString(const QString &s, const CfgEntry *e, int i);
181QString paramString(const QString &group, const QList<Param> &parameters);
182
183QString defaultValue(const QString &t);
184QString memberGetDefaultBody(const CfgEntry *e);
185QString literalString(const QString &s);
186QString enumTypeQualifier(const QString &n, const CfgEntry::Choices &c);
187
188void addQuotes(QString &s);
189void addDebugMethod(QTextStream &out, const KConfigParameters &cfg, const QString &n);
190
191#endif
192

source code of kconfig/src/kconfig_compiler/KConfigCommonStructs.h