1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

1008: big uploads. Added info in the status bar about uploded data.

This commit is contained in:
Witold Filipczyk 2008-05-03 00:13:40 +02:00 committed by Witold Filipczyk
parent 6c0979aae9
commit 8508c18341
5 changed files with 52 additions and 22 deletions

View File

@ -15,10 +15,9 @@
#include "util/memory.h"
#include "util/string.h"
unsigned char *
get_progress_msg(struct progress *progress, struct terminal *term,
int wide, int full, unsigned char *separator)
static unsigned char *
get_progress_msg_2(struct progress *progress, struct terminal *term,
int wide, int full, unsigned char *separator, unsigned char *type)
{
struct string msg;
int newlines = separator[strlen(separator) - 1] == '\n';
@ -29,7 +28,7 @@ get_progress_msg(struct progress *progress, struct terminal *term,
* one, _("of")-like pearls are a nightmare. Format strings need to
* be introduced to this fuggy corner of code as well. --pasky */
add_to_string(&msg, _("Received", term));
add_to_string(&msg, type);
add_char_to_string(&msg, ' ');
add_xnum_to_string(&msg, progress->pos);
if (progress->size >= 0) {
@ -90,6 +89,20 @@ get_progress_msg(struct progress *progress, struct terminal *term,
return msg.source;
}
unsigned char *
get_upload_progress_msg(struct progress *progress, struct terminal *term,
int wide, int full, unsigned char *separator)
{
return get_progress_msg_2(progress, term, wide, full, separator, _("Sent", term));
}
unsigned char *
get_progress_msg(struct progress *progress, struct terminal *term,
int wide, int full, unsigned char *separator)
{
return get_progress_msg_2(progress, term, wide, full, separator, _("Received", term));
}
void
draw_progress_bar(struct progress *progress, struct terminal *term,
int x, int y, int width,

View File

@ -8,6 +8,11 @@ unsigned char *
get_progress_msg(struct progress *progress, struct terminal *term,
int wide, int full, unsigned char *separator);
unsigned char *
get_upload_progress_msg(struct progress *progress, struct terminal *term,
int wide, int full, unsigned char *separator);
/* Draws a progress bar meter or progress coloured text depending on whether
* @text is NULL. If @meter_color is NULL dialog.meter color is used. */
void

View File

@ -55,6 +55,9 @@ get_download_msg(struct download *download, struct terminal *term,
&& download->conn->uri->protocol == PROTOCOL_BITTORRENT)
return get_bittorrent_message(download, term, wide, full, separator);
#endif
if (download->conn && download->conn->upload_progress)
return get_upload_progress_msg(download->conn->upload_progress,
term, wide, full, separator);
return get_progress_msg(download->progress, term, wide, full, separator);
}
@ -229,6 +232,7 @@ display_status_bar(struct session *ses, struct terminal *term, int tabs_count)
}
}
if (!msg) {
int full = term->width > 130;
int wide = term->width > 80;

View File

@ -26,6 +26,7 @@
#include "network/progress.h"
#include "network/socket.h"
#include "network/ssl/ssl.h"
#include "protocol/http/http.h"
#include "protocol/protocol.h"
#include "protocol/proxy.h"
#include "protocol/uri.h"
@ -64,9 +65,8 @@ static INIT_LIST_OF(struct host_connection, host_connections);
static INIT_LIST_OF(struct keepalive_connection, keepalive_connections);
/* Prototypes */
static void notify_connection_callbacks(struct connection *conn);
static void check_keepalive_connections(void);
static void notify_connection_callbacks(struct connection *conn);
static /* inline */ enum connection_priority
get_priority(struct connection *conn)
@ -338,17 +338,38 @@ stat_timer(struct connection *conn)
notify_connection_callbacks(conn);
}
static void
upload_stat_timer(struct connection *conn)
{
struct http_connection_info *http = conn->info;
assert(conn->upload_progress && http);
if_assert_failed return;
update_progress(conn->upload_progress, http->uploaded,
http->total_upload_length, http->uploaded);
notify_connection_callbacks(conn);
}
void
set_connection_state(struct connection *conn, enum connection_state state)
{
struct download *download;
struct progress *progress = conn->progress;
struct progress *upload_progress = conn->upload_progress;
if (is_in_result_state(conn->state) && is_in_progress_state(state))
conn->prev_error = conn->state;
conn->state = state;
if (conn->state == S_TRANS) {
if (upload_progress && upload_progress->timer == TIMER_ID_UNDEF) {
start_update_progress(upload_progress,
(void (*)(void *)) upload_stat_timer, conn);
upload_stat_timer(conn);
if (connection_disappeared(conn))
return;
}
if (progress->timer == TIMER_ID_UNDEF) {
start_update_progress(progress, (void (*)(void *)) stat_timer, conn);
update_connection_progress(conn);
@ -358,6 +379,7 @@ set_connection_state(struct connection *conn, enum connection_state state)
} else {
kill_timer(&progress->timer);
if (upload_progress) kill_timer(&upload_progress->timer);
}
foreach (download, conn->downloads) {
@ -437,7 +459,7 @@ free_connection_data(struct connection *conn)
done_host_connection(conn);
}
void
static void
notify_connection_callbacks(struct connection *conn)
{
enum connection_state state = conn->state;

View File

@ -611,18 +611,6 @@ post_length(unsigned char *post_data, unsigned int *count)
return size;
}
static void
update_upload_progress(struct connection *conn)
{
struct http_connection_info *http = conn->info;
assert(conn->upload_progress && http);
if_assert_failed return;
update_progress(conn->upload_progress, http->uploaded,
http->total_upload_length, http->uploaded);
}
#define POST_BUFFER_SIZE 4096
#define BIG_READ 655360
@ -1097,8 +1085,6 @@ http_send_header(struct socket *socket)
socket->state = SOCKET_END_ONCLOSE;
if (!conn->upload_progress)
conn->upload_progress = init_progress(0);
start_update_progress(conn->upload_progress,
(void (*)(void *))update_upload_progress, conn);
write_to_socket(socket, header.source, header.length, S_TRANS,
send_big_files);
done_string(&header);