diff options
author | James Booth <boothj5@gmail.com> | 2016-07-12 02:16:12 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-07-12 02:16:12 +0100 |
commit | 5f393a6d9f995a9be86923f24e8b634a7a9d4ed9 (patch) | |
tree | 5735138d37f5952b255dea210d5a4b62496af40e /src | |
parent | 1a7eb0076395faf9be1fcd0f5b076b3156693f37 (diff) | |
download | profani-tty-5f393a6d9f995a9be86923f24e8b634a7a9d4ed9.tar.gz |
Remove plugin window on /close
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/api.c | 2 | ||||
-rw-r--r-- | src/plugins/callbacks.c | 10 | ||||
-rw-r--r-- | src/plugins/callbacks.h | 1 | ||||
-rw-r--r-- | src/plugins/plugins.c | 6 | ||||
-rw-r--r-- | src/plugins/plugins.h | 1 | ||||
-rw-r--r-- | src/ui/ui.h | 2 | ||||
-rw-r--r-- | src/ui/win_types.h | 1 | ||||
-rw-r--r-- | src/ui/window.c | 3 | ||||
-rw-r--r-- | src/window_list.c | 5 | ||||
-rw-r--r-- | src/window_list.h | 2 |
10 files changed, 27 insertions, 6 deletions
diff --git a/src/plugins/api.c b/src/plugins/api.c index d66975d5..a5f5deea 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -313,7 +313,7 @@ api_win_create( callbacks_add_window_handler(plugin_name, tag, window); - wins_new_plugin(tag); + wins_new_plugin(plugin_name, tag); // set status bar active ProfPluginWin *pluginwin = wins_get_plugin(tag); diff --git a/src/plugins/callbacks.c b/src/plugins/callbacks.c index 4b958a67..1ac4c5b9 100644 --- a/src/plugins/callbacks.c +++ b/src/plugins/callbacks.c @@ -221,6 +221,16 @@ callbacks_win_exists(const char *const plugin_name, const char *tag) } void +callbacks_remove_win(const char *const plugin_name, const char *const tag) +{ + GHashTable *window_callbacks = g_hash_table_lookup(p_window_callbacks, plugin_name); + if (window_callbacks) { + g_hash_table_remove(window_callbacks, tag); + } +} + + +void callbacks_add_window_handler(const char *const plugin_name, const char *tag, PluginWindowCallback *window_callback) { GHashTable *window_callbacks = g_hash_table_lookup(p_window_callbacks, plugin_name); diff --git a/src/plugins/callbacks.h b/src/plugins/callbacks.h index 0b5ea141..72e5d4e2 100644 --- a/src/plugins/callbacks.h +++ b/src/plugins/callbacks.h @@ -72,5 +72,6 @@ void callbacks_add_timed(const char *const plugin_name, PluginTimedFunction *tim gboolean callbacks_win_exists(const char *const plugin_name, const char *tag); void callbacks_add_window_handler(const char *const plugin_name, const char *tag, PluginWindowCallback *window_callback); void * callbacks_get_window_handler(const char *tag); +void callbacks_remove_win(const char *const plugin_name, const char *const tag); #endif diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index ef3fc5c2..24eb40d2 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -287,6 +287,12 @@ plugins_win_process_line(char *win, const char * const line) } void +plugins_close_win(const char *const plugin_name, const char *const tag) +{ + callbacks_remove_win(plugin_name, tag); +} + +void plugins_on_start(void) { GList *values = g_hash_table_get_values(plugins); diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index 78bae9e6..fc10c363 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -134,6 +134,7 @@ char* plugins_pre_priv_message_send(const char *const jid, const char *const mes void plugins_post_priv_message_send(const char *const jid, const char *const message); void plugins_win_process_line(char *win, const char *const line); +void plugins_close_win(const char *const plugin_name, const char *const tag); char* plugins_on_message_stanza_send(const char *const text); gboolean plugins_on_message_stanza_receive(const char *const text); diff --git a/src/ui/ui.h b/src/ui/ui.h index 5cf8cb31..79c1b201 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -344,7 +344,7 @@ ProfWin* win_create_chat(const char *const barejid); ProfWin* win_create_muc(const char *const roomjid); ProfWin* win_create_muc_config(const char *const title, DataForm *form); ProfWin* win_create_private(const char *const fulljid); -ProfWin* win_create_plugin(const char *const tag); +ProfWin* win_create_plugin(const char *const plugin_name, const char *const tag); void win_update_virtual(ProfWin *window); void win_free(ProfWin *window); gboolean win_notify_remind(ProfWin *window); diff --git a/src/ui/win_types.h b/src/ui/win_types.h index f05f237e..8b456993 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -190,6 +190,7 @@ typedef struct prof_xml_win_t { typedef struct prof_plugin_win_t { ProfWin super; char *tag; + char *plugin_name; unsigned long memcheck; } ProfPluginWin; diff --git a/src/ui/window.c b/src/ui/window.c index b9a8c7fd..2bbb327c 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -238,13 +238,14 @@ win_create_xmlconsole(void) } ProfWin* -win_create_plugin(const char *const tag) +win_create_plugin(const char *const plugin_name, const char *const tag) { ProfPluginWin *new_win = malloc(sizeof(ProfPluginWin)); new_win->super.type = WIN_PLUGIN; new_win->super.layout = _win_create_simple_layout(); new_win->tag = strdup(tag); + new_win->plugin_name = strdup(plugin_name); new_win->memcheck = PROFPLUGINWIN_MEMCHECK; diff --git a/src/window_list.c b/src/window_list.c index 0f90ac6b..af17f405 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -580,6 +580,7 @@ wins_close_by_num(int i) case WIN_PLUGIN: { ProfPluginWin *pluginwin = (ProfPluginWin*)window; + plugins_close_win(pluginwin->plugin_name, pluginwin->tag); autocomplete_remove(wins_ac, pluginwin->tag); autocomplete_remove(wins_close_ac, pluginwin->tag); break; @@ -681,12 +682,12 @@ wins_new_private(const char *const fulljid) } ProfWin * -wins_new_plugin(const char * const tag) +wins_new_plugin(const char *const plugin_name, const char * const tag) { GList *keys = g_hash_table_get_keys(windows); int result = get_next_available_win_num(keys); g_list_free(keys); - ProfWin *newwin = win_create_plugin(tag); + ProfWin *newwin = win_create_plugin(plugin_name, tag); g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); autocomplete_add(wins_ac, tag); autocomplete_add(wins_close_ac, tag); diff --git a/src/window_list.h b/src/window_list.h index 930f2150..483301af 100644 --- a/src/window_list.h +++ b/src/window_list.h @@ -44,7 +44,7 @@ ProfWin* wins_new_chat(const char *const barejid); ProfWin* wins_new_muc(const char *const roomjid); ProfWin* wins_new_muc_config(const char *const roomjid, DataForm *form); ProfWin* wins_new_private(const char *const fulljid); -ProfWin* wins_new_plugin(const char *const tag); +ProfWin* wins_new_plugin(const char *const plugin_name, const char *const tag); gboolean wins_chat_exists(const char *const barejid); GList* wins_get_private_chats(const char *const roomjid); |