ocarina/include/core/tags/library.h
Anna Schumaker c2178bc265 core: Cut back on hardcoded dbe_index uses
The dbe_index of a given database item might change in the future, so we
can't rely on it everywhere.  Let's just use it for saving and loading
files, with the expectation that changes will happen sometime after
startup.

Implements #69: Reduce use of dbe_index in Ocarina code
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2016-09-11 10:50:45 -04:00

71 lines
2.1 KiB
C

/*
* Copyright 2014 (c) Anna Schumaker.
*
* The Library tag is used to store a single directory added
* to Ocarina by the user.
*
* When writing a Library tag to disk, write out the library_enabled
* and library_path fields for each tag.
*
* ... true /home/Zelda/Music
* ... false /home/Link/Music
*/
#ifndef OCARINA_CORE_TAGS_LIBRARY_H
#define OCARINA_CORE_TAGS_LIBRARY_H
#include <core/database.h>
struct library {
unsigned int li_size; /* This library's track count. */
bool li_enabled; /* True if this library is enabled. */
gchar *li_path; /* This library's root path. */
void *li_playlist; /* This library's associated playlist. */
struct db_entry li_dbe;
};
#define LIBRARY(dbe) ((struct library *)DBE_DATA(dbe))
/* Called to initialize the library database. */
void library_db_init();
/* Called to clean up the library database. */
void library_db_deinit();
/* Called to access the library database. */
const struct database *library_db_get();
/*
* Called to find a library tag by library path. The difference is that
* library_find() will allocate a new library struct if the requested one
* doesn't exist yet, but library_lookup() will return NULL in this situation.
*/
struct library *library_find(const gchar *);
struct library *library_lookup(const gchar *);
/* Called to get a library tag with a specific index. */
struct library *library_get(const unsigned int);
/* Called to remove a specific library tag. */
void library_remove(struct library *);
/* Called to configure if the library tag is enabled. */
void library_set_enabled(struct library *, bool);
/* Called to find the database index of the library tag. */
static inline unsigned int library_index(struct library *library)
{
return library->li_dbe.dbe_index;
}
/*
* Called to find the full path of files under the library directory.
* This function allocates a new string that MUST be freed with g_free().
*/
gchar *library_file(struct library *, const gchar *);
#ifdef CONFIG_TESTING
const struct db_ops *test_library_ops();
#endif /* CONFIG_TESTING */
#endif /* OCARINA_CORE_TAGS_LIBRARY_H */