summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2013-03-17 22:18:11 +0100
committerSebastien Helleu <flashcode@flashtux.org>2013-03-17 22:18:11 +0100
commitbbd080e6802b8fd6f442e8d8bbf41f45d0e86971 (patch)
tree857bc7bdbe64df3a4080119645f0ed64a8da3604 /src/plugins
parent3e1d811761887ca6c234e7b369febdf3d1710ae5 (diff)
downloadweechat-bbd080e6802b8fd6f442e8d8bbf41f45d0e86971.zip
irc: add option irc.look.pv_buffer: automatically merge private buffers (optionally by server) (task #11924)
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/irc/irc-buffer.c47
-rw-r--r--src/plugins/irc/irc-buffer.h3
-rw-r--r--src/plugins/irc/irc-channel.c19
-rw-r--r--src/plugins/irc/irc-config.c74
-rw-r--r--src/plugins/irc/irc-config.h8
-rw-r--r--src/plugins/irc/irc-server.c2
6 files changed, 146 insertions, 7 deletions
diff --git a/src/plugins/irc/irc-buffer.c b/src/plugins/irc/irc-buffer.c
index c29a1f050..24789ecc2 100644
--- a/src/plugins/irc/irc-buffer.c
+++ b/src/plugins/irc/irc-buffer.c
@@ -184,14 +184,13 @@ irc_buffer_nickcmp_cb (void *data,
}
/*
- * Searches for first server buffer that will be used to merge all IRC server
- * buffers.
+ * Searches for the server buffer with the lowest number.
*
* Returns pointer to buffer found, NULL if not found.
*/
struct t_gui_buffer *
-irc_buffer_search_first_for_all_servers ()
+irc_buffer_search_server_lowest_number ()
{
struct t_gui_buffer *ptr_buffer;
struct t_irc_server *ptr_server;
@@ -215,3 +214,45 @@ irc_buffer_search_first_for_all_servers ()
}
return ptr_buffer;
}
+
+/*
+ * Searches for the private buffer with the lowest number.
+ * If server is not NULL, searches only for this server.
+ *
+ * Returns pointer to buffer found, NULL if not found.
+ */
+
+struct t_gui_buffer *
+irc_buffer_search_private_lowest_number (struct t_irc_server *server)
+{
+ struct t_gui_buffer *ptr_buffer;
+ struct t_irc_server *ptr_server;
+ struct t_irc_channel *ptr_channel;
+ int number, number_found;
+
+ ptr_buffer = NULL;
+ number_found = INT_MAX;
+
+ for (ptr_server = (server) ? server : irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ for (ptr_channel = ptr_server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if ((ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE)
+ && ptr_channel->buffer)
+ {
+ number = weechat_buffer_get_integer (ptr_channel->buffer,
+ "number");
+ if (number < number_found)
+ {
+ number_found = number;
+ ptr_buffer = ptr_channel->buffer;
+ }
+ }
+ }
+ if (server)
+ break;
+ }
+ return ptr_buffer;
+}
diff --git a/src/plugins/irc/irc-buffer.h b/src/plugins/irc/irc-buffer.h
index 4ed76e6dc..c8204d1bd 100644
--- a/src/plugins/irc/irc-buffer.h
+++ b/src/plugins/irc/irc-buffer.h
@@ -57,6 +57,7 @@ extern int irc_buffer_nickcmp_cb (void *data,
struct t_gui_buffer *buffer,
const char *nick1,
const char *nick2);
-extern struct t_gui_buffer *irc_buffer_search_first_for_all_servers ();
+extern struct t_gui_buffer *irc_buffer_search_server_lowest_number ();
+extern struct t_gui_buffer *irc_buffer_search_private_lowest_number (struct t_irc_server *server);
#endif /* __WEECHAT_IRC_BUFFER_H */
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c
index 8e18bee04..7d2f518f8 100644
--- a/src/plugins/irc/irc-channel.c
+++ b/src/plugins/irc/irc-channel.c
@@ -151,7 +151,7 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
int auto_switch)
{
struct t_irc_channel *new_channel;
- struct t_gui_buffer *new_buffer;
+ struct t_gui_buffer *new_buffer, *ptr_buffer_for_merge;
int i, buffer_created, current_buffer_number, buffer_position, manual_join;
int noswitch;
char *buffer_name, str_number[32], str_group[32], *channel_name_lower;
@@ -174,6 +174,21 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
weechat_nicklist_remove_all (new_buffer);
else
{
+ ptr_buffer_for_merge = NULL;
+ if (channel_type == IRC_CHANNEL_TYPE_PRIVATE)
+ {
+ switch (weechat_config_integer (irc_config_look_pv_buffer))
+ {
+ case IRC_CONFIG_LOOK_PV_BUFFER_MERGE_BY_SERVER:
+ /* merge private buffers by server */
+ ptr_buffer_for_merge = irc_buffer_search_private_lowest_number (server);
+ break;
+ case IRC_CONFIG_LOOK_PV_BUFFER_MERGE_ALL:
+ /* merge *ALL* private buffers */
+ ptr_buffer_for_merge = irc_buffer_search_private_lowest_number (NULL);
+ break;
+ }
+ }
current_buffer_number = weechat_buffer_get_integer (weechat_current_buffer (),
"number");
new_buffer = weechat_buffer_new (buffer_name,
@@ -205,6 +220,8 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
irc_channel_move_near_server (server, channel_type, new_buffer);
break;
}
+ if (ptr_buffer_for_merge)
+ weechat_buffer_merge (new_buffer, ptr_buffer_for_merge);
}
buffer_created = 1;
}
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
index 97dd98214..cdadf97cd 100644
--- a/src/plugins/irc/irc-config.c
+++ b/src/plugins/irc/irc-config.c
@@ -56,6 +56,7 @@ struct t_config_option *irc_config_look_color_nicks_in_server_messages;
struct t_config_option *irc_config_look_color_pv_nick_like_channel;
struct t_config_option *irc_config_look_ctcp_time_format;
struct t_config_option *irc_config_look_server_buffer;
+struct t_config_option *irc_config_look_pv_buffer;
struct t_config_option *irc_config_look_new_channel_position;
struct t_config_option *irc_config_look_new_pv_position;
struct t_config_option *irc_config_look_nick_prefix;
@@ -305,7 +306,7 @@ irc_config_change_look_server_buffer (void *data,
ptr_buffer =
(weechat_config_integer (irc_config_look_server_buffer) ==
IRC_CONFIG_LOOK_SERVER_BUFFER_MERGE_WITH_CORE) ?
- weechat_buffer_search_main () : irc_buffer_search_first_for_all_servers ();
+ weechat_buffer_search_main () : irc_buffer_search_server_lowest_number ();
if (ptr_buffer)
{
@@ -320,6 +321,70 @@ irc_config_change_look_server_buffer (void *data,
}
/*
+ * Callback for changes on option "irc.look.pv_buffer".
+ */
+
+void
+irc_config_change_look_pv_buffer (void *data,
+ struct t_config_option *option)
+{
+ struct t_irc_server *ptr_server;
+ struct t_irc_channel *ptr_channel;
+ struct t_gui_buffer *ptr_buffer;
+
+ /* make C compiler happy */
+ (void) data;
+ (void) option;
+
+ /* first unmerge all IRC private buffers */
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ for (ptr_channel = ptr_server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if ((ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE)
+ && ptr_channel->buffer)
+ {
+ weechat_buffer_unmerge (ptr_channel->buffer, -1);
+ }
+ }
+ }
+
+ /* merge IRC private buffers */
+ if ((weechat_config_integer (irc_config_look_pv_buffer) == IRC_CONFIG_LOOK_PV_BUFFER_MERGE_BY_SERVER)
+ || (weechat_config_integer (irc_config_look_pv_buffer) == IRC_CONFIG_LOOK_PV_BUFFER_MERGE_ALL))
+ {
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ for (ptr_channel = ptr_server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if ((ptr_channel->type == IRC_CHANNEL_TYPE_PRIVATE)
+ && ptr_channel->buffer)
+ {
+ ptr_buffer = NULL;
+ switch (weechat_config_integer (irc_config_look_pv_buffer))
+ {
+ case IRC_CONFIG_LOOK_PV_BUFFER_MERGE_BY_SERVER:
+ /* merge private buffers by server */
+ ptr_buffer = irc_buffer_search_private_lowest_number (ptr_server);
+ break;
+ case IRC_CONFIG_LOOK_PV_BUFFER_MERGE_ALL:
+ /* merge *ALL* private buffers */
+ ptr_buffer = irc_buffer_search_private_lowest_number (NULL);
+ break;
+ }
+ if (ptr_buffer && (ptr_channel->buffer != ptr_buffer))
+ weechat_buffer_merge (ptr_channel->buffer, ptr_buffer);
+ }
+ }
+ }
+ }
+}
+
+/*
* Callback for changes on option "irc.look.item_away_message".
*/
@@ -2072,6 +2137,13 @@ irc_config_init ()
"merge_with_core|merge_without_core|independent", 0, 0, "merge_with_core",
NULL, 0, NULL, NULL,
&irc_config_change_look_server_buffer, NULL, NULL, NULL);
+ irc_config_look_pv_buffer = weechat_config_new_option (
+ irc_config_file, ptr_section,
+ "pv_buffer", "integer",
+ N_("merge private buffers"),
+ "independent|merge_by_server|merge_all", 0, 0, "independent",
+ NULL, 0, NULL, NULL,
+ &irc_config_change_look_pv_buffer, NULL, NULL, NULL);
irc_config_look_new_channel_position = weechat_config_new_option (
irc_config_file, ptr_section,
"new_channel_position", "integer",
diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h
index 47ea1bee6..9b28e2ed0 100644
--- a/src/plugins/irc/irc-config.h
+++ b/src/plugins/irc/irc-config.h
@@ -29,6 +29,13 @@ enum t_irc_config_look_server_buffer
IRC_CONFIG_LOOK_SERVER_BUFFER_INDEPENDENT,
};
+enum t_irc_config_look_pv_buffer
+{
+ IRC_CONFIG_LOOK_PV_BUFFER_INDEPENDENT = 0,
+ IRC_CONFIG_LOOK_PV_BUFFER_MERGE_BY_SERVER,
+ IRC_CONFIG_LOOK_PV_BUFFER_MERGE_ALL,
+};
+
enum t_irc_config_look_buffer_position
{
IRC_CONFIG_LOOK_BUFFER_POSITION_NONE = 0,
@@ -91,6 +98,7 @@ extern struct t_config_option *irc_config_look_color_nicks_in_server_messages;
extern struct t_config_option *irc_config_look_color_pv_nick_like_channel;
extern struct t_config_option *irc_config_look_ctcp_time_format;
extern struct t_config_option *irc_config_look_server_buffer;
+extern struct t_config_option *irc_config_look_pv_buffer;
extern struct t_config_option *irc_config_look_new_channel_position;
extern struct t_config_option *irc_config_look_new_pv_position;
extern struct t_config_option *irc_config_look_nick_prefix;
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index eb024e4fe..419d73565 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -3383,7 +3383,7 @@ irc_server_create_buffer (struct t_irc_server *server)
break;
case IRC_CONFIG_LOOK_SERVER_BUFFER_MERGE_WITHOUT_CORE:
/* find buffer used to merge all IRC server buffers */
- ptr_buffer_for_merge = irc_buffer_search_first_for_all_servers ();
+ ptr_buffer_for_merge = irc_buffer_search_server_lowest_number ();
break;
}