void gui_line_free_all (struct t_gui_buffer *buffer) { while (buffer->own_lines->first_line) { gui_line_free (buffer, buffer->own_lines->first_line); } }
void gui_chat_printf_y (struct t_gui_buffer *buffer, int y, const char *message, ...) { va_list argptr; struct t_gui_line *ptr_line; if (gui_init_ok) { if (!buffer) buffer = gui_buffer_search_main (); if (buffer->type != GUI_BUFFER_TYPE_FREE) buffer = gui_buffers; if (buffer->type != GUI_BUFFER_TYPE_FREE) return; } if (!gui_chat_buffer) gui_chat_buffer = malloc (GUI_CHAT_BUFFER_PRINTF_SIZE); if (!gui_chat_buffer) return; va_start (argptr, message); vsnprintf (gui_chat_buffer, GUI_CHAT_BUFFER_PRINTF_SIZE, message, argptr); va_end (argptr); utf8_normalize (gui_chat_buffer, '?'); /* no message: delete line */ if (!gui_chat_buffer[0]) { if (gui_init_ok) { for (ptr_line = buffer->own_lines->first_line; ptr_line; ptr_line = ptr_line->next_line) { if (ptr_line->data->y >= y) break; } if (ptr_line && (ptr_line->data->y == y)) { gui_line_free (buffer, ptr_line); gui_buffer_ask_chat_refresh (buffer, 2); } } } else { if (gui_init_ok) { gui_line_add_y (buffer, y, gui_chat_buffer); gui_buffer_ask_chat_refresh (buffer, 1); } else string_iconv_fprintf (stdout, "%s\n", gui_chat_buffer); } }
void gui_chat_printf_y (struct t_gui_buffer *buffer, int y, const char *message, ...) { struct t_gui_line *ptr_line; int i, num_lines_to_add; if (!gui_buffer_valid (buffer)) return; if (gui_init_ok) { if (!buffer) buffer = gui_buffer_search_main (); if (!buffer || buffer->closing) return; if (buffer->type != GUI_BUFFER_TYPE_FREE) buffer = gui_buffers; if (buffer->type != GUI_BUFFER_TYPE_FREE) return; } weechat_va_format (message); if (!vbuffer) return; utf8_normalize (vbuffer, '?'); /* no message: delete line */ if (!vbuffer[0]) { if (gui_init_ok && (y >= 0)) { for (ptr_line = buffer->own_lines->first_line; ptr_line; ptr_line = ptr_line->next_line) { if (ptr_line->data->y >= y) break; } if (ptr_line && (ptr_line->data->y == y)) { if (ptr_line->next_line) gui_line_clear (ptr_line); else gui_line_free (buffer, ptr_line); gui_buffer_ask_chat_refresh (buffer, 2); } } } else { if (gui_init_ok) { /* if y is negative, add a line -N lines after the last line */ if (y < 0) { y = (buffer->own_lines && buffer->own_lines->last_line) ? buffer->own_lines->last_line->data->y - y : (-1 * y) - 1; } /* compute the number of lines to add before y */ if (buffer->own_lines && buffer->own_lines->last_line) num_lines_to_add = y - buffer->own_lines->last_line->data->y - 1; else num_lines_to_add = y; if (num_lines_to_add > 0) { /* * add empty line(s) before asked line, to ensure there is at * least "y" lines in buffer, and then be able to scroll * properly buffer page by page */ for (i = y - num_lines_to_add; i < y; i++) { gui_line_add_y (buffer, i, ""); } } gui_line_add_y (buffer, y, vbuffer); gui_buffer_ask_chat_refresh (buffer, 1); } else string_fprintf (stdout, "%s\n", vbuffer); } free (vbuffer); }
struct t_gui_line * gui_line_add (struct t_gui_buffer *buffer, time_t date, time_t date_printed, const char *tags, const char *prefix, const char *message) { struct t_gui_line *new_line; struct t_gui_line_data *new_line_data; struct t_gui_window *ptr_win; char *message_for_signal; const char *nick; int notify_level, *max_notify_level, lines_removed; time_t current_time; /* * remove line(s) if necessary, according to history options: * max_lines: if > 0, keep only N lines in buffer * max_minutes: if > 0, keep only lines from last N minutes */ lines_removed = 0; current_time = time (NULL); while (buffer->own_lines->first_line && (((CONFIG_INTEGER(config_history_max_buffer_lines_number) > 0) && (buffer->own_lines->lines_count + 1 > CONFIG_INTEGER(config_history_max_buffer_lines_number))) || ((CONFIG_INTEGER(config_history_max_buffer_lines_minutes) > 0) && (current_time - buffer->own_lines->first_line->data->date_printed > CONFIG_INTEGER(config_history_max_buffer_lines_minutes) * 60)))) { gui_line_free (buffer, buffer->own_lines->first_line); lines_removed++; } /* create new line */ new_line = malloc (sizeof (*new_line)); if (!new_line) { log_printf (_("Not enough memory for new line")); return NULL; } /* create data for line */ new_line_data = malloc (sizeof (*(new_line->data))); if (!new_line_data) { free (new_line); log_printf (_("Not enough memory for new line")); return NULL; } new_line->data = new_line_data; /* fill data in new line */ new_line->data->buffer = buffer; new_line->data->y = -1; new_line->data->date = date; new_line->data->date_printed = date_printed; new_line->data->str_time = gui_chat_get_time_string (date); gui_line_tags_alloc (new_line->data, tags); new_line->data->refresh_needed = 0; new_line->data->prefix = (prefix) ? (char *)string_shared_get (prefix) : ((date != 0) ? (char *)string_shared_get ("") : NULL); new_line->data->prefix_length = (prefix) ? gui_chat_strlen_screen (prefix) : 0; new_line->data->message = (message) ? strdup (message) : strdup (""); /* get notify level and max notify level for nick in buffer */ notify_level = gui_line_get_notify_level (new_line); max_notify_level = NULL; nick = gui_line_get_nick_tag (new_line); if (nick) max_notify_level = hashtable_get (buffer->hotlist_max_level_nicks, nick); if (max_notify_level && (*max_notify_level < notify_level)) notify_level = *max_notify_level; if (notify_level == GUI_HOTLIST_HIGHLIGHT) new_line->data->highlight = 1; else if (max_notify_level && (*max_notify_level < GUI_HOTLIST_HIGHLIGHT)) new_line->data->highlight = 0; else new_line->data->highlight = gui_line_has_highlight (new_line); /* check if line is filtered or not */ new_line->data->displayed = gui_filter_check_line (new_line->data); /* add line to lines list */ gui_line_add_to_list (buffer->own_lines, new_line); /* update hotlist and/or send signals for line */ if (new_line->data->displayed) { if (new_line->data->highlight) { (void) gui_hotlist_add (buffer, GUI_HOTLIST_HIGHLIGHT, NULL); if (!weechat_upgrading) { message_for_signal = gui_chat_build_string_prefix_message (new_line); if (message_for_signal) { hook_signal_send ("weechat_highlight", WEECHAT_HOOK_SIGNAL_STRING, message_for_signal); free (message_for_signal); } } } else { if (!weechat_upgrading && (notify_level == GUI_HOTLIST_PRIVATE)) { message_for_signal = gui_chat_build_string_prefix_message (new_line); if (message_for_signal) { hook_signal_send ("weechat_pv", WEECHAT_HOOK_SIGNAL_STRING, message_for_signal); free (message_for_signal); } } if (notify_level >= GUI_HOTLIST_MIN) (void) gui_hotlist_add (buffer, notify_level, NULL); } } else { buffer->own_lines->lines_hidden++; if (buffer->mixed_lines) buffer->mixed_lines->lines_hidden++; hook_signal_send ("buffer_lines_hidden", WEECHAT_HOOK_SIGNAL_POINTER, buffer); } /* add mixed line, if buffer is attached to at least one other buffer */ if (buffer->mixed_lines) { gui_line_mixed_add (buffer->mixed_lines, new_line->data); } /* * if some lines were removed, force a full refresh if at least one window * is displaying buffer and that number of lines in buffer is lower than * window height */ if (lines_removed > 0) { for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { if ((ptr_win->buffer == buffer) && (buffer->own_lines->lines_count < ptr_win->win_chat_height)) { gui_buffer_ask_chat_refresh (buffer, 2); break; } } } hook_signal_send ("buffer_line_added", WEECHAT_HOOK_SIGNAL_POINTER, new_line); return new_line; }