1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 parses <filename>.ini</filename>-like config files
7 <!-- ##### SECTION Long_Description ##### -->
9 #GKeyFile lets you parse, edit or create files containing groups of
10 key-value pairs, which we call <firstterm>key files</firstterm> for
11 lack of a better name. Several freedesktop.org specifications use
12 key files now, e.g the
13 <ulink url="http://freedesktop.org/Standards/desktop-entry-spec">Desktop
14 Entry Specification</ulink> and the
15 <ulink url="http://freedesktop.org/Standards/icon-theme-spec">Icon
16 Theme Specification</ulink>.
20 The syntax of key files is described in detail in the
21 <ulink url="http://freedesktop.org/Standards/desktop-entry-spec">Desktop
22 Entry Specification</ulink>, here is a quick summary: Key files
23 consists of groups of key-value pairs, interspersed with comments.
26 <informalexample><programlisting>
27 # this is just an example
28 # there can be comments before the first group
32 Name=Key File Example\tthis value shows\nescaping
34 # localized strings are stored in multiple key-value pairs
37 Welcome[fr_FR]=Bonjour
39 Welcome[be@latin]=Hello
45 Booleans=true;false;true;true
47 </programlisting></informalexample>
50 Lines beginning with a '#' and blank lines are considered comments.
54 Groups are started by a header line containing the group name enclosed
55 in '[' and ']', and ended implicitly by the start of the next group or
56 the end of the file. Each key-value pair must be contained in a group.
60 Key-value pairs generally have the form <literal>key=value</literal>,
61 with the exception of localized strings, which have the form
62 <literal>key[locale]=value</literal>, with a locale identifier of the form
63 <literal>lang_COUNTRY@MODIFIER</literal> where <literal>COUNTRY</literal> and
64 <literal>MODIFIER</literal> are optional. Space before and after the
65 '=' character are ignored. Newline, tab, carriage return and backslash
66 characters in value are escaped as \n, \t, \r, and \\, respectively.
67 To preserve leading spaces in values, these can also be escaped as \s.
71 Key files can store strings (possibly with localized variants), integers,
72 booleans and lists of these. Lists are separated by a separator character,
73 typically ';' or ','. To use the list separator character in a value in
74 a list, it has to be escaped by prefixing it with a backslash.
78 This syntax is obviously inspired by the <filename>.ini</filename>
79 files commonly met on Windows, but there are some important differences:
82 <filename>.ini</filename> files use the ';' character to begin comments,
83 key files use the '#' character.
86 Key files do not allow for ungrouped keys meaning only comments can precede the first group.
89 Key files are always encoded in UTF-8.
92 Key and Group names are case-sensitive, for example a group called
93 <literal>[GROUP]</literal> is a different group from <literal>[group]</literal>.
96 <filename>.ini</filename> files don't have a strongly typed boolean entry type, they only
97 have <literal>GetProfileInt</literal>. In <structname>GKeyFile</structname> only
98 <literal>true</literal> and <literal>false</literal> (in lower case) are allowed.
104 Note that in contrast to the
105 <ulink url="http://freedesktop.org/Standards/desktop-entry-spec">Desktop
106 Entry Specification</ulink>, groups in key files may contain the same
107 key multiple times; the last entry wins. Key files may also contain
108 multiple groups with the same name; they are merged together.
109 Another difference is that keys and group names in key files are not
110 restricted to ASCII characters.
113 <!-- ##### SECTION See_Also ##### -->
118 <!-- ##### SECTION Stability_Level ##### -->
121 <!-- ##### SECTION Image ##### -->
124 <!-- ##### STRUCT GKeyFile ##### -->
126 The <structname>GKeyFile</structname> struct contains only private fields
127 and should not be used directly.
131 <!-- ##### MACRO G_KEY_FILE_ERROR ##### -->
133 Error domain for key file parsing. Errors in this domain will
134 be from the #GKeyFileError enumeration. See #GError for information on
140 <!-- ##### ENUM GKeyFileError ##### -->
142 Error codes returned by key file parsing.
145 @G_KEY_FILE_ERROR_UNKNOWN_ENCODING: the text being parsed was in an unknown encoding
146 @G_KEY_FILE_ERROR_PARSE: document was ill-formed
147 @G_KEY_FILE_ERROR_NOT_FOUND: the file was not found
148 @G_KEY_FILE_ERROR_KEY_NOT_FOUND: a requested key was not found
149 @G_KEY_FILE_ERROR_GROUP_NOT_FOUND: a requested group was not found
150 @G_KEY_FILE_ERROR_INVALID_VALUE: a value could not be parsed
152 <!-- ##### ENUM GKeyFileFlags ##### -->
154 Flags which influence the parsing.
157 @G_KEY_FILE_NONE: No flags, default behaviour
158 @G_KEY_FILE_KEEP_COMMENTS: Use this flag if you plan to write the (possibly modified)
159 contents of the key file back to a file; otherwise all comments will be lost when
160 the key file is written back.
161 @G_KEY_FILE_KEEP_TRANSLATIONS: Use this flag if you plan to write the (possibly modified)
162 contents of the key file back to a file; otherwise only the translations for the current
163 language will be written back.
165 <!-- ##### FUNCTION g_key_file_new ##### -->
174 <!-- ##### FUNCTION g_key_file_free ##### -->
182 <!-- ##### FUNCTION g_key_file_set_list_separator ##### -->
191 <!-- ##### FUNCTION g_key_file_load_from_file ##### -->
203 <!-- ##### FUNCTION g_key_file_load_from_data ##### -->
216 <!-- ##### FUNCTION g_key_file_load_from_data_dirs ##### -->
229 <!-- ##### FUNCTION g_key_file_load_from_dirs ##### -->
243 <!-- ##### FUNCTION g_key_file_to_data ##### -->
254 <!-- ##### FUNCTION g_key_file_get_start_group ##### -->
263 <!-- ##### FUNCTION g_key_file_get_groups ##### -->
273 <!-- ##### FUNCTION g_key_file_get_keys ##### -->
285 <!-- ##### FUNCTION g_key_file_has_group ##### -->
295 <!-- ##### FUNCTION g_key_file_has_key ##### -->
307 <!-- ##### FUNCTION g_key_file_get_value ##### -->
319 <!-- ##### FUNCTION g_key_file_get_string ##### -->
331 <!-- ##### FUNCTION g_key_file_get_locale_string ##### -->
344 <!-- ##### FUNCTION g_key_file_get_boolean ##### -->
356 <!-- ##### FUNCTION g_key_file_get_integer ##### -->
368 <!-- ##### FUNCTION g_key_file_get_double ##### -->
380 <!-- ##### FUNCTION g_key_file_get_string_list ##### -->
393 <!-- ##### FUNCTION g_key_file_get_locale_string_list ##### -->
407 <!-- ##### FUNCTION g_key_file_get_boolean_list ##### -->
420 <!-- ##### FUNCTION g_key_file_get_integer_list ##### -->
433 <!-- ##### FUNCTION g_key_file_get_double_list ##### -->
446 <!-- ##### FUNCTION g_key_file_get_comment ##### -->
458 <!-- ##### FUNCTION g_key_file_set_value ##### -->
469 <!-- ##### FUNCTION g_key_file_set_string ##### -->
480 <!-- ##### FUNCTION g_key_file_set_locale_string ##### -->
492 <!-- ##### FUNCTION g_key_file_set_boolean ##### -->
503 <!-- ##### FUNCTION g_key_file_set_integer ##### -->
514 <!-- ##### FUNCTION g_key_file_set_double ##### -->
525 <!-- ##### FUNCTION g_key_file_set_string_list ##### -->
537 <!-- ##### FUNCTION g_key_file_set_locale_string_list ##### -->
550 <!-- ##### FUNCTION g_key_file_set_boolean_list ##### -->
562 <!-- ##### FUNCTION g_key_file_set_integer_list ##### -->
574 <!-- ##### FUNCTION g_key_file_set_double_list ##### -->
586 <!-- ##### FUNCTION g_key_file_set_comment ##### -->
599 <!-- ##### FUNCTION g_key_file_remove_group ##### -->
610 <!-- ##### FUNCTION g_key_file_remove_key ##### -->
622 <!-- ##### FUNCTION g_key_file_remove_comment ##### -->
634 <!-- ##### MACRO G_KEY_FILE_DESKTOP_GROUP ##### -->
636 The name of the main group of a desktop entry file, as defined in the
637 <ulink url="http://freedesktop.org/Standards/desktop-entry-spec">Desktop
638 Entry Specification</ulink>. Consult the specification for more
639 details about the meanings of the keys below.
645 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_TYPE ##### -->
648 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
649 whose value is a string giving the type of the desktop entry. Usually
650 <link linkend="G-KEY-FILE-DESKTOP-TYPE-APPLICATION:CAPS"><literal>G_KEY_FILE_DESKTOP_TYPE_APPLICATION</literal></link>,
651 <link linkend="G-KEY-FILE-DESKTOP-TYPE-LINK:CAPS"><literal>G_KEY_FILE_DESKTOP_TYPE_LINK</literal></link>, or
652 <link linkend="G-KEY-FILE-DESKTOP-TYPE-DIRECTORY:CAPS"><literal>G_KEY_FILE_DESKTOP_TYPE_DIRECTORY</literal></link>.
658 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_VERSION ##### -->
661 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
662 whose value is a string giving the version of the Desktop
663 Entry Specification used for the desktop entry file.
669 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_NAME ##### -->
672 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
673 whose value is a localized string giving the specific name of the
680 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME ##### -->
683 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
684 whose value is a localized string giving the generic name of the
691 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY ##### -->
694 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
695 whose value is a boolean stating whether the desktop entry should be
702 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_COMMENT ##### -->
705 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
706 whose value is a localized string giving the tooltip for the desktop
713 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_ICON ##### -->
716 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
717 whose value is a localized string giving the name of the icon to be
718 displayed for the desktop entry.
724 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_HIDDEN ##### -->
727 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
728 whose value is a boolean stating whether the desktop entry has been
735 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN ##### -->
738 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
739 whose value is a list of strings identifying the environments that
740 should display the desktop entry.
746 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN ##### -->
749 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
750 whose value is a list of strings identifying the environments that
751 should not display the desktop entry.
757 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_TRY_EXEC ##### -->
760 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
761 whose value is a string giving the file name of a binary on disk
762 used to determine if the program is actually installed. It is only
763 valid for desktop entries with the <literal>Application</literal>
770 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_EXEC ##### -->
773 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
774 whose value is a string giving the command line to execute. It is only
775 valid for desktop entries with the <literal>Application</literal>
782 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_PATH ##### -->
785 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
786 whose value is a string containing the working directory to run the
787 program in. It is only valid for desktop entries with the
788 <literal>Application</literal> type.
794 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_TERMINAL ##### -->
797 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
798 whose value is a boolean stating whether the program should be
799 run in a terminal window. It is only valid for desktop entries with
800 the <literal>Application</literal> type.
806 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_MIME_TYPE ##### -->
809 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
810 whose value is a list of strings giving the MIME types supported
811 by this desktop entry.
817 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_CATEGORIES ##### -->
820 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
821 whose value is a list of strings giving the categories in which the
822 desktop entry should be shown in a menu.
828 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY ##### -->
831 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
832 whose value is a boolean stating whether the application supports
834 url="http://www.freedesktop.org/Standards/startup-notification-spec">Startup
835 Notification Protocol Specification</ulink>.
841 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS ##### -->
844 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
845 whose value is string identifying the WM class or name hint of a
846 window that the application will create, which can be used to emulate
847 Startup Notification with older applications.
853 <!-- ##### MACRO G_KEY_FILE_DESKTOP_KEY_URL ##### -->
856 linkend="G-KEY-FILE-DESKTOP-GROUP:CAPS"><literal>G_KEY_FILE_DESKTOP_GROUP</literal></link>
857 whose value is a string giving the URL to access. It is only valid
858 for desktop entries with the <literal>Link</literal> type.
864 <!-- ##### MACRO G_KEY_FILE_DESKTOP_TYPE_APPLICATION ##### -->
866 The value of the <link
867 linkend="G-KEY-FILE-DESKTOP-KEY-TYPE:CAPS"><literal>G_KEY_FILE_DESKTOP_KEY_TYPE</literal></link>
868 key for desktop entries representing applications.
874 <!-- ##### MACRO G_KEY_FILE_DESKTOP_TYPE_LINK ##### -->
876 The value of the <link
877 linkend="G-KEY-FILE-DESKTOP-KEY-TYPE:CAPS"><literal>G_KEY_FILE_DESKTOP_KEY_TYPE</literal></link>
878 key for desktop entries representing links to documents.
884 <!-- ##### MACRO G_KEY_FILE_DESKTOP_TYPE_DIRECTORY ##### -->
886 The value of the <link
887 linkend="G-KEY-FILE-DESKTOP-KEY-TYPE:CAPS"><literal>G_KEY_FILE_DESKTOP_KEY_TYPE</literal></link>
888 key for desktop entries representing directories.