core/playlist: playlist_has() takes a playlist pointer
Rather than going through a lookup step. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
3364d4733e
commit
0e523ed279
|
@ -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)
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
#include <gui/playlists/system.h>
|
||||
#include <gui/sidebar.h>
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -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 *);
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue