core/playlists/library: Add pl_library_set_flag() function

I also take the opportunity to add in a generic lookup function to
convert a library path into a playlist.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-09 09:16:08 -04:00 committed by Anna Schumaker
parent 1599897fbf
commit 7f867199cb
2 changed files with 25 additions and 5 deletions

View File

@ -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,
};

View File

@ -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);