From 03b112796d176a2f1a3a718ebd7480a3f5eebe65 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Mon, 17 Nov 2008 00:56:18 +0200 Subject: [PATCH] bug 153, 1066: Add codepage parameter to update_bookmark(). This also makes the bookmark-update event carry strings in UTF-8. The only current consumer of that event is bookmark_change_hook(), which ignores the strings, so no changes are needed there. --- doc/events.txt | 4 ++-- src/bookmarks/bookmarks.c | 20 ++++++++++++++------ src/bookmarks/bookmarks.h | 3 ++- src/bookmarks/dialogs.c | 5 ++++- src/util/conv.c | 5 ++++- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/doc/events.txt b/doc/events.txt index ca129194..1e1caeb2 100644 --- a/doc/events.txt +++ b/doc/events.txt @@ -85,8 +85,8 @@ Triggered When: Arguments: struct bookmark *bookmark - unsigned char *new_title - unsigned char *new_url + unsigned char *new_title /* UTF-8 */ + unsigned char *new_url /* UTF-8 */ Description: diff --git a/src/bookmarks/bookmarks.c b/src/bookmarks/bookmarks.c index b5a631ab..91add9ec 100644 --- a/src/bookmarks/bookmarks.c +++ b/src/bookmarks/bookmarks.c @@ -465,21 +465,31 @@ add_bookmark_cp(struct bookmark *root, int place, int codepage, * * If any of the fields are NULL, the value is left unchanged. */ int -update_bookmark(struct bookmark *bm, unsigned char *title, - unsigned char *url) +update_bookmark(struct bookmark *bm, int codepage, + unsigned char *title, unsigned char *url) { static int update_bookmark_event_id = EVENT_NONE; + const int utf8_cp = get_cp_index("UTF-8"); + struct conv_table *table; unsigned char *title2 = NULL; unsigned char *url2 = NULL; + table = get_translation_table(codepage, utf8_cp); + if (!table) + return 0; + if (url) { - url2 = stracpy(url); + url2 = convert_string(table, url, strlen(url), + utf8_cp, CSM_NONE, + NULL, NULL, NULL); if (!url2) return 0; sanitize_url(url2); } if (title) { - title2 = stracpy(title); + title2 = convert_string(table, title, strlen(title), + utf8_cp, CSM_NONE, + NULL, NULL, NULL); if (!title2) { mem_free_if(url2); return 0; @@ -491,7 +501,6 @@ update_bookmark(struct bookmark *bm, unsigned char *title, trigger_event(update_bookmark_event_id, bm, title2, url2); if (title2) { - /** @todo Bug 153: bm->title should be UTF-8 */ mem_free_set(&bm->title, title2); } @@ -504,7 +513,6 @@ update_bookmark(struct bookmark *bm, unsigned char *title, if (item) del_hash_item(bookmark_cache, item); } - /** @todo Bug 1066: bm->url should be UTF-8 */ if (check_bookmark_cache(url2)) { add_hash_item(bookmark_cache, url2, strlen(url2), bm); } diff --git a/src/bookmarks/bookmarks.h b/src/bookmarks/bookmarks.h index 6db78446..1c5ab5fc 100644 --- a/src/bookmarks/bookmarks.h +++ b/src/bookmarks/bookmarks.h @@ -52,7 +52,8 @@ struct bookmark *get_bookmark_by_name(struct bookmark *folder, struct bookmark *get_bookmark(unsigned char *url); void bookmark_terminal_tabs(struct terminal *term, unsigned char *foldername); void bookmark_auto_save_tabs(struct terminal *term); -int update_bookmark(struct bookmark *, unsigned char *, unsigned char *); +int update_bookmark(struct bookmark *, int, + unsigned char *, unsigned char *); void open_bookmark_folder(struct session *ses, unsigned char *foldername); #endif diff --git a/src/bookmarks/dialogs.c b/src/bookmarks/dialogs.c index 343e3c7b..f3ad7c81 100644 --- a/src/bookmarks/dialogs.c +++ b/src/bookmarks/dialogs.c @@ -283,8 +283,11 @@ static void bookmark_edit_done(void *data) { struct dialog *dlg = data; struct bookmark *bm = (struct bookmark *) dlg->udata2; + struct dialog_data *parent_dlg_data = dlg->udata; + int term_cp = get_terminal_codepage(parent_dlg_data->win->term); - update_bookmark(bm, dlg->widgets[0].data, dlg->widgets[1].data); + update_bookmark(bm, term_cp, + dlg->widgets[0].data, dlg->widgets[1].data); object_unlock(bm); #ifdef BOOKMARKS_RESAVE diff --git a/src/util/conv.c b/src/util/conv.c index 1bf78774..0404a3ac 100644 --- a/src/util/conv.c +++ b/src/util/conv.c @@ -492,7 +492,10 @@ clr_spaces(unsigned char *str) } /** Replace invalid chars in @a title with ' ' and trim all starting/ending - * spaces. */ + * spaces. + * + * update_bookmark() assumes this function does not switch translation + * tables. */ void sanitize_title(unsigned char *title) {