1
0
Fork 0

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.
This commit is contained in:
Kalle Olavi Niemitalo 2008-11-17 00:56:18 +02:00 committed by Kalle Olavi Niemitalo
parent 73f925ce21
commit 03b112796d
5 changed files with 26 additions and 11 deletions

View File

@ -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:

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -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)
{