glib.GKeyFile.KeyFile Class Reference

List of all members.

Detailed Description

Description 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 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 value shows # 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 are escaped as
, , , and \, respectively. To preserve leading spaces in values, these can also be escaped as . 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.


Public Member Functions

GKeyFilegetKeyFileStruct ()
 this (GKeyFile *gKeyFile)
 Sets our main struct and passes it to the parent class.
 this ()
 Creates a new empty GKeyFile object.
void free ()
 Frees a GKeyFile.
void setListSeparator (char separator)
 Sets the character which is used to separate values in lists.
int loadFromFile (char[] file, GKeyFileFlags flags, GError **error)
 Loads a key file into an empty GKeyFile structure.
int loadFromData (char[] data, uint length, GKeyFileFlags flags, GError **error)
 Loads a key file from memory into an empty GKeyFile structure.
int loadFromDataDirs (char[] file, char **fullPath, GKeyFileFlags flags, GError **error)
 This function looks for a key file named file in the paths returned from g_get_user_data_dir() and g_get_system_data_dirs(), loads the file into key_file and returns the file's full path in full_path.
char[] toData (uint *length, GError **error)
 This function outputs key_file as a string.
char[] getStartGroup ()
 Returns the name of the start group of the file.
char ** getGroups (uint *length)
 Returns all groups in the key file loaded with key_file.
char ** getKeys (char[] groupName, uint *length, GError **error)
 Returns all keys for the group name group_name.
int hasGroup (char[] groupName)
 Looks whether the key file has the group group_name.
int hasKey (char[] groupName, char[] key, GError **error)
 Looks whether the key file has the key key in the group group_name.
char[] getValue (char[] groupName, char[] key, GError **error)
 Returns the value associated with key under group_name.
char[] getString (char[] groupName, char[] key, GError **error)
 Returns the value associated with key under group_name.
char[] getLocaleString (char[] groupName, char[] key, char[] locale, GError **error)
 Returns the value associated with key under group_name translated in the given locale if available.
int getBoolean (char[] groupName, char[] key, GError **error)
 Returns the value associated with key under group_name as a boolean.
int getInteger (char[] groupName, char[] key, GError **error)
 Returns the value associated with key under group_name as an integer.
double getDouble (char[] groupName, char[] key, GError **error)
 Returns the value associated with key under group_name as an integer.
char ** getStringList (char[] groupName, char[] key, uint *length, GError **error)
 Returns the values associated with key under group_name.
char ** getLocaleStringList (char[] groupName, char[] key, char[] locale, uint *length, GError **error)
 Returns the values associated with key under group_name translated in the given locale if available.
intgetBooleanList (char[] groupName, char[] key, uint *length, GError **error)
 Returns the values associated with key under group_name as booleans.
intgetIntegerList (char[] groupName, char[] key, uint *length, GError **error)
 Returns the values associated with key under group_name as integers.
double * getDoubleList (char[] groupName, char[] key, uint *length, GError **error)
 Returns the values associated with key under group_name as doubles.
char[] getComment (char[] groupName, char[] key, GError **error)
 Retrieves a comment above key from group_name.
void setValue (char[] groupName, char[] key, char[] value)
 Associates a new value with key under group_name.
void setString (char[] groupName, char[] key, char[] string)
 Associates a new string value with key under group_name.
void setLocaleString (char[] groupName, char[] key, char[] locale, char[] string)
 Associates a string value for key and locale under group_name.
void setBoolean (char[] groupName, char[] key, int value)
 Associates a new boolean value with key under group_name.
void setInteger (char[] groupName, char[] key, int value)
 Associates a new integer value with key under group_name.
void setDouble (char[] groupName, char[] key, double value)
 Associates a new double value with key under group_name.
void setStringList (char[] groupName, char[] key)
 Associates a list of string values for key under group_name.
void setLocaleStringList (char[] groupName, char[] key, char[] locale)
 Associates a list of string values for key and locale under group_name.
void setBooleanList (char[] groupName, char[] key, int[] list, uint length)
 Associates a list of boolean values with key under group_name.
void setIntegerList (char[] groupName, char[] key, int[] list, uint length)
 Associates a list of integer values with key under group_name.
