diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/irc/irc-bar-item.c | 5 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.c | 96 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.h | 6 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.c | 113 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.h | 6 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 23 |
6 files changed, 154 insertions, 95 deletions
diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c index dce6b6dda..e6e24e682 100644 --- a/src/plugins/irc/irc-bar-item.c +++ b/src/plugins/irc/irc-bar-item.c @@ -423,7 +423,7 @@ irc_bar_item_input_prompt (void *data, struct t_gui_bar_item *item, struct t_irc_channel *channel; struct t_irc_nick *ptr_nick; char *buf, str_prefix[64]; - int length, prefix_color; + int length; /* make C compiler happy */ (void) data; @@ -451,9 +451,8 @@ irc_bar_item_input_prompt (void *data, struct t_gui_bar_item *item, { if (ptr_nick->prefix[0] != ' ') { - prefix_color = irc_nick_get_prefix_color (server, ptr_nick); snprintf (str_prefix, sizeof (str_prefix), "%s%s", - weechat_color (weechat_config_string (weechat_config_get (irc_nick_get_prefix_color_name (prefix_color)))), + weechat_color (irc_nick_get_prefix_color_name (server, ptr_nick)), ptr_nick->prefix); } } diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index 5a1fb26d7..641a76aea 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -99,10 +99,7 @@ struct t_config_option *irc_config_look_topic_strip_colors; struct t_config_option *irc_config_color_message_join; struct t_config_option *irc_config_color_message_quit; -struct t_config_option *irc_config_color_nick_prefix_op; -struct t_config_option *irc_config_color_nick_prefix_halfop; -struct t_config_option *irc_config_color_nick_prefix_voice; -struct t_config_option *irc_config_color_nick_prefix_user; +struct t_config_option *irc_config_color_nick_prefixes; struct t_config_option *irc_config_color_nick_prefix; struct t_config_option *irc_config_color_nick_suffix; struct t_config_option *irc_config_color_notice; @@ -135,6 +132,7 @@ struct t_hook *irc_config_hook_config_nick_colors = NULL; char **irc_config_nick_colors = NULL; int irc_config_num_nick_colors = 0; struct t_hashtable *irc_config_hashtable_nick_color_force = NULL; +struct t_hashtable *irc_config_hashtable_nick_prefixes = NULL; int irc_config_write_temp_servers = 0; @@ -586,18 +584,52 @@ irc_config_change_color_item_lag (void *data, } /* - * irc_config_change_color_nick_prefix: called when the color of a nick prefix - * is changed + * irc_config_change_color_nick_prefixes: called when the string with color of + * nick prefixes is changed */ void -irc_config_change_color_nick_prefix (void *data, - struct t_config_option *option) +irc_config_change_color_nick_prefixes (void *data, + struct t_config_option *option) { + char **items, *pos; + int num_items, i; + /* make C compiler happy */ (void) data; (void) option; + if (!irc_config_hashtable_nick_prefixes) + { + irc_config_hashtable_nick_prefixes = weechat_hashtable_new (8, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, + NULL); + } + else + weechat_hashtable_remove_all (irc_config_hashtable_nick_prefixes); + + items = weechat_string_split (weechat_config_string (irc_config_color_nick_prefixes), + ";", 0, 0, &num_items); + if (items) + { + for (i = 0; i < num_items; i++) + { + pos = strchr (items[i], ':'); + if (pos) + { + pos[0] = '\0'; + weechat_hashtable_set (irc_config_hashtable_nick_prefixes, + items[i], + pos + 1); + } + } + weechat_string_free_split (items); + } + + irc_nick_nicklist_set_prefix_color_all (); + weechat_bar_item_update ("input_prompt"); weechat_bar_item_update ("nicklist"); } @@ -1777,6 +1809,11 @@ irc_config_init () WEECHAT_HASHTABLE_STRING, NULL, NULL); + irc_config_hashtable_nick_prefixes = weechat_hashtable_new (8, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, + NULL); irc_config_file = weechat_config_new (IRC_CONFIG_NAME, &irc_config_reload, NULL); @@ -2105,30 +2142,17 @@ irc_config_init () N_("color for text in part/quit messages"), NULL, -1, 0, "red", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); - irc_config_color_nick_prefix_op = weechat_config_new_option ( - irc_config_file, ptr_section, - "nick_prefix_op", "color", - N_("color for prefix of nick which is op/admin/owner on channel"), - NULL, -1, 0, "lightgreen", NULL, 0, NULL, NULL, - &irc_config_change_color_nick_prefix, NULL, NULL, NULL); - irc_config_color_nick_prefix_halfop = weechat_config_new_option ( - irc_config_file, ptr_section, - "nick_prefix_halfop", "color", - N_("color for prefix of nick which is halfop on channel"), - NULL, -1, 0, "lightmagenta", NULL, 0, NULL, NULL, - &irc_config_change_color_nick_prefix, NULL, NULL, NULL); - irc_config_color_nick_prefix_voice = weechat_config_new_option ( - irc_config_file, ptr_section, - "nick_prefix_voice", "color", - N_("color for prefix of nick which has voice on channel"), - NULL, -1, 0, "yellow", NULL, 0, NULL, NULL, - &irc_config_change_color_nick_prefix, NULL, NULL, NULL); - irc_config_color_nick_prefix_user = weechat_config_new_option ( - irc_config_file, ptr_section, - "nick_prefix_user", "color", - N_("color for prefix of nick which is user on channel"), - NULL, -1, 0, "blue", NULL, 0, NULL, NULL, - &irc_config_change_color_nick_prefix, NULL, NULL, NULL); + irc_config_color_nick_prefixes = weechat_config_new_option ( + irc_config_file, ptr_section, + "nick_prefixes", "string", + N_("color for nick prefixes using mode char (o=op, h=halfop, v=voice, " + "..), format is: \"o:color1;h:color2;v:color3\" (if a mode is not " + "found, WeeChat will try with next modes received from server " + "(\"PREFIX\"); a special mode \"*\" can be used as default color " + "if no mode has been found in list)"), + NULL, 0, 0, "q:lightred;a:lightcyan;o:lightgreen;h:lightmagenta;" + "v:yellow;*:lightblue", NULL, 0, NULL, NULL, + &irc_config_change_color_nick_prefixes, NULL, NULL, NULL); irc_config_color_nick_prefix = weechat_config_new_option ( irc_config_file, ptr_section, "nick_prefix", "color", @@ -2360,6 +2384,8 @@ irc_config_read () if (rc == WEECHAT_CONFIG_READ_OK) { irc_notify_new_for_all_servers (); + irc_config_change_look_nick_color_force (NULL, NULL); + irc_config_change_color_nick_prefixes (NULL, NULL); irc_config_change_network_notify_check_ison (NULL, NULL); irc_config_change_network_notify_check_whois (NULL, NULL); } @@ -2404,4 +2430,10 @@ irc_config_free () weechat_hashtable_free (irc_config_hashtable_nick_color_force); irc_config_hashtable_nick_color_force = NULL; } + + if (irc_config_hashtable_nick_prefixes) + { + weechat_hashtable_free (irc_config_hashtable_nick_prefixes); + irc_config_hashtable_nick_prefixes = NULL; + } } diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h index 1f505460e..ae01d5931 100644 --- a/src/plugins/irc/irc-config.h +++ b/src/plugins/irc/irc-config.h @@ -122,10 +122,7 @@ extern struct t_config_option *irc_config_look_topic_strip_colors; extern struct t_config_option *irc_config_color_message_join; extern struct t_config_option *irc_config_color_message_quit; -extern struct t_config_option *irc_config_color_nick_prefix_op; -extern struct t_config_option *irc_config_color_nick_prefix_halfop; -extern struct t_config_option *irc_config_color_nick_prefix_voice; -extern struct t_config_option *irc_config_color_nick_prefix_user; +extern struct t_config_option *irc_config_color_nick_prefixes; extern struct t_config_option *irc_config_color_nick_prefix; extern struct t_config_option *irc_config_color_nick_suffix; extern struct t_config_option *irc_config_color_notice; @@ -154,6 +151,7 @@ extern char **irc_config_nick_colors; extern int irc_config_num_nick_colors; extern struct t_hashtable *irc_config_hashtable_nick_color_force; +extern struct t_hashtable *irc_config_hashtable_nick_prefixes; extern void irc_config_set_nick_colors (); extern void irc_config_server_change_cb (void *data, diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 2dadbc9ae..ead04f71d 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -384,52 +384,48 @@ irc_nick_get_nicklist_group (struct t_irc_server *server, } /* - * irc_nick_get_prefix_color: get prefix color index for a nick + * irc_nick_get_prefix_color_name: return name of prefix color for a nick */ -int -irc_nick_get_prefix_color (struct t_irc_server *server, - struct t_irc_nick *nick) +const char * +irc_nick_get_prefix_color_name (struct t_irc_server *server, + struct t_irc_nick *nick) { - int index, prefix_color; + static char *default_color = "chat"; + const char *prefix_modes, *color; + char mode[2]; + int i, index; - prefix_color = 0; - index = irc_server_get_prefix_char_index (server, nick->prefix[0]); - if (index >= 0) + if (irc_config_hashtable_nick_prefixes) { - if (index <= irc_server_get_prefix_mode_index (server, 'o')) - prefix_color = 1; /* color for op (or better than op) */ - else if (index == irc_server_get_prefix_mode_index (server, 'h')) - prefix_color = 2; /* color for halh-op */ - else if (index == irc_server_get_prefix_mode_index (server, 'v')) - prefix_color = 3; /* color for voice */ - else if (index == irc_server_get_prefix_mode_index (server, 'u')) - prefix_color = 4; /* color for chan user */ + index = irc_server_get_prefix_char_index (server, nick->prefix[0]); + if (index >= 0) + { + mode[0] = ' '; + mode[1] = '\0'; + prefix_modes = irc_server_get_prefix_modes (server); + for (i = index; prefix_modes[i]; i++) + { + mode[0] = prefix_modes[i]; + color = weechat_hashtable_get (irc_config_hashtable_nick_prefixes, + mode); + if (color) + return color; + } + /* + * no color found with mode (and following modes)? + * => fallback to "*" + */ + mode[0] = '*'; + color = weechat_hashtable_get (irc_config_hashtable_nick_prefixes, + mode); + if (color) + return color; + } } - return prefix_color; -} - -/* - * irc_nick_get_prefix_color_name: return name of color with a prefix number - */ - -const char * -irc_nick_get_prefix_color_name (int prefix_color) -{ - static char *color_for_prefix[] = { - "chat", - "irc.color.nick_prefix_op", - "irc.color.nick_prefix_halfop", - "irc.color.nick_prefix_voice", - "irc.color.nick_prefix_user", - }; - - if ((prefix_color >= 0) && (prefix_color <= 4)) - return color_for_prefix[prefix_color]; - - /* no color by default (should not happen) */ - return color_for_prefix[0]; + /* no color by default */ + return default_color; } /* @@ -467,16 +463,14 @@ irc_nick_nicklist_add (struct t_irc_server *server, struct t_irc_channel *channel, struct t_irc_nick *nick) { - int prefix_color; struct t_gui_nick_group *ptr_group; ptr_group = irc_nick_get_nicklist_group (server, channel->buffer, nick); - prefix_color = irc_nick_get_prefix_color (server, nick); weechat_nicklist_add_nick (channel->buffer, ptr_group, nick->name, irc_nick_get_color_for_nicklist (server, nick), nick->prefix, - irc_nick_get_prefix_color_name (prefix_color), + irc_nick_get_prefix_color_name (server, nick), 1); } @@ -517,6 +511,35 @@ irc_nick_nicklist_set (struct t_irc_channel *channel, } /* + * irc_nick_nicklist_set_prefix_color_all: set nick prefix colors in nicklist + * for all servers/channels + */ + +void +irc_nick_nicklist_set_prefix_color_all () +{ + struct t_irc_server *ptr_server; + struct t_irc_channel *ptr_channel; + struct t_irc_nick *ptr_nick; + + 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) + { + for (ptr_nick = ptr_channel->nicks; ptr_nick; + ptr_nick = ptr_nick->next_nick) + { + irc_nick_nicklist_set (ptr_channel, ptr_nick, "prefix_color", + irc_nick_get_prefix_color_name (ptr_server, + ptr_nick)); + } + } + } +} + +/* * irc_nick_nicklist_set_color_all: set nick colors in nicklist for all * servers/channels */ @@ -840,19 +863,17 @@ irc_nick_as_prefix (struct t_irc_server *server, struct t_irc_nick *nick, static char result[256]; char prefix[2]; const char *str_prefix_color; - int prefix_color; - + prefix[0] = (nick) ? nick->prefix[0] : '\0'; prefix[1] = '\0'; if (weechat_config_boolean (weechat_config_get ("weechat.look.nickmode"))) { if (nick) { - prefix_color = irc_nick_get_prefix_color (server, nick); if ((prefix[0] == ' ') && !weechat_config_boolean (weechat_config_get ("weechat.look.nickmode_empty"))) prefix[0] = '\0'; - str_prefix_color = weechat_color (weechat_config_string (weechat_config_get (irc_nick_get_prefix_color_name (prefix_color)))); + str_prefix_color = weechat_color (irc_nick_get_prefix_color_name (server, nick)); } else { diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index b5da137d1..e40347f23 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.h @@ -55,9 +55,9 @@ extern int irc_nick_is_op (struct t_irc_server *server, extern int irc_nick_has_prefix_mode (struct t_irc_server *server, struct t_irc_nick *nick, char prefix_mode); -extern int irc_nick_get_prefix_color (struct t_irc_server *server, - struct t_irc_nick *nick); -extern const char *irc_nick_get_prefix_color_name (int prefix_color); +extern const char *irc_nick_get_prefix_color_name (struct t_irc_server *server, + struct t_irc_nick *nick); +extern void irc_nick_nicklist_set_prefix_color_all (); extern void irc_nick_nicklist_set_color_all (); extern struct t_irc_nick *irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel, diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index a81854f39..1f070822e 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -3549,7 +3549,7 @@ IRC_PROTOCOL_CALLBACK(366) struct t_config_option *ptr_option; int num_nicks, num_op, num_halfop, num_voice, num_normal, length, i; char *string; - const char *prefix, *nickname; + const char *prefix, *prefix_color, *nickname; /* * 366 message looks like: @@ -3599,12 +3599,21 @@ IRC_PROTOCOL_CALLBACK(366) prefix = weechat_infolist_string (infolist, "prefix"); if (prefix[0] && (prefix[0] != ' ')) { - weechat_config_search_with_string (weechat_infolist_string (infolist, - "prefix_color"), - NULL, NULL, &ptr_option, - NULL); - if (ptr_option) - strcat (string, weechat_color (weechat_config_string (ptr_option))); + prefix_color = weechat_infolist_string (infolist, + "prefix_color"); + if (strchr (prefix_color, '.')) + { + weechat_config_search_with_string (weechat_infolist_string (infolist, + "prefix_color"), + NULL, NULL, &ptr_option, + NULL); + if (ptr_option) + strcat (string, weechat_color (weechat_config_string (ptr_option))); + } + else + { + strcat (string, weechat_color (prefix_color)); + } strcat (string, prefix); } nickname = weechat_infolist_string (infolist, "name"); |