From 1d3a7629363b68e07a4f10a253d9df1c299575e9 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 9 Dec 2015 09:31:12 -0500 Subject: [PATCH] core/playlist: Move playlist_has() out of the playlist namespace Signed-off-by: Anna Schumaker --- core/playlist.cpp | 16 ++++++++-------- gui/playlist.cpp | 6 +++--- include/core/playlist.h | 13 ++++--------- tests/core/playlist.cpp | 7 +++++-- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/core/playlist.cpp b/core/playlist.cpp index a08bfe50..722a86ab 100644 --- a/core/playlist.cpp +++ b/core/playlist.cpp @@ -108,19 +108,12 @@ void playlist_deinit() db_deinit(&playlist_db); } -bool playlist :: has(struct track *track, const std::string &name) -{ - if (playlist_db.db_size == 0) - return false; - return index_has(&playlist_db, name.c_str(), track->tr_dbe.dbe_index); -} - void playlist :: add(struct track *track, const std::string &name) { if (!( (name == "Banned") || (name == "Favorites") )) return; - if (!has(track, name)) { + if (!playlist_has(name.c_str(), track)) { index_insert(&playlist_db, name.c_str(), track->tr_dbe.dbe_index); if (cur_plist == name) queue_add(&playlist_q, track); @@ -138,6 +131,13 @@ void playlist :: del(struct track *track, const std::string &name) queue_add(collection_get_queue(), track); } +bool playlist_has(const gchar *name, struct track *track) +{ + if (!track || !name) + return false; + return index_has(&playlist_db, name, track->tr_dbe.dbe_index); +} + void playlist :: select(const std::string &name) { index_entry *ent = INDEX_ENTRY(db_get(&playlist_db, name.c_str())); diff --git a/gui/playlist.cpp b/gui/playlist.cpp index 5d541d22..7125148c 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -126,7 +126,7 @@ static void on_ban() { struct track *track = audio :: current_track(); if (o_ban->get_active()) { - if (!playlist :: has(track, "Banned")) { + if (!playlist_has("Banned", track)) { playlist :: add(track, "Banned"); audio :: next(); } @@ -175,8 +175,8 @@ struct queue_ops playlist_ops = { void plist :: track_loaded(struct track *track) { if (p_tab) { - o_ban->set_active(playlist :: has(track, "Banned")); - o_fav->set_active(playlist :: has(track, "Favorites")); + o_ban->set_active(playlist_has("Banned", track)); + o_fav->set_active(playlist_has("Favorites", track)); } } diff --git a/include/core/playlist.h b/include/core/playlist.h index 0db6df15..0d68032d 100644 --- a/include/core/playlist.h +++ b/include/core/playlist.h @@ -26,15 +26,6 @@ extern "C" { namespace playlist { - /** - * Check if a specific track is in a playlist. - * - * @param track The track in question. - * @param name The name of the playlist to check. - * @return True if the track is in the playlist, false otherwise. - */ - bool has(struct track *, const std::string &); - /** * Add a track to a playlist. * @@ -86,4 +77,8 @@ void playlist_init(struct queue_ops *); /* Called to deinitialize the playlist manager. */ void playlist_deinit(); + +/* Called to check if a specific track is in the playlist. */ +bool playlist_has(const gchar *, struct track *); + #endif /* OCARINA_CORE_PLAYLIST_H */ diff --git a/tests/core/playlist.cpp b/tests/core/playlist.cpp index 8f796c0d..e8664d1d 100644 --- a/tests/core/playlist.cpp +++ b/tests/core/playlist.cpp @@ -117,15 +117,18 @@ static void test_has() { struct track *track; + test_equal(playlist_has("Favorites", NULL), false); + test_equal(playlist_has(NULL, track_get(0)), false); + for (unsigned int i = 0; i < 24; i++) { track = track_get(i); - test_loop_equal(playlist :: has(track, "Banned"), + test_loop_equal(playlist_has("Banned", track), (i <= 3) ? true : false, i); } test_loop_passed(); for (unsigned int i = 0; i < 24; i++) { track = track_get(i); - test_loop_equal(playlist :: has(track, "Favorites"), + test_loop_equal(playlist_has("Favorites", track), (i >= 16) ? true : false, i); } test_loop_passed(); }