12
11
#include "bfu/dialog.h"
13
12
#include "cache/cache.h"
14
13
#include "config/options.h"
15
#include "dialogs/download.h"
14
#include "dialogs/progress.h"
16
15
#include "dialogs/status.h"
17
16
#include "document/document.h"
18
17
#include "document/renderer.h"
19
18
#include "document/view.h"
20
19
#include "intl/gettext/libintl.h"
20
#include "network/connection.h"
21
#include "network/progress.h"
22
#include "network/state.h"
23
#include "protocol/bittorrent/dialogs.h"
24
#include "protocol/protocol.h"
21
25
#include "protocol/uri.h"
22
#include "sched/connection.h"
23
#include "sched/error.h"
24
#include "sched/session.h"
26
#include "session/download.h"
27
#include "session/session.h"
25
28
#include "terminal/draw.h"
26
29
#include "terminal/screen.h"
27
30
#include "terminal/tab.h"
38
41
#include "viewer/text/view.h"
41
#define average_speed(progress) \
42
((longlong) (progress)->loaded * 10 / ((progress)->elapsed / 100))
44
#define current_speed(progress) \
45
((progress)->cur_loaded / (CURRENT_SPD_SEC * SPD_DISP_TIME / 1000))
47
#define estimated_time(progress) \
48
(((progress)->size - (progress)->pos) \
49
/ ((longlong) (progress)->loaded * 10 / ((progress)->elapsed / 100)) \
53
45
get_download_msg(struct download *download, struct terminal *term,
54
int wide, int full, unsigned char *separator)
46
int wide, int full, unsigned char *separator)
57
int newlines = separator[strlen(separator) - 1] == '\n';
59
48
if (!download_is_progressing(download)) {
60
49
/* DBG("%d -> %s", download->state, _(get_err_msg(download->state), term)); */
61
return stracpy(get_err_msg(download->state, term));
64
if (!init_string(&msg)) return NULL;
66
/* FIXME: The following is a PITA from the l10n standpoint. A *big*
67
* one, _("of")-like pearls are a nightmare. Format strings need to
68
* be introduced to this fuggy corner of code as well. --pasky */
70
add_to_string(&msg, _("Received", term));
71
add_char_to_string(&msg, ' ');
72
add_xnum_to_string(&msg, download->progress->pos);
73
if (download->progress->size >= 0) {
74
add_char_to_string(&msg, ' ');
75
add_to_string(&msg, _("of", term));
76
add_char_to_string(&msg, ' ');
77
add_xnum_to_string(&msg, download->progress->size);
80
add_to_string(&msg, separator);
82
if (wide && download->progress->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME) {
84
_(full ? (newlines ? N_("Average speed")
85
: N_("average speed"))
89
add_to_string(&msg, _(newlines ? N_("Speed") : N_("speed"),
93
add_char_to_string(&msg, ' ');
94
add_xnum_to_string(&msg, average_speed(download->progress));
95
add_to_string(&msg, "/s");
97
if (wide && download->progress->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME) {
98
add_to_string(&msg, ", ");
100
_(full ? N_("current speed") : N_("cur"), term));
101
add_char_to_string(&msg, ' '),
102
add_xnum_to_string(&msg, current_speed(download->progress));
103
add_to_string(&msg, "/s");
107
/* Do the following only if there is room */
109
add_to_string(&msg, separator);
111
add_to_string(&msg, _(full ? (newlines ? N_("Elapsed time")
112
: N_("elapsed time"))
115
add_char_to_string(&msg, ' ');
116
add_time_to_string(&msg, download->progress->elapsed);
119
if (download->progress->size >= 0 && download->progress->loaded > 0) {
120
add_to_string(&msg, ", ");
121
add_to_string(&msg, _(full ? N_("estimated time")
124
add_char_to_string(&msg, ' ');
125
add_time_to_string(&msg, estimated_time(download->progress));
50
return stracpy(get_state_message(download->state, term));
53
#ifdef CONFIG_BITTORRENT
55
&& download->conn->uri->protocol == PROTOCOL_BITTORRENT)
56
return get_bittorrent_message(download, term, wide, full, separator);
59
return get_progress_msg(download->progress, term, wide, full, separator);
132
62
#define show_tabs(option, tabs) (((option) > 0) && !((option) == 1 && (tabs) < 2))
418
346
draw_box(term, &box, ' ', 0, color);
421
download_progress_bar(term, box.x, box.y,
422
actual_tab_width, msg, NULL,
423
download->progress->pos, download->progress->size);
349
draw_progress_bar(download->progress, term,
350
box.x, box.y, actual_tab_width,
425
353
int msglen = int_min(strlen(msg), actual_tab_width);
547
475
find_in_cache(ses->doc_view->document->uri);
550
status->ssl_led->value = (cached->ssl_info)
478
if (cached->ssl_info)
479
set_led_value(status->ssl_led, 'S');
481
unset_led_value(status->ssl_led);
553
483
/* FIXME: We should do this thing better. */
554
status->ssl_led->value = '?';
484
set_led_value(status->ssl_led, '?');
558
488
if (ses->insert_mode == INSERT_MODE_LESS) {
559
status->insert_mode_led->value = 'i';
489
set_led_value(status->insert_mode_led, 'i');
561
unsigned char value = ses->insert_mode == INSERT_MODE_ON
563
status->insert_mode_led->value = value;
491
if (ses->insert_mode == INSERT_MODE_ON)
492
set_led_value(status->insert_mode_led, 'I');
494
unset_led_value(status->insert_mode_led);