summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2009-03-23 13:58:42 +0100
committerSebastien Helleu <flashcode@flashtux.org>2009-03-23 13:58:42 +0100
commita745409e22d5d971f9a1374e9466b0af79ed119f (patch)
tree5f041546f44d9005d641bce1b30debe17d64efc1 /src
parentfdf56fc7b073080fb1a19eaf234f688779aaa00c (diff)
downloadweechat-a745409e22d5d971f9a1374e9466b0af79ed119f.zip
Add new IRC modifiers: irc_color_decode/irc_color_encode, add IRC color support in xfer DCC chat (bug #25974)
Diffstat (limited to 'src')
-rw-r--r--src/plugins/irc/irc-color.c28
-rw-r--r--src/plugins/irc/irc-color.h3
-rw-r--r--src/plugins/irc/irc.c5
-rw-r--r--src/plugins/xfer/xfer-chat.c22
4 files changed, 56 insertions, 2 deletions
diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c
index e2b10e0e8..a3f2ff6c7 100644
--- a/src/plugins/irc/irc-color.c
+++ b/src/plugins/irc/irc-color.c
@@ -356,3 +356,31 @@ irc_color_encode (const char *string, int keep_colors)
return (char *)out;
}
+
+/*
+ * irc_color_modifier_cb: callback for modifiers "irc_color_decode" and
+ * "irc_color_encode"
+ * This modifier can be used by other plugins to
+ * decode/encode IRC colors in messages
+ */
+
+char *
+irc_color_modifier_cb (void *data, const char *modifier,
+ const char *modifier_data, const char *string)
+{
+ int keep_colors;
+
+ /* make C compiler happy */
+ (void) data;
+
+ keep_colors = (modifier_data && (strcmp (modifier_data, "1") == 0)) ? 1 : 0;
+
+ if (strcmp (modifier, "irc_color_decode") == 0)
+ return irc_color_decode (string, keep_colors);
+
+ if (strcmp (modifier, "irc_color_encode") == 0)
+ return irc_color_decode (string, keep_colors);
+
+ /* unknown modifier */
+ return NULL;
+}
diff --git a/src/plugins/irc/irc-color.h b/src/plugins/irc/irc-color.h
index cf2cd063d..1aa9ae336 100644
--- a/src/plugins/irc/irc-color.h
+++ b/src/plugins/irc/irc-color.h
@@ -56,5 +56,8 @@
extern char *irc_color_decode (const char *string, int keep_colors);
extern char *irc_color_decode_for_user_entry (const char *string);
extern char *irc_color_encode (const char *string, int keep_colors);
+extern char *irc_color_modifier_cb (void *data, const char *modifier,
+ const char *modifier_data,
+ const char *string);
#endif /* irc-color.h */
diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c
index 7549f3e92..f36956b3d 100644
--- a/src/plugins/irc/irc.c
+++ b/src/plugins/irc/irc.c
@@ -27,6 +27,7 @@
#include "irc.h"
#include "irc-bar-item.h"
#include "irc-buffer.h"
+#include "irc-color.h"
#include "irc-command.h"
#include "irc-completion.h"
#include "irc-config.h"
@@ -165,6 +166,10 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_signal ("xfer_resume_ready", &irc_server_xfer_resume_ready_cb, NULL);
weechat_hook_signal ("xfer_send_accept_resume", &irc_server_xfer_send_accept_resume_cb, NULL);
+ /* modifiers */
+ weechat_hook_modifier ("irc_color_decode", &irc_color_modifier_cb, NULL);
+ weechat_hook_modifier ("irc_color_encode", &irc_color_modifier_cb, NULL);
+
/* hook completions */
irc_completion_init ();
diff --git a/src/plugins/xfer/xfer-chat.c b/src/plugins/xfer/xfer-chat.c
index 495a94ee3..579e47fd0 100644
--- a/src/plugins/xfer/xfer-chat.c
+++ b/src/plugins/xfer/xfer-chat.c
@@ -90,6 +90,7 @@ xfer_chat_recv_cb (void *arg_xfer, int fd)
struct t_xfer *xfer;
static char buffer[4096 + 2];
char *buf2, *pos, *ptr_buf, *next_ptr_buf;
+ char *ptr_buf_without_weechat_colors, *ptr_buf_color;
int num_read;
/* make C compiler happy */
@@ -136,8 +137,19 @@ xfer_chat_recv_cb (void *arg_xfer, int fd)
if (ptr_buf)
{
+ ptr_buf_without_weechat_colors = weechat_string_remove_color (ptr_buf, "?");
+ ptr_buf_color = weechat_hook_modifier_exec ("irc_color_decode",
+ "1",
+ (ptr_buf_without_weechat_colors) ?
+ ptr_buf_without_weechat_colors : ptr_buf);
weechat_printf_tags (xfer->buffer, "notify_message", "%s\t%s",
- xfer->remote_nick, ptr_buf);
+ xfer->remote_nick,
+ (ptr_buf_color) ?
+ ptr_buf_color : ((ptr_buf_without_weechat_colors) ? ptr_buf_without_weechat_colors : ptr_buf));
+ if (ptr_buf_without_weechat_colors)
+ free (ptr_buf_without_weechat_colors);
+ if (ptr_buf_color)
+ free (ptr_buf_color);
}
ptr_buf = next_ptr_buf;
@@ -165,6 +177,7 @@ xfer_chat_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
const char *input_data)
{
struct t_xfer *ptr_xfer;
+ char *input_data_color;
/* make C compiler happy */
(void) data;
@@ -185,10 +198,15 @@ xfer_chat_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
xfer_chat_sendf (ptr_xfer, "%s\n", input_data);
if (!XFER_HAS_ENDED(ptr_xfer->status))
{
+ input_data_color = weechat_hook_modifier_exec ("irc_color_decode",
+ "1",
+ input_data);
weechat_printf (buffer,
"%s\t%s",
ptr_xfer->local_nick,
- input_data);
+ (input_data_color) ? input_data_color : input_data);
+ if (input_data_color)
+ free (input_data_color);
}
}