glibmm 2.46.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Attributes | List of all members
Glib::KeyFile Class Reference

This class lets you parse, edit or create files containing groups of key-value pairs, which we call key files for lack of a better name. More...

`#include <glibmm/keyfile.h>`

## Public Member Functions

| KeyFile ()
| Creates a new, empty KeyFile object. More...
| KeyFile (const KeyFile&)=delete
KeyFile& | operator= (const KeyFile&)=delete
| KeyFile (KeyFile&& other) noexcept
KeyFile& | operator= (KeyFile&& other) noexcept
| ~KeyFile ()
| Destructor. More...
| KeyFile (GKeyFile* castitem, bool takes_ownership=false)
| Creates a glibmm KeyFile wrapper for a GKeyFile object. More...
bool | load_from_file (const std::string& file, KeyFileFlags flags=Glib::KEY_FILE_NONE)
| Loads a key file into an empty KeyFile instance. More...
bool | load_from_data (const Glib::ustring& data, KeyFileFlags flags=Glib::KEY_FILE_NONE)
| Loads a KeyFile from memory. More...
bool | load_from_dirs (const std::string& file, const Glib::ArrayHandle< std::string >& search_dirs, Glib::ArrayHandle< std::string >& full_path, KeyFileFlags flags=Glib::KEY_FILE_NONE)
| 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. More...
bool | load_from_dirs (const std::string& file, const Glib::ArrayHandle< std::string >& search_dirs, std::string& full_path, KeyFileFlags flags=Glib::KEY_FILE_NONE)
| 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. More...
bool | load_from_data_dirs (const std::string& file, std::string& full_path, KeyFileFlags flags=Glib::KEY_FILE_NONE)
| Looks for a KeyFile named file in the paths returned from g_get_user_data_dir() and g_get_system_data_dirs() and loads them into the keyfile object, placing the full path to the file in full_path. More...
Glib::ustring | to_data ()
| Outputs the KeyFile as a string. More...
bool | save_to_file (const std::string& filename)
| Writes the contents of key_file to filename using g_file_set_contents(). More...
Glib::ustring | get_start_group () const
| Returns the name of the start group of the file. More...
Glib::ArrayHandle< Glib::ustring > | get_groups () const
| Gets a list of all groups in the KeyFile. More...
Glib::ArrayHandle< Glib::ustring > | get_keys (const Glib::ustring& group_name) const
| Gets a list of all keys from the group group_name. More...
bool | has_group (const Glib::ustring& group_name) const
| Looks whether the key file has the group group_name. More...
bool | has_key (const Glib::ustring& group_name, const Glib::ustring& key) const
| Looks whether the key file has the key key in the group group_name. More...
Glib::ustring | get_value (const Glib::ustring& group_name, const Glib::ustring& key) const
| Returns the value associated with key under group_name. More...
Glib::ustring | get_string (const Glib::ustring& group_name, const Glib::ustring& key) const
| Return value: a newly allocated string or `0`. More...
Glib::ustring | get_locale_string (const Glib::ustring& group_name, const Glib::ustring& key) const
| Gets the value associated with key under group_name translated into the current locale. More...
Glib::ustring | get_locale_string (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale) const
| Return value: a newly allocated string or `0`. More...
bool | get_boolean (const Glib::ustring& key) const
| Gets the value in the first group, under key, interpreting it as a boolean. More...
bool | get_boolean (const Glib::ustring& group_name, const Glib::ustring& key) const
| Return value: the value associated with the key as a boolean. More...
int | get_integer (const Glib::ustring& key) const
| Gets the value in the first group, under key, interpreting it as an integer. More...
int | get_integer (const Glib::ustring& group_name, const Glib::ustring& key) const
| Return value: the value associated with the key as an integer. More...
gint64 | get_int64 (const Glib::ustring& key) const
| Gets the value in the first group, under key, interpreting it as a signed 64-bit integer. More...
gint64 | get_int64 (const Glib::ustring& group_name, const Glib::ustring& key) const
| Returns the value associated with key under group_name as a signed 64-bit integer. More...
guint64 | get_uint64 (const Glib::ustring& key) const
| Gets the value in the first group, under key, interpreting it as an unsigned 64-bit integer. More...
guint64 | get_uint64 (const Glib::ustring& group_name, const Glib::ustring& key) const
| Returns the value associated with key under group_name as an unsigned 64-bit integer. More...
double | get_double (const Glib::ustring& key) const
| Gets the value in the first group, under key, interpreting it as a double. More...
double | get_double (const Glib::ustring& group_name, const Glib::ustring& key) const
| Return value: the value associated with the key as a double. More...
void | set_double (const Glib::ustring& group_name, const Glib::ustring& key, double value)
| Associates a new double value with key under group_name. More...
void | set_double (const Glib::ustring& key, double value)
| Associates a new double value with key under the start group. More...
Glib::ArrayHandle< Glib::ustring > | get_string_list (const Glib::ustring& group_name, const Glib::ustring& key) const
| Returns the values associated with key under group_name. More...
Glib::ArrayHandle< Glib::ustring > | get_locale_string_list (const Glib::ustring& group_name, const Glib::ustring& key) const
| Returns the values associated with key under group_name translated into the current locale, if available. More...
Glib::ArrayHandle< Glib::ustring > | get_locale_string_list (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale) const
| Returns the values associated with key under group_name translated into locale, if available. More...
Glib::ArrayHandle< bool > | get_boolean_list (const Glib::ustring& group_name, const Glib::ustring& key) const
| Returns the values associated with key under group_name. More...
Glib::ArrayHandle< int > | get_integer_list (const Glib::ustring& group_name, const Glib::ustring& key) const
| Returns the values associated with key under group_name. More...
Glib::ArrayHandle< double > | get_double_list (const Glib::ustring& group_name, const Glib::ustring& key) const
| Returns the values associated with key under group_name. More...
Glib::ustring | get_comment () const
| Get comment from top of file. More...
Glib::ustring | get_comment (const Glib::ustring& group_name) const
| Get comment from above a group. More...
Glib::ustring | get_comment (const Glib::ustring& group_name, const Glib::ustring& key) const
| Retrieves a comment above key from group_name. More...
void | set_list_separator (gchar separator)
| Sets the character which is used to separate values in lists. More...
void | set_value (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& value)
| Associates a new value with key under group_name. More...
void | set_string (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring&string)
| Associates a new string value with key under group_name. More...
void | set_locale_string (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale, const Glib::ustring&string)
| Associates a string value for key and locale under group_name. More...
void | set_boolean (const Glib::ustring& group_name, const Glib::ustring& key, bool value)
| Associates a new boolean value with key under group_name. More...
void | set_integer (const Glib::ustring& group_name, const Glib::ustring& key, int value)
| Associates a new integer value with key under group_name. More...
void | set_int64 (const Glib::ustring& group_name, const Glib::ustring& key, gint64 value)
| Associates a new integer value with key under group_name. More...
void | set_uint64 (const Glib::ustring& group_name, const Glib::ustring& key, guint64 value)
| Associates a new integer value with key under group_name. More...
void | set_string_list (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ArrayHandle< Glib::ustring >& list)
| Sets a list of string values for key under group_name. More...
void | set_locale_string_list (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale, const Glib::ArrayHandle< Glib::ustring >& list)
| Sets a list of string values for the key under group_name and marks them as being for locale. More...
void | set_boolean_list (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ArrayHandle< bool >& list)
| Sets a list of booleans for the key under group_name. More...
void | set_integer_list (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ArrayHandle< int >& list)
| Sets a list of integers for the key under group_name. More...
void | set_double_list (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ArrayHandle< double >& list)
| Sets a list of doubles for the key under group_name. More...
void | set_comment (const Glib::ustring& comment)
| Places comment at the start of the file, before the first group. More...
void | set_comment (const Glib::ustring& group_name, const Glib::ustring& comment)
| Places comment above group_name. More...
void | set_comment (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& comment)
| Places a comment above key from group_name. More...
void | remove_comment (const Glib::ustring& group_name, const Glib::ustring& key)
| Removes a comment above key from group_name. More...
void | remove_key (const Glib::ustring& group_name, const Glib::ustring& key)
| Removes key in group_name from the key file. More...
void | remove_group (const Glib::ustring& group_name)
| Removes the specified group, group_name, from the key file. More...
GKeyFile* | gobj ()
const GKeyFile* | gobj () const

