glibmm: 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 Types

Public Member Functions

void reference () const
 Increment the reference count for this object. More...

 
void unreference () const
 Decrement the reference count for this object. More...

 
GKeyFile* gobj ()
 Provides access to the underlying C instance. More...

 
const GKeyFile* gobj () const
 Provides access to the underlying C instance. More...

 
GKeyFile* gobj_copy () const
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...

 
 KeyFile ()=delete
 
 KeyFile (const KeyFile&)=delete
 
KeyFileoperator= (const KeyFile&)=delete
 
bool load_from_file (const std::string& file, Flags flags=Flags::NONE)
 Loads a key file into an empty KeyFile instance. More...

 
bool load_from_data (const Glib::ustring& data, Flags flags=Flags::NONE)
 Loads a KeyFile from memory. More...

 
bool load_from_dirs (const std::string& file, const std::vector< std::string >& search_dirs, std::string& full_path, Flags flags=Flags::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, Flags flags=Flags::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...

 
std::vector< Glib::ustringget_groups () const
 Gets a list of all groups in the KeyFile. More...

 
std::vector< Glib::ustringget_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 nullptr. More...

 
Glib::ustring get_locale_for_key (const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale={}) const
 Returns the actual locale which the result of g_key_file_get_locale_string() or g_key_file_get_locale_string_list() came from. 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 nullptr. 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...

 
std::vector< Glib::ustringget_string_list (const Glib::ustring& group_name, const Glib::ustring& key) const
 Returns the values associated with key under group_name. More...

 
std::vector< Glib::ustringget_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...

 
std::vector< Glib::ustringget_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...

 
std::vector< bool > get_boolean_list (const Glib::ustring& group_name, const Glib::ustring& key) const
 Returns the values associated with key under group_name. More...

 
std::vector< int > get_integer_list (const Glib::ustring& group_name, const Glib::ustring& key) const
 Returns the values associated with key under group_name. More...

 
std::vector< 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 std::vector< 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 std::vector< 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 std::vector< 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 std::vector< 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 std::vector< 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...

 

Static Public Member Functions

static Glib::RefPtr< KeyFilecreate ()
 

Protected Member Functions

void operator delete (void*, std::size_t)
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Glib::KeyFilewrap (GKeyFile* object, bool take_copy=false)
 A Glib::wrap() method for this object. More...

 

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 ( )
delete
Glib::KeyFile::KeyFile ( const KeyFile )
delete

Member Function Documentation

static Glib::RefPtr<KeyFile> Glib::KeyFile::create ( )
static
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
keyThe 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_nameA group name.
keyA key.
Returns
The value associated with the key as a boolean, or false if the key was not found or could not be parsed.
std::vector<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_nameThe name of a group
keyThe 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_nameThe 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 nullptr then comment will be read from above group_name. If both key and group_name are nullptr, then comment will be read from above the first group in the file. Use the overrides for a nullptr key or group.

Since glibmm 2.6:
Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.
keyA 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
keyThe 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_nameA group name.
keyA 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.
std::vector<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_nameThe name of a group
keyThe name of a key
Returns
A list of doubles
Exceptions
Glib::KeyFileError
std::vector<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
keyThe 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_nameA non-nullptr group name.
keyA non-nullptr 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.
Exceptions
Glib::KeyFileError
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
keyThe 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_nameA group name.
keyA key.
Returns
The value associated with the key as an integer, or 0 if the key was not found or could not be parsed.
std::vector<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_nameThe name of a group
keyThe name of a key
Returns
A list of integers
Exceptions
Glib::KeyFileError
std::vector<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_nameThe 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_for_key ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ustring locale = {} 
) const

Returns the actual locale which the result of g_key_file_get_locale_string() or g_key_file_get_locale_string_list() came from.

If calling g_key_file_get_locale_string() or g_key_file_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.

Since glibmm 2.60:
Parameters
group_nameA group name.
keyA key.
localeA locale identifier or nullptr.
Returns
The locale from the file, or nullptr if the key was not found or the entry in the file was was untranslated.
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 nullptr.

Since glibmm 2.6:
Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.
keyA key.
localeA locale identifier or nullptr.
Returns
A newly allocated string or nullptr if the specified key cannot be found.
std::vector<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_nameThe name of a group
keyThe name of a key
Returns
A list containing the values requested
Exceptions
Glib::KeyFileError
std::vector<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_nameThe name of a group
keyThe name of a key
localeThe 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 nullptr.

Since glibmm 2.6:
Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.
keyA key.
Returns
A newly allocated string or nullptr if the specified key cannot be found.
std::vector<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_nameThe name of a group
keyThe 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
keyThe 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_nameA non-nullptr group name.
keyA non-nullptr 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.
Exceptions
Glib::KeyFileError
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::KeyFileErrorin the event the key cannot be found (with the Glib::KeyFileError::KEY_NOT_FOUND code).
Glib::KeyFileErrorin the event that the group_name cannot be found (with the Glib::KeyFileError::GROUP_NOT_FOUND code).
Parameters
group_nameA group name.
keyA key.
Returns
The value as a string.
GKeyFile* Glib::KeyFile::gobj ( )

