summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-05-20 16:30:32 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-05-20 17:08:28 +0200
commit00f4ae760d03cd5d1781e940d95b46d707e72585 (patch)
treeafdaea0f9a26a1a65c464dabff0e32d7bca0c636 /src
parent1ad45598b5db3b639047f69d3e95ce84a59db100 (diff)
downloadweechat-00f4ae760d03cd5d1781e940d95b46d707e72585.zip
relay: create buffers with function buffer_new_props (issue #1942)
With this function, buffer properties are set when the buffer is created and can be read immediately by other plugins/scripts, for example in a callback of signal "buffer_opened".
Diffstat (limited to 'src')
-rw-r--r--src/plugins/relay/relay-buffer.c40
-rw-r--r--src/plugins/relay/relay-raw.c36
2 files changed, 51 insertions, 25 deletions
diff --git a/src/plugins/relay/relay-buffer.c b/src/plugins/relay/relay-buffer.c
index aa72d80a8..191f076cf 100644
--- a/src/plugins/relay/relay-buffer.c
+++ b/src/plugins/relay/relay-buffer.c
@@ -245,20 +245,32 @@ relay_buffer_close_cb (const void *pointer, void *data,
void
relay_buffer_open ()
{
- if (!relay_buffer)
+ struct t_hashtable *buffer_props;
+
+ if (relay_buffer)
+ return;
+
+ buffer_props = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (buffer_props)
{
- relay_buffer = weechat_buffer_new (RELAY_BUFFER_NAME,
- &relay_buffer_input_cb, NULL, NULL,
- &relay_buffer_close_cb, NULL, NULL);
-
- /* failed to create buffer ? then exit */
- if (!relay_buffer)
- return;
-
- weechat_buffer_set (relay_buffer, "type", "free");
- weechat_buffer_set (relay_buffer, "title", _("List of clients for relay"));
- weechat_buffer_set (relay_buffer, "key_bind_up", "/relay up");
- weechat_buffer_set (relay_buffer, "key_bind_down", "/relay down");
- weechat_buffer_set (relay_buffer, "localvar_set_type", "relay");
+ weechat_hashtable_set (buffer_props, "type", "free");
+ weechat_hashtable_set (buffer_props,
+ "title", _("List of clients for relay"));
+ weechat_hashtable_set (buffer_props, "key_bind_up", "/relay up");
+ weechat_hashtable_set (buffer_props, "key_bind_down", "/relay down");
+ weechat_hashtable_set (buffer_props, "localvar_set_type", "relay");
}
+
+ relay_buffer = weechat_buffer_new_props (
+ RELAY_BUFFER_NAME,
+ buffer_props,
+ &relay_buffer_input_cb, NULL, NULL,
+ &relay_buffer_close_cb, NULL, NULL);
+
+ if (buffer_props)
+ weechat_hashtable_free (buffer_props);
}
diff --git a/src/plugins/relay/relay-raw.c b/src/plugins/relay/relay-raw.c
index c73357ce7..cca3a6d0a 100644
--- a/src/plugins/relay/relay-raw.c
+++ b/src/plugins/relay/relay-raw.c
@@ -65,6 +65,7 @@ void
relay_raw_open (int switch_to_buffer)
{
struct t_relay_raw_message *ptr_raw_message;
+ struct t_hashtable *buffer_props;
if (!relay_raw_buffer)
{
@@ -72,30 +73,43 @@ relay_raw_open (int switch_to_buffer)
RELAY_RAW_BUFFER_NAME);
if (!relay_raw_buffer)
{
- relay_raw_buffer = weechat_buffer_new (
+ buffer_props = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ if (buffer_props)
+ {
+ weechat_hashtable_set (buffer_props,
+ "title", _("Relay raw messages"));
+ weechat_hashtable_set (buffer_props,
+ "localvar_set_type", "debug");
+ weechat_hashtable_set (buffer_props,
+ "localvar_set_server", RELAY_RAW_BUFFER_NAME);
+ weechat_hashtable_set (buffer_props,
+ "localvar_set_channel", RELAY_RAW_BUFFER_NAME);
+ weechat_hashtable_set (buffer_props,
+ "localvar_set_no_log", "1");
+ /* disable all highlights on this buffer */
+ weechat_hashtable_set (buffer_props, "highlight_words", "-");
+ }
+ relay_raw_buffer = weechat_buffer_new_props (
RELAY_RAW_BUFFER_NAME,
+ buffer_props,
&relay_buffer_input_cb, NULL, NULL,
&relay_buffer_close_cb, NULL, NULL);
+ if (buffer_props)
+ weechat_hashtable_free (buffer_props);
/* failed to create buffer ? then return */
if (!relay_raw_buffer)
return;
- weechat_buffer_set (relay_raw_buffer,
- "title", _("Relay raw messages"));
-
if (!weechat_buffer_get_integer (relay_raw_buffer, "short_name_is_set"))
{
weechat_buffer_set (relay_raw_buffer, "short_name",
RELAY_RAW_BUFFER_NAME);
}
- weechat_buffer_set (relay_raw_buffer, "localvar_set_type", "debug");
- weechat_buffer_set (relay_raw_buffer, "localvar_set_server", RELAY_RAW_BUFFER_NAME);
- weechat_buffer_set (relay_raw_buffer, "localvar_set_channel", RELAY_RAW_BUFFER_NAME);
- weechat_buffer_set (relay_raw_buffer, "localvar_set_no_log", "1");
-
- /* disable all highlights on this buffer */
- weechat_buffer_set (relay_raw_buffer, "highlight_words", "-");
/* print messages in list */
for (ptr_raw_message = relay_raw_messages; ptr_raw_message;