From 9d128cad2279ff070d8204e1d3d7003f379c58da Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Mon, 11 Apr 2011 13:57:00 +0200 Subject: core: add messages counts in hotlist for each buffer, option weechat.look.hotlist_buffer_separator and tag "notify_none" New options: - weechat.look.hotlist_buffer_separator - weechat.look.hotlist_count_max - weechat.look.hotlist_count_min_msg - weechat.color.status_count_msg - weechat.color.status_count_private - weechat.color.status_count_highlight - weechat.color.status_count_other --- src/gui/gui-bar-item.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/gui/gui-buffer.c | 2 +- src/gui/gui-hotlist.c | 77 +++++++++++++++++++++++++++++++++++++++--------- src/gui/gui-hotlist.h | 37 +++++++++++++---------- src/gui/gui-line.c | 8 +++-- 5 files changed, 169 insertions(+), 34 deletions(-) (limited to 'src/gui') diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index e3c589872..148be7724 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -1034,6 +1034,7 @@ gui_bar_item_default_hotlist (void *data, struct t_gui_bar_item *item, char buf[2048], format[32], *buffer_without_name_displayed; struct t_gui_hotlist *ptr_hotlist; int numbers_count, names_count, display_name; + int priority, priority_min, priority_min_displayed, private; /* make C compiler happy */ (void) data; @@ -1045,6 +1046,7 @@ gui_bar_item_default_hotlist (void *data, struct t_gui_bar_item *item, buf[0] = '\0'; + /* TRANSLATORS: if possible use short word or abbreviation here ("Act" is abbreviation of "Activity" in english) */ strcat (buf, _("Act: ")); buffer_without_name_displayed = NULL; @@ -1088,10 +1090,12 @@ gui_bar_item_default_hotlist (void *data, struct t_gui_bar_item *item, if (display_name || !buffer_without_name_displayed || (buffer_without_name_displayed[ptr_hotlist->buffer->number - 1] == 0)) { - if (numbers_count > 0) + if ((numbers_count > 0) + && (CONFIG_STRING(config_look_hotlist_buffer_separator)) + && (CONFIG_STRING(config_look_hotlist_buffer_separator)[0])) { strcat (buf, GUI_COLOR_CUSTOM_BAR_DELIM); - strcat (buf, ","); + strcat (buf, CONFIG_STRING(config_look_hotlist_buffer_separator)); } switch (ptr_hotlist->priority) @@ -1108,6 +1112,12 @@ gui_bar_item_default_hotlist (void *data, struct t_gui_bar_item *item, case GUI_HOTLIST_HIGHLIGHT: strcat (buf, gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_status_data_highlight)))); break; + case GUI_HOTLIST_NUM_PRIORITIES: + /* + * this constant is used to count hotlist priorities only, + * it is never used as priority + */ + break; } sprintf (buf + strlen (buf), "%d", ptr_hotlist->buffer->number); numbers_count++; @@ -1135,6 +1145,71 @@ gui_bar_item_default_hotlist (void *data, struct t_gui_bar_item *item, buffer_without_name_displayed[ptr_hotlist->buffer->number - 1] = 1; } + /* display messages count by priority */ + if (CONFIG_INTEGER(config_look_hotlist_count_max) > 0) + { + private = (ptr_hotlist->count[GUI_HOTLIST_PRIVATE] > 0) ? 1 : 0; + priority_min_displayed = ptr_hotlist->priority + 1; + priority_min = ptr_hotlist->priority - CONFIG_INTEGER(config_look_hotlist_count_max); + if (priority_min < 0) + priority_min = 0; + for (priority = ptr_hotlist->priority; + priority >= priority_min; + priority--) + { + if (!private && (priority == GUI_HOTLIST_PRIVATE)) + continue; + if (private && (priority == GUI_HOTLIST_MESSAGE)) + continue; + if (((priority == (int)ptr_hotlist->priority) + && (ptr_hotlist->count[priority] >= CONFIG_INTEGER(config_look_hotlist_count_min_msg))) + || ((priority != (int)ptr_hotlist->priority) + && (ptr_hotlist->count[priority] > 0))) + { + priority_min_displayed = priority; + } + } + if (priority_min_displayed <= (int)ptr_hotlist->priority) + { + for (priority = ptr_hotlist->priority; + priority >= priority_min_displayed; + priority--) + { + if (!private && (priority == GUI_HOTLIST_PRIVATE)) + continue; + if (private && (priority == GUI_HOTLIST_MESSAGE)) + continue; + strcat (buf, GUI_COLOR_CUSTOM_BAR_DELIM); + strcat (buf, (priority == (int)ptr_hotlist->priority) ? "(" : ","); + switch (priority) + { + case GUI_HOTLIST_LOW: + strcat (buf, gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_status_count_other)))); + break; + case GUI_HOTLIST_MESSAGE: + strcat (buf, gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_status_count_msg)))); + break; + case GUI_HOTLIST_PRIVATE: + strcat (buf, gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_status_count_private)))); + break; + case GUI_HOTLIST_HIGHLIGHT: + strcat (buf, gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_status_count_highlight)))); + break; + case GUI_HOTLIST_NUM_PRIORITIES: + /* + * this constant is used to count hotlist priorities only, + * it is never used as priority + */ + break; + } + sprintf (buf + strlen (buf), + "%d", ptr_hotlist->count[priority]); + } + strcat (buf, GUI_COLOR_CUSTOM_BAR_DELIM); + strcat (buf, ")"); + } + } + if (strlen (buf) > sizeof (buf) - 64) break; } diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 6f55badaa..162e1e62b 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -1346,7 +1346,7 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, error = NULL; number = strtol (value, &error, 10); if (error && !error[0]) - gui_hotlist_add (buffer, number, NULL, 1); + (void) gui_hotlist_add (buffer, number, NULL, 1); } } diff --git a/src/gui/gui-hotlist.c b/src/gui/gui-hotlist.c index ff951868b..953e3ddd2 100644 --- a/src/gui/gui-hotlist.c +++ b/src/gui/gui-hotlist.c @@ -131,7 +131,8 @@ gui_hotlist_free_all (struct t_gui_hotlist **hotlist, */ int -gui_hotlist_check_buffer_notify (struct t_gui_buffer *buffer, int priority) +gui_hotlist_check_buffer_notify (struct t_gui_buffer *buffer, + enum t_gui_hotlist_priority priority) { switch (priority) { @@ -142,6 +143,12 @@ gui_hotlist_check_buffer_notify (struct t_gui_buffer *buffer, int priority) case GUI_HOTLIST_PRIVATE: case GUI_HOTLIST_HIGHLIGHT: return (buffer->notify >= 1); + case GUI_HOTLIST_NUM_PRIORITIES: + /* + * this constant is used to count hotlist priorities only, + * it is never used as priority + */ + break; } return 1; } @@ -152,7 +159,8 @@ gui_hotlist_check_buffer_notify (struct t_gui_buffer *buffer, int priority) */ struct t_gui_hotlist * -gui_hotlist_find_pos (struct t_gui_hotlist *hotlist, struct t_gui_hotlist *new_hotlist) +gui_hotlist_find_pos (struct t_gui_hotlist *hotlist, + struct t_gui_hotlist *new_hotlist) { struct t_gui_hotlist *ptr_hotlist; @@ -267,42 +275,59 @@ gui_hotlist_add_hotlist (struct t_gui_hotlist **hotlist, /* * gui_hotlist_add: add a buffer to hotlist, with priority * if creation_time is NULL, current time is used + * return pointer to hotlist created or changed, or NULL if no + * hotlist was created/changed */ -void -gui_hotlist_add (struct t_gui_buffer *buffer, int priority, +struct t_gui_hotlist * +gui_hotlist_add (struct t_gui_buffer *buffer, + enum t_gui_hotlist_priority priority, struct timeval *creation_time, int allow_current_buffer) { struct t_gui_hotlist *new_hotlist, *ptr_hotlist; + int i, count[GUI_HOTLIST_NUM_PRIORITIES]; if (!buffer || !gui_add_hotlist) - return; + return NULL; /* do not add current buffer */ if ((buffer == gui_current_window->buffer) && (!allow_current_buffer || (!gui_buffer_is_scrolled (buffer)))) - return; + return NULL; /* do not add buffer if it is displayed in a window */ if (buffer->num_displayed > 0) - return; + return NULL; - if (priority < GUI_HOTLIST_MIN) - priority = GUI_HOTLIST_MIN; - else if (priority > GUI_HOTLIST_MAX) + if (priority > GUI_HOTLIST_MAX) priority = GUI_HOTLIST_MAX; /* check if priority is ok according to buffer notify level value */ if (!gui_hotlist_check_buffer_notify (buffer, priority)) - return; + return NULL; + + /* init count */ + for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++) + { + count[i] = 0; + } ptr_hotlist = gui_hotlist_search (gui_hotlist, buffer); if (ptr_hotlist) { /* return if priority is greater or equal than the one to add */ if (ptr_hotlist->priority >= priority) - return; - /* remove buffer if present with lower priority and go on */ + { + ptr_hotlist->count[priority]++; + gui_hotlist_changed_signal (); + return ptr_hotlist; + } + + /* + * if buffer is present with lower priority: save counts, remove it + * and go on + */ + memcpy (count, ptr_hotlist->count, sizeof (ptr_hotlist->count)); gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist); } @@ -311,7 +336,7 @@ gui_hotlist_add (struct t_gui_buffer *buffer, int priority, { log_printf (_("Error: not enough memory to add a buffer to " "hotlist")); - return; + return NULL; } new_hotlist->priority = priority; @@ -321,12 +346,16 @@ gui_hotlist_add (struct t_gui_buffer *buffer, int priority, else gettimeofday (&(new_hotlist->creation_time), NULL); new_hotlist->buffer = buffer; + memcpy (new_hotlist->count, count, sizeof (new_hotlist->count)); + new_hotlist->count[priority]++; new_hotlist->next_hotlist = NULL; new_hotlist->prev_hotlist = NULL; gui_hotlist_add_hotlist (&gui_hotlist, &last_gui_hotlist, new_hotlist); gui_hotlist_changed_signal (); + + return new_hotlist; } /* @@ -345,6 +374,7 @@ gui_hotlist_dup (struct t_gui_hotlist *hotlist) memcpy (&(new_hotlist->creation_time), &(hotlist->creation_time), sizeof (new_hotlist->creation_time)); new_hotlist->buffer = hotlist->buffer; + memcpy (new_hotlist->count, hotlist->count, sizeof (hotlist->count)); new_hotlist->prev_hotlist = NULL; new_hotlist->next_hotlist = NULL; return new_hotlist; @@ -431,6 +461,8 @@ gui_hotlist_add_to_infolist (struct t_infolist *infolist, struct t_gui_hotlist *hotlist) { struct t_infolist_item *ptr_item; + int i; + char option_name[64]; if (!infolist || !hotlist) return 0; @@ -463,6 +495,12 @@ gui_hotlist_add_to_infolist (struct t_infolist *infolist, gui_color_get_name (CONFIG_COLOR(config_color_status_data_highlight)))) return 0; break; + case GUI_HOTLIST_NUM_PRIORITIES: + /* + * this constant is used to count hotlist priorities only, + * it is never used as priority + */ + break; } if (!infolist_new_var_buffer (ptr_item, "creation_time", &(hotlist->creation_time), sizeof (struct timeval))) return 0; @@ -474,6 +512,12 @@ gui_hotlist_add_to_infolist (struct t_infolist *infolist, return 0; if (!infolist_new_var_string (ptr_item, "buffer_name", hotlist->buffer->name)) return 0; + for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++) + { + snprintf (option_name, sizeof (option_name), "count_%02d", i); + if (!infolist_new_var_integer (ptr_item, option_name, hotlist->count[i])) + return 0; + } return 1; } @@ -486,6 +530,7 @@ void gui_hotlist_print_log () { struct t_gui_hotlist *ptr_hotlist; + int i; for (ptr_hotlist = gui_hotlist; ptr_hotlist; ptr_hotlist = ptr_hotlist->next_hotlist) @@ -496,6 +541,10 @@ gui_hotlist_print_log () ptr_hotlist->creation_time.tv_sec, ptr_hotlist->creation_time.tv_usec); log_printf (" buffer . . . . . . . . : 0x%lx", ptr_hotlist->buffer); + for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++) + { + log_printf (" count[%02d]. . . . . . . : %d", i, ptr_hotlist->count[i]); + } log_printf (" prev_hotlist . . . . . : 0x%lx", ptr_hotlist->prev_hotlist); log_printf (" next_hotlist . . . . . : 0x%lx", ptr_hotlist->next_hotlist); } diff --git a/src/gui/gui-hotlist.h b/src/gui/gui-hotlist.h index fe87166e5..69ac2aed3 100644 --- a/src/gui/gui-hotlist.h +++ b/src/gui/gui-hotlist.h @@ -20,22 +20,28 @@ #ifndef __WEECHAT_GUI_HOTLIST_H #define __WEECHAT_GUI_HOTLIST_H 1 -#define GUI_HOTLIST_LOW 0 -#define GUI_HOTLIST_MESSAGE 1 -#define GUI_HOTLIST_PRIVATE 2 -#define GUI_HOTLIST_HIGHLIGHT 3 +enum t_gui_hotlist_priority +{ + GUI_HOTLIST_LOW = 0, + GUI_HOTLIST_MESSAGE, + GUI_HOTLIST_PRIVATE, + GUI_HOTLIST_HIGHLIGHT, + /* number of priorities */ + GUI_HOTLIST_NUM_PRIORITIES, +}; -#define GUI_HOTLIST_MIN 0 -#define GUI_HOTLIST_MAX 3 +#define GUI_HOTLIST_MIN 0 +#define GUI_HOTLIST_MAX (GUI_HOTLIST_NUM_PRIORITIES - 1) struct t_gui_hotlist { - int priority; /* 0=crappy msg (join/part), 1=msg, */ - /* 2=pv, 3=nick highlight */ - struct timeval creation_time; /* time when entry was added */ - struct t_gui_buffer *buffer; /* associated buffer */ - struct t_gui_hotlist *prev_hotlist;/* link to previous hotlist */ - struct t_gui_hotlist *next_hotlist;/* link to next hotlist */ + enum t_gui_hotlist_priority priority; /* 0=crappy msg (join/part), */ + /* 1=msg, 2=pv, 3=nick highlight */ + struct timeval creation_time; /* time when entry was added */ + struct t_gui_buffer *buffer; /* associated buffer */ + int count[GUI_HOTLIST_NUM_PRIORITIES]; /* number of msgs by priority */ + struct t_gui_hotlist *prev_hotlist; /* link to previous hotlist */ + struct t_gui_hotlist *next_hotlist; /* link to next hotlist */ }; /* history variables */ @@ -47,9 +53,10 @@ extern int gui_add_hotlist; /* hotlist functions */ -extern void gui_hotlist_add (struct t_gui_buffer *buffer, int priority, - struct timeval *creation_time, - int allow_current_buffer); +extern struct t_gui_hotlist *gui_hotlist_add (struct t_gui_buffer *buffer, + enum t_gui_hotlist_priority priority, + struct timeval *creation_time, + int allow_current_buffer); extern void gui_hotlist_resort (); extern void gui_hotlist_clear (); extern void gui_hotlist_remove_buffer (struct t_gui_buffer *buffer); diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index 1f46457ea..9f020b620 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -738,6 +738,8 @@ gui_line_free_all (struct t_gui_buffer *buffer) /* * gui_line_get_notify_level: get notify level for a line + * return -1 if "notify_none" is found (no notify + * for line) */ int @@ -747,6 +749,8 @@ gui_line_get_notify_level (struct t_gui_line *line) for (i = 0; i < line->data->tags_count; i++) { + if (string_strcasecmp (line->data->tags_array[i], "notify_none") == 0) + return -1; if (string_strcasecmp (line->data->tags_array[i], "notify_highlight") == 0) return GUI_HOTLIST_HIGHLIGHT; if (string_strcasecmp (line->data->tags_array[i], "notify_private") == 0) @@ -844,7 +848,7 @@ gui_line_add (struct t_gui_buffer *buffer, time_t date, { if (new_line->data->highlight) { - gui_hotlist_add (buffer, GUI_HOTLIST_HIGHLIGHT, NULL, 1); + (void) gui_hotlist_add (buffer, GUI_HOTLIST_HIGHLIGHT, NULL, 1); if (!weechat_upgrading) { message_for_signal = gui_chat_build_string_prefix_message (new_line); @@ -871,7 +875,7 @@ gui_line_add (struct t_gui_buffer *buffer, time_t date, } } if (notify_level >= GUI_HOTLIST_MIN) - gui_hotlist_add (buffer, notify_level, NULL, 1); + (void) gui_hotlist_add (buffer, notify_level, NULL, 1); } } else -- cgit v1.2.3