## Protected Attributes

GKeyFile* | gobject_
bool | owns_gobject_

## Detailed Description

This class 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.

# 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]=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. 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:

- .ini files use the ';' character to begin comments, key files use the '#' character.
- Key files allow only comments before 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 group from [group].

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.

Since glibmm 2.14:

## Constructor & Destructor Documentation

Glib::KeyFile::KeyFile | ( |  | ) |

Creates a new, empty KeyFile object.

Glib::KeyFile::KeyFile | ( | const KeyFile& |  | ) |

delete

Glib::KeyFile::KeyFile | ( | KeyFile&& | other | ) |

noexcept

Glib::KeyFile::~KeyFile | ( |  | ) |

Destructor.

Glib::KeyFile::KeyFile | ( | GKeyFile * | castitem,
|  | bool | takes_ownership = `false`
| ) |  |

Creates a glibmm KeyFile wrapper for a GKeyFile object.

Note, when using this that when the wrapper is deleted, it will not automatically delete the GKeyFile unless you set the takes_ownership boolean to `true`.

Parameters

  castitem | The C instance to wrap.
  takes_ownership | If the C instance should be deleted when the wrapper is deleted.

## Member Function Documentation

bool Glib::KeyFile::get_boolean | ( | const Glib::ustring& | key | ) | const

