gui/queue: Add flags to the gui queue

This will be used to determine if the random and random buttons should
be enabled.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-01-14 08:00:04 -05:00
parent ce8ec63886
commit 410a784ede
7 changed files with 49 additions and 9 deletions

View File

@ -56,7 +56,7 @@ static CollectionTab *collection_tab;
static void *collection_init(struct queue *queue)
{
return gui_queue_alloc(queue, "Collection");
return gui_queue_alloc(queue, "Collection", GQ_CAN_RANDOM);
}
static void collection_added(struct queue *queue, unsigned int pos)

View File

@ -41,7 +41,7 @@ static HistoryTab *history_tab;
static void *history_init(struct queue *queue)
{
return gui_queue_alloc(queue, "History");
return gui_queue_alloc(queue, "History", 0);
}
static void history_added(struct queue *queue, unsigned int pos)

View File

@ -87,7 +87,7 @@ static void on_favorite()
static void *playlist_init(struct queue *queue)
{
return gui_queue_alloc(queue, "Playlist");
return gui_queue_alloc(queue, "Playlist", 0);
}
static void playlist_added(struct queue *queue, unsigned int pos)

View File

@ -3,12 +3,15 @@
*/
#include <gui/queue.h>
struct gui_queue *gui_queue_alloc(struct queue *queue, const gchar *text)
struct gui_queue *gui_queue_alloc(struct queue *queue, const gchar *text,
unsigned int flags)
{
struct gui_queue *gq = g_malloc(sizeof(struct gui_queue));
gq->gq_queue = queue;
gq->gq_flags = flags;
gq->gq_text = g_strdup(text);
gq->gq_queue = queue;
return gq;
}

View File

@ -26,7 +26,8 @@ static compare_t sort_fields[] = {
static void *tempq_init(struct queue *queue)
{
return gui_queue_alloc(queue, "Queued Tracks");
return gui_queue_alloc(queue, "Queued Tracks",
GQ_CAN_RANDOM | GQ_CAN_REPEAT);
}
static void tempq_added(struct queue *queue, unsigned int pos)

View File

@ -6,14 +6,21 @@
#include <core/queue.h>
enum gui_queue_flags {
GQ_CAN_RANDOM = (1 << 0), /* Random button can be clicked. */
GQ_CAN_REPEAT = (1 << 1), /* Repeat button can be clicked. */
};
struct gui_queue {
struct queue *gq_queue;
unsigned int gq_flags;
gchar *gq_text;
struct queue *gq_queue;
};
/* Called to allocate a new struct gui_queue. */
struct gui_queue *gui_queue_alloc(struct queue *, const gchar *);
struct gui_queue *gui_queue_alloc(struct queue *, const gchar *, unsigned int);
/* Called to free a struct gui_queue. */
void gui_queue_free(struct queue *);
@ -24,4 +31,20 @@ static inline struct gui_queue *gui_queue(struct queue *queue)
return (struct gui_queue *)queue->q_private;
}
/* Called to ask the struct gui_queue if it can change random flag. */
static inline bool gui_queue_can_random(struct gui_queue *gq)
{
if (gq)
return (gq->gq_flags & GQ_CAN_RANDOM) == GQ_CAN_RANDOM;
return false;
}
/* Called to ask the struct gui_queue if it can change repeat flag. */
static inline bool gui_queue_can_repeat(struct gui_queue *gq)
{
if (gq)
return (gq->gq_flags & GQ_CAN_REPEAT) == GQ_CAN_REPEAT;
return false;
}
#endif /* OCARINA_GUI_QUEUE_H */

View File

@ -6,7 +6,8 @@
static void *test_queue_init(struct queue *queue)
{
return gui_queue_alloc(queue, "Test Queue");
return gui_queue_alloc(queue, "Test Queue",
GQ_CAN_RANDOM | GQ_CAN_REPEAT);
}
void __test_queue_clear(struct queue *queue, unsigned int n) {}
@ -22,11 +23,23 @@ static void test_queue()
struct gui_queue *gq;
struct queue q;
test_equal(gui_queue_can_random(NULL), (bool)false);
test_equal(gui_queue_can_repeat(NULL), (bool)false);
queue_init(&q, 0, &test_ops);
gq = gui_queue(&q);
test_not_equal((void *)gq, NULL);
test_equal((void *)gq->gq_queue, (void *)&q);
test_equal(gq->gq_text, "Test Queue");
test_equal(gq->gq_flags, GQ_CAN_RANDOM | GQ_CAN_REPEAT);
test_equal(gui_queue_can_random(gq), (bool)true);
test_equal(gui_queue_can_repeat(gq), (bool)true);
gq->gq_flags = 0;
test_equal(gui_queue_can_random(gq), (bool)false);
test_equal(gui_queue_can_repeat(gq), (bool)false);
queue_deinit(&q);
test_equal((void *)gui_queue(&q), NULL);