1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-25 20:36:38 +02:00

Add new option irc.look.buffer_switch_autojoin, rename option irc.look.buffer_auto_switch_on_join to irc.look.buffer_switch_join (task #10506)

This commit is contained in:
Sebastien Helleu
2011-03-16 18:38:41 +01:00
parent 15121096d4
commit ea65e4d50f
23 changed files with 256 additions and 63 deletions
+34 -8
View File
@@ -150,8 +150,8 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
{
struct t_irc_channel *new_channel;
struct t_gui_buffer *new_buffer;
int i, buffer_created, current_buffer_number, buffer_position;
char *buffer_name, str_number[32], str_group[32];
int i, buffer_created, current_buffer_number, buffer_position, manual_join;
char *buffer_name, str_number[32], str_group[32], *channel_name_lower;
const char *prefix_modes;
/* alloc memory for new channel */
@@ -283,14 +283,40 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
server->channels = new_channel;
server->last_channel = new_channel;
if (switch_to_channel
&& ((channel_type != IRC_CHANNEL_TYPE_CHANNEL)
|| weechat_config_boolean (irc_config_look_buffer_auto_switch_on_join)))
manual_join = 0;
channel_name_lower = NULL;
if (channel_type == IRC_CHANNEL_TYPE_CHANNEL)
{
weechat_buffer_set (new_buffer, "display",
(auto_switch) ? "auto" : "1");
channel_name_lower = strdup (channel_name);
if (channel_name_lower)
{
weechat_string_tolower (channel_name_lower);
manual_join = weechat_hashtable_has_key (server->manual_joins,
channel_name_lower);
}
}
if (switch_to_channel)
{
if (channel_type == IRC_CHANNEL_TYPE_CHANNEL)
{
if ((manual_join && !weechat_config_boolean (irc_config_look_buffer_switch_join))
|| (!manual_join && !weechat_config_boolean (irc_config_look_buffer_switch_autojoin)))
switch_to_channel = 0;
}
if (switch_to_channel)
{
weechat_buffer_set (new_buffer, "display",
(auto_switch) ? "auto" : "1");
}
}
if (manual_join)
weechat_hashtable_remove (server->manual_joins, channel_name_lower);
if (channel_name_lower)
free (channel_name_lower);
weechat_hook_signal_send ((channel_type == IRC_CHANNEL_TYPE_CHANNEL) ?
"irc_channel_opened" : "irc_pv_opened",
WEECHAT_HOOK_SIGNAL_POINTER, new_buffer);
@@ -654,7 +680,7 @@ irc_channel_rejoin (struct t_irc_server *server, struct t_irc_channel *channel)
(channel->key) ? " " : "",
(channel->key) ? channel->key : "");
irc_command_join_server (server, join_args);
irc_command_join_server (server, join_args, 0);
}
/*
+40 -12
View File
@@ -1757,8 +1757,13 @@ irc_command_ison (void *data, struct t_gui_buffer *buffer, int argc,
*/
void
irc_command_join_server (struct t_irc_server *server, const char *arguments)
irc_command_join_server (struct t_irc_server *server, const char *arguments,
int manual_join)
{
char *args, **channels, *pos_space;
int i, length, num_channels;
int time_now;
if (server->sock < 0)
{
weechat_printf (NULL,
@@ -1766,19 +1771,42 @@ irc_command_join_server (struct t_irc_server *server, const char *arguments)
"connected irc server"),
weechat_prefix ("error"), IRC_PLUGIN_NAME,
"join");
return;
}
if (irc_channel_is_channel (arguments))
args = strdup (arguments);
else
{
if (irc_channel_is_channel (arguments))
length = 1 + strlen (arguments) + 1;
args = malloc (length);
if (args)
snprintf (args, length, "#%s", arguments);
}
if (args)
{
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
"JOIN %s", args);
if (manual_join)
{
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
"JOIN %s", arguments);
}
else
{
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
"JOIN #%s", arguments);
pos_space = strchr (args, ' ');
if (pos_space)
pos_space[0] = '\0';
channels = weechat_string_split (args, ",", 0, 0, &num_channels);
if (channels)
{
time_now = (int)time (NULL);
for (i = 0; i < num_channels; i++)
{
weechat_string_tolower (channels[i]);
weechat_hashtable_set (server->manual_joins,
channels[i],
&time_now);
}
weechat_string_free_split (channels);
}
}
free (args);
}
}
@@ -1802,13 +1830,13 @@ irc_command_join (void *data, struct t_gui_buffer *buffer, int argc,
ptr_server = irc_server_search (argv[2]);
if (!ptr_server)
return WEECHAT_RC_ERROR;
irc_command_join_server (ptr_server, argv_eol[3]);
irc_command_join_server (ptr_server, argv_eol[3], 1);
}
else
{
if (!ptr_server)
return WEECHAT_RC_ERROR;
irc_command_join_server (ptr_server, argv_eol[1]);
irc_command_join_server (ptr_server, argv_eol[1], 1);
}
}
else
@@ -1816,7 +1844,7 @@ irc_command_join (void *data, struct t_gui_buffer *buffer, int argc,
if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
&& !ptr_channel->nicks)
{
irc_command_join_server (ptr_server, ptr_channel->name);
irc_command_join_server (ptr_server, ptr_channel->name, 1);
}
else
{
+2 -1
View File
@@ -54,7 +54,8 @@ extern void irc_command_away_server (struct t_irc_server *server,
const char *arguments,
int reset_unread_marker);
extern void irc_command_join_server (struct t_irc_server *server,
const char *arguments);
const char *arguments,
int manual_join);
extern void irc_command_mode_server (struct t_irc_server *server,
struct t_irc_channel *channel,
const char *arguments);
+14 -5
View File
@@ -50,7 +50,8 @@ struct t_config_section *irc_config_section_server = NULL;
/* IRC config, look section */
struct t_config_option *irc_config_look_buffer_auto_switch_on_join;
struct t_config_option *irc_config_look_buffer_switch_autojoin;
struct t_config_option *irc_config_look_buffer_switch_join;
struct t_config_option *irc_config_look_color_nicks_in_names;
struct t_config_option *irc_config_look_color_nicks_in_nicklist;
struct t_config_option *irc_config_look_color_nicks_in_server_messages;
@@ -1793,11 +1794,19 @@ irc_config_init ()
weechat_config_free (irc_config_file);
return 0;
}
irc_config_look_buffer_auto_switch_on_join = weechat_config_new_option (
irc_config_look_buffer_switch_autojoin = weechat_config_new_option (
irc_config_file, ptr_section,
"buffer_auto_switch_on_join", "boolean",
N_("auto switch to channel buffer on join"),
"buffer_switch_autojoin", "boolean",
N_("auto switch to channel buffer when it is auto joined (with "
"server option \"autojoin\")"),
NULL, 0, 0, "on", NULL, 0, NULL, NULL,
NULL, NULL, NULL, NULL);
irc_config_look_buffer_switch_join = weechat_config_new_option (
irc_config_file, ptr_section,
"buffer_switch_join", "boolean",
N_("auto switch to channel buffer when it is manually joined "
"(with /join command)"),
NULL, 0, 0, "on", NULL, 0, NULL, NULL,
NULL, NULL, NULL, NULL);
irc_config_look_color_nicks_in_names = weechat_config_new_option (
+2 -1
View File
@@ -75,7 +75,8 @@ extern struct t_config_section *irc_config_section_ctcp;
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_buffer_auto_switch_on_join;
extern struct t_config_option *irc_config_look_buffer_switch_autojoin;
extern struct t_config_option *irc_config_look_buffer_switch_join;
extern struct t_config_option *irc_config_look_color_nicks_in_names;
extern struct t_config_option *irc_config_look_color_nicks_in_nicklist;
extern struct t_config_option *irc_config_look_color_nicks_in_server_messages;
+3 -3
View File
@@ -1258,14 +1258,14 @@ IRC_PROTOCOL_CALLBACK(part)
snprintf (join_string, join_length, "%s %s",
ptr_channel->name,
ptr_channel->key);
irc_command_join_server (server, join_string);
irc_command_join_server (server, join_string, 1);
free (join_string);
}
else
irc_command_join_server (server, ptr_channel->name);
irc_command_join_server (server, ptr_channel->name, 1);
}
else
irc_command_join_server (server, ptr_channel->name);
irc_command_join_server (server, ptr_channel->name, 1);
}
else
{
+43 -1
View File
@@ -98,6 +98,8 @@ char *irc_server_prefix_chars_default = "~&@%+-";
const char *irc_server_send_default_tags = NULL; /* default tags when */
/* sending a message */
time_t irc_server_last_check_manual_joins = 0;
void irc_server_reconnect (struct t_irc_server *server);
void irc_server_free_data (struct t_irc_server *server);
@@ -656,6 +658,11 @@ irc_server_alloc (const char *name)
new_server->last_redirect = NULL;
new_server->notify_list = NULL;
new_server->last_notify = NULL;
new_server->manual_joins = weechat_hashtable_new (4,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_INTEGER,
NULL,
NULL);
new_server->buffer = NULL;
new_server->buffer_as_string = NULL;
new_server->channels = NULL;
@@ -1095,6 +1102,7 @@ irc_server_free_data (struct t_irc_server *server)
irc_server_outqueue_free_all (server, i);
}
irc_notify_free_all (server);
weechat_hashtable_free (server->manual_joins);
irc_redirect_free_all (server);
if (server->channels)
irc_channel_free_all (server);
@@ -2186,6 +2194,26 @@ irc_server_timer_sasl_cb (void *data, int remaining_calls)
return WEECHAT_RC_OK;
}
/*
* irc_server_check_manual_joins_cb: callback called for each manual join of a
* server, it will delete old channels in
* this hashtable
*/
void
irc_server_check_manual_joins_cb (void *data, struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_irc_server *server;
server = (struct t_irc_server *)data;
if (server)
{
if (*((int *)value) + 60 < time (NULL))
weechat_hashtable_remove (hashtable, key);
}
}
/*
* irc_server_timer_cb: timer called each second to perform some operations
* on servers
@@ -2298,6 +2326,14 @@ irc_server_timer_cb (void *data, int remaining_calls)
ptr_redirect = ptr_next_redirect;
}
/* remove old channels in "manual_joins" (each 60 seconds) */
if (current_time > irc_server_last_check_manual_joins + 60)
{
weechat_hashtable_map (ptr_server->manual_joins,
&irc_server_check_manual_joins_cb,
ptr_server);
}
}
}
}
@@ -2374,6 +2410,9 @@ irc_server_close_connection (struct t_irc_server *server)
/* remove all redirects */
irc_redirect_free_all (server);
/* remove all manual joins */
weechat_hashtable_remove_all (server->manual_joins);
/* server is now disconnected */
server->is_connected = 0;
server->ssl_connected = 0;
@@ -3484,7 +3523,7 @@ irc_server_autojoin_channels (struct t_irc_server *server)
/* auto-join when connecting to server for first time */
autojoin = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN);
if (!server->disable_autojoin && autojoin && autojoin[0])
irc_command_join_server (server, autojoin);
irc_command_join_server (server, autojoin, 0);
}
server->disable_autojoin = 0;
@@ -4317,6 +4356,9 @@ irc_server_print_log ()
weechat_log_printf (" last_redirect. . . . : 0x%lx", ptr_server->last_redirect);
weechat_log_printf (" notify_list. . . . . : 0x%lx", ptr_server->notify_list);
weechat_log_printf (" last_notify. . . . . : 0x%lx", ptr_server->last_notify);
weechat_log_printf (" manual_joins . . . . : 0x%lx (hashtable: '%s')",
ptr_server->manual_joins,
weechat_hashtable_get_string (ptr_server->manual_joins, "keys_values"));
weechat_log_printf (" buffer . . . . . . . : 0x%lx", ptr_server->buffer);
weechat_log_printf (" buffer_as_string . . : 0x%lx", ptr_server->buffer_as_string);
weechat_log_printf (" channels . . . . . . : 0x%lx", ptr_server->channels);
+1
View File
@@ -176,6 +176,7 @@ struct t_irc_server
struct t_irc_redirect *last_redirect; /* last command redirection */
struct t_irc_notify *notify_list; /* list of notify */
struct t_irc_notify *last_notify; /* last notify */
struct t_hashtable *manual_joins; /* manual joins pending */
struct t_gui_buffer *buffer; /* GUI buffer allocated for server */
char *buffer_as_string; /* used to return buffer info */
struct t_irc_channel *channels; /* opened channels on server */