diff --git a/gui/collection_tab.cpp b/gui/collection_tab.cpp index f295da36..2e983bb5 100644 --- a/gui/collection_tab.cpp +++ b/gui/collection_tab.cpp @@ -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) diff --git a/gui/history.cpp b/gui/history.cpp index 652a26bb..be722a05 100644 --- a/gui/history.cpp +++ b/gui/history.cpp @@ -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) diff --git a/gui/playlist_tab.cpp b/gui/playlist_tab.cpp index 4909e38d..96f9312d 100644 --- a/gui/playlist_tab.cpp +++ b/gui/playlist_tab.cpp @@ -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) diff --git a/gui/queue.c b/gui/queue.c index 73f086c6..6e890cbb 100644 --- a/gui/queue.c +++ b/gui/queue.c @@ -3,12 +3,15 @@ */ #include -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; } diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 86203bb3..3af9059a 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -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) diff --git a/include/gui/queue.h b/include/gui/queue.h index a8206664..45cad9cb 100644 --- a/include/gui/queue.h +++ b/include/gui/queue.h @@ -6,14 +6,21 @@ #include +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 */ diff --git a/tests/gui/queue.c b/tests/gui/queue.c index 6b6c3e1f..d94a03b1 100644 --- a/tests/gui/queue.c +++ b/tests/gui/queue.c @@ -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);