diff --git a/gui/queue.c b/gui/queue.c index 35409402..8bda29a1 100644 --- a/gui/queue.c +++ b/gui/queue.c @@ -37,6 +37,17 @@ void __queue_repeat(GtkToggleButton *button, gpointer data) __queue_toggle_button(button, Q_REPEAT); } +void __queue_disabled(GtkSwitch *enabled, GParamSpec *pspec, gpointer data) +{ + if (gq_queue == NULL) + return; + + if (gtk_switch_get_active(enabled)) + queue_set_flag(gq_queue->gq_queue, Q_ENABLED); + else + queue_unset_flag(gq_queue->gq_queue, Q_ENABLED); +} + struct gui_queue *gui_queue_alloc(struct queue *queue, const gchar *text, unsigned int flags) { @@ -61,23 +72,27 @@ void gui_queue_free(struct queue *queue) void gui_queue_show(struct gui_queue *queue) { - GtkButton *random = GTK_BUTTON(gui_builder_widget("o_random")); - GtkButton *repeat = GTK_BUTTON(gui_builder_widget("o_repeat")); - GtkEntry *search = GTK_ENTRY(gui_builder_widget("o_search")); - bool has_random = false, has_repeat = false; + GtkButton *random = GTK_BUTTON(gui_builder_widget("o_random")); + GtkButton *repeat = GTK_BUTTON(gui_builder_widget("o_repeat")); + GtkSwitch *enabled = GTK_SWITCH(gui_builder_widget("o_enable")); + GtkEntry *search = GTK_ENTRY(gui_builder_widget("o_search")); + bool has_random = false, has_repeat = false, is_enabled = false;; gq_queue = queue; - gtk_widget_set_sensitive(GTK_WIDGET(random), gui_queue_can_random(queue)); - gtk_widget_set_sensitive(GTK_WIDGET(repeat), gui_queue_can_repeat(queue)); + gtk_widget_set_sensitive(GTK_WIDGET(random), gui_queue_can_random(queue)); + gtk_widget_set_sensitive(GTK_WIDGET(repeat), gui_queue_can_repeat(queue)); + gtk_widget_set_sensitive(GTK_WIDGET(enabled), gui_queue_can_disable(queue)); if (queue) { has_random = queue_has_flag(queue->gq_queue, Q_RANDOM); has_repeat = queue_has_flag(queue->gq_queue, Q_REPEAT); + is_enabled = queue_has_flag(queue->gq_queue, Q_ENABLED); } - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), has_random); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(repeat), has_repeat); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), has_random); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(repeat), has_repeat); + gtk_switch_set_active(GTK_SWITCH(enabled), is_enabled); /* * Some GTK themes have trouble with toggle buttons, diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 20eeb1f5..1c214704 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -27,7 +27,7 @@ static compare_t sort_fields[] = { static void *tempq_init(struct queue *queue) { return gui_queue_alloc(queue, "Queued Tracks", - GQ_CAN_RANDOM | GQ_CAN_REPEAT); + GQ_CAN_RANDOM | GQ_CAN_REPEAT | GQ_CAN_DISABLE); } static void tempq_added(struct queue *queue, unsigned int pos) diff --git a/include/gui/queue.h b/include/gui/queue.h index f5f47b5d..10771d36 100644 --- a/include/gui/queue.h +++ b/include/gui/queue.h @@ -7,8 +7,9 @@ #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. */ + GQ_CAN_RANDOM = (1 << 0), /* Random button can be clicked. */ + GQ_CAN_REPEAT = (1 << 1), /* Repeat button can be clicked. */ + GQ_CAN_DISABLE = (1 << 2), /* Disable switch can be clicked. */ }; struct gui_queue { @@ -47,6 +48,14 @@ static inline bool gui_queue_can_repeat(struct gui_queue *gq) return false; } +/* Called to ask the struct gui_queue if it can change enabled flag. */ +static inline bool gui_queue_can_disable(struct gui_queue *gq) +{ + if (gq) + return (gq->gq_flags & GQ_CAN_DISABLE) == GQ_CAN_DISABLE; + return false; +} + /* Called to set the correct state of the random and repeat buttons. */ void gui_queue_show(struct gui_queue *); diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index 221c4b79..4117c0d4 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -846,6 +846,7 @@ True False + 5 True @@ -863,6 +864,20 @@ 0 + + + True + True + center + True + + + + False + True + 1 + + False diff --git a/tests/gui/queue.c b/tests/gui/queue.c index b0808800..ca926bc5 100644 --- a/tests/gui/queue.c +++ b/tests/gui/queue.c @@ -14,7 +14,7 @@ static void *test_queue_init(struct queue *queue) { return gui_queue_alloc(queue, "Test Queue", - GQ_CAN_RANDOM | GQ_CAN_REPEAT); + GQ_CAN_RANDOM | GQ_CAN_REPEAT | GQ_CAN_DISABLE); } void __test_queue_clear(struct queue *queue, unsigned int n) {} @@ -30,6 +30,7 @@ static void test_queue() GtkToggleButton *random, *repeat; GtkWidget *random_img, *repeat_img; struct gui_queue *gq; + GtkSwitch *enable; GtkEntry *search; struct queue q; int argc = 0; @@ -37,6 +38,7 @@ static void test_queue() gtk_init(&argc, NULL); gui_builder_init("share/ocarina/ocarina6.glade"); search = GTK_ENTRY(gui_builder_widget("o_search")); + enable = GTK_SWITCH(gui_builder_widget("o_enable")); random = GTK_TOGGLE_BUTTON(gui_builder_widget("o_random")); repeat = GTK_TOGGLE_BUTTON(gui_builder_widget("o_repeat")); random_img = gtk_button_get_image(GTK_BUTTON(random)); @@ -45,21 +47,25 @@ static void test_queue() /* Test initialization */ queue_init(&q, 0, &test_ops); gq = gui_queue(&q); - test_equal(gui_queue_can_random(gq), (bool)true); - test_equal(gui_queue_can_repeat(gq), (bool)true); + test_equal(gui_queue_can_random(gq), (bool)true); + test_equal(gui_queue_can_repeat(gq), (bool)true); + test_equal(gui_queue_can_disable(gq), (bool)true); gq->gq_flags = 0; - test_equal(gui_queue_can_random(NULL), (bool)false); - test_equal(gui_queue_can_repeat(NULL), (bool)false); + test_equal(gui_queue_can_random(gq), (bool)false); + test_equal(gui_queue_can_repeat(gq), (bool)false); + test_equal(gui_queue_can_disable(gq), (bool)false); gtk_entry_set_text(search, "Test text"); - /* Show a queue where random and repeat are disabled */ + /* Show a queue where random, repeat, and switch are disabled */ gui_queue_show(gq); test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), false); test_equal(gtk_widget_get_sensitive(GTK_WIDGET(repeat)), false); + test_equal(gtk_widget_get_sensitive(GTK_WIDGET(enable)), false); test_equal(gtk_toggle_button_get_active(random), false); test_equal(gtk_toggle_button_get_active(repeat), false); + test_equal(gtk_switch_get_active(enable), false); test_equal(gtk_widget_get_sensitive(random_img), false); test_equal(gtk_widget_get_sensitive(repeat_img), false); test_equal(gtk_entry_get_text(search), ""); @@ -82,14 +88,23 @@ static void test_queue() test_equal(gtk_widget_get_sensitive(repeat_img), false); test_equal(queue_has_flag(&q, Q_REPEAT), (bool)false); + /* Test clicking enabled switch. */ + gtk_switch_set_active(enable, true); + test_equal(queue_has_flag(&q, Q_ENABLED), (bool)true); + + gtk_switch_set_active(enable, false); + test_equal(queue_has_flag(&q, Q_ENABLED), (bool)false); + /* Show a queue where random and repeat are enabled */ - gq->gq_flags = GQ_CAN_RANDOM | GQ_CAN_REPEAT; + gq->gq_flags = GQ_CAN_RANDOM | GQ_CAN_REPEAT | GQ_CAN_DISABLE; q.q_flags = Q_RANDOM | Q_REPEAT; gui_queue_show(gq); test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), true); test_equal(gtk_widget_get_sensitive(GTK_WIDGET(repeat)), true); + test_equal(gtk_widget_get_sensitive(GTK_WIDGET(enable)), true); test_equal(gtk_toggle_button_get_active(random), true); test_equal(gtk_toggle_button_get_active(repeat), true); + test_equal(gtk_switch_get_active(enable), false); test_equal(gtk_widget_get_sensitive(random_img), true); test_equal(gtk_widget_get_sensitive(repeat_img), true); @@ -98,8 +113,10 @@ static void test_queue() test_equal(gtk_widget_get_sensitive(GTK_WIDGET(search)), false); test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), false); test_equal(gtk_widget_get_sensitive(GTK_WIDGET(repeat)), false); + test_equal(gtk_widget_get_sensitive(GTK_WIDGET(enable)), false); test_equal(gtk_toggle_button_get_active(random), false); test_equal(gtk_toggle_button_get_active(repeat), false); + test_equal(gtk_switch_get_active(enable), false); test_equal(gtk_widget_get_sensitive(random_img), false); test_equal(gtk_widget_get_sensitive(repeat_img), false);