forked from PsychoticNinja/irssi
after script is unloaded. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1883 dbcabf3a-b0e7-0310-adc4-f8d773084564
120 lines
2.5 KiB
Plaintext
120 lines
2.5 KiB
Plaintext
#include "module.h"
|
|
#include "misc.h"
|
|
|
|
static GHashTable *perl_settings;
|
|
|
|
static void perl_settings_add(const char *key)
|
|
{
|
|
PERL_SCRIPT_REC *script;
|
|
GSList *list;
|
|
|
|
script = perl_script_find_package(perl_get_package());
|
|
g_return_if_fail(script != NULL);
|
|
|
|
list = g_hash_table_lookup(perl_settings, script);
|
|
list = g_slist_append(list, g_strdup(key));
|
|
g_hash_table_insert(perl_settings, script, list);
|
|
}
|
|
|
|
static void perl_settings_remove(const char *key)
|
|
{
|
|
PERL_SCRIPT_REC *script;
|
|
GSList *list, *pos;
|
|
|
|
script = perl_script_find_package(perl_get_package());
|
|
g_return_if_fail(script != NULL);
|
|
|
|
list = g_hash_table_lookup(perl_settings, script);
|
|
pos = gslist_find_icase_string(list, key);
|
|
if (pos != NULL) {
|
|
list = g_slist_remove(list, pos->data);
|
|
g_hash_table_insert(perl_settings, script, list);
|
|
}
|
|
}
|
|
|
|
static void perl_settings_free(PERL_SCRIPT_REC *script, GSList *list)
|
|
{
|
|
g_slist_foreach(list, (GFunc) g_free, NULL);
|
|
g_slist_free(list);
|
|
}
|
|
|
|
static void sig_script_destroyed(PERL_SCRIPT_REC *script)
|
|
{
|
|
GSList *list;
|
|
|
|
list = g_hash_table_lookup(perl_settings, script);
|
|
if (list != NULL) {
|
|
g_slist_foreach(list, (GFunc) settings_remove, NULL);
|
|
perl_settings_free(script, list);
|
|
g_hash_table_remove(perl_settings, script);
|
|
}
|
|
}
|
|
|
|
void perl_settings_init(void)
|
|
{
|
|
perl_settings = g_hash_table_new((GHashFunc) g_direct_hash,
|
|
(GCompareFunc) g_direct_equal);
|
|
signal_add("script destroyed", (SIGNAL_FUNC) sig_script_destroyed);
|
|
}
|
|
|
|
void perl_settings_deinit(void)
|
|
{
|
|
signal_remove("script destroyed", (SIGNAL_FUNC) sig_script_destroyed);
|
|
|
|
g_hash_table_foreach(perl_settings, (GHFunc) perl_settings_free, NULL);
|
|
g_hash_table_destroy(perl_settings);
|
|
}
|
|
|
|
MODULE = Irssi::Settings PACKAGE = Irssi
|
|
PROTOTYPES: ENABLE
|
|
|
|
char *
|
|
settings_get_str(key)
|
|
char *key
|
|
CODE:
|
|
RETVAL = (char *) settings_get_str(key);
|
|
OUTPUT:
|
|
RETVAL
|
|
|
|
int
|
|
settings_get_int(key)
|
|
char *key
|
|
|
|
int
|
|
settings_get_bool(key)
|
|
char *key
|
|
|
|
void
|
|
settings_add_str(section, key, def)
|
|
char *section
|
|
char *key
|
|
char *def
|
|
CODE:
|
|
perl_settings_add(key);
|
|
settings_add_str(section, key, def);
|
|
|
|
void
|
|
settings_add_int(section, key, def)
|
|
char *section
|
|
char *key
|
|
int def
|
|
CODE:
|
|
perl_settings_add(key);
|
|
settings_add_int(section, key, def);
|
|
|
|
void
|
|
settings_add_bool(section, key, def)
|
|
char *section
|
|
char *key
|
|
int def
|
|
CODE:
|
|
perl_settings_add(key);
|
|
settings_add_bool(section, key, def);
|
|
|
|
void
|
|
settings_remove(key)
|
|
char *key
|
|
CODE:
|
|
perl_settings_remove(key);
|
|
settings_remove(key);
|