歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

鍵值形式的文件解析api-解析類ini形式的配置文件

函數

GKeyFile *g_key_file_new ()

voidg_key_file_free ()

GKeyFile *g_key_file_ref ()

voidg_key_file_unref ()

voidg_key_file_set_list_separator ()

gbooleang_key_file_load_from_file ()

gbooleang_key_file_load_from_data ()

gbooleang_key_file_load_from_data_dirs ()

gbooleang_key_file_load_from_dirs ()

gchar *g_key_file_to_data ()

gbooleang_key_file_save_to_file ()

gchar *g_key_file_get_start_group ()

gchar **g_key_file_get_groups ()

gchar **g_key_file_get_keys ()

gbooleang_key_file_has_group ()

gbooleang_key_file_has_key ()

gchar *g_key_file_get_value ()

gchar *g_key_file_get_string ()

gchar *g_key_file_get_locale_string ()

gbooleang_key_file_get_boolean ()

gintg_key_file_get_integer ()

gint64g_key_file_get_int64 ()

guint64g_key_file_get_uint64 ()

gdoubleg_key_file_get_double ()

gchar **g_key_file_get_string_list ()

gchar **g_key_file_get_locale_string_list ()

gboolean *g_key_file_get_boolean_list ()

gint *g_key_file_get_integer_list ()

gdouble *g_key_file_get_double_list ()

gchar *g_key_file_get_comment ()

voidg_key_file_set_value ()

voidg_key_file_set_string ()

voidg_key_file_set_locale_string ()

voidg_key_file_set_boolean ()

voidg_key_file_set_integer ()

voidg_key_file_set_int64 ()

voidg_key_file_set_uint64 ()

voidg_key_file_set_double ()

voidg_key_file_set_string_list ()

voidg_key_file_set_locale_string_list ()

voidg_key_file_set_boolean_list ()

voidg_key_file_set_integer_list ()

voidg_key_file_set_double_list ()

gbooleang_key_file_set_comment ()

gbooleang_key_file_remove_group ()

gbooleang_key_file_remove_key ()

gbooleang_key_file_remove_comment ()

類型和常值

GKeyFile

#defineG_KEY_FILE_ERROR

enumGKeyFileError

enumGKeyFileFlags

#defineG_KEY_FILE_DESKTOP_GROUP

#defineG_KEY_FILE_DESKTOP_KEY_TYPE

#defineG_KEY_FILE_DESKTOP_KEY_VERSION

#defineG_KEY_FILE_DESKTOP_KEY_NAME

#defineG_KEY_FILE_DESKTOP_KEY_GENERIC_NAME

#defineG_KEY_FILE_DESKTOP_KEY_NO_DISPLAY

#defineG_KEY_FILE_DESKTOP_KEY_COMMENT

#defineG_KEY_FILE_DESKTOP_KEY_ICON

#defineG_KEY_FILE_DESKTOP_KEY_HIDDEN

#defineG_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN

#defineG_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN

#defineG_KEY_FILE_DESKTOP_KEY_TRY_EXEC

#defineG_KEY_FILE_DESKTOP_KEY_EXEC

#defineG_KEY_FILE_DESKTOP_KEY_PATH

#defineG_KEY_FILE_DESKTOP_KEY_TERMINAL

#defineG_KEY_FILE_DESKTOP_KEY_MIME_TYPE

#defineG_KEY_FILE_DESKTOP_KEY_CATEGORIES

#defineG_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY

#defineG_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS

#defineG_KEY_FILE_DESKTOP_KEY_URL

#defineG_KEY_FILE_DESKTOP_KEY_ACTIONS

#defineG_KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE

#defineG_KEY_FILE_DESKTOP_TYPE_APPLICATION

#defineG_KEY_FILE_DESKTOP_TYPE_LINK

#defineG_KEY_FILE_DESKTOP_TYPE_DIRECTORY

使用時需添加引用

#include

描述

使用GKeyFile可以解析、編輯或者創建包含使用分組形式的鍵值對格式的文件。姑且稱這種文件為“鍵值”文件。freedesktop.org中的有些配置文件使用了這種格式,如Desktop Entry Specification和Icon Theme Specification等。

“鍵值”文件的詳細語法可以參考Desktop Entry Specification。此處僅做簡要介紹。

“鍵值”文件是由多個分組形式的鍵值對組成,其中可以包含注釋。示例如下:

# this is just an example

# there can be comments before the first group

[First Group]

Name=Key File Example\tthis value shows\nescaping