Gets the value in the first group, under key, interpreting it as a boolean.

Parameters

  key | The name of the key.

Returns
  The value of key as a boolean.

Exceptions

  Glib::KeyFileError. |

Since glibmm 2.6:

bool Glib::KeyFile::get_boolean | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Return value: the value associated with the key as a boolean.

Since glibmm 2.6:

Exceptions

  Glib::KeyFileError |

Parameters

  group_name | A group name.
  key | A key.

Returns
  The value associated with the key as a boolean, or `false` if the key was not found or could not be parsed.

Glib::ArrayHandle<bool> Glib::KeyFile::get_boolean_list | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Returns the values associated with key under group_name.

Parameters

  group_name | The name of a group
  key | The name of a key

Returns
  A list of booleans

Exceptions

  Glib::KeyFileError |

Glib::ustring Glib::KeyFile::get_comment | ( |  | ) | const

Get comment from top of file.

Returns
  The comment

Exceptions

  Glib::KeyFileError |

Glib::ustring Glib::KeyFile::get_comment | ( | const Glib::ustring& | group_name | ) | const

Get comment from above a group.

Parameters

  group_name | The group

Returns
  The comment

Exceptions

  Glib::KeyFileError |

Glib::ustring Glib::KeyFile::get_comment | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Retrieves a comment above key from group_name.

If key is `0` then comment will be read from above group_name. If both key and group_name are `0`, then comment will be read from above the first group in the file. Use the overrides for a `0` key or group.

Since glibmm 2.6:

Exceptions

  Glib::KeyFileError |

Parameters

  group_name | A group name.
  key | A key.

Returns
  The comment.

double Glib::KeyFile::get_double | ( | const Glib::ustring& | key | ) | const

Gets the value in the first group, under key, interpreting it as a double.

Parameters

  key | The name of the key

Returns
  The value of key as an double

Exceptions

  Glib::KeyFileError |

Since glibmm 2.14:

double Glib::KeyFile::get_double | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Return value: the value associated with the key as a double.

Since glibmm 2.14:

Exceptions

  Glib::KeyFileError |

Parameters

  group_name | A group name.
  key | A key.

Returns
  The value associated with the key as a double, or 0.0 if the key was not found or could not be parsed.

Glib::ArrayHandle<double> Glib::KeyFile::get_double_list | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Returns the values associated with key under group_name.

Parameters

  group_name | The name of a group
  key | The name of a key

