diff --git a/src/core/channels.c b/src/core/channels.c index f3d3a7a4..6a0a315e 100644 --- a/src/core/channels.c +++ b/src/core/channels.c @@ -48,6 +48,7 @@ void channel_init(CHANNEL_REC *channel, int automatic) MODULE_DATA_INIT(channel); channel->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "CHANNEL"); + channel->destroy = (void (*) (WI_ITEM_REC *)) channel_destroy; channel->mode = g_strdup(""); channel->createtime = time(NULL); channel->get_join_data = get_join_data; diff --git a/src/core/queries.c b/src/core/queries.c index d1c51352..cdbdbd9f 100644 --- a/src/core/queries.c +++ b/src/core/queries.c @@ -36,6 +36,7 @@ void query_init(QUERY_REC *query, int automatic) MODULE_DATA_INIT(query); query->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY"); + query->destroy = (void (*) (WI_ITEM_REC *)) query_destroy; if (query->server_tag != NULL) { query->server = server_find_tag(query->server_tag); if (query->server != NULL) { diff --git a/src/core/window-item-rec.h b/src/core/window-item-rec.h index 5c09a5b0..eeb465f4 100644 --- a/src/core/window-item-rec.h +++ b/src/core/window-item-rec.h @@ -12,4 +12,6 @@ time_t createtime; int data_level; char *hilight_color; +void (*destroy)(WI_ITEM_REC *item); + #undef STRUCT_SERVER_REC diff --git a/src/fe-common/core/fe-channels.c b/src/fe-common/core/fe-channels.c index e25c3dc8..8e6ec57b 100644 --- a/src/fe-common/core/fe-channels.c +++ b/src/fe-common/core/fe-channels.c @@ -74,16 +74,6 @@ static void signal_channel_destroyed(CHANNEL_REC *channel) window_auto_destroy(window); } -static void signal_window_item_destroy(WINDOW_REC *window, WI_ITEM_REC *item) -{ - CHANNEL_REC *channel; - - g_return_if_fail(window != NULL); - - channel = CHANNEL(item); - if (channel != NULL) channel_destroy(channel); -} - static void sig_disconnected(SERVER_REC *server) { WINDOW_REC *window; @@ -576,7 +566,6 @@ void fe_channels_init(void) signal_add("channel created", (SIGNAL_FUNC) signal_channel_created); signal_add("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed); - signal_add_last("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy); signal_add_last("window item changed", (SIGNAL_FUNC) signal_window_item_changed); signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected); @@ -599,7 +588,6 @@ void fe_channels_deinit(void) { signal_remove("channel created", (SIGNAL_FUNC) signal_channel_created); signal_remove("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed); - signal_remove("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy); signal_remove("window item changed", (SIGNAL_FUNC) signal_window_item_changed); signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected); diff --git a/src/fe-common/core/fe-exec.c b/src/fe-common/core/fe-exec.c index bc8f4691..e0a1b0ca 100644 --- a/src/fe-common/core/fe-exec.c +++ b/src/fe-common/core/fe-exec.c @@ -38,28 +38,6 @@ static GSList *processes; static int signal_exec_input; -static EXEC_WI_REC *exec_wi_create(WINDOW_REC *window, PROCESS_REC *rec) -{ - EXEC_WI_REC *item; - - g_return_val_if_fail(window != NULL, NULL); - g_return_val_if_fail(rec != NULL, NULL); - - item = g_new0(EXEC_WI_REC, 1); - item->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "EXEC"); - item->name = rec->name != NULL ? - g_strdup_printf("%%%s", rec->name) : - g_strdup_printf("%%%d", rec->id); - - item->window = window; - item->createtime = time(NULL); - item->process = rec; - - MODULE_DATA_INIT(item); - window_item_add(window, (WI_ITEM_REC *) item, FALSE); - return item; -} - static void exec_wi_destroy(EXEC_WI_REC *rec) { g_return_if_fail(rec != NULL); @@ -75,6 +53,29 @@ static void exec_wi_destroy(EXEC_WI_REC *rec) g_free(rec); } +static EXEC_WI_REC *exec_wi_create(WINDOW_REC *window, PROCESS_REC *rec) +{ + EXEC_WI_REC *item; + + g_return_val_if_fail(window != NULL, NULL); + g_return_val_if_fail(rec != NULL, NULL); + + item = g_new0(EXEC_WI_REC, 1); + item->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "EXEC"); + item->destroy = (void (*) (WI_ITEM_REC *)) exec_wi_destroy; + item->name = rec->name != NULL ? + g_strdup_printf("%%%s", rec->name) : + g_strdup_printf("%%%d", rec->id); + + item->window = window; + item->createtime = time(NULL); + item->process = rec; + + MODULE_DATA_INIT(item); + window_item_add(window, (WI_ITEM_REC *) item, FALSE); + return item; +} + static int process_get_new_id(void) { PROCESS_REC *rec; @@ -590,14 +591,6 @@ static void sig_window_destroyed(WINDOW_REC *window) } } -static void sig_window_item_destroyed(WINDOW_REC *window, EXEC_WI_REC *item) -{ - if (IS_EXEC_WI(item)) { - item->process->target_item = NULL; - exec_wi_destroy(item); - } -} - static void event_text(const char *data, SERVER_REC *server, EXEC_WI_REC *item) { if (!IS_EXEC_WI(item)) return; @@ -616,7 +609,6 @@ void fe_exec_init(void) signal_add("pidwait", (SIGNAL_FUNC) sig_pidwait); signal_add("exec input", (SIGNAL_FUNC) sig_exec_input); signal_add("window destroyed", (SIGNAL_FUNC) sig_window_destroyed); - signal_add("window item destroy", (SIGNAL_FUNC) sig_window_item_destroyed); signal_add_first("send text", (SIGNAL_FUNC) event_text); } @@ -636,6 +628,5 @@ void fe_exec_deinit(void) signal_remove("pidwait", (SIGNAL_FUNC) sig_pidwait); signal_remove("exec input", (SIGNAL_FUNC) sig_exec_input); signal_remove("window destroyed", (SIGNAL_FUNC) sig_window_destroyed); - signal_remove("window item destroy", (SIGNAL_FUNC) sig_window_item_destroyed); signal_remove("send text", (SIGNAL_FUNC) event_text); } diff --git a/src/fe-common/core/fe-queries.c b/src/fe-common/core/fe-queries.c index 4adf4945..dba01817 100644 --- a/src/fe-common/core/fe-queries.c +++ b/src/fe-common/core/fe-queries.c @@ -120,16 +120,6 @@ static void signal_window_item_server_changed(WINDOW_REC *window, } } -static void signal_window_item_destroy(WINDOW_REC *window, WI_ITEM_REC *item) -{ - QUERY_REC *query; - - g_return_if_fail(window != NULL); - - query = QUERY(item); - if (query != NULL) query_destroy(query); -} - static void sig_server_connected(SERVER_REC *server) { GSList *tmp; @@ -349,7 +339,6 @@ void fe_queries_init(void) signal_add("query server changed", (SIGNAL_FUNC) signal_query_server_changed); signal_add("query nick changed", (SIGNAL_FUNC) signal_query_nick_changed); signal_add("window item server changed", (SIGNAL_FUNC) signal_window_item_server_changed); - signal_add_last("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy); signal_add("server connected", (SIGNAL_FUNC) sig_server_connected); signal_add("window changed", (SIGNAL_FUNC) sig_window_changed); signal_add_first("message private", (SIGNAL_FUNC) sig_message_private); @@ -371,7 +360,6 @@ void fe_queries_deinit(void) signal_remove("query server changed", (SIGNAL_FUNC) signal_query_server_changed); signal_remove("query nick changed", (SIGNAL_FUNC) signal_query_nick_changed); signal_remove("window item server changed", (SIGNAL_FUNC) signal_window_item_server_changed); - signal_remove("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy); signal_remove("server connected", (SIGNAL_FUNC) sig_server_connected); signal_remove("window changed", (SIGNAL_FUNC) sig_window_changed); signal_remove("message private", (SIGNAL_FUNC) sig_message_private); diff --git a/src/fe-common/core/window-items.c b/src/fe-common/core/window-items.c index d7726521..fef32a5f 100644 --- a/src/fe-common/core/window-items.c +++ b/src/fe-common/core/window-items.c @@ -66,7 +66,7 @@ void window_item_remove(WI_ITEM_REC *item) window = window_item_window(item); - if (g_slist_find(window->items, item) == NULL) + if (window == NULL) return; item->window = NULL; @@ -86,8 +86,7 @@ void window_item_destroy(WI_ITEM_REC *item) window = window_item_window(item); window_item_remove(item); - - signal_emit("window item destroy", 2, window, item); + item->destroy(item); } void window_item_change_server(WI_ITEM_REC *item, void *server)