mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
Prettier displaying of DCC transfers, including adding ETA.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3021 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
5bf764ac14
commit
ecff491e02
@ -33,12 +33,18 @@
|
||||
|
||||
static void dcc_request(GET_DCC_REC *dcc)
|
||||
{
|
||||
char *sizestr;
|
||||
|
||||
if (!IS_DCC_GET(dcc)) return;
|
||||
|
||||
sizestr = dcc_get_size_str(dcc->size);
|
||||
|
||||
printformat(dcc->server, NULL, MSGLEVEL_DCC,
|
||||
ischannel(*dcc->target) ? IRCTXT_DCC_SEND_CHANNEL :
|
||||
IRCTXT_DCC_SEND, dcc->nick, dcc->addrstr,
|
||||
dcc->port, dcc->arg, dcc->size, dcc->target);
|
||||
dcc->port, dcc->arg, sizestr, dcc->target);
|
||||
|
||||
g_free(sizestr);
|
||||
}
|
||||
|
||||
static void dcc_connected(GET_DCC_REC *dcc)
|
||||
@ -51,6 +57,7 @@ static void dcc_connected(GET_DCC_REC *dcc)
|
||||
|
||||
static void dcc_closed(GET_DCC_REC *dcc)
|
||||
{
|
||||
char *sizestr, timestr[20];
|
||||
double kbs;
|
||||
time_t secs;
|
||||
|
||||
@ -60,16 +67,21 @@ static void dcc_closed(GET_DCC_REC *dcc)
|
||||
kbs = (double) (dcc->transfd-dcc->skipped) /
|
||||
(secs == 0 ? 1 : secs) / 1024.0;
|
||||
|
||||
sizestr = dcc_get_size_str(dcc->transfd);
|
||||
g_snprintf(timestr, sizeof(timestr), "%02d:%02d:%02d",
|
||||
(int)(secs/3600), (int)((secs/60)%60), (int)(secs%60));
|
||||
|
||||
if (secs == -1) {
|
||||
/* aborted */
|
||||
printformat(dcc->server, NULL, MSGLEVEL_DCC,
|
||||
IRCTXT_DCC_GET_ABORTED, dcc->arg, dcc->nick);
|
||||
} else {
|
||||
printformat(dcc->server, NULL, MSGLEVEL_DCC,
|
||||
IRCTXT_DCC_GET_COMPLETE, dcc->arg,
|
||||
(dcc->transfd+1023)/1024,
|
||||
dcc->nick, (long) secs, kbs);
|
||||
IRCTXT_DCC_GET_COMPLETE, dcc->arg, sizestr,
|
||||
dcc->nick, timestr, kbs);
|
||||
}
|
||||
|
||||
g_free(sizestr);
|
||||
}
|
||||
|
||||
static void dcc_error_file_create(GET_DCC_REC *dcc, const char *fname,
|
||||
|
@ -45,6 +45,7 @@ static void dcc_connected(SEND_DCC_REC *dcc)
|
||||
|
||||
static void dcc_closed(SEND_DCC_REC *dcc)
|
||||
{
|
||||
char *sizestr, timestr[20];
|
||||
double kbs;
|
||||
time_t secs;
|
||||
|
||||
@ -60,10 +61,16 @@ static void dcc_closed(SEND_DCC_REC *dcc)
|
||||
IRCTXT_DCC_SEND_ABORTED,
|
||||
dcc->arg, dcc->nick);
|
||||
} else {
|
||||
sizestr = dcc_get_size_str(dcc->transfd);
|
||||
g_snprintf(timestr, sizeof(timestr), "%02d:%02d:%02d",
|
||||
(int)(secs/3600), (int)((secs/60)%60),
|
||||
(int)(secs%60));
|
||||
|
||||
printformat(dcc->server, NULL, MSGLEVEL_DCC,
|
||||
IRCTXT_DCC_SEND_COMPLETE,
|
||||
dcc->arg, (dcc->transfd+1023)/1024,
|
||||
dcc->nick, (long) secs, kbs);
|
||||
dcc->arg, sizestr, dcc->nick, timestr, kbs);
|
||||
|
||||
g_free(sizestr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,15 @@ void fe_dcc_get_deinit(void);
|
||||
void fe_dcc_send_init(void);
|
||||
void fe_dcc_send_deinit(void);
|
||||
|
||||
char *dcc_get_size_str(uoff_t size)
|
||||
{
|
||||
if (size < 1024)
|
||||
return g_strdup_printf("%"PRIuUOFF_T"B", size);
|
||||
if (size < 1024*1024)
|
||||
return g_strdup_printf("%"PRIuUOFF_T"kB", (size+1023) / 1024);
|
||||
return g_strdup_printf("%"PRIuUOFF_T"MB", size / (1024*1024));
|
||||
}
|
||||
|
||||
static void dcc_request(DCC_REC *dcc)
|
||||
{
|
||||
char *service;
|
||||
@ -91,17 +100,34 @@ static void dcc_error_unknown_type(const char *type)
|
||||
|
||||
void dcc_list_print_file(FILE_DCC_REC *dcc)
|
||||
{
|
||||
time_t going;
|
||||
time_t going, eta;
|
||||
char *transfd_str, *size_str, etastr[20];
|
||||
uoff_t bps;
|
||||
|
||||
going = time(NULL) - dcc->starttime;
|
||||
if (going == 0) going = 1; /* no division by zeros :) */
|
||||
if (going <= 0) going = 1;
|
||||
|
||||
transfd_str = dcc_get_size_str(dcc->transfd);
|
||||
size_str = dcc_get_size_str(dcc->size);
|
||||
|
||||
bps = (dcc->transfd-dcc->skipped) / going;
|
||||
if (bps == 0) {
|
||||
strcpy(etastr, "(stalled)");
|
||||
} else {
|
||||
eta = (dcc->size - dcc->transfd) / bps;
|
||||
g_snprintf(etastr, sizeof(etastr), "%02d:%02d:%02d",
|
||||
(int)(eta/3600), (int)((eta/60)%60), (int)(eta%60));
|
||||
}
|
||||
|
||||
printformat(NULL, NULL, MSGLEVEL_DCC,
|
||||
IRCTXT_DCC_LIST_LINE_FILE,
|
||||
dcc->nick, dcc_type2str(dcc->type),
|
||||
(dcc->transfd+1023)/1024, (dcc->size+1023)/1024,
|
||||
transfd_str, size_str,
|
||||
dcc->size == 0 ? 0 : (int)((double)dcc->transfd/(double)dcc->size*100.0),
|
||||
(double) (dcc->transfd-dcc->skipped)/going/1024, dcc->arg);
|
||||
(double)bps/1024.0, dcc->arg, etastr);
|
||||
|
||||
g_free(transfd_str);
|
||||
g_free(size_str);
|
||||
}
|
||||
|
||||
static void cmd_dcc_list(const char *data)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef __FE_DCC_H
|
||||
#define __FE_DCC_H
|
||||
|
||||
char *dcc_get_size_str(uoff_t size);
|
||||
void dcc_list_print_file(FILE_DCC_REC *dcc);
|
||||
|
||||
#endif
|
||||
|
@ -42,18 +42,18 @@ FORMAT_REC fecommon_irc_dcc_formats[] = {
|
||||
{ "dcc_chat_not_found", "{dcc No DCC CHAT connection open to {nick $0}}", 1, { 0 } },
|
||||
{ "dcc_chat_connected", "{dcc DCC CHAT connection with {nick $0} [$1 port $2] established}", 3, { 0, 0, 1 } },
|
||||
{ "dcc_chat_disconnected", "{dcc DCC lost chat to {nick $0}}", 1, { 0 } },
|
||||
{ "dcc_send", "{dcc DCC SEND from {nick $0} [$1 port $2]: $3 [$4 bytes]}", 5, { 0, 0, 1, 0, 2 } },
|
||||
{ "dcc_send_channel", "{dcc DCC SEND from {nick $0} [$1 port $2]: $3 [$4 bytes] requested in channel {channel $5}}", 6, { 0, 0, 1, 0, 2, 0 } },
|
||||
{ "dcc_send", "{dcc DCC SEND from {nick $0} [$1 port $2]: $3 [$4]}", 5, { 0, 0, 1, 0, 0 } },
|
||||
{ "dcc_send_channel", "{dcc DCC SEND from {nick $0} [$1 port $2]: $3 [$4 bytes] requested in channel {channel $5}}", 6, { 0, 0, 1, 0, 0, 0 } },
|
||||
{ "dcc_send_exists", "{dcc DCC already sending file {dccfile $0} for {nick $1}}", 2, { 0, 0 } },
|
||||
{ "dcc_send_no_route", "{dcc DCC route lost to nick {nick $0} when trying to send file {dccfile $1}}", 2, { 0, 0 } },
|
||||
{ "dcc_send_not_found", "{dcc DCC not sending file {dccfile $1} to {nick $0}}", 2, { 0, 0 } },
|
||||
{ "dcc_send_file_open_error", "{dcc DCC can't open file {dccfile $0}: $1}", 2, { 0, 0 } },
|
||||
{ "dcc_send_connected", "{dcc DCC sending file {dccfile $0} for {nick $1} [$2 port $3]}", 4, { 0, 0, 0, 1 } },
|
||||
{ "dcc_send_complete", "{dcc DCC sent file {dccfile $0} [{hilight $1}kB] for {nick $2} in {hilight $3} secs [{hilight $4kB/s}]}", 5, { 0, 2, 0, 2, 3 } },
|
||||
{ "dcc_send_complete", "{dcc DCC sent file {dccfile $0} [{hilight $1}] for {nick $2} in {hilight $3} [{hilight $4kB/s}]}", 5, { 0, 0, 0, 0, 3 } },
|
||||
{ "dcc_send_aborted", "{dcc DCC aborted sending file {dccfile $0} for {nick $1}}", 2, { 0, 0 } },
|
||||
{ "dcc_get_not_found", "{dcc DCC no file offered by {nick $0}}", 1, { 0 } },
|
||||
{ "dcc_get_connected", "{dcc DCC receiving file {dccfile $0} from {nick $1} [$2 port $3]}", 4, { 0, 0, 0, 1 } },
|
||||
{ "dcc_get_complete", "{dcc DCC received file {dccfile $0} [$1kB] from {nick $2} in {hilight $3} secs [$4kB/s]}", 5, { 0, 2, 0, 2, 3 } },
|
||||
{ "dcc_get_complete", "{dcc DCC received file {dccfile $0} [$1] from {nick $2} in {hilight $3} [$4kB/s]}", 5, { 0, 0, 0, 0, 3 } },
|
||||
{ "dcc_get_aborted", "{dcc DCC aborted receiving file {dccfile $0} from {nick $1}}", 2, { 0, 0 } },
|
||||
{ "dcc_get_write_error", "{dcc DCC error writing to file {dccfile $0}: {comment $1}", 2, { 0, 0 } },
|
||||
{ "dcc_unknown_ctcp", "{dcc DCC unknown ctcp {hilight $0} from {nick $1} [$2]}", 3, { 0, 0, 0 } },
|
||||
@ -68,7 +68,7 @@ FORMAT_REC fecommon_irc_dcc_formats[] = {
|
||||
{ "dcc_lowport", "{dcc Warning: Port sent with DCC request is a lowport ({hilight $0, $1}) - this isn't normal. It is possible the address/port is faked (or maybe someone is just trying to bypass firewall)}", 2, { 1, 0 } },
|
||||
{ "dcc_list_header", "{dcc DCC connections}", 0 },
|
||||
{ "dcc_list_line_chat", "{dcc $0 $1}", 2, { 0, 0 } },
|
||||
{ "dcc_list_line_file", "{dcc $0 $1: $2k of $3k ($4%%) - $5kB/s - $6}", 7, { 0, 0, 2, 2, 1, 3, 0 } },
|
||||
{ "dcc_list_line_file", "{dcc $0 $1: %|$2 of $3 ($4%%) - $5kB/s - ETA $7 - $6}", 8, { 0, 0, 0, 0, 1, 3, 0, 0 } },
|
||||
{ "dcc_list_line_queued_send", "{dcc - $0 $2 (queued)}", 3, { 0, 0, 0 } },
|
||||
{ "dcc_list_footer", "", 0 },
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user