core/playlist: Add a function for getting the current playlist

This is useful to keep playlist settings variables hidden to the GUI.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-08-30 13:40:55 -04:00
parent 38cd2f761d
commit fd84222c2b
7 changed files with 25 additions and 3 deletions

View File

@ -159,6 +159,17 @@ struct playlist *playlist_get(enum playlist_type_t type, const gchar *name)
return playlist_types[type]->pl_get_playlist(name);
}
struct playlist *playlist_cur(void)
{
enum playlist_type_t type = settings_get(SETTINGS_CUR_TYPE);
unsigned int id = settings_get(SETTINGS_CUR_ID);
gchar *name = playlist_get_name(type, id);
struct playlist *ret = playlist_get(type, name);
g_free(name);
return ret;
}
struct queue *playlist_get_queue(enum playlist_type_t type, const gchar *name)
{
struct playlist *playlist = playlist_get(type, name);

View File

@ -52,8 +52,7 @@ static void __playlist_set_size(GtkTreeIter *iter, const gchar *name)
const gchar *fmt = "%s\n%d track%s";
gchar *text;
if (settings_get("core.playlist.cur.type") == type &&
settings_get("core.playlist.cur.id") == playlist_get_id(type, name))
if (playlist_cur() == playlist_get(type, name))
fmt = "<b>%s\n%d track%s</b>";
text = g_markup_printf_escaped(fmt, name, size, (size == 1) ? "" : "s");

View File

@ -72,6 +72,9 @@ struct track *playlist_prev(void);
/* Called to access the playlist. */
struct playlist *playlist_get(enum playlist_type_t, const gchar *);
/* Called to access the current playlist. */
struct playlist *playlist_cur(void);
/* Called to access the playlist queue. */
struct queue *playlist_get_queue(enum playlist_type_t, const gchar *);

View File

@ -35,9 +35,11 @@ void test_artist()
g_assert_false(playlist_remove(PL_ARTIST, "Koji Kondo", track_get(0)));
g_assert_cmpuint(playlist_size(PL_ARTIST, "Koji Kondo"), ==, 2);
g_assert(playlist_cur() != playlist_get(PL_ARTIST, "Koji Kondo"));
g_assert_true(playlist_select(PL_ARTIST, "Koji Kondo"));
g_assert_cmpuint(settings_get("core.playlist.cur.type"), ==, PL_ARTIST);
g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, 0);
g_assert(playlist_cur() == playlist_get(PL_ARTIST, "Koji Kondo"));
g_assert_false(playlist_delete(PL_ARTIST, "Koji Kondo"));
pl_artist_deinit();

View File

@ -35,9 +35,11 @@ void test_library()
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Unplayed"), ==, 48);
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Collection"), ==, 48);
g_assert(playlist_cur() != playlist_get(PL_LIBRARY, "tests/Music"));
g_assert_true(playlist_select(PL_LIBRARY, "tests/Music"));
g_assert_cmpuint(settings_get("core.playlist.cur.type"), ==, PL_LIBRARY);
g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, 0);
g_assert(playlist_cur() == playlist_get(PL_LIBRARY, "tests/Music"));
g_assert_false(playlist_add(PL_LIBRARY, "tests/Music", track_get(0)));
g_assert_false(playlist_add(PL_LIBRARY, "tests/Music", track_get(1)));

View File

@ -69,13 +69,16 @@
#define __test_playlist_select(name, id) \
g_assert_true(playlist_select(PL_SYSTEM, name)); \
g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, id)
g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, id); \
g_assert(playlist_cur() == playlist_get(PL_SYSTEM, name))
#define __test_playlist_noselect(name) \
do { \
unsigned int id = settings_get("core.playlist.cur.id"); \
struct playlist *cur = playlist_cur(); \
g_assert_false(playlist_select(PL_SYSTEM, name)); \
g_assert_cmpuint(settings_get("core.playlist.cur.id"), ==, id); \
g_assert(playlist_cur() == cur); \
} while (0)
#define __test_playlist_reinit(name, ex_size, ex_track0, ex_track1) \

View File

@ -31,7 +31,9 @@ void test_user()
g_assert_cmpstr_free(playlist_get_name(PL_USER, 0), ==, "Test Playlist");
g_assert_null(playlist_get_name(PL_USER, 1));
g_assert(playlist_cur() != playlist_get(PL_USER, "Test Playlist"));
g_assert_true( playlist_select(PL_USER, "Test Playlist"));
g_assert(playlist_cur() == playlist_get(PL_USER, "Test Playlist"));
g_assert_false(playlist_select(PL_USER, "No Playlist"));
g_assert_cmpuint(playlist_size(PL_USER, "Test Playlist"), ==, 0);