diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c index ae751f358..f32935882 100644 --- a/src/plugins/irc/irc-bar-item.c +++ b/src/plugins/irc/irc-bar-item.c @@ -239,66 +239,6 @@ irc_bar_item_buffer_short_name (const void *pointer, void *data, return irc_bar_item_buffer_name_content (buffer, 1); } -/* - * Returns content of bar item "buffer_modes": bar item with buffer modes. - */ - -char * -irc_bar_item_buffer_modes (const void *pointer, void *data, - struct t_gui_bar_item *item, - struct t_gui_window *window, - struct t_gui_buffer *buffer, - struct t_hashtable *extra_info) -{ - char modes[128], *modes_without_args; - const char *pos_space; - int part_from_channel; - struct t_irc_server *server; - struct t_irc_channel *channel; - - /* make C compiler happy */ - (void) pointer; - (void) data; - (void) item; - (void) window; - (void) extra_info; - - if (!buffer) - return NULL; - - modes[0] = '\0'; - - irc_buffer_get_server_and_channel (buffer, &server, &channel); - if (!channel) - return NULL; - - part_from_channel = ((channel->type == IRC_CHANNEL_TYPE_CHANNEL) - && !channel->nicks); - if (!part_from_channel - && channel->modes && channel->modes[0] - && (strcmp (channel->modes, "+") != 0)) - { - modes_without_args = NULL; - if (!irc_config_display_channel_modes_arguments (channel->modes)) - { - pos_space = strchr (channel->modes, ' '); - if (pos_space) - { - modes_without_args = weechat_strndup ( - channel->modes, pos_space - channel->modes); - } - } - snprintf (modes, sizeof (modes), - "%s%s", - IRC_COLOR_ITEM_CHANNEL_MODES, - (modes_without_args) ? modes_without_args : channel->modes); - free (modes_without_args); - return strdup (modes); - } - - return NULL; -} - /* * Returns content of bar item "irc_channel": bar item with channel name * (without modes). @@ -792,8 +732,6 @@ irc_bar_item_init () &irc_bar_item_buffer_name, NULL, NULL); weechat_bar_item_new ("buffer_short_name", &irc_bar_item_buffer_short_name, NULL, NULL); - weechat_bar_item_new ("buffer_modes", - &irc_bar_item_buffer_modes, NULL, NULL); weechat_bar_item_new ("irc_channel", &irc_bar_item_channel, NULL, NULL); weechat_bar_item_new ("irc_nick", diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index 7df7c2d0f..b97d7fbba 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -571,7 +571,56 @@ irc_channel_add_nicklist_groups (struct t_irc_server *server, } /* - * Sets input prompt on channel. + * Sets modes on channel buffer. + */ + +void +irc_channel_set_buffer_modes (struct t_irc_server *server, + struct t_irc_channel *channel) +{ + char *modes, *modes_without_args; + const char *pos_space; + + if (!server || !channel || !channel->buffer) + return; + + if ((channel->type == IRC_CHANNEL_TYPE_CHANNEL) + && channel->nicks + && channel->modes && channel->modes[0] + && (strcmp (channel->modes, "+") != 0)) + { + modes_without_args = NULL; + if (!irc_config_display_channel_modes_arguments (channel->modes)) + { + pos_space = strchr (channel->modes, ' '); + if (pos_space) + { + modes_without_args = weechat_strndup ( + channel->modes, pos_space - channel->modes); + } + } + if (weechat_asprintf ( + &modes, "%s%s", + IRC_COLOR_ITEM_CHANNEL_MODES, + (modes_without_args) ? modes_without_args : channel->modes) >= 0) + { + weechat_buffer_set (channel->buffer, "modes", modes); + free (modes); + } + else + { + weechat_buffer_set (channel->buffer, "modes", ""); + } + free (modes_without_args); + } + else + { + weechat_buffer_set (channel->buffer, "modes", ""); + } +} + +/* + * Sets input prompt on channel buffer. */ void diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h index 092f9513a..257d7f90c 100644 --- a/src/plugins/irc/irc-channel.h +++ b/src/plugins/irc/irc-channel.h @@ -116,6 +116,8 @@ extern void irc_channel_pv_rename (struct t_irc_server *server, const char *new_name); extern void irc_channel_add_nicklist_groups (struct t_irc_server *server, struct t_irc_channel *channel); +extern void irc_channel_set_buffer_modes (struct t_irc_server *server, + struct t_irc_channel *channel); extern void irc_channel_set_buffer_input_prompt (struct t_irc_server *server, struct t_irc_channel *channel); extern void irc_channel_set_buffer_title (struct t_irc_channel *channel); diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index c7fd4103c..aff6e27a8 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -523,20 +523,32 @@ irc_config_change_look_pv_buffer (const void *pointer, void *data, } /* - * Callback for changes on option "irc.look.item_channel_modes_hide_args". + * Callback for changes on an option affecting buffer modes. */ void -irc_config_change_look_item_channel_modes_hide_args (const void *pointer, - void *data, - struct t_config_option *option) +irc_config_change_buffer_modes (const void *pointer, + void *data, + struct t_config_option *option) { + struct t_irc_server *ptr_server; + struct t_irc_channel *ptr_channel; + /* make C compiler happy */ (void) pointer; (void) data; (void) option; - weechat_bar_item_update ("buffer_modes"); + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + for (ptr_channel = ptr_server->channels; ptr_channel; + ptr_channel = ptr_channel->next_channel) + { + if (ptr_channel->buffer) + irc_channel_set_buffer_modes (ptr_server, ptr_channel); + } + } } /* @@ -665,8 +677,8 @@ irc_config_change_look_topic_strip_colors (const void *pointer, void *data, */ void -irc_config_change_input_prompt (const void *pointer, void *data, - struct t_config_option *option) +irc_config_change_buffer_input_prompt (const void *pointer, void *data, + struct t_config_option *option) { struct t_irc_server *ptr_server; @@ -683,22 +695,6 @@ irc_config_change_input_prompt (const void *pointer, void *data, } } -/* - * Callback for changes on option "irc.color.item_channel_modes". - */ - -void -irc_config_change_color_item_channel_modes (const void *pointer, void *data, - struct t_config_option *option) -{ - /* make C compiler happy */ - (void) pointer; - (void) data; - (void) option; - - weechat_bar_item_update ("buffer_modes"); -} - /* * Callback for changes on options "irc.color.item_lag_counting" and * "irc.color.item_lag_finished". @@ -729,7 +725,7 @@ irc_config_change_color_item_nick_modes (const void *pointer, void *data, (void) data; (void) option; - irc_config_change_input_prompt (NULL, NULL, NULL); + irc_config_change_buffer_input_prompt (NULL, NULL, NULL); weechat_bar_item_update ("irc_nick_modes"); } @@ -879,7 +875,7 @@ irc_config_change_color_nick_prefixes (const void *pointer, void *data, irc_nick_nicklist_set_prefix_color_all (); - irc_config_change_input_prompt (NULL, NULL, NULL); + irc_config_change_buffer_input_prompt (NULL, NULL, NULL); } /* @@ -3368,7 +3364,7 @@ irc_config_init () "arguments if \"k\" or \"f\" are in channel modes"), NULL, 0, 0, "k", NULL, 0, NULL, NULL, NULL, - &irc_config_change_look_item_channel_modes_hide_args, NULL, NULL, + &irc_config_change_buffer_modes, NULL, NULL, NULL, NULL, NULL); irc_config_look_item_display_server = weechat_config_new_option ( irc_config_file, irc_config_section_look, @@ -3384,7 +3380,7 @@ irc_config_init () N_("display nick modes in bar item \"input_prompt\""), NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, - &irc_config_change_input_prompt, NULL, NULL, + &irc_config_change_buffer_input_prompt, NULL, NULL, NULL, NULL, NULL); irc_config_look_item_nick_prefix = weechat_config_new_option ( irc_config_file, irc_config_section_look, @@ -3392,7 +3388,7 @@ irc_config_init () N_("display nick prefix in bar item \"input_prompt\""), NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, - &irc_config_change_input_prompt, NULL, NULL, + &irc_config_change_buffer_input_prompt, NULL, NULL, NULL, NULL, NULL); irc_config_look_join_auto_add_chantype = weechat_config_new_option ( irc_config_file, irc_config_section_look, @@ -3496,7 +3492,7 @@ irc_config_init () "(not op, voice, ...)"), NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, - &irc_config_change_input_prompt, NULL, NULL, + &irc_config_change_buffer_input_prompt, NULL, NULL, NULL, NULL, NULL); irc_config_look_nicks_hide_password = weechat_config_new_option ( irc_config_file, irc_config_section_look, @@ -3729,7 +3725,7 @@ irc_config_init () N_("color for nick in input bar"), NULL, -1, 0, "lightcyan", NULL, 0, NULL, NULL, NULL, - &irc_config_change_input_prompt, NULL, NULL, + &irc_config_change_buffer_input_prompt, NULL, NULL, NULL, NULL, NULL); irc_config_color_item_channel_modes = weechat_config_new_option ( irc_config_file, irc_config_section_color, @@ -3737,7 +3733,7 @@ irc_config_init () N_("color for channel modes, near channel name"), NULL, -1, 0, "default", NULL, 0, NULL, NULL, NULL, - &irc_config_change_color_item_channel_modes, NULL, NULL, + &irc_config_change_buffer_modes, NULL, NULL, NULL, NULL, NULL); irc_config_color_item_lag_counting = weechat_config_new_option ( irc_config_file, irc_config_section_color, diff --git a/src/plugins/irc/irc-mode.c b/src/plugins/irc/irc-mode.c index be749741d..2dd95cc28 100644 --- a/src/plugins/irc/irc-mode.c +++ b/src/plugins/irc/irc-mode.c @@ -564,7 +564,7 @@ irc_mode_channel_set (struct t_irc_server *server, weechat_string_free_split (argv); if (channel_modes_updated) - weechat_bar_item_update ("buffer_modes"); + irc_channel_set_buffer_modes (server, channel); return smart_filter; } diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 7d714e72f..8aad87939 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -814,6 +814,7 @@ irc_nick_free_all (struct t_irc_server *server, struct t_irc_channel *channel) /* should be zero, but prevent any bug :D */ channel->nicks_count = 0; + irc_channel_set_buffer_modes (server, channel); irc_channel_set_buffer_input_prompt (server, channel); } diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c index d0416e361..03240ad03 100644 --- a/src/plugins/irc/irc-upgrade.c +++ b/src/plugins/irc/irc-upgrade.c @@ -984,14 +984,13 @@ irc_upgrade_read_cb (const void *pointer, void *data, } /* - * Set buffer prompt on IRC buffers where it's not set and if it should be. - * - * This is needed when upgrading from WeeChat < 4.3.0 to Weechat ≥ 4.3.0, - * where the "input_prompt" has been added in buffer. + * Set buffer properties on IRC buffers after upgrade: + * - "input_prompt" (introduced in WeeChat 4.3.0) + * - "modes" (introduced in WeeChat 4.3.0) */ void -irc_upgrade_set_buffer_prompt () +irc_upgrade_set_buffer_properties () { struct t_irc_server *ptr_server; struct t_irc_channel *ptr_channel; @@ -999,20 +998,16 @@ irc_upgrade_set_buffer_prompt () for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { + /* set input prompt on server and all channels */ if (ptr_server->buffer) + irc_server_set_buffer_input_prompt (ptr_server); + + /* set modes on all channels */ + for (ptr_channel = ptr_server->channels; ptr_channel; + ptr_channel = ptr_channel->next_channel) { - if (!weechat_buffer_get_string (ptr_server->buffer, "input_prompt")) - { - irc_server_set_buffer_input_prompt (ptr_server); - } - else - { - for (ptr_channel = ptr_server->channels; ptr_channel; - ptr_channel = ptr_channel->next_channel) - { - irc_channel_set_buffer_input_prompt (ptr_server, ptr_channel); - } - } + if (ptr_channel->buffer) + irc_channel_set_buffer_modes (ptr_server, ptr_channel); } } } @@ -1053,7 +1048,7 @@ irc_upgrade_load () (ptr_filter && ptr_filter[0]) ? ptr_filter : "*"); } - irc_upgrade_set_buffer_prompt (); + irc_upgrade_set_buffer_properties (); return rc; }