diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2009-11-19 14:48:36 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2009-11-19 14:48:36 +0100 |
commit | 018973370d307cecf5d32b0bea82b1ef976ccf32 (patch) | |
tree | 2e880fae1b5c95d7abd3f0830d6496103982a8d9 /src | |
parent | 3c7c99b1b56160b5bc22fc35988209ce01237b4a (diff) | |
download | weechat-018973370d307cecf5d32b0bea82b1ef976ccf32.zip |
Add IRC option to use same nick color in channel and private (on by default) (task #9870)
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/irc/irc-channel.c | 6 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.h | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.c | 9 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.h | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-ctcp.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.c | 34 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.h | 6 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 180 |
8 files changed, 81 insertions, 158 deletions
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index 8dc9c06ca..822259159 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -243,6 +243,7 @@ irc_channel_new (struct t_irc_server *server, int channel_type, new_channel->cycle = 0; new_channel->display_creation_date = 0; new_channel->nick_completion_reset = 0; + new_channel->pv_remote_nick_color = NULL; new_channel->nicks_count = 0; new_channel->nicks = NULL; new_channel->last_nick = NULL; @@ -652,6 +653,8 @@ irc_channel_free (struct t_irc_server *server, struct t_irc_channel *channel) irc_nick_free_all (channel); if (channel->away_message) free (channel->away_message); + if (channel->pv_remote_nick_color) + free (channel->pv_remote_nick_color); if (channel->nicks_speaking[0]) weechat_list_free (channel->nicks_speaking[0]); if (channel->nicks_speaking[1]) @@ -722,6 +725,8 @@ irc_channel_add_to_infolist (struct t_infolist *infolist, return 0; if (!weechat_infolist_new_var_string (ptr_item, "key", channel->key)) return 0; + if (!weechat_infolist_new_var_string (ptr_item, "pv_remote_nick_color", channel->pv_remote_nick_color)) + return 0; if (!weechat_infolist_new_var_integer (ptr_item, "nicks_count", channel->nicks_count)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "checking_away", channel->checking_away)) @@ -799,6 +804,7 @@ irc_channel_print_log (struct t_irc_channel *channel) weechat_log_printf (" cycle. . . . . . . . . . : %d", channel->cycle); weechat_log_printf (" display_creation_date. . : %d", channel->display_creation_date); weechat_log_printf (" nick_completion_reset. . : %d", channel->nick_completion_reset); + weechat_log_printf (" pv_remote_nick_color . . : '%s'", channel->pv_remote_nick_color); weechat_log_printf (" nicks_count. . . . . . . : %d", channel->nicks_count); weechat_log_printf (" nicks. . . . . . . . . . : 0x%lx", channel->nicks); weechat_log_printf (" last_nick. . . . . . . . : 0x%lx", channel->last_nick); diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h index d1f08ff5a..031625c58 100644 --- a/src/plugins/irc/irc-channel.h +++ b/src/plugins/irc/irc-channel.h @@ -53,6 +53,7 @@ struct t_irc_channel int display_creation_date; /* 1 for displaying creation date */ int nick_completion_reset; /* 1 for resetting nick completion */ /* there was some join/part on chan */ + char *pv_remote_nick_color; /* color for remote nick in pv */ int nicks_count; /* # nicks on channel (0 if pv) */ struct t_irc_nick *nicks; /* nicks on the channel */ struct t_irc_nick *last_nick; /* last nick on the channel */ diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index c246958aa..0ea853566 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -45,6 +45,7 @@ struct t_config_section *irc_config_section_server = NULL; /* IRC config, look section */ struct t_config_option *irc_config_look_color_nicks_in_server_messages; +struct t_config_option *irc_config_look_color_pv_nick_like_channel; struct t_config_option *irc_config_look_server_buffer; struct t_config_option *irc_config_look_open_channel_near_server; struct t_config_option *irc_config_look_open_pv_near_server; @@ -150,7 +151,7 @@ irc_config_change_look_color_nicks_number (void *data, const char *option, for (ptr_nick = ptr_channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick) { - ptr_nick->color = irc_nick_find_color (ptr_nick); + ptr_nick->color = irc_nick_find_color (ptr_nick->name); } } } @@ -1227,6 +1228,12 @@ irc_config_init () N_("use nick color in messages from server"), NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); + irc_config_look_color_pv_nick_like_channel = weechat_config_new_option ( + irc_config_file, ptr_section, + "color_pv_nick_like_channel", "boolean", + N_("use same nick color for channel and private"), + NULL, 0, 0, "on", NULL, 0, NULL, NULL, + NULL, NULL, NULL, NULL); irc_config_look_server_buffer = weechat_config_new_option ( irc_config_file, ptr_section, "server_buffer", "integer", diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h index 47cc1696f..3b83e18f8 100644 --- a/src/plugins/irc/irc-config.h +++ b/src/plugins/irc/irc-config.h @@ -62,6 +62,7 @@ extern struct t_config_section *irc_config_section_server_default; extern struct t_config_section *irc_config_section_server; extern struct t_config_option *irc_config_look_color_nicks_in_server_messages; +extern struct t_config_option *irc_config_look_color_pv_nick_like_channel; extern struct t_config_option *irc_config_look_server_buffer; extern struct t_config_option *irc_config_look_open_channel_near_server; extern struct t_config_option *irc_config_look_open_pv_near_server; diff --git a/src/plugins/irc/irc-ctcp.c b/src/plugins/irc/irc-ctcp.c index cfdf75cdf..4bcc66480 100644 --- a/src/plugins/irc/irc-ctcp.c +++ b/src/plugins/irc/irc-ctcp.c @@ -883,7 +883,7 @@ irc_ctcp_recv (struct t_irc_server *server, const char *command, "%s%s%s%s%s%s", weechat_prefix ("action"), (nick_is_me) ? - IRC_COLOR_CHAT_NICK_SELF : IRC_COLOR_CHAT_NICK_OTHER, + IRC_COLOR_CHAT_NICK_SELF : irc_nick_color_for_pv (ptr_channel, nick), nick, (pos_args) ? IRC_COLOR_CHAT : "", (pos_args) ? " " : "", diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index c87c7fd3a..1a0519b07 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -61,15 +61,15 @@ irc_nick_valid (struct t_irc_channel *channel, struct t_irc_nick *nick) */ const char * -irc_nick_find_color (struct t_irc_nick *nick) +irc_nick_find_color (const char *nickname) { int i, color; char color_name[64]; color = 0; - for (i = strlen (nick->name) - 1; i >= 0; i--) + for (i = strlen (nickname) - 1; i >= 0; i--) { - color += (int)(nick->name[i]); + color += (int)(nickname[i]); } color = (color % weechat_config_integer (weechat_config_get ("weechat.look.color_nicks_number"))); @@ -179,7 +179,7 @@ irc_nick_get_gui_infos (struct t_irc_nick *nick, struct t_irc_nick * irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, - const char *nick_name, int is_chanowner, int is_chanadmin, + const char *nickname, int is_chanowner, int is_chanadmin, int is_chanadmin2, int is_op, int is_halfop, int has_voice, int is_chanuser, int is_away) { @@ -189,7 +189,7 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, struct t_gui_nick_group *ptr_group; /* nick already exists on this channel? */ - ptr_nick = irc_nick_search (channel, nick_name); + ptr_nick = irc_nick_search (channel, nickname); if (ptr_nick) { /* remove old nick from nicklist */ @@ -232,7 +232,7 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, return NULL; /* initialize new nick */ - new_nick->name = strdup (nick_name); + new_nick->name = strdup (nickname); new_nick->host = NULL; new_nick->flags = 0; IRC_NICK_SET_FLAG(new_nick, is_chanowner, IRC_NICK_CHANOWNER); @@ -246,7 +246,7 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, if (weechat_strcasecmp (new_nick->name, server->nick) == 0) new_nick->color = IRC_COLOR_CHAT_NICK_SELF; else - new_nick->color = irc_nick_find_color (new_nick); + new_nick->color = irc_nick_find_color (new_nick->name); /* add nick to end of list */ new_nick->prev_nick = channel->last_nick; @@ -311,7 +311,7 @@ irc_nick_change (struct t_irc_server *server, struct t_irc_channel *channel, if (nick_is_me) nick->color = IRC_COLOR_CHAT_NICK_SELF; else - nick->color = irc_nick_find_color (nick); + nick->color = irc_nick_find_color (nick->name); /* add nick in nicklist */ prefix[0] = ' '; @@ -580,6 +580,24 @@ irc_nick_as_prefix (struct t_irc_nick *nick, const char *nickname, } /* + * irc_nick_color_for_pv: return string with color of nick for private + */ + +const char * +irc_nick_color_for_pv (struct t_irc_channel *channel, const char *nickname) +{ + if (weechat_config_boolean (irc_config_look_color_pv_nick_like_channel)) + { + if (!channel->pv_remote_nick_color) + channel->pv_remote_nick_color = strdup (irc_nick_find_color (nickname)); + if (channel->pv_remote_nick_color) + return channel->pv_remote_nick_color; + } + + return IRC_COLOR_CHAT_NICK_OTHER; +} + +/* * irc_nick_add_to_infolist: add a nick in an infolist * return 1 if ok, 0 if error */ diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index af1f556e0..985582583 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.h @@ -61,10 +61,10 @@ struct t_irc_nick extern int irc_nick_valid (struct t_irc_channel *channel, struct t_irc_nick *nick); -extern const char *irc_nick_find_color (struct t_irc_nick *nick); +extern const char *irc_nick_find_color (const char *nickname); extern struct t_irc_nick *irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, - const char *nick_name, + const char *nickname, int is_chanowner, int is_chanadmin, int is_chanadmin2, @@ -90,6 +90,8 @@ extern void irc_nick_set_away (struct t_irc_channel *channel, struct t_irc_nick *nick, int is_away); extern char *irc_nick_as_prefix (struct t_irc_nick *nick, const char *nickname, const char *force_color); +extern const char * irc_nick_color_for_pv (struct t_irc_channel *channel, + const char *nickname); extern int irc_nick_add_to_infolist (struct t_infolist *infolist, struct t_irc_nick *nick); extern void irc_nick_print_log (struct t_irc_nick *nick); diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 7766a7d19..fe6d6413c 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -665,6 +665,11 @@ irc_protocol_cmd_nick (struct t_irc_server *server, const char *command, { free (ptr_channel->name); ptr_channel->name = strdup (new_nick); + if (ptr_channel->pv_remote_nick_color) + { + free (ptr_channel->pv_remote_nick_color); + ptr_channel->pv_remote_nick_color = NULL; + } buffer_name = irc_buffer_build_name (server->name, ptr_channel->name); weechat_buffer_set (ptr_channel->buffer, "name", buffer_name); weechat_buffer_set (ptr_channel->buffer, "short_name", ptr_channel->name); @@ -1081,7 +1086,7 @@ int irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, int argc, char **argv, char **argv_eol) { - char *pos_args, *pos_end_01, *pos, *pos_message; + char *pos_args; const char *remote_nick; int nick_is_me; struct t_irc_channel *ptr_channel; @@ -1180,157 +1185,40 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, ptr_channel = irc_channel_search (server, remote_nick); - if (strncmp (pos_args, "\01ACTION ", 8) == 0) + if (!irc_ignore_check (server, ptr_channel, remote_nick, host)) { - if (!irc_ignore_check (server, ptr_channel, remote_nick, host)) + if (!ptr_channel) { + ptr_channel = irc_channel_new (server, + IRC_CHANNEL_TYPE_PRIVATE, + remote_nick, 0, 0); if (!ptr_channel) { - ptr_channel = irc_channel_new (server, - IRC_CHANNEL_TYPE_PRIVATE, - remote_nick, 0, 0); - if (!ptr_channel) - { - weechat_printf (server->buffer, - _("%s%s: cannot create new " - "private buffer \"%s\""), - weechat_prefix ("error"), - IRC_PLUGIN_NAME, remote_nick); - return WEECHAT_RC_ERROR; - } - } - if (!ptr_channel->topic) - irc_channel_set_topic (ptr_channel, address); - - pos_args += 8; - pos_end_01 = strrchr (pos_args, '\01'); - if (pos_end_01) - pos_end_01[0] = '\0'; - - weechat_printf_tags (ptr_channel->buffer, - irc_protocol_tags (command, - (nick_is_me) ? - "irc_action,notify_private,no_highlight" : - "irc_action,notify_private"), - "%s%s%s %s%s", - weechat_prefix ("action"), - (nick_is_me) ? - IRC_COLOR_CHAT_NICK_SELF : IRC_COLOR_CHAT_NICK_OTHER, - nick, - IRC_COLOR_CHAT, - pos_args); - weechat_hook_signal_send ("irc_pv", - WEECHAT_HOOK_SIGNAL_STRING, - argv_eol[0]); - - if (pos_end_01) - pos_end_01[0] = '\01'; - } - } - else - { - /* unknown CTCP ? */ - pos_end_01 = strrchr (pos_args + 1, '\01'); - if ((pos_args[0] == '\01') - && pos_end_01 && (pos_end_01[1] == '\0')) - { - if (!irc_ignore_check (server, ptr_channel, remote_nick, host)) - { - pos_args++; - pos_end_01[0] = '\0'; - pos = strchr (pos_args, ' '); - if (pos) - { - pos[0] = '\0'; - pos_message = pos + 1; - while (pos_message[0] == ' ') - { - pos_message++; - } - if (!pos_message[0]) - pos_message = NULL; - } - else - pos_message = NULL; - - if (pos_message) - { - weechat_printf_tags (server->buffer, - irc_protocol_tags (command, "irc_ctcp"), - _("%sUnknown CTCP %s%s%s " - "received from %s%s%s: %s"), - weechat_prefix ("network"), - IRC_COLOR_CHAT_CHANNEL, - pos_args, - IRC_COLOR_CHAT, - IRC_COLOR_CHAT_NICK, - nick, - IRC_COLOR_CHAT, - pos_message); - } - else - { - weechat_printf_tags (server->buffer, - irc_protocol_tags (command, "irc_ctcp"), - _("%sUnknown CTCP %s%s%s " - "received from %s%s%s"), - weechat_prefix ("network"), - IRC_COLOR_CHAT_CHANNEL, - pos_args, - IRC_COLOR_CHAT, - IRC_COLOR_CHAT_NICK, - nick, - IRC_COLOR_CHAT); - } - if (pos_end_01) - pos_end_01[0] = '\01'; - if (pos) - pos[0] = ' '; - - weechat_hook_signal_send ("irc_ctcp", - WEECHAT_HOOK_SIGNAL_STRING, - argv_eol[0]); - } - } - else - { - /* private message */ - if (!irc_ignore_check (server, ptr_channel, remote_nick, host)) - { - if (!ptr_channel) - { - ptr_channel = irc_channel_new (server, - IRC_CHANNEL_TYPE_PRIVATE, - remote_nick, 0, 0); - if (!ptr_channel) - { - weechat_printf (server->buffer, - _("%s%s: cannot create new " - "private buffer \"%s\""), - weechat_prefix ("error"), - IRC_PLUGIN_NAME, remote_nick); - return WEECHAT_RC_ERROR; - } - } - irc_channel_set_topic (ptr_channel, address); - - weechat_printf_tags (ptr_channel->buffer, - irc_protocol_tags (command, - (nick_is_me) ? - "notify_private,no_highlight" : - "notify_private"), - "%s%s", - irc_nick_as_prefix (NULL, - nick, - (nick_is_me) ? - IRC_COLOR_CHAT_NICK_SELF : IRC_COLOR_CHAT_NICK_OTHER), - pos_args); - - weechat_hook_signal_send ("irc_pv", - WEECHAT_HOOK_SIGNAL_STRING, - argv_eol[0]); + weechat_printf (server->buffer, + _("%s%s: cannot create new " + "private buffer \"%s\""), + weechat_prefix ("error"), + IRC_PLUGIN_NAME, remote_nick); + return WEECHAT_RC_ERROR; } } + irc_channel_set_topic (ptr_channel, address); + + weechat_printf_tags (ptr_channel->buffer, + irc_protocol_tags (command, + (nick_is_me) ? + "notify_private,no_highlight" : + "notify_private"), + "%s%s", + irc_nick_as_prefix (NULL, + nick, + (nick_is_me) ? + IRC_COLOR_CHAT_NICK_SELF : irc_nick_color_for_pv (ptr_channel, nick)), + pos_args); + + weechat_hook_signal_send ("irc_pv", + WEECHAT_HOOK_SIGNAL_STRING, + argv_eol[0]); } } |