core/playlist: Use separate queues for favorite and hidden playlists

Implements issue #6: Store playlists as queues
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-04-22 14:35:35 -04:00 committed by Anna Schumaker
parent e5dc36ca6e
commit 151c446635
5 changed files with 27 additions and 12 deletions

View File

@ -6,12 +6,12 @@
#include <core/string.h>
#include <core/playlist.h>
static GHashTable *playlist_db;
static GHashTable *playlist_db = NULL;
static struct file playlist_f = FILE_INIT("playlist.db", 0, 0);
static struct queue playlist_q;
static enum playlist_t playlist_cur;
static const gchar *playlist_names[2] = { "Favorites", "Banned" };
static struct queue_ops *playlist_ops;
static struct queue_ops *playlist_ops = NULL;
static inline struct queue *__playlist_lookup(const gchar *name)
@ -201,7 +201,9 @@ void playlist_select(enum playlist_t plist)
queue_resort(&playlist_q);
}
struct queue *playlist_get_queue()
struct queue *playlist_get_queue(enum playlist_t plist)
{
if (__playlist_is_static(plist))
return __playlist_lookup(playlist_names[plist]);
return &playlist_q;
}

View File

@ -42,7 +42,7 @@ void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data)
gtk_stack_set_visible_child_name(stack, "queues");
gui_sidebar_selected(SB_PLAYLIST,
gui_queue(playlist_get_queue()));
gui_queue(playlist_get_queue(p_cur)));
playlist_select(p_cur);
}
}

View File

@ -41,6 +41,6 @@ void playlist_select(enum playlist_t);
/* Called to access the playlist queue. */
struct queue *playlist_get_queue();
struct queue *playlist_get_queue(enum playlist_t);
#endif /* OCARINA_CORE_PLAYLIST_H */

View File

@ -34,7 +34,7 @@ void gui_queue_free(struct queue *);
/* Called to access a the struct gui_queue attached to a queue. */
static inline struct gui_queue *gui_queue(struct queue *queue)
{
return (struct gui_queue *)queue->q_private;
return queue ? (struct gui_queue *)queue->q_private : NULL;
}
/* Called to ask the struct gui_queue if it can change random flag. */

View File

@ -9,13 +9,20 @@
static void test_init()
{
struct queue *q = playlist_get_queue();
struct queue *q = playlist_get_queue(PL_MOST_PLAYED);
struct library *library;
GSList *list;
filter_init();
tags_init();
playlist_init(NULL);
while (idle_run_task()) {};
test_equal((void *)playlist_get_queue(PL_FAVORITED), NULL);
test_equal((void *)playlist_get_queue(PL_HIDDEN), NULL);
test_not_equal((void *)playlist_get_queue(PL_UNPLAYED), NULL);
test_not_equal((void *)playlist_get_queue(PL_MOST_PLAYED), NULL);
test_not_equal((void *)playlist_get_queue(PL_LEAST_PLAYED), NULL);
test_not_equal((void *)q, NULL);
test_equal(queue_has_flag(q, Q_ENABLED), (bool)true);
@ -51,7 +58,7 @@ static void test_init()
static void test_add()
{
struct queue *q = playlist_get_queue();
struct queue *q = playlist_get_queue(PL_FAVORITED);
struct track *track = track_get(0);
test_equal(playlist_add(PL_FAVORITED, NULL), (bool)false);
@ -60,6 +67,8 @@ static void test_add()
test_equal(playlist_has(PL_FAVORITED, track), (bool)false);
test_equal(playlist_add(PL_FAVORITED, track), (bool)true);
test_equal(playlist_has(PL_FAVORITED, track), (bool)true);
q = playlist_get_queue(PL_FAVORITED);
test_not_equal((void *)q, NULL);
test_equal(queue_size(q), 1);
test_equal(playlist_add(PL_FAVORITED, track), (bool)false);
test_equal(queue_size(q), 1);
@ -68,16 +77,19 @@ static void test_add()
track = track_get(2);
playlist_select(PL_HIDDEN);
test_equal(queue_size(q), 0);
q = playlist_get_queue(PL_HIDDEN);
test_equal((void *)q, NULL);
test_equal(playlist_has(PL_HIDDEN, track), (bool)false);
test_equal(playlist_add(PL_HIDDEN, track), (bool)true);
test_equal(playlist_has(PL_HIDDEN, track), (bool)true);
q = playlist_get_queue(PL_HIDDEN);
test_not_equal((void *)q, NULL);
test_equal(queue_size(q), 1);
}
static void test_remove()
{
struct queue *q = playlist_get_queue();
struct queue *q = playlist_get_queue(PL_FAVORITED);
struct track *track = track_get(0);
/* The important thing here is that we don't crash */
@ -94,6 +106,7 @@ static void test_remove()
test_equal(playlist_remove(PL_FAVORITED, track_get(1)), (bool)true);
test_equal(queue_size(q), 0);
q = playlist_get_queue(PL_HIDDEN);
track = track_get(2);
playlist_select(PL_HIDDEN);
test_equal(queue_size(q), 1);
@ -105,7 +118,7 @@ static void test_remove()
static void test_dynamic()
{
struct queue *q = playlist_get_queue();
struct queue *q = playlist_get_queue(PL_UNPLAYED);
struct db_entry *dbe, *next;
unsigned int i, average = 0;
struct track *track;
@ -153,7 +166,7 @@ static void test_dynamic()
static void test_deinit()
{
struct queue *q = playlist_get_queue();
struct queue *q = playlist_get_queue(PL_UNPLAYED);
playlist_deinit();
tags_deinit();