diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/curses/gui-curses-chat.c | 31 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 10 | ||||
-rw-r--r-- | src/gui/gui-filter.c | 14 | ||||
-rw-r--r-- | src/gui/gui-line.c | 176 | ||||
-rw-r--r-- | src/gui/gui-line.h | 7 |
5 files changed, 154 insertions, 84 deletions
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index cbdedbe98..509a6f406 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -575,8 +575,9 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window, int simulate) { char str_space[] = " ", str_plus[] = "+"; - char *prefix_no_color, *prefix_highlighted, *ptr_prefix; - const char *short_name; + char *prefix_no_color, *prefix_highlighted, *ptr_prefix, *ptr_prefix2; + char *ptr_prefix_color; + const char *short_name, *str_color; int i, length, length_allowed, num_spaces, prefix_length, extra_spaces; int chars_displayed; struct t_gui_lines *mixed_lines; @@ -738,8 +739,30 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window, } } + /* get prefix for display */ + gui_line_get_prefix_for_display (line, &ptr_prefix, &prefix_length, + &ptr_prefix_color); + if (ptr_prefix) + { + ptr_prefix2 = NULL; + if (ptr_prefix_color && ptr_prefix_color[0]) + { + str_color = gui_color_get_custom (ptr_prefix_color); + if (str_color && str_color[0]) + { + length = strlen (str_color) + strlen (ptr_prefix) + 1; + ptr_prefix2 = malloc (length); + if (ptr_prefix2) + { + snprintf (ptr_prefix2, length, "%s%s", + str_color, ptr_prefix); + } + } + } + ptr_prefix = (ptr_prefix2) ? ptr_prefix2 : strdup (ptr_prefix); + } + /* display prefix */ - gui_line_get_prefix_for_display (line, &ptr_prefix, &prefix_length); if (ptr_prefix && (ptr_prefix[0] || (CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE))) @@ -921,6 +944,8 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window, lines_displayed, simulate, 0); } } + if (ptr_prefix) + free (ptr_prefix); } /* diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 1e1ee32a8..814619ad9 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -3364,11 +3364,10 @@ gui_buffer_dump_hexa (struct t_gui_buffer *buffer) free (message_without_colors); tags = string_build_with_split_string ((const char **)ptr_line->data->tags_array, ","); - log_printf (" tags: %s, displayed: %d, highlight: %d, prefix_same_nick: %d", + log_printf (" tags: '%s', displayed: %d, highlight: %d", (tags) ? tags : "(none)", ptr_line->data->displayed, - ptr_line->data->highlight, - ptr_line->data->prefix_same_nick); + ptr_line->data->highlight); if (tags) free (tags); snprintf (buf, sizeof (buf), "%s", ctime (&ptr_line->data->date)); @@ -3554,13 +3553,12 @@ gui_buffer_print_log () tags = string_build_with_split_string ((const char **)ptr_line->data->tags_array, ","); log_printf (" line N-%05d: y:%d, str_time:'%s', tags:'%s', " - "displayed:%d, highlight:%d, prefix_same_nick:%d, " - "refresh_needed:%d, prefix:'%s'", + "displayed:%d, highlight:%d, refresh_needed:%d, " + "prefix:'%s'", num, ptr_line->data->y, ptr_line->data->str_time, (tags) ? tags : "", (int)(ptr_line->data->displayed), (int)(ptr_line->data->highlight), - (int)(ptr_line->data->prefix_same_nick), (int)(ptr_line->data->refresh_needed), ptr_line->data->prefix); log_printf (" data: '%s'", diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c index c503954af..fa149b37b 100644 --- a/src/gui/gui-filter.c +++ b/src/gui/gui-filter.c @@ -133,11 +133,9 @@ void gui_filter_buffer (struct t_gui_buffer *buffer) { struct t_gui_line *ptr_line; - int line_displayed, lines_hidden, prev_line_changed, line_changed; + int line_displayed, lines_hidden; lines_hidden = 0; - prev_line_changed = 0; - line_changed = 0; buffer->lines->prefix_max_length = CONFIG_INTEGER(config_look_prefix_align_min); @@ -154,20 +152,10 @@ gui_filter_buffer (struct t_gui_buffer *buffer) /* force chat refresh if at least one line changed */ if (ptr_line->data->displayed != line_displayed) - { - line_changed = 1; gui_buffer_ask_chat_refresh (buffer, 2); - } - else - line_changed = 0; ptr_line->data->displayed = line_displayed; - if (line_changed || prev_line_changed) - gui_line_set_prefix_same_nick (ptr_line); - - prev_line_changed = line_changed; - if (!line_displayed) lines_hidden = 1; } diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index 6b865b816..23399e822 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -84,6 +84,58 @@ gui_lines_free (struct t_gui_lines *lines) } /* + * gui_line_prefix_is_same_nick_as_previous: return 1 if prefix on line is a + * nick and is the same as nick on + * previour line, otherwise 0 + */ + +int +gui_line_prefix_is_same_nick_as_previous (struct t_gui_line *line) +{ + const char *nick, *nick_previous; + struct t_gui_line *prev_line; + + /* + * if line is not displayed, has a highlight, or does not have a tag + * beginning with "prefix_nick" => display standard prefix + */ + if (!line->data->displayed || line->data->highlight + || !gui_line_search_tag_starting_with (line, "prefix_nick")) + return 0; + + /* no nick on line => display standard prefix */ + nick = gui_line_get_nick_tag (line); + if (!nick) + return 0; + + /* + * previous line is not found => display standard prefix + */ + prev_line = gui_line_get_prev_displayed (line); + if (!prev_line) + return 0; + + /* buffer is not the same as previous line => display standard prefix */ + if (line->data->buffer != prev_line->data->buffer) + return 0; + + /* + * previous line does not have a tag beginning with "prefix_nick" + * => display standard prefix + */ + if (!gui_line_search_tag_starting_with (prev_line, "prefix_nick")) + return 0; + + /* no nick on previous line => display standard prefix */ + nick_previous = gui_line_get_nick_tag (prev_line); + if (!nick_previous) + return 0; + + /* prefix can be hidden/replaced if nicks are equal */ + return (strcmp (nick, nick_previous) == 0) ? 1 : 0; +} + +/* * gui_line_get_prefix_for_display: get prefix and its length (for display only) * if the prefix can be hidden (same nick as * previous message), and if the option is @@ -94,29 +146,50 @@ gui_lines_free (struct t_gui_lines *lines) void gui_line_get_prefix_for_display (struct t_gui_line *line, - char **prefix, int *length) + char **prefix, int *length, + char **color) { - if (line->data->prefix_same_nick - && CONFIG_STRING(config_look_prefix_same_nick) - && CONFIG_STRING(config_look_prefix_same_nick)[0]) + const char *tag_prefix_nick; + + if (CONFIG_STRING(config_look_prefix_same_nick) + && CONFIG_STRING(config_look_prefix_same_nick)[0] + && gui_line_prefix_is_same_nick_as_previous (line)) { /* same nick: return empty prefix or value from option */ if (strcmp (CONFIG_STRING(config_look_prefix_same_nick), " ") == 0) { - *prefix = gui_chat_prefix_empty; - *length = 0; + if (prefix) + *prefix = gui_chat_prefix_empty; + if (length) + *length = 0; + if (color) + *color = NULL; } else { - *prefix = CONFIG_STRING(config_look_prefix_same_nick); - *length = config_length_prefix_same_nick; + if (prefix) + *prefix = CONFIG_STRING(config_look_prefix_same_nick); + if (length) + *length = config_length_prefix_same_nick; + if (color) + { + *color = NULL; + tag_prefix_nick = gui_line_search_tag_starting_with (line, + "prefix_nick_"); + if (tag_prefix_nick) + *color = (char *)(tag_prefix_nick + 12); + } } } else { /* not same nick: return prefix from line */ - *prefix = line->data->prefix; - *length = line->data->prefix_length; + if (prefix) + *prefix = line->data->prefix; + if (length) + *length = line->data->prefix_length; + if (color) + *color = NULL; } } @@ -129,7 +202,6 @@ gui_line_get_align (struct t_gui_buffer *buffer, struct t_gui_line *line, int with_suffix, int first_line) { int length_time, length_buffer, length_suffix, prefix_length; - char *ptr_prefix; /* return immediately if alignment for end of lines is "time" */ if (!first_line @@ -179,7 +251,7 @@ gui_line_get_align (struct t_gui_buffer *buffer, struct t_gui_line *line, return length_time + length_buffer; } - gui_line_get_prefix_for_display (line, &ptr_prefix, &prefix_length); + gui_line_get_prefix_for_display (line, NULL, &prefix_length, NULL); if (CONFIG_INTEGER(config_look_prefix_align) == CONFIG_LOOK_PREFIX_ALIGN_NONE) { @@ -421,24 +493,48 @@ 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 + * gui_line_search_tag_starting_with: return pointer on tag starting with "tag", + * NULL if such tag is not found */ const char * -gui_line_get_nick_tag (struct t_gui_line *line) +gui_line_search_tag_starting_with (struct t_gui_line *line, const char *tag) { - int i; + int i, length; + + if (!line || !tag) + return NULL; + + length = strlen (tag); 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; + if (strncmp (line->data->tags_array[i], tag, length) == 0) + return line->data->tags_array[i]; } + + /* tag not found */ return NULL; } /* + * 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) +{ + const char *tag; + + tag = gui_line_search_tag_starting_with (line, "nick_"); + if (!tag) + return NULL; + + return tag + 5; +} + +/* * gui_line_has_highlight: return 1 if given message contains highlight (with * a string in global highlight or buffer highlight) */ @@ -572,51 +668,19 @@ void gui_line_compute_prefix_max_length (struct t_gui_lines *lines) { struct t_gui_line *ptr_line; - char *ptr_prefix; int prefix_length; lines->prefix_max_length = CONFIG_INTEGER(config_look_prefix_align_min); for (ptr_line = lines->first_line; ptr_line; ptr_line = ptr_line->next_line) { - gui_line_get_prefix_for_display (ptr_line, &ptr_prefix, &prefix_length); + gui_line_get_prefix_for_display (ptr_line, NULL, &prefix_length, NULL); if (prefix_length > lines->prefix_max_length) lines->prefix_max_length = prefix_length; } } /* - * gui_line_set_prefix_same_nick: set the "prefix_same_nick" flag in a line - */ - -void -gui_line_set_prefix_same_nick (struct t_gui_line *line) -{ - const char *nick, *nick_previous; - struct t_gui_line *prev_line; - - /* - * check if prefix can be hidden: if nick is the same as previous message - * on this buffer - */ - line->data->prefix_same_nick = 0; - if (line->data->displayed && !line->data->highlight) - { - nick = gui_line_get_nick_tag (line); - if (nick) - { - prev_line = gui_line_get_prev_displayed (line); - if (prev_line) - { - nick_previous = gui_line_get_nick_tag (prev_line); - if (nick_previous && (strcmp (nick, nick_previous) == 0)) - line->data->prefix_same_nick = 1; - } - } - } -} - -/* * gui_line_add_to_list: add a line to a "t_gui_lines" structure */ @@ -624,7 +688,6 @@ void gui_line_add_to_list (struct t_gui_lines *lines, struct t_gui_line *line) { - char *ptr_prefix; int prefix_length; if (!lines->first_line) @@ -635,10 +698,8 @@ gui_line_add_to_list (struct t_gui_lines *lines, line->next_line = NULL; lines->last_line = line; - gui_line_set_prefix_same_nick (line); - /* adjust "prefix_max_length" if this prefix length is > max */ - gui_line_get_prefix_for_display (line, &ptr_prefix, &prefix_length); + gui_line_get_prefix_for_display (line, NULL, &prefix_length, NULL); if (prefix_length > lines->prefix_max_length) lines->prefix_max_length = prefix_length; @@ -658,7 +719,6 @@ gui_line_remove_from_list (struct t_gui_buffer *buffer, struct t_gui_window *ptr_win; struct t_gui_window_scroll *ptr_scroll; int i, update_prefix_max_length, prefix_length; - char *ptr_prefix; for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { @@ -684,7 +744,7 @@ gui_line_remove_from_list (struct t_gui_buffer *buffer, } } - gui_line_get_prefix_for_display (line, &ptr_prefix, &prefix_length); + gui_line_get_prefix_for_display (line, NULL, &prefix_length, NULL); update_prefix_max_length = (prefix_length == lines->prefix_max_length); @@ -1395,8 +1455,6 @@ gui_line_add_to_infolist (struct t_infolist *infolist, return 0; if (!infolist_new_var_integer (ptr_item, "highlight", line->data->highlight)) return 0; - if (!infolist_new_var_integer (ptr_item, "prefix_same_nick", line->data->prefix_same_nick)) - return 0; if (!infolist_new_var_string (ptr_item, "prefix", line->data->prefix)) return 0; if (!infolist_new_var_string (ptr_item, "message", line->data->message)) diff --git a/src/gui/gui-line.h b/src/gui/gui-line.h index eba7b090b..59ce95973 100644 --- a/src/gui/gui-line.h +++ b/src/gui/gui-line.h @@ -37,8 +37,6 @@ struct t_gui_line_data char **tags_array; /* tags for line */ char displayed; /* 1 if line is displayed */ char highlight; /* 1 if line has highlight */ - char prefix_same_nick; /* 1 if prefix can be hidden */ - /* (same nick as previous message) */ char refresh_needed; /* 1 if refresh asked (free buffer) */ char *prefix; /* prefix for line (may be NULL) */ int prefix_length; /* prefix length (on screen) */ @@ -70,7 +68,8 @@ struct t_gui_lines extern struct t_gui_lines *gui_lines_alloc (); extern void gui_lines_free (struct t_gui_lines *lines); extern void gui_line_get_prefix_for_display (struct t_gui_line *line, - char **prefix, int *length); + char **prefix, int *length, + char **color); extern int gui_line_get_align (struct t_gui_buffer *buffer, struct t_gui_line *line, int with_suffix, int first_line); @@ -86,6 +85,8 @@ extern int gui_line_match_regex (struct t_gui_line *line, regex_t *regex_message); extern int gui_line_match_tags (struct t_gui_line *line, int tags_count, char **tags_array); +extern const char *gui_line_search_tag_starting_with (struct t_gui_line *line, + const char *tag); extern const char *gui_line_get_nick_tag (struct t_gui_line *line); extern int gui_line_has_highlight (struct t_gui_line *line); extern void gui_line_compute_buffer_max_length (struct t_gui_buffer *buffer, |