diff --git a/src/bookmarks/bookmarks.c b/src/bookmarks/bookmarks.c index 9416a5aa1..4b0e91324 100644 --- a/src/bookmarks/bookmarks.c +++ b/src/bookmarks/bookmarks.c @@ -267,15 +267,17 @@ delete_bookmark(struct bookmark *bm) done_bookmark(bm); } -/* Deletes any bookmarks with no URLs (i.e., folders) and of which - * the title matches the given argument. */ +/** Deletes any bookmarks with no URLs (i.e., folders) and of which + * the title matches the given argument. + * + * @param foldername + * The title of the folder, in UTF-8. */ static void -delete_folder_by_name(unsigned char *foldername) +delete_folder_by_name(const unsigned char *foldername) { struct bookmark *bookmark, *next; foreachsafe (bookmark, next, bookmarks) { - /** @todo Bug 153: bookmark->title should be UTF-8 */ if ((bookmark->url && *bookmark->url) || strcmp(bookmark->title, foldername)) continue; @@ -571,6 +573,7 @@ bookmark_terminal(struct terminal *term, struct bookmark *folder) { unsigned char title[MAX_STR_LEN], url[MAX_STR_LEN]; struct window *tab; + int term_cp = get_terminal_codepage(term); foreachback_tab (tab, term->windows) { struct session *ses = tab->data; @@ -581,15 +584,21 @@ bookmark_terminal(struct terminal *term, struct bookmark *folder) if (!get_current_title(ses, title, MAX_STR_LEN)) continue; - /** @todo Bugs 153, 1066: add_bookmark() expects UTF-8. */ - add_bookmark(folder, 1, title, url); + add_bookmark_cp(folder, 1, term_cp, title, url); } } +/** Create a bookmark for each document on the specified terminal, + * and a folder to contain those bookmarks. + * + * @param term + * The terminal whose open documents should be bookmarked. + * + * @param foldername + * The name of the new bookmark folder, in UTF-8. */ void bookmark_terminal_tabs(struct terminal *term, unsigned char *foldername) { - /** @todo Bug 153: add_bookmark() expects UTF-8. */ struct bookmark *folder = add_bookmark(NULL, 1, foldername, NULL); if (!folder) return; @@ -631,23 +640,48 @@ bookmark_all_terminals(struct bookmark *folder) } +unsigned char * +get_auto_save_bookmark_foldername_utf8(void) +{ + unsigned char *foldername; + int from_cp, to_cp; + struct conv_table *convert_table; + + foldername = get_opt_str("ui.sessions.auto_save_foldername"); + if (!*foldername) return NULL; + + /* The charset of the string returned by get_opt_str() + * seems to be documented nowhere. Let's assume it is + * the system charset. */ + from_cp = get_cp_index("System"); + to_cp = get_cp_index("UTF-8"); + convert_table = get_translation_table(from_cp, to_cp); + if (!convert_table) return NULL; + + return convert_string(convert_table, + foldername, strlen(foldername), + to_cp, CSM_NONE, + NULL, NULL, NULL); +} + void bookmark_auto_save_tabs(struct terminal *term) { - unsigned char *foldername; + unsigned char *foldername; /* UTF-8 */ if (get_cmd_opt_bool("anonymous") || !get_opt_bool("ui.sessions.auto_save")) return; - foldername = get_opt_str("ui.sessions.auto_save_foldername"); - if (!*foldername) return; + foldername = get_auto_save_bookmark_foldername_utf8(); + if (!foldername) return; /* Ensure uniqueness of the auto save folder, so it is possible to * restore the (correct) session when starting up. */ delete_folder_by_name(foldername); bookmark_terminal_tabs(term, foldername); + mem_free(foldername); } static void @@ -665,8 +699,10 @@ bookmark_snapshot(void) add_date_to_string(&folderstring, get_opt_str("ui.date_format"), NULL); #endif - /** @todo Bug 153: add_bookmark() expects UTF-8. */ - folder = add_bookmark(NULL, 1, folderstring.source, NULL); + /* folderstring must be in the system codepage because + * add_date_to_string() uses strftime(). */ + folder = add_bookmark_cp(NULL, 1, get_cp_index("System"), + folderstring.source, NULL); done_string(&folderstring); if (!folder) return; @@ -677,6 +713,14 @@ bookmark_snapshot(void) } +/** Open all bookmarks from the named folder. + * + * @param ses + * The session in which to open the first bookmark. The other + * bookmarks of the folder open in new tabs on the same terminal. + * + * @param foldername + * The name of the bookmark folder, in UTF-8. */ void open_bookmark_folder(struct session *ses, unsigned char *foldername) { @@ -690,7 +734,6 @@ open_bookmark_folder(struct session *ses, unsigned char *foldername) foreach (bookmark, bookmarks) { if (bookmark->box_item->type != BI_FOLDER) continue; - /** @todo Bug 153: bookmark->title should be UTF-8 */ if (strcmp(bookmark->title, foldername)) continue; folder = bookmark; diff --git a/src/bookmarks/bookmarks.h b/src/bookmarks/bookmarks.h index 1c5ab5fc2..e3cdc3df5 100644 --- a/src/bookmarks/bookmarks.h +++ b/src/bookmarks/bookmarks.h @@ -51,6 +51,7 @@ struct bookmark *get_bookmark_by_name(struct bookmark *folder, unsigned char *title); struct bookmark *get_bookmark(unsigned char *url); void bookmark_terminal_tabs(struct terminal *term, unsigned char *foldername); +unsigned char *get_auto_save_bookmark_foldername_utf8(void); void bookmark_auto_save_tabs(struct terminal *term); int update_bookmark(struct bookmark *, int, unsigned char *, unsigned char *); diff --git a/src/bookmarks/dialogs.c b/src/bookmarks/dialogs.c index f3ad7c81c..9f6359833 100644 --- a/src/bookmarks/dialogs.c +++ b/src/bookmarks/dialogs.c @@ -699,6 +699,28 @@ launch_bm_add_link_dialog(struct terminal *term, Bookmark tabs dialog. \****************************************************************************/ +static void +bookmark_terminal_tabs_ok(void *term_void, unsigned char *foldername) +{ + struct terminal *const term = term_void; + int from_cp = get_terminal_codepage(term); + int to_cp = get_cp_index("UTF-8"); + struct conv_table *convert_table; + unsigned char *converted; + + convert_table = get_translation_table(from_cp, to_cp); + if (convert_table == NULL) return; /** @todo Report the error */ + + converted = convert_string(convert_table, + foldername, strlen(foldername), + to_cp, CSM_NONE, + NULL, NULL, NULL); + if (converted == NULL) return; /** @todo Report the error */ + + bookmark_terminal_tabs(term_void, converted); + mem_free(converted); +} + void bookmark_terminal_tabs_dialog(struct terminal *term) { @@ -717,8 +739,7 @@ bookmark_terminal_tabs_dialog(struct terminal *term) N_("Bookmark tabs"), N_("Enter folder name"), term, NULL, MAX_STR_LEN, string.source, 0, 0, NULL, - (void (*)(void *, unsigned char *)) bookmark_terminal_tabs, - NULL); + bookmark_terminal_tabs_ok, NULL); done_string(&string); } diff --git a/src/document/document.h b/src/document/document.h index 441a8a942..d51349be9 100644 --- a/src/document/document.h +++ b/src/document/document.h @@ -178,6 +178,9 @@ struct document { #endif struct uri *uri; + + /** The title of the document. The charset of this string is + * document.options.cp. */ unsigned char *title; struct cache_entry *cached; diff --git a/src/session/session.c b/src/session/session.c index dead46476..3df7eb541 100644 --- a/src/session/session.c +++ b/src/session/session.c @@ -825,10 +825,13 @@ setup_first_session(struct session *ses, struct uri *uri) #ifdef CONFIG_BOOKMARKS } else if (!uri && get_opt_bool("ui.sessions.auto_restore")) { - unsigned char *folder; + unsigned char *folder; /* UTF-8 */ - folder = get_opt_str("ui.sessions.auto_save_foldername"); - open_bookmark_folder(ses, folder); + folder = get_auto_save_bookmark_foldername_utf8(); + if (folder) { + open_bookmark_folder(ses, folder); + mem_free(folder); + } return 1; #endif }