diff --git a/core/playlist.c b/core/playlist.c index a81865b2..1f2a115f 100644 --- a/core/playlist.c +++ b/core/playlist.c @@ -118,13 +118,11 @@ void playlist_update(enum playlist_type_t type, const gchar *name) playlist_types[type]->pl_update(name); } -bool playlist_has(enum playlist_type_t type, const gchar *name, - struct track *track) +bool playlist_has(struct playlist *playlist, struct track *track) { - struct queue *queue = playlist_get_queue(type, name); - if (!track || !queue) + if (!playlist || !track) return false; - return queue_has(queue, track); + return queue_has(&playlist->pl_queue, track); } unsigned int playlist_size(enum playlist_type_t type, const gchar *name) diff --git a/gui/playlists/system.c b/gui/playlists/system.c index f1977f56..b2b695fb 100644 --- a/gui/playlists/system.c +++ b/gui/playlists/system.c @@ -8,6 +8,9 @@ #include #include +static struct playlist *favorites; +static struct playlist *hidden; + static bool __gui_pl_system_is_playlist(struct playlist *playlist) { return string_match(playlist->pl_name, "Favorites") || @@ -35,7 +38,6 @@ static bool __gui_pl_system_find_descend_header(GtkTreeIter *iter, void __gui_pl_system_favorite_toggled(GtkToggleButton *toggle, gpointer data) { - struct playlist *favorites = playlist_get(PL_SYSTEM, "Favorites"); if (gtk_toggle_button_get_active(toggle)) playlist_add(favorites, audio_cur_track()); else @@ -44,7 +46,6 @@ void __gui_pl_system_favorite_toggled(GtkToggleButton *toggle, gpointer data) void __gui_pl_system_hide_toggled(GtkToggleButton *toggle, gpointer data) { - struct playlist *hidden = playlist_get(PL_SYSTEM, "Hidden"); if (gtk_toggle_button_get_active(toggle)) { if (playlist_add(hidden, audio_cur_track())) audio_next(); @@ -86,6 +87,8 @@ static bool __gui_pl_system_init_idle() void gui_pl_system_init() { + favorites = playlist_get(PL_SYSTEM, "Favorites"); + hidden = playlist_get(PL_SYSTEM, "Hidden"); idle_schedule(IDLE_SYNC, __gui_pl_system_init_idle, NULL); } @@ -130,7 +133,7 @@ void gui_pl_system_select(struct playlist *playlist) void gui_pl_system_track_loaded(struct track *track) { gtk_toggle_button_set_active(gui_favorite_button(), - playlist_has(PL_SYSTEM, "Favorites", track)); + playlist_has(favorites, track)); gtk_toggle_button_set_active(gui_hide_button(), - playlist_has(PL_SYSTEM, "Hidden", track)); + playlist_has(hidden, track)); } diff --git a/include/core/playlist.h b/include/core/playlist.h index e68d1302..7c5fb9ad 100644 --- a/include/core/playlist.h +++ b/include/core/playlist.h @@ -46,7 +46,7 @@ void playlist_update(enum playlist_type_t, const gchar *); /* Called to check if a specific track is in the playlist. */ -bool playlist_has(enum playlist_type_t, const gchar *, struct track *); +bool playlist_has(struct playlist *, struct track *); /* Called to find the number of tracks in the playlist. */ unsigned int playlist_size(enum playlist_type_t, const gchar *); diff --git a/tests/core/playlist.c b/tests/core/playlist.c index 8a5abab8..fd513267 100644 --- a/tests/core/playlist.c +++ b/tests/core/playlist.c @@ -14,6 +14,8 @@ static void test_null() g_assert_false(playlist_add(NULL, NULL)); g_assert_false(playlist_add(NULL, track_get(0))); + g_assert_false(playlist_has(NULL, NULL)); + g_assert_false(playlist_has(NULL, track_get(0))); g_assert_false(playlist_remove(NULL, NULL)); g_assert_false(playlist_remove(NULL, track_get(0))); } diff --git a/tests/core/playlists/system.c b/tests/core/playlists/system.c index 427bf3ff..84be4390 100644 --- a/tests/core/playlists/system.c +++ b/tests/core/playlists/system.c @@ -14,9 +14,9 @@ #define __test_playlist_has(name, track, expected) \ if (expected) \ - g_assert_true(playlist_has(PL_SYSTEM, name, track)); \ + g_assert_true(playlist_has(playlist_get(PL_SYSTEM, name), track)); \ else \ - g_assert_false(playlist_has(PL_SYSTEM, name, track)) + g_assert_false(playlist_has(playlist_get(PL_SYSTEM, name), track)) #define __test_playlist_state(name, ex_size, ex_track0, ex_track1) \ g_assert_cmpuint(playlist_size(PL_SYSTEM, name), ==, ex_size); \ @@ -144,7 +144,6 @@ static void test_invalid() __test_playlist_noselect("Invalid"); playlist_update(PL_SYSTEM, NULL); - g_assert_false(playlist_has(PL_SYSTEM, NULL, track_get(0))); g_assert_cmpuint(playlist_size(PL_SYSTEM, NULL), ==, 0); g_assert_false(playlist_get_random(PL_SYSTEM, NULL)); @@ -396,9 +395,9 @@ static void test_add() g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, 1); g_assert_cmpuint(playlist_size(PL_SYSTEM, "History"), ==, 2); - g_assert_true(playlist_has(PL_SYSTEM, "Favorites", track_get(0))); - g_assert_true(playlist_has(PL_SYSTEM, "Queued Tracks", track_get(0))); - g_assert_true(playlist_has(PL_SYSTEM, "History", track_get(0))); + g_assert_true(playlist_has(__test_pl_favorites(), track_get(0))); + g_assert_true(playlist_has(__test_pl_queued(), track_get(0))); + g_assert_true(playlist_has(__test_pl_history(), track_get(0))); g_assert_true( playlist_add(__test_pl_hidden(), track_get(0))); g_assert_true( playlist_add(__test_pl_hidden(), track_get(1))); @@ -416,15 +415,15 @@ static void test_add() g_assert_cmpuint(playlist_size(PL_SYSTEM, "Least Played"), ==, 0); g_assert_cmpuint(playlist_size(PL_SYSTEM, "Unplayed"), ==, 0); - g_assert_true( playlist_has(PL_SYSTEM, "Hidden", track_get(0))); - g_assert_true( playlist_has(PL_SYSTEM, "Hidden", track_get(1))); - g_assert_true( playlist_has(PL_SYSTEM, "Hidden", track_get(2))); - g_assert_false(playlist_has(PL_SYSTEM, "Collection", track_get(0))); - g_assert_false(playlist_has(PL_SYSTEM, "Collection", track_get(1))); - g_assert_false(playlist_has(PL_SYSTEM, "Collection", track_get(2))); - g_assert_false(playlist_has(PL_SYSTEM, "Most Played", track_get(0))); - g_assert_false(playlist_has(PL_SYSTEM, "Least Played", track_get(1))); - g_assert_false(playlist_has(PL_SYSTEM, "Unplayed", track_get(2))); + g_assert_true( playlist_has(__test_pl_hidden(), track_get(0))); + g_assert_true( playlist_has(__test_pl_hidden(), track_get(1))); + g_assert_true( playlist_has(__test_pl_hidden(), track_get(2))); + g_assert_false(playlist_has(__test_pl_collection(), track_get(0))); + g_assert_false(playlist_has(__test_pl_collection(), track_get(1))); + g_assert_false(playlist_has(__test_pl_collection(), track_get(2))); + g_assert_false(playlist_has(__test_pl_most_played(), track_get(0))); + g_assert_false(playlist_has(__test_pl_least_played(), track_get(1))); + g_assert_false(playlist_has(__test_pl_unplayed(), track_get(2))); } static void test_remove() @@ -439,9 +438,9 @@ static void test_remove() g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, 0); g_assert_cmpuint(playlist_size(PL_SYSTEM, "History"), ==, 2); - g_assert_false(playlist_has(PL_SYSTEM, "Favorites", track_get(0))); - g_assert_false(playlist_has(PL_SYSTEM, "Queued Tracks", track_get(0))); - g_assert_true( playlist_has(PL_SYSTEM, "History", track_get(0))); + g_assert_false(playlist_has(__test_pl_favorites(), track_get(0))); + g_assert_false(playlist_has(__test_pl_queued(), track_get(0))); + g_assert_true( playlist_has(__test_pl_history(), track_get(0))); g_assert_true( playlist_remove(__test_pl_hidden(), track_get(0))); g_assert_true( playlist_remove(__test_pl_hidden(), track_get(1))); @@ -456,21 +455,21 @@ static void test_remove() g_assert_cmpuint(playlist_size(PL_SYSTEM, "Least Played"), ==, 1); g_assert_cmpuint(playlist_size(PL_SYSTEM, "Unplayed"), ==, 1); - g_assert_false(playlist_has(PL_SYSTEM, "Hidden", track_get(0))); - g_assert_false(playlist_has(PL_SYSTEM, "Hidden", track_get(1))); - g_assert_false(playlist_has(PL_SYSTEM, "Hidden", track_get(2))); - g_assert_true( playlist_has(PL_SYSTEM, "Collection", track_get(0))); - g_assert_true( playlist_has(PL_SYSTEM, "Collection", track_get(1))); - g_assert_true( playlist_has(PL_SYSTEM, "Collection", track_get(2))); - g_assert_true( playlist_has(PL_SYSTEM, "Most Played", track_get(0))); - g_assert_true( playlist_has(PL_SYSTEM, "Least Played", track_get(1))); - g_assert_true( playlist_has(PL_SYSTEM, "Unplayed", track_get(2))); + g_assert_false(playlist_has(__test_pl_hidden(), track_get(0))); + g_assert_false(playlist_has(__test_pl_hidden(), track_get(1))); + g_assert_false(playlist_has(__test_pl_hidden(), track_get(2))); + g_assert_true( playlist_has(__test_pl_collection(), track_get(0))); + g_assert_true( playlist_has(__test_pl_collection(), track_get(1))); + g_assert_true( playlist_has(__test_pl_collection(), track_get(2))); + g_assert_true( playlist_has(__test_pl_most_played(), track_get(0))); + g_assert_true( playlist_has(__test_pl_least_played(), track_get(1))); + g_assert_true( playlist_has(__test_pl_unplayed(), track_get(2))); g_assert_true(playlist_remove(__test_pl_collection(), track_get(0))); g_assert_cmpuint(playlist_size(PL_SYSTEM, "Hidden"), ==, 1); g_assert_cmpuint(playlist_size(PL_SYSTEM, "Collection"), ==, 2); - g_assert_true (playlist_has(PL_SYSTEM, "Hidden", track_get(0))); - g_assert_false(playlist_has(PL_SYSTEM, "Collection", track_get(0))); + g_assert_true (playlist_has(__test_pl_hidden(), track_get(0))); + g_assert_false(playlist_has(__test_pl_collection(), track_get(0))); } static void test_delete() diff --git a/tests/core/playlists/user.c b/tests/core/playlists/user.c index 4f1c1a0d..5fd491db 100644 --- a/tests/core/playlists/user.c +++ b/tests/core/playlists/user.c @@ -39,10 +39,10 @@ void test_user() g_assert_false(playlist_select(PL_USER, "No Playlist")); g_assert_cmpuint(playlist_size(PL_USER, "Test Playlist"), ==, 0); - g_assert_false(playlist_has( PL_USER, "Test Playlist", track_get(0))); + g_assert_false(playlist_has(playlist, track_get(0))); g_assert_true( playlist_add(playlist, track_get(0))); g_assert_false(playlist_add(playlist, track_get(0))); - g_assert_true( playlist_has( PL_USER, "Test Playlist", track_get(0))); + g_assert_true( playlist_has(playlist, track_get(0))); g_assert_cmpuint(playlist_size(PL_USER, "Test Playlist"), ==, 1); playlist_update(PL_USER, "Test Playlist"); @@ -56,10 +56,10 @@ void test_user() g_assert_nonnull(playlist); g_assert_cmpuint(playlist_size(PL_USER, "Test Playlist"), ==, 1); - g_assert_true( playlist_has( PL_USER, "Test Playlist", track_get(0))); + g_assert_true( playlist_has( playlist, track_get(0))); g_assert_true( playlist_remove(playlist, track_get(0))); g_assert_false(playlist_remove(playlist, track_get(0))); - g_assert_false(playlist_has( PL_USER, "Test Playlist", track_get(0))); + g_assert_false(playlist_has( playlist, track_get(0))); g_assert_cmpuint(playlist_size(PL_USER, "Test Playlist"), ==, 0); g_assert_true(playlist_delete(playlist)); diff --git a/tests/gui/playlists/system.c b/tests/gui/playlists/system.c index 211fdb4f..9ada8a0f 100644 --- a/tests/gui/playlists/system.c +++ b/tests/gui/playlists/system.c @@ -65,32 +65,35 @@ static void test_system() static void test_buttons() { + struct playlist *favorites = playlist_get(PL_SYSTEM, "Favorites"); + struct playlist *hidden = playlist_get(PL_SYSTEM, "Hidden"); + g_assert_nonnull(gui_pl_library_add("tests/Music/Hyrule Symphony")); while (idle_run_task()) {} g_assert_false(gtk_toggle_button_get_active(gui_favorite_button())); g_assert_false(gtk_toggle_button_get_active(gui_hide_button())); - playlist_add(playlist_get(PL_SYSTEM, "Favorites"), track_get(0)); + playlist_add(favorites, track_get(0)); audio_load(track_get(0)); g_assert_true( gtk_toggle_button_get_active(gui_favorite_button())); g_assert_false(gtk_toggle_button_get_active(gui_hide_button())); gtk_toggle_button_set_active(gui_favorite_button(), false); - g_assert_false(playlist_has(PL_SYSTEM, "Favorites", track_get(0))); + g_assert_false(playlist_has(favorites, track_get(0))); gtk_toggle_button_set_active(gui_favorite_button(), true); - g_assert_true(playlist_has(PL_SYSTEM, "Favorites", track_get(0))); + g_assert_true(playlist_has(favorites, track_get(0))); - playlist_add(playlist_get(PL_SYSTEM, "Hidden"), track_get(1)); + playlist_add(hidden, track_get(1)); audio_load(track_get(1)); g_assert_false(gtk_toggle_button_get_active(gui_favorite_button())); g_assert_true(gtk_toggle_button_get_active(gui_hide_button())); gtk_toggle_button_set_active(gui_hide_button(), false); - g_assert_false(playlist_has(PL_SYSTEM, "Hidden", track_get(1))); + g_assert_false(playlist_has(hidden, track_get(1))); g_assert(audio_cur_track() == track_get(1)); gtk_toggle_button_set_active(gui_hide_button(), true); - g_assert_true(playlist_has(PL_SYSTEM, "Hidden", track_get(1))); + g_assert_true(playlist_has(hidden, track_get(1))); g_assert(audio_cur_track() != track_get(1)); }