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

287 lines
7.2 KiB
C
Raw Normal View History

/* Info dialogs */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "elinks.h"
#include "bfu/dialog.h"
#include "cache/cache.h"
#include "config/kbdbind.h"
#include "config/options.h"
#include "dialogs/info.h"
#include "document/renderer.h"
#include "ecmascript/ecmascript.h"
#include "intl/gettext/libintl.h"
#include "main/select.h"
#include "main/timer.h"
#include "main/version.h"
#include "network/connection.h"
#include "session/session.h"
#include "terminal/terminal.h"
#include "util/conv.h"
#ifdef DEBUG_MEMLEAK
#include "util/memdebug.h"
#endif
#include "util/memlist.h"
#include "util/memory.h"
#include "util/string.h"
void
menu_about(struct terminal *term, void *xxx, void *xxxx)
{
info_box(term, MSGBOX_FREE_TEXT,
N_("About"), ALIGN_CENTER,
get_dyn_full_version(term, 1));
}
struct keys_toggle_info {
struct terminal *term;
int toggle;
};
static void
push_toggle_keys_display_button(void *data)
{
struct keys_toggle_info *info = data;
menu_keys(info->term, (void *) (long) !info->toggle, NULL);
}
void
menu_keys(struct terminal *term, void *d_, void *xxx)
{
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(menu_keys)] */
int d = (long) d_;
/* We scale by main mapping because it has the most actions */
action_id_T action_ids[MAIN_ACTIONS] = {
ACT_MAIN_MENU,
ACT_MAIN_QUIT,
ACT_MAIN_MOVE_LINK_NEXT,
ACT_MAIN_MOVE_LINK_PREV,
ACT_MAIN_SCROLL_DOWN,
ACT_MAIN_SCROLL_UP,
ACT_MAIN_SCROLL_LEFT,
ACT_MAIN_SCROLL_RIGHT,
ACT_MAIN_HISTORY_MOVE_BACK,
ACT_MAIN_GOTO_URL,
ACT_MAIN_GOTO_URL_CURRENT,
ACT_MAIN_DOCUMENT_INFO,
ACT_MAIN_HEADER_INFO,
ACT_MAIN_SEARCH,
ACT_MAIN_SEARCH_BACK,
ACT_MAIN_FIND_NEXT,
ACT_MAIN_FIND_NEXT_BACK,
ACT_MAIN_LINK_FOLLOW,
ACT_MAIN_LINK_DOWNLOAD,
ACT_MAIN_TOGGLE_HTML_PLAIN,
ACT_MAIN_NONE,
};
struct string keys;
struct keys_toggle_info *info;
info = mem_calloc(1, sizeof(*info));
if (!info || !init_string(&keys)) {
mem_free_if(info);
return;
}
info->term = term;
info->toggle = d;
if (info->toggle) {
action_id_T action_id;
int keymap_id;
for (action_id = 0; action_id < MAIN_ACTIONS - 1; action_id++) {
action_ids[action_id] = action_id + 1;
}
for (keymap_id = 0; keymap_id < KEYMAP_MAX; keymap_id++) {
add_actions_to_string(&keys, action_ids, keymap_id, term);
if (keymap_id + 1 < KEYMAP_MAX)
add_to_string(&keys, "\n\n");
/* Just a little reminder that the following code takes
* the easy way. */
assert((int) MAIN_ACTIONS > (int) EDIT_ACTIONS);
assert((int) EDIT_ACTIONS > (int) MENU_ACTIONS);
if (keymap_id == KEYMAP_MAIN) {
action_ids[EDIT_ACTIONS] = ACT_EDIT_NONE;
} else if (keymap_id == KEYMAP_EDIT) {
action_ids[MENU_ACTIONS] = ACT_MENU_NONE;
}
}
} else {
add_actions_to_string(&keys, action_ids, KEYMAP_MAIN, term);
}
msg_box(term, getml(info, (void *) NULL), MSGBOX_FREE_TEXT | MSGBOX_SCROLLABLE,
N_("Keys"), ALIGN_LEFT,
keys.source,
info, 2,
MSG_BOX_BUTTON(N_("~OK"), NULL, B_ENTER | B_ESC),
MSG_BOX_BUTTON(N_("~Toggle display"), push_toggle_keys_display_button, B_ENTER));
}
void
menu_copying(struct terminal *term, void *xxx, void *xxxx)
{
info_box(term, MSGBOX_FREE_TEXT,
N_("Copying"), ALIGN_CENTER,
msg_text(term, N_("ELinks %s\n"
"\n"
"%s"
"et al.\n"
"\n"
"This program is free software; you can redistribute it "
"and/or modify it under the terms of the GNU General Public "
"License as published by the Free Software Foundation, "
"specifically version 2 of the License."),
VERSION_STRING, COPYRIGHT_STRING));
}
static unsigned char *
get_resource_info(struct terminal *term, void *data)
{
struct string info;
long val;
unsigned longlong bigval;
if (!init_string(&info))
return NULL;
#define val_add(text) \
add_format_to_string(&info, text, val);
add_to_string(&info, _("Resources", term));
add_to_string(&info, ": ");
val = get_file_handles_count();
val_add(n_("%ld handle", "%ld handles", val, term));
add_to_string(&info, ", ");
val = get_timers_count();
val_add(n_("%ld timer", "%ld timers", val, term));
add_to_string(&info, ".\n");
add_to_string(&info, _("Connections", term));
add_to_string(&info, ": ");
val = get_connections_count();
val_add(n_("%ld connection", "%ld connections", val, term));
add_to_string(&info, ", ");
val = get_connections_connecting_count();
val_add(n_("%ld connecting", "%ld connecting", val, term));
add_to_string(&info, ", ");
val = get_connections_transfering_count();
val_add(n_("%ld transferring", "%ld transferring", val, term));
add_to_string(&info, ", ");
val = get_keepalive_connections_count();
val_add(n_("%ld keepalive", "%ld keepalive", val, term));
add_to_string(&info, ".\n");
add_to_string(&info, _("Memory cache", term));
add_to_string(&info, ": ");
/* What about just using Kibi/Mebi representation here? --jonas */
bigval = get_cache_size();
add_format_to_string(&info, n_("%ld byte", "%ld bytes", bigval, term), bigval);
add_to_string(&info, ", ");
val = get_cache_entry_count();
val_add(n_("%ld file", "%ld files", val, term));
add_to_string(&info, ", ");
val = get_cache_entry_used_count();
val_add(n_("%ld in use", "%ld in use", val, term));
add_to_string(&info, ", ");
val = get_cache_entry_loading_count();
val_add(n_("%ld loading", "%ld loading", val, term));
add_to_string(&info, ".\n");
add_to_string(&info, _("Document cache", term));
add_to_string(&info, ": ");
val = get_format_cache_size();
val_add(n_("%ld formatted", "%ld formatted", val, term));
add_to_string(&info, ", ");
val = get_format_cache_used_count();
val_add(n_("%ld in use", "%ld in use", val, term));
add_to_string(&info, ", ");
val = get_format_cache_refresh_count();
val_add(n_("%ld refreshing", "%ld refreshing", val, term));
add_to_string(&info, ".\n");
#ifdef CONFIG_ECMASCRIPT
add_to_string(&info, _("ECMAScript", term));
add_to_string(&info, ": ");
val = ecmascript_get_interpreter_count();
val_add(n_("%ld interpreter", "%ld interpreters", val, term));
add_to_string(&info, ".\n");
#endif
add_to_string(&info, _("Interlinking", term));
add_to_string(&info, ": ");
if (term->master)
add_to_string(&info, _("master terminal", term));
else
add_to_string(&info, _("slave terminal", term));
add_to_string(&info, ", ");
val = list_size(&terminals);
val_add(n_("%ld terminal", "%ld terminals", val, term));
add_to_string(&info, ", ");
val = list_size(&sessions);
val_add(n_("%ld session", "%ld sessions", val, term));
add_char_to_string(&info, '.');
#ifdef DEBUG_MEMLEAK
add_char_to_string(&info, '\n');
add_to_string(&info, _("Memory allocated", term));
add_to_string(&info, ": ");
val = mem_stats.amount;
val_add(n_("%ld byte", "%ld bytes", val, term));
add_to_string(&info, ", ");
val = mem_stats.true_amount - mem_stats.amount;
val_add(n_("%ld byte overhead", "%ld bytes overhead", val, term));
add_format_to_string(&info, " (%0.2f%%).",
(double) (mem_stats.true_amount - mem_stats.amount) / (double) mem_stats.amount * 100);
#endif /* DEBUG_MEMLEAK */
#undef val_add
return info.source;
}
void
resource_info(struct terminal *term)
{
refreshed_msg_box(term, 0, N_("Resources"), ALIGN_LEFT,
get_resource_info, NULL);
}