diff --git a/core/playlist.c b/core/playlist.c index 55c161cd..4af4999f 100644 --- a/core/playlist.c +++ b/core/playlist.c @@ -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); diff --git a/gui/playlist.c b/gui/playlist.c index 98e3b5ae..60643ce0 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -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 = "%s\n%d track%s"; text = g_markup_printf_escaped(fmt, name, size, (size == 1) ? "" : "s"); diff --git a/include/core/playlist.h b/include/core/playlist.h index a08f9e5f..4cc2c926 100644 --- a/include/core/playlist.h +++ b/include/core/playlist.h @@ -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 *); diff --git a/tests/core/playlists/artist.c b/tests/core/playlists/artist.c index bd1cc109..b0ce9879 100644 --- a/tests/core/playlists/artist.c +++ b/tests/core/playlists/artist.c @@ -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(); diff --git a/tests/core/playlists/library.c b/tests/core/playlists/library.c index 60fc2071..8c3a1440 100644 --- a/tests/core/playlists/library.c +++ b/tests/core/playlists/library.c @@ -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))); diff --git a/tests/core/playlists/system.c b/tests/core/playlists/system.c index 6a582b22..2d334715 100644 --- a/tests/core/playlists/system.c +++ b/tests/core/playlists/system.c @@ -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) \ diff --git a/tests/core/playlists/user.c b/tests/core/playlists/user.c index d0b08b4b..bbfb9710 100644 --- a/tests/core/playlists/user.c +++ b/tests/core/playlists/user.c @@ -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);