From 952ab7b6e442d6e7a0a880f01b799fb39a5b92c7 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 15 Aug 2013 20:57:09 +0100 Subject: Move urldb data acquisition so it doesn't need to be duplicated when there are other entry points. --- desktop/hotlist.c | 96 +++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'desktop/hotlist.c') diff --git a/desktop/hotlist.c b/desktop/hotlist.c index 52c85bdea..d137a5e57 100644 --- a/desktop/hotlist.c +++ b/desktop/hotlist.c @@ -148,6 +148,30 @@ static nserror hotlist_entry_insert(struct hotlist_entry *e, } +/** + * Delete a hotlist entry + * + * This does not delete the treeview node, rather it should only be called from + * the treeview node delete event message. + * + * \param e Entry to delete + */ +static void hotlist_delete_entry_internal(struct hotlist_entry *e) +{ + assert(e != NULL); + assert(e->entry == NULL); + + /* Destroy fields */ + free((void *)e->data[HL_TITLE].value); /* Eww */ + free((void *)e->data[HL_LAST_VISIT].value); /* Eww */ + free((void *)e->data[HL_VISITS].value); /* Eww */ + nsurl_unref(e->url); + + /* Destroy entry */ + free(e); +} + + /** * Add an entry to the hotlist (creates the entry). * @@ -162,7 +186,7 @@ static nserror hotlist_entry_insert(struct hotlist_entry *e, * * \param url URL for entry to add to hotlist. * \param title Title for entry, or NULL if using title from data - * \param data URL data for the entry + * \param data URL data for the entry, or NULL * \param relation Existing node to insert as relation of, or NULL * \param rel Entry's relationship to relation * \param entry Updated to new treeview entry node @@ -175,6 +199,20 @@ static nserror hotlist_add_entry_internal(nsurl *url, const char *title, nserror err; struct hotlist_entry *e; + if (data == NULL) { + /* Get the URL data */ + data = urldb_get_url_data(url); + if (data == NULL) { + /* No entry in database, so add one */ + urldb_add_url(url); + /* now attempt to get url data */ + data = urldb_get_url_data(url); + } + if (data == NULL) { + return NSERROR_NOMEM; + } + } + /* Create new local hotlist entry */ e = malloc(sizeof(struct hotlist_entry)); if (e == NULL) { @@ -186,44 +224,26 @@ static nserror hotlist_add_entry_internal(nsurl *url, const char *title, err = hotlist_create_treeview_field_data(e, title, data); if (err != NSERROR_OK) { + nsurl_unref(e->url); + free(e); return err; } err = hotlist_entry_insert(e, relation, rel); if (err != NSERROR_OK) { + hotlist_delete_entry_internal(e); return err; } + /* Make this URL persistent */ + urldb_set_url_persistence(url, true); + *entry = e->entry; return NSERROR_OK; } -/** - * Delete a hotlist entry - * - * This does not delete the treeview node, rather it should only be called from - * the treeview node delete event message. - * - * \param e Entry to delete - */ -static void hotlist_delete_entry_internal(struct hotlist_entry *e) -{ - assert(e != NULL); - assert(e->entry == NULL); - - /* Destroy fields */ - free((void *)e->data[HL_TITLE].value); /* Eww */ - free((void *)e->data[HL_LAST_VISIT].value); /* Eww */ - free((void *)e->data[HL_VISITS].value); /* Eww */ - nsurl_unref(e->url); - - /* Destroy entry */ - free(e); -} - - static nserror hotlist_tree_node_folder_cb( struct treeview_node_msg msg, void *data) { @@ -312,11 +332,9 @@ typedef struct { static nserror hotlist_load_entry(dom_node *li, hotlist_load_ctx *ctx) { dom_node *a; - dom_string *title1; - dom_string *url1; + dom_string *title1, *url1; char *title; nsurl *url; - const struct url_data *data; dom_exception derror; nserror err; @@ -348,7 +366,7 @@ static nserror hotlist_load_entry(dom_node *li, hotlist_load_ctx *ctx) dom_string_byte_length(title1)); dom_string_unref(title1); } else { - title = strdup(""); + title = strdup(""); } if (title == NULL) { warn_user("NoMemory", NULL); @@ -370,26 +388,8 @@ static nserror hotlist_load_entry(dom_node *li, hotlist_load_ctx *ctx) return err; } - /* Get the URL data */ - data = urldb_get_url_data(url); - if (data == NULL) { - /* No entry in database, so add one */ - urldb_add_url(url); - /* now attempt to get url data */ - data = urldb_get_url_data(url); - } - if (data == NULL) { - nsurl_unref(url); - free(title); - - return NSERROR_NOMEM; - } - - /* Make this URL persistent */ - urldb_set_url_persistence(url, true); - /* Add the entry */ - err = hotlist_add_entry_internal(url, title, data, ctx->rel, + err = hotlist_add_entry_internal(url, title, NULL, ctx->rel, ctx->relshp, &ctx->rel); nsurl_unref(url); ctx->relshp = TREE_REL_NEXT_SIBLING; -- cgit v1.2.3