~ubuntu-branches/ubuntu/feisty/elinks/feisty-updates

« back to all changes in this revision

Viewing changes to src/dialogs/status.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-30 08:57:43 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630085743-l81fgbw9dehvl1ds
Tags: 0.11.1-1ubuntu1
* Merge to Debian unstable.
* Removed gnutls12 porting, this is upstream now.
* Only Ubuntu changes left:
  - Killed type-handling.
  - Add X-Ubuntu-Gettext-Domain to .desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Sessions status managment */
2
 
/* $Id: status.c,v 1.95.2.5 2005/09/14 13:15:39 jonas Exp $ */
 
1
/* Sessions status management */
3
2
 
4
3
#ifdef HAVE_CONFIG_H
5
4
#include "config.h"
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"
39
42
 
40
43
 
41
 
#define average_speed(progress) \
42
 
        ((longlong) (progress)->loaded * 10 / ((progress)->elapsed / 100))
43
 
 
44
 
#define current_speed(progress) \
45
 
        ((progress)->cur_loaded / (CURRENT_SPD_SEC * SPD_DISP_TIME / 1000))
46
 
 
47
 
#define estimated_time(progress) \
48
 
        (((progress)->size - (progress)->pos) \
49
 
         / ((longlong) (progress)->loaded * 10 / ((progress)->elapsed / 100)) \
50
 
         * 1000)
51
 
 
52
44
unsigned char *
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)
55
47
{
56
 
        struct string msg;
57
 
        int newlines = separator[strlen(separator) - 1] == '\n';
58
 
 
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));
62
 
        }
63
 
 
64
 
        if (!init_string(&msg)) return NULL;
65
 
 
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 */
69
 
 
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);
78
 
        }
79
 
 
80
 
        add_to_string(&msg, separator);
81
 
 
82
 
        if (wide && download->progress->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME) {
83
 
                add_to_string(&msg,
84
 
                              _(full ? (newlines ? N_("Average speed")
85
 
                                                 : N_("average speed"))
86
 
                                     : N_("avg"),
87
 
                                term));
88
 
        } else {
89
 
                add_to_string(&msg, _(newlines ? N_("Speed") : N_("speed"),
90
 
                                        term));
91
 
        }
92
 
 
93
 
        add_char_to_string(&msg, ' ');
94
 
        add_xnum_to_string(&msg, average_speed(download->progress));
95
 
        add_to_string(&msg, "/s");
96
 
 
97
 
        if (wide && download->progress->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME) {
98
 
                add_to_string(&msg, ", ");
99
 
                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");
104
 
        }
105
 
 
106
 
        if (wide) {
107
 
                /* Do the following only if there is room */
108
 
 
109
 
                add_to_string(&msg, separator);
110
 
 
111
 
                add_to_string(&msg, _(full ? (newlines ? N_("Elapsed time")
112
 
                                                       : N_("elapsed time"))
113
 
                                           : N_("ETT"),
114
 
                                   term));
115
 
                add_char_to_string(&msg, ' ');
116
 
                add_time_to_string(&msg, download->progress->elapsed);
117
 
        }
118
 
 
119
 
        if (download->progress->size >= 0 && download->progress->loaded > 0) {
120
 
                add_to_string(&msg, ", ");
121
 
                add_to_string(&msg, _(full ? N_("estimated time")
122
 
                                           : N_("ETA"),
123
 
                                      term));
124
 
                add_char_to_string(&msg, ' ');
125
 
                add_time_to_string(&msg, estimated_time(download->progress));
126
 
        }
127
 
 
128
 
        return msg.source;
 
50
                return stracpy(get_state_message(download->state, term));
 
51
        }
 
52
 
 
53
#ifdef CONFIG_BITTORRENT
 
54
        if (download->conn
 
55
            && download->conn->uri->protocol == PROTOCOL_BITTORRENT)
 
56
                return get_bittorrent_message(download, term, wide, full, separator);
 
57
#endif
 
58
 
 
59
        return get_progress_msg(download->progress, term, wide, full, separator);
129
60
}
130
61
 
131
 
 
132
62
#define show_tabs(option, tabs) (((option) > 0) && !((option) == 1 && (tabs) < 2))
133
63
 
134
64
void
292
222
                }
293
223
 
294
224
                if (!msg) {
295
 
                        /* FIXME: improve that, values should depend on
296
 
                         * context (leds, digital clock, ...). --Zas */
297
225
                        int full = term->width > 130;
298
226
                        int wide = term->width > 80;
299
227
 
340
268
                width = int_max(0, xend - msglen - tab_info_len - 1);
341
269
                if (width < 6) return;
342
270
                int_upper_bound(&width, 20);
343
 
                download_progress_bar(term, xend - width, term->height - 1,
344
 
                                      width, NULL, NULL,
345
 
                                      download->progress->pos, download->progress->size);
 
271
                draw_progress_bar(download->progress, term,
 
272
                                  xend - width, term->height - 1, width,
 
273
                                  NULL, NULL);
346
274
        }
347
275
}
348
276
 
418
346
                draw_box(term, &box, ' ', 0, color);
419
347
 
420
348
                if (download) {
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,
 
351
                                          msg, NULL);
424
352
                } else {
425
353
                        int msglen = int_min(strlen(msg), actual_tab_width);
426
354
 
547
475
                        find_in_cache(ses->doc_view->document->uri);
548
476
 
549
477
                if (cached) {
550
 
                        status->ssl_led->value = (cached->ssl_info)
551
 
                                            ? 'S' : '-';
 
478
                        if (cached->ssl_info)
 
479
                                set_led_value(status->ssl_led, 'S');
 
480
                        else
 
481
                                unset_led_value(status->ssl_led);
552
482
                } else {
553
483
                        /* FIXME: We should do this thing better. */
554
 
                        status->ssl_led->value = '?';
 
484
                        set_led_value(status->ssl_led, '?');
555
485
                }
556
486
        }
557
487
 
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');
560
490
        } else {
561
 
                unsigned char value = ses->insert_mode == INSERT_MODE_ON
562
 
                                    ? 'I' : '-';
563
 
                status->insert_mode_led->value = value;
 
491
                if (ses->insert_mode == INSERT_MODE_ON)
 
492
                        set_led_value(status->insert_mode_led, 'I');
 
493
                else
 
494
                        unset_led_value(status->insert_mode_led);
564
495
        }
565
496
 
566
497
        draw_leds(ses);