Provides access to the underlying C instance.

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

Provides access to the underlying C instance.

GKeyFile* Glib::KeyFile::gobj_copy ( ) const

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

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_nameA 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_nameA group name.
keyA key name.
Returns
true if key is a part of group_name, false otherwise.
bool Glib::KeyFile::load_from_data ( const Glib::ustring data,
Flags  flags = Flags::NONE 
)

Loads a KeyFile from memory.

Parameters
dataThe data to use as a KeyFile
flagsBitwise 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,
Flags  flags = Flags::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
fileThe file to search for
[out]full_pathReturn location for a string containing the full path of the file
flagsBitwise 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 std::vector< std::string > &  search_dirs,
std::string full_path,
Flags  flags = Flags::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 found in any of the search_dirs, Glib::KeyFileError::NOT_FOUND is returned. If the file is found but the OS returns an error when opening or reading the file, a Glib::FileError is returned. If there is a problem parsing the file, a Glib::KeyFileError is returned.

Since glibmm 2.14:
Parameters
fileA relative path to a filename to open and parse.
search_dirsnullptr-terminated array of directories to search.
full_pathReturn location for a string containing the full path of the file, or nullptr.
flagsFlags from Glib::KeyFile::Flags.
Returns
true if a key file could be loaded, false otherwise.
Exceptions
Glib::KeyFileError
Glib::FileError
bool Glib::KeyFile::load_from_file ( const std::string file,
Flags  flags = Flags::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
fileThe path of a filename to load, in the GLib filename encoding.
flagsFlags from Glib::KeyFile::Flags.
Returns
true if a key file could be loaded, false otherwise.
void Glib::KeyFile::operator delete ( void *  ,
std::size_t   
)
protected
KeyFile& Glib::KeyFile::operator= ( const KeyFile )
delete
void Glib::KeyFile::reference ( ) const

Increment the reference count for this object.

You should never need to do this manually - use the object via a RefPtr instead.

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 nullptr then comment will be removed above group_name. If both key and group_name are nullptr, then comment will be removed above the first group in the file.

Exceptions
Glib::KeyFileError
Parameters
group_nameA group name, or nullptr.
keyA 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_nameA 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_nameA group name.
keyA 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().

If you need stricter guarantees about durability of the written file than are provided by g_file_set_contents(), use g_file_set_contents_full() with the return value of g_key_file_to_data().

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

Since glibmm 2.40:
Parameters
filenameThe name of the file to write to.
Returns
true if successful, else false with error set.
Exceptions
Glib::FileError
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_nameA group name.
keyA key.
valuetrue or false.
void Glib::KeyFile::set_boolean_list ( const Glib::ustring group_name,
const Glib::ustring key,
const std::vector< 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_nameThe name of a group
keyThe name of a key
listA 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
commentThe 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_nameThe Group the comment should be above
commentThe 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 nullptr then comment will be written above group_name. If both key and group_name are nullptr, then comment will be written above the first group in the file.

Exceptions
Glib::KeyFileError
Parameters
group_nameA group name, or nullptr.
keyA key.
commentA 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_nameA group name.
keyA key.
valueA 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
keyA key.
valueAn double value.
void Glib::KeyFile::set_double_list ( const Glib::ustring group_name,
const Glib::ustring key,
const std::vector< 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_nameThe name of a group
keyThe name of a key
listA 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_nameA group name.
keyA key.
valueAn 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_nameA group name.
keyA key.
valueAn integer value.
void Glib::KeyFile::set_integer_list ( const Glib::ustring group_name,
const Glib::ustring key,
const std::vector< 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_nameThe name of a group
keyThe name of a key
listA 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
separatorThe 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_nameA group name.
keyA key.
localeA locale identifier.
stringA string.
void Glib::KeyFile::set_locale_string_list ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ustring locale,
const std::vector< 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_nameThe name of a group
keyThe name of a key
localeA locale
listA 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_nameA group name.
keyA key.
stringA string.
void Glib::KeyFile::set_string_list ( const Glib::ustring group_name,
const Glib::ustring key,
const std::vector< 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_nameThe name of a group
keyThe name of a key
listA 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_nameA group name.
keyA key.
valueAn 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_nameA group name.
keyA key.
valueA 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
void Glib::KeyFile::unreference ( ) const

Decrement the reference count for this object.

You should never need to do this manually - use the object via a RefPtr instead.

Friends And Related Function Documentation

Glib::RefPtr< Glib::KeyFile > wrap ( GKeyFile *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.