Returns
  A list of doubles

Exceptions

  Glib::KeyFileError |

Glib::ArrayHandle<Glib::ustring> Glib::KeyFile::get_groups | ( |  | ) | const

Gets a list of all groups in the KeyFile.

Returns
  A list containing the names of the groups

gint64 Glib::KeyFile::get_int64 | ( | const Glib::ustring& | key | ) | const

Gets the value in the first group, under key, interpreting it as a signed 64-bit integer.

This is similar to get_integer() but can return 64-bit results without truncation.

Parameters

  key | The name of the key.

Returns
  The value of key as a signed 64-bit integer, or `0` if the key was not found or could not be parsed.

Exceptions

  Glib::KeyFileError. |

Since glibmm 2.28:

gint64 Glib::KeyFile::get_int64 | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Returns the value associated with key under group_name as a signed 64-bit integer.

This is similar to g_key_file_get_integer() but can return 64-bit results without truncation.

Since glibmm 2.26:

Parameters

  group_name | A non-`0` group name.
  key | A non-`0` key.

Returns
  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.

int Glib::KeyFile::get_integer | ( | const Glib::ustring& | key | ) | const

Gets the value in the first group, under key, interpreting it as an integer.

Parameters

  key | The name of the key

Returns
  The value of key as an integer

Exceptions

  Glib::KeyFileError |

Since glibmm 2.6:

int Glib::KeyFile::get_integer | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Return value: the value associated with the key as an integer.

Since glibmm 2.6:

Exceptions

  Glib::KeyFileError |

Parameters

  group_name | A group name.
  key | A key.

Returns
  The value associated with the key as an integer, or 0 if the key was not found or could not be parsed.

Glib::ArrayHandle<int> Glib::KeyFile::get_integer_list | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Returns the values associated with key under group_name.

Parameters

  group_name | The name of a group
  key | The name of a key

Returns
  A list of integers

Exceptions

  Glib::KeyFileError |

Glib::ArrayHandle<Glib::ustring> Glib::KeyFile::get_keys | ( | const Glib::ustring& | group_name | ) | const

Gets a list of all keys from the group group_name.

Parameters

  group_name | The name of a group

Returns
  A list containing the names of the keys in group_name

Exceptions

  Glib::KeyFileError |

Glib::ustring Glib::KeyFile::get_locale_string | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Gets the value associated with key under group_name translated into the current locale.

Returns
  the value as a Glib::ustring

Exceptions

  Glib::KeyFileError |

Glib::ustring Glib::KeyFile::get_locale_string | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | const Glib::ustring& | locale
| ) |  | const

Return value: a newly allocated string or `0`.

Since glibmm 2.6:

Exceptions

  Glib::KeyFileError |

Parameters

  group_name | A group name.
  key | A key.
  locale | A locale identifier or `0`.

Returns
  A newly allocated string or `0` if the specified key cannot be found.

Glib::ArrayHandle<Glib::ustring> Glib::KeyFile::get_locale_string_list | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Returns the values associated with key under group_name translated into the current locale, if available.

Parameters

  group_name | The name of a group
  key | The name of a key

Returns
  A list containing the values requested

Exceptions

  Glib::KeyFileError |

Glib::ArrayHandle<Glib::ustring> Glib::KeyFile::get_locale_string_list | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | const Glib::ustring& | locale
| ) |  | const

Returns the values associated with key under group_name translated into locale, if available.

Parameters

  group_name | The name of a group
  key | The name of a key
  locale | The name of a locale

Returns
  A list containing the values requested

Exceptions

  Glib::KeyFileError |

Glib::ustring Glib::KeyFile::get_start_group | ( |  | ) | const

Returns the name of the start group of the file.

Since glibmm 2.6:

Returns
  The start group of the key file.

Glib::ustring Glib::KeyFile::get_string | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Return value: a newly allocated string or `0`.

Since glibmm 2.6:

Exceptions

  Glib::KeyFileError |

Parameters

  group_name | A group name.
  key | A key.

Returns
  A newly allocated string or `0` if the specified key cannot be found.

