core/playlist: Add playlist_get() function

This is called to get the requested playlist.  I also reworked
playlist_get_queue() to call this function.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-08-20 19:13:18 -04:00
parent 7d0dbcbdc7
commit e7b4973a50
7 changed files with 24 additions and 18 deletions

View File

@ -154,9 +154,15 @@ struct track *playlist_prev(void)
return playlist_types[PL_SYSTEM]->pl_next("History");
}
struct playlist *playlist_get(enum playlist_type_t type, const gchar *name)
{
return playlist_types[type]->pl_get_playlist(name);
}
struct queue *playlist_get_queue(enum playlist_type_t type, const gchar *name)
{
return playlist_types[type]->pl_get_queue(name);
struct playlist *playlist = playlist_get(type, name);
return playlist ? &playlist->pl_queue : NULL;
}
unsigned int playlist_get_id(enum playlist_type_t type, const gchar *name)

View File

@ -95,10 +95,9 @@ static void pl_artist_save(void)
file_close(&artist_file);
}
static struct queue *pl_artist_get_queue(const gchar *name)
static struct playlist *pl_artist_get_playlist(const gchar *name)
{
struct playlist *playlist = __artist_pl_lookup(name);
return playlist ? &playlist->pl_queue : NULL;
return __artist_pl_lookup(name);
}
static unsigned int pl_artist_get_id(const gchar *name)
@ -159,7 +158,7 @@ static struct track *pl_artist_next(const gchar *name)
struct playlist_type pl_artist = {
.pl_save = pl_artist_save,
.pl_get_queue = pl_artist_get_queue,
.pl_get_playlist = pl_artist_get_playlist,
.pl_get_id = pl_artist_get_id,
.pl_get_name = pl_artist_get_name,
.pl_can_select = pl_artist_can_select,

View File

@ -186,10 +186,9 @@ static void pl_library_save(void)
file_close(&lib_file);
}
static struct queue *pl_library_get_queue(const gchar *name)
static struct playlist *pl_library_get_playlist(const gchar *name)
{
struct playlist *playlist = __lib_pl_lookup(name);
return playlist ? &playlist->pl_queue : NULL;
return __lib_pl_lookup(name);
}
static unsigned int pl_library_get_id(const gchar *name)
@ -283,7 +282,7 @@ static struct track *pl_library_next(const gchar *name)
struct playlist_type pl_library = {
.pl_save = pl_library_save,
.pl_get_queue = pl_library_get_queue,
.pl_get_playlist = pl_library_get_playlist,
.pl_get_id = pl_library_get_id,
.pl_get_name = pl_library_get_name,
.pl_can_select = pl_library_can_select,

View File

@ -476,10 +476,10 @@ static void pl_system_save(void)
__sys_pl_save();
}
static struct queue *pl_system_get_queue(const gchar *name)
static struct playlist *pl_system_get_playlist(const gchar *name)
{
struct sys_playlist *sys_pl = __sys_pl_lookup(name);
return sys_pl ? &sys_pl->spl_playlist.pl_queue : NULL;
return sys_pl ? &sys_pl->spl_playlist : NULL;
}
static unsigned int pl_system_get_id(const gchar *name)
@ -587,7 +587,7 @@ static struct track *pl_system_next(const gchar *name)
struct playlist_type pl_system = {
.pl_save = pl_system_save,
.pl_get_queue = pl_system_get_queue,
.pl_get_playlist = pl_system_get_playlist,
.pl_get_id = pl_system_get_id,
.pl_get_name = pl_system_get_name,
.pl_can_select = pl_system_can_select,

View File

@ -79,10 +79,9 @@ static void pl_user_save(void)
db_save(&user_db);
}
static struct queue *pl_user_get_queue(const gchar *name)
static struct playlist *pl_user_get_playlist(const gchar *name)
{
struct playlist *playlist = __user_pl_lookup(name);
return playlist ? &playlist->pl_queue : NULL;
return __user_pl_lookup(name);
}
static unsigned int pl_user_get_id(const gchar *name)
@ -178,7 +177,7 @@ static struct track *pl_user_next(const gchar *name)
struct playlist_type pl_user = {
.pl_save = pl_user_save,
.pl_get_queue = pl_user_get_queue,
.pl_get_playlist = pl_user_get_playlist,
.pl_get_id = pl_user_get_id,
.pl_get_name = pl_user_get_name,
.pl_can_select = pl_user_can_select,

View File

@ -69,6 +69,9 @@ struct track *playlist_next(void);
struct track *playlist_prev(void);
/* Called to access the playlist. */
struct playlist *playlist_get(enum playlist_type_t, const gchar *);
/* Called to access the playlist queue. */
struct queue *playlist_get_queue(enum playlist_type_t, const gchar *);

View File

@ -32,8 +32,8 @@ struct playlist_type {
/* Called to save all playlists of the given type. */
void (*pl_save)(void);
/* Called to get the queue for the playlist. */
struct queue *(*pl_get_queue)(const gchar *);
/* Called to get the playlist. */
struct playlist *(*pl_get_playlist)(const gchar *);
/* Called to convert a playlist name to an integer id. */
unsigned int (*pl_get_id)(const gchar *);