diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 960b26470..4ac12674b 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -30,6 +30,7 @@ New features:: * api: replace argument "keep_eol" by "flags" in function string_split (issue #1322) * api: add function command_options (issue #928) * api: add function string_match_list + * irc: add bar items "irc_nick", "irc_host" and "irc_nick_host" * irc: add variable "nick_host" in server structure * relay: add option relay.weechat.commands (issue #928) * script: use SHA-512 instead of MD5 for script checksum diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c index bfc8379de..2afb1027f 100644 --- a/src/plugins/irc/irc-bar-item.c +++ b/src/plugins/irc/irc-bar-item.c @@ -379,6 +379,106 @@ irc_bar_item_channel (const void *pointer, void *data, return strdup (buf); } +/* + * Returns content of bar item "irc_nick": bar item with nick name + * (without modes). + */ + +char * +irc_bar_item_nick (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 buf[512]; + struct t_irc_server *server; + + /* 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, NULL); + if (!server || !server->nick) + return NULL; + + snprintf (buf, sizeof (buf), "%s%s", + IRC_COLOR_INPUT_NICK, + server->nick); + + return strdup (buf); +} + +/* + * Returns content of bar item "irc_host": bar item with self host. + */ + +char * +irc_bar_item_host (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; + + /* 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, NULL); + if (!server || !server->nick_host) + return NULL; + + return strdup (server->nick_host); +} + +/* + * Returns content of bar item "irc_nick_host": bar item with nick and host. + */ + +char * +irc_bar_item_nick_host (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 buf[512]; + struct t_irc_server *server; + + /* 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, NULL); + if (!server || !server->nick) + return NULL; + + snprintf (buf, sizeof (buf), "%s%s%s", + server->nick, + (server->nick_host) ? "@" : "", + (server->nick_host) ? server->nick_host : ""); + + return strdup (buf); +} + /* * Returns content of bar item "lag": bar item with lag value. */ @@ -615,6 +715,9 @@ irc_bar_item_buffer_switch (const void *pointer, void *data, weechat_bar_item_update ("lag"); weechat_bar_item_update ("input_prompt"); weechat_bar_item_update ("irc_nick_modes"); + weechat_bar_item_update ("irc_nick"); + weechat_bar_item_update ("irc_host"); + weechat_bar_item_update ("irc_nick_host"); return WEECHAT_RC_OK; } @@ -648,6 +751,12 @@ irc_bar_item_init () &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", + &irc_bar_item_nick, NULL, NULL); + weechat_bar_item_new ("irc_host", + &irc_bar_item_host, NULL, NULL); + weechat_bar_item_new ("irc_nick_host", + &irc_bar_item_nick_host, NULL, NULL); weechat_bar_item_new ("lag", &irc_bar_item_lag, NULL, NULL); weechat_bar_item_new ("input_prompt", diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 3e8b55c25..5295016b5 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -624,7 +624,11 @@ irc_nick_set_mode (struct t_irc_server *server, struct t_irc_channel *channel, irc_nick_nicklist_add (server, channel, nick); if (irc_server_strcasecmp (server, nick->name, server->nick) == 0) + { weechat_bar_item_update ("input_prompt"); + weechat_bar_item_update ("irc_nick"); + weechat_bar_item_update ("irc_nick_host"); + } } /* diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index aa23ed56e..28d0136af 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -756,6 +756,8 @@ irc_server_set_nick (struct t_irc_server *server, const char *nick) } weechat_bar_item_update ("input_prompt"); + weechat_bar_item_update ("irc_nick"); + weechat_bar_item_update ("irc_nick_host"); } /* @@ -787,6 +789,9 @@ irc_server_set_nick_host (struct t_irc_server *server, const char *host) weechat_buffer_set (ptr_channel->buffer, "localvar_set_nick_host", host); } + + weechat_bar_item_update ("irc_host"); + weechat_bar_item_update ("irc_nick_host"); } /* @@ -5115,6 +5120,8 @@ irc_server_disconnect (struct t_irc_server *server, int switch_address, { free (server->nick_host); server->nick_host = NULL; + weechat_bar_item_update ("irc_host"); + weechat_bar_item_update ("irc_nick_host"); } server->checking_cap_ls = 0; weechat_hashtable_remove_all (server->cap_ls);