1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Remove plugin window on /close

This commit is contained in:
James Booth 2016-07-12 02:16:12 +01:00
parent 1a7eb00763
commit 5f393a6d9f
11 changed files with 28 additions and 7 deletions

View File

@ -313,7 +313,7 @@ api_win_create(
callbacks_add_window_handler(plugin_name, tag, window); callbacks_add_window_handler(plugin_name, tag, window);
wins_new_plugin(tag); wins_new_plugin(plugin_name, tag);
// set status bar active // set status bar active
ProfPluginWin *pluginwin = wins_get_plugin(tag); ProfPluginWin *pluginwin = wins_get_plugin(tag);

View File

@ -220,6 +220,16 @@ callbacks_win_exists(const char *const plugin_name, const char *tag)
return FALSE; return FALSE;
} }
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 void
callbacks_add_window_handler(const char *const plugin_name, const char *tag, PluginWindowCallback *window_callback) callbacks_add_window_handler(const char *const plugin_name, const char *tag, PluginWindowCallback *window_callback)
{ {

View File

@ -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); 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_add_window_handler(const char *const plugin_name, const char *tag, PluginWindowCallback *window_callback);
void * callbacks_get_window_handler(const char *tag); void * callbacks_get_window_handler(const char *tag);
void callbacks_remove_win(const char *const plugin_name, const char *const tag);
#endif #endif

View File

@ -286,6 +286,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 void
plugins_on_start(void) plugins_on_start(void)
{ {

View File

@ -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_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_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); char* plugins_on_message_stanza_send(const char *const text);
gboolean plugins_on_message_stanza_receive(const char *const text); gboolean plugins_on_message_stanza_receive(const char *const text);

View File

@ -344,7 +344,7 @@ ProfWin* win_create_chat(const char *const barejid);
ProfWin* win_create_muc(const char *const roomjid); ProfWin* win_create_muc(const char *const roomjid);
ProfWin* win_create_muc_config(const char *const title, DataForm *form); ProfWin* win_create_muc_config(const char *const title, DataForm *form);
ProfWin* win_create_private(const char *const fulljid); 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_update_virtual(ProfWin *window);
void win_free(ProfWin *window); void win_free(ProfWin *window);
gboolean win_notify_remind(ProfWin *window); gboolean win_notify_remind(ProfWin *window);

View File

@ -190,6 +190,7 @@ typedef struct prof_xml_win_t {
typedef struct prof_plugin_win_t { typedef struct prof_plugin_win_t {
ProfWin super; ProfWin super;
char *tag; char *tag;
char *plugin_name;
unsigned long memcheck; unsigned long memcheck;
} ProfPluginWin; } ProfPluginWin;

View File

@ -238,13 +238,14 @@ win_create_xmlconsole(void)
} }
ProfWin* 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)); ProfPluginWin *new_win = malloc(sizeof(ProfPluginWin));
new_win->super.type = WIN_PLUGIN; new_win->super.type = WIN_PLUGIN;
new_win->super.layout = _win_create_simple_layout(); new_win->super.layout = _win_create_simple_layout();
new_win->tag = strdup(tag); new_win->tag = strdup(tag);
new_win->plugin_name = strdup(plugin_name);
new_win->memcheck = PROFPLUGINWIN_MEMCHECK; new_win->memcheck = PROFPLUGINWIN_MEMCHECK;

View File

@ -580,6 +580,7 @@ wins_close_by_num(int i)
case WIN_PLUGIN: case WIN_PLUGIN:
{ {
ProfPluginWin *pluginwin = (ProfPluginWin*)window; ProfPluginWin *pluginwin = (ProfPluginWin*)window;
plugins_close_win(pluginwin->plugin_name, pluginwin->tag);
autocomplete_remove(wins_ac, pluginwin->tag); autocomplete_remove(wins_ac, pluginwin->tag);
autocomplete_remove(wins_close_ac, pluginwin->tag); autocomplete_remove(wins_close_ac, pluginwin->tag);
break; break;
@ -681,12 +682,12 @@ wins_new_private(const char *const fulljid)
} }
ProfWin * 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); GList *keys = g_hash_table_get_keys(windows);
int result = get_next_available_win_num(keys); int result = get_next_available_win_num(keys);
g_list_free(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); g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
autocomplete_add(wins_ac, tag); autocomplete_add(wins_ac, tag);
autocomplete_add(wins_close_ac, tag); autocomplete_add(wins_close_ac, tag);

View File

@ -44,7 +44,7 @@ ProfWin* wins_new_chat(const char *const barejid);
ProfWin* wins_new_muc(const char *const roomjid); ProfWin* wins_new_muc(const char *const roomjid);
ProfWin* wins_new_muc_config(const char *const roomjid, DataForm *form); ProfWin* wins_new_muc_config(const char *const roomjid, DataForm *form);
ProfWin* wins_new_private(const char *const fulljid); 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); gboolean wins_chat_exists(const char *const barejid);
GList* wins_get_private_chats(const char *const roomjid); GList* wins_get_private_chats(const char *const roomjid);

View File

@ -497,7 +497,7 @@ ProfWin* win_create_private(const char * const fulljid)
{ {
return NULL; return NULL;
} }
ProfWin* win_create_plugin(const char * const tag) ProfWin* win_create_plugin(const char *const plugin_name, const char * const tag)
{ {
return NULL; return NULL;
} }