void setDoubleList (char[] groupName, char[] key, double[] list, uint length)
 Associates a list of double values with key under group_name.
void setComment (char[] groupName, char[] key, char[] comment, GError **error)
 Places a comment above key from group_name.
void removeGroup (char[] groupName, GError **error)
 Removes the specified group, group_name, from the key file.
void removeKey (char[] groupName, char[] key, GError **error)
 Removes key in group_name from the key file.
void removeComment (char[] groupName, char[] key, GError **error)
 Removes a comment above key from group_name.

Protected Member Functions

void * getStruct ()
 the main Gtk struct as a void*

Protected Attributes

GKeyFilegKeyFile
 the main Gtk struct


Constructor & Destructor Documentation

glib.GKeyFile.KeyFile.this ( GKeyFile gKeyFile  ) 

Sets our main struct and passes it to the parent class.

glib.GKeyFile.KeyFile.this (  ) 

Creates a new empty GKeyFile object.

Use g_key_file_load_from_file(), g_key_file_load_from_data() or g_key_file_load_from_data_dirs() to read an existing key file. Returns: an empty GKeyFile. Since 2.6


Member Function Documentation

void glib.GKeyFile.KeyFile.free (  ) 

Frees a GKeyFile.

key_file: a GKeyFile Since 2.6

int glib.GKeyFile.KeyFile.getBoolean ( char[]  groupName,
char[]  key,
GError **  error 
)

Returns the value associated with key under group_name as a boolean.

If key cannot be found then the return value is undefined and error is set to G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the value associated with key cannot be interpreted as a boolean then the return value is also undefined and error is set to G_KEY_FILE_ERROR_INVALID_VALUE. key_file: a GKeyFile group_name: a group name key: a key error: return location for a GError Returns: the value associated with the key as a boolean Since 2.6

int* glib.GKeyFile.KeyFile.getBooleanList ( char[]  groupName,
char[]  key,
uint length,
GError **  error 
)

Returns the values associated with key under group_name as booleans.

If group_name is NULL, the start_group is used. If key cannot be found then the return value is undefined and error is set to G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the values associated with key cannot be interpreted as booleans then the return value is also undefined and error is set to G_KEY_FILE_ERROR_INVALID_VALUE. key_file: a GKeyFile group_name: a group name key: a key length: the number of booleans returned error: return location for a GError Returns: the values associated with the key as a boolean Since 2.6

char [] glib.GKeyFile.KeyFile.getComment ( char[]  groupName,
char[]  key,
GError **  error 
)

Retrieves a comment above key from group_name.

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. key_file: a GKeyFile group_name: a group name, or NULL key: a key error: return location for a GError Returns: a comment that should be freed with g_free() Since 2.6

double glib.GKeyFile.KeyFile.getDouble ( char[]  groupName,
char[]  key,
GError **  error 
)

Returns the value associated with key under group_name as an integer.

If group_name is NULL, the start_group is used. If key cannot be found then the return value is undefined and error is set to G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the value associated with key cannot be interpreted as a double then the return value is also undefined and error is set to G_KEY_FILE_ERROR_INVALID_VALUE. key_file: a GKeyFile group_name: a group name key: a key error: return location for a GError Returns: the value associated with the key as a double. Since 2.12

double* glib.GKeyFile.KeyFile.getDoubleList ( char[]  groupName,
char[]  key,
uint length,
GError **  error 
)

Returns the values associated with key under group_name as doubles.

If group_name is NULL, the start group is used. If key cannot be found then the return value is undefined and error is set to G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the values associated with key cannot be interpreted as doubles then the return value is also undefined and error is set to G_KEY_FILE_ERROR_INVALID_VALUE. key_file: a GKeyFile group_name: a group name key: a key length: the number of doubles returned error: return location for a GError Returns: the values associated with the key as a double Since 2.12

char** glib.GKeyFile.KeyFile.getGroups ( uint length  ) 

Returns all groups in the key file loaded with key_file.

The array of returned groups will be NULL-terminated, so length may optionally be NULL. key_file: a GKeyFile length: return location for the number of returned groups, or NULL Returns: a newly-allocated NULL-terminated array of strings. Use g_strfreev() to free it. Since 2.6