# localized strings are stored in multiple key-value pairs

Welcome=Hello

Welcome[de]=Hallo

Welcome[fr_FR]=Bonjour

Welcome[it]=Ciao

Welcome[be@latin]=Hello

[Another Group]

Numbers=2;20;-200;0

Booleans=true;false;true;true

以'#'開頭的行和空行為注釋行。

分組的起始行由‘[’和‘]’包含的分組名。下一個分組的開始或文件尾表示分組的結束。每一個鍵值對必須包含在一個分組中。

鍵值對通常的形式為鍵=值。 但對於本地化字符串,其表示形式為鍵[locale]=值,其中lang_COUNTRY@MODIFIER中,COUNTRY和MODIFIER是可選的。忽略'='前後的空格。換行符,制表符,回車符和反斜槓字符分別使用\n,\t, \r和 \表示。 To preserve leading spaces in values,these can also be escaped as \s.

鍵值文件可以存儲字符串、整數、布爾值和列表。列表通常使用';'或者 ','分隔符進行分割。要在列表值中使用列表分隔符,必須加上一個反斜槓轉義前綴。

鍵值文件的格式與Windows平台的ini文件類似,但是二者有明顯的差異:

.ini文件使用 ';注釋行,鍵值文件使用 '#'注釋行;

鍵值文件不允許又未分組鍵值對,即第一個分組前的所有內容都必須是注釋;

鍵值文件的編碼格式為UTF-8;

鍵值文件中鍵和值是大小寫敏感的,比如[GROUP]和[group]表示兩個不同的分組。

.ini文件中沒有boolean類型,只能用GetProfileInt()獲取整形數表示boolean類型,而鍵值文件只能使用true和false(必須小寫)表示boolean類型。

注意與Desktop Entry Specification相比,一個鍵可以在同一個分組中出現多次,但只有最後一個有效。鍵值文件中也可以出現多個名稱相同的分組,每個分組下的鍵值對均有效。另一個區別是分組和鍵的名稱並不僅限於ASCII字符。

接口函數

g_key_file_new ()

GKeyFile * g_key_file_new (void);

創建空的GKeyFile 對象。可以使用g_key_file_load_from_file(),g_key_file_load_from_data(),g_key_file_load_from_dirs() 或者 g_key_file_load_from_data_dirs() 從已有GKeyFile 對象讀取書記。

返回值:空的GKeyFile.

適用版本:2.6及以上

g_key_file_free ()

void g_key_file_free (GKeyFile *key_file);

釋放key_file中的所有鍵和組,引用計數減1。如果引用計數到0是,釋放GkeyFile及所有已分配的內存。

參數:

key_fileGKeyFile

適用版本:2.6及以上

g_key_file_ref ()

GKeyFile * g_key_file_ref (GKeyFile *key_file);

增加鍵值文件key_file的引用計數

參數

key_file鍵值文件GKeyFile

返回值

與輸入參數的鍵值文件key_file相同

適用版本:2.32及以上

g_key_file_unref ()

void g_key_file_unref (GKeyFile *key_file);

對鍵值文件key_file的引用計數減1。如果減1後引用計數為0,則釋放鍵值文件及其分配的內存。

參數

key_file鍵值文件GKeyFile

適用版本:2.32及以上

g_key_file_set_list_separator ()

void g_key_file_set_list_separator (GKeyFile *key_file,gchar separator);

設置列表值的分隔符,通常使用';'或者','作為分隔符,默認使用';'。

參數

key_file鍵值文件GKeyFile

separator分隔符

適用版本:2.6及以上

g_key_file_load_from_file ()

gboolean g_key_file_load_from_file (GKeyFile *key_file,const gchar *file,GKeyFileFlags flags,GError **error);

加載鍵值文件到一個空的GKeyFile結構。如果加載失敗,返回的錯誤為GFileError或者GKeyFileError。

參數

key_file一個空的GKeyFile結構

file鍵值文件的路徑,使用GLib文件編碼[type filename]

flags參見 GKeyFileFlags

error加載失敗時返回GError或者NULL

Returns

加載成功返回TRUE,否則返回FALSE

適用版本:2.6及以上

g_key_file_load_from_data ()

gboolean

g_key_file_load_from_data (GKeyFile *key_file,const gchar *data,gsize length,GKeyFileFlags flags,GError **error);

從內存中加載到一個空的GKeyFile結構, 如果加載失敗則設置error為GKeyFileError。

參數

key_file一個空的GKeyFile結構

data內存中的鍵值文件

