mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
4c2831677a
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.
247 lines
5.8 KiB
C
247 lines
5.8 KiB
C
/* Cache-related dialogs */
|
|
|
|
#ifndef _GNU_SOURCE
|
|
#define _GNU_SOURCE /* XXX: we _WANT_ strcasestr() ! */
|
|
#endif
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
#include "elinks.h"
|
|
|
|
#include "bfu/dialog.h"
|
|
#include "cache/cache.h"
|
|
#include "cache/dialogs.h"
|
|
#include "dialogs/edit.h"
|
|
#include "intl/gettext/libintl.h"
|
|
#include "main/object.h"
|
|
#include "protocol/uri.h"
|
|
#include "session/session.h"
|
|
#include "terminal/draw.h"
|
|
#include "terminal/terminal.h"
|
|
#include "util/conv.h"
|
|
#include "util/memory.h"
|
|
#include "util/string.h"
|
|
|
|
|
|
static void
|
|
lock_cache_entry(struct listbox_item *item)
|
|
{
|
|
object_lock((struct cache_entry *) item->udata);
|
|
}
|
|
|
|
static void
|
|
unlock_cache_entry(struct listbox_item *item)
|
|
{
|
|
object_unlock((struct cache_entry *) item->udata);
|
|
}
|
|
|
|
static int
|
|
is_cache_entry_used(struct listbox_item *item)
|
|
{
|
|
return is_object_used((struct cache_entry *) item->udata);
|
|
}
|
|
|
|
static unsigned char *
|
|
get_cache_entry_text(struct listbox_item *item, struct terminal *term)
|
|
{
|
|
struct cache_entry *cached = item->udata;
|
|
|
|
return get_uri_string(cached->uri, URI_PUBLIC);
|
|
}
|
|
|
|
static unsigned char *
|
|
get_cache_entry_info(struct listbox_item *item, struct terminal *term)
|
|
{
|
|
struct cache_entry *cached = item->udata;
|
|
struct string msg;
|
|
|
|
if (item->type == BI_FOLDER) return NULL;
|
|
if (!init_string(&msg)) return NULL;
|
|
|
|
add_to_string(&msg, _("URL", term));
|
|
add_to_string(&msg, ": ");
|
|
add_uri_to_string(&msg, cached->uri, URI_PUBLIC);
|
|
|
|
/* No need to use compare_uri() here we only want to check whether they
|
|
* point to the same URI. */
|
|
if (cached->proxy_uri != cached->uri) {
|
|
add_format_to_string(&msg, "\n%s: ", _("Proxy URL", term));
|
|
add_uri_to_string(&msg, cached->proxy_uri, URI_PUBLIC);
|
|
}
|
|
|
|
if (cached->redirect) {
|
|
add_format_to_string(&msg, "\n%s: ", _("Redirect", term));
|
|
add_uri_to_string(&msg, cached->redirect, URI_PUBLIC);
|
|
|
|
if (cached->redirect_get) {
|
|
add_to_string(&msg, " (GET)");
|
|
}
|
|
}
|
|
|
|
add_format_to_string(&msg, "\n%s: %" PRId64, _("Size", term),
|
|
cached->length);
|
|
add_format_to_string(&msg, "\n%s: %" PRId64, _("Loaded size", term),
|
|
cached->data_size);
|
|
if (cached->content_type) {
|
|
add_format_to_string(&msg, "\n%s: %s", _("Content type", term),
|
|
cached->content_type);
|
|
}
|
|
if (cached->last_modified) {
|
|
add_format_to_string(&msg, "\n%s: %s", _("Last modified", term),
|
|
cached->last_modified);
|
|
}
|
|
if (cached->etag) {
|
|
add_format_to_string(&msg, "\n%s: %s", "ETag",
|
|
cached->etag);
|
|
}
|
|
if (cached->ssl_info) {
|
|
add_format_to_string(&msg, "\n%s: %s", _("SSL Cipher", term),
|
|
cached->ssl_info);
|
|
}
|
|
if (cached->encoding_info) {
|
|
add_format_to_string(&msg, "\n%s: %s", _("Encoding", term),
|
|
cached->encoding_info);
|
|
}
|
|
|
|
if (cached->incomplete || !cached->valid) {
|
|
add_char_to_string(&msg, '\n');
|
|
add_to_string(&msg, _("Flags", term));
|
|
add_to_string(&msg, ": ");
|
|
if (cached->incomplete) {
|
|
add_to_string(&msg, _("incomplete", term));
|
|
add_char_to_string(&msg, ' ');
|
|
}
|
|
if (!cached->valid) add_to_string(&msg, _("invalid", term));
|
|
}
|
|
|
|
#ifdef HAVE_STRFTIME
|
|
if (cached->expire) {
|
|
time_t expires = timeval_to_seconds(&cached->max_age);
|
|
|
|
add_format_to_string(&msg, "\n%s: ", _("Expires", term));
|
|
add_date_to_string(&msg, get_opt_str("ui.date_format"), &expires);
|
|
}
|
|
#endif
|
|
#ifdef CONFIG_DEBUG
|
|
add_format_to_string(&msg, "\n%s: %d", "Refcount", get_object_refcount(cached));
|
|
add_format_to_string(&msg, "\n%s: %u", _("ID", term), cached->id);
|
|
|
|
if (cached->head && *cached->head) {
|
|
add_format_to_string(&msg, "\n%s:\n\n%s", _("Header", term),
|
|
cached->head);
|
|
}
|
|
#endif
|
|
|
|
return msg.source;
|
|
}
|
|
|
|
static struct uri *
|
|
get_cache_entry_uri(struct listbox_item *item)
|
|
{
|
|
struct cache_entry *cached = item->udata;
|
|
|
|
return get_uri_reference(cached->uri);
|
|
}
|
|
|
|
static struct listbox_item *
|
|
get_cache_entry_root(struct listbox_item *item)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static int
|
|
can_delete_cache_entry(struct listbox_item *item)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
static void
|
|
delete_cache_entry_item(struct listbox_item *item, int last)
|
|
{
|
|
struct cache_entry *cached = item->udata;
|
|
|
|
assert(!is_object_used(cached));
|
|
|
|
delete_cache_entry(cached);
|
|
}
|
|
|
|
static enum listbox_match
|
|
match_cache_entry(struct listbox_item *item, struct terminal *term,
|
|
unsigned char *text)
|
|
{
|
|
struct cache_entry *cached = item->udata;
|
|
|
|
if (strcasestr(struri(cached->uri), text)
|
|
|| (cached->head && strcasestr(cached->head, text)))
|
|
return LISTBOX_MATCH_OK;
|
|
|
|
return LISTBOX_MATCH_NO;
|
|
}
|
|
|
|
static struct listbox_ops_messages cache_messages = {
|
|
/* cant_delete_item */
|
|
N_("Sorry, but cache entry \"%s\" cannot be deleted."),
|
|
/* cant_delete_used_item */
|
|
N_("Sorry, but cache entry \"%s\" is being used by something else."),
|
|
/* cant_delete_folder */
|
|
NULL,
|
|
/* cant_delete_used_folder */
|
|
NULL,
|
|
/* delete_marked_items_title */
|
|
N_("Delete marked cache entries"),
|
|
/* delete_marked_items */
|
|
N_("Delete marked cache entries?"),
|
|
/* delete_folder_title */
|
|
NULL,
|
|
/* delete_folder */
|
|
NULL,
|
|
/* delete_item_title */
|
|
N_("Delete cache entry"),
|
|
/* delete_item */
|
|
N_("Delete this cache entry?"),
|
|
/* clear_all_items_title */
|
|
NULL,
|
|
/* clear_all_items_title */
|
|
NULL,
|
|
};
|
|
|
|
static struct listbox_ops cache_entry_listbox_ops = {
|
|
lock_cache_entry,
|
|
unlock_cache_entry,
|
|
is_cache_entry_used,
|
|
get_cache_entry_text,
|
|
get_cache_entry_info,
|
|
get_cache_entry_uri,
|
|
get_cache_entry_root,
|
|
match_cache_entry,
|
|
can_delete_cache_entry,
|
|
delete_cache_entry_item,
|
|
NULL,
|
|
&cache_messages,
|
|
};
|
|
|
|
static struct hierbox_browser_button cache_buttons[] = {
|
|
/* [gettext_accelerator_context(.cache_buttons)] */
|
|
{ N_("~Info"), push_hierbox_info_button, 1 },
|
|
{ N_("~Goto"), push_hierbox_goto_button, 1 },
|
|
{ N_("~Delete"), push_hierbox_delete_button, 1 },
|
|
{ N_("~Search"), push_hierbox_search_button, 1 },
|
|
};
|
|
|
|
struct_hierbox_browser(
|
|
cache_browser,
|
|
N_("Cache manager"),
|
|
cache_buttons,
|
|
&cache_entry_listbox_ops
|
|
);
|
|
|
|
void
|
|
cache_manager(struct session *ses)
|
|
{
|
|
hierbox_browser(&cache_browser, ses);
|
|
}
|