Glib::ArrayHandle<Glib::ustring> Glib::KeyFile::get_string_list | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Returns the values associated with key under group_name.

Parameters

  group_name | The name of a group
  key | The name of a key

Returns
  A list containing the values requested

Exceptions

  Glib::KeyFileError |

guint64 Glib::KeyFile::get_uint64 | ( | const Glib::ustring& | key | ) | const

Gets the value in the first group, under key, interpreting it as an unsigned 64-bit integer.

This is similar to get_integer() but can return large positive results without truncation.

Parameters

  key | The name of the key.

Returns
  The value of key as an unsigned 64-bit integer, or `0` if the key was not found or could not be parsed.

Exceptions

  Glib::KeyFileError. |

Since glibmm 2.28:

guint64 Glib::KeyFile::get_uint64 | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Returns the value associated with key under group_name as an unsigned 64-bit integer.

This is similar to g_key_file_get_integer() but can return large positive results without truncation.

Since glibmm 2.26:

Parameters

  group_name | A non-`0` group name.
  key | A non-`0` key.

Returns
  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.

Glib::ustring Glib::KeyFile::get_value | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Returns the value associated with key under group_name.

Since glibmm 2.6:

Exceptions

  Glib::KeyFileError | in the event the key cannot be found (with the Glib::KeyFileError::KEY_NOT_FOUND code).
  Glib::KeyFileError | in the event that the group_name cannot be found (with the Glib::KeyFileError::GROUP_NOT_FOUND code).

Parameters

  group_name | A group name.
  key | A key.

Returns
  The value as a string.

GKeyFile* Glib::KeyFile::gobj | ( |  | ) |

inline

const GKeyFile* Glib::KeyFile::gobj | ( |  | ) | const

inline

bool Glib::KeyFile::has_group | ( | const Glib::ustring& | group_name | ) | const

Looks whether the key file has the group group_name.

Since glibmm 2.6:

Parameters

  group_name | A group name.

Returns
  `true` if group_name is a part of key_file, `false` otherwise.

bool Glib::KeyFile::has_key | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  | const

Looks whether the key file has the key key in the group group_name.

Since glibmm 2.6:

Exceptions

  Glib::KeyFileError |

Parameters

  group_name | A group name.
  key | A key name.

Returns
  `true` if key is a part of group_name, `false` otherwise.

bool Glib::KeyFile::load_from_data | ( | const Glib::ustring& | data,
|  | KeyFileFlags | flags = `Glib::KEY_FILE_NONE`
| ) |  |

Loads a KeyFile from memory.

Parameters

  data | The data to use as a KeyFile
  flags | Bitwise combination of the flags to use for the KeyFile

Returns
  true if the KeyFile was successfully loaded, false otherwise

Exceptions

  Glib::KeyFileError |

bool Glib::KeyFile::load_from_data_dirs | ( | const std::string & | file,
|  | std::string & | full_path,
|  | KeyFileFlags | flags = `Glib::KEY_FILE_NONE`
| ) |  |

Looks for a KeyFile named file in the paths returned from g_get_user_data_dir() and g_get_system_data_dirs() and loads them into the keyfile object, placing the full path to the file in full_path.

Parameters

  file | The file to search for
  full_path | Return location for a string containing the full path of the file
  flags | Bitwise combination of the flags to use for the KeyFile

Returns
  true if the KeyFile was successfully loaded, false otherwise

Exceptions

  Glib::KeyFileError |
  Glib::FileError |

bool Glib::KeyFile::load_from_dirs | ( | const std::string & | file,
|  | const Glib::ArrayHandle< std::string >& | search_dirs,
|  | Glib::ArrayHandle< std::string >& | full_path,
|  | KeyFileFlags | flags = `Glib::KEY_FILE_NONE`
| ) |  |

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.

If the file could not be loaded then an error is set to either a FileError or KeyFileError.

Since glibmm 2.14:

Deprecated:
  Use the load_from_dirs() method that takes a std::string& full_path.

