diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-10 11:03:44 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-11 14:05:52 +0200 |
commit | 827a0567909fe2dc59f03fa6bfce862f4cebe616 (patch) | |
tree | 7508de309c34c2ed8bfd1ac5dfc649208d3df8ea /src/plugins | |
parent | 7634774327a231f2705a2ad68229b0037a92c9e7 (diff) | |
download | weechat-827a0567909fe2dc59f03fa6bfce862f4cebe616.zip |
irc: remove redefinition of bar item "input_prompt"
The new buffer property "input_prompt" is used instead.
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/irc/irc-bar-item.c | 86 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.c | 62 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.h | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.c | 27 | ||||
-rw-r--r-- | src/plugins/irc/irc-mode.c | 8 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.c | 4 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 5 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 57 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 1 |
9 files changed, 147 insertions, 105 deletions
diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c index 92c4f3d3e..ae751f358 100644 --- a/src/plugins/irc/irc-bar-item.c +++ b/src/plugins/irc/irc-bar-item.c @@ -590,90 +590,6 @@ irc_bar_item_tls_version (const void *pointer, void *data, return NULL; } - -/* - * Returns content of bar item "input_prompt": bar item with input prompt. - */ - -char * -irc_bar_item_input_prompt (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) -{ - struct t_irc_server *server; - struct t_irc_channel *channel; - struct t_irc_nick *ptr_nick; - char *buf, str_prefix[64]; - int length; - - /* make C compiler happy */ - (void) pointer; - (void) data; - (void) item; - (void) window; - (void) extra_info; - - if (!buffer) - return NULL; - - irc_buffer_get_server_and_channel (buffer, &server, &channel); - if (!server || !server->nick) - return NULL; - - /* build prefix */ - str_prefix[0] = '\0'; - if (weechat_config_boolean (irc_config_look_item_nick_prefix) - && channel - && (channel->type == IRC_CHANNEL_TYPE_CHANNEL)) - { - ptr_nick = irc_nick_search (server, channel, server->nick); - if (ptr_nick) - { - if (weechat_config_boolean (irc_config_look_nick_mode_empty) - || (ptr_nick->prefix[0] != ' ')) - { - snprintf (str_prefix, sizeof (str_prefix), "%s%s", - weechat_color ( - irc_nick_get_prefix_color_name ( - server, ptr_nick->prefix[0])), - ptr_nick->prefix); - } - } - } - - /* build bar item */ - length = 64 + strlen (server->nick) + 64 + - ((server->nick_modes) ? strlen (server->nick_modes) : 0) + 64 + 1; - - buf = malloc (length); - if (buf) - { - if (weechat_config_boolean (irc_config_look_item_nick_modes) - && server->nick_modes && server->nick_modes[0]) - { - snprintf (buf, length, "%s%s%s%s(%s%s%s)", - str_prefix, - IRC_COLOR_INPUT_NICK, - server->nick, - IRC_COLOR_BAR_DELIM, - IRC_COLOR_ITEM_NICK_MODES, - server->nick_modes, - IRC_COLOR_BAR_DELIM); - } - else - { - snprintf (buf, length, "%s%s%s", - str_prefix, - IRC_COLOR_INPUT_NICK, - server->nick); - } - } - - return buf; -} - /* * Returns content of bar item "nick_modes": bar item with nick modes. */ @@ -888,8 +804,6 @@ irc_bar_item_init () &irc_bar_item_nick_host, NULL, NULL); weechat_bar_item_new ("lag", &irc_bar_item_lag, NULL, NULL); - weechat_bar_item_new ("input_prompt", - &irc_bar_item_input_prompt, NULL, NULL); weechat_bar_item_new ("irc_nick_modes", &irc_bar_item_nick_modes, NULL, NULL); weechat_bar_item_new ("irc_nick_prefix", diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index ce2dca01e..7df7c2d0f 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -571,6 +571,68 @@ irc_channel_add_nicklist_groups (struct t_irc_server *server, } /* + * Sets input prompt on channel. + */ + +void +irc_channel_set_buffer_input_prompt (struct t_irc_server *server, + struct t_irc_channel *channel) +{ + struct t_irc_nick *ptr_nick; + int display_modes; + char str_prefix[64], *prompt; + + if (!server || !channel || !channel->buffer) + return; + + if (server->nick) + { + /* build prefix */ + str_prefix[0] = '\0'; + if (weechat_config_boolean (irc_config_look_item_nick_prefix) + && (channel->type == IRC_CHANNEL_TYPE_CHANNEL)) + { + ptr_nick = irc_nick_search (server, channel, server->nick); + if (ptr_nick) + { + if (weechat_config_boolean (irc_config_look_nick_mode_empty) + || (ptr_nick->prefix[0] != ' ')) + { + snprintf (str_prefix, sizeof (str_prefix), "%s%s", + weechat_color ( + irc_nick_get_prefix_color_name ( + server, ptr_nick->prefix[0])), + ptr_nick->prefix); + } + } + } + + display_modes = (weechat_config_boolean (irc_config_look_item_nick_modes) + && server->nick_modes && server->nick_modes[0]); + + weechat_asprintf (&prompt, "%s%s%s%s%s%s%s%s%s", + str_prefix, + IRC_COLOR_INPUT_NICK, + server->nick, + (display_modes) ? IRC_COLOR_BAR_DELIM : "", + (display_modes) ? "(" : "", + (display_modes) ? IRC_COLOR_ITEM_NICK_MODES : "", + (display_modes) ? server->nick_modes : "", + (display_modes) ? IRC_COLOR_BAR_DELIM : "", + (display_modes) ? ")" : ""); + if (prompt) + { + weechat_buffer_set (channel->buffer, "input_prompt", prompt); + free (prompt); + } + } + else + { + weechat_buffer_set (channel->buffer, "input_prompt", ""); + } +} + +/* * Sets the buffer title with the channel topic. */ diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h index 8218df9ec..092f9513a 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_input_prompt (struct t_irc_server *server, + struct t_irc_channel *channel); extern void irc_channel_set_buffer_title (struct t_irc_channel *channel); extern void irc_channel_set_topic (struct t_irc_channel *channel, const char *topic); diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index a09bceac8..c7fd4103c 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -661,19 +661,26 @@ irc_config_change_look_topic_strip_colors (const void *pointer, void *data, } /* - * Callback for changes on an option affecting bar item "input_prompt". + * Callback for changes on an option affecting input prompt. */ void -irc_config_change_bar_item_input_prompt (const void *pointer, void *data, - struct t_config_option *option) +irc_config_change_input_prompt (const void *pointer, void *data, + struct t_config_option *option) { + struct t_irc_server *ptr_server; + /* make C compiler happy */ (void) pointer; (void) data; (void) option; - weechat_bar_item_update ("input_prompt"); + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (ptr_server->buffer) + irc_server_set_buffer_input_prompt (ptr_server); + } } /* @@ -722,7 +729,7 @@ irc_config_change_color_item_nick_modes (const void *pointer, void *data, (void) data; (void) option; - weechat_bar_item_update ("input_prompt"); + irc_config_change_input_prompt (NULL, NULL, NULL); weechat_bar_item_update ("irc_nick_modes"); } @@ -872,7 +879,7 @@ irc_config_change_color_nick_prefixes (const void *pointer, void *data, irc_nick_nicklist_set_prefix_color_all (); - weechat_bar_item_update ("input_prompt"); + irc_config_change_input_prompt (NULL, NULL, NULL); } /* @@ -3377,7 +3384,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_bar_item_input_prompt, NULL, NULL, + &irc_config_change_input_prompt, NULL, NULL, NULL, NULL, NULL); irc_config_look_item_nick_prefix = weechat_config_new_option ( irc_config_file, irc_config_section_look, @@ -3385,7 +3392,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_bar_item_input_prompt, NULL, NULL, + &irc_config_change_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, @@ -3489,7 +3496,7 @@ irc_config_init () "(not op, voice, ...)"), NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, - &irc_config_change_bar_item_input_prompt, NULL, NULL, + &irc_config_change_input_prompt, NULL, NULL, NULL, NULL, NULL); irc_config_look_nicks_hide_password = weechat_config_new_option ( irc_config_file, irc_config_section_look, @@ -3722,7 +3729,7 @@ irc_config_init () N_("color for nick in input bar"), NULL, -1, 0, "lightcyan", NULL, 0, NULL, NULL, NULL, - &irc_config_change_bar_item_input_prompt, NULL, NULL, + &irc_config_change_input_prompt, NULL, NULL, NULL, NULL, NULL); irc_config_color_item_channel_modes = 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 ea7337266..be749741d 100644 --- a/src/plugins/irc/irc-mode.c +++ b/src/plugins/irc/irc-mode.c @@ -599,7 +599,7 @@ irc_mode_user_add (struct t_irc_server *server, char mode) } server->nick_modes = nick_modes2; strcat (server->nick_modes, str_mode); - weechat_bar_item_update ("input_prompt"); + irc_server_set_buffer_input_prompt (server); weechat_bar_item_update ("irc_nick_modes"); } } @@ -607,7 +607,7 @@ irc_mode_user_add (struct t_irc_server *server, char mode) { server->nick_modes = malloc (2); strcpy (server->nick_modes, str_mode); - weechat_bar_item_update ("input_prompt"); + irc_server_set_buffer_input_prompt (server); weechat_bar_item_update ("irc_nick_modes"); } @@ -642,7 +642,7 @@ irc_mode_user_remove (struct t_irc_server *server, char mode) nick_modes2 = realloc (server->nick_modes, new_size); if (nick_modes2) server->nick_modes = nick_modes2; - weechat_bar_item_update ("input_prompt"); + irc_server_set_buffer_input_prompt (server); weechat_bar_item_update ("irc_nick_modes"); } } @@ -700,7 +700,7 @@ irc_mode_user_set (struct t_irc_server *server, const char *modes, break; modes++; } - weechat_bar_item_update ("input_prompt"); + irc_server_set_buffer_input_prompt (server); weechat_bar_item_update ("irc_nick_modes"); } diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 255b20620..7d714e72f 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -692,7 +692,7 @@ irc_nick_set_mode (struct t_irc_server *server, struct t_irc_channel *channel, if (irc_server_strcasecmp (server, nick->name, server->nick) == 0) { - weechat_bar_item_update ("input_prompt"); + irc_server_set_buffer_input_prompt (server); weechat_bar_item_update ("irc_nick"); weechat_bar_item_update ("irc_nick_host"); } @@ -813,6 +813,8 @@ 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_input_prompt (server, channel); } /* diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index def738d8b..f80ead19a 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -2384,6 +2384,8 @@ IRC_PROTOCOL_CALLBACK(nick) /* enable hotlist */ weechat_buffer_set (NULL, "hotlist", "+"); + + irc_server_set_buffer_input_prompt (ctxt->server); } else { @@ -6769,10 +6771,9 @@ IRC_PROTOCOL_CALLBACK(366) { weechat_hashtable_set (ptr_channel->join_msg_received, "353", "1"); weechat_hashtable_set (ptr_channel->join_msg_received, "366", "1"); + irc_channel_set_buffer_input_prompt (ctxt->server, ptr_channel); } - weechat_bar_item_update ("input_prompt"); - return WEECHAT_RC_OK; } diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index d082243fa..a1180236c 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -879,7 +879,7 @@ irc_server_set_nick (struct t_irc_server *server, const char *nick) weechat_buffer_set (ptr_channel->buffer, "localvar_set_nick", nick); } - weechat_bar_item_update ("input_prompt"); + irc_server_set_buffer_input_prompt (server); weechat_bar_item_update ("irc_nick"); weechat_bar_item_update ("irc_nick_host"); } @@ -1583,6 +1583,53 @@ irc_server_get_default_msg (const char *default_msg, } /* + * Sets input prompt on server, channels and private buffers. + */ + +void +irc_server_set_buffer_input_prompt (struct t_irc_server *server) +{ + struct t_irc_channel *ptr_channel; + int display_modes; + char *prompt; + + if (!server || !server->buffer) + return; + + display_modes = (weechat_config_boolean (irc_config_look_item_nick_modes) + && server->nick_modes && server->nick_modes[0]); + + if (server->nick) + { + weechat_asprintf (&prompt, "%s%s%s%s%s%s%s%s", + IRC_COLOR_INPUT_NICK, + server->nick, + (display_modes) ? IRC_COLOR_BAR_DELIM : "", + (display_modes) ? "(" : "", + (display_modes) ? IRC_COLOR_ITEM_NICK_MODES : "", + (display_modes) ? server->nick_modes : "", + (display_modes) ? IRC_COLOR_BAR_DELIM : "", + (display_modes) ? ")" : ""); + if (prompt) + { + weechat_buffer_set (server->buffer, "input_prompt", prompt); + free (prompt); + } + } + else + { + weechat_buffer_set (server->buffer, "input_prompt", ""); + } + + for (ptr_channel = server->channels; ptr_channel; + ptr_channel = ptr_channel->next_channel) + { + if (ptr_channel->buffer) + irc_channel_set_buffer_input_prompt (server, ptr_channel); + } +} + +/* * Sets "input_multiline" to 1 or 0, according to capability draft/multiline * on all channels and private buffers. */ @@ -1593,6 +1640,9 @@ irc_server_set_buffer_input_multiline (struct t_irc_server *server, { struct t_irc_channel *ptr_channel; + if (!server) + return; + for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { @@ -1614,6 +1664,9 @@ irc_server_has_channels (struct t_irc_server *server) { struct t_irc_channel *ptr_channel; + if (!server) + return 0; + for (ptr_channel = server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { @@ -5712,7 +5765,7 @@ irc_server_disconnect (struct t_irc_server *server, int switch_address, { free (server->nick_modes); server->nick_modes = NULL; - weechat_bar_item_update ("input_prompt"); + irc_server_set_buffer_input_prompt (server); weechat_bar_item_update ("irc_nick_modes"); } if (server->host) diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 6a1c2d48f..a23871967 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -382,6 +382,7 @@ extern char *irc_server_get_default_msg (const char *default_msg, struct t_irc_server *server, const char *channel_name, const char *target_nick); +extern void irc_server_set_buffer_input_prompt (struct t_irc_server *server); extern void irc_server_set_buffer_input_multiline (struct t_irc_server *server, int multiline); extern int irc_server_has_channels (struct t_irc_server *server); |