void gui_line_get_prefix_for_display (struct t_gui_line *line, char **prefix, int *length, char **color, int *prefix_is_nick) { 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) { /* return empty prefix */ if (prefix) *prefix = gui_chat_prefix_empty; if (length) *length = 0; if (color) *color = NULL; } else { /* return prefix from option "weechat.look.prefix_same_nick" */ if (prefix) *prefix = CONFIG_STRING(config_look_prefix_same_nick); if (length) *length = config_length_prefix_same_nick; if (color) { tag_prefix_nick = gui_line_search_tag_starting_with (line, "prefix_nick_"); *color = (tag_prefix_nick) ? (char *)(tag_prefix_nick + 12) : NULL; } } if (prefix_is_nick) *prefix_is_nick = 0; } else { /* not same nick: return prefix from line */ if (prefix) *prefix = line->data->prefix; if (length) *length = line->data->prefix_length; if (color) *color = NULL; if (prefix_is_nick) *prefix_is_nick = gui_line_search_tag_starting_with (line, "prefix_nick_") ? 1 : 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; }
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; }
int gui_line_has_offline_nick (struct t_gui_line *line) { const char *nick; if (line && gui_line_search_tag_starting_with (line, "prefix_nick")) { nick = gui_line_get_nick_tag (line); if (nick && (line->data->buffer->nicklist_root && (line->data->buffer->nicklist_root->nicks || line->data->buffer->nicklist_root->children)) && !gui_nicklist_search_nick (line->data->buffer, NULL, nick)) { return 1; } } return 0; }
int gui_chat_hsignal_quote_line_cb (const void *pointer, void *data, const char *signal, struct t_hashtable *hashtable) { const char *date, *line, *prefix, *ptr_prefix, *message; long unsigned int value; long number; struct tm *local_time; struct t_gui_line *ptr_line; int is_nick, length_time, length_nick_prefix, length_prefix; int length_nick_suffix, length_message, length, rc; time_t line_date; char str_time[128], *str, *error; /* make C compiler happy */ (void) pointer; (void) data; if (!gui_current_window->buffer->input) return WEECHAT_RC_OK; /* get time */ str_time[0] = '\0'; date = (strstr (signal, "time")) ? hashtable_get (hashtable, "_chat_line_date") : NULL; if (date) { number = strtol (date, &error, 10); if (error && !error[0]) { line_date = (time_t)number; local_time = localtime (&line_date); if (local_time) { strftime (str_time, sizeof (str_time), CONFIG_STRING(config_look_quote_time_format), local_time); } } } /* check if the prefix is a nick */ is_nick = 0; line = hashtable_get (hashtable, "_chat_line"); if (line && line[0]) { rc = sscanf (line, "%lx", &value); if ((rc != EOF) && (rc != 0)) { ptr_line = (struct t_gui_line *)value; if (gui_line_search_tag_starting_with (ptr_line, "prefix_nick")) is_nick = 1; } } /* get prefix + message */ prefix = (strstr (signal, "prefix")) ? hashtable_get (hashtable, "_chat_line_prefix") : NULL; ptr_prefix = prefix; if (ptr_prefix) { while (ptr_prefix[0] == ' ') { ptr_prefix++; } } message = hashtable_get (hashtable, "_chat_line_message"); if (!message) return WEECHAT_RC_OK; length_time = strlen (str_time); length_nick_prefix = strlen (CONFIG_STRING(config_look_quote_nick_prefix)); length_prefix = (ptr_prefix) ? strlen (ptr_prefix) : 0; length_nick_suffix = strlen (CONFIG_STRING(config_look_quote_nick_suffix)); length_message = strlen (message); length = length_time + 1 + length_nick_prefix + length_prefix + length_nick_suffix + 1 + length_message + 1 + 1; str = malloc (length); if (str) { snprintf (str, length, "%s%s%s%s%s%s%s ", str_time, (str_time[0]) ? " " : "", (ptr_prefix && ptr_prefix[0] && is_nick) ? CONFIG_STRING(config_look_quote_nick_prefix) : "", (ptr_prefix) ? ptr_prefix : "", (ptr_prefix && ptr_prefix[0] && is_nick) ? CONFIG_STRING(config_look_quote_nick_suffix) : "", (ptr_prefix && ptr_prefix[0]) ? " " : "", message); gui_input_insert_string (gui_current_window->buffer, str, -1); gui_input_text_changed_modifier_and_signal (gui_current_window->buffer, 1, /* save undo */ 1); /* stop completion */ free (str); } return WEECHAT_RC_OK; }