Core hotlist API: Take save path at init, rather than fini.

This commit is contained in:
Michael Drake 2017-04-25 11:52:47 +01:00
parent ab53f74788
commit c47b9f465c
2 changed files with 24 additions and 8 deletions

View File

@ -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;

View File

@ -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.