diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/command.c | 25 | ||||
-rw-r--r-- | src/common/weechat.c | 2 | ||||
-rw-r--r-- | src/common/weeconfig.c | 29 | ||||
-rw-r--r-- | src/common/weeconfig.h | 1 | ||||
-rw-r--r-- | src/gui/gui-common.c | 2 | ||||
-rw-r--r-- | src/gui/gui.h | 4 | ||||
-rw-r--r-- | src/irc/irc-channel.c | 131 | ||||
-rw-r--r-- | src/irc/irc-display.c | 4 | ||||
-rw-r--r-- | src/irc/irc-server.c | 14 | ||||
-rw-r--r-- | src/irc/irc.h | 6 |
10 files changed, 205 insertions, 13 deletions
diff --git a/src/common/command.c b/src/common/command.c index 123e77922..fa8d4bdcd 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -995,7 +995,8 @@ weechat_cmd_buffer (int argc, char **argv) (ptr_buffer->dcc) ? "DCC" : ((BUFFER_IS_SERVER(ptr_buffer)) ? SERVER(ptr_buffer)->name : CHANNEL(ptr_buffer)->name)); - if (ptr_buffer->dcc) + if ((!BUFFER_IS_CHANNEL(ptr_buffer)) + && (!BUFFER_IS_PRIVATE(ptr_buffer))) gui_printf (NULL, "-"); else gui_printf (NULL, "%d", ptr_buffer->notify_level); @@ -1010,22 +1011,34 @@ weechat_cmd_buffer (int argc, char **argv) number = strtol (argv[1], &error, 10); if ((error) && (error[0] == '\0')) { - if ((number < 0) || (number > 3)) + if ((number < NOTIFY_LEVEL_MIN) || (number > NOTIFY_LEVEL_MAX)) { /* invalid highlight level */ irc_display_prefix (NULL, PREFIX_ERROR); - gui_printf (NULL, _("%s incorrect notify level (must be between 0 and 3)\n"), + gui_printf (NULL, _("%s incorrect notify level (must be between %d and %d)\n"), + WEECHAT_ERROR, NOTIFY_LEVEL_MIN, NOTIFY_LEVEL_MAX); + return -1; + } + if ((!BUFFER_IS_CHANNEL(gui_current_window->buffer)) + && (!BUFFER_IS_PRIVATE(gui_current_window->buffer))) + { + /* invalid buffer type (only ok on channel or private) */ + irc_display_prefix (NULL, PREFIX_ERROR); + gui_printf (NULL, _("%s incorrect buffer for notify (must be channel or private)\n"), WEECHAT_ERROR); return -1; } gui_current_window->buffer->notify_level = number; + channel_set_notify_level (SERVER(gui_current_window->buffer), + CHANNEL(gui_current_window->buffer), + number); } else { /* invalid number */ irc_display_prefix (NULL, PREFIX_ERROR); - gui_printf (NULL, _("%s incorrect notify level (must be between 0 and 3)\n"), - WEECHAT_ERROR); + gui_printf (NULL, _("%s incorrect notify level (must be between %d and %d)\n"), + WEECHAT_ERROR, NOTIFY_LEVEL_MIN, NOTIFY_LEVEL_MAX); return -1; } } @@ -1841,7 +1854,7 @@ weechat_cmd_server (int argc, char **argv) 0, server.address, server.port, server.password, server.nick1, server.nick2, server.nick3, server.username, server.realname, - server.command, 1, server.autojoin, 1); + server.command, 1, server.autojoin, 1, NULL); if (new_server) { irc_display_prefix (NULL, PREFIX_INFO); diff --git a/src/common/weechat.c b/src/common/weechat.c index 1e45eda04..3b20f3d5a 100644 --- a/src/common/weechat.c +++ b/src/common/weechat.c @@ -371,7 +371,7 @@ wee_parse_args (int argc, char *argv[]) 1, server_tmp.address, server_tmp.port, server_tmp.password, server_tmp.nick1, server_tmp.nick2, server_tmp.nick3, - NULL, NULL, NULL, 0, server_tmp.autojoin, 1)) + NULL, NULL, NULL, 0, server_tmp.autojoin, 1, NULL)) fprintf (stderr, _("%s unable to create server ('%s'), ignored\n"), WEECHAT_WARNING, argv[i]); server_destroy (&server_tmp); diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c index 23a4c7a86..c51f29332 100644 --- a/src/common/weeconfig.c +++ b/src/common/weeconfig.c @@ -690,6 +690,10 @@ t_config_option weechat_options_server[] = N_("automatically rejoin channels when kicked"), 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,..)"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &(cfg_server.notify_levels), config_change_notify_levels }, { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; @@ -835,6 +839,23 @@ config_change_fifo_pipe () } /* + * config_change_notify_levels: called when notify levels is changed for a server + */ + +void +config_change_notify_levels () +{ + t_gui_buffer *ptr_buffer; + + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if (BUFFER_IS_CHANNEL(ptr_buffer) || BUFFER_IS_PRIVATE(ptr_buffer)) + ptr_buffer->notify_level = + channel_get_notify_level (SERVER(ptr_buffer), CHANNEL(ptr_buffer)); + } +} + +/* * config_option_set_value: set new value for an option * return: 0 if success * -1 if error (bad value) @@ -919,6 +940,8 @@ config_get_server_option_ptr (t_irc_server *server, char *option_name) return (void *)(&server->autojoin); if (strcasecmp (option_name, "server_autorejoin") == 0) return (void *)(&server->autorejoin); + if (strcasecmp (option_name, "server_notify_levels") == 0) + return (void *)(&server->notify_levels); /* option not found */ return NULL; } @@ -988,6 +1011,8 @@ config_set_server_value (t_irc_server *server, char *option_name, *((char **)ptr_data) = strdup (value); break; } + if (ptr_option->handler_change != NULL) + (void) (ptr_option->handler_change()); return 0; } @@ -1073,7 +1098,7 @@ config_allocate_server (char *filename, int line_number) cfg_server.password, cfg_server.nick1, cfg_server.nick2, cfg_server.nick3, cfg_server.username, cfg_server.realname, cfg_server.command, cfg_server.command_delay, cfg_server.autojoin, - cfg_server.autorejoin)) + cfg_server.autorejoin, cfg_server.notify_levels)) { server_free_all (); gui_printf (NULL, @@ -1661,6 +1686,8 @@ config_write (char *config_name) (ptr_server->autojoin) ? ptr_server->autojoin : ""); fprintf (file, "server_autorejoin=%s\n", (ptr_server->autorejoin) ? "on" : "off"); + fprintf (file, "server_notify_levels=%s\n", + (ptr_server->notify_levels) ? ptr_server->notify_levels : ""); } } diff --git a/src/common/weeconfig.h b/src/common/weeconfig.h index 186327a1e..016cc062e 100644 --- a/src/common/weeconfig.h +++ b/src/common/weeconfig.h @@ -193,6 +193,7 @@ extern void config_change_buffer_content (); extern void config_change_color (); extern void config_change_away_check (); extern void config_change_fifo_pipe (); +extern void config_change_notify_levels (); extern int config_option_set_value (t_config_option *, char *); extern t_config_option *config_option_search (char *); extern int config_set_value (char *, char *); diff --git a/src/gui/gui-common.c b/src/gui/gui-common.c index e1d9f9112..fb1446c86 100644 --- a/src/gui/gui-common.c +++ b/src/gui/gui-common.c @@ -186,7 +186,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int dcc, new_buffer->line_complete = 1; /* notify level */ - new_buffer->notify_level = 3; + new_buffer->notify_level = channel_get_notify_level (server, channel); /* create/append to log file */ new_buffer->log_filename = NULL; diff --git a/src/gui/gui.h b/src/gui/gui.h index d684f01ba..63d5ab50c 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -98,6 +98,10 @@ #define gui_printf_nolog(buffer, fmt, argz...) \ gui_printf_type_color(buffer, MSG_TYPE_INFO | MSG_TYPE_NOLOG, -1, fmt, ##argz) +#define NOTIFY_LEVEL_MIN 0 +#define NOTIFY_LEVEL_MAX 3 +#define NOTIFY_LEVEL_DEFAULT NOTIFY_LEVEL_MAX + typedef struct t_gui_message t_gui_message; struct t_gui_message diff --git a/src/irc/irc-channel.c b/src/irc/irc-channel.c index b7ffa3a5f..f17596ce5 100644 --- a/src/irc/irc-channel.c +++ b/src/irc/irc-channel.c @@ -30,6 +30,7 @@ #include "../common/weechat.h" #include "irc.h" +#include "../gui/gui.h" char *channel_modes = "iklmnst"; @@ -263,6 +264,136 @@ channel_remove_dcc (t_irc_dcc *ptr_dcc) } /* + * channel_get_notify_level: get channel notify level + */ + +int +channel_get_notify_level (t_irc_server *server, t_irc_channel *channel) +{ + char *name, *pos, *pos2, notify; + + if ((!server) || (!channel)) + return NOTIFY_LEVEL_DEFAULT; + + if ((!server->notify_levels) || (!server->notify_levels[0])) + return NOTIFY_LEVEL_DEFAULT; + + 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; + + pos2 = pos + strlen (channel->name); + if (pos2[0] != ':') + return NOTIFY_LEVEL_DEFAULT; + pos2++; + if (!pos2[0]) + return NOTIFY_LEVEL_DEFAULT; + + notify = (int)(pos2[0] - '0'); + if ((notify < NOTIFY_LEVEL_MIN) || (notify > NOTIFY_LEVEL_MAX)) + return NOTIFY_LEVEL_DEFAULT; + else + return notify; +} + +/* + * server_remove_notify_level: remove channel notify from list + */ + +void +channel_remove_notify_level (t_irc_server *server, t_irc_channel *channel) +{ + char *name, *pos, *pos2; + + if ((!server) || (!channel)) + return; + + name = (char *) malloc (strlen (channel->name) + 2); + strcpy (name, channel->name); + strcat (name, ":"); + pos = strstr (server->notify_levels, name); + free (name); + if (pos) + { + pos2 = pos + strlen (channel->name); + if (pos2[0] == ':') + { + pos2++; + if (pos2[0]) + { + pos2++; + if (pos2[0] == ',') + pos2++; + if (!pos2[0] && (pos != server->notify_levels)) + pos--; + strcpy (pos, pos2); + server->notify_levels = (char *) realloc (server->notify_levels, + strlen (server->notify_levels) + 1); + } + } + } +} + +/* + * server_set_notify_level: set channel notify level + */ + +void +channel_set_notify_level (t_irc_server *server, t_irc_channel *channel, int notify) +{ + char *name, *pos, *pos2, level_string[2]; + + if ((!server) || (!channel)) + return; + + if (notify == NOTIFY_LEVEL_DEFAULT) + { + channel_remove_notify_level (server, channel); + return; + } + + if (!server->notify_levels) + { + server->notify_levels = (char *) malloc (strlen (channel->name) + 3); + server->notify_levels[0] = '\0'; + } + else + { + name = (char *) malloc (strlen (channel->name) + 2); + strcpy (name, channel->name); + strcat (name, ":"); + pos = strstr (server->notify_levels, name); + free (name); + if (pos) + { + pos2 = pos + strlen (channel->name) + 1; + if (pos2[0]) + { + pos2[0] = '0' + notify; + return; + } + } + /* realloc notify list to add channel */ + server->notify_levels = (char *) realloc (server->notify_levels, + strlen (server->notify_levels) + 1 + + strlen (channel->name) + 2 + 1); + } + + /* channel not in notify list => add it */ + if (server->notify_levels[0]) + strcat (server->notify_levels, ","); + strcat (server->notify_levels, channel->name); + strcat (server->notify_levels, ":"); + level_string[0] = notify + '0'; + level_string[1] = '\0'; + strcat (server->notify_levels, level_string); +} + +/* * channel_print_log: print channel infos in log (usually for crash dump) */ diff --git a/src/irc/irc-display.c b/src/irc/irc-display.c index 4b5212fa3..1fd1e045c 100644 --- a/src/irc/irc-display.c +++ b/src/irc/irc-display.c @@ -202,4 +202,8 @@ irc_display_server (t_irc_server *server) " server_autojoin . . . . .: %s\n", (server->autojoin && server->autojoin[0]) ? server->autojoin : ""); + gui_printf_color (NULL, COLOR_WIN_CHAT, + " server_notify_levels . . .: %s\n", + (server->notify_levels && server->notify_levels[0]) ? + server->notify_levels : ""); } diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index ec7312739..e1cbf5453 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -77,6 +77,7 @@ server_init (t_irc_server *server) server->command_delay = 1; server->autojoin = NULL; server->autorejoin = 0; + server->notify_levels = NULL; /* internal vars */ server->child_pid = 0; @@ -256,6 +257,10 @@ server_destroy (t_irc_server *server) free (server->command); if (server->autojoin) free (server->autojoin); + if (server->notify_levels) + free (server->notify_levels); + if (server->unterminated_message) + free (server->unterminated_message); if (server->nick) free (server->nick); if (server->channels) @@ -315,7 +320,7 @@ server_new (char *name, int autoconnect, int autoreconnect, int autoreconnect_de int command_line, char *address, int port, char *password, char *nick1, char *nick2, char *nick3, char *username, char *realname, char *command, int command_delay, char *autojoin, - int autorejoin) + int autorejoin, char *notify_levels) { t_irc_server *new_server; @@ -325,12 +330,12 @@ server_new (char *name, int autoconnect, int autoreconnect, int autoreconnect_de #ifdef DEBUG wee_log_printf ("Creating new server (name:%s, address:%s, port:%d, pwd:%s, " "nick1:%s, nick2:%s, nick3:%s, username:%s, realname:%s, " - "command:%s, autojoin:%s, autorejoin:%s)\n", + "command:%s, autojoin:%s, autorejoin:%s, notify_levels:%s)\n", name, address, port, (password) ? password : "", (nick1) ? nick1 : "", (nick2) ? nick2 : "", (nick3) ? nick3 : "", (username) ? username : "", (realname) ? realname : "", (command) ? command : "", (autojoin) ? autojoin : "", - (autorejoin) ? "on" : "off"); + (autorejoin) ? "on" : "off", (notify_levels) ? notify_levels : ""); #endif if ((new_server = server_alloc ())) @@ -357,6 +362,8 @@ server_new (char *name, int autoconnect, int autoreconnect, int autoreconnect_de (autojoin) ? strdup (autojoin) : NULL; new_server->autorejoin = autorejoin; new_server->nick = strdup (new_server->nick1); + new_server->notify_levels = + (notify_levels) ? strdup (notify_levels) : NULL; } else return NULL; @@ -1155,6 +1162,7 @@ server_print_log (t_irc_server *server) wee_log_printf (" command_delay . . . : %d\n", server->command_delay); wee_log_printf (" autojoin. . . . . . : '%s'\n", server->autojoin); wee_log_printf (" autorejoin. . . . . : %d\n", server->autorejoin); + wee_log_printf (" notify_levels . . . : %s\n", server->notify_levels); wee_log_printf (" child_pid . . . . . : %d\n", server->child_pid); wee_log_printf (" child_read . . . . : %d\n", server->child_read); wee_log_printf (" child_write . . . . : %d\n", server->child_write); diff --git a/src/irc/irc.h b/src/irc/irc.h index 73da3e2d0..e397937d0 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -147,6 +147,7 @@ struct t_irc_server int command_delay; /* delay after execution of command */ char *autojoin; /* channels to automatically join */ int autorejoin; /* auto rejoin channels when kicked */ + char *notify_levels; /* channels notify levels */ /* internal vars */ pid_t child_pid; /* pid of child process (connecting) */ @@ -250,7 +251,7 @@ extern void server_free (t_irc_server *); extern void server_free_all (); extern t_irc_server *server_new (char *, int, int, int, int, char *, int, char *, char *, char *, char *, char *, char *, char *, - int, char *, int); + int, char *, int, char *); extern int server_send (t_irc_server *, char *, int); extern void server_sendf (t_irc_server *, char *, ...); extern void server_recv (t_irc_server *); @@ -280,6 +281,9 @@ extern void channel_check_away (t_irc_server *, t_irc_channel *); extern void channel_set_away (t_irc_channel *, char *, int); extern int channel_create_dcc (t_irc_dcc *); extern void channel_remove_dcc (t_irc_dcc *); +extern int channel_get_notify_level (t_irc_server *, t_irc_channel *); +extern void channel_remove_notify_level (t_irc_server *, t_irc_channel *); +extern void channel_set_notify_level (t_irc_server *, t_irc_channel *, int); extern void channel_print_log (t_irc_channel *); /* nick functions (irc-nick.c) */ |