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

Convert link titles to correct codepage before displaying it on screen.

Don't replace UTF-8 bytes with '*'. Probably there is need to do better
check what will be displayed.

Also get_current_link_title is no longer pretty and trivial. (o:
This commit is contained in:
Pavol Babincak 2006-03-13 01:54:34 +01:00 committed by Pavol Babincak
parent 7d4dedcb8d
commit 8b9d06c977
10 changed files with 87 additions and 19 deletions

View File

@ -145,7 +145,12 @@ download_dialog_layouter(struct dialog_data *dlg_data)
mem_free(msg); mem_free(msg);
return; return;
} }
decode_uri_for_display(url); #ifdef CONFIG_UTF_8
if (term->utf8)
decode_uri(url);
else
#endif /* CONFIG_UTF_8 */
decode_uri_for_display(url);
url_len = strlen(url); url_len = strlen(url);
if (show_meter) { if (show_meter) {
@ -296,7 +301,14 @@ get_file_download_text(struct listbox_item *item, struct terminal *term)
unsigned char *uristring; unsigned char *uristring;
uristring = get_uri_string(file_download->uri, URI_PUBLIC); uristring = get_uri_string(file_download->uri, URI_PUBLIC);
if (uristring) decode_uri_for_display(uristring); if (uristring) {
#ifdef CONFIG_UTF_8
if (term->utf8)
decode_uri(uristring);
else
#endif /* CONFIG_UTF_8 */
decode_uri_for_display(uristring);
}
return uristring; return uristring;
} }

View File

