From 8f7e8be39d68da5cd0400a1bc9f3f25d826fda1c Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 24 May 2016 07:48:11 -0400 Subject: [PATCH] core/playlists/generic: Add a playlist_generic_set_flag() function The history playlist uses a noop function, since changing random or repeat settings doesn't make sense for this playlist. The collection playlist uses a custom function to save changes after setting a flag. Signed-off-by: Anna Schumaker --- core/playlists/artist.c | 4 ++-- core/playlists/generic.c | 13 +++++++++++++ core/playlists/library.c | 6 +----- core/playlists/system.c | 27 +++++++++++++++++---------- include/core/playlists/system.h | 1 + include/core/playlists/type.h | 6 ++++++ 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/core/playlists/artist.c b/core/playlists/artist.c index 38bb49bd..3f8a25d9 100644 --- a/core/playlists/artist.c +++ b/core/playlists/artist.c @@ -72,8 +72,8 @@ static void pl_artist_update(const gchar *name) static void pl_artist_set_flag(const gchar *name, enum queue_flags flag, bool enabled) { - struct queue *queue = pl_artist_get_queue(name); - (enabled ? queue_set_flag : queue_unset_flag)(queue, flag); + struct playlist *playlist = __artist_pl_lookup(name); + playlist_generic_set_flag(playlist, flag, enabled); } static void pl_artist_sort(const gchar *name, enum compare_t sort, bool reset) diff --git a/core/playlists/generic.c b/core/playlists/generic.c index 1ee6a424..2cae0cf9 100644 --- a/core/playlists/generic.c +++ b/core/playlists/generic.c @@ -7,6 +7,11 @@ /* * Noop playlist operations. */ +void playlist_noop_set_flag(struct playlist *playlist, + enum queue_flags flag, bool enabled) +{ +} + void playlist_noop_sort(struct playlist *playlist, enum compare_t sort, bool reset) { @@ -16,6 +21,14 @@ void playlist_noop_sort(struct playlist *playlist, /* * Generic playlist operations. */ +void playlist_generic_set_flag(struct playlist *playlist, + enum queue_flags flag, bool enabled) +{ + if (enabled) + return queue_set_flag(&playlist->pl_queue, flag); + return queue_unset_flag(&playlist->pl_queue, flag); +} + void playlist_generic_sort(struct playlist *playlist, enum compare_t sort, bool reset) { diff --git a/core/playlists/library.c b/core/playlists/library.c index 1c27a2ed..b81cf897 100644 --- a/core/playlists/library.c +++ b/core/playlists/library.c @@ -195,11 +195,7 @@ static void pl_library_set_flag(const gchar *name, enum queue_flags flag, bool enabled) { struct playlist *playlist = __lib_pl_lookup(name); - - if (enabled) - queue_set_flag(&playlist->pl_queue, flag); - else - queue_unset_flag(&playlist->pl_queue, flag); + playlist_generic_set_flag(playlist, flag, enabled); } static void pl_library_sort(const gchar *name, enum compare_t sort, bool reset) diff --git a/core/playlists/system.c b/core/playlists/system.c index 7bc9a9ed..bc8efd84 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -15,6 +15,13 @@ static struct file sys_collection = FILE_INIT("library.q", 0, 0); /* * Collection playlist operations. */ +static void sys_pl_collection_set_flag(struct playlist *playlist, + enum queue_flags flag, bool enabled) +{ + playlist_generic_set_flag(playlist, flag, enabled); + __sys_pl_save_collection(); +} + static void sys_pl_collection_sort(struct playlist *playlist, enum compare_t sort, bool reset) { @@ -26,30 +33,37 @@ static void sys_pl_collection_sort(struct playlist *playlist, static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = { [SYS_PL_FAVORITES] = { .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Favorites"), + .spl_set_flag = playlist_generic_set_flag, .spl_sort = playlist_generic_sort, }, [SYS_PL_HIDDEN] = { .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Hidden"), + .spl_set_flag = playlist_generic_set_flag, .spl_sort = playlist_generic_sort, }, [SYS_PL_COLLECTION] = { .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Collection"), + .spl_set_flag = sys_pl_collection_set_flag, .spl_sort = sys_pl_collection_sort, }, [SYS_PL_HISTORY] = { .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "History"), + .spl_set_flag = playlist_noop_set_flag, .spl_sort = playlist_noop_sort, }, [SYS_PL_UNPLAYED] = { .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed"), + .spl_set_flag = playlist_generic_set_flag, .spl_sort = playlist_generic_sort, }, [SYS_PL_MOST_PLAYED] = { .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played"), + .spl_set_flag = playlist_generic_set_flag, .spl_sort = playlist_generic_sort, }, [SYS_PL_LEAST_PLAYED] = { .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played"), + .spl_set_flag = playlist_generic_set_flag, .spl_sort = playlist_generic_sort, }, }; @@ -278,16 +292,9 @@ static void pl_system_update(const gchar *name) static void pl_system_set_flag(const gchar *name, enum queue_flags flag, bool enabled) { - enum sys_playlist_t plist = __sys_pl_convert(name); - if (plist == SYS_PL_HISTORY || plist == SYS_PL_NUM_PLAYLISTS) - return; - if (enabled) - queue_set_flag(__sys_pl_queue(plist), flag); - else - queue_unset_flag(__sys_pl_queue(plist), flag); - - if (plist == SYS_PL_COLLECTION) - __sys_pl_save_collection(); + struct sys_playlist *sys_pl = __sys_pl_lookup(name); + if (sys_pl) + sys_pl->spl_set_flag(&sys_pl->spl_playlist, flag, enabled); } static void pl_system_sort(const gchar *name, enum compare_t sort, bool reset) diff --git a/include/core/playlists/system.h b/include/core/playlists/system.h index ba9ce821..e37efdaa 100644 --- a/include/core/playlists/system.h +++ b/include/core/playlists/system.h @@ -20,6 +20,7 @@ enum sys_playlist_t { struct sys_playlist { struct playlist spl_playlist; + void (*spl_set_flag)(struct playlist *, enum queue_flags, bool); void (*spl_sort)(struct playlist *, enum compare_t, bool); }; diff --git a/include/core/playlists/type.h b/include/core/playlists/type.h index 787a230d..9935e313 100644 --- a/include/core/playlists/type.h +++ b/include/core/playlists/type.h @@ -54,10 +54,16 @@ struct playlist_type { }; +/* Noop playlist set_flag operation. */ +void playlist_noop_set_flag(struct playlist *, enum queue_flags, bool); + /* Noop playlist sorting operation. */ void playlist_noop_sort(struct playlist *, enum compare_t, bool); +/* Generic playlist set_flag operation. */ +void playlist_generic_set_flag(struct playlist *, enum queue_flags, bool); + /* Generic playlist sorting operation. */ void playlist_generic_sort(struct playlist *, enum compare_t, bool);