summaryrefslogtreecommitdiff
path: root/src/plugins/irc
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-12-20 15:08:30 +0100
committerSebastien Helleu <flashcode@flashtux.org>2010-12-20 15:08:30 +0100
commit2ee9f7b0fcac460fca5597ec349309e83de64d00 (patch)
tree2a2648efc0a638ad534c747a30d5874aa72065f1 /src/plugins/irc
parent1340ce6b41cfb0fa1f69d4d1c5c3000eac3e6f61 (diff)
downloadweechat-2ee9f7b0fcac460fca5597ec349309e83de64d00.zip
Replace the 10 nick color options and number of nick colors by a single option "weechat.color.chat_nick_colors" (comma separated list of colors)
Diffstat (limited to 'src/plugins/irc')
-rw-r--r--src/plugins/irc/irc-config.c55
-rw-r--r--src/plugins/irc/irc-config.h4
-rw-r--r--src/plugins/irc/irc-nick.c35
-rw-r--r--src/plugins/irc/irc-nick.h2
4 files changed, 73 insertions, 23 deletions
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
index 44e0e3cdc..3421c8de6 100644
--- a/src/plugins/irc/irc-config.c
+++ b/src/plugins/irc/irc-config.c
@@ -126,7 +126,9 @@ struct t_config_option *irc_config_network_send_unknown_commands;
struct t_config_option *irc_config_server_default[IRC_SERVER_NUM_OPTIONS];
-struct t_hook *hook_config_color_nicks_number = NULL;
+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;
int irc_config_write_temp_servers = 0;
@@ -187,20 +189,41 @@ irc_config_compute_nick_colors ()
}
/*
- * irc_config_change_look_color_nicks_number: called when the
- * "weechat.look.color_nicks_number"
- * option is changed
+ * irc_config_set_nick_colors: set nick colors using option
+ * "weechat.color.chat_nick_colors"
+ */
+
+void
+irc_config_set_nick_colors ()
+{
+ if (irc_config_nick_colors)
+ {
+ weechat_string_free_split (irc_config_nick_colors);
+ irc_config_nick_colors = NULL;
+ irc_config_num_nick_colors = 0;
+ }
+
+ irc_config_nick_colors =
+ weechat_string_split (weechat_config_string (weechat_config_get ("weechat.color.chat_nick_colors")),
+ ",", 0, 0,
+ &irc_config_num_nick_colors);
+}
+
+/*
+ * irc_config_change_nick_colors_cb: callback called when option
+ * "weechat.color.chat_nick_colors" is changed
*/
int
-irc_config_change_look_color_nicks_number (void *data, const char *option,
- const char *value)
+irc_config_change_nick_colors_cb (void *data, const char *option,
+ const char *value)
{
/* make C compiler happy */
(void) data;
(void) option;
(void) value;
+ irc_config_set_nick_colors ();
irc_config_compute_nick_colors ();
return WEECHAT_RC_OK;
@@ -2254,8 +2277,8 @@ irc_config_init ()
}
irc_config_section_server = ptr_section;
- hook_config_color_nicks_number = weechat_hook_config ("weechat.look.color_nicks_number",
- &irc_config_change_look_color_nicks_number, NULL);
+ irc_config_hook_config_nick_colors = weechat_hook_config ("weechat.color.chat_nick_colors",
+ &irc_config_change_nick_colors_cb, NULL);
return 1;
}
@@ -2299,13 +2322,19 @@ void
irc_config_free ()
{
weechat_config_free (irc_config_file);
-
- if (hook_config_color_nicks_number)
+
+ if (irc_config_hook_config_nick_colors)
{
- weechat_unhook (hook_config_color_nicks_number);
- hook_config_color_nicks_number = NULL;
+ weechat_unhook (irc_config_hook_config_nick_colors);
+ irc_config_hook_config_nick_colors = NULL;
}
-
+ if (irc_config_nick_colors)
+ {
+ weechat_string_free_split (irc_config_nick_colors);
+ irc_config_nick_colors = NULL;
+ irc_config_num_nick_colors = 0;
+ }
+
if (irc_config_hashtable_nick_color_force)
{
weechat_hashtable_free (irc_config_hashtable_nick_color_force);
diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h
index aed25367e..e199f4bcc 100644
--- a/src/plugins/irc/irc-config.h
+++ b/src/plugins/irc/irc-config.h
@@ -145,8 +145,12 @@ extern struct t_config_option *irc_config_network_send_unknown_commands;
extern struct t_config_option *irc_config_server_default[];
+extern char **irc_config_nick_colors;
+extern int irc_config_num_nick_colors;
+
extern struct t_hashtable *irc_config_hashtable_nick_color_force;
+extern void irc_config_set_nick_colors ();
extern void irc_config_server_change_cb (void *data,
struct t_config_option *option);
struct t_config_option *irc_config_server_new_option (struct t_config_file *config_file,
diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c
index 3d42afca1..f29eaf480 100644
--- a/src/plugins/irc/irc-nick.c
+++ b/src/plugins/irc/irc-nick.c
@@ -141,6 +141,12 @@ irc_nick_hash_color (const char *nickname)
int color;
const char *ptr_nick;
+ if (!irc_config_nick_colors)
+ irc_config_set_nick_colors ();
+
+ if (irc_config_num_nick_colors == 0)
+ return 0;
+
color = 0;
ptr_nick = nickname;
while (ptr_nick && ptr_nick[0])
@@ -148,8 +154,8 @@ irc_nick_hash_color (const char *nickname)
color += weechat_utf8_char_int (ptr_nick);
ptr_nick = weechat_utf8_next_char (ptr_nick);
}
- return (color %
- weechat_config_integer (weechat_config_get ("weechat.look.color_nicks_number")));
+
+ return (color % irc_config_num_nick_colors);
}
/*
@@ -161,9 +167,15 @@ const char *
irc_nick_find_color (const char *nickname)
{
int color;
- char *nickname2, color_name[64];
+ char *nickname2;
const char *forced_color;
+ if (!irc_config_nick_colors)
+ irc_config_set_nick_colors ();
+
+ if (irc_config_num_nick_colors == 0)
+ return weechat_color ("default");
+
nickname2 = irc_nick_strdup_for_color (nickname);
/* look if color is forced */
@@ -186,9 +198,7 @@ irc_nick_find_color (const char *nickname)
free (nickname2);
/* return color */
- snprintf (color_name, sizeof (color_name),
- "chat_nick_color%02d", color + 1);
- return weechat_color (color_name);
+ return weechat_color (irc_config_nick_colors[color]);
}
/*
@@ -200,8 +210,15 @@ const char *
irc_nick_find_color_name (const char *nickname)
{
int color;
- char *nickname2, color_name[128];
+ char *nickname2;
const char *forced_color;
+ static char *default_color = "default";
+
+ if (!irc_config_nick_colors)
+ irc_config_set_nick_colors ();
+
+ if (irc_config_num_nick_colors == 0)
+ return default_color;
nickname2 = irc_nick_strdup_for_color (nickname);
@@ -221,9 +238,7 @@ irc_nick_find_color_name (const char *nickname)
free (nickname2);
/* return color name */
- snprintf (color_name, sizeof (color_name),
- "weechat.color.chat_nick_color%02d", color + 1);
- return weechat_config_color (weechat_config_get (color_name));
+ return irc_config_nick_colors[color];
}
/*
diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h
index 8df1c66fa..54799fc7f 100644
--- a/src/plugins/irc/irc-nick.h
+++ b/src/plugins/irc/irc-nick.h
@@ -46,6 +46,8 @@ struct t_irc_nick
extern int irc_nick_valid (struct t_irc_channel *channel,
struct t_irc_nick *nick);
extern int irc_nick_is_nick (const char *string);
+extern int irc_nick_config_colors_cb (void *data, const char *option,
+ const char *value);
extern const char *irc_nick_find_color (const char *nickname);
extern const char *irc_nick_find_color_name (const char *nickname);
extern int irc_nick_is_op (struct t_irc_server *server,