diff --git a/core/playlist.cpp b/core/playlist.cpp index 722a86ab..180b5fb5 100644 --- a/core/playlist.cpp +++ b/core/playlist.cpp @@ -3,6 +3,7 @@ */ extern "C" { #include +#include } #include @@ -79,6 +80,22 @@ static struct database playlist_db; static PlaylistQueue playlist_q; static std::string cur_plist; +static inline bool __playlist_is_static(const gchar *name) +{ + if (string_compare(name, "Favorites") == 0) + return true; + return string_compare(name, "Banned") == 0; +} + +static inline bool __playlist_is_dynamic(const gchar *name) +{ + if (string_compare(name, "Most Played") == 0) + return true; + if (string_compare(name, "Least Played") == 0) + return true; + return string_compare(name, "Unplayed") == 0; +} + void playlist_init(struct queue_ops *ops) { @@ -138,14 +155,20 @@ bool playlist_has(const gchar *name, struct track *track) return index_has(&playlist_db, name, track->tr_dbe.dbe_index); } -void playlist :: select(const std::string &name) +void playlist_select(const gchar *name) { - index_entry *ent = INDEX_ENTRY(db_get(&playlist_db, name.c_str())); + index_entry *ent; - if (ent != NULL) + if (!name) + return; + + if (__playlist_is_static(name)) { + ent = INDEX_ENTRY(db_get(&playlist_db, name)); playlist_q.fill(ent); - else + } else if (__playlist_is_dynamic(name)) playlist_q.dynamic_fill(name); + else + return; cur_plist = name; } diff --git a/gui/playlist.cpp b/gui/playlist.cpp index 7125148c..9feb76d5 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -56,7 +56,7 @@ public: void on_cursor_changed() { - playlist :: select(current_playlist()); + playlist_select(current_playlist().c_str()); } bool on_clicked(GdkEventButton *button) diff --git a/include/core/playlist.h b/include/core/playlist.h index 0d68032d..c67cfab2 100644 --- a/include/core/playlist.h +++ b/include/core/playlist.h @@ -48,13 +48,6 @@ namespace playlist */ void del(struct track *, const std::string &); - /** - * Use to change the currently displayed playlist. - * - * @param name The name of the queue to queue up. - */ - void select(const std::string &); - /** * Use to access specific tracks in a playlist. * @@ -81,4 +74,7 @@ void playlist_deinit(); /* Called to check if a specific track is in the playlist. */ bool playlist_has(const gchar *, struct track *); +/* Called to fill the queue with a specific playlist. */ +void playlist_select(const gchar *); + #endif /* OCARINA_CORE_PLAYLIST_H */ diff --git a/tests/core/playlist.cpp b/tests/core/playlist.cpp index e8664d1d..7b68aa21 100644 --- a/tests/core/playlist.cpp +++ b/tests/core/playlist.cpp @@ -51,19 +51,23 @@ static void test_queue() collection_init(NULL); playlist_init(NULL); - playlist :: select("Banned"); + playlist_select(NULL); + playlist_select("Banned"); test_equal(queue_size(q), (unsigned)4); - playlist :: select("Favorites"); + playlist_select("Favorites"); test_equal(queue_size(q), (unsigned)8); - playlist :: select("Unplayed"); + playlist_select("Unplayed"); test_equal(queue_size(q), (unsigned)3); - playlist :: select("Most Played"); + playlist_select("Most Played"); test_equal(queue_size(q), (unsigned)10); - playlist :: select("Least Played"); + playlist_select("Least Played"); + test_equal(queue_size(q), (unsigned)12); + + playlist_select("No Such Playlist"); test_equal(queue_size(q), (unsigned)12); } @@ -73,7 +77,7 @@ static void test_add() queue *q = playlist :: get_queue(); queue *l = collection_get_queue(); - playlist :: select("Favorites"); + playlist_select("Favorites"); playlist :: add(track_get(5), "Banned"); ent = playlist :: get_tracks("Banned");