summaryrefslogtreecommitdiff
path: root/src/plugins/buflist
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/buflist')
-rw-r--r--src/plugins/buflist/buflist-bar-item.c55
-rw-r--r--src/plugins/buflist/buflist-config.c6
-rw-r--r--src/plugins/buflist/buflist.c107
-rw-r--r--src/plugins/buflist/buflist.h6
4 files changed, 118 insertions, 56 deletions
diff --git a/src/plugins/buflist/buflist-bar-item.c b/src/plugins/buflist/buflist-bar-item.c
index 036b42f0b..46a275aed 100644
--- a/src/plugins/buflist/buflist-bar-item.c
+++ b/src/plugins/buflist/buflist-bar-item.c
@@ -52,18 +52,15 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
struct t_gui_buffer *ptr_buffer, *ptr_current_buffer;
struct t_gui_nick *ptr_gui_nick;
struct t_gui_hotlist *ptr_hotlist;
- struct t_hdata *hdata_irc_server, *hdata_irc_channel;
struct t_irc_server *ptr_server;
struct t_irc_channel *ptr_channel;
char **buflist, *str_buflist, *condition;
- char str_condition[512];
char str_format_number[32], str_format_number_empty[32];
char str_nick_prefix[32], str_color_nick_prefix[32];
char str_number[32], *line, **hotlist, *str_hotlist;
char str_hotlist_count[32];
const char *ptr_format, *ptr_format_current, *ptr_format_indent;
- const char *ptr_name, *ptr_type, *ptr_server_name, *ptr_channel_name;
- const char *ptr_nick, *ptr_nick_prefix;
+ const char *ptr_name, *ptr_type, *ptr_nick, *ptr_nick_prefix;
const char *ptr_hotlist_format, *ptr_hotlist_priority;
const char *hotlist_priority_none = "none";
const char *hotlist_priority[4] = { "low", "message", "private",
@@ -84,9 +81,6 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
prev_number = -1;
- hdata_irc_server = NULL;
- hdata_irc_channel = NULL;
-
buflist = weechat_string_dyn_alloc (256);
ptr_format = weechat_config_string (buflist_config_format_buffer);
@@ -122,52 +116,7 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
"buffer", ptr_buffer);
/* set IRC server/channel pointers */
- ptr_server = NULL;
- ptr_channel = NULL;
- if (strcmp (weechat_buffer_get_string (ptr_buffer, "plugin"), "irc") == 0)
- {
- ptr_server_name = weechat_buffer_get_string (ptr_buffer, "localvar_server");
- if (ptr_server_name && ptr_server_name[0])
- {
- if (!hdata_irc_server)
- hdata_irc_server = weechat_hdata_get ("irc_server");
- if (hdata_irc_server)
- {
- snprintf (str_condition, sizeof (str_condition),
- "${irc_server.name} == %s",
- ptr_server_name);
- ptr_server = weechat_hdata_get_list (hdata_irc_server,
- "irc_servers");
- ptr_server = weechat_hdata_search (hdata_irc_server,
- ptr_server,
- str_condition,
- 1);
- if (ptr_server)
- {
- ptr_channel_name = weechat_buffer_get_string (ptr_buffer,
- "localvar_channel");
- if (ptr_channel_name && ptr_channel_name[0])
- {
- if (!hdata_irc_channel)
- hdata_irc_channel = weechat_hdata_get ("irc_channel");
- if (hdata_irc_channel)
- {
- snprintf (str_condition, sizeof (str_condition),
- "${irc_channel.name} == %s",
- ptr_channel_name);
- ptr_channel = weechat_hdata_pointer (hdata_irc_server,
- ptr_server,
- "channels");
- ptr_channel = weechat_hdata_search (hdata_irc_channel,
- ptr_channel,
- str_condition,
- 1);
- }
- }
- }
- }
- }
- }
+ buflist_buffer_get_irc_pointers (ptr_buffer, &ptr_server, &ptr_channel);
weechat_hashtable_set (buflist_hashtable_pointers,
"irc_server", ptr_server);
weechat_hashtable_set (buflist_hashtable_pointers,
diff --git a/src/plugins/buflist/buflist-config.c b/src/plugins/buflist/buflist-config.c
index 9398b4d0e..87ca1f8c1 100644
--- a/src/plugins/buflist/buflist-config.c
+++ b/src/plugins/buflist/buflist-config.c
@@ -369,8 +369,10 @@ buflist_config_init ()
buflist_config_file, ptr_section,
"sort", "string",
N_("comma-separated list of fields to sort buffers; each field is "
- "a hdata variable of buffer; char \"-\" can be used before field "
- "to reverse order"),
+ "a hdata variable of buffer (\"var\"), a hdata variable of "
+ "IRC server (\"irc_server.var\") or a hdata variable of "
+ "IRC channel (\"irc_channel.var\"); "
+ "char \"-\" can be used before field to reverse order"),
NULL, 0, 0, "number,-active", NULL, 0,
NULL, NULL, NULL,
&buflist_config_change_sort, NULL, NULL,
diff --git a/src/plugins/buflist/buflist.c b/src/plugins/buflist/buflist.c
index 08d2889ff..891d9b25d 100644
--- a/src/plugins/buflist/buflist.c
+++ b/src/plugins/buflist/buflist.c
@@ -20,6 +20,7 @@
*/
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include "../weechat-plugin.h"
@@ -44,6 +45,78 @@ struct t_hdata *buflist_hdata_hotlist = NULL;
/*
+ * Get IRC server and channel pointers for a buffer.
+ *
+ * According to buffer:
+ * - non IRC buffer: both are NULL
+ * - IRC server/private: server is set, channel is NULL
+ * - IRC channel: server and channel are set
+ */
+
+void
+buflist_buffer_get_irc_pointers(struct t_gui_buffer *buffer,
+ struct t_irc_server **server,
+ struct t_irc_channel **channel)
+{
+ const char *ptr_server_name, *ptr_channel_name;
+ char str_condition[512];
+ struct t_hdata *hdata_irc_server, *hdata_irc_channel;
+
+ *server = NULL;
+ *channel = NULL;
+
+ /* check if the buffer belongs to IRC plugin */
+ if (strcmp (weechat_buffer_get_string (buffer, "plugin"), "irc") != 0)
+ return;
+
+ /* get server name from buffer local variable */
+ ptr_server_name = weechat_buffer_get_string (buffer, "localvar_server");
+ if (!ptr_server_name || !ptr_server_name[0])
+ return;
+
+ /* get hdata "irc_server" (can be NULL if irc plugin is not loaded) */
+ hdata_irc_server = weechat_hdata_get ("irc_server");
+ if (!hdata_irc_server)
+ return;
+
+ /* search the server by name in list of servers */
+ snprintf (str_condition, sizeof (str_condition),
+ "${irc_server.name} == %s",
+ ptr_server_name);
+ *server = weechat_hdata_get_list (hdata_irc_server,
+ "irc_servers");
+ *server = weechat_hdata_search (hdata_irc_server,
+ *server,
+ str_condition,
+ 1);
+ if (!*server)
+ return;
+
+ /* get channel name from buffer local variable */
+ ptr_channel_name = weechat_buffer_get_string (buffer,
+ "localvar_channel");
+ if (!ptr_channel_name || !ptr_channel_name[0])
+ return;
+
+ /* get hdata "irc_channel" (can be NULL if irc plugin is not loaded) */
+ hdata_irc_channel = weechat_hdata_get ("irc_channel");
+ if (!hdata_irc_channel)
+ return;
+
+ /* search the channel by name in list of channels on the server */
+ snprintf (str_condition, sizeof (str_condition),
+ "${irc_channel.name} == %s",
+ ptr_channel_name);
+ *channel = weechat_hdata_pointer (hdata_irc_server,
+ *server,
+ "channels");
+ *channel = weechat_hdata_search (hdata_irc_channel,
+ *channel,
+ str_condition,
+ 1);
+}
+
+/*
* Compares a hdata variable of two objects.
*
* Returns:
@@ -143,13 +216,20 @@ buflist_compare_buffers (void *data, struct t_arraylist *arraylist,
int i, reverse, rc;
const char *ptr_field;
struct t_gui_hotlist *ptr_hotlist1, *ptr_hotlist2;
+ struct t_irc_server *ptr_server1, *ptr_server2;
+ struct t_irc_channel *ptr_channel1, *ptr_channel2;
+ struct t_hdata *hdata_irc_server, *hdata_irc_channel;
/* make C compiler happy */
(void) data;
(void) arraylist;
+ hdata_irc_server = weechat_hdata_get ("irc_server");
+ hdata_irc_channel = weechat_hdata_get ("irc_channel");
+
for (i = 0; i < buflist_config_sort_fields_count; i++)
{
+ rc = 0;
reverse = 1;
if (buflist_config_sort_fields[i][0] == '-')
{
@@ -160,7 +240,6 @@ buflist_compare_buffers (void *data, struct t_arraylist *arraylist,
{
ptr_field = buflist_config_sort_fields[i];
}
- rc = 0;
if (strncmp (ptr_field, "hotlist.", 8) == 0)
{
ptr_hotlist1 = weechat_hdata_pointer (buflist_hdata_buffer,
@@ -180,6 +259,32 @@ buflist_compare_buffers (void *data, struct t_arraylist *arraylist,
ptr_field + 8);
}
}
+ else if (strncmp (ptr_field, "irc_server.", 11) == 0)
+ {
+ if (hdata_irc_server)
+ {
+ buflist_buffer_get_irc_pointers (pointer1,
+ &ptr_server1, &ptr_channel1);
+ buflist_buffer_get_irc_pointers (pointer2,
+ &ptr_server2, &ptr_channel2);
+ rc = buflist_compare_hdata_var (hdata_irc_server,
+ ptr_server1, ptr_server2,
+ ptr_field + 11);
+ }
+ }
+ else if (strncmp (ptr_field, "irc_channel.", 12) == 0)
+ {
+ if (hdata_irc_channel)
+ {
+ buflist_buffer_get_irc_pointers (pointer1,
+ &ptr_server1, &ptr_channel1);
+ buflist_buffer_get_irc_pointers (pointer2,
+ &ptr_server2, &ptr_channel2);
+ rc = buflist_compare_hdata_var (hdata_irc_channel,
+ ptr_channel1, ptr_channel2,
+ ptr_field + 12);
+ }
+ }
else
{
rc = buflist_compare_hdata_var (buflist_hdata_buffer,
diff --git a/src/plugins/buflist/buflist.h b/src/plugins/buflist/buflist.h
index 51af55c15..56a16d450 100644
--- a/src/plugins/buflist/buflist.h
+++ b/src/plugins/buflist/buflist.h
@@ -26,11 +26,17 @@
#define BUFLIST_BAR_NAME "buflist"
+struct t_irc_server;
+struct t_irc_channel;
+
extern struct t_weechat_plugin *weechat_buflist_plugin;
extern struct t_hdata *buflist_hdata_buffer;
extern struct t_hdata *buflist_hdata_hotlist;
+extern void buflist_buffer_get_irc_pointers(struct t_gui_buffer *buffer,
+ struct t_irc_server **server,
+ struct t_irc_channel **channel);
extern struct t_gui_hotlist *buflist_search_hotlist_for_buffer (struct t_gui_buffer *buffer);
extern struct t_arraylist *buflist_sort_buffers ();