core/playlist: Move playlist_select() out of the playlist namespace
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
1d3a762936
commit
6f0b95608a
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
extern "C" {
|
||||
#include <core/collection.h>
|
||||
#include <core/string.h>
|
||||
}
|
||||
#include <core/playlist.h>
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
void on_cursor_changed()
|
||||
{
|
||||
playlist :: select(current_playlist());
|
||||
playlist_select(current_playlist().c_str());
|
||||
}
|
||||
|
||||
bool on_clicked(GdkEventButton *button)
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue