diff --git a/core/playlists/library.c b/core/playlists/library.c index f9c6d66c..f4e1e67e 100644 --- a/core/playlists/library.c +++ b/core/playlists/library.c @@ -42,14 +42,16 @@ static bool __lib_pl_load(void *data) return true; } +static struct playlist *__lib_pl_lookup(const gchar *name) +{ + struct library *library = library_lookup(name); + return library ? library->li_playlist : NULL; +} + static struct queue *pl_library_get_queue(const gchar *name) { - struct library *library = library_lookup(name); - struct playlist *playlist = NULL; - - if (library) - playlist = (struct playlist *)library->li_playlist; + struct playlist *playlist = __lib_pl_lookup(name); return playlist ? &playlist->pl_queue : NULL; } @@ -58,11 +60,23 @@ static bool pl_library_add_rm(const gchar *name, struct track *track) return false; } +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); +} + struct playlist_type pl_library = { .pl_get_queue = pl_library_get_queue, .pl_add_track = pl_library_add_rm, .pl_remove_track = pl_library_add_rm, + .pl_set_flag = pl_library_set_flag, }; diff --git a/tests/core/playlists/library.c b/tests/core/playlists/library.c index 4b10d732..68abc27b 100644 --- a/tests/core/playlists/library.c +++ b/tests/core/playlists/library.c @@ -45,6 +45,12 @@ void test_library() test_equal(pl_library.pl_remove_track("tests/Music", track_get(1)), (bool)false); test_equal(queue_size(&playlist->pl_queue), 2); + test_equal(queue_has_flag(&playlist->pl_queue, Q_RANDOM), (bool)false); + pl_library.pl_set_flag("tests/Music", Q_RANDOM, true); + test_equal(queue_has_flag(&playlist->pl_queue, Q_RANDOM), (bool)true); + pl_library.pl_set_flag("tests/Music", Q_RANDOM, false); + test_equal(queue_has_flag(&playlist->pl_queue, Q_RANDOM), (bool)false); + pl_library_deinit(); test_equal(library->li_playlist, NULL);