void gui_chat_change_time_format () { struct t_gui_buffer *ptr_buffer; struct t_gui_line *ptr_line; for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { for (ptr_line = ptr_buffer->lines->first_line; ptr_line; ptr_line = ptr_line->next_line) { if (ptr_line->data->date != 0) { if (ptr_line->data->str_time) free (ptr_line->data->str_time); ptr_line->data->str_time = gui_chat_get_time_string (ptr_line->data->date); } } } }
int gui_chat_get_time_length () { time_t date; char *text_time; int length; if (!CONFIG_STRING(config_look_buffer_time_format) || !CONFIG_STRING(config_look_buffer_time_format)[0]) return 0; length = 0; date = time (NULL); text_time = gui_chat_get_time_string (date); if (text_time) { length = gui_chat_strlen_screen (text_time); free (text_time); } return length; }
int gui_line_hdata_line_data_update_cb (void *data, struct t_hdata *hdata, void *pointer, struct t_hashtable *hashtable) { const char *value; struct t_gui_line_data *line_data; struct t_gui_window *ptr_win; int rc, update_coords; /* make C compiler happy */ (void) data; line_data = (struct t_gui_line_data *)pointer; rc = 0; update_coords = 0; if (hashtable_has_key (hashtable, "date")) { value = hashtable_get (hashtable, "date"); if (value) { hdata_set (hdata, pointer, "date", value); if (line_data->str_time) free (line_data->str_time); line_data->str_time = gui_chat_get_time_string (line_data->date); rc++; update_coords = 1; } } if (hashtable_has_key (hashtable, "date_printed")) { value = hashtable_get (hashtable, "date_printed"); if (value) { hdata_set (hdata, pointer, "date_printed", value); rc++; } } if (hashtable_has_key (hashtable, "tags_array")) { value = hashtable_get (hashtable, "tags_array"); gui_line_tags_free (line_data); gui_line_tags_alloc (line_data, value); rc++; } if (hashtable_has_key (hashtable, "prefix")) { value = hashtable_get (hashtable, "prefix"); hdata_set (hdata, pointer, "prefix", value); line_data->prefix_length = (line_data->prefix) ? gui_chat_strlen_screen (line_data->prefix) : 0; line_data->buffer->lines->prefix_max_length_refresh = 1; rc++; update_coords = 1; } if (hashtable_has_key (hashtable, "message")) { value = hashtable_get (hashtable, "message"); hdata_set (hdata, pointer, "message", value); rc++; update_coords = 1; } if (rc > 0) { if (update_coords) { for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { gui_window_coords_remove_line_data (ptr_win, line_data); } } gui_filter_buffer (line_data->buffer, line_data); gui_buffer_ask_chat_refresh (line_data->buffer, 1); } return rc; }
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; }