diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2006-08-25 16:30:10 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2006-08-25 16:30:10 +0000 |
commit | 00fbd7ad56d4520bac6d7b8240ebf7148e2bc73f (patch) | |
tree | 22aab2893a586b17fd2e7e8ea7e7acb234aea001 /src | |
parent | 77e3fb3c8312031572e6aa6d1962a9bb3faf68b8 (diff) | |
download | weechat-00fbd7ad56d4520bac6d7b8240ebf7148e2bc73f.zip |
Added server default notify level (task #5634), fixed crashs with /buffer and /charset commands when not connected to any server (bug #17525)
Diffstat (limited to 'src')
-rw-r--r-- | src/common/command.c | 159 | ||||
-rw-r--r-- | src/common/weeconfig.c | 4 | ||||
-rw-r--r-- | src/irc/irc-channel.c | 27 | ||||
-rw-r--r-- | src/irc/irc-server.c | 47 | ||||
-rw-r--r-- | src/irc/irc.h | 2 |
5 files changed, 166 insertions, 73 deletions
diff --git a/src/common/command.c b/src/common/command.c index 8b6c311c6..7e109784a 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -65,7 +65,8 @@ t_weechat_command weechat_commands[] = " close: close buffer (optional arg is part message, for a channel)\n" " list: list open buffers (no parameter implies this list)\n" " notify: set notify level for buffer (0=never, 1=highlight, 2=1+msg, 3=2+join/part)\n" - "server\n" + " (when executed on server buffer, this sets default notify level for whole server)\n" + "server,\n" "channel: jump to buffer by server and/or channel name\n" " number: jump to buffer by number"), "move|close|list|notify", 0, MAX_ARGS, 0, NULL, weechat_cmd_buffer }, @@ -1003,7 +1004,7 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, t_irc_channel *ptr_channel; long number; char *error, *pos, **argv; - int argc, target_buffer; + int argc, target_buffer, count; irc_find_context (server, channel, &window, &buffer); @@ -1083,31 +1084,34 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, } if (BUFFER_IS_SERVER(buffer)) { - if (SERVER(buffer)->channels) - { - irc_display_prefix (NULL, NULL, PREFIX_ERROR); - gui_printf (NULL, - _("%s can not close server buffer while channels " - "are open\n"), - WEECHAT_ERROR); - free_exploded_string (argv); - return -1; - } - server_disconnect (SERVER(buffer), 0); - ptr_server = SERVER(buffer); - if (!buffer->all_servers) - { - gui_buffer_free (buffer, 1); - ptr_server->buffer = NULL; - } - else + if (SERVER(buffer)) { - ptr_server->buffer = NULL; - buffer->server = NULL; - gui_window_switch_server (window); + if (SERVER(buffer)->channels) + { + irc_display_prefix (NULL, NULL, PREFIX_ERROR); + gui_printf (NULL, + _("%s can not close server buffer while channels " + "are open\n"), + WEECHAT_ERROR); + free_exploded_string (argv); + return -1; + } + server_disconnect (SERVER(buffer), 0); + ptr_server = SERVER(buffer); + if (!buffer->all_servers) + { + gui_buffer_free (buffer, 1); + ptr_server->buffer = NULL; + } + else + { + ptr_server->buffer = NULL; + buffer->server = NULL; + gui_window_switch_server (window); + } + gui_status_draw (gui_current_window->buffer, 1); + gui_input_draw (gui_current_window->buffer, 1); } - gui_status_draw (gui_current_window->buffer, 1); - gui_input_draw (gui_current_window->buffer, 1); } else { @@ -1157,24 +1161,42 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, { if (argc < 2) { - /* display notify level for all buffers */ gui_printf (NULL, "\n"); - gui_printf (NULL, _("Notify levels: ")); - for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + + /* display default notify level for all connected servers */ + gui_printf (NULL, _("Default notify levels for servers:")); + count = 0; + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) { - gui_printf (NULL, "%d.%s:", + if (ptr_server->buffer) + { + gui_printf (NULL, " %s:%d", + ptr_server->name, + server_get_default_notify_level (ptr_server)); + count++; + } + } + if (count == 0) + gui_printf (NULL, " -"); + gui_printf (NULL, "\n"); + + /* display notify level for all buffers */ + gui_printf (NULL, _("Notify levels:")); + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + gui_printf (NULL, " %d.%s:", ptr_buffer->number, (ptr_buffer->type == BUFFER_TYPE_DCC) ? "DCC" : ((ptr_buffer->type == BUFFER_TYPE_RAW_DATA) ? _("Raw IRC data") : - ((BUFFER_IS_SERVER(ptr_buffer)) ? SERVER(ptr_buffer)->name : - CHANNEL(ptr_buffer)->name))); + ((BUFFER_IS_SERVER(ptr_buffer) && SERVER(ptr_buffer)) ? SERVER(ptr_buffer)->name : + ((CHANNEL(ptr_buffer)) ? (CHANNEL(ptr_buffer)->name) : "-")))); if ((!BUFFER_IS_CHANNEL(ptr_buffer)) && (!BUFFER_IS_PRIVATE(ptr_buffer))) gui_printf (NULL, "-"); else gui_printf (NULL, "%d", ptr_buffer->notify_level); - if (ptr_buffer->next_buffer) - gui_printf (NULL, " "); } gui_printf (NULL, "\n"); } @@ -1194,28 +1216,47 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, free_exploded_string (argv); return -1; } - if ((!BUFFER_IS_CHANNEL(buffer)) - && (!BUFFER_IS_PRIVATE(buffer))) + if (!SERVER(buffer) + || ((!BUFFER_IS_SERVER(buffer)) + && (!BUFFER_IS_CHANNEL(buffer)) + && (!BUFFER_IS_PRIVATE(buffer)))) { - /* invalid buffer type (only ok on channel or private) */ + /* invalid buffer type (only ok on server, channel or private) */ irc_display_prefix (NULL, NULL, PREFIX_ERROR); - gui_printf (NULL, _("%s incorrect buffer for notify (must be channel or private)\n"), + gui_printf (NULL, + _("%s incorrect buffer for notify " + "(must be server, channel or private)\n"), WEECHAT_ERROR); free_exploded_string (argv); return -1; } - buffer->notify_level = number; - channel_set_notify_level (SERVER(buffer), - CHANNEL(buffer), - number); - irc_display_prefix (NULL, NULL, PREFIX_INFO); - gui_printf (NULL, _("New notify level for %s%s%s: %s%d %s"), - GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), - CHANNEL(buffer)->name, - GUI_COLOR(COLOR_WIN_CHAT), - GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), - number, - GUI_COLOR(COLOR_WIN_CHAT)); + if (BUFFER_IS_SERVER(buffer)) + { + server_set_default_notify_level (SERVER(buffer), + number); + irc_display_prefix (NULL, NULL, PREFIX_INFO); + gui_printf (NULL, _("New default notify level for server %s%s%s: %s%d %s"), + GUI_COLOR(COLOR_WIN_CHAT_SERVER), + SERVER(buffer)->name, + GUI_COLOR(COLOR_WIN_CHAT), + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + number, + GUI_COLOR(COLOR_WIN_CHAT)); + } + else + { + channel_set_notify_level (SERVER(buffer), + CHANNEL(buffer), + number); + irc_display_prefix (NULL, NULL, PREFIX_INFO); + gui_printf (NULL, _("New notify level for %s%s%s: %s%d %s"), + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + CHANNEL(buffer)->name, + GUI_COLOR(COLOR_WIN_CHAT), + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + number, + GUI_COLOR(COLOR_WIN_CHAT)); + } switch (number) { case 0: @@ -1234,6 +1275,7 @@ weechat_cmd_buffer (t_irc_server *server, t_irc_channel *channel, gui_printf (NULL, "\n"); break; } + config_change_notify_levels (); } else { @@ -1353,9 +1395,9 @@ weechat_cmd_charset_display (t_gui_buffer *buffer) char *value, *string, *herited; int length; - if (BUFFER_IS_SERVER(buffer) || - BUFFER_IS_CHANNEL(buffer) || - BUFFER_IS_PRIVATE(buffer)) + if ((BUFFER_IS_SERVER(buffer) && (SERVER(buffer))) + || BUFFER_IS_CHANNEL(buffer) + || BUFFER_IS_PRIVATE(buffer)) { if (BUFFER_IS_SERVER(buffer)) { @@ -1504,11 +1546,14 @@ weechat_cmd_charset_set (t_gui_buffer *buffer, char **string, char *charset, } if (BUFFER_IS_SERVER(buffer)) { - if (charset) - config_option_list_set (string, "server", charset); - else - config_option_list_remove (string, "server"); - weechat_cmd_charset_display (buffer); + if (SERVER(buffer)) + { + if (charset) + config_option_list_set (string, "server", charset); + else + config_option_list_remove (string, "server"); + weechat_cmd_charset_display (buffer); + } } else if (BUFFER_IS_CHANNEL(buffer) || BUFFER_IS_PRIVATE(buffer)) diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c index c04265f33..08b293a45 100644 --- a/src/common/weeconfig.c +++ b/src/common/weeconfig.c @@ -1026,7 +1026,9 @@ t_config_option weechat_options_server[] = OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_TRUE, NULL, NULL, &(cfg_server.autorejoin), NULL, NULL }, { "server_notify_levels", N_("notify levels for channels of this server"), - N_("comma separated list of notify levels for channels of this server (format: #channel:1,..)"), + N_("comma separated list of notify levels for channels of this server " + "(format: #channel:1,..), a channel name '*' is reserved for server " + "default notify level"), OPTION_TYPE_STRING, 0, 0, 0, "", NULL, NULL, &(cfg_server.notify_levels), config_change_notify_levels }, { "server_charset_decode_iso", N_("charset for decoding ISO on server and channels"), diff --git a/src/irc/irc-channel.c b/src/irc/irc-channel.c index 63f0849eb..117c549f3 100644 --- a/src/irc/irc-channel.c +++ b/src/irc/irc-channel.c @@ -488,7 +488,7 @@ int channel_get_notify_level (t_irc_server *server, t_irc_channel *channel) { char *name, *pos, *pos2; - int notify; + int server_default_notify, notify; if ((!server) || (!channel)) return NOTIFY_LEVEL_DEFAULT; @@ -496,26 +496,28 @@ channel_get_notify_level (t_irc_server *server, t_irc_channel *channel) if ((!server->notify_levels) || (!server->notify_levels[0])) return NOTIFY_LEVEL_DEFAULT; + server_default_notify = server_get_default_notify_level (server); + name = (char *) malloc (strlen (channel->name) + 2); strcpy (name, channel->name); strcat (name, ":"); pos = strstr (server->notify_levels, name); free (name); if (!pos) - return NOTIFY_LEVEL_DEFAULT; + return server_default_notify; pos2 = pos + strlen (channel->name); if (pos2[0] != ':') - return NOTIFY_LEVEL_DEFAULT; + return server_default_notify; pos2++; if (!pos2[0]) - return NOTIFY_LEVEL_DEFAULT; + return server_default_notify; notify = (int)(pos2[0] - '0'); - if ((notify < NOTIFY_LEVEL_MIN) || (notify > NOTIFY_LEVEL_MAX)) - return NOTIFY_LEVEL_DEFAULT; - else + if ((notify >= NOTIFY_LEVEL_MIN) && (notify <= NOTIFY_LEVEL_MAX)) return notify; + + return server_default_notify; } /* @@ -530,14 +532,9 @@ channel_set_notify_level (t_irc_server *server, t_irc_channel *channel, int noti if ((!server) || (!channel)) return; - if (notify == NOTIFY_LEVEL_DEFAULT) - config_option_list_remove (&(server->notify_levels), channel->name); - else - { - level_string[0] = notify + '0'; - level_string[1] = '\0'; - config_option_list_set (&(server->notify_levels), channel->name, level_string); - } + level_string[0] = notify + '0'; + level_string[1] = '\0'; + config_option_list_set (&(server->notify_levels), channel->name, level_string); } /* diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index 498cdc09e..0df519975 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -1936,6 +1936,53 @@ server_set_away (t_irc_server *server, char *nick, int is_away) } /* + * server_get_default_notify_level: get default notify level for server + */ + +int +server_get_default_notify_level (t_irc_server *server) +{ + int notify, value; + char *pos; + + notify = NOTIFY_LEVEL_DEFAULT; + + if (!server) + return notify; + + pos = strstr (server->notify_levels, "*:"); + if (pos) + { + pos += 2; + if (pos[0]) + { + value = (int)(pos[0] - '0'); + if ((value >= NOTIFY_LEVEL_MIN) && (value <= NOTIFY_LEVEL_MAX)) + notify = value; + } + } + + return notify; +} + +/* + * server_set_default_notify_level: set default notify level for server + */ + +void +server_set_default_notify_level (t_irc_server *server, int notify) +{ + char level_string[2]; + + if (server) + { + level_string[0] = notify + '0'; + level_string[1] = '\0'; + config_option_list_set (&(server->notify_levels), "*", level_string); + } +} + +/* * server_print_log: print server infos in log (usually for crash dump) */ diff --git a/src/irc/irc.h b/src/irc/irc.h index 3b1469046..454834c3c 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -355,6 +355,8 @@ extern int server_name_already_exists (char *); extern void server_remove_away (); extern void server_check_away (); extern void server_set_away (t_irc_server *, char *, int); +extern int server_get_default_notify_level (t_irc_server *); +extern void server_set_default_notify_level (t_irc_server *, int); extern void server_print_log (t_irc_server *); /* proxy functions (irc-server.c) */ |