From de4ce8eeb664c3dc6c707d2096bd6431d2067c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Fri, 4 Apr 2014 12:32:59 +0200 Subject: irc: add option irc.look.item_channel_modes_hide_args (task #12070, task #12163, closes #48) This option replaces the option irc.look.item_channel_modes_hide_key. It is now a string, so channel modes arguments can be hidden using many channel modes (or all, with "*"). --- src/plugins/irc/irc-bar-item.c | 12 +++----- src/plugins/irc/irc-config.c | 63 ++++++++++++++++++++++++++++++++++-------- src/plugins/irc/irc-config.h | 3 +- 3 files changed, 58 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c index 3306efbf0..e98292d39 100644 --- a/src/plugins/irc/irc-bar-item.c +++ b/src/plugins/irc/irc-bar-item.c @@ -260,7 +260,7 @@ irc_bar_item_buffer_modes (void *data, struct t_gui_bar_item *item, struct t_hashtable *extra_info) { char modes[128], *modes_without_args; - const char *pos_space, *pos_key; + const char *pos_space; int part_from_channel; struct t_irc_server *server; struct t_irc_channel *channel; @@ -287,17 +287,13 @@ irc_bar_item_buffer_modes (void *data, struct t_gui_bar_item *item, && (strcmp (channel->modes, "+") != 0)) { modes_without_args = NULL; - if (weechat_config_boolean (irc_config_look_item_channel_modes_hide_key)) + if (!irc_config_display_channel_modes_arguments (channel->modes)) { pos_space = strchr(channel->modes, ' '); if (pos_space) { - pos_key = strchr(channel->modes, 'k'); - if (pos_key && (pos_key < pos_space)) - { - modes_without_args = weechat_strndup (channel->modes, - pos_space - channel->modes); - } + modes_without_args = weechat_strndup (channel->modes, + pos_space - channel->modes); } } snprintf (modes, sizeof (modes), diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index f5a48cc4f..c7dce6c10 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -71,7 +71,7 @@ struct t_config_option *irc_config_look_highlight_channel; struct t_config_option *irc_config_look_highlight_pv; struct t_config_option *irc_config_look_highlight_tags_restrict; struct t_config_option *irc_config_look_item_away_message; -struct t_config_option *irc_config_look_item_channel_modes_hide_key; +struct t_config_option *irc_config_look_item_channel_modes_hide_args; struct t_config_option *irc_config_look_item_display_server; struct t_config_option *irc_config_look_item_nick_modes; struct t_config_option *irc_config_look_item_nick_prefix; @@ -246,6 +246,45 @@ irc_config_set_nick_colors () &irc_config_num_nick_colors); } +/* + * Checks if channel modes arguments must be displayed or hidden + * (according to option irc.look.item_channel_modes_hide_args). + * + * Returns: + * 1: channel modes arguments must be displayed + * 0: channel modes arguments must be hidden + */ + +int +irc_config_display_channel_modes_arguments (const char *modes) +{ + char *pos_space, *pos; + const char *ptr_mode; + + pos_space = strchr (modes, ' '); + if (!pos_space) + return 1; + + ptr_mode = weechat_config_string (irc_config_look_item_channel_modes_hide_args); + if (!ptr_mode) + return 1; + + /* "*" means hide all arguments */ + if (strcmp (ptr_mode, "*") == 0) + return 0; + + while (ptr_mode[0]) + { + pos = strchr (modes, ptr_mode[0]); + if (pos && (pos < pos_space)) + return 0; + ptr_mode++; + } + + /* arguments are displayed by default */ + return 1; +} + /* * Callback for changes on option "weechat.color.chat_nick_colors". */ @@ -445,12 +484,12 @@ irc_config_change_look_item_away_message (void *data, } /* - * Callback for changes on option "irc.look.item_channel_modes_hide_key". + * Callback for changes on option "irc.look.item_channel_modes_hide_args". */ void -irc_config_change_look_item_channel_modes_hide_key (void *data, - struct t_config_option *option) +irc_config_change_look_item_channel_modes_hide_args (void *data, + struct t_config_option *option) { /* make C compiler happy */ (void) data; @@ -2357,13 +2396,15 @@ irc_config_init () N_("display server away message in away bar item"), NULL, 0, 0, "on", NULL, 0, NULL, NULL, &irc_config_change_look_item_away_message, NULL, NULL, NULL); - irc_config_look_item_channel_modes_hide_key = weechat_config_new_option ( - irc_config_file, ptr_section, - "item_channel_modes_hide_key", "boolean", - N_("hide channel key in channel modes (this will hide all channel modes " - "arguments if mode +k is set on channel)"), - NULL, 0, 0, "off", NULL, 0, NULL, NULL, - &irc_config_change_look_item_channel_modes_hide_key, NULL, NULL, NULL); + irc_config_look_item_channel_modes_hide_args = weechat_config_new_option ( + irc_config_file, ptr_section, + "item_channel_modes_hide_args", "string", + N_("hide channel modes arguments if at least one of these modes is in " + "channel modes (\"*\" to always hide all arguments, empty value to " + "never hide arguments); example: \"kf\" to hide arguments if \"k\" " + "or \"f\" are in channel modes"), + NULL, 0, 0, "k", NULL, 0, NULL, NULL, + &irc_config_change_look_item_channel_modes_hide_args, NULL, NULL, NULL); irc_config_look_item_display_server = weechat_config_new_option ( irc_config_file, ptr_section, "item_display_server", "integer", diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h index e059ce8f0..5e2bebfc0 100644 --- a/src/plugins/irc/irc-config.h +++ b/src/plugins/irc/irc-config.h @@ -119,7 +119,7 @@ extern struct t_config_option *irc_config_look_highlight_channel; extern struct t_config_option *irc_config_look_highlight_pv; extern struct t_config_option *irc_config_look_highlight_tags_restrict; extern struct t_config_option *irc_config_look_item_away_message; -extern struct t_config_option *irc_config_look_item_channel_modes_hide_key; +extern struct t_config_option *irc_config_look_item_channel_modes_hide_args; extern struct t_config_option *irc_config_look_item_display_server; extern struct t_config_option *irc_config_look_item_nick_modes; extern struct t_config_option *irc_config_look_item_nick_prefix; @@ -196,6 +196,7 @@ extern char **irc_config_nicks_hide_password; extern int irc_config_num_nicks_hide_password; extern void irc_config_set_nick_colors (); +extern int irc_config_display_channel_modes_arguments (const char *modes); extern int irc_config_server_check_value_cb (void *data, struct t_config_option *option, const char *value); -- cgit v1.2.3