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:
parent
1599897fbf
commit
7f867199cb
|
@ -42,14 +42,16 @@ static bool __lib_pl_load(void *data)
|
||||||
return true;
|
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)
|
static struct queue *pl_library_get_queue(const gchar *name)
|
||||||
{
|
{
|
||||||
struct library *library = library_lookup(name);
|
struct playlist *playlist = __lib_pl_lookup(name);
|
||||||
struct playlist *playlist = NULL;
|
|
||||||
|
|
||||||
if (library)
|
|
||||||
playlist = (struct playlist *)library->li_playlist;
|
|
||||||
return playlist ? &playlist->pl_queue : NULL;
|
return playlist ? &playlist->pl_queue : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,11 +60,23 @@ static bool pl_library_add_rm(const gchar *name, struct track *track)
|
||||||
return false;
|
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 = {
|
struct playlist_type pl_library = {
|
||||||
.pl_get_queue = pl_library_get_queue,
|
.pl_get_queue = pl_library_get_queue,
|
||||||
.pl_add_track = pl_library_add_rm,
|
.pl_add_track = pl_library_add_rm,
|
||||||
.pl_remove_track = pl_library_add_rm,
|
.pl_remove_track = pl_library_add_rm,
|
||||||
|
.pl_set_flag = pl_library_set_flag,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,12 @@ void test_library()
|
||||||
test_equal(pl_library.pl_remove_track("tests/Music", track_get(1)), (bool)false);
|
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_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();
|
pl_library_deinit();
|
||||||
test_equal(library->li_playlist, NULL);
|
test_equal(library->li_playlist, NULL);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue