From cefcce0197b98be11575670aaca84357ec917b11 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 24 Jul 2011 11:40:08 +0000 Subject: Shared URL nodes in the treeview actually want to be readonly. They certainly have no business not copying transient data. svn path=/trunk/netsurf/; revision=12623 --- desktop/history_global_core.c | 4 ++-- desktop/hotlist.c | 6 +++--- desktop/tree_url_node.c | 50 +++++++++++++++++++++---------------------- desktop/tree_url_node.h | 4 ++-- 4 files changed, 32 insertions(+), 32 deletions(-) (limited to 'desktop') diff --git a/desktop/history_global_core.c b/desktop/history_global_core.c index f06d79d8b..a73bd7c2b 100644 --- a/desktop/history_global_core.c +++ b/desktop/history_global_core.c @@ -146,7 +146,7 @@ static bool global_history_add_internal(const char *url, node = history_global_find(url); if (node != NULL) { tree_update_URL_node(global_history_tree, - node, url, data, true); + node, url, data); tree_delink_node(global_history_tree, node); tree_link_node(global_history_tree, parent, node, false); @@ -155,7 +155,7 @@ static bool global_history_add_internal(const char *url, } /* Add the node at the bottom */ - node = tree_create_URL_node_shared(global_history_tree, + node = tree_create_URL_node_readonly(global_history_tree, parent, url, data, tree_url_node_callback, NULL); diff --git a/desktop/hotlist.c b/desktop/hotlist.c index acfef10cd..16e249ee1 100644 --- a/desktop/hotlist.c +++ b/desktop/hotlist.c @@ -179,7 +179,7 @@ bool hotlist_initialise(struct tree *tree, const char *hotlist_path, const char* hotlist_node_callback, NULL); tree_update_URL_node(hotlist_tree, node, hotlist_default_entries[hlst_loop].url, - url_data, false); + url_data); } } @@ -234,7 +234,7 @@ static void hotlist_visited_internal(hlcache_handle *content, struct node *node) text = tree_url_node_get_url(node); if (strcmp(text, url) == 0) { tree_update_URL_node(hotlist_tree, node, - url, NULL, false); + url, NULL); } } child = tree_node_get_child(node); @@ -423,7 +423,7 @@ void hotlist_add_page(const char *url) node = tree_create_URL_node(hotlist_tree, hotlist_tree_root, url, NULL, hotlist_node_callback, NULL); - tree_update_URL_node(hotlist_tree, node, url, data, false); + tree_update_URL_node(hotlist_tree, node, url, data); } /** diff --git a/desktop/tree_url_node.c b/desktop/tree_url_node.c index b524f9b8c..edae767da 100644 --- a/desktop/tree_url_node.c +++ b/desktop/tree_url_node.c @@ -176,35 +176,38 @@ struct node *tree_create_URL_node(struct tree *tree, struct node *parent, /** - * Creates a tree entry for a URL, and links it into the tree. - * - * All information is used directly from the url_data, and as such cannot be - * edited and should never be freed. + * Creates a read only tree entry for a URL, and links it into the tree. * * \param parent the node to link to * \param url the URL * \param data the URL data to use * \return the node created, or NULL for failure */ -struct node *tree_create_URL_node_shared(struct tree *tree, struct node *parent, - const char *url, const struct url_data *data, +struct node *tree_create_URL_node_readonly(struct tree *tree, + struct node *parent, const char *url, + const struct url_data *data, tree_node_user_callback user_callback, void *callback_data) { struct node *node; struct node_element *element; - const char *title; + char *title; assert(url && data); if (data->title != NULL) { - title = data->title; + title = strdup(data->title); } else { - title = url; + title = strdup(url); } + if (title == NULL) + return NULL; + node = tree_create_leaf_node(tree, parent, title, false, false, false); - if (node == NULL) + if (node == NULL) { + free(title); return NULL; + } if (user_callback != NULL) { tree_set_node_user_callback(node, user_callback, @@ -223,7 +226,8 @@ struct node *tree_create_URL_node_shared(struct tree *tree, struct node *parent, tree_update_node_element(tree, element, url, NULL); } - tree_update_URL_node(tree, node, url, data, true); + tree_update_URL_node(tree, node, url, data); + return node; } @@ -234,7 +238,7 @@ struct node *tree_create_URL_node_shared(struct tree *tree, struct node *parent, * \param node the node to update */ void tree_update_URL_node(struct tree *tree, struct node *node, - const char *url, const struct url_data *data, bool shared) + const char *url, const struct url_data *data) { struct node_element *element; struct bitmap *bitmap = NULL; @@ -256,18 +260,14 @@ void tree_update_URL_node(struct tree *tree, struct node *node, element = tree_node_find_element(node, TREE_ELEMENT_TITLE, NULL); - if (shared) - tree_update_node_element(tree, element, data->title, - NULL); - else { - text_cp = strdup(data->title); - if (text_cp == NULL) { - LOG(("malloc failed")); - warn_user("NoMemory", 0); - return; - } - tree_update_node_element(tree, element, text_cp, NULL); + + text_cp = strdup(data->title); + if (text_cp == NULL) { + LOG(("malloc failed")); + warn_user("NoMemory", 0); + return; } + tree_update_node_element(tree, element, text_cp, NULL); } else { data = urldb_get_url_data(url); if (data == NULL) @@ -423,7 +423,7 @@ node_callback_resp tree_url_node_callback(void *user_data, } tree = user_data; tree_update_URL_node(tree, msg_data->node, - norm_text, NULL, false); + norm_text, NULL); } else if (msg_data->flag == TREE_ELEMENT_TITLE) { while (isspace(*text)) @@ -552,7 +552,7 @@ static void tree_url_load_entry(xmlNode *li, struct tree *tree, /** \todo why isn't this fatal? */ warn_user("NoMemory", 0); } else { - tree_update_URL_node(tree, entry, url, data, false); + tree_update_URL_node(tree, entry, url, data); } diff --git a/desktop/tree_url_node.h b/desktop/tree_url_node.h index 6d62895e4..15243e93d 100644 --- a/desktop/tree_url_node.h +++ b/desktop/tree_url_node.h @@ -32,12 +32,12 @@ void tree_url_node_cleanup(void); struct node *tree_create_URL_node(struct tree *tree, struct node *parent, const char *url, const char *title, tree_node_user_callback, void *callback_data); -struct node *tree_create_URL_node_shared(struct tree *tree, +struct node *tree_create_URL_node_readonly(struct tree *tree, struct node *parent, const char *url, const struct url_data *data, tree_node_user_callback, void *callback_data); void tree_update_URL_node(struct tree *tree,struct node *node, - const char *url, const struct url_data *data, bool shared); + const char *url, const struct url_data *data); const char *tree_url_node_get_title(struct node *node); const char *tree_url_node_get_url(struct node *node); void tree_url_node_edit_title(struct tree *tree, struct node *node); -- cgit v1.2.3