mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
bug 153, 1066: Convert session-snapshot bookmarks to/from UTF-8.
These functions now expect or return strings in UTF-8: delete_folder_by_name (sneak in a const, too), bookmark_terminal_tabs, open_bookmark_folder, and get_auto_save_bookmark_foldername_utf8 (new function).
This commit is contained in:
parent
11acd03eb2
commit
99d1269bc5
@ -267,15 +267,17 @@ delete_bookmark(struct bookmark *bm)
|
|||||||
done_bookmark(bm);
|
done_bookmark(bm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Deletes any bookmarks with no URLs (i.e., folders) and of which
|
/** Deletes any bookmarks with no URLs (i.e., folders) and of which
|
||||||
* the title matches the given argument. */
|
* the title matches the given argument.
|
||||||
|
*
|
||||||
|
* @param foldername
|
||||||
|
* The title of the folder, in UTF-8. */
|
||||||
static void
|
static void
|
||||||
delete_folder_by_name(unsigned char *foldername)
|
delete_folder_by_name(const unsigned char *foldername)
|
||||||
{
|
{
|
||||||
struct bookmark *bookmark, *next;
|
struct bookmark *bookmark, *next;
|
||||||
|
|
||||||
foreachsafe (bookmark, next, bookmarks) {
|
foreachsafe (bookmark, next, bookmarks) {
|
||||||
/** @todo Bug 153: bookmark->title should be UTF-8 */
|
|
||||||
if ((bookmark->url && *bookmark->url)
|
if ((bookmark->url && *bookmark->url)
|
||||||
|| strcmp(bookmark->title, foldername))
|
|| strcmp(bookmark->title, foldername))
|
||||||
continue;
|
continue;
|
||||||
@ -571,6 +573,7 @@ bookmark_terminal(struct terminal *term, struct bookmark *folder)
|
|||||||
{
|
{
|
||||||
unsigned char title[MAX_STR_LEN], url[MAX_STR_LEN];
|
unsigned char title[MAX_STR_LEN], url[MAX_STR_LEN];
|
||||||
struct window *tab;
|
struct window *tab;
|
||||||
|
int term_cp = get_terminal_codepage(term);
|
||||||
|
|
||||||
foreachback_tab (tab, term->windows) {
|
foreachback_tab (tab, term->windows) {
|
||||||
struct session *ses = tab->data;
|
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))
|
if (!get_current_title(ses, title, MAX_STR_LEN))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/** @todo Bugs 153, 1066: add_bookmark() expects UTF-8. */
|
add_bookmark_cp(folder, 1, term_cp, title, url);
|
||||||
add_bookmark(folder, 1, 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
|
void
|
||||||
bookmark_terminal_tabs(struct terminal *term, unsigned char *foldername)
|
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);
|
struct bookmark *folder = add_bookmark(NULL, 1, foldername, NULL);
|
||||||
|
|
||||||
if (!folder) return;
|
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
|
void
|
||||||
bookmark_auto_save_tabs(struct terminal *term)
|
bookmark_auto_save_tabs(struct terminal *term)
|
||||||
{
|
{
|
||||||
unsigned char *foldername;
|
unsigned char *foldername; /* UTF-8 */
|
||||||
|
|
||||||
if (get_cmd_opt_bool("anonymous")
|
if (get_cmd_opt_bool("anonymous")
|
||||||
|| !get_opt_bool("ui.sessions.auto_save"))
|
|| !get_opt_bool("ui.sessions.auto_save"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foldername = get_opt_str("ui.sessions.auto_save_foldername");
|
foldername = get_auto_save_bookmark_foldername_utf8();
|
||||||
if (!*foldername) return;
|
if (!foldername) return;
|
||||||
|
|
||||||
/* Ensure uniqueness of the auto save folder, so it is possible to
|
/* Ensure uniqueness of the auto save folder, so it is possible to
|
||||||
* restore the (correct) session when starting up. */
|
* restore the (correct) session when starting up. */
|
||||||
delete_folder_by_name(foldername);
|
delete_folder_by_name(foldername);
|
||||||
|
|
||||||
bookmark_terminal_tabs(term, foldername);
|
bookmark_terminal_tabs(term, foldername);
|
||||||
|
mem_free(foldername);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -665,8 +699,10 @@ bookmark_snapshot(void)
|
|||||||
add_date_to_string(&folderstring, get_opt_str("ui.date_format"), NULL);
|
add_date_to_string(&folderstring, get_opt_str("ui.date_format"), NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** @todo Bug 153: add_bookmark() expects UTF-8. */
|
/* folderstring must be in the system codepage because
|
||||||
folder = add_bookmark(NULL, 1, folderstring.source, NULL);
|
* add_date_to_string() uses strftime(). */
|
||||||
|
folder = add_bookmark_cp(NULL, 1, get_cp_index("System"),
|
||||||
|
folderstring.source, NULL);
|
||||||
done_string(&folderstring);
|
done_string(&folderstring);
|
||||||
if (!folder) return;
|
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
|
void
|
||||||
open_bookmark_folder(struct session *ses, unsigned char *foldername)
|
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) {
|
foreach (bookmark, bookmarks) {
|
||||||
if (bookmark->box_item->type != BI_FOLDER)
|
if (bookmark->box_item->type != BI_FOLDER)
|
||||||
continue;
|
continue;
|
||||||
/** @todo Bug 153: bookmark->title should be UTF-8 */
|
|
||||||
if (strcmp(bookmark->title, foldername))
|
if (strcmp(bookmark->title, foldername))
|
||||||
continue;
|
continue;
|
||||||
folder = bookmark;
|
folder = bookmark;
|
||||||
|
@ -51,6 +51,7 @@ struct bookmark *get_bookmark_by_name(struct bookmark *folder,
|
|||||||
unsigned char *title);
|
unsigned char *title);
|
||||||
struct bookmark *get_bookmark(unsigned char *url);
|
struct bookmark *get_bookmark(unsigned char *url);
|
||||||
void bookmark_terminal_tabs(struct terminal *term, unsigned char *foldername);
|
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);
|
void bookmark_auto_save_tabs(struct terminal *term);
|
||||||
int update_bookmark(struct bookmark *, int,
|
int update_bookmark(struct bookmark *, int,
|
||||||
unsigned char *, unsigned char *);
|
unsigned char *, unsigned char *);
|
||||||
|
@ -699,6 +699,28 @@ launch_bm_add_link_dialog(struct terminal *term,
|
|||||||
Bookmark tabs dialog.
|
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
|
void
|
||||||
bookmark_terminal_tabs_dialog(struct terminal *term)
|
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"),
|
N_("Bookmark tabs"), N_("Enter folder name"),
|
||||||
term, NULL,
|
term, NULL,
|
||||||
MAX_STR_LEN, string.source, 0, 0, NULL,
|
MAX_STR_LEN, string.source, 0, 0, NULL,
|
||||||
(void (*)(void *, unsigned char *)) bookmark_terminal_tabs,
|
bookmark_terminal_tabs_ok, NULL);
|
||||||
NULL);
|
|
||||||
|
|
||||||
done_string(&string);
|
done_string(&string);
|
||||||
}
|
}
|
||||||
|
@ -178,6 +178,9 @@ struct document {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct uri *uri;
|
struct uri *uri;
|
||||||
|
|
||||||
|
/** The title of the document. The charset of this string is
|
||||||
|
* document.options.cp. */
|
||||||
unsigned char *title;
|
unsigned char *title;
|
||||||
struct cache_entry *cached;
|
struct cache_entry *cached;
|
||||||
|
|
||||||
|
@ -825,10 +825,13 @@ setup_first_session(struct session *ses, struct uri *uri)
|
|||||||
|
|
||||||
#ifdef CONFIG_BOOKMARKS
|
#ifdef CONFIG_BOOKMARKS
|
||||||
} else if (!uri && get_opt_bool("ui.sessions.auto_restore")) {
|
} 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");
|
folder = get_auto_save_bookmark_foldername_utf8();
|
||||||
open_bookmark_folder(ses, folder);
|
if (folder) {
|
||||||
|
open_bookmark_folder(ses, folder);
|
||||||
|
mem_free(folder);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user