Parameters

  file | A relative path to a filename to open and parse.
  search_dirs | `0`-terminated array of directories to search.
  full_path | Return location for a string containing the full path of the file, or `0`.
  flags | Flags from KeyFileFlags.

Returns
  `true` if a key file could be loaded, `false` otherwise.

bool Glib::KeyFile::load_from_dirs | ( | const std::string & | file,
|  | const Glib::ArrayHandle< std::string >& | search_dirs,
|  | std::string & | full_path,
|  | KeyFileFlags | flags = `Glib::KEY_FILE_NONE`
| ) |  |

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.

If the file could not be loaded then an error is set to either a FileError or KeyFileError.

Since glibmm 2.14:

Parameters

  file | A relative path to a filename to open and parse.
  search_dirs | `0`-terminated array of directories to search.
  full_path | Return location for a string containing the full path of the file, or `0`.
  flags | Flags from KeyFileFlags.

Returns
  `true` if a key file could be loaded, `false` otherwise.

bool Glib::KeyFile::load_from_file | ( | const std::string & | file,
|  | KeyFileFlags | flags = `Glib::KEY_FILE_NONE`
| ) |  |

Loads a key file into an empty KeyFile instance.

If the file could not be loaded then a FileError or KeyFileError exception is thrown.

Since glibmm 2.6:

Exceptions

  Glib::FileError |
  Glib::KeyFileError |

Parameters

  file | The path of a filename to load, in the GLib filename encoding.
  flags | Flags from KeyFileFlags.

Returns
  `true` if a key file could be loaded, `false` otherwise.

KeyFile& Glib::KeyFile::operator= | ( | const KeyFile& |  | ) |

delete

KeyFile& Glib::KeyFile::operator= | ( | KeyFile&& | other | ) |

noexcept

void Glib::KeyFile::remove_comment | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  |

Removes a comment above key from group_name.

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

Exceptions

  Glib::KeyFileError |

Parameters

  group_name | A group name, or `0`.
  key | A key.

void Glib::KeyFile::remove_group | ( | const Glib::ustring& | group_name | ) |

Removes the specified group, group_name, from the key file.

Exceptions

  Glib::KeyFileError |

Parameters

  group_name | A group name.

void Glib::KeyFile::remove_key | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key
| ) |  |

Removes key in group_name from the key file.

Exceptions

  Glib::KeyFileError |

Parameters

  group_name | A group name.
  key | A key name to remove.

bool Glib::KeyFile::save_to_file | ( | const std::string & | filename | ) |

Writes the contents of key_file to filename using g_file_set_contents().

This function can fail for any of the reasons that g_file_set_contents() may fail.

Since glibmm 2.40:

Parameters

  filename | The name of the file to write to.

Returns
  `true` if successful, else `false` with error set.

void Glib::KeyFile::set_boolean | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | bool | value
| ) |  |

Associates a new boolean value with key under group_name.

If key cannot be found then it is created.

Since glibmm 2.6:

Parameters

  group_name | A group name.
  key | A key.
  value | `true` or `false`.

void Glib::KeyFile::set_boolean_list | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | const Glib::ArrayHandle< bool >& | list
| ) |  |

Sets a list of booleans for the key under group_name.

If either the key or group_name cannot be found they are created.

Parameters

  group_name | The name of a group
  key | The name of a key
  list | A list holding object of type bool

void Glib::KeyFile::set_comment | ( | const Glib::ustring& | comment | ) |

Places comment at the start of the file, before the first group.

Parameters

  comment | The Comment

Exceptions

  Glib::KeyFileError |

void Glib::KeyFile::set_comment | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | comment
| ) |  |

Places comment above group_name.

Parameters

  group_name | The Group the comment should be above
  comment | The comment

Exceptions

  Glib::KeyFileError |

void Glib::KeyFile::set_comment | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | const Glib::ustring& | comment
| ) |  |

Places a comment above key from group_name.

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

Exceptions

  Glib::KeyFileError |

Parameters

  group_name | A group name, or `0`.
  key | A key.
  comment | A comment.

void Glib::KeyFile::set_double | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | double | value
| ) |  |

Associates a new double value with key under group_name.

