Warning, /frameworks/kconfig/src/kconfig_compiler/README.dox is written in an unsupported language. File is not indexed.

0001 /**
0002 \page kconfig_compiler The KDE Configuration Compiler
0003 
0004 kconfig_compiler generates C++ source code from an XML file containing
0005 information about configuration options (.kcfg) and a file that provides
0006 the code generation options (.kcfgc) The generated class is based on
0007 KConfigSkeleton and provides an API for the application to access its
0008 configuration data.
0009 
0010 The generated C++ source code is output to a .h and a .cpp file, whose base
0011 name is the same as that of the .kcfgc file.
0012 
0013 \section kcfg_format The .kcfg XML file format: description of the configuration skeleton
0014 
0015 The structure of the .kcfg file is described by its DTD kcfg.xsd.
0016 
0017 The \<kcfgfile\> tag may contain either the "name" attribute, which should be the name
0018 of the configuration file described, or the "arg" attribute, which, if set to
0019 "true", will allow you to pass the KSharedConfig::Ptr object to use.
0020 
0021 If neither "name" nor "arg" is set, the default configuration file
0022 ("\<appname\>rc") will be used.
0023 
0024 The \<include\> tags are optional and may contain C++ header files that
0025 are needed to compile the code needed to compute default values. To generate
0026 a \#include "..." statement instead of \#include \<...\>, enclose the header
0027 file name in double quotes (e.g. \<include\>"header.h"\</include\>).
0028 
0029 The remaining entries in the XML file are grouped by the tag \<group\>
0030 which describes the corresponding group in the configuration file.
0031 
0032 The individual entries must have at least a name or a key. The key is used
0033 as the key in the config file, while the name is used to create accessor and
0034 modifier functions. If \<key\> is given, but not \<name\>, the name is
0035 constructed by removing all spaces from \<key\>. If \<name\> is given, but
0036 not \<key\>, the key is the same as \<name\>.
0037 
0038 An entry must also have a type. The list of allowable types is
0039 specified in the DTD and loosely follows the list of types supported
0040 by the QVariant with exception of the clearly binary types
0041 (e.g. Pixmap, Image...) which are not supported. Besides those basic
0042 types the following special types are supported:
0043 
0044 <dl>
0045   <dt>Path</dt>
0046   <dd>
0047     This is a string that is specially treated as a file-path.
0048     In particular paths in the home directory are prefixed with $HOME in
0049     when being stored in the configuration file.
0050   </dd>
0051 
0052   <dt>Enum</dt>
0053   <dd>
0054     This indicates an enumeration. The possible enum values and optional
0055     enum name should be provided via the \<choices\> tag. Enum values are
0056     accessed as integers by the application but stored as strings in the
0057     configuration file. This makes it possible to add more values at a later
0058     date without breaking compatibility.
0059   </dd>
0060 
0061   <dt>IntList</dt>
0062   <dd>
0063     This indicates a list of integers. This information is provided
0064     to the application as QList<int>. Useful for storing QSplitter
0065     geometries.
0066   </dd>
0067 
0068   <dt>Color</dt>
0069   <dd>
0070     Isn't a special type but has special input. It is generated as QColor.
0071     Any valid input to QColor(QString) can be used (hex or SVG keyword notation)
0072     as well as a special format r,g,b,a where the a denotes the alpha channel and
0073     may be omitted.
0074   </dd>
0075 </dl>
0076 
0077 An entry can optionally have a default value which is used as default when
0078 the value isn't specified in any config file. Default values are interpreted
0079 as literal constant values. If a default value needs to be computed
0080 or if it needs to be obtained from a function call, the \<default\> tag
0081 should contain the code="true" attribute. The contents of the \<default\>
0082 tag is then considered to be a C++ expression. Note that in this case you
0083 might have to add an \<include\> tag as described above, or a
0084 SourceIncludeFiles entry in the .kcfgc file as described below, so that the
0085 code which computes the default value can be compiled.
0086 
0087 Additional code for computing default values can be provided outside any
0088 entry definition via the \<code\> tag. The contents of the \<code\> tag is
0089 inserted as-is. A typical use for this is to compute a common default value
0090 which can then be referenced by multiple entries that follow.
0091 
0092 \section kcfgc_format The .kcfgc file format: code generation options
0093 
0094 The options for generating the C++ sources are read from the file with the
0095 extension .kcfgc. To generate a class add the corresponding kcfgc file to the
0096 SOURCES line in the Makefile.am.
0097 
0098 The following options are read from the kcfgc file:
0099 
0100 
0101 <dl>
0102   <dt>File=\<string\></dt>
0103   <dd>
0104     Default: \<programname\>.kcfg \n
0105     Name of kcfg file containing the options the class is generated for
0106     <!-- what? -->
0107   </dd>
0108 
0109   <dt>HeaderExtension=\<string\></dt>
0110   <dd>
0111     Default: h \n
0112     Since KF 5.57 \n
0113     Extension to use for the name of the generated C++ header files.
0114   </dd>
0115 
0116   <dt>SourceExtension=\<string\></dt>
0117   <dd>
0118     Default: cpp \n
0119     Since KF 5.57 \n
0120     Extension to use for the name of the generated C++ source file.
0121   </dd>
0122 
0123   <dt>NameSpace=\<string\></dt>
0124   <dd>
0125     Optional namespace for generated class
0126   </dd>
0127 
0128   <dt>ClassName=\<string\></dt>
0129   <dd>
0130     Name of generated class (required)
0131   </dd>
0132 
0133   <dt>Inherits=\<string\></dt>
0134   <dd>
0135     Default: KConfigSkeleton \n
0136     Class the generated class inherits from.
0137 
0138     This class must inherit KConfigSkeleton and must provide a default
0139     constructor (kcfgfile not specified), a constructor taking a
0140     QString argument (kcfgfile with "name" attribute) and a constructor
0141     taking a KSharedConfig::Ptr as argument (kcfgfile with "arg" attribute).
0142     Please refer to the documentation of KConfigSkeleton.
0143   </dd>
0144 
0145   <dt>Visibility=\<string\></dt>
0146   <dd>
0147     Inserts visibility directive (for example KDE_EXPORT) between
0148     "class" keyword and class name in header file
0149   </dd>
0150 
0151   <dt>Singleton=\<bool\></dt>
0152   <dd>
0153     Default: false \n
0154     Generated class is a singleton.
0155   </dd>
0156 
0157   <dt>CustomAdditions=\<bool\></dt>
0158   <dd>
0159     <!-- what? -->
0160   </dd>
0161 
0162   <dt>MemberVariables=\<string\></dt>
0163   <dd>
0164     Values: public, protected, private, dpointer \n
0165     Default: private \n
0166     C++ access modifier used for member variables holding the configuration
0167     values
0168   </dd>
0169 
0170   <dt>IncludeFiles=\<string\>, \<string\> ...</dt>
0171   <dd>
0172     Names of files to be included in the header of the generated class.
0173 
0174     Enclose a file name in (escaped) double quotes to generate
0175     \#include "..." instead of \#include \<...\>.
0176   </dd>
0177 
0178   <dt>SourceIncludeFiles=\<string\>, \<string\> ...</dt>
0179   <dd>
0180     Names of files to be included in the source file of the generated class.
0181 
0182     Enclose a file name in (escaped) double quotes to generate
0183     \#include "..." instead of \#include \<...\>.
0184   </dd>
0185 
0186   <dt>Mutators=\<value\></dt>
0187   <dd>
0188     Values: true, false or a comma separated list of options \n
0189     Default: false \n
0190     If true, mutator functions for all configuration options are generated.
0191     If false, no mutator functions are generated. If a list is provided,
0192     mutator functions are generated for the options that are listed.
0193   </dd>
0194 
0195   <dt>Notifiers=\<value\></dt>
0196   <dd>
0197     Values: true, false or a comma separated list of options \n
0198     Default: false \n
0199     If true, entries will be written with the <b>Notify</b> flag enabled,
0200     so changes can be detected using <b>KConfigWatcher</b>.
0201     If a list is provided, the options that are listed are written with
0202     said flag.
0203   </dd>
0204 
0205   <dt>DefaultValueGetters=\<value\></dt>
0206   <dd>
0207     Values: true, false or a comma separated list of options \n
0208     Default: false \n
0209     If true, functions to return the default value of all configuration options
0210     are generated. If false, no default value functions are generated. If a list
0211     is provided, default value functions are generated for the options that are listed.
0212   </dd>
0213 
0214   <dt>ItemAccessors=\<bool\></dt>
0215   <dd>
0216     Default: false \n
0217     Generate accessor functions for the KConfigSkeletonItem objects
0218     corresponding to the configuration options. If <b>SetUserTexts</b> is set,
0219     <b>ItemAccessors</b> also has to be set.
0220   </dd>
0221 
0222   <dt>SetUserTexts=\<bool\></dt>
0223   <dd>
0224     Default: false \n
0225     Set the label and whatthis texts of the items from the kcfg file.
0226     If <b>SetUserTexts</b> is set, <b>ItemAccessors</b> also has to be set.
0227   </dd>
0228 
0229   <dt>GlobalEnums=\<bool\></dt>
0230   <dd>
0231     Default: false \n
0232     If set to true all choices of Enum items will be created in the global
0233     scope of the generated class. If set to false, each Enum item whose enum is not
0234     explicitly named will get its own namespace for its choices.
0235   </dd>
0236 
0237   <dt>UseEnumTypes=\<bool\></dt>
0238   <dd>
0239     Default: false \n
0240     If set to true, all Enum items whose enums are named will use enum types for
0241     the return value of accessor functions and for the parameter of mutator
0242     functions. This eliminates the need to cast accessor return values to the enum
0243     type if you want to use the enum type in your own code. If set to false,
0244     accessor return values and mutator parameters will be of type int.
0245   </dd>
0246 
0247   <dt>ForceStringFilename=\<bool\></dt>
0248   <dd>
0249     Default: false \n
0250     If set to true, forces the first parameter of the generated class
0251     to be a QString when using an argument for the filename.
0252     This is useful to specify at runtime the filename of the configuration class.
0253   </dd>
0254 
0255   <dt>GenerateProperties=\<bool\></dt>
0256   <dd>
0257     Default: false \n
0258     If set to true, a Q_PROPERTY will be generated for each member variable holding a
0259     configuration value and the Q_OBJECT macro will be added to the generated class.
0260     Note that you will also need to pass the GENERATE_MOC option to the
0261     kconfig_add_kcfg_files macro.
0262   </dd>
0263 
0264 
0265   <dt>ParentInConstructor=\<bool\></dt>
0266   <dd>
0267     Default: false \n
0268     If set to true, the generated constructor will take an additional QObject*
0269     parameter that will be used as the object's parent.
0270     This is useful when working with KQuickAddons::ManagedConfigModule
0271     to set it as the parent of the generated class to allow automatic
0272     settings discovery and handle the deallocation.
0273     Note this parameter is incompatible with <b>Singleton</b> set to true.
0274   </dd>
0275 
0276   <dt>TranslationSystem=\<string\></dt>
0277   <dd>
0278     Default: qt \n
0279     Set the translation system for label, tooltip and whatsthis text in generated KConfigSkeleton.
0280     Set the value to <b>kde</b> to use the KDE Framework translation system, see KI18n.
0281   </dd>
0282 
0283   <dt>TranslationDomain=\<value\></dt>
0284   <dd>
0285     When <b>TranslationSystem=kde</b> is set, allow to specify the domain in which to look for translations.
0286   </dd>
0287 
0288 </dl>
0289 
0290 
0291 \section entry_options Advanced entry options
0292 
0293 There are several possibilities to parameterize entries.
0294 
0295 \subsection parametrized_entries Parameterized entries
0296 
0297 An entry can be parameterized using a fixed range parameter specified with
0298 the \<parameter\> tag. Such parameter can either be an Enum or an int. An Enum
0299 parameter should specify the possible enumeration values with the \<choices\>
0300 tag. An int parameter should specify its maximum value. Its minimum value
0301 is always 0.
0302 
0303 A parameterized entry is expanded to a number of entries, one for each
0304 value in the parameter range. The name and key should contain a reference
0305 to the parameter in the form of $(parameter-name). When expanding the entries
0306 the $(parameter-name) part is replaced with the value of the parameter.
0307 In the case of an Enum parameter it is replaced with the name of the
0308 enumuration value. In the case of an int parameter it is replaced with
0309 the numeric value of the parameter.
0310 
0311 Parameterized entries all share the same default value unless different
0312 default values have been specified for specific parameter values.
0313 This can be done with the param= attribute of the \<default\>. When a
0314 param attribute is specified the default value only applies to that
0315 particular parameter value.
0316 
0317 Example 1:
0318 \code{.xml}
0319 <entry name="Color$(ColorIndex)" type="Color" key="color_$(ColorIndex)">
0320   <parameter name="ColorIndex" type="Int" max="3"/>
0321   <default param="0">#ff0000</default>
0322   <default param="1">#00ff00</default>
0323   <default param="2">#0000ff</default>
0324   <default param="3">#ffff00</default>
0325 </entry>
0326 \endcode
0327 
0328 The above describes 4 color configuration entries with the following defaults:
0329 
0330 \verbatim
0331 color_0=#ff0000
0332 color_1=#00ff00
0333 color_2=#0000ff
0334 color_3=#ffff00
0335 \endverbatim
0336 
0337 The configuration options will be accessible to the application via
0338 a QColor color(int ColorIndex) and a
0339 void setColor(int ColorIndex, const QColor &v) function.
0340 
0341 Example 2:
0342 \code{.xml}
0343 <entry name="Sound$(SoundEvent)" type="String" key="sound_$(SoundEvent)">
0344   <parameter name="SoundEvent" type="Enum">
0345     <values>
0346       <value>Explosion</value>
0347       <value>Crash</value>
0348       <value>Missile</value>
0349     </values>
0350   </parameter>
0351   <default param="Explosion">boom.wav</default>
0352   <default param="Crash">crash.wav</default>
0353   <default param="Missile">missile.wav</default>
0354 </entry>
0355 \endcode
0356 
0357 The above describes 3 string configuration entries with the following defaults:
0358 
0359 \verbatim
0360 sound_Explosion=boom.wav
0361 sound_Crash=crash.wav
0362 sound_Missile=missile.wav
0363 \endverbatim
0364 
0365 The configuration options will be accessible to the application via
0366 a QString sound(int SoundEvent) and a
0367 void setSound(int SoundEvent, const QString &v) function.
0368 
0369 \subsection parametrized_groups Parameterized groups
0370 
0371 A group name can be parametrized using a parameter given to the KConfigSkeleton
0372 instance (which means this feature cannot be used with singleton classes).
0373 
0374 Example 1:
0375 \code{.xml}
0376 <kcfgfile name="testrc">
0377   <parameter name="groupname"/>
0378 </kcfgfile>
0379 <group name="$(groupname)">
0380   <entry key="Text" type="string">
0381   </entry>
0382 </group>
0383 \endcode
0384 
0385 In this case passing "Group2" as the 'groupname' parameter to the generated class
0386 will make it use group "Group2" for the entry "Text".
0387 
0388 By setting the stateConfig attribute of kcfgfile to "true", KSharedConfig::openStateConfig is used.
0389 This should be used when one stores volatile data, like window sizes or autocompletion texts.
0390 It is recommended to have at least two separate kcfg files for the different kinds of data.
0391 NOTE: This option is ignored when ForceStringFilename is set.
0392 
0393 \subsection enums Enums
0394 
0395 By default, if <b>GlobalEnums</b> is set to false, a separate named enum will be generated
0396 for each Enum entry. Since each enum is defined in a little enclosing class of its own,
0397 this allows the same Enum value names to be used in different enums. For example, the
0398 .kcfg entry
0399 
0400 \code{.xml}
0401 <entry name="KeepData" type="Enum">
0402   <choices>
0403     <choice name="Do"/>
0404     <choice name="Dont" value="Don't"/>
0405   </choices>
0406 </entry>
0407 \endcode
0408 
0409 will generate this public class containing the enum definition, inside the generated class:
0410 
0411 \code{.cpp}
0412 class EnumKeepData
0413 {
0414   public:
0415   enum type { Do, Dont, COUNT };
0416 };
0417 \endcode
0418 
0419 Since 5.68, if present the <b>value</b> attribute will be used as the choice value written to the backend
0420 instead of the <b>name</b>, allowing to write text incompatible with enum naming.
0421 
0422 Alternatively, if <b>GlobalEnums</b> is set to true, all Enum items are defined as
0423 unnamed enums in the global scope of the generated class. In this case, all Enum values
0424 must have different names to avoid clashes. However, you can use a 'prefix' argument
0425 in \<choices\> to prevent duplicate enum member names clashing. Using this, the Enum value
0426 names are prefixed in code with the string you specify. For example, if <b>GlobalEnums</b>
0427 is set to true, the .kcfg entry
0428 
0429 \code{.xml}
0430 <entry name="KeepData" type="Enum">
0431   <choices prefix="Keep_">
0432     <choice name="Do"/>
0433     <choice name="Dont" value="Don't"/>
0434   </choices>
0435 </entry>
0436 \endcode
0437 
0438 will generate config file entries of "KeepData=Do" and "KeepData=Dont", but the enum
0439 will be declared
0440 
0441 \code{.cpp}
0442 enum { Keep_Do, Keep_Dont };
0443 \endcode
0444 
0445 It is possible to specify your own name for a generated enum, by including a
0446 'name' parameter in \<choices\>. Just like unnamed enums, this enum will be defined in
0447 the global scope of the generated class (without any enclosing class of its own).
0448 Therefore the names of Enum values must be unique across both unnamed enums (if
0449 <b>GlobalEnums</b> is set to true) and all specifically named enums.
0450 
0451 An example of a specifically named enum:
0452 
0453 \code{.xml}
0454 <entry name="KeepData" type="Enum">
0455   <choices name="Types">
0456     <choice name="Do"/>
0457     <choice name="Dont"/>
0458   </choices>
0459 </entry>
0460 \endcode
0461 
0462 which results in the following enum declaration, inside the generated class:
0463 
0464 \code{.cpp}
0465 enum Types { Do, Dont };
0466 \endcode
0467 
0468 It is also possible to specify the use of enums external to the generated class, by
0469 including the string "::" in the enum name - just ensure that it is sufficiently
0470 qualified to be unambiguous in use. To specify use of an unnamed enum, append a
0471 trailing "::". For example, to use the enum 'myEnum' defined in class ClassA, use
0472 either of
0473 
0474 \code{.xml}
0475 <choices name="ClassA::myEnum">
0476 <choices name="::ClassA::myEnum">
0477 \endcode
0478 
0479 To specify an unnamed enum in namespace ProgSpace, use
0480 
0481 \code{.xml}
0482 <choices name="ProgSpace::">
0483 \endcode
0484 
0485 To specify a top-level unnamed enum, use
0486 
0487 \code{.xml}
0488 <choices name="::">
0489 \endcode
0490 
0491 To specify the top-level enum 'anotherEnum', use
0492 
0493 \code{.xml}
0494 
0495 <choices name="::anotherEnum">
0496 \endcode
0497 
0498 
0499 \subsection notify_signals Notify signals
0500 
0501 An entry can emit a signal when it gets changed. First of all, you must
0502 define a list of signals for the configuration class. The signal's name may be
0503 any legal identifier you wish. The \<argument\> tag allows you to specify arguments
0504 for the emitted signal. It supports all types as defined in
0505 the KConfigXT DTD. The argument value must specify the name, without spaces, of one
0506 of the entries defined in the .kcfg file.
0507 A signal definition can also contain a \<label\> tag which will be
0508 the documentation line in the generated file.
0509 
0510 \code{.xml}
0511 <signal name="emoticonSettingsChanged" />
0512 
0513 <signal name="styleChanged">
0514   <label>Tell when a complete style change.</label>
0515   <argument type="String">stylePath</argument>
0516   <argument type="String">StyleCSSVariant</argument>
0517 </signal>
0518 \endcode
0519 
0520 After defining the signals, you must tell which signal to emit for the entry.
0521 A signal can be emitted by multiple entries. Also, you don't need to specify the arguments
0522 for a signal, the signal name will suffice.
0523 
0524 \code{.xml}
0525 <entry key="stylePath" type="String">
0526   <label>Absolute path to a directory containing a Adium/Kopete chat window style.</label>
0527   <emit signal="styleChanged" />
0528 </entry>
0529 \endcode
0530 
0531 The signal will be emitted when save() is called.
0532 
0533 @warning
0534 You must not call save() in direct response to any notify signal.
0535 If you need to call save(),
0536 use a QueuedConnection to listen to the notify signal.
0537 
0538 You can also listen to the generic configChanged() signal from KConfigSkeleton to
0539 notify your application about configuration changes.
0540 In that case you may also call save() in direct response.
0541 
0542 Note that you will also need to pass the GENERATE_MOC option to the kconfig_add_kcfg_files macro.
0543 
0544 \subsection translation_context Translation context
0545 
0546 In the kcfg file you can specify the translation's context for \<tooltip\>, \<whatsthis\> and \<label\> element for an entry.
0547 
0548 \code{.xml}
0549 <entry type="Bool" key="Auto Save">
0550   <label>Enable automatic saving of calendar</label>
0551   <whatsthis context="@info:whatsthis">Enable automatic saving of calendars to have calendars saved automatically.</whatsthis>
0552   <default>false</default>
0553 </entry>
0554 \endcode
0555 
0556 For more information on translation context and how to write good translatable text,
0557 please refer to https://api.kde.org/frameworks/ki18n/html/prg_guide.html
0558 
0559 */