@ -578,7 +578,12 @@ query_file(struct session *ses, struct uri *uri, void *data,
add_mime_filename_to_string(&def, uri); add_mime_filename_to_string(&def, uri);
/* Remove the %-ugliness for display */ /* Remove the %-ugliness for display */
decode_uri_string_for_display(&def); #ifdef CONFIG_UTF_8
if (ses->tab->term->utf8)
decode_uri_string(&def);
else
#endif /* CONFIG_UTF_8 */
decode_uri_string_for_display(&def);
if (interactive) { if (interactive) {
input_dialog(ses->tab->term, NULL, input_dialog(ses->tab->term, NULL,

View File

@ -142,15 +142,8 @@ get_current_link_info_and_title(struct session *ses,
link_title = get_current_link_title(doc_view); link_title = get_current_link_title(doc_view);
if (link_title) { if (link_title) {
unsigned char *src;
assert(*link_title); assert(*link_title);
/* Remove illicit chars. */
for (src = link_title; *src; src++)
if (!isprint(*src) || iscntrl(*src))
*src = '*';
ret = straconcat(link_info, " - ", link_title, NULL); ret = straconcat(link_info, " - ", link_title, NULL);
mem_free(link_info); mem_free(link_info);
mem_free(link_title); mem_free(link_title);

View File

@ -345,8 +345,14 @@ render_document(struct view_state *vs, struct document_view *doc_view,
} }
document->title = get_uri_string(document->uri, components); document->title = get_uri_string(document->uri, components);
if (document->title) if (document->title) {
decode_uri_for_display(document->title); #ifdef CONFIG_UTF_8
if (doc_view->document->options.utf8)
decode_uri(document->title);
else
#endif /* CONFIG_UTF_8 */
decode_uri_for_display(document->title);
}
} }
#ifdef CONFIG_CSS #ifdef CONFIG_CSS

View File

@ -574,7 +574,12 @@ bittorrent_message_dialog(struct session *ses, void *data)
uristring = get_uri_string(message->uri, URI_PUBLIC); uristring = get_uri_string(message->uri, URI_PUBLIC);
if (uristring) { if (uristring) {
decode_uri_for_display(uristring); #ifdef CONFIG_UTF_8
if (ses->tab->term->utf8)
decode_uri(uristring);
else
#endif /* CONFIG_UTF_8 */
decode_uri_for_display(uristring);
add_format_to_string(&string, add_format_to_string(&string,
_("Unable to retrieve %s", ses->tab->term), _("Unable to retrieve %s", ses->tab->term),
uristring); uristring);
@ -719,7 +724,12 @@ bittorrent_query_callback(void *data, enum connection_state state,
/* Let's make the filename pretty for display & save */ /* Let's make the filename pretty for display & save */
/* TODO: The filename can be the empty string here. See bug 396. */ /* TODO: The filename can be the empty string here. See bug 396. */
decode_uri_string_for_display(&filename); #ifdef CONFIG_UTF_8
if (term->utf8)
decode_uri_string(&filename);
else
#endif /* CONFIG_UTF_8 */
decode_uri_string_for_display(&filename);
} }
add_format_to_string(&msg, add_format_to_string(&msg,

View File

@ -649,6 +649,10 @@ init_gopher_index_cache_entry(struct connection *conn)
return S_OUT_OF_MEM; return S_OUT_OF_MEM;
where = get_uri_string(conn->uri, URI_PUBLIC); where = get_uri_string(conn->uri, URI_PUBLIC);
/* TODO: Use different function when using UTF-8
* in terminal (decode_uri_for_display replaces
* bytes of UTF-8 characters width '*'). */
if (where) decode_uri_for_display(where); if (where) decode_uri_for_display(where);
add_format_to_string(&buffer, add_format_to_string(&buffer,

View File

@ -1048,7 +1048,12 @@ do_type_query(struct type_query *type_query, unsigned char *ct, struct mime_hand
/* Let's make the filename pretty for display & save */ /* Let's make the filename pretty for display & save */
/* TODO: The filename can be the empty string here. See bug 396. */ /* TODO: The filename can be the empty string here. See bug 396. */
decode_uri_string_for_display(&filename); #ifdef CONFIG_UTF_8
if (term->utf8)
decode_uri_string(&filename);
else
#endif /* CONFIG_UTF_8 */
decode_uri_string_for_display(&filename);
} }
text = get_dialog_offset(dlg, TYPE_QUERY_WIDGETS_COUNT); text = get_dialog_offset(dlg, TYPE_QUERY_WIDGETS_COUNT);

View File

@ -268,7 +268,12 @@ print_error_dialog(struct session *ses, enum connection_state state,
uristring = uri ? get_uri_string(uri, URI_PUBLIC) : NULL; uristring = uri ? get_uri_string(uri, URI_PUBLIC) : NULL;
if (uristring) { if (uristring) {
decode_uri_for_display(uristring); #ifdef CONFIG_UTF_8
if (ses->tab->term->utf8)
decode_uri(uristring);
else
#endif /* CONFIG_UTF_8 */
decode_uri_for_display(uristring);
add_format_to_string(&msg, add_format_to_string(&msg,
_("Unable to retrieve %s", ses->tab->term), _("Unable to retrieve %s", ses->tab->term),
uristring); uristring);

View File

@ -1347,7 +1347,7 @@ end:
do_menu(term, mi, ses, 1); do_menu(term, mi, ses, 1);
} }
/* Return current link's title. Pretty trivial. */ /* Return current link's title. */
unsigned char * unsigned char *
get_current_link_title(struct document_view *doc_view) get_current_link_title(struct document_view *doc_view)
{ {
@ -1361,7 +1361,29 @@ get_current_link_title(struct document_view *doc_view)
link = get_current_link(doc_view); link = get_current_link(doc_view);
return (link && link->title && *link->title) ? stracpy(link->title) : NULL; if (link && link->title && *link->title) {
unsigned char *link_title, *src;
struct conv_table *convert_table;
convert_table = get_translation_table(doc_view->document->cp,
doc_view->document->options.cp);
link_title = convert_string(convert_table, link->title,
strlen(link->title),
doc_view->document->options.cp,
CSM_DEFAULT, NULL, NULL, NULL);
/* Remove illicit chars. */
#ifdef CONFIG_UTF_8
if (link_title && !doc_view->document->options.utf8)
#endif /* CONFIG_UTF_8 */
for (src = link_title; *src; src++)
if (!isprint(*src) || iscntrl(*src))
*src = '*';
return link_title;
}
return NULL;
} }
unsigned char * unsigned char *
@ -1406,7 +1428,12 @@ get_current_link_info(struct session *ses, struct document_view *doc_view)
add_char_to_string(&str, ')'); add_char_to_string(&str, ')');
} }
decode_uri_string_for_display(&str); #ifdef CONFIG_UTF_8
if (term->utf8)
decode_uri_string(&str);
else
#endif /* CONFIG_UTF_8 */
decode_uri_string_for_display(&str);
return str.source; return str.source;
} }

View File

@ -11,6 +11,7 @@ struct session;
struct term_event; struct term_event;
struct terminal; struct terminal;
struct uri; struct uri;
struct conv_table;
void set_link(struct document_view *doc_view); void set_link(struct document_view *doc_view);
void free_link(struct document_view *doc_view); void free_link(struct document_view *doc_view);