lengthdata變量的字節大小(如果以空字符結束則問長度-1)the length of datain bytes (or (gsize)-1 if data is nul-terminated)

flags參見GKeyFileFlags

error加載失敗時返回GError或者NULL

返回

加載成功返回TRUE,否則返回FALSE

適用版本:2.6及以上

g_key_file_load_from_data_dirs ()

gboolean g_key_file_load_from_data_dirs (GKeyFile *key_file,const gchar *file,gchar **full_path,GKeyFileFlags flags,GError **error);

This function looks for a key file named file in the paths returned fromg_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 isset to either a GFileError or GKeyFileError.

Parameters

key_filean empty GKeyFile struct

filea relative path to a filename to open and parse.[type filename]

full_pathreturn location for a string containing the full pathof the file, or NULL.[out][type filename][allow-none]

flagsflags from GKeyFileFlags

errorreturn location for a GError, or NULL

Returns

TRUE if a key file could be loaded,FALSE othewise

Since: 2.6

g_key_file_load_from_dirs ()

gboolean

g_key_file_load_from_dirs (GKeyFile *key_file,

const gchar *file,

const gchar **search_dirs,

gchar **full_path,

GKeyFileFlags flags,

GError **error);

This function looks for a key file named file in the pathsspecified insearch_dirs, loads the file intokey_file andreturns the file's full path infull_path. If the file could notbe loaded then anerror is set to either aGFileError orGKeyFileError.

Parameters

key_filean empty GKeyFile struct

filea relative path to a filename to open and parse.[type filename]

search_dirsNULL-terminated array of directories to search.[array zero-terminated=1][element-type filename]

full_pathreturn location for a string containing the full pathof the file, or NULL.[out][type filename][allow-none]

flagsflags from GKeyFileFlags

errorreturn location for a GError, or NULL

Returns

TRUE if a key file could be loaded,FALSE otherwise

Since: 2.14

g_key_file_to_data ()

gchar *

g_key_file_to_data (GKeyFile *key_file,

gsize *length,

GError **error);

This function outputs key_file as a string.

Note that this function never reports an error,so it is safe to pass NULL as error.

Parameters

key_filea GKeyFile

lengthreturn location for the length of thereturned string, or NULL.[out][allow-none]

errorreturn location for a GError, or NULL

Returns

a newly allocated string holdingthe contents of the GKeyFile

Since: 2.6

g_key_file_save_to_file ()

gboolean

g_key_file_save_to_file (GKeyFile *key_file,

const gchar *filename,

GError **error);

Writes the contents of key_file to filename usingg_file_set_contents().

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

Parameters

key_filea GKeyFile

filenamethe name of the file to write to

errora pointer to a NULL GError, or NULL

Returns

TRUE if successful, elseFALSE with errorset

Since: 2.40

g_key_file_get_start_group ()

gchar *

g_key_file_get_start_group (GKeyFile *key_file);

Returns the name of the start group of the file.

Parameters

key_filea GKeyFile

Returns

The start group of the key file.

Since: 2.6

g_key_file_get_groups ()

gchar **

g_key_file_get_groups (GKeyFile *key_file,

gsize *length);

Returns all groups in the key file loaded with key_file. The array of returned groups will beNULL-terminated, so length may optionally beNULL.

Parameters

key_filea GKeyFile

lengthreturn location for the number of returned groups, or NULL.[out][allow-none]

Returns

a newly-allocated NULL-terminated array of strings.Use g_strfreev() to free it.

[array zero-terminated=1][transfer full]

Since: 2.6

g_key_file_get_keys ()

gchar **

g_key_file_get_keys (GKeyFile *key_file,

const gchar *group_name,

gsize *length,

GError **error);

Returns all keys for the group name group_name. The array ofreturned keys will beNULL-terminated, so length mayoptionally beNULL. In the event that the group_name cannotbe found,NULL is returned and error is set toG_KEY_FILE_ERROR_GROUP_NOT_FOUND.

Parameters

key_filea GKeyFile

group_namea group name

lengthreturn location for the number of keys returned, or NULL.[out][allow-none]

errorreturn location for a GError, or NULL

Returns

a newly-allocated NULL-terminated array of strings.Use g_strfreev() to free it.

[array zero-terminated=1][transfer full]

Since: 2.6

g_key_file_has_group ()

gboolean

g_key_file_has_group (GKeyFile *key_file,

const gchar *group_name);

Looks whether the key file has the group group_name.

Parameters

key_filea GKeyFile

group_namea group name

Returns

