summaryrefslogtreecommitdiff
path: root/src/plugins/xfer
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2009-03-23 13:37:25 +0100
committerSebastien Helleu <flashcode@flashtux.org>2009-03-23 13:37:25 +0100
commitfdf56fc7b073080fb1a19eaf234f688779aaa00c (patch)
tree12820d316d199d0792b1d2977e4a5647a30d3cdd /src/plugins/xfer
parent2a2f019cd838e3ff182adbedd7c53dc76036860f (diff)
downloadweechat-fdf56fc7b073080fb1a19eaf234f688779aaa00c.zip
Add nick completion in xfer dcc buffers, fix bug when opening xfer dcc buffer if it already exists
Diffstat (limited to 'src/plugins/xfer')
-rw-r--r--src/plugins/xfer/CMakeLists.txt1
-rw-r--r--src/plugins/xfer/Makefile.am2
-rw-r--r--src/plugins/xfer/xfer-chat.c93
-rw-r--r--src/plugins/xfer/xfer-completion.c73
-rw-r--r--src/plugins/xfer/xfer-completion.h25
-rw-r--r--src/plugins/xfer/xfer.c29
-rw-r--r--src/plugins/xfer/xfer.h1
7 files changed, 191 insertions, 33 deletions
diff --git a/src/plugins/xfer/CMakeLists.txt b/src/plugins/xfer/CMakeLists.txt
index a7d7135b1..4d8e8f543 100644
--- a/src/plugins/xfer/CMakeLists.txt
+++ b/src/plugins/xfer/CMakeLists.txt
@@ -19,6 +19,7 @@ xfer.c xfer.h
xfer-buffer.c xfer-buffer.h
xfer-chat.c xfer-chat.h
xfer-command.c xfer-command.h
+xfer-completion.c xfer-completion.h
xfer-config.c xfer-config.h
xfer-dcc.c xfer-dcc.h
xfer-file.c xfer-file.h
diff --git a/src/plugins/xfer/Makefile.am b/src/plugins/xfer/Makefile.am
index 9e2615180..d7c1fa52b 100644
--- a/src/plugins/xfer/Makefile.am
+++ b/src/plugins/xfer/Makefile.am
@@ -28,6 +28,8 @@ xfer_la_SOURCES = xfer.c \
xfer-chat.h \
xfer-command.c \
xfer-command.h \
+ xfer-completion.c \
+ xfer-completion.h \
xfer-config.c \
xfer-config.h \
xfer-dcc.c \
diff --git a/src/plugins/xfer/xfer-chat.c b/src/plugins/xfer/xfer-chat.c
index 27dfb1a41..495a94ee3 100644
--- a/src/plugins/xfer/xfer-chat.c
+++ b/src/plugins/xfer/xfer-chat.c
@@ -136,7 +136,8 @@ xfer_chat_recv_cb (void *arg_xfer, int fd)
if (ptr_buf)
{
- weechat_printf (xfer->buffer, "%s\t%s", xfer->remote_nick, ptr_buf);
+ weechat_printf_tags (xfer->buffer, "notify_message", "%s\t%s",
+ xfer->remote_nick, ptr_buf);
}
ptr_buf = next_ptr_buf;
@@ -163,18 +164,30 @@ int
xfer_chat_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
const char *input_data)
{
- struct t_xfer *xfer;
+ struct t_xfer *ptr_xfer;
+
+ /* make C compiler happy */
+ (void) data;
- xfer = (struct t_xfer *)data;
+ ptr_xfer = xfer_search_by_buffer (buffer);
- if (!XFER_HAS_ENDED(xfer->status))
+ if (!ptr_xfer)
{
- xfer_chat_sendf (xfer, "%s\n", input_data);
- if (!XFER_HAS_ENDED(xfer->status))
+ weechat_printf (NULL,
+ _("%s%s: can't find xfer for buffer \"%s\""),
+ weechat_prefix ("error"), XFER_PLUGIN_NAME,
+ weechat_buffer_get_string (buffer, "name"));
+ return WEECHAT_RC_OK;
+ }
+
+ if (!XFER_HAS_ENDED(ptr_xfer->status))
+ {
+ xfer_chat_sendf (ptr_xfer, "%s\n", input_data);
+ if (!XFER_HAS_ENDED(ptr_xfer->status))
{
weechat_printf (buffer,
"%s\t%s",
- xfer->local_nick,
+ ptr_xfer->local_nick,
input_data);
}
}
@@ -190,21 +203,25 @@ xfer_chat_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
int
xfer_chat_buffer_close_cb (void *data, struct t_gui_buffer *buffer)
{
- struct t_xfer *xfer;
+ struct t_xfer *ptr_xfer;
/* make C compiler happy */
+ (void) data;
(void) buffer;
- xfer = (struct t_xfer *)data;
+ ptr_xfer = xfer_search_by_buffer (buffer);
- if (!XFER_HAS_ENDED(xfer->status))
- {
- xfer_close (xfer, XFER_STATUS_ABORTED);
- xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE);
+ if (ptr_xfer)
+ {
+ if (!XFER_HAS_ENDED(ptr_xfer->status))
+ {
+ xfer_close (ptr_xfer, XFER_STATUS_ABORTED);
+ xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE);
+ }
+
+ ptr_xfer->buffer = NULL;
}
- xfer->buffer = NULL;
-
return WEECHAT_RC_OK;
}
@@ -217,28 +234,40 @@ xfer_chat_open_buffer (struct t_xfer *xfer)
{
char *name;
int length;
-
- length = strlen (xfer->plugin_name) + 1 + strlen (xfer->remote_nick) + 1;
+
+ length = strlen (xfer->plugin_name) + 8 + strlen (xfer->remote_nick) + 1;
name = malloc (length);
if (name)
{
- snprintf (name, length, "%s_%s", xfer->plugin_name, xfer->remote_nick);
- xfer->buffer = weechat_buffer_new (name,
- &xfer_chat_buffer_input_cb, xfer,
- &xfer_chat_buffer_close_cb, xfer);
- if (xfer->buffer)
+ snprintf (name, length, "%s_dcc_%s",
+ xfer->plugin_name, xfer->remote_nick);
+ xfer->buffer = weechat_buffer_search (XFER_PLUGIN_NAME, name);
+ if (!xfer->buffer)
{
- weechat_buffer_set (xfer->buffer, "title", _("xfer chat"));
- weechat_buffer_set (xfer->buffer, "localvar_set_type", "private");
- weechat_printf (xfer->buffer,
- _("Connected to %s (%d.%d.%d.%d) via "
- "xfer chat"),
- xfer->remote_nick,
- xfer->address >> 24,
- (xfer->address >> 16) & 0xff,
- (xfer->address >> 8) & 0xff,
- xfer->address & 0xff);
+ xfer->buffer = weechat_buffer_new (name,
+ &xfer_chat_buffer_input_cb, NULL,
+ &xfer_chat_buffer_close_cb, NULL);
+
+ /* failed to create buffer ? then return */
+ if (!xfer->buffer)
+ return;
}
+
+ weechat_buffer_set (xfer->buffer, "title", _("xfer chat"));
+ weechat_buffer_set (xfer->buffer, "short_name", xfer->remote_nick);
+ weechat_buffer_set (xfer->buffer, "localvar_set_type", "private");
+ weechat_buffer_set (xfer->buffer, "localvar_set_nick", xfer->local_nick);
+ weechat_buffer_set (xfer->buffer, "localvar_set_channel", xfer->remote_nick);
+ weechat_buffer_set (xfer->buffer, "highlight_words", xfer->local_nick);
+ weechat_printf (xfer->buffer,
+ _("Connected to %s (%d.%d.%d.%d) via "
+ "xfer chat"),
+ xfer->remote_nick,
+ xfer->address >> 24,
+ (xfer->address >> 16) & 0xff,
+ (xfer->address >> 8) & 0xff,
+ xfer->address & 0xff);
+
free (name);
}
}
diff --git a/src/plugins/xfer/xfer-completion.c b/src/plugins/xfer/xfer-completion.c
new file mode 100644
index 000000000..d0f36b3ca
--- /dev/null
+++ b/src/plugins/xfer/xfer-completion.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2003-2009 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* xfer-completion.c: nick completion for xfer chats */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "../weechat-plugin.h"
+#include "xfer.h"
+#include "xfer-completion.h"
+
+
+/*
+ * xfer_completion_nick_cb: callback for completion with nick
+ */
+
+int
+xfer_completion_nick_cb (void *data, const char *completion_item,
+ struct t_gui_buffer *buffer,
+ struct t_gui_completion *completion)
+{
+ struct t_xfer *ptr_xfer;
+
+ /* make C compiler happy */
+ (void) data;
+ (void) completion_item;
+
+ ptr_xfer = xfer_search_by_buffer (buffer);
+ if (ptr_xfer)
+ {
+ /* remote nick */
+ weechat_hook_completion_list_add (completion,
+ ptr_xfer->remote_nick,
+ 0,
+ WEECHAT_LIST_POS_SORT);
+ /* add self nick at the end */
+ weechat_hook_completion_list_add (completion,
+ ptr_xfer->local_nick,
+ 1,
+ WEECHAT_LIST_POS_END);
+ }
+
+ return WEECHAT_RC_OK;
+}
+
+/*
+ * xfer_completion_init: init completion for xfer plugin
+ */
+
+void
+xfer_completion_init ()
+{
+ weechat_hook_completion ("nick",
+ &xfer_completion_nick_cb, NULL);
+}
diff --git a/src/plugins/xfer/xfer-completion.h b/src/plugins/xfer/xfer-completion.h
new file mode 100644
index 000000000..c4e279925
--- /dev/null
+++ b/src/plugins/xfer/xfer-completion.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2003-2009 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_XFER_COMPLETION_H
+#define __WEECHAT_XFER_COMPLETION_H 1
+
+extern void xfer_completion_init ();
+
+#endif /* xfer-completion.h */
diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c
index 16bb46d01..2ea59bdc5 100644
--- a/src/plugins/xfer/xfer.c
+++ b/src/plugins/xfer/xfer.c
@@ -34,6 +34,7 @@
#include "xfer.h"
#include "xfer-buffer.h"
#include "xfer-command.h"
+#include "xfer-completion.h"
#include "xfer-config.h"
#include "xfer-file.h"
#include "xfer-info.h"
@@ -231,6 +232,28 @@ xfer_search_by_number (int number)
}
/*
+ * xfer_search_by_buffer: search a xfer by buffer (for chat only)
+ */
+
+struct t_xfer *
+xfer_search_by_buffer (struct t_gui_buffer *buffer)
+{
+ struct t_xfer *ptr_xfer;
+
+ if (!buffer)
+ return NULL;
+
+ for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer)
+ {
+ if (ptr_xfer->buffer == buffer)
+ return ptr_xfer;
+ }
+
+ /* xfer not found */
+ return NULL;
+}
+
+/*
* xfer_close: close a xfer
*/
@@ -1393,13 +1416,17 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
xfer_create_directories ();
xfer_command_init ();
-
+
+ /* hook some signals */
weechat_hook_signal ("upgrade", &xfer_signal_upgrade_cb, NULL);
weechat_hook_signal ("xfer_add", &xfer_add_cb, NULL);
weechat_hook_signal ("xfer_start_resume", &xfer_start_resume_cb, NULL);
weechat_hook_signal ("xfer_accept_resume", &xfer_accept_resume_cb, NULL);
weechat_hook_signal ("debug_dump", &xfer_debug_dump_cb, NULL);
+ /* hook completions */
+ xfer_completion_init ();
+
xfer_info_init ();
return WEECHAT_RC_OK;
diff --git a/src/plugins/xfer/xfer.h b/src/plugins/xfer/xfer.h
index 195e61ddb..ba973223a 100644
--- a/src/plugins/xfer/xfer.h
+++ b/src/plugins/xfer/xfer.h
@@ -157,6 +157,7 @@ extern int xfer_count;
extern int xfer_valid (struct t_xfer *xfer);
extern struct t_xfer *xfer_search_by_number (int number);
+extern struct t_xfer *xfer_search_by_buffer (struct t_gui_buffer *buffer);
extern void xfer_close (struct t_xfer *xfer, enum t_xfer_status status);
extern void xfer_send_signal (struct t_xfer *xfer, const char *signal);
extern void xfer_free (struct t_xfer *xfer);