summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2011-03-09 10:13:41 +0100
committerSebastien Helleu <flashcode@flashtux.org>2011-03-09 10:13:41 +0100
commite2510cbd0426cecadb15b5049220cea39b87195b (patch)
treee3f46414854b51b30a25910cae2b0ce834386eac /src
parent78435e83ee4e2f40d7cdc0bfbaad33a0710a38fd (diff)
downloadweechat-e2510cbd0426cecadb15b5049220cea39b87195b.zip
Allow list of buffers in command /filter (exclusion with prefix "!") (task #10880)
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-command.c51
-rw-r--r--src/core/wee-config.c4
-rw-r--r--src/gui/gui-filter.c105
-rw-r--r--src/gui/gui-filter.h12
-rw-r--r--src/gui/gui-line.c17
5 files changed, 100 insertions, 89 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 16aae65ea..a8121a3b3 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -1183,7 +1183,7 @@ void
command_filter_display (struct t_gui_filter *filter)
{
gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
- _(" %s[%s%s%s]%s buffer: %s%s%s%s%s "
+ _(" %s[%s%s%s]%s buffer: %s%s%s "
"/ tags: %s / regex: %s %s"),
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT),
@@ -1191,8 +1191,6 @@ command_filter_display (struct t_gui_filter *filter)
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT),
GUI_COLOR(GUI_COLOR_CHAT_BUFFER),
- (filter->plugin_name) ? filter->plugin_name : "",
- (filter->plugin_name) ? "." : "",
filter->buffer_name,
GUI_COLOR(GUI_COLOR_CHAT),
filter->tags,
@@ -4773,28 +4771,34 @@ command_init ()
"to tags or regex"),
N_("list"
" || enable|disable|toggle [<name>]"
- " || add <name> <plugin.buffer> <tags> <regex>"
+ " || add <name> <buffer>[,<buffer>...] <tags> <regex>"
" || del <name>|-all"),
- N_(" list: list all filters\n"
- " enable: enable filters (filters are enabled by "
+ N_(" list: list all filters\n"
+ " enable: enable filters (filters are enabled by "
"default)\n"
- " disable: disable filters\n"
- " toggle: toggle filters\n"
- " name: filter name\n"
- " add: add a filter\n"
- " del: delete a filter\n"
- " -all: delete all filters\n"
- "plugin.buffer: plugin and buffer where filter is active "
- "(\"*\" for all buffers)\n"
- " tags: comma separated list of tags, for "
+ "disable: disable filters\n"
+ " toggle: toggle filters\n"
+ " name: filter name\n"
+ " add: add a filter\n"
+ " del: delete a filter\n"
+ " -all: delete all filters\n"
+ " buffer: comma separated list of buffers where filter "
+ "is active:\n"
+ " - this is full name including plugin (example: "
+ "\"irc.freenode.#weechat\")\n"
+ " - \"*\" means all buffers\n"
+ " - a name starting with '!' is excluded\n"
+ " - name can start or end with '*' to "
+ "match many buffers\n"
+ " tags: comma separated list of tags, for "
"example: \"irc_join,irc_part,irc_quit\"\n"
- " regex: regular expression to search in line\n"
- " - use '\\t' to separate prefix from message, special "
+ " regex: regular expression to search in line\n"
+ " - use '\\t' to separate prefix from message, special "
"chars like '|' must be escaped: '\\|'\n"
- " - if regex starts with '!', then matching "
+ " - if regex starts with '!', then matching "
"result is reversed (use '\\!' to start with '!')\n"
- " note: two regex are created: one for prefix "
- "and one for message\n\n"
+ " - two regular expressions are created: one for "
+ "prefix and one for message\n\n"
"The default key alt+'=' toggles filtering on/off.\n\n"
"Tags most commonly used:\n"
" no_filter, no_highlight, no_log, log0..log9 (log level),\n"
@@ -4804,8 +4808,11 @@ command_init ()
" irc_numeric, irc_error, irc_action, irc_ctcp, "
"irc_ctcp_reply, irc_smart_filter, away_info.\n\n"
"Examples:\n"
- " use IRC smart filter for join/part/quit messages:\n"
+ " use IRC smart filter on all buffers:\n"
" /filter add irc_smart * irc_smart_filter *\n"
+ " use IRC smart filter on all buffers except those with "
+ "\"#weechat\" in name:\n"
+ " /filter add irc_smart *,!*#weechat* irc_smart_filter *\n"
" filter all IRC join/part/quit messages:\n"
" /filter add joinquit * irc_join,irc_part,irc_quit *\n"
" filter nicks displayed when joining channels or with /names:\n"
@@ -5082,7 +5089,7 @@ command_init ()
hook_command (NULL, "set",
N_("set config options"),
N_("[<option> [<value>]]"),
- N_("option: name of an option (can start or end with \"*\" "
+ N_("option: name of an option (can start or end with '*' "
"to list many options)\n"
" value: new value for option\n\n"
"New value can be, according to variable type:\n"
diff --git a/src/core/wee-config.c b/src/core/wee-config.c
index 3cc9f3731..46a42d20f 100644
--- a/src/core/wee-config.c
+++ b/src/core/wee-config.c
@@ -1305,10 +1305,8 @@ config_weechat_filter_write_cb (void *data, struct t_config_file *config_file,
{
if (!config_file_write_line (config_file,
ptr_filter->name,
- "%s;%s%s%s;%s;%s",
+ "%s;%s;%s;%s",
(ptr_filter->enabled) ? "on" : "off",
- (ptr_filter->plugin_name) ? ptr_filter->plugin_name : "",
- (ptr_filter->plugin_name) ? "." : "",
ptr_filter->buffer_name,
ptr_filter->tags,
ptr_filter->regex))
diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c
index 9510afe45..6fee8c640 100644
--- a/src/gui/gui-filter.c
+++ b/src/gui/gui-filter.c
@@ -68,15 +68,42 @@ gui_filter_line_has_tag_no_filter (struct t_gui_line *line)
}
/*
+ * gui_filter_match_buffer: return 1 if filters matches full name of buffer
+ */
+
+int
+gui_filter_match_buffer (struct t_gui_filter *filter, const char *full_name)
+{
+ int i, match;
+ char *ptr_name;
+
+ match = 0;
+ for (i = 0; i < filter->num_buffers; i++)
+ {
+ ptr_name = filter->buffers[i];
+ if (ptr_name[0] == '!')
+ ptr_name++;
+ if (string_match (full_name, ptr_name, 0))
+ {
+ if (filter->buffers[i][0] == '!')
+ return 0;
+ else
+ match = 1;
+ }
+ }
+
+ return match;
+}
+
+/*
* gui_filter_check_line: return 1 if a line should be displayed, or
* 0 if line is hidden (tag or regex found)
*/
int
-gui_filter_check_line (struct t_gui_buffer *buffer, struct t_gui_line *line)
+gui_filter_check_line (struct t_gui_line *line, const char *buffer_full_name)
{
struct t_gui_filter *ptr_filter;
- const char *buffer_plugin_name;
int rc;
/* line is always displayed if filters are disabled */
@@ -85,19 +112,14 @@ gui_filter_check_line (struct t_gui_buffer *buffer, struct t_gui_line *line)
if (gui_filter_line_has_tag_no_filter (line))
return 1;
-
- buffer_plugin_name = (!buffer->plugin && buffer->plugin_name_for_upgrade) ?
- buffer->plugin_name_for_upgrade : plugin_get_name (buffer->plugin);
for (ptr_filter = gui_filters; ptr_filter;
ptr_filter = ptr_filter->next_filter)
{
if (ptr_filter->enabled)
{
- /* check plugin and buffer names */
- if ((!ptr_filter->plugin_name
- || (string_strcasecmp (buffer_plugin_name, ptr_filter->plugin_name) == 0))
- && string_match (buffer->name, ptr_filter->buffer_name, 0))
+ /* check buffer */
+ if (gui_filter_match_buffer (ptr_filter, buffer_full_name))
{
if ((strcmp (ptr_filter->tags, "*") == 0)
|| (gui_line_match_tags (line,
@@ -136,15 +158,21 @@ gui_filter_buffer (struct t_gui_buffer *buffer)
{
struct t_gui_line *ptr_line;
int line_displayed, lines_hidden;
+ char buffer_full_name[512];
lines_hidden = 0;
buffer->lines->prefix_max_length = CONFIG_INTEGER(config_look_prefix_align_min);
+ snprintf (buffer_full_name, sizeof (buffer_full_name), "%s.%s",
+ (!buffer->plugin && buffer->plugin_name_for_upgrade) ?
+ buffer->plugin_name_for_upgrade : plugin_get_name (buffer->plugin),
+ buffer->name);
+
for (ptr_line = buffer->lines->first_line; ptr_line;
ptr_line = ptr_line->next_line)
{
- line_displayed = gui_filter_check_line (buffer, ptr_line);
+ line_displayed = gui_filter_check_line (ptr_line, buffer_full_name);
if (line_displayed
&& (ptr_line->data->prefix_length > buffer->lines->prefix_max_length))
@@ -247,28 +275,6 @@ gui_filter_disable (struct t_gui_filter *filter)
}
/*
- * gui_filter_search: search a filter
- */
-
-struct t_gui_filter *
-gui_filter_search (const char *buffer_name, const char *tags, const char *regex)
-{
- struct t_gui_filter *ptr_filter;
-
- for (ptr_filter = gui_filters; ptr_filter;
- ptr_filter = ptr_filter->next_filter)
- {
- if ((strcmp (ptr_filter->buffer_name, buffer_name) == 0)
- && (strcmp (ptr_filter->tags, tags) == 0)
- && (strcmp (ptr_filter->regex, regex) == 0))
- return ptr_filter;
- }
-
- /* filter not found */
- return NULL;
-}
-
-/*
* gui_filter_search_by_name: search a filter by name
*/
@@ -298,7 +304,7 @@ gui_filter_new (int enabled, const char *name, const char *buffer_name,
{
struct t_gui_filter *new_filter;
regex_t *regex1, *regex2;
- char *pos_tab, *pos_point, *regex_prefix;
+ char *pos_tab, *regex_prefix;
const char *ptr_start_regex, *pos_regex_message;
if (!name || !buffer_name || !tags || !regex)
@@ -372,22 +378,10 @@ gui_filter_new (int enabled, const char *name, const char *buffer_name,
/* init filter */
new_filter->enabled = enabled;
new_filter->name = strdup (name);
- new_filter->plugin_name = NULL;
- if (buffer_name)
- {
- pos_point = strchr (buffer_name, '.');
- if (pos_point)
- {
- new_filter->plugin_name = string_strndup (buffer_name, pos_point - buffer_name);
- new_filter->buffer_name = strdup (pos_point + 1);
- }
- else
- new_filter->buffer_name = strdup (buffer_name);
- }
- else
- {
- new_filter->buffer_name = strdup ("*");
- }
+ new_filter->buffer_name = strdup ((buffer_name) ? buffer_name : "*");
+ new_filter->buffers = string_split (new_filter->buffer_name,
+ ",", 0, 0,
+ &new_filter->num_buffers);
if (tags)
{
new_filter->tags = (tags) ? strdup (tags) : NULL;
@@ -454,10 +448,10 @@ gui_filter_free (struct t_gui_filter *filter)
/* free data */
if (filter->name)
free (filter->name);
- if (filter->plugin_name)
- free (filter->plugin_name);
if (filter->buffer_name)
free (filter->buffer_name);
+ if (filter->buffers)
+ string_free_split (filter->buffers);
if (filter->tags)
free (filter->tags);
if (filter->tags_array)
@@ -529,8 +523,6 @@ gui_filter_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!infolist_new_var_string (ptr_item, "name", filter->name))
return 0;
- if (!infolist_new_var_string (ptr_item, "plugin_name", filter->plugin_name))
- return 0;
if (!infolist_new_var_string (ptr_item, "buffer_name", filter->buffer_name))
return 0;
if (!infolist_new_var_string (ptr_item, "tags", filter->tags))
@@ -558,6 +550,7 @@ void
gui_filter_print_log ()
{
struct t_gui_filter *ptr_filter;
+ int i;
log_printf ("");
log_printf ("gui_filters_enabled = %d", gui_filters_enabled);
@@ -569,8 +562,12 @@ gui_filter_print_log ()
log_printf ("[filter (addr:0x%lx)]", ptr_filter);
log_printf (" enabled. . . . . . . . : %d", ptr_filter->enabled);
log_printf (" name . . . . . . . . . : '%s'", ptr_filter->name);
- log_printf (" plugin_name. . . . . . : '%s'", ptr_filter->plugin_name);
log_printf (" buffer_name. . . . . . : '%s'", ptr_filter->buffer_name);
+ log_printf (" num_buffers. . . . . . : %d", ptr_filter->num_buffers);
+ for (i = 0; i < ptr_filter->num_buffers; i++)
+ {
+ log_printf (" buffers[%03d] . . . . . : '%s'", i, ptr_filter->buffers[i]);
+ }
log_printf (" tags . . . . . . . . . : '%s'", ptr_filter->tags);
log_printf (" regex. . . . . . . . . : '%s'", ptr_filter->regex);
log_printf (" regex_prefix . . . . . : 0x%lx", ptr_filter->regex_prefix);
diff --git a/src/gui/gui-filter.h b/src/gui/gui-filter.h
index fed7c288a..668b8a506 100644
--- a/src/gui/gui-filter.h
+++ b/src/gui/gui-filter.h
@@ -32,8 +32,9 @@ struct t_gui_filter
{
int enabled; /* 1 if filter enabled, otherwise 0 */
char *name; /* filter name */
- char *plugin_name; /* plugin name */
- char *buffer_name; /* name of buffer */
+ char *buffer_name; /* name of buffer(s) */
+ int num_buffers; /* number of buffers in list */
+ char **buffers; /* list of buffer names */
char *tags; /* tags */
int tags_count; /* number of tags */
char **tags_array; /* array of tags */
@@ -52,15 +53,12 @@ extern int gui_filters_enabled;
/* filter functions */
-extern int gui_filter_check_line (struct t_gui_buffer *buffer,
- struct t_gui_line *line);
+extern int gui_filter_check_line (struct t_gui_line *line,
+ const char *buffer_full_name);
extern void gui_filter_global_enable ();
extern void gui_filter_global_disable ();
extern void gui_filter_enable (struct t_gui_filter *filter);
extern void gui_filter_disable (struct t_gui_filter *filter);
-extern struct t_gui_filter *gui_filter_search (const char *buffer_name,
- const char *tags,
- const char *regex);
extern struct t_gui_filter *gui_filter_search_by_name (const char *name);
extern struct t_gui_filter *gui_filter_new (int enabled,
const char *name,
diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c
index cbdd7ef0a..747f39e92 100644
--- a/src/gui/gui-line.c
+++ b/src/gui/gui-line.c
@@ -754,7 +754,7 @@ gui_line_add (struct t_gui_buffer *buffer, time_t date,
struct t_gui_line *new_line;
struct t_gui_line_data *new_line_data;
struct t_gui_window *ptr_win;
- char *message_for_signal;
+ char *message_for_signal, buffer_full_name[512];
const char *nick;
int notify_level, *max_notify_level;
@@ -819,7 +819,12 @@ gui_line_add (struct t_gui_buffer *buffer, time_t date,
gui_line_add_to_list (buffer->own_lines, new_line);
/* check if line is filtered or not */
- new_line->data->displayed = gui_filter_check_line (buffer, new_line);
+ snprintf (buffer_full_name, sizeof (buffer_full_name), "%s.%s",
+ (!buffer->plugin && buffer->plugin_name_for_upgrade) ?
+ buffer->plugin_name_for_upgrade : plugin_get_name (buffer->plugin),
+ buffer->name);
+ new_line->data->displayed = gui_filter_check_line (new_line,
+ buffer_full_name);
if (new_line->data->displayed)
{
if (new_line->data->highlight)
@@ -900,6 +905,7 @@ gui_line_add_y (struct t_gui_buffer *buffer, int y, const char *message)
{
struct t_gui_line *ptr_line, *new_line;
struct t_gui_line_data *new_line_data;
+ char buffer_full_name[512];
/* search if line exists for "y" */
for (ptr_line = buffer->own_lines->first_line; ptr_line;
@@ -975,7 +981,12 @@ gui_line_add_y (struct t_gui_buffer *buffer, int y, const char *message)
ptr_line->data->message = (message) ? strdup (message) : strdup ("");
/* check if line is filtered or not */
- ptr_line->data->displayed = gui_filter_check_line (buffer, ptr_line);
+ snprintf (buffer_full_name, sizeof (buffer_full_name), "%s.%s",
+ (!buffer->plugin && buffer->plugin_name_for_upgrade) ?
+ buffer->plugin_name_for_upgrade : plugin_get_name (buffer->plugin),
+ buffer->name);
+ ptr_line->data->displayed = gui_filter_check_line (ptr_line,
+ buffer_full_name);
if (!ptr_line->data->displayed)
{
if (!buffer->own_lines->lines_hidden)