From c47b9f465cfdea1b37e7a5ff7e569290e4a0387e Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 25 Apr 2017 11:52:47 +0100 Subject: Core hotlist API: Take save path at init, rather than fini. --- desktop/hotlist.c | 22 ++++++++++++++++++---- desktop/hotlist.h | 10 ++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'desktop') diff --git a/desktop/hotlist.c b/desktop/hotlist.c index 78473c744..033b668e1 100644 --- a/desktop/hotlist.c +++ b/desktop/hotlist.c @@ -62,6 +62,7 @@ struct hotlist_ctx { struct treeview_field_desc fields[HL_N_FIELDS]; bool built; struct hotlist_folder *default_folder; + char *save_path; }; struct hotlist_ctx hl_ctx; @@ -1227,7 +1228,9 @@ static nserror hotlist_populate(const char *path) /* Exported interface, documented in hotlist.h */ -nserror hotlist_init(const char *path) +nserror hotlist_init( + const char *load_path, + const char *save_path) { nserror err; @@ -1242,9 +1245,16 @@ nserror hotlist_init(const char *path) hl_ctx.built = false; hl_ctx.default_folder = NULL; + /* Store the save path */ + hl_ctx.save_path = strdup(save_path); + if (hl_ctx.save_path == NULL) { + return NSERROR_NOMEM; + } + /* Init. hotlist treeview entry fields */ err = hotlist_initialise_entry_fields(); if (err != NSERROR_OK) { + free(hl_ctx.save_path); hl_ctx.tree = NULL; return err; } @@ -1254,13 +1264,15 @@ nserror hotlist_init(const char *path) HL_N_FIELDS, hl_ctx.fields, NULL, NULL, TREEVIEW_NO_FLAGS); if (err != NSERROR_OK) { + free(hl_ctx.save_path); hl_ctx.tree = NULL; return err; } /* Populate the hotlist */ - err = hotlist_populate(path); + err = hotlist_populate(load_path); if (err != NSERROR_OK) { + free(hl_ctx.save_path); return err; } @@ -1310,7 +1322,7 @@ nserror hotlist_manager_fini(void) /* Exported interface, documented in hotlist.h */ -nserror hotlist_fini(const char *path) +nserror hotlist_fini(void) { int i; nserror err; @@ -1318,11 +1330,13 @@ nserror hotlist_fini(const char *path) LOG("Finalising hotlist"); /* Save the hotlist */ - err = hotlist_save(path); + err = hotlist_save(hl_ctx.save_path); if (err != NSERROR_OK) { LOG("Problem saving the hotlist."); } + free(hl_ctx.save_path); + /* Destroy the hotlist treeview */ err = treeview_destroy(hl_ctx.tree); hl_ctx.built = false; diff --git a/desktop/hotlist.h b/desktop/hotlist.h index ef54f6b8b..e38eac1c2 100644 --- a/desktop/hotlist.h +++ b/desktop/hotlist.h @@ -40,10 +40,13 @@ struct rect; * be called before URLs can be added to the hotlist, and before the * hotlist can be queried to ask if URLs are present in the hotlist. * - * \param path The path to hotlist file to load + * \param load_path The path to load hotlist from. + * \param save_path The path to save hotlist to. * \return NSERROR_OK on success, appropriate error otherwise */ -nserror hotlist_init(const char *path); +nserror hotlist_init( + const char *load_path, + const char *save_path); /** * Initialise the hotlist manager. @@ -78,10 +81,9 @@ nserror hotlist_manager_fini(void); * internal data. After calling this if hotlist is required again, * hotlist_init must be called. * - * \param path The path to save hotlist to * \return NSERROR_OK on success, appropriate error otherwise */ -nserror hotlist_fini(const char *path); +nserror hotlist_fini(void); /** * Add an entry to the hotlist for given URL. -- cgit v1.2.3