summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-05-11 12:38:30 +0200
committerSebastien Helleu <flashcode@flashtux.org>2008-05-11 12:38:30 +0200
commitbaeea17773f4c4123d006969eeaf71ae61a7acff (patch)
treec1e06dc2fc21c1b35c6e7c02c44e9ae60995deca /src
parent53ad9cddc1852bf7ebfed44a79f08a47a89015b9 (diff)
downloadweechat-baeea17773f4c4123d006969eeaf71ae61a7acff.zip
Add "list" and "listfull" options to /xfer command
Diffstat (limited to 'src')
-rw-r--r--src/plugins/xfer/xfer-command.c127
1 files changed, 123 insertions, 4 deletions
diff --git a/src/plugins/xfer/xfer-command.c b/src/plugins/xfer/xfer-command.c
index 771b144b1..f7a211699 100644
--- a/src/plugins/xfer/xfer-command.c
+++ b/src/plugins/xfer/xfer-command.c
@@ -21,13 +21,122 @@
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include "../weechat-plugin.h"
#include "xfer.h"
#include "xfer-buffer.h"
+#include "xfer-config.h"
/*
+ * xfer_command_xfer_list: list xfer
+ */
+
+void
+xfer_command_xfer_list (int full)
+{
+ struct t_xfer *ptr_xfer;
+ int i;
+ char date[128];
+ unsigned long pct_complete;
+ struct tm *date_tmp;
+
+ if (xfer_list)
+ {
+ weechat_printf (NULL, "");
+ weechat_printf (NULL, _("Xfer list:"));
+ i = 1;
+ for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer)
+ {
+ /* xfer info */
+ if (XFER_IS_FILE(ptr_xfer->type))
+ {
+ if (ptr_xfer->size == 0)
+ {
+ if (ptr_xfer->status == XFER_STATUS_DONE)
+ pct_complete = 100;
+ else
+ pct_complete = 0;
+ }
+ else
+ pct_complete = (unsigned long)(((float)(ptr_xfer->pos)/(float)(ptr_xfer->size)) * 100);
+
+ weechat_printf (NULL,
+ _("%3d. %s (%s), file: \"%s\" (local: "
+ "\"%s\"), %s %s, status: %s%s%s "
+ "(%lu %%)"),
+ i,
+ xfer_type_string[ptr_xfer->type],
+ xfer_protocol_string[ptr_xfer->protocol],
+ ptr_xfer->filename,
+ ptr_xfer->local_filename,
+ (XFER_IS_SEND(ptr_xfer->type)) ?
+ _("sent to") : _("received from"),
+ ptr_xfer->remote_nick,
+ weechat_color (
+ weechat_config_string (
+ xfer_config_color_status[ptr_xfer->status])),
+ _(xfer_status_string[ptr_xfer->status]),
+ weechat_color ("chat"),
+ pct_complete);
+ }
+ else
+ {
+ date_tmp = localtime (&(ptr_xfer->start_time));
+ strftime (date, sizeof (date),
+ "%a, %d %b %Y %H:%M:%S", date_tmp);
+ weechat_printf (NULL,
+ _("%3d. %s, chat with %s (local nick: %s), "
+ "started on %s, status: %s%s"),
+ i,
+ xfer_type_string[ptr_xfer->type],
+ ptr_xfer->remote_nick,
+ ptr_xfer->local_nick,
+ date,
+ weechat_color(
+ weechat_config_string(
+ xfer_config_color_status[ptr_xfer->status])),
+ _(xfer_status_string[ptr_xfer->status]));
+ }
+
+ if (full)
+ {
+ /* second line of xfer info */
+ if (XFER_IS_FILE(ptr_xfer->type))
+ {
+ weechat_printf (NULL,
+ _(" plugin: %s (id: %s), file: %lu "
+ "bytes (position: %lu), address: "
+ "%d.%d.%d.%d (port %d)"),
+ ptr_xfer->plugin_name,
+ ptr_xfer->plugin_id,
+ ptr_xfer->size,
+ ptr_xfer->pos,
+ ptr_xfer->address >> 24,
+ (ptr_xfer->address >> 16) & 0xff,
+ (ptr_xfer->address >> 8) & 0xff,
+ ptr_xfer->address & 0xff,
+ ptr_xfer->port);
+ date_tmp = localtime (&(ptr_xfer->start_transfer));
+ strftime (date, sizeof (date),
+ "%a, %d %b %Y %H:%M:%S", date_tmp);
+ weechat_printf (NULL,
+ _(" fast_send: %s, blocksize: %d, "
+ "started on %s"),
+ (ptr_xfer->fast_send) ? _("yes") : _("no"),
+ ptr_xfer->blocksize,
+ date);
+ }
+ }
+ i++;
+ }
+ }
+ else
+ weechat_printf (NULL, _("No xfer"));
+}
+
+/*
* xfer_command_xfer: command /xfer
*/
@@ -38,9 +147,19 @@ xfer_command_xfer (void *data, struct t_gui_buffer *buffer, int argc,
/* make C compiler happy */
(void) data;
(void) buffer;
- (void) argc;
- (void) argv;
(void) argv_eol;
+
+ if ((argc > 1) && (weechat_strcasecmp (argv[1], "list") == 0))
+ {
+ xfer_command_xfer_list (0);
+ return WEECHAT_RC_OK;
+ }
+
+ if ((argc > 1) && (weechat_strcasecmp (argv[1], "listfull") == 0))
+ {
+ xfer_command_xfer_list (1);
+ return WEECHAT_RC_OK;
+ }
if (!xfer_buffer)
xfer_buffer_open ();
@@ -63,7 +182,7 @@ xfer_command_xfer (void *data, struct t_gui_buffer *buffer, int argc,
}
}
}
-
+
xfer_buffer_refresh (NULL);
return WEECHAT_RC_OK;
@@ -80,5 +199,5 @@ xfer_command_init ()
N_("xfer control"),
"",
_("Open buffer with xfer list"),
- NULL, &xfer_command_xfer, NULL);
+ "list|listfull", &xfer_command_xfer, NULL);
}