Klasse KeyFile

Alle implementierten Schnittstellen:
PointerInterface

public class KeyFile extends Record
`GKeyFile` parses .ini-like config files.

`GKeyFile` 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. For example, the
[Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/)
and the [Icon Theme Specification](https://specifications.freedesktop.org/icon-theme-spec/latest/).

The syntax of key files is described in detail in the
[Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/),
here is a quick summary: Key files consists of groups of key-value pairs, interspersed
with comments.

```txt
# this is just an example
# there can be comments before the first group

[First Group]

Name=Key File Example\tthis value shows\nescaping

# localized strings are stored in multiple key-value pairs
Welcome=Hello
Welcome[de]=Hallo
Welcome[fr_FR]=Bonjour
Welcome[it]=Ciao

[Another Group]

Numbers=2;20;-200;0

Booleans=true;false;true;true
```

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. As a special case, the locale `C` is associated
with the untranslated pair `key=value` (since GLib 2.84). Space before and
after the `=` character is 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:

- .ini files use the `;` character to begin comments,
key files use the `#` character.

- Key files do not allow for ungrouped keys meaning only
comments can precede the first group.

- Key files are always encoded in UTF-8.

- Key and Group names are case-sensitive. For example, a group called
`[GROUP]` is a different from `[group]`.

- .ini files don’t have a strongly typed boolean entry type,
they only have `GetProfileInt()`. In key files, only
`true` and `false` (in lower case) are allowed.

Note that in contrast to the
[Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/),
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:

```c
g_autoptr(GError) error = NULL;
g_autoptr(GKeyFile) key_file = g_key_file_new ();

if (!g_key_file_load_from_file (key_file, "key-file.ini", flags, &error))
{
if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
g_warning ("Error loading key file: %s", error->message);
return;
}

g_autofree gchar *val = g_key_file_get_string (key_file, "Group Name", "SomeKey", &error);
if (val == NULL &&
!g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
{
g_warning ("Error finding key in key file: %s", error->message);
return;
}
else if (val == NULL)
{
// Fall back to a default value.
val = g_strdup ("default-value");
}
```

Here is an example of creating and saving a key file:

```c
g_autoptr(GKeyFile) key_file = g_key_file_new ();
const gchar *val = …;
g_autoptr(GError) error = NULL;

g_key_file_set_string (key_file, "Group Name", "SomeKey", val);

// Save as a file.
if (!g_key_file_save_to_file (key_file, "key-file.ini", &error))
{
g_warning ("Error saving key file: %s", error->message);
return;
}

// Or store to a GBytes for use elsewhere.
gsize data_len;
g_autofree guint8 *data = (guint8 *) g_key_file_to_data (key_file, &data_len, &error);
if (data == NULL)
{
g_warning ("Error saving key file: %s", error->message);
return;
}
g_autoptr(GBytes) bytes = g_bytes_new_take (g_steal_pointer (&data), data_len);
```

https://docs.gtk.org/glib/struct.KeyFile.html

  • Konstruktordetails

    • KeyFile

      public KeyFile(PointerContainer pointer)
    • KeyFile

      public KeyFile()
      Creates a new empty [struct@GLib.KeyFile] object.

      Use [method@GLib.KeyFile.load_from_file],
      [method@GLib.KeyFile.load_from_data], [method@GLib.KeyFile.load_from_dirs] or
      [method@GLib.KeyFile.load_from_data_dirs] to
      read an existing key file.
  • Methodendetails

    • getClassHandler

      public static ClassHandler getClassHandler()
    • free

      public void free()
      Clears all keys and groups from @key_file, and decreases the
      reference count by 1.

      If the reference count reaches zero, frees the key file and all its allocated
      memory.
    • getBoolean

      public boolean getBoolean(@Nonnull Str group_name, @Nonnull Str key) throws AllocationError
      Returns the value associated with @key under @group_name as a
      boolean.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the value associated with @key cannot be interpreted
      as a boolean then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      the value associated with the key as a boolean, or false if the key was not found or could not be parsed.
      Löst aus:
      AllocationError
    • getBoolean

      public boolean getBoolean(String group_name, String key) throws AllocationError
      Returns the value associated with @key under @group_name as a
      boolean.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the value associated with @key cannot be interpreted
      as a boolean then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      the value associated with the key as a boolean, or false if the key was not found or could not be parsed.
      Löst aus:
      AllocationError
    • getBooleanList

      public Int getBooleanList(@Nonnull Str group_name, @Nonnull Str key, @Nonnull Int64 length) throws AllocationError
      Returns the values associated with @key under @group_name as
      booleans.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the values associated with @key cannot be interpreted
      as booleans then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      length - the number of booleans returned
      Gibt zurück:
      the values associated with the key as a list of booleans, or `NULL` if the key was not found or could not be parsed. The returned list of booleans should be freed with [func@GLib.free] when no longer needed.
      Löst aus:
      AllocationError
    • getBooleanList

      public Int getBooleanList(String group_name, String key, @Nonnull Int64 length) throws AllocationError
      Returns the values associated with @key under @group_name as
      booleans.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the values associated with @key cannot be interpreted
      as booleans then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      length - the number of booleans returned
      Gibt zurück:
      the values associated with the key as a list of booleans, or `NULL` if the key was not found or could not be parsed. The returned list of booleans should be freed with [func@GLib.free] when no longer needed.
      Löst aus:
      AllocationError
    • getComment

      public Str getComment(@Nullable Str group_name, @Nullable Str key) throws AllocationError
      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.

      Note that the returned string does not include the `#` comment markers,
      but does include any whitespace after them (on each line). It includes
      the line breaks between lines, but does not include the final line break.
      Parameter:
      group_name - a group name, or `NULL` to get a top-level comment
      key - a key, or `NULL` to get a group comment
      Gibt zurück:
      a comment that should be freed with [func@GLib.free]
      Löst aus:
      AllocationError
    • getComment

      public Str getComment(String group_name, String key) throws AllocationError
      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.

      Note that the returned string does not include the `#` comment markers,
      but does include any whitespace after them (on each line). It includes
      the line breaks between lines, but does not include the final line break.
      Parameter:
      group_name - a group name, or `NULL` to get a top-level comment
      key - a key, or `NULL` to get a group comment
      Gibt zurück:
      a comment that should be freed with [func@GLib.free]
      Löst aus:
      AllocationError
    • getDouble

      public double getDouble(@Nonnull Str group_name, @Nonnull Str key) throws AllocationError
      Returns the value associated with @key under @group_name as a double.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the value associated with @key cannot be interpreted
      as a double then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      the value associated with the key as a double, or `0.0` if the key was not found or could not be parsed.
      Löst aus:
      AllocationError
    • getDouble

      public double getDouble(String group_name, String key) throws AllocationError
      Returns the value associated with @key under @group_name as a double.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the value associated with @key cannot be interpreted
      as a double then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      the value associated with the key as a double, or `0.0` if the key was not found or could not be parsed.
      Löst aus:
      AllocationError
    • getDoubleList

      public Dbl getDoubleList(@Nonnull Str group_name, @Nonnull Str key, @Nonnull Int64 length) throws AllocationError
      Returns the values associated with @key under @group_name as
      doubles.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the values associated with @key cannot be interpreted
      as doubles then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      length - the number of doubles returned
      Gibt zurück:
      the values associated with the key as a list of doubles, or `NULL` if the key was not found or could not be parsed. The returned list of doubles should be freed with [func@GLib.free] when no longer needed.
      Löst aus:
      AllocationError
    • getDoubleList

      public Dbl getDoubleList(String group_name, String key, @Nonnull Int64 length) throws AllocationError
      Returns the values associated with @key under @group_name as
      doubles.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the values associated with @key cannot be interpreted
      as doubles then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      length - the number of doubles returned
      Gibt zurück:
      the values associated with the key as a list of doubles, or `NULL` if the key was not found or could not be parsed. The returned list of doubles should be freed with [func@GLib.free] when no longer needed.
      Löst aus:
      AllocationError
    • getInt64

      public long getInt64(@Nonnull Str group_name, @Nonnull Str key) throws AllocationError
      Returns the value associated with @key under @group_name as a signed
      64-bit integer.

      This is similar to [method@GLib.KeyFile.get_integer] but can return
      64-bit results without truncation.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      the value associated with the key as a signed 64-bit integer, or `0` if the key was not found or could not be parsed.
      Löst aus:
      AllocationError
    • getInt64

      public long getInt64(String group_name, String key) throws AllocationError
      Returns the value associated with @key under @group_name as a signed
      64-bit integer.

      This is similar to [method@GLib.KeyFile.get_integer] but can return
      64-bit results without truncation.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      the value associated with the key as a signed 64-bit integer, or `0` if the key was not found or could not be parsed.
      Löst aus:
      AllocationError
    • getInteger

      public int getInteger(@Nonnull Str group_name, @Nonnull Str key) throws AllocationError
      Returns the value associated with @key under @group_name as an
      integer.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the value associated with @key cannot be interpreted
      as an integer, or is out of range for a `gint`, then
      [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      the value associated with the key as an integer, or `0` if the key was not found or could not be parsed.
      Löst aus:
      AllocationError
    • getInteger

      public int getInteger(String group_name, String key) throws AllocationError
      Returns the value associated with @key under @group_name as an
      integer.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the value associated with @key cannot be interpreted
      as an integer, or is out of range for a `gint`, then
      [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      the value associated with the key as an integer, or `0` if the key was not found or could not be parsed.
      Löst aus:
      AllocationError
    • getIntegerList

      public Int getIntegerList(@Nonnull Str group_name, @Nonnull Str key, @Nonnull Int64 length) throws AllocationError
      Returns the values associated with @key under @group_name as
      integers.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the values associated with @key cannot be interpreted
      as integers, or are out of range for `gint`, then
      [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      length - the number of integers returned
      Gibt zurück:
      the values associated with the key as a list of integers, or `NULL` if the key was not found or could not be parsed. The returned list of integers should be freed with [func@GLib.free] when no longer needed.
      Löst aus:
      AllocationError
    • getIntegerList

      public Int getIntegerList(String group_name, String key, @Nonnull Int64 length) throws AllocationError
      Returns the values associated with @key under @group_name as
      integers.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. Likewise, if the values associated with @key cannot be interpreted
      as integers, or are out of range for `gint`, then
      [error@GLib.KeyFileError.INVALID_VALUE] is returned.
      Parameter:
      group_name - a group name
      key - a key
      length - the number of integers returned
      Gibt zurück:
      the values associated with the key as a list of integers, or `NULL` if the key was not found or could not be parsed. The returned list of integers should be freed with [func@GLib.free] when no longer needed.
      Löst aus:
      AllocationError
    • getLocaleForKey

      public Str getLocaleForKey(@Nonnull Str group_name, @Nonnull Str key, @Nullable Str locale)
      Returns the actual locale which the result of
      [method@GLib.KeyFile.get_locale_string] or
      [method@GLib.KeyFile.get_locale_string_list] came from.

      If calling [method@GLib.KeyFile.get_locale_string] or
      [method@GLib.KeyFile.get_locale_string_list] with exactly the same @key_file,
      @group_name, @key and @locale, the result of those functions will
      have originally been tagged with the locale that is the result of
      this function.
      Parameter:
      group_name - a group name
      key - a key
      locale - a locale identifier or `NULL` to use the current locale
      Gibt zurück:
      the locale from the file, or `NULL` if the key was not found or the entry in the file was was untranslated
    • getLocaleForKey

      public Str getLocaleForKey(String group_name, String key, String locale)
      Returns the actual locale which the result of
      [method@GLib.KeyFile.get_locale_string] or
      [method@GLib.KeyFile.get_locale_string_list] came from.

      If calling [method@GLib.KeyFile.get_locale_string] or
      [method@GLib.KeyFile.get_locale_string_list] with exactly the same @key_file,
      @group_name, @key and @locale, the result of those functions will
      have originally been tagged with the locale that is the result of
      this function.
      Parameter:
      group_name - a group name
      key - a key
      locale - a locale identifier or `NULL` to use the current locale
      Gibt zurück:
      the locale from the file, or `NULL` if the key was not found or the entry in the file was was untranslated
    • getLocaleString

      public Str getLocaleString(@Nonnull Str group_name, @Nonnull Str key, @Nullable Str locale) throws AllocationError
      Returns the value associated with @key under @group_name
      translated in the given @locale if available.

      If @locale is `C` then the untranslated value is returned (since GLib 2.84).

      If @locale is `NULL` then the current locale is assumed.

      If @locale is to be non-`NULL`, or if the current locale will change over
      the lifetime of the [struct@GLib.KeyFile], it must be loaded with
      [flags@GLib.KeyFileFlags.KEEP_TRANSLATIONS] in order to load strings for all
      locales.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. If the value associated
      with @key cannot be interpreted or no suitable translation can
      be found then the untranslated value is returned.
      Parameter:
      group_name - a group name
      key - a key
      locale - a locale identifier or `NULL` to use the current locale
      Gibt zurück:
      a newly allocated string or `NULL` if the specified key cannot be found.
      Löst aus:
      AllocationError
    • getLocaleString

      public Str getLocaleString(String group_name, String key, String locale) throws AllocationError
      Returns the value associated with @key under @group_name
      translated in the given @locale if available.

      If @locale is `C` then the untranslated value is returned (since GLib 2.84).

      If @locale is `NULL` then the current locale is assumed.

      If @locale is to be non-`NULL`, or if the current locale will change over
      the lifetime of the [struct@GLib.KeyFile], it must be loaded with
      [flags@GLib.KeyFileFlags.KEEP_TRANSLATIONS] in order to load strings for all
      locales.

      If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. If the value associated
      with @key cannot be interpreted or no suitable translation can
      be found then the untranslated value is returned.
      Parameter:
      group_name - a group name
      key - a key
      locale - a locale identifier or `NULL` to use the current locale
      Gibt zurück:
      a newly allocated string or `NULL` if the specified key cannot be found.
      Löst aus:
      AllocationError
    • getStartGroup

      public Str getStartGroup()
      Returns the name of the start group of the file.
      Gibt zurück:
      The start group of the key file.
    • getString

      public Str getString(@Nonnull Str group_name, @Nonnull Str key) throws AllocationError
      Returns the string value associated with @key under @group_name.

      Unlike [method@GLib.KeyFile.get_value], this function handles escape
      sequences like `\s`.

      If the key cannot be found, [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. If the @group_name cannot be found,
      [error@GLib.KeyFileError.GROUP_NOT_FOUND] is returned.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      a newly allocated string or `NULL` if the specified key cannot be found.
      Löst aus:
      AllocationError
    • getString

      public Str getString(String group_name, String key) throws AllocationError
      Returns the string value associated with @key under @group_name.

      Unlike [method@GLib.KeyFile.get_value], this function handles escape
      sequences like `\s`.

      If the key cannot be found, [error@GLib.KeyFileError.KEY_NOT_FOUND] is
      returned. If the @group_name cannot be found,
      [error@GLib.KeyFileError.GROUP_NOT_FOUND] is returned.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      a newly allocated string or `NULL` if the specified key cannot be found.
      Löst aus:
      AllocationError
    • getUint64

      public long getUint64(@Nonnull Str group_name, @Nonnull Str key) throws AllocationError
      Returns the value associated with @key under @group_name as an unsigned
      64-bit integer.

      This is similar to [method@GLib.KeyFile.get_integer] but can return
      large positive results without truncation.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      the value associated with the key as an unsigned 64-bit integer, or `0` if the key was not found or could not be parsed.
      Löst aus:
      AllocationError
    • getUint64

      public long getUint64(String group_name, String key) throws AllocationError
      Returns the value associated with @key under @group_name as an unsigned
      64-bit integer.

      This is similar to [method@GLib.KeyFile.get_integer] but can return
      large positive results without truncation.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      the value associated with the key as an unsigned 64-bit integer, or `0` if the key was not found or could not be parsed.
      Löst aus:
      AllocationError
    • getValue

      public Str getValue(@Nonnull Str group_name, @Nonnull Str key) throws AllocationError
      Returns the raw value associated with @key under @group_name.

      Use [method@GLib.KeyFile.get_string] to retrieve an unescaped UTF-8 string.

      If the key cannot be found, [error@GLib.KeyFileError.KEY_NOT_FOUND]
      is returned. If the @group_name cannot be found,
      [error@GLib.KeyFileError.GROUP_NOT_FOUND] is returned.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      a newly allocated string or `NULL` if the specified key cannot be found.
      Löst aus:
      AllocationError
    • getValue

      public Str getValue(String group_name, String key) throws AllocationError
      Returns the raw value associated with @key under @group_name.

      Use [method@GLib.KeyFile.get_string] to retrieve an unescaped UTF-8 string.

      If the key cannot be found, [error@GLib.KeyFileError.KEY_NOT_FOUND]
      is returned. If the @group_name cannot be found,
      [error@GLib.KeyFileError.GROUP_NOT_FOUND] is returned.
      Parameter:
      group_name - a group name
      key - a key
      Gibt zurück:
      a newly allocated string or `NULL` if the specified key cannot be found.
      Löst aus:
      AllocationError
    • hasGroup

      public boolean hasGroup(@Nonnull Str group_name)
      Looks whether the key file has the group @group_name.
      Parameter:
      group_name - a group name
      Gibt zurück:
      true if @group_name is a part of @key_file, false otherwise.
    • hasGroup

      public boolean hasGroup(String group_name)
      Looks whether the key file has the group @group_name.
      Parameter:
      group_name - a group name
      Gibt zurück:
      true if @group_name is a part of @key_file, false otherwise.
    • hasKey

      public boolean hasKey(@Nonnull Str group_name, @Nonnull Str key) throws AllocationError
      Looks whether the key file has the key @key in the group
      @group_name.

      Note that this function does not follow the rules for [struct@GLib.Error]
      strictly;
      the return value both carries meaning and signals an error. To use
      this function, you must pass a [struct@GLib.Error] pointer in @error, and
      check whether it is not `NULL` to see if an error occurred.

      Language bindings should use [method@GLib.KeyFile.get_value] to test whether
      a key exists.
      Parameter:
      group_name - a group name
      key - a key name
      Gibt zurück:
      true if @key is a part of @group_name, false otherwise
      Löst aus:
      AllocationError
    • hasKey

      public boolean hasKey(String group_name, String key) throws AllocationError
      Looks whether the key file has the key @key in the group
      @group_name.

      Note that this function does not follow the rules for [struct@GLib.Error]
      strictly;
      the return value both carries meaning and signals an error. To use
      this function, you must pass a [struct@GLib.Error] pointer in @error, and
      check whether it is not `NULL` to see if an error occurred.

      Language bindings should use [method@GLib.KeyFile.get_value] to test whether
      a key exists.
      Parameter:
      group_name - a group name
      key - a key name
      Gibt zurück:
      true if @key is a part of @group_name, false otherwise
      Löst aus:
      AllocationError
    • loadFromBytes

      public boolean loadFromBytes(@Nonnull Bytes bytes, int flags) throws AllocationError
      Loads a key file from the data in @bytes into an empty [struct@GLib.KeyFile]
      structure.

      If the object cannot be created then a [error@GLib.KeyFileError] is returned.
      Parameter:
      bytes - a [struct@GLib.Bytes]
      flags - flags from [flags@GLib.KeyFileFlags]
      Gibt zurück:
      true if a key file could be loaded, false otherwise
      Löst aus:
      AllocationError
    • loadFromData

      public boolean loadFromData(@Nonnull Str data, long length, int flags) throws AllocationError
      Loads a key file from memory into an empty [struct@GLib.KeyFile] structure.

      If the object cannot be created then a [error@GLib.KeyFileError is returned.
      Parameter:
      data - key file loaded in memory
      length - the length of @data in bytes (or `(gsize)-1` if data is nul-terminated)
      flags - flags from [flags@GLib.KeyFileFlags]
      Gibt zurück:
      true if a key file could be loaded, false otherwise
      Löst aus:
      AllocationError
    • loadFromData

      public boolean loadFromData(String data, long length, int flags) throws AllocationError
      Loads a key file from memory into an empty [struct@GLib.KeyFile] structure.

      If the object cannot be created then a [error@GLib.KeyFileError is returned.
      Parameter:
      data - key file loaded in memory
      length - the length of @data in bytes (or `(gsize)-1` if data is nul-terminated)
      flags - flags from [flags@GLib.KeyFileFlags]
      Gibt zurück:
      true if a key file could be loaded, false otherwise
      Löst aus:
      AllocationError
    • loadFromFile

      public boolean loadFromFile(@Nonnull Str file, int flags) throws AllocationError
      Loads a key file into an empty [struct@GLib.KeyFile] structure.

      If the OS returns an error when opening or reading the file, a
      [error@GLib.FileError] is returned. If there is a problem parsing the file,
      a [error@GLib.KeyFileError] is returned.

      This function will never return a [error@GLib.KeyFileError.NOT_FOUND]
      error. If the @file is not found, [error@GLib.FileError.NOENT] is returned.
      Parameter:
      file - the path of a filename to load, in the GLib filename encoding
      flags - flags from [flags@GLib.KeyFileFlags]
      Gibt zurück:
      true if a key file could be loaded, false otherwise
      Löst aus:
      AllocationError
    • loadFromFile

      public boolean loadFromFile(String file, int flags) throws AllocationError
      Loads a key file into an empty [struct@GLib.KeyFile] structure.

      If the OS returns an error when opening or reading the file, a
      [error@GLib.FileError] is returned. If there is a problem parsing the file,
      a [error@GLib.KeyFileError] is returned.

      This function will never return a [error@GLib.KeyFileError.NOT_FOUND]
      error. If the @file is not found, [error@GLib.FileError.NOENT] is returned.
      Parameter:
      file - the path of a filename to load, in the GLib filename encoding
      flags - flags from [flags@GLib.KeyFileFlags]
      Gibt zurück:
      true if a key file could be loaded, false otherwise
      Löst aus:
      AllocationError
    • ref

      public KeyFile ref()
      Increases the reference count of @key_file.
      Gibt zurück:
      the same @key_file.
    • removeComment

      public boolean removeComment(@Nullable Str group_name, @Nullable Str key) throws AllocationError
      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.
      Parameter:
      group_name - a group name, or `NULL` to get a top-level comment
      key - a key, or `NULL` to get a group comment
      Gibt zurück:
      true if the comment was removed, false otherwise
      Löst aus:
      AllocationError
    • removeComment

      public boolean removeComment(String group_name, String key) throws AllocationError
      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.
      Parameter:
      group_name - a group name, or `NULL` to get a top-level comment
      key - a key, or `NULL` to get a group comment
      Gibt zurück:
      true if the comment was removed, false otherwise
      Löst aus:
      AllocationError
    • removeGroup

      public boolean removeGroup(@Nonnull Str group_name) throws AllocationError
      Removes the specified group, @group_name,
      from the key file.
      Parameter:
      group_name - a group name
      Gibt zurück:
      true if the group was removed, false otherwise
      Löst aus:
      AllocationError
    • removeGroup

      public boolean removeGroup(String group_name) throws AllocationError
      Removes the specified group, @group_name,
      from the key file.
      Parameter:
      group_name - a group name
      Gibt zurück:
      true if the group was removed, false otherwise
      Löst aus:
      AllocationError
    • removeKey

      public boolean removeKey(@Nonnull Str group_name, @Nonnull Str key) throws AllocationError
      Removes @key in @group_name from the key file.
      Parameter:
      group_name - a group name
      key - a key name to remove
      Gibt zurück:
      true if the key was removed, false otherwise
      Löst aus:
      AllocationError
    • removeKey

      public boolean removeKey(String group_name, String key) throws AllocationError
      Removes @key in @group_name from the key file.
      Parameter:
      group_name - a group name
      key - a key name to remove
      Gibt zurück:
      true if the key was removed, false otherwise
      Löst aus:
      AllocationError
    • saveToFile

      public boolean saveToFile(@Nonnull Str filename) throws AllocationError
      Writes the contents of @key_file to @filename using
      [func@GLib.file_set_contents].

      If you need stricter guarantees about durability of
      the written file than are provided by [func@GLib.file_set_contents], use
      [func@GLib.file_set_contents_full] with the return value of
      [method@GLib.KeyFile.to_data].

      This function can fail for any of the reasons that
      [func@GLib.file_set_contents] may fail.
      Parameter:
      filename - the name of the file to write to
      Gibt zurück:
      true if successful, false otherwise
      Löst aus:
      AllocationError
    • saveToFile

      public boolean saveToFile(String filename) throws AllocationError
      Writes the contents of @key_file to @filename using
      [func@GLib.file_set_contents].

      If you need stricter guarantees about durability of
      the written file than are provided by [func@GLib.file_set_contents], use
      [func@GLib.file_set_contents_full] with the return value of
      [method@GLib.KeyFile.to_data].

      This function can fail for any of the reasons that
      [func@GLib.file_set_contents] may fail.
      Parameter:
      filename - the name of the file to write to
      Gibt zurück:
      true if successful, false otherwise
      Löst aus:
      AllocationError
    • setBoolean

      public void setBoolean(@Nonnull Str group_name, @Nonnull Str key, boolean value)
      Associates a new boolean value with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      value - true or false
    • setBoolean

      public void setBoolean(String group_name, String key, boolean value)
      Associates a new boolean value with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      value - true or false
    • setBooleanList

      public void setBooleanList(@Nonnull Str group_name, @Nonnull Str key, @Nonnull Int list, long length)
      Associates a list of boolean values with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      list - an array of boolean values
      length - length of @list
    • setBooleanList

      public void setBooleanList(String group_name, String key, @Nonnull Int list, long length)
      Associates a list of boolean values with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      list - an array of boolean values
      length - length of @list
    • setComment

      public boolean setComment(@Nullable Str group_name, @Nullable Str key, @Nonnull Str comment) throws AllocationError
      Places a comment above @key from @group_name.

      If @key is `NULL` then @comment will be written above @group_name.
      If both @key and @group_name are `NULL`, then @comment will be
      written above the first group in the file.

      Note that this function prepends a `#` comment marker to
      each line of @comment.
      Parameter:
      group_name - a group name, or `NULL` to write a top-level comment
      key - a key, or `NULL` to write a group comment
      comment - a comment
      Gibt zurück:
      true if the comment was written, false otherwise
      Löst aus:
      AllocationError
    • setComment

      public boolean setComment(String group_name, String key, String comment) throws AllocationError
      Places a comment above @key from @group_name.

      If @key is `NULL` then @comment will be written above @group_name.
      If both @key and @group_name are `NULL`, then @comment will be
      written above the first group in the file.

      Note that this function prepends a `#` comment marker to
      each line of @comment.
      Parameter:
      group_name - a group name, or `NULL` to write a top-level comment
      key - a key, or `NULL` to write a group comment
      comment - a comment
      Gibt zurück:
      true if the comment was written, false otherwise
      Löst aus:
      AllocationError
    • setDouble

      public void setDouble(@Nonnull Str group_name, @Nonnull Str key, double value)
      Associates a new double value with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      value - a double value
    • setDouble

      public void setDouble(String group_name, String key, double value)
      Associates a new double value with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      value - a double value
    • setDoubleList

      public void setDoubleList(@Nonnull Str group_name, @Nonnull Str key, @Nonnull Dbl list, long length)
      Associates a list of double values with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      list - an array of double values
      length - number of double values in @list
    • setDoubleList

      public void setDoubleList(String group_name, String key, @Nonnull Dbl list, long length)
      Associates a list of double values with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      list - an array of double values
      length - number of double values in @list
    • setInt64

      public void setInt64(@Nonnull Str group_name, @Nonnull Str key, long value)
      Associates a new integer value with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      value - an integer value
    • setInt64

      public void setInt64(String group_name, String key, long value)
      Associates a new integer value with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      value - an integer value
    • setInteger

      public void setInteger(@Nonnull Str group_name, @Nonnull Str key, int value)
      Associates a new integer value with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      value - an integer value
    • setInteger

      public void setInteger(String group_name, String key, int value)
      Associates a new integer value with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      value - an integer value
    • setIntegerList

      public void setIntegerList(@Nonnull Str group_name, @Nonnull Str key, @Nonnull Int list, long length)
      Associates a list of integer values with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      list - an array of integer values
      length - number of integer values in @list
    • setIntegerList

      public void setIntegerList(String group_name, String key, @Nonnull Int list, long length)
      Associates a list of integer values with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      list - an array of integer values
      length - number of integer values in @list
    • setListSeparator

      public void setListSeparator(byte separator)
      Sets the character which is used to separate values in lists.

      Typically `;` or `,` are used as separators. The default list separator
      is `;`.
      Parameter:
      separator - the separator
    • setLocaleString

      public void setLocaleString(@Nonnull Str group_name, @Nonnull Str key, @Nonnull Str locale, @Nonnull Str string)
      Associates a string value for @key and @locale under @group_name.

      If the translation for @key cannot be found then it is created.

      If @locale is `C` then the untranslated value is set (since GLib 2.84).
      Parameter:
      group_name - a group name
      key - a key
      locale - a locale identifier
      string - a string
    • setLocaleString

      public void setLocaleString(String group_name, String key, String locale, String string)
      Associates a string value for @key and @locale under @group_name.

      If the translation for @key cannot be found then it is created.

      If @locale is `C` then the untranslated value is set (since GLib 2.84).
      Parameter:
      group_name - a group name
      key - a key
      locale - a locale identifier
      string - a string
    • setString

      public void setString(@Nonnull Str group_name, @Nonnull Str key, @Nonnull Str string)
      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 [method@GLib.KeyFile.set_value], this function handles characters
      that need escaping, such as newlines.
      Parameter:
      group_name - a group name
      key - a key
      string - a string
    • setString

      public void setString(String group_name, String key, String string)
      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 [method@GLib.KeyFile.set_value], this function handles characters
      that need escaping, such as newlines.
      Parameter:
      group_name - a group name
      key - a key
      string - a string
    • setUint64

      public void setUint64(@Nonnull Str group_name, @Nonnull Str key, long value)
      Associates a new integer value with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      value - an integer value
    • setUint64

      public void setUint64(String group_name, String key, long value)
      Associates a new integer value with @key under @group_name.

      If @key cannot be found then it is created.
      Parameter:
      group_name - a group name
      key - a key
      value - an integer value
    • setValue

      public void setValue(@Nonnull Str group_name, @Nonnull Str key, @Nonnull Str value)
      Associates a new 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. To set an UTF-8 string which may contain
      characters that need escaping (such as newlines or spaces), use
      [method@GLib.KeyFile.set_string].
      Parameter:
      group_name - a group name
      key - a key
      value - a string
    • setValue

      public void setValue(String group_name, String key, String value)
      Associates a new 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. To set an UTF-8 string which may contain
      characters that need escaping (such as newlines or spaces), use
      [method@GLib.KeyFile.set_string].
      Parameter:
      group_name - a group name
      key - a key
      value - a string
    • toData

      public Str toData(@Nullable Int64 length) throws AllocationError
      Outputs @key_file as a string.

      Note that this function never reports an error.
      Parameter:
      length - return location for the length of the returned string, or `NULL` to ignore
      Gibt zurück:
      a newly allocated string holding the contents of the key file
      Löst aus:
      AllocationError
    • unref

      public void unref()
      Decreases the reference count of @key_file by 1.

      If the reference count reaches zero, frees the key file and all its allocated
      memory.
    • errorQuark

      public static int errorQuark()
      Gibt zurück:
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()