3 static GHashTable *perl_sbar_defs;
5 static int check_sbar_destroy(char *key, char *value, char *script)
7 if (strncmp(value, script, strlen(script)) == 0 &&
8 value[strlen(script)] == ':') {
9 statusbar_item_unregister(key);
18 static void script_unregister_statusbars(PERL_SCRIPT_REC *script)
20 g_hash_table_foreach_remove(perl_sbar_defs,
21 (GHRFunc) check_sbar_destroy,
25 void perl_statusbar_init(void)
27 perl_sbar_defs = g_hash_table_new((GHashFunc) g_str_hash,
28 (GCompareFunc) g_str_equal);
29 signal_add("script destroyed", (SIGNAL_FUNC) script_unregister_statusbars);
32 static void statusbar_item_def_destroy(void *key, void *value)
34 statusbar_item_unregister(key);
39 void perl_statusbar_deinit(void)
41 signal_remove("script destroyed", (SIGNAL_FUNC) script_unregister_statusbars);
43 g_hash_table_foreach(perl_sbar_defs,
44 (GHFunc) statusbar_item_def_destroy, NULL);
45 g_hash_table_destroy(perl_sbar_defs);
48 static void perl_statusbar_event(char *function, SBAR_ITEM_REC *item,
60 item_sv = plain_bless(item, "Irssi::TextUI::StatusbarItem");
61 XPUSHs(sv_2mortal(item_sv));
62 XPUSHs(sv_2mortal(newSViv(get_size_only)));
65 retcount = perl_call_pv(function, G_EVAL|G_DISCARD);
69 PERL_SCRIPT_REC *script;
72 package = perl_function_get_package(function);
73 script = perl_script_find_package(package);
77 /* make sure we don't get back here */
78 script_unregister_statusbars(script);
80 signal_emit("script error", 2, script, SvPV(ERRSV, PL_na));
82 /* min_size and max_size can be changed, move them to SBAR_ITEM_REC */
85 sv = hv_fetch(hv, "min_size", 8, 0);
86 if (sv != NULL) item->min_size = SvIV(*sv);
87 sv = hv_fetch(hv, "max_size", 8, 0);
88 if (sv != NULL) item->max_size = SvIV(*sv);
98 static void sig_perl_statusbar(SBAR_ITEM_REC *item, int get_size_only)
102 function = g_hash_table_lookup(perl_sbar_defs, item->config->name);
103 if (function != NULL)
104 perl_statusbar_event(function, item, get_size_only);
106 /* use default function - this shouldn't actually happen.. */
107 statusbar_item_default_handler(item, get_size_only, NULL, "", TRUE);
111 MODULE = Irssi::TextUI::Statusbar PACKAGE = Irssi
115 statusbar_item_register(name, value, func = NULL)
120 statusbar_item_register(name, value, func == NULL || *func == '\0' ? NULL : sig_perl_statusbar);
122 g_hash_table_insert(perl_sbar_defs, g_strdup(name),
123 g_strdup_printf("%s::%s", perl_get_package(), func));
127 statusbar_item_unregister(name)
132 if (g_hash_table_lookup_extended(perl_sbar_defs, name, &key, &value)) {
133 g_hash_table_remove(perl_sbar_defs, name);
137 statusbar_item_unregister(name);
140 statusbar_items_redraw(name)
144 statusbars_recreate_items()
146 #*******************************
147 MODULE = Irssi::TextUI::Statusbar PACKAGE = Irssi::TextUI::StatusbarItem PREFIX = statusbar_item_
148 #*******************************
151 statusbar_item_default_handler(item, get_size_only, str, data, escape_vars = TRUE)
152 Irssi::TextUI::StatusbarItem item
160 statusbar_item_default_handler(item, get_size_only,
161 *str == '\0' ? NULL : str,
164 hv_store(hv, "min_size", 8, newSViv(item->min_size), 0);
165 hv_store(hv, "max_size", 8, newSViv(item->max_size), 0);