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)
38 void perl_statusbar_deinit(void)
40 signal_remove("script destroyed", (SIGNAL_FUNC) script_unregister_statusbars);
42 g_hash_table_foreach(perl_sbar_defs,
43 (GHFunc) statusbar_item_def_destroy, NULL);
44 g_hash_table_destroy(perl_sbar_defs);
47 static void perl_statusbar_event(char *function, SBAR_ITEM_REC *item,
59 item_sv = plain_bless(item, "Irssi::TextUI::StatusbarItem");
60 XPUSHs(sv_2mortal(item_sv));
61 XPUSHs(sv_2mortal(newSViv(get_size_only)));
64 retcount = perl_call_pv(function, G_EVAL|G_DISCARD);
68 PERL_SCRIPT_REC *script;
71 package = perl_function_get_package(function);
72 script = perl_script_find_package(package);
76 /* make sure we don't get back here */
77 script_unregister_statusbars(script);
79 signal_emit("script error", 2, script, SvPV(ERRSV, PL_na));
81 /* min_size and max_size can be changed, move them to SBAR_ITEM_REC */
84 sv = hv_fetch(hv, "min_size", 8, 0);
85 if (sv != NULL) item->min_size = SvIV(*sv);
86 sv = hv_fetch(hv, "max_size", 8, 0);
87 if (sv != NULL) item->max_size = SvIV(*sv);
97 static void sig_perl_statusbar(SBAR_ITEM_REC *item, int get_size_only)
101 function = g_hash_table_lookup(perl_sbar_defs, item->config->name);
102 if (function != NULL)
103 perl_statusbar_event(function, item, get_size_only);
105 /* use default function - this shouldn't actually happen.. */
106 statusbar_item_default_handler(item, get_size_only, NULL, "", TRUE);
110 MODULE = Irssi::TextUI::Statusbar PACKAGE = Irssi
114 statusbar_item_register(name, value, func = NULL)
119 statusbar_item_register(name, value, func == NULL || *func == '\0' ? NULL : sig_perl_statusbar);
121 g_hash_table_insert(perl_sbar_defs, g_strdup(name),
122 g_strdup_printf("%s::%s", perl_get_package(), func));
126 statusbar_item_unregister(name)
131 if (g_hash_table_lookup_extended(perl_sbar_defs, name, &key, &value)) {
132 g_hash_table_remove(perl_sbar_defs, name);
136 statusbar_item_unregister(name);
139 statusbar_items_redraw(name)
143 statusbars_recreate_items()
145 #*******************************
146 MODULE = Irssi::TextUI::Statusbar PACKAGE = Irssi::TextUI::StatusbarItem PREFIX = statusbar_item_
147 #*******************************
150 statusbar_item_default_handler(item, get_size_only, str, data, escape_vars = TRUE)
151 Irssi::TextUI::StatusbarItem item
159 statusbar_item_default_handler(item, get_size_only,
160 *str == '\0' ? NULL : str,
163 hv_store(hv, "min_size", 8, newSViv(item->min_size), 0);
164 hv_store(hv, "max_size", 8, newSViv(item->max_size), 0);