int glib.GKeyFile.KeyFile.getInteger ( char[]  groupName,
char[]  key,
GError **  error 
)

Returns the value associated with key under group_name as an integer.

If group_name is NULL, the start_group is used. If key cannot be found then the return value is undefined and error is set to G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the value associated with key cannot be interpreted as an integer then the return value is also undefined and error is set to G_KEY_FILE_ERROR_INVALID_VALUE. key_file: a GKeyFile group_name: a group name key: a key error: return location for a GError Returns: the value associated with the key as an integer. Since 2.6

int* glib.GKeyFile.KeyFile.getIntegerList ( char[]  groupName,
char[]  key,
uint length,
GError **  error 
)

Returns the values associated with key under group_name as integers.

If key cannot be found then the return value is undefined and error is set to G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the values associated with key cannot be interpreted as integers then the return value is also undefined and error is set to G_KEY_FILE_ERROR_INVALID_VALUE. key_file: a GKeyFile group_name: a group name key: a key length: the number of integers returned error: return location for a GError Returns: the values associated with the key as a integer Since 2.6

GKeyFile* glib.GKeyFile.KeyFile.getKeyFileStruct (  ) 

char** glib.GKeyFile.KeyFile.getKeys ( char[]  groupName,
uint length,
GError **  error 
)

Returns all keys for the group name group_name.

The array of returned keys will be NULL-terminated, so length may optionally be NULL. In the event that the group_name cannot be found, NULL is returned and error is set to G_KEY_FILE_ERROR_GROUP_NOT_FOUND. key_file: a GKeyFile group_name: a group name length: return location for the number of keys returned, or NULL error: return location for a GError, or NULL Returns: a newly-allocated NULL-terminated array of strings. Use g_strfreev() to free it. Since 2.6

char [] glib.GKeyFile.KeyFile.getLocaleString ( char[]  groupName,
char[]  key,
char[]  locale,
GError **  error 
)

Returns the value associated with key under group_name translated in the given locale if available.

If locale is NULL then the current locale is assumed. If key cannot be found then NULL is returned and error is set to G_KEY_FILE_ERROR_KEY_NOT_FOUND. If the value associated with key cannot be interpreted or no suitable translation can be found then the untranslated value is returned. key_file: a GKeyFile group_name: a group name key: a key locale: a locale or NULL error: return location for a GError, or NULL Returns: a newly allocated string or NULL if the specified key cannot be found. Since 2.6

char** glib.GKeyFile.KeyFile.getLocaleStringList ( char[]  groupName,
char[]  key,
char[]  locale,
uint length,
GError **  error 
)

Returns the values associated with key under group_name translated in the given locale if available.

If locale is NULL then the current locale is assumed. If key cannot be found then NULL is returned and error is set to G_KEY_FILE_ERROR_KEY_NOT_FOUND. If the values associated with key cannot be interpreted or no suitable translations can be found then the untranslated values are returned. The returned array is NULL-terminated, so length may optionally be NULL. key_file: a GKeyFile group_name: a group name key: a key locale: a locale length: return location for the number of returned strings or NULL error: return location for a GError or NULL Returns: a newly allocated NULL-terminated string array or NULL if the key isn't found. The string array should be freed with g_strfreev(). Since 2.6

char [] glib.GKeyFile.KeyFile.getStartGroup (  ) 

Returns the name of the start group of the file.

key_file: a GKeyFile Returns: The start group of the key file. Since 2.6

char [] glib.GKeyFile.KeyFile.getString ( char[]  groupName,
char[]  key,
GError **  error 
)

Returns the value associated with key under group_name.

In the event the key cannot be found, NULL is returned and error is set to G_KEY_FILE_ERROR_KEY_NOT_FOUND. In the event that the group_name cannot be found, NULL is returned and error is set to G_KEY_FILE_ERROR_GROUP_NOT_FOUND. key_file: a GKeyFile group_name: a group name key: a key error: return location for a GError, or NULL Returns: a newly allocated string or NULL if the specified key cannot be found. Since 2.6

char** glib.GKeyFile.KeyFile.getStringList ( char[]  groupName,
char[]  key,
uint length,
GError **  error 
)

Returns the values associated with key under group_name.

