2005-09-15 09:58:31 -04:00
|
|
|
/* Download dialogs */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "bfu/dialog.h"
|
|
|
|
#include "bfu/hierbox.h"
|
|
|
|
#include "dialogs/download.h"
|
|
|
|
#include "dialogs/menu.h"
|
|
|
|
#include "dialogs/progress.h"
|
|
|
|
#include "dialogs/status.h"
|
2021-08-08 15:25:08 -04:00
|
|
|
#include "intl/libintl.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "main/object.h"
|
|
|
|
#include "main/select.h"
|
|
|
|
#include "network/connection.h"
|
|
|
|
#include "network/progress.h"
|
|
|
|
#include "protocol/bittorrent/dialogs.h"
|
|
|
|
#include "protocol/protocol.h"
|
|
|
|
#include "protocol/uri.h"
|
|
|
|
#include "session/download.h"
|
|
|
|
#include "session/session.h"
|
|
|
|
#include "terminal/draw.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "util/color.h"
|
|
|
|
#include "util/conv.h"
|
|
|
|
#include "util/error.h"
|
|
|
|
#include "util/memlist.h"
|
|
|
|
#include "util/memory.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
#include "util/time.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
undisplay_download(struct file_download *file_download)
|
|
|
|
{
|
|
|
|
/* We are maybe called from bottom halve so check consistency */
|
|
|
|
if (is_in_downloads_list(file_download) && file_download->dlg_data)
|
|
|
|
cancel_dialog(file_download->dlg_data, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_abort_download(struct file_download *file_download)
|
|
|
|
{
|
|
|
|
/* We are maybe called from bottom halve so check consistency */
|
|
|
|
if (is_in_downloads_list(file_download)) {
|
|
|
|
file_download->stop = 1;
|
|
|
|
abort_download(file_download);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
dlg_set_notify(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct file_download *file_download = (struct file_download *)dlg_data->dlg->udata;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
file_download->notify = 1;
|
bug 1054: Don't abort downloads when closing a terminal.
Except if they have external handlers.
When ELinks receives an event from a terminal, move that terminal to
the beginning of the global "terminals" list, so that the terminals
are always sorted according to the time of the most recent use. Note,
this affects the numbering of bookmark folders in session snapshots.
Add get_default_terminal(), which returns the most recently used
terminal that is still open. Use that in various places that
previously used terminals.prev or terminals.next. Four functions
fetch the size of the terminal for User-Agent headers, and
get_default_terminal() is not really right, but neither was the
original code; add TODO comments in those functions.
When the user chooses "Background and Notify", associate the download
with the terminal where the dialog box is. So any later messages will
then appear in that terminal, if it is still open. However, don't
change the terminal if the download has an external handler.
When a download gets some data, don't immediately check the associated
terminal. Instead, wait for the download to end. Then, if the
terminal of the download has been closed, use get_default_terminal()
instead. If there is no default terminal either, just skip any
message boxes.
2008-10-15 04:05:43 -04:00
|
|
|
/* The user of this terminal wants to be notified about the
|
|
|
|
* download. Make this also the terminal where the
|
|
|
|
* notification appears. However, keep the original terminal
|
|
|
|
* for external handlers, because the handler may have been
|
|
|
|
* chosen based on the environment variables (usually TERM or
|
|
|
|
* DISPLAY) of the ELinks process in that terminal. */
|
|
|
|
if (!file_download->external_handler)
|
|
|
|
file_download->term = dlg_data->win->term;
|
|
|
|
|
2020-09-13 10:12:57 -04:00
|
|
|
#ifdef CONFIG_BITTORRENT
|
2005-09-15 09:58:31 -04:00
|
|
|
if (file_download->uri->protocol == PROTOCOL_BITTORRENT)
|
|
|
|
set_bittorrent_notify_on_completion(&file_download->download,
|
|
|
|
file_download->term);
|
|
|
|
#endif
|
|
|
|
undisplay_download(file_download);
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
dlg_abort_download(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct file_download *file_download = (struct file_download *)dlg_data->dlg->udata;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
object_unlock(file_download);
|
|
|
|
register_bottom_half(do_abort_download, file_download);
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
push_delete_button(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct file_download *file_download = (struct file_download *)dlg_data->dlg->udata;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2016-04-20 12:57:32 -04:00
|
|
|
file_download->delete_ = 1;
|
2020-09-13 10:12:57 -04:00
|
|
|
#ifdef CONFIG_BITTORRENT
|
2005-09-15 09:58:31 -04:00
|
|
|
if (file_download->uri->protocol == PROTOCOL_BITTORRENT)
|
|
|
|
set_bittorrent_files_for_deletion(&file_download->download);
|
|
|
|
#endif
|
|
|
|
object_unlock(file_download);
|
|
|
|
register_bottom_half(do_abort_download, file_download);
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
dlg_undisplay_download(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct file_download *file_download = (struct file_download *)dlg_data->dlg->udata;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
object_unlock(file_download);
|
|
|
|
register_bottom_half(undisplay_download, file_download);
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
download_abort_function(struct dialog_data *dlg_data)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct file_download *file_download = (struct file_download *)dlg_data->dlg->udata;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
file_download->dlg_data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
download_dialog_layouter(struct dialog_data *dlg_data)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct file_download *file_download = (struct file_download *)dlg_data->dlg->udata;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct terminal *term = dlg_data->win->term;
|
|
|
|
int w = dialog_max_width(term);
|
|
|
|
int rw = w;
|
|
|
|
int x, y = 0;
|
|
|
|
int url_len;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *url;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct download *download = &file_download->download;
|
2022-10-16 09:18:34 -04:00
|
|
|
struct color_pair *dialog_text_color = get_bfu_color(term, "dialog.text");
|
2021-01-02 10:20:27 -05:00
|
|
|
char *msg = get_download_msg(download, term, 1, 1, "\n");
|
2005-09-15 09:58:31 -04:00
|
|
|
int show_meter = (download_is_progressing(download)
|
|
|
|
&& download->progress->size >= 0);
|
2020-09-13 10:12:57 -04:00
|
|
|
#ifdef CONFIG_BITTORRENT
|
2005-09-19 10:02:27 -04:00
|
|
|
int bittorrent = (file_download->uri->protocol == PROTOCOL_BITTORRENT
|
2008-08-03 08:24:26 -04:00
|
|
|
&& (show_meter || is_in_state(download->state, S_RESUME)));
|
2005-09-19 10:02:27 -04:00
|
|
|
#endif
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2008-10-12 07:01:05 -04:00
|
|
|
redraw_windows(REDRAW_BEHIND_WINDOW, dlg_data->win);
|
2005-09-15 09:58:31 -04:00
|
|
|
file_download->dlg_data = dlg_data;
|
|
|
|
|
|
|
|
if (!msg) return;
|
|
|
|
|
|
|
|
url = get_uri_string(file_download->uri, URI_PUBLIC);
|
|
|
|
if (!url) {
|
|
|
|
mem_free(msg);
|
|
|
|
return;
|
|
|
|
}
|
2006-09-17 09:12:47 -04:00
|
|
|
#ifdef CONFIG_UTF8
|
2007-05-20 08:31:02 -04:00
|
|
|
if (term->utf8_cp)
|
2006-03-12 19:54:34 -05:00
|
|
|
decode_uri(url);
|
|
|
|
else
|
2006-09-17 09:12:47 -04:00
|
|
|
#endif /* CONFIG_UTF8 */
|
2006-03-12 19:54:34 -05:00
|
|
|
decode_uri_for_display(url);
|
2005-09-15 09:58:31 -04:00
|
|
|
url_len = strlen(url);
|
|
|
|
|
|
|
|
if (show_meter) {
|
|
|
|
int_lower_bound(&w, DOWN_DLG_MIN);
|
|
|
|
}
|
|
|
|
|
2022-10-16 09:18:34 -04:00
|
|
|
dlg_format_text_do(dlg_data, url, 0, &y, w, &rw,
|
|
|
|
dialog_text_color, ALIGN_LEFT, 1);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
y++;
|
|
|
|
if (show_meter) y += 2;
|
|
|
|
|
2020-09-13 10:12:57 -04:00
|
|
|
#ifdef CONFIG_BITTORRENT
|
2005-09-19 10:02:27 -04:00
|
|
|
if (bittorrent) y += 2;
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|
2022-10-16 09:18:34 -04:00
|
|
|
dlg_format_text_do(dlg_data, msg, 0, &y, w, &rw,
|
|
|
|
dialog_text_color, ALIGN_LEFT, 1);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
y++;
|
2008-09-07 12:27:06 -04:00
|
|
|
dlg_format_buttons(dlg_data, dlg_data->widgets_data,
|
2005-09-15 09:58:31 -04:00
|
|
|
dlg_data->number_of_widgets, 0, &y, w,
|
2006-03-06 00:01:12 -05:00
|
|
|
&rw, ALIGN_CENTER, 1);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
draw_dialog(dlg_data, w, y);
|
|
|
|
|
|
|
|
w = rw;
|
|
|
|
if (url_len > w) {
|
|
|
|
/* Truncate too long urls */
|
|
|
|
url_len = w;
|
|
|
|
url[url_len] = '\0';
|
|
|
|
if (url_len > 4) {
|
|
|
|
url[--url_len] = '.';
|
|
|
|
url[--url_len] = '.';
|
|
|
|
url[--url_len] = '.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
y = dlg_data->box.y + DIALOG_TB + 1;
|
|
|
|
x = dlg_data->box.x + DIALOG_LB;
|
2022-10-16 09:18:34 -04:00
|
|
|
dlg_format_text_do(dlg_data, url, x, &y, w, NULL,
|
|
|
|
dialog_text_color, ALIGN_LEFT, 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (show_meter) {
|
|
|
|
y++;
|
2022-10-16 09:18:34 -04:00
|
|
|
draw_progress_bar(download->progress, term, x, y, w, NULL, NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
y++;
|
|
|
|
}
|
|
|
|
|
2020-09-13 10:12:57 -04:00
|
|
|
#ifdef CONFIG_BITTORRENT
|
2005-09-19 10:02:27 -04:00
|
|
|
if (bittorrent) {
|
2005-09-15 09:58:31 -04:00
|
|
|
y++;
|
2022-10-16 09:18:34 -04:00
|
|
|
draw_bittorrent_piece_progress(download, term, x, y, w, NULL, NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
y++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
y++;
|
2022-10-16 09:18:34 -04:00
|
|
|
dlg_format_text_do(dlg_data, msg, x, &y, w, NULL,
|
|
|
|
dialog_text_color, ALIGN_LEFT, 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
y++;
|
2008-09-07 12:27:06 -04:00
|
|
|
dlg_format_buttons(dlg_data, dlg_data->widgets_data,
|
2005-09-15 09:58:31 -04:00
|
|
|
dlg_data->number_of_widgets, x, &y, w,
|
2006-03-06 00:01:12 -05:00
|
|
|
NULL, ALIGN_CENTER, 0);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
mem_free(url);
|
|
|
|
mem_free(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
display_download(struct terminal *term, struct file_download *file_download,
|
|
|
|
struct session *ses)
|
|
|
|
{
|
Here is a framework that detects cases where a PO file assigns
the same accelerator key to multiple buttons in a dialog box or
to multiple items in a menu. ELinks already has some support for
this but it requires the translator to run ELinks and manually
scan through all menus and dialogs. The attached changes make it
possible to quickly detect and list any conflicts, including ones
that can only occur on operating systems or configurations that
the translator is not currently using.
The changes have no immediate effect on the elinks executable or
the MO files. PO files become larger, however.
The scheme works like this:
- Like before, accelerator keys in translatable strings are
tagged with the tilde (~) character.
- Whenever a C source file defines an accelerator key, it must
assign one or more named "contexts" to it. The translations in
the PO files inherit these contexts. If multiple strings use
the same accelerator (case insensitive) in the same context,
that's a conflict and can be detected automatically.
- The contexts are defined with "gettext_accelerator_context"
comments in source files. These comments delimit regions where
all translatable strings containing tildes are given the same
contexts. There must be one special comment at the top of the
region; it lists the contexts assigned to that region. The
region automatically ends at the end of the function (found
with regexp /^\}/), but it can also be closed explicitly with
another special comment. The comments are formatted like this:
/* [gettext_accelerator_context(foo, bar, baz)]
begins a region that uses the contexts "foo", "bar", and "baz".
The comma is the delimiter; whitespace is optional.
[gettext_accelerator_context()]
ends the region. */
The scripts don't currently check whether this syntax occurs
inside or outside comments.
- The names of contexts consist of C identifiers delimited with
periods. I typically used the name of a function that sets
up a dialog, or the name of an array where the items of a
menu are listed. There is a special feature for static
functions: if the name begins with a period, then the period
will be replaced with the name of the source file and a colon.
- If a menu is programmatically generated from multiple parts,
of which some are never used together, so that it is safe to
use the same accelerators in them, then it is necessary to
define multiple contexts for the same menu. link_menu() in
src/viewer/text/link.c is the most complex example of this.
- During make update-po:
- A Perl script (po/gather-accelerator-contexts.pl) reads
po/elinks.pot, scans the source files listed in it for
"gettext_accelerator_context" comments, and rewrites
po/elinks.pot with "accelerator_context" comments that
indicate the contexts of each msgid: the union of all
contexts of all of its uses in the source files. It also
removes any "gettext_accelerator_context" comments that
xgettext --add-comments has copied to elinks.pot.
- If po/gather-accelerator-contexts.pl does not find any
contexts for some use of an msgid that seems to contain an
accelerator (because it contains a tilde), it warns. If the
tilde refers to e.g. "~/.elinks" and does not actually mark
an accelerator, the warning can be silenced by specifying the
special context "IGNORE", which the script otherwise ignores.
- msgmerge copies the "accelerator_context" comments from
po/elinks.pot to po/*.po. Translators do not edit those
comments.
- During make check-po:
- Another Perl script (po/check-accelerator-contexts.pl) reads
po/*.po and keeps track of which accelerators have been bound
in each context. It warns about any conflicts it finds.
This script does not access the C source files; thus it does
not matter if the line numbers in "#:" lines are out of date.
This implementation is not perfect and I am not proposing to
add it to the main source tree at this time. Specifically:
- It introduces compile-time dependencies on Perl and Locale::PO.
There should be a configure-time or compile-time check so that
the new features are skipped if the prerequisites are missing.
- When the scripts include msgstr strings in warnings, they
should transcode them from the charset of the PO file to the
one specified by the user's locale.
- It is not adequately documented (well, except perhaps here).
- po/check-accelerator-contexts.pl reports the same conflict
multiple times if it occurs in multiple contexts.
- The warning messages should include line numbers, so that users
of Emacs could conveniently edit the conflicting part of the PO
file. This is not feasible with the current version of
Locale::PO.
- Locale::PO does not understand #~ lines and spews warnings
about them. There is an ugly hack to hide these warnings.
- Jonas Fonseca suggested the script could propose accelerators
that are still available. This has not been implemented.
There are three files attached:
- po/gather-accelerator-contexts.pl: Augments elinks.pot with
context information.
- po/check-accelerator-contexts.pl: Checks conflicts.
- accelerator-contexts.diff: Makes po/Makefile run the scripts,
and adds special comments to source files.
2005-12-04 18:38:29 -05:00
|
|
|
/* [gettext_accelerator_context(display_download)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct dialog *dlg;
|
|
|
|
|
|
|
|
if (!is_in_downloads_list(file_download))
|
|
|
|
return;
|
|
|
|
|
2020-09-19 04:11:09 -04:00
|
|
|
if (file_download->uri->protocol == PROTOCOL_DATA)
|
|
|
|
return;
|
|
|
|
|
2020-09-13 10:12:57 -04:00
|
|
|
#ifdef CONFIG_BITTORRENT
|
2005-09-15 09:58:31 -04:00
|
|
|
#define DOWNLOAD_WIDGETS_COUNT 5
|
|
|
|
#else
|
|
|
|
#define DOWNLOAD_WIDGETS_COUNT 4
|
|
|
|
#endif
|
|
|
|
|
|
|
|
dlg = calloc_dialog(DOWNLOAD_WIDGETS_COUNT, 0);
|
|
|
|
if (!dlg) return;
|
|
|
|
|
|
|
|
undisplay_download(file_download);
|
|
|
|
file_download->ses = ses;
|
|
|
|
dlg->title = _("Download", term);
|
|
|
|
dlg->layouter = download_dialog_layouter;
|
|
|
|
dlg->abort = download_abort_function;
|
|
|
|
dlg->udata = file_download;
|
|
|
|
|
|
|
|
object_lock(file_download);
|
|
|
|
|
|
|
|
add_dlg_button(dlg, _("~Background", term), B_ENTER | B_ESC, dlg_undisplay_download, NULL);
|
|
|
|
add_dlg_button(dlg, _("Background with ~notify", term), B_ENTER | B_ESC, dlg_set_notify, NULL);
|
|
|
|
|
2020-09-13 10:12:57 -04:00
|
|
|
#ifdef CONFIG_BITTORRENT
|
2005-09-15 09:58:31 -04:00
|
|
|
if (file_download->uri->protocol == PROTOCOL_BITTORRENT)
|
|
|
|
add_dlg_button(dlg, _("~Info", term), B_ENTER | B_ESC, dlg_show_bittorrent_info, NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
add_dlg_button(dlg, _("~Abort", term), 0, dlg_abort_download, NULL);
|
|
|
|
|
|
|
|
/* Downloads scheduled to be opened by external handlers are always
|
|
|
|
* deleted. */
|
|
|
|
if (!file_download->external_handler) {
|
|
|
|
add_dlg_button(dlg, _("Abort and ~delete file", term), 0, push_delete_button, NULL);
|
|
|
|
}
|
|
|
|
|
2020-09-13 10:12:57 -04:00
|
|
|
#ifdef CONFIG_BITTORRENT
|
2005-09-15 09:58:31 -04:00
|
|
|
add_dlg_end(dlg, DOWNLOAD_WIDGETS_COUNT - !!file_download->external_handler
|
|
|
|
- (file_download->uri->protocol != PROTOCOL_BITTORRENT));
|
|
|
|
#else
|
|
|
|
add_dlg_end(dlg, DOWNLOAD_WIDGETS_COUNT - !!file_download->external_handler);
|
|
|
|
#endif
|
|
|
|
|
2007-03-11 06:41:17 -04:00
|
|
|
do_dialog(term, dlg, getml(dlg, (void *) NULL));
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The download manager */
|
|
|
|
|
|
|
|
static void
|
|
|
|
lock_file_download(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
object_lock((struct file_download *) item->udata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unlock_file_download(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
object_unlock((struct file_download *) item->udata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_file_download_used(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
return is_object_used((struct file_download *) item->udata);
|
|
|
|
}
|
|
|
|
|
2021-01-02 10:20:27 -05:00
|
|
|
static char *
|
2005-09-15 09:58:31 -04:00
|
|
|
get_file_download_text(struct listbox_item *item, struct terminal *term)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct file_download *file_download = (struct file_download *)item->udata;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *uristring;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
uristring = get_uri_string(file_download->uri, URI_PUBLIC);
|
2006-03-12 19:54:34 -05:00
|
|
|
if (uristring) {
|
2006-09-17 09:12:47 -04:00
|
|
|
#ifdef CONFIG_UTF8
|
2007-05-20 08:31:02 -04:00
|
|
|
if (term->utf8_cp)
|
2006-03-12 19:54:34 -05:00
|
|
|
decode_uri(uristring);
|
|
|
|
else
|
2006-09-17 09:12:47 -04:00
|
|
|
#endif /* CONFIG_UTF8 */
|
2006-03-12 19:54:34 -05:00
|
|
|
decode_uri_for_display(uristring);
|
|
|
|
}
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
return uristring;
|
|
|
|
}
|
|
|
|
|
2021-01-02 10:20:27 -05:00
|
|
|
static char *
|
2005-09-15 09:58:31 -04:00
|
|
|
get_file_download_info(struct listbox_item *item, struct terminal *term)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct uri *
|
|
|
|
get_file_download_uri(struct listbox_item *item)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct file_download *file_download = (struct file_download *)item->udata;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
return get_uri_reference(file_download->uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct listbox_item *
|
|
|
|
get_file_download_root(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
can_delete_file_download(struct listbox_item *item)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
delete_file_download(struct listbox_item *item, int last)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct file_download *file_download = (struct file_download *)item->udata;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
assert(!is_object_used(file_download));
|
|
|
|
register_bottom_half(do_abort_download, file_download);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum dlg_refresh_code
|
|
|
|
refresh_file_download(struct dialog_data *dlg_data, void *data)
|
|
|
|
{
|
|
|
|
/* Always refresh (until we keep finished downloads) */
|
|
|
|
return are_there_downloads() ? REFRESH_DIALOG : REFRESH_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Make it configurable */
|
|
|
|
#define DOWNLOAD_METER_WIDTH 15
|
|
|
|
#define DOWNLOAD_URI_PERCENTAGE 50
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_file_download(struct listbox_item *item, struct listbox_context *context,
|
|
|
|
int x, int y, int width)
|
|
|
|
{
|
2022-01-25 11:39:39 -05:00
|
|
|
struct file_download *file_download = (struct file_download *)item->udata;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct download *download = &file_download->download;
|
2022-02-17 15:24:45 -05:00
|
|
|
const char *stylename;
|
2022-10-16 09:18:34 -04:00
|
|
|
struct color_pair *color;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *text;
|
2005-09-15 09:58:31 -04:00
|
|
|
int length;
|
|
|
|
int trimmedlen;
|
|
|
|
int meter = DOWNLOAD_METER_WIDTH;
|
|
|
|
|
|
|
|
/* We have nothing to work with */
|
|
|
|
if (width < 4) return;
|
|
|
|
|
|
|
|
stylename = (item == context->box->sel) ? "menu.selected"
|
|
|
|
: ((item->marked) ? "menu.marked"
|
|
|
|
: "menu.normal");
|
|
|
|
|
2022-10-16 09:18:34 -04:00
|
|
|
color = get_bfu_color(context->term, stylename);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2006-07-26 17:28:40 -04:00
|
|
|
text = get_file_download_text(item, context->term);
|
2005-09-15 09:58:31 -04:00
|
|
|
if (!text) return;
|
|
|
|
|
|
|
|
length = strlen(text);
|
|
|
|
/* Show atleast the required percentage of the URI */
|
|
|
|
if (length * DOWNLOAD_URI_PERCENTAGE / 100 < width - meter - 4) {
|
|
|
|
trimmedlen = int_min(length, width - meter - 4);
|
|
|
|
} else {
|
|
|
|
trimmedlen = int_min(length, width - 3);
|
|
|
|
}
|
|
|
|
|
2022-10-16 09:18:34 -04:00
|
|
|
draw_text(context->term, x, y, text, trimmedlen, 0, color);
|
2005-09-15 09:58:31 -04:00
|
|
|
if (trimmedlen < length) {
|
2022-10-16 09:18:34 -04:00
|
|
|
draw_text(context->term, x + trimmedlen, y, "...", 3, 0, color);
|
2005-09-15 09:58:31 -04:00
|
|
|
trimmedlen += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
mem_free(text);
|
|
|
|
|
|
|
|
if (!download->progress
|
|
|
|
|| download->progress->size < 0
|
2008-08-03 08:24:26 -04:00
|
|
|
|| !is_in_state(download->state, S_TRANS)
|
2005-09-15 09:58:31 -04:00
|
|
|
|| !has_progress(download->progress)) {
|
|
|
|
/* TODO: Show trimmed error message. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dialog_has_refresh(context->dlg_data))
|
|
|
|
refresh_dialog(context->dlg_data, refresh_file_download, NULL);
|
|
|
|
|
|
|
|
if (trimmedlen + meter >= width) return;
|
|
|
|
|
|
|
|
x += width - meter;
|
|
|
|
|
2022-10-16 09:18:34 -04:00
|
|
|
draw_progress_bar(download->progress, context->term, x, y, meter, NULL, NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct listbox_ops_messages download_messages = {
|
|
|
|
/* cant_delete_item */
|
|
|
|
N_("Sorry, but download \"%s\" cannot be interrupted."),
|
|
|
|
/* cant_delete_used_item */
|
|
|
|
N_("Sorry, but download \"%s\" is being used by something else."),
|
|
|
|
/* cant_delete_folder */
|
|
|
|
NULL,
|
|
|
|
/* cant_delete_used_folder */
|
|
|
|
NULL,
|
|
|
|
/* delete_marked_items_title */
|
|
|
|
N_("Interrupt marked downloads"),
|
|
|
|
/* delete_marked_items */
|
|
|
|
N_("Interrupt marked downloads?"),
|
|
|
|
/* delete_folder_title */
|
|
|
|
NULL,
|
|
|
|
/* delete_folder */
|
|
|
|
NULL,
|
|
|
|
/* delete_item_title */
|
|
|
|
N_("Interrupt download"),
|
2006-05-27 01:51:24 -04:00
|
|
|
/* delete_item; xgettext:c-format */
|
2005-09-15 09:58:31 -04:00
|
|
|
N_("Interrupt this download?"),
|
|
|
|
/* clear_all_items_title */
|
|
|
|
N_("Interrupt all downloads"),
|
|
|
|
/* clear_all_items_title */
|
|
|
|
N_("Do you really want to interrupt all downloads?"),
|
|
|
|
};
|
|
|
|
|
2007-02-04 08:17:49 -05:00
|
|
|
static const struct listbox_ops downloads_listbox_ops = {
|
2005-09-15 09:58:31 -04:00
|
|
|
lock_file_download,
|
|
|
|
unlock_file_download,
|
|
|
|
is_file_download_used,
|
|
|
|
get_file_download_text,
|
|
|
|
get_file_download_info,
|
|
|
|
get_file_download_uri,
|
|
|
|
get_file_download_root,
|
|
|
|
NULL,
|
|
|
|
can_delete_file_download,
|
|
|
|
delete_file_download,
|
|
|
|
draw_file_download,
|
|
|
|
&download_messages,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static widget_handler_status_T
|
|
|
|
push_info_button(struct dialog_data *dlg_data, struct widget_data *button)
|
|
|
|
{
|
|
|
|
struct listbox_data *box = get_dlg_listbox_data(dlg_data);
|
|
|
|
struct terminal *term = dlg_data->win->term;
|
2022-01-25 11:39:39 -05:00
|
|
|
struct session *ses = (struct session *)dlg_data->dlg->udata;
|
|
|
|
struct file_download *file_download = (struct file_download *)(box->sel ? box->sel->udata : NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
assert(ses);
|
|
|
|
|
|
|
|
if (!file_download) return EVENT_PROCESSED;
|
|
|
|
|
|
|
|
/* Don't layer on top of the download manager */
|
|
|
|
delete_window(dlg_data->win);
|
|
|
|
|
|
|
|
display_download(term, file_download, ses);
|
|
|
|
return EVENT_PROCESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* TODO: Ideas for buttons .. should be pretty trivial most of it
|
|
|
|
*
|
|
|
|
* - Resume or something that will use some goto like handler
|
|
|
|
* - Open button that can be used to set file_download->prog.
|
|
|
|
* - Toggle notify button
|
|
|
|
*/
|
2007-02-04 06:54:07 -05:00
|
|
|
static const struct hierbox_browser_button download_buttons[] = {
|
Here is a framework that detects cases where a PO file assigns
the same accelerator key to multiple buttons in a dialog box or
to multiple items in a menu. ELinks already has some support for
this but it requires the translator to run ELinks and manually
scan through all menus and dialogs. The attached changes make it
possible to quickly detect and list any conflicts, including ones
that can only occur on operating systems or configurations that
the translator is not currently using.
The changes have no immediate effect on the elinks executable or
the MO files. PO files become larger, however.
The scheme works like this:
- Like before, accelerator keys in translatable strings are
tagged with the tilde (~) character.
- Whenever a C source file defines an accelerator key, it must
assign one or more named "contexts" to it. The translations in
the PO files inherit these contexts. If multiple strings use
the same accelerator (case insensitive) in the same context,
that's a conflict and can be detected automatically.
- The contexts are defined with "gettext_accelerator_context"
comments in source files. These comments delimit regions where
all translatable strings containing tildes are given the same
contexts. There must be one special comment at the top of the
region; it lists the contexts assigned to that region. The
region automatically ends at the end of the function (found
with regexp /^\}/), but it can also be closed explicitly with
another special comment. The comments are formatted like this:
/* [gettext_accelerator_context(foo, bar, baz)]
begins a region that uses the contexts "foo", "bar", and "baz".
The comma is the delimiter; whitespace is optional.
[gettext_accelerator_context()]
ends the region. */
The scripts don't currently check whether this syntax occurs
inside or outside comments.
- The names of contexts consist of C identifiers delimited with
periods. I typically used the name of a function that sets
up a dialog, or the name of an array where the items of a
menu are listed. There is a special feature for static
functions: if the name begins with a period, then the period
will be replaced with the name of the source file and a colon.
- If a menu is programmatically generated from multiple parts,
of which some are never used together, so that it is safe to
use the same accelerators in them, then it is necessary to
define multiple contexts for the same menu. link_menu() in
src/viewer/text/link.c is the most complex example of this.
- During make update-po:
- A Perl script (po/gather-accelerator-contexts.pl) reads
po/elinks.pot, scans the source files listed in it for
"gettext_accelerator_context" comments, and rewrites
po/elinks.pot with "accelerator_context" comments that
indicate the contexts of each msgid: the union of all
contexts of all of its uses in the source files. It also
removes any "gettext_accelerator_context" comments that
xgettext --add-comments has copied to elinks.pot.
- If po/gather-accelerator-contexts.pl does not find any
contexts for some use of an msgid that seems to contain an
accelerator (because it contains a tilde), it warns. If the
tilde refers to e.g. "~/.elinks" and does not actually mark
an accelerator, the warning can be silenced by specifying the
special context "IGNORE", which the script otherwise ignores.
- msgmerge copies the "accelerator_context" comments from
po/elinks.pot to po/*.po. Translators do not edit those
comments.
- During make check-po:
- Another Perl script (po/check-accelerator-contexts.pl) reads
po/*.po and keeps track of which accelerators have been bound
in each context. It warns about any conflicts it finds.
This script does not access the C source files; thus it does
not matter if the line numbers in "#:" lines are out of date.
This implementation is not perfect and I am not proposing to
add it to the main source tree at this time. Specifically:
- It introduces compile-time dependencies on Perl and Locale::PO.
There should be a configure-time or compile-time check so that
the new features are skipped if the prerequisites are missing.
- When the scripts include msgstr strings in warnings, they
should transcode them from the charset of the PO file to the
one specified by the user's locale.
- It is not adequately documented (well, except perhaps here).
- po/check-accelerator-contexts.pl reports the same conflict
multiple times if it occurs in multiple contexts.
- The warning messages should include line numbers, so that users
of Emacs could conveniently edit the conflicting part of the PO
file. This is not feasible with the current version of
Locale::PO.
- Locale::PO does not understand #~ lines and spews warnings
about them. There is an ugly hack to hide these warnings.
- Jonas Fonseca suggested the script could propose accelerators
that are still available. This has not been implemented.
There are three files attached:
- po/gather-accelerator-contexts.pl: Augments elinks.pot with
context information.
- po/check-accelerator-contexts.pl: Checks conflicts.
- accelerator-contexts.diff: Makes po/Makefile run the scripts,
and adds special comments to source files.
2005-12-04 18:38:29 -05:00
|
|
|
/* [gettext_accelerator_context(.download_buttons)] */
|
2005-09-15 09:58:31 -04:00
|
|
|
{ N_("~Info"), push_info_button },
|
|
|
|
{ N_("~Abort"), push_hierbox_delete_button },
|
|
|
|
#if 0
|
|
|
|
/* This requires more work to make locking work and query the user */
|
|
|
|
{ N_("Abort and delete file"), push_delete_button },
|
|
|
|
#endif
|
|
|
|
{ N_("C~lear"), push_hierbox_clear_button },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct_hierbox_browser(
|
|
|
|
download_browser,
|
|
|
|
N_("Download manager"),
|
|
|
|
download_buttons,
|
|
|
|
&downloads_listbox_ops
|
|
|
|
);
|
|
|
|
|
|
|
|
void
|
|
|
|
download_manager(struct session *ses)
|
|
|
|
{
|
|
|
|
hierbox_browser(&download_browser, ses);
|
|
|
|
|
|
|
|
/* FIXME: It's workaround for bug 397. Real fix is needed. */
|
|
|
|
download_browser.do_not_save_state = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
init_download_display(struct file_download *file_download)
|
|
|
|
{
|
|
|
|
file_download->box_item = add_listbox_leaf(&download_browser, NULL,
|
|
|
|
file_download);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
done_download_display(struct file_download *file_download)
|
|
|
|
{
|
|
|
|
if (file_download->box_item) {
|
|
|
|
done_listbox_item(&download_browser, file_download->box_item);
|
|
|
|
file_download->box_item = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|