第五章 GNOME ライブラリ

Table of Contents
gnome-config
gnome-defs
gnome-dentry
gnome-fileconvert
gnome-help
gnome-history
gnome-hook
gnome-i18n
gnome-mime
gnome-score
gnome-string
gnome-triggers
gnome-util
libgnome

この章は libgnome のリファレンスとなるつもりである。

This chapter is intended to be a reference to the libgnome.

gnome-config

著者 Author(s)

Miguel de Icaza <miguel@nuclecu.unam.mx>

説明 Description

コンフィグレーションの情報データベースを操作するルーチンのセット

A set of routines for manipulating the database of configuration information.

用語集 Glossary

gnome_config_*get_* - 指定された config path から情報を引き出すためのルーチン routines to retrieve information for a specified config path.

type gnome_config_get_typename(const char *path);

説明 Description

コンフィギュレーションの項目を引き出すルーチン。'typename' では string, translated_string, int, bool, float, vector のどれかを指定する。 gnome_config_get_string(), gnome_config_get_translated_string(), and gnome_config_get_vector(), の場合は、返り値を確保するために使用された メモリーの所有権がアプリケーションに引き渡される [* 多分 g_alloc or malloc で確保したメモリへのポインタを返すんでしょう] 。アプリケーションが終了した時、 そのメモリは、適切のために g_free() か g_string_array_free() を使って 解放されるべきである。

Routine to retrieve a config item. 'typename' would be one of string, translated_string, int, bool, float, or vector. In the case of the gnome_config_get_string(), gnome_config_get_translated_string(), and gnome_config_get_vector(), ownership of the memory used by the returned value is given over to the application. When the application is done with it, it should be freed using g_free() or g_string_array_free() as appropriate.

これらの関数と、"private" や "with_default" とを組み合わせたバージョンが 存在する。例えば、gnome_config_get_string(), gnome_config_get_string_with_default(), gnome_config_private_get_string(), gnome_config_private_get_string_with_default() というルーチンが存在する。

Combinations of "private" and "with_default" versions of these routines exist. For example, there are gnome_config_get_string(), gnome_config_get_string_with_default() gnome_config_private_get_string(), and gnome_config_private_get_string_with_default() routines.

使いかた Usage

char *myitem;
gboolean is_default;

myitem =
gnome_config_get_string_with_default("/foo/blah=DefaultValue", &is_default);

パラメータ Parameters

gnome_config_set_* - 指定された config path に情報を保管するためのルーチン routines to store information for a specified config path.

void gnome_config_set_typename(const char *path, type value);

説明 Description

コンフィギュレーションデータベースの指定された config path に 指定された値を保管する。

Stores the specified value into the configuration database at the specified config path.

すべての標準ルーチンには "private" のバージョンもあることに注意しなさい。 例: gnome_config_set_string() と gnome_config_private_set_string()

Note that there are "private" variations on all the regular routines, e.g. gnome_config_set_string() and gnome_config_private_set_string().

使いかた Usage

char *values[] = {"A one", "a two", "a three"};

gnome_config_set_vector("/foo/bar/baz", 3, values);

gnome_config_has_section - コンフィギュレーションのセクションが存在するか どうか調べる Checks whether a config section exists

gboolean gnome_config_has_section(const char *path);

説明 Description

このルーチンは、もし指定されたセクションか項目が存在すれば TRUE を、 しなければ FALSE を返す。

This routine returns TRUE if the specified section/item exists, xor FALSE if it does not.

対応する gnome_config_private_has_section() も利用可能である。

A parallel gnome_config_private_has_section() routine also is available.

使いかた Usage

if(gnome_config_has_section("/foo/bar/baz")) {
        g_print("You have saved preferences.\n");
} else {
        g_print("You haven't saved preferences yet.\n");
}

パラメータ Parameters

gnome_config_init_iterator - 指定されたコンフィギュレーションのセクションにある項目のリストを得るために イテレータを作成する Setup an iterator to get a listing of items in a specified config section.

void *gnome_config_init_iterator(const char *path);

説明 Description

このルーチンはあるコンフィギュレーションのセクションにある項目 すべてからなるループを作るために使われる。gnome_config_iterator_next() は次のアイテムに進むために使われる。

This routine is used to begin a loop over all the items in a config section. gnome_config_iterator_next() is used to advance to the next item.

gnome_config_private_init_iterator() という変形版も存在することに注意。

Note that a gnome_config_private_init_iterator() variant exists.

使いかた Usage

gnome_config_iterator_next() の使用例を見なさい。

See the gnome_config_iterator_next() usage example

パラメータ Parameters

gnome_config_init_iterator_sections - 指定されたコンフィギュレーションのセクションにある セクションのリストを得るためにイテレータを作成する Setup an iterator to get a listing of sections in a specified config section.

void *gnome_config_init_iterator_sections(const char *path);

説明 Description