TRUE ifgroup_nameis a part ofkey_file,FALSEotherwise.

Since: 2.6

g_key_file_has_key ()

gboolean

g_key_file_has_key (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

GError **error);

Looks whether the key file has the key key in the groupgroup_name.

Note that this function does not follow the rules for GError strictly;the return value both carries meaning and signals an error. To usethis function, you must pass aGError pointer in error, and checkwhether it is notNULL to see if an error occurred.

Language bindings should use g_key_file_get_value() to test whetheror not a key exists.

[skip]

Parameters

key_filea GKeyFile

group_namea group name

keya key name

errorreturn location for a GError

Returns

TRUE ifkeyis a part ofgroup_name,FALSE otherwise

Since: 2.6

g_key_file_get_value ()

gchar *

g_key_file_get_value (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

GError **error);

Returns the raw value associated with key undergroup_name. Useg_key_file_get_string() to retrieve an unescaped UTF-8 string.

In the event the key cannot be found, NULL is returned and error is set toG_KEY_FILE_ERROR_KEY_NOT_FOUND. In the event that thegroup_name cannot be found,NULL is returned and error is set toG_KEY_FILE_ERROR_GROUP_NOT_FOUND.

Parameters

key_filea GKeyFile

group_namea group name

keya key

errorreturn location for a GError, or NULL

Returns

a newly allocated string or NULL if the specifiedkey cannot be found.

Since: 2.6

g_key_file_get_string ()

gchar *

g_key_file_get_string (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

GError **error);

Returns the string value associated with key undergroup_name.Unlikeg_key_file_get_value(), this function handles escape sequenceslike \s.

In the event the key cannot be found, NULL is returned and error is set toG_KEY_FILE_ERROR_KEY_NOT_FOUND. In the event that thegroup_name cannot be found,NULL is returned and error is set toG_KEY_FILE_ERROR_GROUP_NOT_FOUND.

Parameters

key_filea GKeyFile

group_namea group name

keya key

errorreturn location for a GError, or NULL

Returns

a newly allocated string or NULL if the specifiedkey cannot be found.

Since: 2.6

g_key_file_get_locale_string ()

gchar *

g_key_file_get_locale_string (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

const gchar *locale,

GError **error);

Returns the value associated with key undergroup_nametranslated in the givenlocale if available. Iflocale isNULL then the current locale is assumed.

If key cannot be found then NULL is returned and error is set toG_KEY_FILE_ERROR_KEY_NOT_FOUND. If the value associatedwithkey cannot be interpreted or no suitable translation canbe found then the untranslated value is returned.

Parameters

key_filea GKeyFile

group_namea group name

keya key

localea locale identifier or NULL.[allow-none]

errorreturn location for a GError, or NULL

Returns

a newly allocated string or NULL if the specifiedkey cannot be found.

Since: 2.6

g_key_file_get_boolean ()

gboolean

g_key_file_get_boolean (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

GError **error);

Returns the value associated with key undergroup_name as aboolean.

If key cannot be found then FALSE is returned and error is settoG_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the valueassociated withkey cannot be interpreted as a boolean thenFALSEis returned and error is set toG_KEY_FILE_ERROR_INVALID_VALUE.

Parameters

key_filea GKeyFile

group_namea group name

keya key

errorreturn location for a GError

Returns

the value associated with the key as a boolean,or FALSE if the key was not found or could not be parsed.

Since: 2.6

g_key_file_get_integer ()

gint

g_key_file_get_integer (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

GError **error);

Returns the value associated with key undergroup_name as aninteger.

If key cannot be found then 0 is returned anderror is set toG_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the value associatedwith key cannot be interpreted as an integer then 0 is returnedanderror is set toG_KEY_FILE_ERROR_INVALID_VALUE.

Parameters

key_filea GKeyFile

group_namea group name

keya key

errorreturn location for a GError

Returns

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

Since: 2.6

g_key_file_get_int64 ()

gint64

g_key_file_get_int64 (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

GError **error);

Returns the value associated with key undergroup_name as a signed64-bit integer. This is similar tog_key_file_get_integer() but can return64-bit results without truncation.

Parameters

key_filea non-NULLGKeyFile

group_namea non-NULL group name

keya non-NULL key

errorreturn location for a GError

Returns

the value associated with the key as a signed 64-bit integer, or0 if the key was not found or could not be parsed.

Since: 2.26

g_key_file_get_uint64 ()

guint64

g_key_file_get_uint64 (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

GError **error);