In the event the key cannot be found, NULL is returned and error is set to G_KEY_FILE_ERROR_KEY_NOT_FOUND. In the event that the group_name cannot be found, NULL is returned and error is set to G_KEY_FILE_ERROR_GROUP_NOT_FOUND. key_file: a GKeyFile group_name: a group name key: a key length: return location for the number of returned strings, or NULL error: return location for a GError, or NULL Returns: a NULL-terminated string array or NULL if the specified key cannot be found. The array should be freed with g_strfreev(). Since 2.6

void* glib.GKeyFile.KeyFile.getStruct (  )  [protected]

the main Gtk struct as a void*

char [] glib.GKeyFile.KeyFile.getValue ( char[]  groupName,
char[]  key,
GError **  error 
)

Returns the value associated with key under group_name.

In the event the key cannot be found, NULL is returned and error is set to G_KEY_FILE_ERROR_KEY_NOT_FOUND. In the event that the group_name cannot be found, NULL is returned and error is set to G_KEY_FILE_ERROR_GROUP_NOT_FOUND. key_file: a GKeyFile group_name: a group name key: a key error: return location for a GError, or NULL Returns: a newly allocated string or NULL if the specified key cannot be found. Since 2.6

int glib.GKeyFile.KeyFile.hasGroup ( char[]  groupName  ) 

Looks whether the key file has the group group_name.

key_file: a GKeyFile group_name: a group name Returns: TRUE if group_name is a part of key_file, FALSE otherwise. Since 2.6

int glib.GKeyFile.KeyFile.hasKey ( char[]  groupName,
char[]  key,
GError **  error 
)

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

key_file: a GKeyFile group_name: a group name key: a key name error: return location for a GError Returns: TRUE if key is a part of group_name, FALSE otherwise. Since 2.6

int glib.GKeyFile.KeyFile.loadFromData ( char[]  data,
uint  length,
GKeyFileFlags  flags,
GError **  error 
)

Loads a key file from memory into an empty GKeyFile structure.

If the object cannot be created then error is set to a GKeyFileError. key_file: an empty GKeyFile struct data: key file loaded in memory. length: the length of data in bytes flags: flags from GKeyFileFlags error: return location for a GError, or NULL Returns: TRUE if a key file could be loaded, FALSE othewise Since 2.6

int glib.GKeyFile.KeyFile.loadFromDataDirs ( char[]  file,
char **  fullPath,
GKeyFileFlags  flags,
GError **  error 
)

This function looks for a key file named file in the paths returned from g_get_user_data_dir() and g_get_system_data_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 GFileError or GKeyFileError. key_file: an empty GKeyFile struct file: a relative path to a filename to open and parse full_path: return location for a string containing the full path of the file, or NULL flags: flags from GKeyFileFlags error: return location for a GError, or NULL Returns: TRUE if a key file could be loaded, FALSE othewise Since 2.6

int glib.GKeyFile.KeyFile.loadFromFile ( char[]  file,
GKeyFileFlags  flags,
GError **  error 
)

Loads a key file into an empty GKeyFile structure.

If the file could not be loaded then error is set to either a GFileError or GKeyFileError. key_file: an empty GKeyFile struct file: the path of a filename to load, in the GLib file name encoding flags: flags from GKeyFileFlags error: return location for a GError, or NULL Returns: TRUE if a key file could be loaded, FALSE othewise Since 2.6

void glib.GKeyFile.KeyFile.removeComment ( char[]  groupName,
char[]  key,
GError **  error 
)

Removes a comment above key from group_name.

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. key_file: a GKeyFile group_name: a group name, or NULL key: a key error: return location for a GError Since 2.6

void glib.GKeyFile.KeyFile.removeGroup ( char[]  groupName,
GError **  error 
)

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

key_file: a GKeyFile group_name: a group name error: return location for a GError or NULL Since 2.6

void glib.GKeyFile.KeyFile.removeKey ( char[]  groupName,
char[]  key,
GError **  error 
)

Removes key in group_name from the key file.

key_file: a GKeyFile group_name: a group name key: a key name to remove error: return location for a GError or NULL Since 2.6

void glib.GKeyFile.KeyFile.setBoolean ( char[]  groupName,
char[]  key,
int  value 
)