このルーチンはあるコンフィギュレーションのセクションにある項目 すべてからなるループを作るために使われる。gnome_config_iterator_next() は次の項目に進むために使われる。

This routine is used to begin a loop over all the items in a config section. gnome_config_iterator_next() is used to advance to the next item.

gnome_config_private_init_iterator_sections() という変形版もあることに注意。

Note that a gnome_config_private_init_iterator_sections() variant exists.

使いかた Usage

gnome_config_iterator_next() の使用例を見なさい。

See the gnome_config_iterator_next() usage example

パラメータ Parameters

gnome_config_iterator_next - イテレータから次のアイテムを得る get the next item from an iterator

void *gnome_config_iterator_next(void *s, char **key, char **value);

説明 Description

この関数は通常はコンフィギュレーションの項目/セクションイテレータの ループの更新としてはたらく。返り値は gnome_config_iterator_next() が必要としている void 型のポインタか、もしこれ以上入手可能なデータが イテレータになければ NULL である。

This function normally serves as the loop update for a config item or section iterator. The return value is an opaque pointer needed by gnome_config_iterator_next, or NULL if there are no more available data in the iterator.

使いかた Usage

char *section_name, *key, *value;
void *section_iter, *item_iter;
GString *tmpstr;
tmpstr = g_string_new(NULL);
for(section_iter = gnome_config_init_iterator_sections("/foo");
    section_iter != NULL;
    section_iter = gnome_config_iterator_next(section_iter, NULL, &section_name)) {
    
    g_string_sprintf(tmpstr, "/foo/%s", section_name);
    
    for(item_iter = gnome_config_init_iterator(tmpstr->str);
        item_iter;
        item_iter = gnome_config_iterator_next(item_iter, &key, &value)) {
        g_print("Got key %s -> value %s in section %s of /foo\n",
                key, value, section_name);

        g_free(key); g_free(value);
    }

    g_free(section_name);
}
g_string_free(tmpstr);

パラメータ Parameters

gnome_config_drop_all - メモリ内キャッシュから全てのキャッシュされた コンフィギュレーションデータを落す drops all the cached config data from the in-memory cache

void gnome_config_drop_all(void);

説明 Description

gnome_config ルーチンは処理を速くするためにコンフィギュレーションの エントリーをメモリ内にキャッシュする。gnome_config_drop_all() を呼ぶと、 そのキャッシュがクリアされる。

The gnome_config routines cache the configuration entries in memory to increase speed. Calling gnome_config_drop_all() causes the cache to be cleared.

gnome_config_sync - まだ書かれていない全てのエントリーを、 コンフィギュレーションデータベースに書き込む writes all unwritten config entries to the config database

void gnome_config_sync(void);

説明 Description

前に述べたように、gnome_config ルーチンは処理を速くするために、 コンフィギュレーションのエントリーをキャッシュする。このルーチンは キャッシュをディスクにフラッシュする。あなたは通常は、 gnome_config_set_* の処理をたくさん行なった後でこれを使うであろう。

As previously stated, the gnome_config routines cache configuration entries in memory to increase speed. This routine flushes the cache to disk - you would ordinarily use it after a number of gnome_config_set_* operations.

gnome_config_*clean_* - コンフィギュレーションのエントリーを一つ、または、あるサブツリー [一部のツリー] 全体を削除するルーチン routines for removing a configuration database entry or subtree altogether

void gnome_config_clean_file(const char *path);

void gnome_config_private_clean_file(const char *path);

void gnome_config_clean_section(const char *path);

void gnome_config_private_clean_section(const char *path);

void gnome_config_clean_key(const char *path);

void gnome_config_private_clean_key(const char *path);

説明 Description

このルーチンは指定されたもの(ファイルか、セクションか、キーのいずれか) に関係するコンフィギュレーションのエントリー全てを削除する。

These routines delete all the configuration entries associated with the specified entity (either a file, section, or key).

使いかた Usage

char *val1, *val2;

gnome_config_set_string("/foo/bar", "baz");
val1 = gnome_config_get_string("/foo/bar");
gnome_config_clean_section("/foo");
val2 = gnome_config_get_string("/foo/bar");
if(val1 && val2 && !strcmp(val1, val2)) {
    g_error("The values match! gnome_config_clean_section is broken!");
} else {
    g_message("gnome_config_clean_section worked.");
}

Parameters

gnome_config_*get_real_path

char *gnome_config_get_real_path(const char *path);

char *gnome_config_private_get_real_path(const char *path);

説明 Description

時として、プログラマはコンフィギュレーション項目が保管されている ローカルのファイル名を得たいと思うかもしれない。これらの関数 (現在はマクロとして実装されている) は、config path が渡されると、 そのファイル名を返す。

Occasionally an application writer may want to get the local filename where a config item is stored. When passed a config path, these routines (currently implemented as macros) return that filename.

使いかた Usage

char *filename = gnome_config_get_real_path("/foo/bar");
FILE *filehandle = fopen(filename, "w");
/* do devious things with the file */

Parameters