Creates a new empty #GKeyFile object. Use glib.key_file.KeyFile.loadFromFile, glib.key_file.KeyFile.loadFromData, glib.key_file.KeyFile.loadFromDirs or glib.key_file.KeyFile.loadFromDataDirs to read an existing key file.
Returns the value associated with key under group_name as a boolean.
Returns the values associated with key under group_name as booleans.
Retrieves a comment above key from group_name. If key is null then comment will be read from above group_name. If both key and group_name are null, then comment will be read from above the first group in the file.
Returns the value associated with key under group_name as a double. If group_name is null, the start_group is used.
Returns the values associated with key under group_name as doubles.
Returns all groups in the key file loaded with key_file. The array of returned groups will be null-terminated, so length may optionally be null.
Returns the value associated with key under group_name as a signed 64-bit integer. This is similar to glib.key_file.KeyFile.getInteger but can return 64-bit results without truncation.
Returns the value associated with key under group_name as an integer.
Returns the values associated with key under group_name as integers.
Returns all keys for the group name group_name. The array of returned keys will be null-terminated, so length may optionally be null. In the event that the group_name cannot be found, null is returned and error is set to G_KEY_FILE_ERROR_GROUP_NOT_FOUND.
Returns the actual locale which the result of glib.key_file.KeyFile.getLocaleString or glib.key_file.KeyFile.getLocaleStringList came from.
Returns the value associated with key under group_name translated in the given locale if available. If locale is null then the current locale is assumed.
Returns the values associated with key under group_name translated in the given locale if available. If locale is null then the current locale is assumed.
Returns the name of the start group of the file.
Returns the string value associated with key under group_name. Unlike glib.key_file.KeyFile.getValue, this function handles escape sequences like \s.
Returns the values associated with key under group_name.
Returns the value associated with key under group_name as an unsigned 64-bit integer. This is similar to glib.key_file.KeyFile.getInteger but can return large positive results without truncation.
Returns the raw value associated with key under group_name. Use glib.key_file.KeyFile.getString to retrieve an unescaped UTF-8 string.
Looks whether the key file has the group group_name.
Loads a key file from the data in bytes into an empty #GKeyFile structure. If the object cannot be created then error is set to a #GKeyFileError.
Loads a key file from memory into an empty #GKeyFile structure. If the object cannot be created then error is set to a #GKeyFileError.
This function looks for a key file named file in the paths returned from glib.global.getUserDataDir and glib.global.getSystemDataDirs, loads the file into key_file and returns the file's full path in full_path. If the file could not be loaded then an error is set to either a #GFileError or #GKeyFileError.
This function looks for a key file named file in the paths specified in search_dirs, loads the file into key_file and returns the file's full path in full_path.
Loads a key file into an empty #GKeyFile structure.
Removes a comment above key from group_name. If key is null then comment will be removed above group_name. If both key and group_name are null, then comment will be removed above the first group in the file.
Removes the specified group, group_name, from the key file.
Removes key in group_name from the key file.
Writes the contents of key_file to filename using glib.global.fileSetContents. If you need stricter guarantees about durability of the written file than are provided by glib.global.fileSetContents, use glib.global.fileSetContentsFull with the return value of glib.key_file.KeyFile.toData.
Associates a new boolean value with key under group_name. If key cannot be found then it is created.
Associates a list of boolean values with key under group_name. If key cannot be found then it is created. If group_name is null, the start_group is used.
Places a comment above key from group_name.
Associates a new double value with key under group_name. If key cannot be found then it is created.
Associates a list of double values with key under group_name. If key cannot be found then it is created.
Associates a new integer value with key under group_name. If key cannot be found then it is created.
Associates a new integer value with key under group_name. If key cannot be found then it is created.
Associates a list of integer values with key under group_name. If key cannot be found then it is created.
Sets the character which is used to separate values in lists. Typically ';' or ',' are used as separators. The default list separator is ';'.
Associates a string value for key and locale under group_name. If the translation for key cannot be found then it is created.
Associates a list of string values for key and locale under group_name. If the translation for key cannot be found then it is created.
Associates a new string value with key under group_name. If key cannot be found then it is created. If group_name cannot be found then it is created. Unlike glib.key_file.KeyFile.setValue, this function handles characters that need escaping, such as newlines.
Associates a list of string values for key under group_name. If key cannot be found then it is created. If group_name cannot be found then it is created.
Associates a new integer value with key under group_name. If key cannot be found then it is created.
Associates a new value with key under group_name.
This function outputs key_file as a string.
Pointer to the C boxed value
Get the GType of this boxed type.
Boxed GType property.
Convenience method to return this cast to a type. For use in D with statements.
Make a copy of the wrapped C boxed data.
Copy a C boxed value using g_boxed_copy.
Free a C boxed value using g_boxed_free.
glib.key_file.KeyFile parses .ini-like config files.
glib.key_file.KeyFile lets you parse, edit or create files containing groups of key-value pairs, which we call "key files" for lack of a better name. Several freedesktop.org specifications use key files now, e.g the Desktop Entry Specification
and the Icon Theme Specification.
The syntax of key files is described in detail in the Desktop Entry Specification, here is a quick summary: Key files consists of groups of key-value pairs, interspersed with comments.
Lines beginning with a '#' and blank lines are considered comments.
Groups are started by a header line containing the group name enclosed in '[' and ']', and ended implicitly by the start of the next group or the end of the file. Each key-value pair must be contained in a group.
Key-value pairs generally have the form key=value, with the exception of localized strings, which have the form key[locale]=value, with a locale identifier of the form lang_COUNTRY@MODIFIER where COUNTRY and MODIFIER are optional. Space before and after the '=' character are ignored. Newline, tab, carriage return and backslash characters in value are escaped as \n, \t, \r, and \\\\, respectively. To preserve leading spaces in values, these can also be escaped as \s.
Key files can store strings (possibly with localized variants), integers, booleans and lists of these. Lists are separated by a separator character, typically ';' or ','. To use the list separator character in a value in a list, it has to be escaped by prefixing it with a backslash.
This syntax is obviously inspired by the .ini files commonly met on Windows, but there are some important differences:
Note that in contrast to the Desktop Entry Specification, groups in key files may contain the same key multiple times; the last entry wins. Key files may also contain multiple groups with the same name; they are merged together. Another difference is that keys and group names in key files are not restricted to ASCII characters.
Here is an example of loading a key file and reading a value:
Here is an example of creating and saving a key file: