diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/plugin-api.c | 274 | ||||
-rw-r--r-- | src/plugins/scripts/script.c | 4 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 15 |
3 files changed, 212 insertions, 81 deletions
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 0aea6d584..c0a390b7c 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -38,6 +38,9 @@ #include "../core/wee-infolist.h" #include "../core/wee-input.h" #include "../core/wee-string.h" +#include "../gui/gui-bar.h" +#include "../gui/gui-bar-item.h" +#include "../gui/gui-bar-window.h" #include "../gui/gui-buffer.h" #include "../gui/gui-chat.h" #include "../gui/gui-color.h" @@ -288,6 +291,9 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name, void *pointer, const char *arguments) { struct t_infolist *ptr_infolist; + struct t_gui_bar *ptr_bar; + struct t_gui_bar_item *ptr_bar_item; + struct t_gui_bar_window *ptr_bar_window; struct t_gui_buffer *ptr_buffer; struct t_gui_line *ptr_line; struct t_gui_filter *ptr_filter; @@ -300,8 +306,128 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name, if (!infolist_name || !infolist_name[0]) return NULL; - - if (string_strcasecmp (infolist_name, "buffer") == 0) + + if (string_strcasecmp (infolist_name, "bar") == 0) + { + /* invalid bar pointer ? */ + if (pointer && (!gui_bar_valid (pointer))) + return NULL; + + ptr_infolist = infolist_new (); + if (ptr_infolist) + { + if (pointer) + { + /* build list with only one bar */ + if (!gui_bar_add_to_infolist (ptr_infolist, pointer)) + { + infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + else + { + /* build list with all bars */ + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + if (!gui_bar_add_to_infolist (ptr_infolist, ptr_bar)) + { + infolist_free (ptr_infolist); + return NULL; + } + } + return ptr_infolist; + } + } + } + else if (string_strcasecmp (infolist_name, "bar_item") == 0) + { + /* invalid bar item pointer ? */ + if (pointer && (!gui_bar_item_valid (pointer))) + return NULL; + + ptr_infolist = infolist_new (); + if (ptr_infolist) + { + if (pointer) + { + /* build list with only one bar item */ + if (!gui_bar_item_add_to_infolist (ptr_infolist, pointer)) + { + infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + else + { + /* build list with all bar items */ + for (ptr_bar_item = gui_bar_items; ptr_bar_item; + ptr_bar_item = ptr_bar_item->next_item) + { + if (!gui_bar_item_add_to_infolist (ptr_infolist, ptr_bar_item)) + { + infolist_free (ptr_infolist); + return NULL; + } + } + return ptr_infolist; + } + } + } + else if (string_strcasecmp (infolist_name, "bar_window") == 0) + { + /* invalid bar window pointer ? */ + if (pointer && (!gui_bar_window_valid (pointer))) + return NULL; + + ptr_infolist = infolist_new (); + if (ptr_infolist) + { + if (pointer) + { + /* build list with only one bar window */ + if (!gui_bar_window_add_to_infolist (ptr_infolist, pointer)) + { + infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + else + { + /* build list with all bar windows (from root and window bars) */ + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + if (ptr_bar->bar_window) + { + if (!gui_bar_window_add_to_infolist (ptr_infolist, ptr_bar->bar_window)) + { + infolist_free (ptr_infolist); + return NULL; + } + } + } + for (ptr_window = gui_windows; ptr_window; + ptr_window = ptr_window->next_window) + { + for (ptr_bar_window = ptr_window->bar_windows; + ptr_bar_window; + ptr_bar_window = ptr_bar_window->next_bar_window) + { + if (!gui_bar_window_add_to_infolist (ptr_infolist, ptr_bar_window)) + { + infolist_free (ptr_infolist); + return NULL; + } + } + } + return ptr_infolist; + } + } + } + else if (string_strcasecmp (infolist_name, "buffer") == 0) { /* invalid buffer pointer ? */ if (pointer && (!gui_buffer_valid (pointer))) @@ -380,16 +506,12 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name, return ptr_infolist; } } - else if (string_strcasecmp (infolist_name, "nicklist") == 0) + else if (string_strcasecmp (infolist_name, "hook") == 0) { - /* invalid buffer pointer ? */ - if (!pointer || (!gui_buffer_valid (pointer))) - return NULL; - ptr_infolist = infolist_new (); if (ptr_infolist) { - if (!gui_nicklist_add_to_infolist (ptr_infolist, pointer)) + if (!hook_add_to_infolist (ptr_infolist, arguments)) { infolist_free (ptr_infolist); return NULL; @@ -397,60 +519,6 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name, return ptr_infolist; } } - else if (string_strcasecmp (infolist_name, "window") == 0) - { - /* invalid window pointer ? */ - if (pointer && (!gui_window_valid (pointer))) - return NULL; - - ptr_infolist = infolist_new (); - if (ptr_infolist) - { - if (pointer) - { - /* build list with only one window */ - if (!gui_window_add_to_infolist (ptr_infolist, pointer)) - { - infolist_free (ptr_infolist); - return NULL; - } - return ptr_infolist; - } - else - { - if (arguments && arguments[0]) - { - if ((string_strcasecmp (arguments, "current") == 0) - && gui_current_window) - { - if (!gui_window_add_to_infolist (ptr_infolist, - gui_current_window)) - { - infolist_free (ptr_infolist); - return NULL; - } - return ptr_infolist; - } - return NULL; - } - else - { - /* build list with all windows */ - for (ptr_window = gui_windows; ptr_window; - ptr_window = ptr_window->next_window) - { - if (!gui_window_add_to_infolist (ptr_infolist, - ptr_window)) - { - infolist_free (ptr_infolist); - return NULL; - } - } - return ptr_infolist; - } - } - } - } else if (string_strcasecmp (infolist_name, "hotlist") == 0) { ptr_infolist = infolist_new (); @@ -468,12 +536,16 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name, return ptr_infolist; } } - else if (string_strcasecmp (infolist_name, "option") == 0) + else if (string_strcasecmp (infolist_name, "nicklist") == 0) { + /* invalid buffer pointer ? */ + if (!pointer || (!gui_buffer_valid (pointer))) + return NULL; + ptr_infolist = infolist_new (); if (ptr_infolist) { - if (!config_file_add_to_infolist (ptr_infolist, arguments)) + if (!gui_nicklist_add_to_infolist (ptr_infolist, pointer)) { infolist_free (ptr_infolist); return NULL; @@ -481,12 +553,12 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name, return ptr_infolist; } } - else if (string_strcasecmp (infolist_name, "hook") == 0) + else if (string_strcasecmp (infolist_name, "option") == 0) { ptr_infolist = infolist_new (); if (ptr_infolist) { - if (!hook_add_to_infolist (ptr_infolist, arguments)) + if (!config_file_add_to_infolist (ptr_infolist, arguments)) { infolist_free (ptr_infolist); return NULL; @@ -529,6 +601,60 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name, } } } + else if (string_strcasecmp (infolist_name, "window") == 0) + { + /* invalid window pointer ? */ + if (pointer && (!gui_window_valid (pointer))) + return NULL; + + ptr_infolist = infolist_new (); + if (ptr_infolist) + { + if (pointer) + { + /* build list with only one window */ + if (!gui_window_add_to_infolist (ptr_infolist, pointer)) + { + infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + else + { + if (arguments && arguments[0]) + { + if ((string_strcasecmp (arguments, "current") == 0) + && gui_current_window) + { + if (!gui_window_add_to_infolist (ptr_infolist, + gui_current_window)) + { + infolist_free (ptr_infolist); + return NULL; + } + return ptr_infolist; + } + return NULL; + } + else + { + /* build list with all windows */ + for (ptr_window = gui_windows; ptr_window; + ptr_window = ptr_window->next_window) + { + if (!gui_window_add_to_infolist (ptr_infolist, + ptr_window)) + { + infolist_free (ptr_infolist); + return NULL; + } + } + return ptr_infolist; + } + } + } + } /* infolist not found */ return NULL; @@ -699,22 +825,28 @@ plugin_api_init () &plugin_api_info_get_internal, NULL); /* WeeChat core infolist hooks */ + hook_infolist (NULL, "bar", N_("list of bars"), + &plugin_api_infolist_get_internal, NULL); + hook_infolist (NULL, "bar_item", N_("list of bar items"), + &plugin_api_infolist_get_internal, NULL); + hook_infolist (NULL, "bar_window", N_("list of bar windows"), + &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "buffer", N_("list of buffers"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "buffer_lines", N_("lines of a buffer"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "filter", N_("list of filters"), &plugin_api_infolist_get_internal, NULL); - hook_infolist (NULL, "nicklist", N_("nicks in nicklist for a buffer"), - &plugin_api_infolist_get_internal, NULL); - hook_infolist (NULL, "window", N_("list of windows"), + hook_infolist (NULL, "hook", N_("list of hooks"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "hotlist", N_("list of buffers in hotlist"), &plugin_api_infolist_get_internal, NULL); - hook_infolist (NULL, "option", N_("list of options"), + hook_infolist (NULL, "nicklist", N_("nicks in nicklist for a buffer"), &plugin_api_infolist_get_internal, NULL); - hook_infolist (NULL, "hook", N_("list of hooks"), + hook_infolist (NULL, "option", N_("list of options"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "plugin", N_("list of plugins"), &plugin_api_infolist_get_internal, NULL); + hook_infolist (NULL, "window", N_("list of windows"), + &plugin_api_infolist_get_internal, NULL); } diff --git a/src/plugins/scripts/script.c b/src/plugins/scripts/script.c index 9095bca28..7b44e5e2c 100644 --- a/src/plugins/scripts/script.c +++ b/src/plugins/scripts/script.c @@ -175,9 +175,9 @@ char * script_ptr2str (void *pointer) { char pointer_str[128]; - + if (!pointer) - return strdup (""); + return strdup ("0x0"); snprintf (pointer_str, sizeof (pointer_str), "0x%lx", (long unsigned int)pointer); diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 6a1ad8970..3a07ae3e4 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -496,8 +496,7 @@ struct t_weechat_plugin void (*bar_item_update) (const char *name); void (*bar_item_remove) (struct t_gui_bar_item *item); struct t_gui_bar *(*bar_search) (const char *name); - struct t_gui_bar *(*bar_new) (struct t_weechat_plugin *plugin, - const char *name, + struct t_gui_bar *(*bar_new) (const char *name, const char *hidden, const char *priority, const char *type, @@ -1004,12 +1003,12 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); __filling_left_right, __size, __size_max, \ __color_fg, __color_delim, __color_bg, \ __separator, __items) \ - weechat_plugin->bar_new(weechat_plugin, __name, __hidden, \ - __priority, __type, __condition, \ - __position, __filling_top_bottom, \ - __filling_left_right, __size, __size_max, \ - __color_fg, __color_delim, __color_bg, \ - __separator, __items) + weechat_plugin->bar_new(__name, __hidden, __priority, __type, \ + __condition, __position, \ + __filling_top_bottom, __filling_left_right, \ + __size, __size_max, __color_fg, \ + __color_delim, __color_bg, __separator, \ + __items) #define weechat_bar_set(__bar, __property, __value) \ weechat_plugin->bar_set(__bar, __property, __value) #define weechat_bar_update(__name) \ |