Returns the value associated with key undergroup_name as an unsigned64-bit integer. This is similar tog_key_file_get_integer() but can returnlarge positive results without truncation.

Parameters

key_filea non-NULLGKeyFile

group_namea non-NULL group name

keya non-NULL key

errorreturn location for a GError

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.

Since: 2.26

g_key_file_get_double ()

gdouble

g_key_file_get_double (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

GError **error);

Returns the value associated with key undergroup_name as adouble. Ifgroup_name isNULL, the start_group is used.

If key cannot be found then 0.0 is returned anderror is set toG_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the value associatedwith key cannot be interpreted as a double then 0.0 is returnedanderror is set toG_KEY_FILE_ERROR_INVALID_VALUE.

Parameters

key_filea GKeyFile

group_namea group name

keya key

errorreturn location for a GError

Returns

the value associated with the key as a double, or0.0 if the key was not found or could not be parsed.

Since: 2.12

g_key_file_get_string_list ()

gchar **

g_key_file_get_string_list (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

gsize *length,

GError **error);

Returns the values associated with key undergroup_name.

In the event the key cannot be found, NULL is returned anderror is set toG_KEY_FILE_ERROR_KEY_NOT_FOUND. In theevent that thegroup_name cannot be found,NULL is returnedand error is set toG_KEY_FILE_ERROR_GROUP_NOT_FOUND.

Parameters

key_filea GKeyFile

group_namea group name

keya key

lengthreturn location for the number of returned strings, or NULL.[out][allow-none]

errorreturn location for a GError, or NULL

Returns

a NULL-terminated string array or NULL if the specifiedkey cannot be found. The array should be freed withg_strfreev().

[array zero-terminated=1 length=length][element-type utf8][transfer full]

Since: 2.6

g_key_file_get_locale_string_list ()

gchar **

g_key_file_get_locale_string_list (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

const gchar *locale,

gsize *length,

GError **error);

Returns the values associated with key undergroup_nametranslated in the givenlocale if available. Iflocale isNULL then the current locale is assumed.

If key cannot be found then NULL is returned and error is set toG_KEY_FILE_ERROR_KEY_NOT_FOUND. If the values associatedwithkey cannot be interpreted or no suitable translationscan be found then the untranslated values are returned. The returned array isNULL-terminated, so length may optionally beNULL.

Parameters

key_filea GKeyFile

group_namea group name

keya key

localea locale identifier or NULL.[allow-none]

lengthreturn location for the number of returned strings or NULL.[out][allow-none]

errorreturn location for a GError or NULL

Returns

a newly allocated NULL-terminated string arrayor NULL if the key isn't found. The string array should be freedwithg_strfreev().

[array zero-terminated=1 length=length][element-type utf8][transfer full]

Since: 2.6

g_key_file_get_boolean_list ()

gboolean *

g_key_file_get_boolean_list (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

gsize *length,

GError **error);

Returns the values associated with key undergroup_name asbooleans.

If key cannot be found then NULL is returned and error is set toG_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the values associatedwith key cannot be interpreted as booleans thenNULL is returnedand error is set toG_KEY_FILE_ERROR_INVALID_VALUE.

Parameters

key_filea GKeyFile

group_namea group name

keya key

lengththe number of booleans returned.[out]

errorreturn location for a GError

Returns

the values associated with the key as a list of booleans, or NULL if thekey was not found or could not be parsed. The returned list of booleansshould be freed withg_free() when no longer needed.

[array length=length][element-type gboolean][transfer container]

Since: 2.6

g_key_file_get_integer_list ()

gint *

g_key_file_get_integer_list (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

gsize *length,

GError **error);

Returns the values associated with key undergroup_name asintegers.

If key cannot be found then NULL is returned and error is set toG_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the values associatedwith key cannot be interpreted as integers thenNULL is returnedand error is set toG_KEY_FILE_ERROR_INVALID_VALUE.

Parameters

key_filea GKeyFile

group_namea group name

keya key

lengththe number of integers returned.[out]

errorreturn location for a GError

Returns

the values associated with the key as a list of integers, or NULL ifthe key was not found or could not be parsed. The returned list ofintegers should be freed withg_free() when no longer needed.

[array length=length][element-type gint][transfer container]

Since: 2.6

g_key_file_get_double_list ()

gdouble *

g_key_file_get_double_list (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

gsize *length,

GError **error);

Returns the values associated with key undergroup_name asdoubles.

If key cannot be found then NULL is returned and error is set toG_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the values associatedwith key cannot be interpreted as doubles thenNULL is returnedand error is set toG_KEY_FILE_ERROR_INVALID_VALUE.

