diff options
author | James Booth <boothj5@gmail.com> | 2016-07-12 01:51:27 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-07-12 01:51:27 +0100 |
commit | 1a7eb0076395faf9be1fcd0f5b076b3156693f37 (patch) | |
tree | 8a65d50474aa9e879ef646b503172efdb1eee6f6 /src | |
parent | 9a0111c10a3bd461c036d6d5ffb0e3390bed47c5 (diff) | |
download | profani-tty-1a7eb0076395faf9be1fcd0f5b076b3156693f37.tar.gz |
Check for plugin win before creating
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/api.c | 4 | ||||
-rw-r--r-- | src/plugins/callbacks.c | 14 | ||||
-rw-r--r-- | src/plugins/callbacks.h | 1 | ||||
-rw-r--r-- | src/window_list.c | 29 | ||||
-rw-r--r-- | src/window_list.h | 2 |
5 files changed, 31 insertions, 19 deletions
diff --git a/src/plugins/api.c b/src/plugins/api.c index c8e6a166..d66975d5 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -302,6 +302,10 @@ api_win_create( void(*callback_exec)(PluginWindowCallback *window_callback, const char *tag, const char * const line), void(*callback_destroy)(void *callback)) { + if (callbacks_win_exists(plugin_name, tag)) { + return; + } + PluginWindowCallback *window = malloc(sizeof(PluginWindowCallback)); window->callback = callback; window->callback_exec = callback_exec; diff --git a/src/plugins/callbacks.c b/src/plugins/callbacks.c index 52f0aebd..4b958a67 100644 --- a/src/plugins/callbacks.c +++ b/src/plugins/callbacks.c @@ -206,6 +206,20 @@ callbacks_add_timed(const char *const plugin_name, PluginTimedFunction *timed_fu } } +gboolean +callbacks_win_exists(const char *const plugin_name, const char *tag) +{ + GHashTable *window_callbacks = g_hash_table_lookup(p_window_callbacks, plugin_name); + if (window_callbacks) { + PluginWindowCallback *cb = g_hash_table_lookup(window_callbacks, tag); + if (cb) { + return TRUE; + } + } + + return FALSE; +} + void callbacks_add_window_handler(const char *const plugin_name, const char *tag, PluginWindowCallback *window_callback) { diff --git a/src/plugins/callbacks.h b/src/plugins/callbacks.h index b73f80ff..0b5ea141 100644 --- a/src/plugins/callbacks.h +++ b/src/plugins/callbacks.h @@ -69,6 +69,7 @@ void callbacks_close(void); void callbacks_add_command(const char *const plugin_name, PluginCommand *command); void callbacks_add_timed(const char *const plugin_name, PluginTimedFunction *timed_function); +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); diff --git a/src/window_list.c b/src/window_list.c index 4f2d86e0..0f90ac6b 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -48,7 +48,7 @@ #include "window_list.h" #include "plugins/plugins.h" #include "xmpp/xmpp.h" - +#include "config/preferences.h" static GHashTable *windows; static int current; @@ -227,26 +227,19 @@ wins_get_plugin(const char *const tag) } void -wins_close_plugin(const char *const tag) +wins_close_plugin(char *tag) { - GList *values = g_hash_table_get_values(windows); - GList *curr = values; - - while (curr) { - ProfWin *window = curr->data; - if (window->type == WIN_PLUGIN) { - ProfPluginWin *pluginwin = (ProfPluginWin*)window; - if (g_strcmp0(pluginwin->tag, tag) == 0) { - int num = wins_get_num(window); - wins_close_by_num(num); - g_list_free(values); - return; - } - } - curr = g_list_next(curr); + ProfWin *toclose = wins_get_by_string(tag); + if (toclose == NULL) { + return; } - g_list_free(values); + int index = wins_get_num(toclose); + ui_close_win(index); + + if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) { + wins_tidy(); + } } GList* diff --git a/src/window_list.h b/src/window_list.h index 109620f9..930f2150 100644 --- a/src/window_list.h +++ b/src/window_list.h @@ -61,7 +61,7 @@ ProfPrivateWin* wins_get_private(const char *const fulljid); ProfPluginWin* wins_get_plugin(const char *const tag); ProfXMLWin* wins_get_xmlconsole(void); -void wins_close_plugin(const char *const tag); +void wins_close_plugin(char *tag); ProfWin* wins_get_current(void); |