diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui-buffer.c | 9 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 2 | ||||
-rw-r--r-- | src/gui/gui-line.c | 17 | ||||
-rw-r--r-- | src/gui/gui-line.h | 3 |
4 files changed, 30 insertions, 1 deletions
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 16fab2c71..3ffc1bb96 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -92,7 +92,7 @@ char *gui_buffer_properties_get_integer[] = { "number", "layout_number", "layout_number_merge_order", "type", "notify", "num_displayed", "active", "hidden", "zoomed", "print_hooks_enabled", "day_change", "clear", "filter", "closing", "lines_hidden", - "prefix_max_length", "time_for_each_line", "nicklist", + "prefix_max_length", "next_line_id", "time_for_each_line", "nicklist", "nicklist_case_sensitive", "nicklist_max_length", "nicklist_display_groups", "nicklist_count", "nicklist_visible_count", "nicklist_groups_count", "nicklist_groups_visible_count", @@ -742,6 +742,7 @@ gui_buffer_new_props (struct t_weechat_plugin *plugin, new_buffer->own_lines = gui_line_lines_alloc (); new_buffer->mixed_lines = NULL; new_buffer->lines = new_buffer->own_lines; + new_buffer->next_line_id = 0; new_buffer->time_for_each_line = 1; new_buffer->chat_refresh_needed = 2; @@ -1266,6 +1267,8 @@ gui_buffer_get_integer (struct t_gui_buffer *buffer, const char *property) return buffer->lines->lines_hidden; else if (string_strcasecmp (property, "prefix_max_length") == 0) return buffer->lines->prefix_max_length; + else if (string_strcasecmp (property, "next_line_id") == 0) + return buffer->next_line_id; else if (string_strcasecmp (property, "time_for_each_line") == 0) return buffer->time_for_each_line; else if (string_strcasecmp (property, "nicklist") == 0) @@ -4482,6 +4485,7 @@ gui_buffer_hdata_buffer_cb (const void *pointer, void *data, HDATA_VAR(struct t_gui_buffer, own_lines, POINTER, 0, NULL, "lines"); HDATA_VAR(struct t_gui_buffer, mixed_lines, POINTER, 0, NULL, "lines"); HDATA_VAR(struct t_gui_buffer, lines, POINTER, 0, NULL, "lines"); + HDATA_VAR(struct t_gui_buffer, next_line_id, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, time_for_each_line, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, chat_refresh_needed, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, nicklist, INTEGER, 0, NULL, NULL); @@ -4683,6 +4687,8 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist, return 0; if (!infolist_new_var_integer (ptr_item, "prefix_max_length", buffer->lines->prefix_max_length)) return 0; + if (!infolist_new_var_integer (ptr_item, "next_line_id", buffer->next_line_id)) + return 0; if (!infolist_new_var_integer (ptr_item, "time_for_each_line", buffer->time_for_each_line)) return 0; if (!infolist_new_var_integer (ptr_item, "nicklist_case_sensitive", buffer->nicklist_case_sensitive)) @@ -4913,6 +4919,7 @@ gui_buffer_print_log () log_printf (" mixed_lines . . . . . . : 0x%lx", ptr_buffer->mixed_lines); gui_lines_print_log (ptr_buffer->mixed_lines); log_printf (" lines . . . . . . . . . : 0x%lx", ptr_buffer->lines); + log_printf (" next_line_id. . . . . . : %d", ptr_buffer->next_line_id); log_printf (" time_for_each_line. . . : %d", ptr_buffer->time_for_each_line); log_printf (" chat_refresh_needed . . : %d", ptr_buffer->chat_refresh_needed); log_printf (" nicklist. . . . . . . . : %d", ptr_buffer->nicklist); diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index 336e6a316..d4b840e90 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -124,6 +124,8 @@ struct t_gui_buffer struct t_gui_lines *mixed_lines; /* mixed lines (if buffers merged) */ struct t_gui_lines *lines; /* pointer to "own_lines" or */ /* "mixed_lines" */ + int next_line_id; /* next line id */ + /* (used with formatted type only) */ int time_for_each_line; /* time is displayed for each line? */ int chat_refresh_needed; /* refresh for chat is needed ? */ /* (1=refresh, 2=erase+refresh) */ diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index f31d3e2b4..cb69f1787 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -1488,6 +1488,9 @@ gui_line_new (struct t_gui_buffer *buffer, int y, time_t date, struct t_gui_line_data *new_line_data; int max_notify_level; + if (!buffer) + return NULL; + /* create new line */ new_line = malloc (sizeof (*new_line)); if (!new_line) @@ -1508,6 +1511,16 @@ gui_line_new (struct t_gui_buffer *buffer, int y, time_t date, if (buffer->type == GUI_BUFFER_TYPE_FORMATTED) { + /* + * the line identifier is almost unique: when reaching INT_MAX, it is + * reset to 0; it is extremely unlikely all integer are used in the + * same buffer, that would mean the buffer has a huge number of lines; + * when searching a line id in a buffer, it is recommended to start + * from the last line and loop to the first + */ + new_line->data->id = buffer->next_line_id; + buffer->next_line_id = (buffer->next_line_id == INT_MAX) ? + 0 : buffer->next_line_id + 1; new_line->data->y = -1; new_line->data->date = date; new_line->data->date_printed = date_printed; @@ -1526,6 +1539,7 @@ gui_line_new (struct t_gui_buffer *buffer, int y, time_t date, } else { + new_line->data->id = y; new_line->data->y = y; new_line->data->date = date; new_line->data->date_printed = date_printed; @@ -2225,6 +2239,7 @@ gui_line_hdata_line_data_cb (const void *pointer, void *data, if (hdata) { HDATA_VAR(struct t_gui_line_data, buffer, POINTER, 0, NULL, "buffer"); + HDATA_VAR(struct t_gui_line_data, id, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_line_data, y, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_line_data, date, TIME, 1, NULL, NULL); HDATA_VAR(struct t_gui_line_data, date_printed, TIME, 1, NULL, NULL); @@ -2266,6 +2281,8 @@ gui_line_add_to_infolist (struct t_infolist *infolist, if (!ptr_item) return 0; + if (!infolist_new_var_integer (ptr_item, "id", line->data->id)) + return 0; if (!infolist_new_var_integer (ptr_item, "y", line->data->y)) return 0; if (!infolist_new_var_time (ptr_item, "date", line->data->date)) diff --git a/src/gui/gui-line.h b/src/gui/gui-line.h index 9bb7ea95a..9941ab7d4 100644 --- a/src/gui/gui-line.h +++ b/src/gui/gui-line.h @@ -30,6 +30,9 @@ struct t_infolist; struct t_gui_line_data { struct t_gui_buffer *buffer; /* pointer to buffer */ + int id; /* formatted buffer: (almost) unique */ + /* line id in buffer */ + /* free buffer: equals to "y" */ int y; /* line position (for free buffer) */ time_t date; /* date/time of line (may be past) */ time_t date_printed; /* date/time when weechat print it */ |