1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-10-06 04:45:17 -04:00
elinks/src/scripting/scripting.c
Kalle Olavi Niemitalo 84e19d0e4e 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 23:29:25 +03:00

101 lines
2.0 KiB
C

/* General scripting system functionality */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "elinks.h"
#include "bfu/msgbox.h"
#include "intl/gettext/libintl.h"
#include "main/module.h"
#include "scripting/scripting.h"
#include "session/session.h"
#include "terminal/terminal.h"
#include "terminal/window.h"
/* Backends dynamic area: */
#include "scripting/guile/guile.h"
#include "scripting/lua/lua.h"
#include "scripting/perl/perl.h"
#include "scripting/python/python.h"
#include "scripting/ruby/ruby.h"
#include "scripting/smjs/smjs.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
/* Error reporting. */
#if defined(CONFIG_SCRIPTING_RUBY) || defined(CONFIG_SCRIPTING_SPIDERMONKEY) || defined(CONFIG_SCRIPTING_PYTHON)
void
report_scripting_error(struct module *module, struct session *ses,
unsigned char *msg)
{
struct terminal *term;
struct string string;
if (!ses) {
term = get_default_terminal();
if (term == NULL) {
usrerror(gettext("[%s error] %s"),
gettext(module->name), msg);
sleep(3);
return;
}
} else {
term = ses->tab->term;
}
if (!init_string(&string))
return;
add_format_to_string(&string,
_("An error occurred while running a %s script", term),
_(module->name, term));
add_format_to_string(&string, ":\n\n%s", msg);
info_box(term, MSGBOX_NO_TEXT_INTL | MSGBOX_FREE_TEXT,
N_("Browser scripting error"), ALIGN_LEFT, string.source);
}
#endif
static struct module *scripting_modules[] = {
#ifdef CONFIG_SCRIPTING_LUA
&lua_scripting_module,
#endif
#ifdef CONFIG_SCRIPTING_GUILE
&guile_scripting_module,
#endif
#ifdef CONFIG_SCRIPTING_PERL
&perl_scripting_module,
#endif
#ifdef CONFIG_SCRIPTING_PYTHON
&python_scripting_module,
#endif
#ifdef CONFIG_SCRIPTING_RUBY
&ruby_scripting_module,
#endif
#ifdef CONFIG_SCRIPTING_SPIDERMONKEY
&smjs_scripting_module,
#endif
NULL,
};
struct module scripting_module = struct_module(
/* name: */ N_("Scripting"),
/* options: */ NULL,
/* events: */ NULL,
/* submodules: */ scripting_modules,
/* data: */ NULL,
/* init: */ NULL,
/* done: */ NULL
);