Parameters

key_filea GKeyFile

group_namea group name

keya key

lengththe number of doubles returned.[out]

errorreturn location for a GError

Returns

the values associated with the key as a list of doubles, or NULL if thekey was not found or could not be parsed. The returned list of doublesshould be freed withg_free() when no longer needed.

[array length=length][element-type gdouble][transfer container]

Since: 2.12

g_key_file_get_comment ()

gchar *

g_key_file_get_comment (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

GError **error);

Retrieves a comment above key from group_name.If key is NULL then comment will be read from abovegroup_name. If bothkey andgroup_name areNULL, thencomment will be read from above the first group in the file.

Note that the returned string includes the '#' comment markers.

Parameters

key_filea GKeyFile

group_namea group name, or NULL.[allow-none]

keya key

errorreturn location for a GError

Returns

a comment that should be freed with g_free()

Since: 2.6

g_key_file_set_value ()

void

g_key_file_set_value (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

const gchar *value);

Associates a new value with key under group_name.

If key cannot be found then it is created. Ifgroup_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), useg_key_file_set_string().

Parameters

key_filea GKeyFile

group_namea group name

keya key

valuea string

Since: 2.6

g_key_file_set_string ()

void

g_key_file_set_string (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

const gchar *string);

Associates a new string value with key undergroup_name. Ifkey cannot be found then it is created. Ifgroup_name cannot be found then it is created.Unlikeg_key_file_set_value(), this function handles charactersthat need escaping, such as newlines.

Parameters

key_filea GKeyFile

group_namea group name

keya key

stringa string

Since: 2.6

g_key_file_set_locale_string ()

void

g_key_file_set_locale_string (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

const gchar *locale,

const gchar *string);

Associates a string value for key and locale under group_name.If the translation forkey cannot be found then it is created.

Parameters

key_filea GKeyFile

group_namea group name

keya key

localea locale identifier

stringa string

Since: 2.6

g_key_file_set_boolean ()

void

g_key_file_set_boolean (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

gboolean value);

Associates a new boolean value with key undergroup_name.Ifkey cannot be found then it is created.

Parameters

key_filea GKeyFile

group_namea group name

keya key

valueTRUE orFALSE

Since: 2.6

g_key_file_set_integer ()

void

g_key_file_set_integer (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

gint value);

Associates a new integer value with key undergroup_name.Ifkey cannot be found then it is created.

Parameters

key_filea GKeyFile

group_namea group name

keya key

valuean integer value

Since: 2.6

g_key_file_set_int64 ()

void

g_key_file_set_int64 (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

gint64 value);

Associates a new integer value with key undergroup_name.Ifkey cannot be found then it is created.

Parameters

key_filea GKeyFile

group_namea group name

keya key

valuean integer value

Since: 2.26

g_key_file_set_uint64 ()

void

g_key_file_set_uint64 (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

guint64 value);

Associates a new integer value with key undergroup_name.Ifkey cannot be found then it is created.

Parameters

key_filea GKeyFile

group_namea group name

keya key

valuean integer value

Since: 2.26

g_key_file_set_double ()

void

g_key_file_set_double (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

gdouble value);

Associates a new double value with key undergroup_name.Ifkey cannot be found then it is created.

Parameters

key_filea GKeyFile

group_namea group name

keya key

valuean double value

Since: 2.12

g_key_file_set_string_list ()

void

g_key_file_set_string_list (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

const gchar * const list[],

gsize length);

Associates a list of string values for key undergroup_name.Ifkey cannot be found then it is created.Ifgroup_name cannot be found then it is created.

Parameters

key_filea GKeyFile

group_namea group name

keya key

listan array of string values.[array zero-terminated=1 length=length][element-type utf8]

lengthnumber of string values in list

Since: 2.6

g_key_file_set_locale_string_list ()

void

g_key_file_set_locale_string_list (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

const gchar *locale,

const gchar * const list[],

gsize length);

Associates a list of string values for key andlocale undergroup_name. If the translation forkey cannot be found thenit is created.

Parameters

key_filea GKeyFile

group_namea group name

keya key

localea locale identifier

lista NULL-terminated array of locale string values.[array zero-terminated=1 length=length]

lengththe length of list

Since: 2.6

g_key_file_set_boolean_list ()

void

g_key_file_set_boolean_list (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

gboolean list[],

gsize length);

Associates a list of boolean values with key undergroup_name. Ifkey cannot be found then it is created.Ifgroup_name isNULL, the start_group is used.

