core/playlist: Move playlist_has() out of the playlist namespace

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-09 09:31:12 -05:00
parent 1f5ce9e0d1
commit 1d3a762936
4 changed files with 20 additions and 22 deletions

View File

@ -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()));

View File

@ -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));
}
}

View File

@ -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 */

View File

@ -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();
}