diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/gui-filter.c | 40 | ||||
-rw-r--r-- | src/gui/gui-filter.h | 2 | ||||
-rw-r--r-- | src/plugins/plugin-api.c | 20 |
3 files changed, 62 insertions, 0 deletions
diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c index 6919ffc56..bf7a4e53d 100644 --- a/src/gui/gui-filter.c +++ b/src/gui/gui-filter.c @@ -29,6 +29,7 @@ #include "../core/weechat.h" #include "../core/wee-hook.h" +#include "../core/wee-infolist.h" #include "../core/wee-log.h" #include "../core/wee-string.h" #include "../plugins/plugin.h" @@ -408,6 +409,45 @@ gui_filter_free_all () } /* + * gui_filter_add_to_infolist: add a filter in an infolist + * return 1 if ok, 0 if error + */ + +int +gui_filter_add_to_infolist (struct t_infolist *infolist, + struct t_gui_filter *filter) +{ + struct t_infolist_item *ptr_item; + char option_name[64]; + int i; + + if (!infolist || !filter) + return 0; + + ptr_item = infolist_new_item (infolist); + if (!ptr_item) + return 0; + + if (!infolist_new_var_string (ptr_item, "buffer", filter->buffer)) + return 0; + if (!infolist_new_var_string (ptr_item, "tags", filter->tags)) + return 0; + if (!infolist_new_var_integer (ptr_item, "tags_count", filter->tags_count)) + return 0; + for (i = 0; i < filter->tags_count; i++) + { + snprintf (option_name, sizeof (option_name), "tag_%05d", i + 1); + if (!infolist_new_var_string (ptr_item, option_name, + filter->tags_array[i])) + return 0; + } + if (!infolist_new_var_string (ptr_item, "regex", filter->regex)) + return 0; + + return 1; +} + +/* * gui_filter_print_log: print filter infos in log (usually for crash dump) */ diff --git a/src/gui/gui-filter.h b/src/gui/gui-filter.h index 9daa65b4a..3522463bc 100644 --- a/src/gui/gui-filter.h +++ b/src/gui/gui-filter.h @@ -62,6 +62,8 @@ extern struct t_gui_filter *gui_filter_new (const char *buffer, const char *regex); extern void gui_filter_free (struct t_gui_filter *filter); extern void gui_filter_free_all (); +extern int gui_filter_add_to_infolist (struct t_infolist *infolist, + struct t_gui_filter *filter); extern void gui_filter_print_log (); #endif /* gui-filter.h */ diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index c1ce8e414..36f989b63 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -345,6 +345,7 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name, struct t_infolist *ptr_infolist; struct t_gui_buffer *ptr_buffer; struct t_gui_line *ptr_line; + struct t_gui_filter *ptr_filter; struct t_gui_window *ptr_window; struct t_gui_hotlist *ptr_hotlist; @@ -415,6 +416,23 @@ plugin_api_infolist_get_internal (void *data, const char *infolist_name, return ptr_infolist; } } + else if (string_strcasecmp (infolist_name, "filter") == 0) + { + ptr_infolist = infolist_new (); + if (ptr_infolist) + { + for (ptr_filter = gui_filters; ptr_filter; + ptr_filter = ptr_filter->next_filter) + { + if (!gui_filter_add_to_infolist (ptr_infolist, ptr_filter)) + { + infolist_free (ptr_infolist); + return NULL; + } + } + return ptr_infolist; + } + } else if (string_strcasecmp (infolist_name, "nicklist") == 0) { /* invalid buffer pointer ? */ @@ -703,6 +721,8 @@ plugin_api_init () &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"), |