Parameters

key_filea GKeyFile

group_namea group name

keya key

listan array of boolean values.[array length=length]

lengthlength of list

Since: 2.6

g_key_file_set_integer_list ()

void

g_key_file_set_integer_list (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

gint list[],

gsize length);

Associates a list of integer values with key undergroup_name. Ifkey cannot be found then it is created.

Parameters

key_filea GKeyFile

group_namea group name

keya key

listan array of integer values.[array length=length]

lengthnumber of integer values in list

Since: 2.6

g_key_file_set_double_list ()

void

g_key_file_set_double_list (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

gdouble list[],

gsize length);

Associates a list of double values with key undergroup_name. Ifkey cannot be found then it is created.

Parameters

key_filea GKeyFile

group_namea group name

keya key

listan array of double values.[array length=length]

lengthnumber of double values in list

Since: 2.12

g_key_file_set_comment ()

gboolean

g_key_file_set_comment (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

const gchar *comment,

GError **error);

Places a comment above key from group_name.

If key is NULL then comment will be written abovegroup_name.If bothkey andgroup_name areNULL, thencomment will bewritten above the first group in the file.

Note that this function prepends a '#' comment marker toeach line of comment.

Parameters

key_filea GKeyFile

group_namea group name, or NULL.[allow-none]

keya key.[allow-none]

commenta comment

errorreturn location for a GError

Returns

TRUE if the comment was written,FALSE otherwise

Since: 2.6

g_key_file_remove_group ()

gboolean

g_key_file_remove_group (GKeyFile *key_file,

const gchar *group_name,

GError **error);

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

Parameters

key_filea GKeyFile

group_namea group name

errorreturn location for a GError or NULL

Returns

TRUE if the group was removed,FALSE otherwise

Since: 2.6

g_key_file_remove_key ()

gboolean

g_key_file_remove_key (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

GError **error);

Removes key in group_name from the key file.

Parameters

key_filea GKeyFile

group_namea group name

keya key name to remove

errorreturn location for a GError or NULL

Returns

TRUE if the key was removed,FALSE otherwise

Since: 2.6

g_key_file_remove_comment ()

gboolean

g_key_file_remove_comment (GKeyFile *key_file,

const gchar *group_name,

const gchar *key,

GError **error);

Removes a comment above key from group_name.If key is NULL then comment will be removed abovegroup_name. If bothkey andgroup_name areNULL, thencomment willbe removed above the first group in the file.

Parameters

key_filea GKeyFile

group_namea group name, or NULL.[allow-none]

keya key.[allow-none]

errorreturn location for a GError

Returns

TRUE if the comment was removed,FALSE otherwise

Since: 2.6

Types and Values

GKeyFile

typedef struct _GKeyFile GKeyFile;

The GKeyFile struct contains only private dataand should not be accessed directly.

G_KEY_FILE_ERROR

#define G_KEY_FILE_ERROR g_key_file_error_quark()

Error domain for key file parsing. Errors in this domain willbe from the GKeyFileError enumeration.

See GError for information on error domains.

enum GKeyFileError

Error codes returned by key file parsing.

Members

G_KEY_FILE_ERROR_UNKNOWN_ENCODINGthe text being parsed was in an unknown encoding

G_KEY_FILE_ERROR_PARSEdocument was ill-formed

G_KEY_FILE_ERROR_NOT_FOUNDthe file was not found

G_KEY_FILE_ERROR_KEY_NOT_FOUNDa requested key was not found

G_KEY_FILE_ERROR_GROUP_NOT_FOUNDa requested group was not found

G_KEY_FILE_ERROR_INVALID_VALUEa value could not be parsed

enum GKeyFileFlags

Flags which influence the parsing.

Members

G_KEY_FILE_NONENo flags, default behaviour

G_KEY_FILE_KEEP_COMMENTSUse this flag if you plan to write the (possibly modified) contents of the key file back to a file; otherwise all comments will be lost when the key file is written back.

G_KEY_FILE_KEEP_TRANSLATIONSUse this flag if you plan to write the (possibly modified) contents of the key file back to a file; otherwise only the translations for the current language will be written back.

G_KEY_FILE_DESKTOP_GROUP

#define G_KEY_FILE_DESKTOP_GROUP "Desktop Entry"

The name of the main group of a desktop entry file, as defined in theDesktop Entry Specification.Consult the specification for moredetails about the meanings of the keys below.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_TYPE

