From e7b4973a503f63657c50dc9504b32a13e9dfa501 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 20 Aug 2016 19:13:18 -0400 Subject: [PATCH] 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 --- core/playlist.c | 8 +++++++- core/playlists/artist.c | 7 +++---- core/playlists/library.c | 7 +++---- core/playlists/system.c | 6 +++--- core/playlists/user.c | 7 +++---- include/core/playlist.h | 3 +++ include/core/playlists/type.h | 4 ++-- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/core/playlist.c b/core/playlist.c index 297f8d12..55c161cd 100644 --- a/core/playlist.c +++ b/core/playlist.c @@ -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) diff --git a/core/playlists/artist.c b/core/playlists/artist.c index 3b54be59..b5c4b299 100644 --- a/core/playlists/artist.c +++ b/core/playlists/artist.c @@ -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, diff --git a/core/playlists/library.c b/core/playlists/library.c index 8a918cf0..2b919fd1 100644 --- a/core/playlists/library.c +++ b/core/playlists/library.c @@ -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, diff --git a/core/playlists/system.c b/core/playlists/system.c index 072c00c2..ef9531ce 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -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, diff --git a/core/playlists/user.c b/core/playlists/user.c index cf750018..0edbb522 100644 --- a/core/playlists/user.c +++ b/core/playlists/user.c @@ -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, diff --git a/include/core/playlist.h b/include/core/playlist.h index 5aa37204..a08f9e5f 100644 --- a/include/core/playlist.h +++ b/include/core/playlist.h @@ -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 *); diff --git a/include/core/playlists/type.h b/include/core/playlists/type.h index e2ae5c9b..50bfec4d 100644 --- a/include/core/playlists/type.h +++ b/include/core/playlists/type.h @@ -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 *);