From d460bcaee83bf29f5869fc821c1dede56506a9a9 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 24 May 2016 07:13:03 -0400 Subject: [PATCH] core/playlists/system: Add struct sys_playlist This will contain the playlist and operations for each secific type. Signed-off-by: Anna Schumaker --- core/playlists/system.c | 30 +++++++++++++++++------------- include/core/playlists/system.h | 4 ++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/core/playlists/system.c b/core/playlists/system.c index 0af4d25d..cc771df7 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -9,14 +9,14 @@ static bool __sys_pl_remove(enum sys_playlist_t, struct track *); static struct file sys_file = FILE_INIT("playlist.db", 0, 0); static struct file sys_collection = FILE_INIT("library.q", 0, 0); -static struct playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = { - [SYS_PL_FAVORITES] = DEFINE_PLAYLIST(PL_SYSTEM, "Favorites"), - [SYS_PL_HIDDEN] = DEFINE_PLAYLIST(PL_SYSTEM, "Hidden"), - [SYS_PL_COLLECTION] = DEFINE_PLAYLIST(PL_SYSTEM, "Collection"), - [SYS_PL_HISTORY] = DEFINE_PLAYLIST(PL_SYSTEM, "History"), - [SYS_PL_UNPLAYED] = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed"), - [SYS_PL_MOST_PLAYED] = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played"), - [SYS_PL_LEAST_PLAYED] = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played"), +static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = { + [SYS_PL_FAVORITES] = { DEFINE_PLAYLIST(PL_SYSTEM, "Favorites") }, + [SYS_PL_HIDDEN] = { DEFINE_PLAYLIST(PL_SYSTEM, "Hidden") }, + [SYS_PL_COLLECTION] = { DEFINE_PLAYLIST(PL_SYSTEM, "Collection") }, + [SYS_PL_HISTORY] = { DEFINE_PLAYLIST(PL_SYSTEM, "History") }, + [SYS_PL_UNPLAYED] = { DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed") }, + [SYS_PL_MOST_PLAYED] = { DEFINE_PLAYLIST(PL_SYSTEM, "Most Played") }, + [SYS_PL_LEAST_PLAYED] = { DEFINE_PLAYLIST(PL_SYSTEM, "Least Played") }, }; @@ -41,7 +41,13 @@ static enum sys_playlist_t __sys_pl_convert(const gchar *name) static inline struct queue *__sys_pl_queue(enum sys_playlist_t plist) { - return &sys_playlists[plist].pl_queue; + return &sys_playlists[plist].spl_playlist.pl_queue; +} + +static struct sys_playlist *__sys_pl_lookup(const gchar *name) +{ + enum sys_playlist_t plist = __sys_pl_convert(name); + return (plist < SYS_PL_NUM_PLAYLISTS) ? &sys_playlists[plist] : NULL; } static void __sys_pl_save() @@ -200,10 +206,8 @@ static bool __sys_pl_update(enum sys_playlist_t plist) static struct queue *pl_system_get_queue(const gchar *name) { - enum sys_playlist_t plist = __sys_pl_convert(name); - if (plist == SYS_PL_NUM_PLAYLISTS) - return NULL; - return __sys_pl_queue(plist); + struct sys_playlist *sys_pl = __sys_pl_lookup(name); + return sys_pl ? &sys_pl->spl_playlist.pl_queue : NULL; } static bool pl_system_new_delete(const gchar *name) diff --git a/include/core/playlists/system.h b/include/core/playlists/system.h index 3ee759ed..49a89ffd 100644 --- a/include/core/playlists/system.h +++ b/include/core/playlists/system.h @@ -17,6 +17,10 @@ enum sys_playlist_t { SYS_PL_NUM_PLAYLISTS, /* Number of system playlists. */ }; +struct sys_playlist { + struct playlist spl_playlist; +}; + /* System playlist type. */ extern struct playlist_type pl_system;