summaryrefslogtreecommitdiff
path: root/src/plugins/irc
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/irc')
-rw-r--r--src/plugins/irc/irc-bar-item.c71
-rw-r--r--src/plugins/irc/irc-channel.c350
-rw-r--r--src/plugins/irc/irc-channel.h8
-rw-r--r--src/plugins/irc/irc-command.c10
-rw-r--r--src/plugins/irc/irc-config.c18
-rw-r--r--src/plugins/irc/irc-config.h2
-rw-r--r--src/plugins/irc/irc-protocol.c2
-rw-r--r--src/plugins/irc/irc-server.c54
8 files changed, 391 insertions, 124 deletions
diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c
index f4dcf1d43..52bcb72fb 100644
--- a/src/plugins/irc/irc-bar-item.c
+++ b/src/plugins/irc/irc-bar-item.c
@@ -99,7 +99,7 @@ irc_bar_item_buffer_plugin (void *data, struct t_gui_bar_item *item,
{
char buf[512];
struct t_weechat_plugin *ptr_plugin;
- const char *name;
+ const char *name, *localvar_server, *localvar_channel;
struct t_irc_server *server;
struct t_irc_channel *channel;
@@ -112,29 +112,50 @@ irc_bar_item_buffer_plugin (void *data, struct t_gui_bar_item *item,
if (!buffer)
return NULL;
+ buf[0] = '\0';
+
ptr_plugin = weechat_buffer_get_pointer (buffer, "plugin");
name = weechat_plugin_get_name (ptr_plugin);
if (ptr_plugin == weechat_irc_plugin)
{
irc_buffer_get_server_and_channel (buffer, &server, &channel);
- if (server && channel
- && (weechat_config_integer (irc_config_look_item_display_server) == IRC_CONFIG_LOOK_ITEM_DISPLAY_SERVER_PLUGIN))
- {
- snprintf (buf, sizeof (buf), "%s%s/%s%s",
- name,
- IRC_COLOR_BAR_DELIM,
- IRC_COLOR_BAR_FG,
- server->name);
- }
- else
+ if (weechat_config_integer (irc_config_look_item_display_server) == IRC_CONFIG_LOOK_ITEM_DISPLAY_SERVER_PLUGIN)
{
- snprintf (buf, sizeof (buf), "%s", name);
+ if (server && channel)
+ {
+ snprintf (buf, sizeof (buf), "%s%s/%s%s",
+ name,
+ IRC_COLOR_BAR_DELIM,
+ IRC_COLOR_BAR_FG,
+ server->name);
+ }
+ else
+ {
+ localvar_server = weechat_buffer_get_string (buffer,
+ "localvar_server");
+ localvar_channel = weechat_buffer_get_string (buffer,
+ "localvar_channel");
+ if (localvar_server && localvar_channel)
+ {
+ server = irc_server_search (localvar_server);
+ if (server)
+ {
+ snprintf (buf, sizeof (buf), "%s%s/%s%s",
+ name,
+ IRC_COLOR_BAR_DELIM,
+ IRC_COLOR_BAR_FG,
+ server->name);
+ }
+ }
+ }
}
}
- else
+
+ if (!buf[0])
{
snprintf (buf, sizeof (buf), "%s", name);
}
+
return strdup (buf);
}
@@ -146,8 +167,8 @@ char *
irc_bar_item_buffer_name_content (struct t_gui_buffer *buffer, int short_name)
{
char buf[512], buf_name[256], modes[128];
- const char *name;
- int part_from_channel, display_server;
+ const char *name, *localvar_type;
+ int part_from_channel, display_server, is_channel;
struct t_irc_server *server;
struct t_irc_channel *channel;
@@ -197,7 +218,25 @@ irc_bar_item_buffer_name_content (struct t_gui_buffer *buffer, int short_name)
name = weechat_buffer_get_string (buffer,
(short_name) ? "short_name" : "name");
if (name)
- snprintf (buf_name, sizeof (buf_name), "%s", name);
+ {
+ localvar_type = weechat_buffer_get_string (buffer,
+ "localvar_type");
+ is_channel = (localvar_type
+ && (strcmp (localvar_type, "channel") == 0));
+ if (is_channel)
+ {
+ name = weechat_buffer_get_string (buffer,
+ "localvar_channel");
+ }
+ snprintf (buf_name, sizeof (buf_name),
+ "%s%s%s%s%s%s",
+ (is_channel) ? IRC_COLOR_BAR_DELIM : "",
+ (is_channel) ? "(" : "",
+ IRC_COLOR_STATUS_NAME,
+ name,
+ (is_channel) ? IRC_COLOR_BAR_DELIM : "",
+ (is_channel) ? ")" : "");
+ }
}
snprintf (buf, sizeof (buf), "%s%s%s",
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c
index 13ef73e80..fafc3fd88 100644
--- a/src/plugins/irc/irc-channel.c
+++ b/src/plugins/irc/irc-channel.c
@@ -140,37 +140,96 @@ irc_channel_move_near_server (struct t_irc_server *server, int channel_type,
}
/*
- * Creates a new channel in a server.
+ * Searches for a channel by name.
*
- * Returns pointer to new channel, NULL if error.
+ * Returns pointer to channel found, NULL if not found.
*/
struct t_irc_channel *
-irc_channel_new (struct t_irc_server *server, int channel_type,
- const char *channel_name, int switch_to_channel,
- int auto_switch)
+irc_channel_search (struct t_irc_server *server, const char *channel_name)
{
- struct t_irc_channel *new_channel;
- struct t_gui_buffer *new_buffer, *ptr_buffer_for_merge;
- int buffer_created, current_buffer_number, buffer_position, manual_join;
- int noswitch;
- char *buffer_name, str_number[32], *channel_name_lower;
+ struct t_irc_channel *ptr_channel;
- /* alloc memory for new channel */
- if ((new_channel = malloc (sizeof (*new_channel))) == NULL)
- {
- weechat_printf (NULL,
- _("%s%s: cannot allocate new channel"),
- weechat_prefix ("error"), IRC_PLUGIN_NAME);
+ if (!server || !channel_name)
return NULL;
+
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if (irc_server_strcasecmp (server, ptr_channel->name, channel_name) == 0)
+ return ptr_channel;
}
+ return NULL;
+}
+
+/*
+ * Searches for a channel buffer by channel name.
+ *
+ * Returns pointer to buffer found, NULL if not found.
+ */
+
+struct t_gui_buffer *
+irc_channel_search_buffer (struct t_irc_server *server,
+ const char *channel_name)
+{
+ struct t_hdata *hdata_buffer;
+ struct t_gui_buffer *ptr_buffer;
+ const char *ptr_server_name, *ptr_channel_name;
+
+ hdata_buffer = weechat_hdata_get ("buffer");
+ ptr_buffer = weechat_hdata_get_list (hdata_buffer, "gui_buffers");
+
+ while (ptr_buffer)
+ {
+ if (weechat_buffer_get_pointer (ptr_buffer,
+ "plugin") == weechat_irc_plugin)
+ {
+ ptr_server_name = weechat_buffer_get_string (ptr_buffer,
+ "localvar_server");
+ ptr_channel_name = weechat_buffer_get_string (ptr_buffer,
+ "localvar_channel");
+ if (ptr_server_name && ptr_server_name[0]
+ && ptr_channel_name && ptr_channel_name[0]
+ && (strcmp (ptr_server_name, server->name) == 0)
+ && ((irc_server_strcasecmp (server, ptr_channel_name,
+ channel_name) == 0)))
+ {
+ return ptr_buffer;
+ }
+ }
+
+ /* move to next buffer */
+ ptr_buffer = weechat_hdata_move (hdata_buffer, ptr_buffer, 1);
+ }
+
+ /* buffer not found */
+ return NULL;
+}
+
+/*
+ * Creates a buffer for a channel.
+ */
+
+struct t_gui_buffer *
+irc_channel_create_buffer (struct t_irc_server *server,
+ int channel_type,
+ const char *channel_name,
+ int switch_to_channel,
+ int auto_switch)
+{
+ struct t_gui_buffer *ptr_buffer, *ptr_buffer_for_merge;
+ int buffer_created, current_buffer_number, buffer_position;
+ int manual_join, noswitch;
+ char *buffer_name, str_number[32], *channel_name_lower;
+ const char *short_name, *localvar_channel;
- /* create buffer for channel (or use existing one) */
buffer_created = 0;
+
buffer_name = irc_buffer_build_name (server->name, channel_name);
- new_buffer = weechat_buffer_search (IRC_PLUGIN_NAME, buffer_name);
- if (new_buffer)
- weechat_nicklist_remove_all (new_buffer);
+
+ ptr_buffer = irc_channel_search_buffer (server, channel_name);
+ if (ptr_buffer)
+ weechat_nicklist_remove_all (ptr_buffer);
else
{
ptr_buffer_for_merge = NULL;
@@ -190,15 +249,14 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
}
current_buffer_number = weechat_buffer_get_integer (
weechat_current_buffer (), "number");
- new_buffer = weechat_buffer_new (buffer_name,
+
+ ptr_buffer = weechat_buffer_new (buffer_name,
&irc_input_data_cb, NULL,
&irc_buffer_close_cb, NULL);
- if (!new_buffer)
- {
- free (new_channel);
+ if (!ptr_buffer)
return NULL;
- }
- if (weechat_buffer_get_integer (new_buffer, "layout_number") < 1)
+
+ if (weechat_buffer_get_integer (ptr_buffer, "layout_number") < 1)
{
buffer_position = (channel_type == IRC_CHANNEL_TYPE_CHANNEL) ?
weechat_config_integer (irc_config_look_new_channel_position) :
@@ -212,50 +270,73 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
/* move buffer to current number + 1 */
snprintf (str_number, sizeof (str_number),
"%d", current_buffer_number + 1);
- weechat_buffer_set (new_buffer, "number", str_number);
+ weechat_buffer_set (ptr_buffer, "number", str_number);
break;
case IRC_CONFIG_LOOK_BUFFER_POSITION_NEAR_SERVER:
/* move buffer after last channel/pv of server */
irc_channel_move_near_server (server, channel_type,
- new_buffer);
+ ptr_buffer);
break;
}
if (ptr_buffer_for_merge)
- weechat_buffer_merge (new_buffer, ptr_buffer_for_merge);
+ weechat_buffer_merge (ptr_buffer, ptr_buffer_for_merge);
}
buffer_created = 1;
}
if (buffer_created)
{
- if (!weechat_buffer_get_integer (new_buffer, "short_name_is_set"))
- weechat_buffer_set (new_buffer, "short_name", channel_name);
- weechat_buffer_set (new_buffer, "localvar_set_type",
- (channel_type == IRC_CHANNEL_TYPE_CHANNEL) ? "channel" : "private");
- weechat_buffer_set (new_buffer, "localvar_set_nick", server->nick);
- weechat_buffer_set (new_buffer, "localvar_set_server", server->name);
- weechat_buffer_set (new_buffer, "localvar_set_channel", channel_name);
- if (server->is_away && server->away_message)
+ if (!weechat_buffer_get_integer (ptr_buffer, "short_name_is_set"))
+ weechat_buffer_set (ptr_buffer, "short_name", channel_name);
+ }
+ else
+ {
+ short_name = weechat_buffer_get_string (ptr_buffer, "short_name");
+ localvar_channel = weechat_buffer_get_string (ptr_buffer,
+ "localvar_channel");
+ if (!short_name
+ || (localvar_channel
+ && (strcmp (localvar_channel, short_name) == 0)))
{
- weechat_buffer_set (new_buffer, "localvar_set_away",
- server->away_message);
+ /* update the short_name only if it was not changed by the user */
+ weechat_buffer_set (ptr_buffer, "short_name", channel_name);
}
+ }
+
+ weechat_buffer_set (ptr_buffer, "name", buffer_name);
+ weechat_buffer_set (ptr_buffer, "localvar_set_type",
+ (channel_type == IRC_CHANNEL_TYPE_CHANNEL) ? "channel" : "private");
+ weechat_buffer_set (ptr_buffer, "localvar_set_nick", server->nick);
+ weechat_buffer_set (ptr_buffer, "localvar_set_server", server->name);
+ weechat_buffer_set (ptr_buffer, "localvar_set_channel", channel_name);
+ if (server->is_away && server->away_message)
+ {
+ weechat_buffer_set (ptr_buffer, "localvar_set_away",
+ server->away_message);
+ }
+ else
+ {
+ weechat_buffer_set (ptr_buffer, "localvar_del_away", "");
+ }
+
+ if (buffer_created)
+ {
(void) weechat_hook_signal_send ("logger_backlog",
WEECHAT_HOOK_SIGNAL_POINTER,
- new_buffer);
+ ptr_buffer);
if (weechat_config_boolean (irc_config_network_send_unknown_commands))
- weechat_buffer_set (new_buffer, "input_get_unknown_commands", "1");
+ weechat_buffer_set (ptr_buffer, "input_get_unknown_commands", "1");
if (channel_type == IRC_CHANNEL_TYPE_CHANNEL)
{
- weechat_buffer_set (new_buffer, "nicklist", "1");
- weechat_buffer_set (new_buffer, "nicklist_display_groups", "0");
- weechat_buffer_set_pointer (new_buffer, "nickcmp_callback",
+ weechat_buffer_set (ptr_buffer, "nicklist", "1");
+ weechat_buffer_set (ptr_buffer, "nicklist_display_groups", "0");
+ weechat_buffer_set_pointer (ptr_buffer, "nickcmp_callback",
&irc_buffer_nickcmp_cb);
}
/* set highlights settings on channel buffer */
weechat_buffer_set(
- new_buffer,
+ ptr_buffer,
"highlight_words_add",
(channel_type == IRC_CHANNEL_TYPE_CHANNEL) ?
weechat_config_string (irc_config_look_highlight_channel) :
@@ -264,10 +345,81 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
&& weechat_config_string (irc_config_look_highlight_tags_restrict)[0])
{
weechat_buffer_set (
- new_buffer,
+ ptr_buffer,
"highlight_tags_restrict",
weechat_config_string (irc_config_look_highlight_tags_restrict));
}
+
+ /* switch to new buffer (if needed) */
+ manual_join = 0;
+ noswitch = 0;
+ channel_name_lower = NULL;
+ if (channel_type == IRC_CHANNEL_TYPE_CHANNEL)
+ {
+ channel_name_lower = strdup (channel_name);
+ if (channel_name_lower)
+ {
+ weechat_string_tolower (channel_name_lower);
+ manual_join = weechat_hashtable_has_key (server->join_manual,
+ channel_name_lower);
+ noswitch = weechat_hashtable_has_key (server->join_noswitch,
+ channel_name_lower);
+ }
+ }
+ if (switch_to_channel)
+ {
+ if (channel_type == IRC_CHANNEL_TYPE_CHANNEL)
+ {
+ if (noswitch
+ || (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 (ptr_buffer, "display",
+ (auto_switch && !manual_join) ? "auto" : "1");
+ }
+ }
+ if (channel_name_lower)
+ {
+ weechat_hashtable_remove (server->join_manual, channel_name_lower);
+ weechat_hashtable_remove (server->join_noswitch, channel_name_lower);
+ free (channel_name_lower);
+ }
+ }
+
+ return ptr_buffer;
+}
+
+/*
+ * Creates a new channel in a server.
+ *
+ * Returns pointer to new channel, NULL if error.
+ */
+
+struct t_irc_channel *
+irc_channel_new (struct t_irc_server *server, int channel_type,
+ const char *channel_name, int switch_to_channel,
+ int auto_switch)
+{
+ struct t_irc_channel *new_channel;
+ struct t_gui_buffer *ptr_buffer;
+
+ /* create buffer for channel (or use existing one) */
+ ptr_buffer = irc_channel_create_buffer (server, channel_type,
+ channel_name, switch_to_channel,
+ auto_switch);
+ if (!ptr_buffer)
+ return NULL;
+
+ /* alloc memory for new channel */
+ if ((new_channel = malloc (sizeof (*new_channel))) == NULL)
+ {
+ weechat_printf (NULL,
+ _("%s%s: cannot allocate new channel"),
+ weechat_prefix ("error"), IRC_PLUGIN_NAME);
+ return NULL;
}
/* initialize new channel */
@@ -308,7 +460,7 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
new_channel->nicks_speaking_time = NULL;
new_channel->last_nick_speaking_time = NULL;
new_channel->join_smart_filtered = NULL;
- new_channel->buffer = new_buffer;
+ new_channel->buffer = ptr_buffer;
new_channel->buffer_as_string = NULL;
/* add new channel to channels list */
@@ -320,57 +472,62 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
server->channels = new_channel;
server->last_channel = new_channel;
- manual_join = 0;
- noswitch = 0;
- channel_name_lower = NULL;
- if (channel_type == IRC_CHANNEL_TYPE_CHANNEL)
+ (void) weechat_hook_signal_send (
+ (channel_type == IRC_CHANNEL_TYPE_CHANNEL) ?
+ "irc_channel_opened" : "irc_pv_opened",
+ WEECHAT_HOOK_SIGNAL_POINTER, ptr_buffer);
+
+ /* all is OK, return address of new channel */
+ return new_channel;
+}
+
+/*
+ * Renames a channel.
+ */
+
+void
+irc_channel_rename (struct t_irc_server *server,
+ struct t_irc_channel *channel,
+ const char *new_name)
+{
+ struct t_irc_channel *ptr_channel;
+ char *buffer_name;
+ const char *short_name;
+
+ /* check if another channel exists with this exact name */
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
{
- channel_name_lower = strdup (channel_name);
- if (channel_name_lower)
+ if ((ptr_channel != channel)
+ && (strcmp (ptr_channel->name, new_name) == 0))
{
- weechat_string_tolower (channel_name_lower);
- manual_join = weechat_hashtable_has_key (server->join_manual,
- channel_name_lower);
- noswitch = weechat_hashtable_has_key (server->join_noswitch,
- channel_name_lower);
+ return;
}
}
- if (switch_to_channel)
+ /* rename the channel in buffer */
+ if (channel->buffer)
{
- if (channel_type == IRC_CHANNEL_TYPE_CHANNEL)
+ short_name = weechat_buffer_get_string (channel->buffer, "short_name");
+ if (!short_name || (strcmp (short_name, channel->name) == 0))
{
- if (noswitch
- || (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;
+ /* update the short_name only if it was not changed by the user */
+ weechat_buffer_set (channel->buffer, "short_name", new_name);
}
-
- if (switch_to_channel)
- {
- weechat_buffer_set (new_buffer, "display",
- (auto_switch && !manual_join) ? "auto" : "1");
- }
- }
-
- if (channel_name_lower)
- {
- weechat_hashtable_remove (server->join_manual, channel_name_lower);
- weechat_hashtable_remove (server->join_noswitch, channel_name_lower);
- free (channel_name_lower);
+ buffer_name = irc_buffer_build_name (server->name,
+ new_name);
+ weechat_buffer_set (channel->buffer, "name", buffer_name);
+ weechat_buffer_set (channel->buffer, "localvar_set_channel", new_name);
}
- (void) weechat_hook_signal_send (
- (channel_type == IRC_CHANNEL_TYPE_CHANNEL) ?
- "irc_channel_opened" : "irc_pv_opened",
- WEECHAT_HOOK_SIGNAL_POINTER, new_buffer);
-
- /* all is OK, return address of new channel */
- return new_channel;
+ /* rename the irc channel */
+ if (channel->name)
+ free (channel->name);
+ channel->name = strdup (new_name);
}
/*
- * Add groups in nicklist for a channel.
+ * Adds groups in nicklist for a channel.
*/
void
@@ -446,29 +603,6 @@ irc_channel_set_modes (struct t_irc_channel *channel, const char *modes)
}
/*
- * Searches for a channel by name.
- *
- * Returns pointer to channel found, NULL if not found.
- */
-
-struct t_irc_channel *
-irc_channel_search (struct t_irc_server *server, const char *channel_name)
-{
- struct t_irc_channel *ptr_channel;
-
- if (!server || !channel_name)
- return NULL;
-
- for (ptr_channel = server->channels; ptr_channel;
- ptr_channel = ptr_channel->next_channel)
- {
- if (irc_server_strcasecmp (server, ptr_channel->name, channel_name) == 0)
- return ptr_channel;
- }
- return NULL;
-}
-
-/*
* Checks if a string is a valid channel name.
*
* Returns:
diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h
index 2d91e1907..3dbbe18a6 100644
--- a/src/plugins/irc/irc-channel.h
+++ b/src/plugins/irc/irc-channel.h
@@ -78,11 +78,19 @@ struct t_irc_channel
extern int irc_channel_valid (struct t_irc_server *server,
struct t_irc_channel *channel);
+extern struct t_gui_buffer *irc_channel_create_buffer (struct t_irc_server *server,
+ int channel_type,
+ const char *channel_name,
+ int switch_to_channel,
+ int auto_switch);
extern struct t_irc_channel *irc_channel_new (struct t_irc_server *server,
int channel_type,
const char *channel_name,
int switch_to_channel,
int auto_switch);
+extern void irc_channel_rename (struct t_irc_server *server,
+ struct t_irc_channel *channel,
+ const char *new_name);
extern void irc_channel_add_nicklist_groups (struct t_irc_server *server,
struct t_irc_channel *channel);
extern void irc_channel_set_buffer_title (struct t_irc_channel *channel);
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index 96e12d22d..07b816038 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -2298,6 +2298,16 @@ irc_command_join_server (struct t_irc_server *server, const char *arguments,
pos_channel, keys[i]);
}
}
+ if (manual_join
+ && weechat_config_boolean (irc_config_look_buffer_open_before_join))
+ {
+ /*
+ * open the channel buffer immediately (do not wait for the
+ * JOIN sent by server)
+ */
+ irc_channel_create_buffer (
+ server, IRC_CHANNEL_TYPE_CHANNEL, pos_channel, 1, 1);
+ }
}
if (pos_space)
strcat (new_args, pos_space);
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
index 3826f40d1..c41d0352f 100644
--- a/src/plugins/irc/irc-config.c
+++ b/src/plugins/irc/irc-config.c
@@ -48,6 +48,8 @@ struct t_config_section *irc_config_section_server = NULL;
/* IRC config, look section */
+struct t_config_option *irc_config_look_buffer_open_before_autojoin;
+struct t_config_option *irc_config_look_buffer_open_before_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;
@@ -2325,6 +2327,22 @@ irc_config_init ()
return 0;
}
+ irc_config_look_buffer_open_before_autojoin = weechat_config_new_option (
+ irc_config_file, ptr_section,
+ "buffer_open_before_autojoin", "boolean",
+ N_("open channel buffer before the JOIN is received from server "
+ "when it is auto joined (with server option \"autojoin\"); "
+ "this is useful to open channels with always the same buffer "
+ "numbers on startup"),
+ NULL, 0, 0, "on", NULL, 0, NULL, NULL,
+ NULL, NULL, NULL, NULL);
+ irc_config_look_buffer_open_before_join = weechat_config_new_option (
+ irc_config_file, ptr_section,
+ "buffer_open_before_join", "boolean",
+ N_("open channel buffer before the JOIN is received from server "
+ "when it is manually joined (with /join command)"),
+ NULL, 0, 0, "off", NULL, 0, NULL, NULL,
+ NULL, NULL, NULL, NULL);
irc_config_look_buffer_switch_autojoin = weechat_config_new_option (
irc_config_file, ptr_section,
"buffer_switch_autojoin", "boolean",
diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h
index 75dd374fd..85218b908 100644
--- a/src/plugins/irc/irc-config.h
+++ b/src/plugins/irc/irc-config.h
@@ -96,6 +96,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_open_before_autojoin;
+extern struct t_config_option *irc_config_look_buffer_open_before_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;
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 3e37e6bc6..c01f12464 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -665,6 +665,8 @@ IRC_PROTOCOL_CALLBACK(join)
if (ptr_channel)
{
ptr_channel->part = 0;
+ if (strcmp (ptr_channel->name, pos_channel) != 0)
+ irc_channel_rename (server, ptr_channel, pos_channel);
}
else
{
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 6016b7da0..2061be3ed 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -127,6 +127,7 @@ const char *irc_server_send_default_tags = NULL; /* default tags when */
void irc_server_reconnect (struct t_irc_server *server);
void irc_server_free_data (struct t_irc_server *server);
+void irc_server_autojoin_create_buffers (struct t_irc_server *server);
/*
@@ -4292,6 +4293,10 @@ irc_server_connect (struct t_irc_server *server)
/* close connection if opened */
irc_server_close_connection (server);
+ /* open auto-joined channels now (if needed) */
+ if (weechat_config_boolean (irc_config_look_buffer_open_before_autojoin))
+ irc_server_autojoin_create_buffers (server);
+
/* init SSL if asked and connect */
server->ssl_connected = 0;
#ifdef HAVE_GNUTLS
@@ -4484,6 +4489,55 @@ irc_server_disconnect_all ()
}
/*
+ * Creates buffers for auto-joined channels on a server.
+ */
+
+void
+irc_server_autojoin_create_buffers (struct t_irc_server *server)
+{
+ const char *pos_space;
+ char *autojoin, *autojoin2, **channels;
+ int num_channels, i;
+
+ /* buffers are opened only if no channels are currently opened */
+ if (server->channels)
+ return;
+
+ /* evaluate server option "autojoin" */
+ autojoin = weechat_string_eval_expression (
+ IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN),
+ NULL, NULL, NULL);
+
+ /* extract channel names from autojoin option */
+ if (autojoin && autojoin[0])
+ {
+ pos_space = strchr (autojoin, ' ');
+ autojoin2 = (pos_space) ?
+ weechat_strndup (autojoin, pos_space - autojoin) :
+ strdup (autojoin);
+ if (autojoin2)
+ {
+ channels = weechat_string_split (autojoin2, ",", 0, 0,
+ &num_channels);
+ if (channels)
+ {
+ for (i = 0; i < num_channels; i++)
+ {
+ irc_channel_create_buffer (
+ server, IRC_CHANNEL_TYPE_CHANNEL, channels[i],
+ 1, 1);
+ }
+ weechat_string_free_split (channels);
+ }
+ free (autojoin2);
+ }
+ }
+
+ if (autojoin)
+ free (autojoin);
+}
+
+/*
* Autojoins (or auto-rejoins) channels.
*/