diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2017-03-19 20:35:39 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2017-03-25 14:19:48 +0100 |
commit | 887362dfd93f6547f42b86e0af71fbe7c8ba78cd (patch) | |
tree | 7bbfc165abbcaed6133ab916d798e82f1b12b99a /src | |
parent | 6f46f65c7304346d2fc8bcb0c72f16500f0efd38 (diff) | |
download | weechat-887362dfd93f6547f42b86e0af71fbe7c8ba78cd.zip |
buflist: add formats for hotlist
New options:
- buflist.format.hotlist
- buflist.format.hotlist_separator
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/buflist/buflist-bar-item.c | 63 | ||||
-rw-r--r-- | src/plugins/buflist/buflist-config.c | 36 | ||||
-rw-r--r-- | src/plugins/buflist/buflist-config.h | 6 |
3 files changed, 89 insertions, 16 deletions
diff --git a/src/plugins/buflist/buflist-bar-item.c b/src/plugins/buflist/buflist-bar-item.c index ce8cc4a76..a84ac26dd 100644 --- a/src/plugins/buflist/buflist-bar-item.c +++ b/src/plugins/buflist/buflist-bar-item.c @@ -51,15 +51,16 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data, struct t_gui_hotlist *ptr_hotlist; char **buflist, *str_buflist; char str_format_number[32], str_format_number_empty[32]; - char str_number[32], str_indent_name[4], *line; + char str_number[32], str_indent_name[4], *line, **hotlist, *str_hotlist; + char str_hotlist_count[32]; const char *ptr_format, *ptr_format_current, *ptr_name, *ptr_type; const char *ptr_hotlist_format, *ptr_hotlist_priority; const char *hotlist_priority_none = "none"; const char *hotlist_priority[4] = { "low", "message", "private", "highlight" }; const char *ptr_lag; - int i, length_max_number, current_buffer, number, prev_number, priority; - int rc; + int i, j, length_max_number, current_buffer, number, prev_number, priority; + int rc, count; /* make C compiler happy */ (void) pointer; @@ -71,7 +72,7 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data, prev_number = -1; - buflist = weechat_string_dyn_alloc (1); + buflist = weechat_string_dyn_alloc (256); ptr_format = weechat_config_string (buflist_config_format_buffer); ptr_format_current = weechat_config_string (buflist_config_format_buffer_current); @@ -150,7 +151,9 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data, weechat_hashtable_set (buflist_hashtable_extra_vars, "name", ptr_name); - ptr_hotlist_format = weechat_config_string (buflist_config_format_hotlist_none); + /* hotlist */ + ptr_hotlist_format = weechat_config_string ( + buflist_config_format_hotlist_level_none); ptr_hotlist_priority = hotlist_priority_none; if (ptr_hotlist) { @@ -159,7 +162,7 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data, if ((priority >= 0) && (priority < 4)) { ptr_hotlist_format = weechat_config_string ( - buflist_config_format_hotlist[priority]); + buflist_config_format_hotlist_level[priority]); ptr_hotlist_priority = hotlist_priority[priority]; } } @@ -167,6 +170,52 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data, "color_hotlist", ptr_hotlist_format); weechat_hashtable_set (buflist_hashtable_extra_vars, "hotlist_priority", ptr_hotlist_priority); + str_hotlist = NULL; + if (ptr_hotlist) + { + hotlist = weechat_string_dyn_alloc (64); + if (hotlist) + { + for (j = 3; j >= 0; j--) + { + snprintf (str_hotlist_count, sizeof (str_hotlist_count), + "%02d|count", j); + count = weechat_hdata_integer (buflist_hdata_hotlist, + ptr_hotlist, + str_hotlist_count); + if (count > 0) + { + if (*hotlist[0]) + { + weechat_string_dyn_concat ( + hotlist, + weechat_config_string ( + buflist_config_format_hotlist_separator)); + } + weechat_string_dyn_concat ( + hotlist, + weechat_config_string ( + buflist_config_format_hotlist_level[j])); + snprintf (str_hotlist_count, sizeof (str_hotlist_count), + "%d", count); + weechat_string_dyn_concat (hotlist, str_hotlist_count); + } + } + str_hotlist = *hotlist; + weechat_string_dyn_free (hotlist, 0); + } + } + weechat_hashtable_set ( + buflist_hashtable_extra_vars, + "format_hotlist", + (str_hotlist) ? weechat_config_string (buflist_config_format_hotlist) : ""); + weechat_hashtable_set (buflist_hashtable_extra_vars, + "hotlist", + (str_hotlist) ? str_hotlist : ""); + if (str_hotlist) + free (str_hotlist); + + /* lag */ ptr_lag = weechat_buffer_get_string (ptr_buffer, "localvar_lag"); if (ptr_lag && ptr_lag[0]) { @@ -232,7 +281,7 @@ buflist_bar_item_init () buflist_hashtable_extra_vars = weechat_hashtable_new ( 32, WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_POINTER, + WEECHAT_HASHTABLE_STRING, NULL, NULL); if (!buflist_hashtable_extra_vars) diff --git a/src/plugins/buflist/buflist-config.c b/src/plugins/buflist/buflist-config.c index 65e518108..2253bebf1 100644 --- a/src/plugins/buflist/buflist-config.c +++ b/src/plugins/buflist/buflist-config.c @@ -37,8 +37,10 @@ struct t_config_option *buflist_config_look_sort; struct t_config_option *buflist_config_format_buffer; struct t_config_option *buflist_config_format_buffer_current; -struct t_config_option *buflist_config_format_hotlist[4]; -struct t_config_option *buflist_config_format_hotlist_none; +struct t_config_option *buflist_config_format_hotlist; +struct t_config_option *buflist_config_format_hotlist_level[4]; +struct t_config_option *buflist_config_format_hotlist_level_none; +struct t_config_option *buflist_config_format_hotlist_separator; struct t_config_option *buflist_config_format_lag; char **buflist_config_sort_fields = NULL; @@ -163,7 +165,17 @@ buflist_config_init () NULL, NULL, NULL, &buflist_config_change_buflist, NULL, NULL, NULL, NULL, NULL); - buflist_config_format_hotlist[0] = weechat_config_new_option ( + buflist_config_format_hotlist = weechat_config_new_option ( + buflist_config_file, ptr_section, + "hotlist", "string", + N_("format for hotlist"), + NULL, 0, 0, + " ${color:green}(${hotlist}${color:green})", + NULL, 0, + NULL, NULL, NULL, + &buflist_config_change_buflist, NULL, NULL, + NULL, NULL, NULL); + buflist_config_format_hotlist_level[0] = weechat_config_new_option ( buflist_config_file, ptr_section, "hotlist_low", "string", N_("format for a buffer with hotlist level \"low\""), @@ -173,7 +185,7 @@ buflist_config_init () NULL, NULL, NULL, &buflist_config_change_buflist, NULL, NULL, NULL, NULL, NULL); - buflist_config_format_hotlist[1] = weechat_config_new_option ( + buflist_config_format_hotlist_level[1] = weechat_config_new_option ( buflist_config_file, ptr_section, "hotlist_message", "string", N_("format for a buffer with hotlist level \"message\""), @@ -183,7 +195,7 @@ buflist_config_init () NULL, NULL, NULL, &buflist_config_change_buflist, NULL, NULL, NULL, NULL, NULL); - buflist_config_format_hotlist[2] = weechat_config_new_option ( + buflist_config_format_hotlist_level[2] = weechat_config_new_option ( buflist_config_file, ptr_section, "hotlist_private", "string", N_("format for a buffer with hotlist level \"private\""), @@ -193,7 +205,7 @@ buflist_config_init () NULL, NULL, NULL, &buflist_config_change_buflist, NULL, NULL, NULL, NULL, NULL); - buflist_config_format_hotlist[3] = weechat_config_new_option ( + buflist_config_format_hotlist_level[3] = weechat_config_new_option ( buflist_config_file, ptr_section, "hotlist_highlight", "string", N_("format for a buffer with hotlist level \"highlight\""), @@ -203,7 +215,7 @@ buflist_config_init () NULL, NULL, NULL, &buflist_config_change_buflist, NULL, NULL, NULL, NULL, NULL); - buflist_config_format_hotlist_none = weechat_config_new_option ( + buflist_config_format_hotlist_level_none = weechat_config_new_option ( buflist_config_file, ptr_section, "hotlist_none", "string", N_("format for a buffer not in hotlist"), @@ -213,6 +225,16 @@ buflist_config_init () NULL, NULL, NULL, &buflist_config_change_buflist, NULL, NULL, NULL, NULL, NULL); + buflist_config_format_hotlist_separator = weechat_config_new_option ( + buflist_config_file, ptr_section, + "hotlist_separator", "string", + N_("separator for counts in hotlist"), + NULL, 0, 0, + "${color:default},", + NULL, 0, + NULL, NULL, NULL, + &buflist_config_change_buflist, NULL, NULL, + NULL, NULL, NULL); buflist_config_format_lag = weechat_config_new_option ( buflist_config_file, ptr_section, "lag", "string", diff --git a/src/plugins/buflist/buflist-config.h b/src/plugins/buflist/buflist-config.h index 584153d81..e7991a034 100644 --- a/src/plugins/buflist/buflist-config.h +++ b/src/plugins/buflist/buflist-config.h @@ -26,8 +26,10 @@ extern struct t_config_file *buflist_config_file; extern struct t_config_option *buflist_config_format_buffer; extern struct t_config_option *buflist_config_format_buffer_current; -extern struct t_config_option *buflist_config_format_hotlist[4]; -extern struct t_config_option *buflist_config_format_hotlist_none; +extern struct t_config_option *buflist_config_format_hotlist; +extern struct t_config_option *buflist_config_format_hotlist_level[4]; +extern struct t_config_option *buflist_config_format_hotlist_level_none; +extern struct t_config_option *buflist_config_format_hotlist_separator; extern struct t_config_option *buflist_config_format_lag; extern char **buflist_config_sort_fields; |