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 | |
22 | struct Param { |
23 | QString name; |
24 | QString type; |
25 | }; |
26 | |
27 | struct Signal { |
28 | QString name; |
29 | QString label; |
30 | QList<Param> arguments; |
31 | bool modify = false; |
32 | }; |
33 | |
34 | class CfgEntry |
35 | { |
36 | public: |
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 | |
86 | public: |
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 | |
113 | struct 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 |
125 | QString enumName(const QString &n); |
126 | QString enumName(const QString &n, const CfgEntry::Choices &c); |
127 | QString param(const QString &t); |
128 | QString cppType(const QString &t); |
129 | QString itemType(const QString &type); |
130 | QString changeSignalName(const QString &n); |
131 | |
132 | QString enumType(const CfgEntry *e, bool globalEnums); |
133 | |
134 | QString getDefaultFunction(const QString &n, const QString &className = QString()); |
135 | QString setFunction(const QString &n, const QString &className = QString()); |
136 | QString getFunction(const QString &n, const QString &className = QString()); |
137 | QString immutableFunction(const QString &n, const QString &className = QString()); |
138 | |
139 | QString itemAccessorBody(const CfgEntry *e, const KConfigParameters &cfg); |
140 | QString signalEnumName(const QString &signalName); |
141 | |
142 | bool 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 |
147 | QString varName(const QString &n, const KConfigParameters &cfg); |
148 | |
149 | QString 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 |
154 | QString 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() |
159 | QString innerItemVar(const CfgEntry *e, const KConfigParameters &cfg); |
160 | |
161 | QString itemPath(const CfgEntry *e, const KConfigParameters &cfg); |
162 | |
163 | QString filenameOnly(const QString &path); |
164 | |
165 | QString itemDeclaration(const CfgEntry *e, const KConfigParameters &cfg); |
166 | |
167 | QString translatedString(const KConfigParameters &cfg, |
168 | const QString &string, |
169 | const QString &context = QString(), |
170 | const QString ¶m = QString(), |
171 | const QString ¶mValue = QString()); |
172 | |
173 | // TODO: Sanitize those functions. |
174 | QString (const CfgEntry *entry, const QString &key, const QString &defaultValue, const KConfigParameters &cfg, const QString ¶m = QString()); |
175 | |
176 | QString (const CfgEntry *entry, const QString &key, const QString &defaultValue, const KConfigParameters &cfg, const QString ¶m = QString()); |
177 | |
178 | QString userTextsFunctions(const CfgEntry *e, const KConfigParameters &cfg, QString itemVarStr = QString(), const QString &i = QString()); |
179 | |
180 | QString paramString(const QString &s, const CfgEntry *e, int i); |
181 | QString paramString(const QString &group, const QList<Param> ¶meters); |
182 | |
183 | QString defaultValue(const QString &t); |
184 | QString memberGetDefaultBody(const CfgEntry *e); |
185 | QString literalString(const QString &s); |
186 | QString enumTypeQualifier(const QString &n, const CfgEntry::Choices &c); |
187 | |
188 | void addQuotes(QString &s); |
189 | void addDebugMethod(QTextStream &out, const KConfigParameters &cfg, const QString &n); |
190 | |
191 | #endif |
192 | |