summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-10-11 16:29:15 +0200
committerSebastien Helleu <flashcode@flashtux.org>2010-10-11 16:29:15 +0200
commitfe2a36136429f451db2546b10502df2655a2b1c8 (patch)
tree30ed8c1fc9be1c5da04470d1bebfd78087e89b64 /src/gui
parentf32e18c717520e3482b1a4155ff4e804da7aecbb (diff)
downloadweechat-fe2a36136429f451db2546b10502df2655a2b1c8.zip
Add property "no_highlight_nicks" in buffers to disable highlight for some nicks in buffer
This can be used with script buffer_autoset.py (see /help autosetbuffer).
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui-buffer.c117
-rw-r--r--src/gui/gui-buffer.h3
-rw-r--r--src/gui/gui-line.c31
3 files changed, 148 insertions, 3 deletions
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 053abb559..4462458b8 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -84,7 +84,7 @@ char *gui_buffer_properties_get_integer[] =
};
char *gui_buffer_properties_get_string[] =
{ "plugin", "name", "short_name", "title", "input", "text_search_input",
- "highlight_words", "highlight_tags",
+ "highlight_words", "highlight_tags", "no_highlight_nicks",
NULL
};
char *gui_buffer_properties_get_pointer[] =
@@ -95,8 +95,9 @@ char *gui_buffer_properties_set[] =
{ "unread", "display", "print_hooks_enabled", "number", "name", "short_name",
"type", "notify", "title", "time_for_each_line", "nicklist",
"nicklist_case_sensitive", "nicklist_display_groups", "highlight_words",
- "highlight_words_add", "highlight_words_del", "highlight_tags", "input",
- "input_pos", "input_get_unknown_commands",
+ "highlight_words_add", "highlight_words_del", "highlight_tags",
+ "no_highlight_nicks", "no_highlight_nicks_add", "no_highlight_nicks_del",
+ "input", "input_pos", "input_get_unknown_commands",
NULL
};
@@ -459,6 +460,11 @@ gui_buffer_new (struct t_weechat_plugin *plugin,
new_buffer->highlight_tags = NULL;
new_buffer->highlight_tags_count = 0;
new_buffer->highlight_tags_array = NULL;
+ new_buffer->no_highlight_nicks = hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
/* keys */
new_buffer->keys = NULL;
@@ -748,6 +754,8 @@ gui_buffer_get_string (struct t_gui_buffer *buffer, const char *property)
return buffer->highlight_words;
else if (string_strcasecmp (property, "highlight_tags") == 0)
return buffer->highlight_tags;
+ else if (string_strcasecmp (property, "no_highlight_nicks") == 0)
+ return hashtable_get_string (buffer->no_highlight_nicks, "keys");
else if (string_strncasecmp (property, "localvar_", 9) == 0)
{
ptr_value = (const char *)hashtable_get (buffer->local_variables,
@@ -1096,6 +1104,87 @@ gui_buffer_set_highlight_tags (struct t_gui_buffer *buffer,
}
/*
+ * gui_buffer_set_no_highlight_nicks: set no_highlight_nicks for a buffer
+ */
+
+void
+gui_buffer_set_no_highlight_nicks (struct t_gui_buffer *buffer,
+ const char *new_no_highlight_nicks)
+{
+ char **nicks;
+ int nicks_count, i;
+
+ hashtable_remove_all (buffer->no_highlight_nicks);
+
+ if (new_no_highlight_nicks && new_no_highlight_nicks[0])
+ {
+ nicks = string_split (new_no_highlight_nicks, ",", 0, 0, &nicks_count);
+ if (nicks)
+ {
+ for (i = 0; i < nicks_count; i++)
+ {
+ hashtable_set (buffer->no_highlight_nicks, nicks[i], NULL);
+ }
+ string_free_split (nicks);
+ }
+ }
+}
+
+/*
+ * gui_buffer_add_no_highlight_nicks: add nicks to no_highlight_nicks for a
+ * buffer
+ */
+
+void
+gui_buffer_add_no_highlight_nicks (struct t_gui_buffer *buffer,
+ const char *nicks_to_add)
+{
+ char **nicks;
+ int nicks_count, i;
+
+ if (!nicks_to_add)
+ return;
+
+ nicks = string_split (nicks_to_add, ",", 0, 0,
+ &nicks_count);
+ if (nicks)
+ {
+ for (i = 0; i < nicks_count; i++)
+ {
+ hashtable_set (buffer->no_highlight_nicks, nicks[i], NULL);
+ }
+ string_free_split (nicks);
+ }
+}
+
+/*
+ * gui_buffer_remove_no_highlight_nicks: remove nicks from no_highlight_nicks
+ * in a buffer
+ */
+
+void
+gui_buffer_remove_no_highlight_nicks (struct t_gui_buffer *buffer,
+ const char *nicks_to_remove)
+{
+ char **nicks;
+ int nicks_count, i;
+
+ if (!nicks_to_remove)
+ return;
+
+ nicks = string_split (nicks_to_remove, ",", 0, 0,
+ &nicks_count);
+ if (nicks)
+ {
+ for (i = 0; i < nicks_count; i++)
+ {
+ hashtable_remove (buffer->no_highlight_nicks, nicks[i]);
+ }
+ string_free_split (nicks);
+ }
+}
+
+/*
* gui_buffer_set_input_get_unknown_commands: set "input_get_unknown_commands"
* flag for a buffer
*/
@@ -1268,6 +1357,18 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
{
gui_buffer_set_highlight_tags (buffer, value);
}
+ else if (string_strcasecmp (property, "no_highlight_nicks") == 0)
+ {
+ gui_buffer_set_no_highlight_nicks (buffer, value);
+ }
+ else if (string_strcasecmp (property, "no_highlight_nicks_add") == 0)
+ {
+ gui_buffer_add_no_highlight_nicks (buffer, value);
+ }
+ else if (string_strcasecmp (property, "no_highlight_nicks_del") == 0)
+ {
+ gui_buffer_remove_no_highlight_nicks (buffer, value);
+ }
else if (string_strncasecmp (property, "key_bind_", 9) == 0)
{
gui_keyboard_bind (buffer, property + 9, value);
@@ -1816,6 +1917,8 @@ gui_buffer_close (struct t_gui_buffer *buffer)
free (buffer->highlight_tags);
if (buffer->highlight_tags_array)
string_free_split (buffer->highlight_tags_array);
+ if (buffer->no_highlight_nicks)
+ hashtable_free (buffer->no_highlight_nicks);
gui_keyboard_free_all (&buffer->keys, &buffer->last_key,
&buffer->keys_count);
gui_buffer_local_var_remove_all (buffer);
@@ -2718,6 +2821,8 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!infolist_new_var_string (ptr_item, "highlight_tags", buffer->highlight_tags))
return 0;
+ if (!infolist_new_var_string (ptr_item, "no_highlight_nicks", hashtable_get_string (buffer->no_highlight_nicks, "keys")))
+ return 0;
i = 0;
for (ptr_key = buffer->keys; ptr_key; ptr_key = ptr_key->next_key)
{
@@ -2898,6 +3003,12 @@ gui_buffer_print_log ()
log_printf (" prev_buffer. . . . . . : 0x%lx", ptr_buffer->prev_buffer);
log_printf (" next_buffer. . . . . . : 0x%lx", ptr_buffer->next_buffer);
+ if (ptr_buffer->no_highlight_nicks)
+ {
+ hashtable_print_log (ptr_buffer->no_highlight_nicks,
+ "no_highlight_nicks");
+ }
+
if (ptr_buffer->keys)
{
log_printf ("");
diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h
index 17be7ed1d..fbe8c4afb 100644
--- a/src/gui/gui-buffer.h
+++ b/src/gui/gui-buffer.h
@@ -162,6 +162,7 @@ struct t_gui_buffer
int highlight_tags_count; /* number of tags to highlight */
/* (if 0, any tag is highlighted) */
char **highlight_tags_array; /* tags to highlight */
+ struct t_hashtable *no_highlight_nicks; /* nicks to NOT highlight */
/* keys associated to buffer */
struct t_gui_key *keys; /* keys specific to buffer */
@@ -231,6 +232,8 @@ extern void gui_buffer_set_highlight_words (struct t_gui_buffer *buffer,
const char *new_highlight_words);
extern void gui_buffer_set_highlight_tags (struct t_gui_buffer *buffer,
const char *new_highlight_tags);
+extern void gui_buffer_set_no_highlight_nicks (struct t_gui_buffer *buffer,
+ const char *new_no_highlight_nicks);
extern void gui_buffer_set_unread (struct t_gui_buffer *buffer);
extern void gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
const char *value);
diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c
index 3aa4b695c..f2cc03583 100644
--- a/src/gui/gui-line.c
+++ b/src/gui/gui-line.c
@@ -30,6 +30,7 @@
#include "../core/weechat.h"
#include "../core/wee-config.h"
+#include "../core/wee-hashtable.h"
#include "../core/wee-hook.h"
#include "../core/wee-infolist.h"
#include "../core/wee-log.h"
@@ -378,6 +379,24 @@ gui_line_match_tags (struct t_gui_line *line, int tags_count,
}
/*
+ * gui_line_get_nick_tag: get nick in tags: return "xxx" if tag "nick_xxx"
+ * is found
+ */
+
+const char *
+gui_line_get_nick_tag (struct t_gui_line *line)
+{
+ int i;
+
+ for (i = 0; i < line->data->tags_count; i++)
+ {
+ if (strncmp (line->data->tags_array[i], "nick_", 5) == 0)
+ return line->data->tags_array[i] + 5;
+ }
+ return NULL;
+}
+
+/*
* gui_line_has_highlight: return 1 if given message contains highlight (with
* a string in global highlight or buffer highlight)
*/
@@ -387,6 +406,7 @@ gui_line_has_highlight (struct t_gui_line *line)
{
int rc, i;
char *msg_no_color, *highlight_words;
+ const char *nick;
/*
* highlights are disabled on this buffer? (special value "-" means that
@@ -414,6 +434,17 @@ gui_line_has_highlight (struct t_gui_line *line)
line->data->buffer->highlight_tags_array))
return 0;
}
+
+ /*
+ * if a nick is defined in tags ("nick_xxx"), then check if highlight is
+ * disabled for this nick (using hashtable buffer->no_highlight_nicks)
+ */
+ nick = gui_line_get_nick_tag (line);
+ if (nick)
+ {
+ if (hashtable_has_key (line->data->buffer->no_highlight_nicks, nick))
+ return 0;
+ }
/* remove color codes from line message */
msg_no_color = gui_color_decode (line->data->message, NULL);