mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 01:03:14 +02:00
Add new plugin "relay", new function "string_format_size" in plugin API
This commit is contained in:
@@ -42,14 +42,10 @@ void
|
||||
xfer_buffer_refresh (const char *hotlist)
|
||||
{
|
||||
struct t_xfer *ptr_xfer, *xfer_selected;
|
||||
char str_color[256], suffix[32], status[64], date[128], *progress_bar;
|
||||
char format[128], format_per_sec[128], bytes_per_sec[256], eta[128];
|
||||
int i, length, line, progress_bar_size, num_bars, num_unit;
|
||||
int num_unit_per_sec;
|
||||
char str_color[256], suffix[32], status[64], date[128], eta[128];
|
||||
char *progress_bar, *str_pos, *str_total, *str_bytes_per_sec;
|
||||
int i, length, line, progress_bar_size, num_bars;
|
||||
unsigned long pct_complete;
|
||||
char *unit_name[] = { N_("bytes"), N_("KB"), N_("MB"), N_("GB") };
|
||||
char *unit_format[] = { "%.0f", "%.1f", "%.02f", "%.02f" };
|
||||
float unit_divide[] = { 1, 1024, 1024*1024, 1024*1024*1024 };
|
||||
struct tm *date_tmp;
|
||||
|
||||
if (xfer_buffer)
|
||||
@@ -77,7 +73,7 @@ xfer_buffer_refresh (const char *hotlist)
|
||||
/* purge old */
|
||||
_(" [P] Purge finished"),
|
||||
/* quit */
|
||||
_(" [Q] Close xfer list"));
|
||||
_(" [Q] Close this buffer"));
|
||||
}
|
||||
for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer)
|
||||
{
|
||||
@@ -170,14 +166,6 @@ xfer_buffer_refresh (const char *hotlist)
|
||||
}
|
||||
|
||||
/* computes percentage */
|
||||
if (ptr_xfer->size < 1024*10)
|
||||
num_unit = 0;
|
||||
else if (ptr_xfer->size < 1024*1024)
|
||||
num_unit = 1;
|
||||
else if (ptr_xfer->size < 1024*1024*1024)
|
||||
num_unit = 2;
|
||||
else
|
||||
num_unit = 3;
|
||||
if (ptr_xfer->size == 0)
|
||||
{
|
||||
if (ptr_xfer->status == XFER_STATUS_DONE)
|
||||
@@ -188,28 +176,10 @@ xfer_buffer_refresh (const char *hotlist)
|
||||
else
|
||||
pct_complete = (unsigned long)(((float)(ptr_xfer->pos)/(float)(ptr_xfer->size)) * 100);
|
||||
|
||||
snprintf (format, sizeof (format),
|
||||
"%%s%%s%%s %%s%%s%%s%%s%%3lu%%%% %s %%s / %s %%s (%%s%%s)",
|
||||
unit_format[num_unit],
|
||||
unit_format[num_unit]);
|
||||
|
||||
/* bytes per second */
|
||||
bytes_per_sec[0] = '\0';
|
||||
if (ptr_xfer->bytes_per_sec < 1024*10)
|
||||
num_unit_per_sec = 0;
|
||||
else if (ptr_xfer->bytes_per_sec < 1024*1024)
|
||||
num_unit_per_sec = 1;
|
||||
else if (ptr_xfer->bytes_per_sec < 1024*1024*1024)
|
||||
num_unit_per_sec = 2;
|
||||
else
|
||||
num_unit_per_sec = 3;
|
||||
snprintf (format_per_sec, sizeof (format_per_sec),
|
||||
"%s %%s/s",
|
||||
unit_format[num_unit_per_sec]);
|
||||
snprintf (bytes_per_sec, sizeof (bytes_per_sec),
|
||||
format_per_sec,
|
||||
((float)ptr_xfer->bytes_per_sec) / ((float)(unit_divide[num_unit_per_sec])),
|
||||
_(unit_name[num_unit_per_sec]));
|
||||
/* position, total and bytes per second */
|
||||
str_pos = weechat_string_format_size (ptr_xfer->pos);
|
||||
str_total = weechat_string_format_size (ptr_xfer->size);
|
||||
str_bytes_per_sec = weechat_string_format_size (ptr_xfer->bytes_per_sec);
|
||||
|
||||
/* ETA */
|
||||
eta[0] = '\0';
|
||||
@@ -225,23 +195,25 @@ xfer_buffer_refresh (const char *hotlist)
|
||||
|
||||
/* display second line for file with status, progress bar and estimated time */
|
||||
weechat_printf_y (xfer_buffer, (line * 2) + 3,
|
||||
format,
|
||||
"%s%s%s %s%s%s%s%3lu%% %s / %s (%s%s/s)",
|
||||
weechat_color(str_color),
|
||||
(line == xfer_buffer_selected_line) ?
|
||||
"*** " : " ",
|
||||
(XFER_IS_SEND(ptr_xfer->type)) ?
|
||||
"<<--" : "-->>",
|
||||
(line == xfer_buffer_selected_line) ? "*** " : " ",
|
||||
(XFER_IS_SEND(ptr_xfer->type)) ? "<<--" : "-->>",
|
||||
weechat_color(weechat_config_string (xfer_config_color_status[ptr_xfer->status])),
|
||||
status,
|
||||
weechat_color (str_color),
|
||||
(progress_bar) ? progress_bar : "",
|
||||
pct_complete,
|
||||
((float)(ptr_xfer->pos)) / unit_divide[num_unit],
|
||||
_(unit_name[num_unit]),
|
||||
((float)(ptr_xfer->size)) / unit_divide[num_unit],
|
||||
_(unit_name[num_unit]),
|
||||
(str_pos) ? str_pos : "?",
|
||||
(str_total) ? str_total : "?",
|
||||
eta,
|
||||
bytes_per_sec);
|
||||
str_bytes_per_sec);
|
||||
if (str_pos)
|
||||
free (str_pos);
|
||||
if (str_total)
|
||||
free (str_total);
|
||||
if (str_bytes_per_sec)
|
||||
free (str_bytes_per_sec);
|
||||
}
|
||||
line++;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ xfer_command_xfer (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
}
|
||||
|
||||
/*
|
||||
* xfer_command: xfer command
|
||||
* xfer_command_init: add /xfer command
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -197,7 +197,10 @@ xfer_command_init ()
|
||||
{
|
||||
weechat_hook_command ("xfer",
|
||||
N_("xfer control"),
|
||||
"",
|
||||
N_("Open buffer with xfer list"),
|
||||
"[list | listfull]",
|
||||
N_(" list: list xfer\n"
|
||||
"listfull: list xfer (verbose)\n\n"
|
||||
"Without argument, this command opens buffer "
|
||||
"with xfer list."),
|
||||
"list|listfull", &xfer_command_xfer, NULL);
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ xfer_network_send_file_fork (struct t_xfer *xfer)
|
||||
xfer->child_pid = pid;
|
||||
xfer->hook_fd = weechat_hook_fd (xfer->child_read,
|
||||
1, 0, 0,
|
||||
xfer_network_child_read_cb,
|
||||
&xfer_network_child_read_cb,
|
||||
xfer);
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ xfer_network_recv_file_fork (struct t_xfer *xfer)
|
||||
xfer->child_pid = pid;
|
||||
xfer->hook_fd = weechat_hook_fd (xfer->child_read,
|
||||
1, 0, 0,
|
||||
xfer_network_child_read_cb,
|
||||
&xfer_network_child_read_cb,
|
||||
xfer);
|
||||
}
|
||||
|
||||
|
||||
@@ -1277,7 +1277,7 @@ xfer_add_to_infolist (struct t_infolist *infolist, struct t_xfer *xfer)
|
||||
}
|
||||
|
||||
/*
|
||||
* xfer_print_log: print DCC infos in log (usually for crash dump)
|
||||
* xfer_print_log: print xfer infos in log (usually for crash dump)
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -1294,6 +1294,9 @@ xfer_print_log ()
|
||||
weechat_log_printf (" type. . . . . . . . : %d (%s)",
|
||||
ptr_xfer->type,
|
||||
xfer_type_string[ptr_xfer->type]);
|
||||
weechat_log_printf (" protocol. . . . . . : %d (%s)",
|
||||
ptr_xfer->protocol,
|
||||
xfer_protocol_string[ptr_xfer->protocol]);
|
||||
weechat_log_printf (" remote_nick . . . . : '%s'", ptr_xfer->remote_nick);
|
||||
weechat_log_printf (" local_nick. . . . . : '%s'", ptr_xfer->local_nick);
|
||||
weechat_log_printf (" filename. . . . . . : '%s'", ptr_xfer->filename);
|
||||
@@ -1314,6 +1317,8 @@ xfer_print_log ()
|
||||
weechat_log_printf (" child_pid . . . . . : %d", ptr_xfer->child_pid);
|
||||
weechat_log_printf (" child_read. . . . . : %d", ptr_xfer->child_read);
|
||||
weechat_log_printf (" child_write . . . . : %d", ptr_xfer->child_write);
|
||||
weechat_log_printf (" hook_fd . . . . . . : 0x%lx", ptr_xfer->hook_fd);
|
||||
weechat_log_printf (" hook_timer. . . . . : 0x%lx", ptr_xfer->hook_timer);
|
||||
weechat_log_printf (" unterminated_message: '%s'", ptr_xfer->unterminated_message);
|
||||
weechat_log_printf (" file. . . . . . . . : %d", ptr_xfer->file);
|
||||
weechat_log_printf (" local_filename. . . : '%s'", ptr_xfer->local_filename);
|
||||
@@ -1380,7 +1385,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
xfer_create_directories ();
|
||||
|
||||
xfer_command_init ();
|
||||
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user