If key cannot be found then it is created.

Since glibmm 2.12:

Parameters

  group_name | A group name.
  key | A key.
  value | An double value.

void Glib::KeyFile::set_double | ( | const Glib::ustring& | key,
|  | double | value
| ) |  |

Associates a new double value with key under the start group.

If key cannot be found then it is created.

Since glibmm 2.12:

Parameters

  key | A key.
  value | An double value.

void Glib::KeyFile::set_double_list | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | const Glib::ArrayHandle< double >& | list
| ) |  |

Sets a list of doubles for the key under group_name.

If either the key or group_name cannot be found they are created.

Parameters

  group_name | The name of a group
  key | The name of a key
  list | A list holding object of type int

Since glibmm 2.14:

void Glib::KeyFile::set_int64 | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | gint64 | value
| ) |  |

Associates a new integer value with key under group_name.

If key cannot be found then it is created.

Since glibmm 2.26:

Parameters

  group_name | A group name.
  key | A key.
  value | An integer value.

void Glib::KeyFile::set_integer | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | int | value
| ) |  |

Associates a new integer value with key under group_name.

If key cannot be found then it is created.

Since glibmm 2.6:

Parameters

  group_name | A group name.
  key | A key.
  value | An integer value.

void Glib::KeyFile::set_integer_list | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | const Glib::ArrayHandle< int >& | list
| ) |  |

Sets a list of integers for the key under group_name.

If either the key or group_name cannot be found they are created.

Parameters

  group_name | The name of a group
  key | The name of a key
  list | A list holding object of type int

void Glib::KeyFile::set_list_separator | ( | gchar | separator | ) |

Sets the character which is used to separate values in lists.

Typically ';' or ',' are used as separators. The default list separator is ';'.

Since glibmm 2.6:

Parameters

  separator | The separator.

void Glib::KeyFile::set_locale_string | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | const Glib::ustring& | locale,
|  | const Glib::ustring& | string
| ) |  |

Associates a string value for key and locale under group_name.

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

Since glibmm 2.6:

Parameters

  group_name | A group name.
  key | A key.
  locale | A locale identifier.
  string | A string.

void Glib::KeyFile::set_locale_string_list | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | const Glib::ustring& | locale,
|  | const Glib::ArrayHandle< Glib::ustring >& | list
| ) |  |

Sets a list of string values for the key under group_name and marks them as being for locale.

If the key or group_name cannot be found, they are created.

Parameters

  group_name | The name of a group
  key | The name of a key
  locale | A locale
  list | A list holding objects of type Glib::ustring

void Glib::KeyFile::set_string | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | const Glib::ustring& | 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 g_key_file_set_value(), this function handles characters that need escaping, such as newlines.

Since glibmm 2.6:

Parameters

  group_name | A group name.
  key | A key.
  string | A string.

void Glib::KeyFile::set_string_list | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | const Glib::ArrayHandle< Glib::ustring >& | list
| ) |  |

Sets a list of string values for key under group_name.

If key cannot be found it is created. If group_name cannot be found it is created.

Parameters

  group_name | The name of a group
  key | The name of a key
  list | A list holding objects of type Glib::ustring

void Glib::KeyFile::set_uint64 | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | guint64 | value
| ) |  |

Associates a new integer value with key under group_name.

If key cannot be found then it is created.

Since glibmm 2.26:

Parameters

  group_name | A group name.
  key | A key.
  value | An integer value.

void Glib::KeyFile::set_value | ( | const Glib::ustring& | group_name,
|  | const Glib::ustring& | key,
|  | const Glib::ustring& | 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 g_key_file_set_string().

Since glibmm 2.6:

Parameters

  group_name | A group name.
  key | A key.
  value | A string.

Glib::ustring Glib::KeyFile::to_data | ( |  | ) |

Outputs the KeyFile as a string.

Returns
  A string object holding the contents of KeyFile

Exceptions

  Glib::KeyFileError |

## Member Data Documentation

GKeyFile* Glib::KeyFile::gobject_

protected

bool Glib::KeyFile::owns_gobject_

protected