#define G_KEY_FILE_DESKTOP_KEY_TYPE "Type"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a stringgiving the type of the desktop entry. UsuallyG_KEY_FILE_DESKTOP_TYPE_APPLICATION,G_KEY_FILE_DESKTOP_TYPE_LINK, orG_KEY_FILE_DESKTOP_TYPE_DIRECTORY.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_VERSION

#define G_KEY_FILE_DESKTOP_KEY_VERSION "Version"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a stringgiving the version of the Desktop Entry Specification used forthe desktop entry file.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_NAME

#define G_KEY_FILE_DESKTOP_KEY_NAME "Name"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a localizedstring giving the specific name of the desktop entry.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME

#define G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME "GenericName"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a localizedstring giving the generic name of the desktop entry.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY

#define G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY "NoDisplay"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a booleanstating whether the desktop entry should be shown in menus.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_COMMENT

#define G_KEY_FILE_DESKTOP_KEY_COMMENT "Comment"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a localizedstring giving the tooltip for the desktop entry.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_ICON

#define G_KEY_FILE_DESKTOP_KEY_ICON "Icon"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a localizedstring giving the name of the icon to be displayed for the desktopentry.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_HIDDEN

#define G_KEY_FILE_DESKTOP_KEY_HIDDEN "Hidden"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a booleanstating whether the desktop entry has been deleted by the user.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN

#define G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN "OnlyShowIn"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a list ofstrings identifying the environments that should display thedesktop entry.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN

#define G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN "NotShowIn"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a list ofstrings identifying the environments that should not display thedesktop entry.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_TRY_EXEC

#define G_KEY_FILE_DESKTOP_KEY_TRY_EXEC "TryExec"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a stringgiving the file name of a binary on disk used to determine if theprogram is actually installed. It is only valid for desktop entrieswith theApplication type.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_EXEC

#define G_KEY_FILE_DESKTOP_KEY_EXEC "Exec"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a stringgiving the command line to execute. It is only valid for desktopentries with theApplication type.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_PATH

#define G_KEY_FILE_DESKTOP_KEY_PATH "Path"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a stringcontaining the working directory to run the program in. It is onlyvalid for desktop entries with theApplication type.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_TERMINAL

#define G_KEY_FILE_DESKTOP_KEY_TERMINAL "Terminal"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a booleanstating whether the program should be run in a terminal window.It is only valid for desktop entries with theApplication type.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_MIME_TYPE

#define G_KEY_FILE_DESKTOP_KEY_MIME_TYPE "MimeType"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a listof strings giving the MIME types supported by this desktop entry.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_CATEGORIES

#define G_KEY_FILE_DESKTOP_KEY_CATEGORIES "Categories"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a listof strings giving the categories in which the desktop entryshould be shown in a menu.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY

#define G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY "StartupNotify"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a booleanstating whether the application supports theStartup Notification Protocol Specification.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS

#define G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS "StartupWMClass"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is stringidentifying the WM class or name hint of a window that the applicationwill create, which can be used to emulate Startup Notification witholder applications.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_URL

#define G_KEY_FILE_DESKTOP_KEY_URL "URL"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a stringgiving the URL to access. It is only valid for desktop entrieswith theLink type.

Since: 2.14

G_KEY_FILE_DESKTOP_KEY_ACTIONS

#define G_KEY_FILE_DESKTOP_KEY_ACTIONS "Actions"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a string listgiving the available application actions.

Since: 2.38

G_KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE

#define G_KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE "DBusActivatable"

A key under G_KEY_FILE_DESKTOP_GROUP, whose value is a boolean set to trueif the application is D-Bus activatable.

Since: 2.38

G_KEY_FILE_DESKTOP_TYPE_APPLICATION

#define G_KEY_FILE_DESKTOP_TYPE_APPLICATION "Application"

The value of the G_KEY_FILE_DESKTOP_KEY_TYPE, key for desktopentries representing applications.

Since: 2.14

G_KEY_FILE_DESKTOP_TYPE_LINK

#define G_KEY_FILE_DESKTOP_TYPE_LINK "Link"

The value of the G_KEY_FILE_DESKTOP_KEY_TYPE, key for desktopentries representing links to documents.

Since: 2.14

G_KEY_FILE_DESKTOP_TYPE_DIRECTORY

#define G_KEY_FILE_DESKTOP_TYPE_DIRECTORY "Directory"

The value of the G_KEY_FILE_DESKTOP_KEY_TYPE, key for desktopentries representing directories.

Since: 2.14

Copyright © Linux教程網 All Rights Reserved