Associates a new boolean value with key under group_name.

If key cannot be found then it is created. key_file: a GKeyFile group_name: a group name key: a key value: TRUE or FALSE Since 2.6

void glib.GKeyFile.KeyFile.setBooleanList ( char[]  groupName,
char[]  key,
int[]  list,
uint  length 
)

Associates a list of boolean values with key under group_name.

If key cannot be found then it is created. If group_name is NULL, the start_group is used. key_file: a GKeyFile group_name: a group name key: a key list: an array of boolean values length: length of list Since 2.6

void glib.GKeyFile.KeyFile.setComment ( char[]  groupName,
char[]  key,
char[]  comment,
GError **  error 
)

Places a comment above key from group_name.

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. key_file: a GKeyFile group_name: a group name, or NULL key: a key comment: a comment error: return location for a GError Since 2.6

void glib.GKeyFile.KeyFile.setDouble ( char[]  groupName,
char[]  key,
double  value 
)

Associates a new double value with key under group_name.

If key cannot be found then it is created. If group_name is NULL, the start group is used. key_file: a GKeyFile group_name: a group name key: a key value: an double value Since 2.12

void glib.GKeyFile.KeyFile.setDoubleList ( char[]  groupName,
char[]  key,
double[]  list,
uint  length 
)

Associates a list of double values with key under group_name.

If key cannot be found then it is created. If group_name is NULL the start group is used. key_file: a GKeyFile group_name: a group name key: a key list: an array of double values length: number of double values in list Since 2.12

void glib.GKeyFile.KeyFile.setInteger ( char[]  groupName,
char[]  key,
int  value 
)

Associates a new integer value with key under group_name.

If key cannot be found then it is created. key_file: a GKeyFile group_name: a group name key: a key value: an integer value Since 2.6

void glib.GKeyFile.KeyFile.setIntegerList ( char[]  groupName,
char[]  key,
int[]  list,
uint  length 
)

Associates a list of integer values with key under group_name.

If key cannot be found then it is created. key_file: a GKeyFile group_name: a group name key: a key list: an array of integer values length: number of integer values in list Since 2.6

void glib.GKeyFile.KeyFile.setListSeparator ( char  separator  ) 

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

Typically ';' or ',' are used as separators. The default list separator is ';'. key_file: a GKeyFile separator: the separator Since 2.6

void glib.GKeyFile.KeyFile.setLocaleString ( char[]  groupName,
char[]  key,
char[]  locale,
char[]  string 
)

Associates a string value for key and locale under group_name.

If the translation for key cannot be found then it is created. key_file: a GKeyFile group_name: a group name key: a key locale: a locale string: a string Since 2.6

void glib.GKeyFile.KeyFile.setLocaleStringList ( char[]  groupName,
char[]  key,
char[]  locale 
)

Associates a list of string values for key and locale under group_name.

If the translation for key cannot be found then it is created. key_file: a GKeyFile group_name: a group name key: a key locale: a locale Since 2.6

void glib.GKeyFile.KeyFile.setString ( char[]  groupName,
char[]  key,
char[]  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. key_file: a GKeyFile group_name: a group name key: a key string: a string Since 2.6

void glib.GKeyFile.KeyFile.setStringList ( char[]  groupName,
char[]  key 
)

Associates a list of string values for key under group_name.

If key cannot be found then it is created. If group_name cannot be found then it is created. key_file: a GKeyFile group_name: a group name key: a key Since 2.6

void glib.GKeyFile.KeyFile.setValue ( char[]  groupName,
char[]  key,
char[]  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. key_file: a GKeyFile group_name: a group name key: a key value: a string Since 2.6

char [] glib.GKeyFile.KeyFile.toData ( uint length,
GError **  error 
)

This function outputs key_file as a string.

key_file: a GKeyFile length: return location for the length of the returned string, or NULL error: return location for a GError, or NULL Returns: a newly allocated string holding the contents of the GKeyFile Since 2.6


Member Data Documentation

GKeyFile* glib.GKeyFile.KeyFile.gKeyFile [protected]

the main Gtk struct


SourceForge.net Logo DSource.org Logo digitalmars.com Logo