gui/queue: Add a switch to enable and disable tempqueues
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
d19e0b2cc0
commit
bc9efade75
31
gui/queue.c
31
gui/queue.c
|
@ -37,6 +37,17 @@ void __queue_repeat(GtkToggleButton *button, gpointer data)
|
||||||
__queue_toggle_button(button, Q_REPEAT);
|
__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,
|
struct gui_queue *gui_queue_alloc(struct queue *queue, const gchar *text,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
|
@ -61,23 +72,27 @@ void gui_queue_free(struct queue *queue)
|
||||||
|
|
||||||
void gui_queue_show(struct gui_queue *queue)
|
void gui_queue_show(struct gui_queue *queue)
|
||||||
{
|
{
|
||||||
GtkButton *random = GTK_BUTTON(gui_builder_widget("o_random"));
|
GtkButton *random = GTK_BUTTON(gui_builder_widget("o_random"));
|
||||||
GtkButton *repeat = GTK_BUTTON(gui_builder_widget("o_repeat"));
|
GtkButton *repeat = GTK_BUTTON(gui_builder_widget("o_repeat"));
|
||||||
GtkEntry *search = GTK_ENTRY(gui_builder_widget("o_search"));
|
GtkSwitch *enabled = GTK_SWITCH(gui_builder_widget("o_enable"));
|
||||||
bool has_random = false, has_repeat = false;
|
GtkEntry *search = GTK_ENTRY(gui_builder_widget("o_search"));
|
||||||
|
bool has_random = false, has_repeat = false, is_enabled = false;;
|
||||||
|
|
||||||
gq_queue = queue;
|
gq_queue = queue;
|
||||||
|
|
||||||
gtk_widget_set_sensitive(GTK_WIDGET(random), gui_queue_can_random(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(repeat), gui_queue_can_repeat(queue));
|
||||||
|
gtk_widget_set_sensitive(GTK_WIDGET(enabled), gui_queue_can_disable(queue));
|
||||||
|
|
||||||
if (queue) {
|
if (queue) {
|
||||||
has_random = queue_has_flag(queue->gq_queue, Q_RANDOM);
|
has_random = queue_has_flag(queue->gq_queue, Q_RANDOM);
|
||||||
has_repeat = queue_has_flag(queue->gq_queue, Q_REPEAT);
|
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(random), has_random);
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(repeat), has_repeat);
|
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,
|
* Some GTK themes have trouble with toggle buttons,
|
||||||
|
|
|
@ -27,7 +27,7 @@ static compare_t sort_fields[] = {
|
||||||
static void *tempq_init(struct queue *queue)
|
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);
|
GQ_CAN_RANDOM | GQ_CAN_REPEAT | GQ_CAN_DISABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tempq_added(struct queue *queue, unsigned int pos)
|
static void tempq_added(struct queue *queue, unsigned int pos)
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
#include <core/queue.h>
|
#include <core/queue.h>
|
||||||
|
|
||||||
enum gui_queue_flags {
|
enum gui_queue_flags {
|
||||||
GQ_CAN_RANDOM = (1 << 0), /* Random 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_REPEAT = (1 << 1), /* Repeat button can be clicked. */
|
||||||
|
GQ_CAN_DISABLE = (1 << 2), /* Disable switch can be clicked. */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gui_queue {
|
struct gui_queue {
|
||||||
|
@ -47,6 +48,14 @@ static inline bool gui_queue_can_repeat(struct gui_queue *gq)
|
||||||
return false;
|
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. */
|
/* Called to set the correct state of the random and repeat buttons. */
|
||||||
void gui_queue_show(struct gui_queue *);
|
void gui_queue_show(struct gui_queue *);
|
||||||
|
|
||||||
|
|
|
@ -846,6 +846,7 @@
|
||||||
<object class="GtkBox" id="box10">
|
<object class="GtkBox" id="box10">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="spacing">5</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkSearchEntry" id="o_search">
|
<object class="GtkSearchEntry" id="o_search">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
@ -863,6 +864,20 @@
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSwitch" id="o_enable">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<property name="active">True</property>
|
||||||
|
<signal name="notify::active" handler="__queue_disabled" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
static void *test_queue_init(struct queue *queue)
|
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);
|
GQ_CAN_RANDOM | GQ_CAN_REPEAT | GQ_CAN_DISABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __test_queue_clear(struct queue *queue, unsigned int n) {}
|
void __test_queue_clear(struct queue *queue, unsigned int n) {}
|
||||||
|
@ -30,6 +30,7 @@ static void test_queue()
|
||||||
GtkToggleButton *random, *repeat;
|
GtkToggleButton *random, *repeat;
|
||||||
GtkWidget *random_img, *repeat_img;
|
GtkWidget *random_img, *repeat_img;
|
||||||
struct gui_queue *gq;
|
struct gui_queue *gq;
|
||||||
|
GtkSwitch *enable;
|
||||||
GtkEntry *search;
|
GtkEntry *search;
|
||||||
struct queue q;
|
struct queue q;
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -37,6 +38,7 @@ static void test_queue()
|
||||||
gtk_init(&argc, NULL);
|
gtk_init(&argc, NULL);
|
||||||
gui_builder_init("share/ocarina/ocarina6.glade");
|
gui_builder_init("share/ocarina/ocarina6.glade");
|
||||||
search = GTK_ENTRY(gui_builder_widget("o_search"));
|
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"));
|
random = GTK_TOGGLE_BUTTON(gui_builder_widget("o_random"));
|
||||||
repeat = GTK_TOGGLE_BUTTON(gui_builder_widget("o_repeat"));
|
repeat = GTK_TOGGLE_BUTTON(gui_builder_widget("o_repeat"));
|
||||||
random_img = gtk_button_get_image(GTK_BUTTON(random));
|
random_img = gtk_button_get_image(GTK_BUTTON(random));
|
||||||
|
@ -45,21 +47,25 @@ static void test_queue()
|
||||||
/* Test initialization */
|
/* Test initialization */
|
||||||
queue_init(&q, 0, &test_ops);
|
queue_init(&q, 0, &test_ops);
|
||||||
gq = gui_queue(&q);
|
gq = gui_queue(&q);
|
||||||
test_equal(gui_queue_can_random(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_repeat(gq), (bool)true);
|
||||||
|
test_equal(gui_queue_can_disable(gq), (bool)true);
|
||||||
|
|
||||||
gq->gq_flags = 0;
|
gq->gq_flags = 0;
|
||||||
test_equal(gui_queue_can_random(NULL), (bool)false);
|
test_equal(gui_queue_can_random(gq), (bool)false);
|
||||||
test_equal(gui_queue_can_repeat(NULL), (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");
|
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);
|
gui_queue_show(gq);
|
||||||
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), 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(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(random), false);
|
||||||
test_equal(gtk_toggle_button_get_active(repeat), 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(random_img), false);
|
||||||
test_equal(gtk_widget_get_sensitive(repeat_img), false);
|
test_equal(gtk_widget_get_sensitive(repeat_img), false);
|
||||||
test_equal(gtk_entry_get_text(search), "");
|
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(gtk_widget_get_sensitive(repeat_img), false);
|
||||||
test_equal(queue_has_flag(&q, Q_REPEAT), (bool)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 */
|
/* 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;
|
q.q_flags = Q_RANDOM | Q_REPEAT;
|
||||||
gui_queue_show(gq);
|
gui_queue_show(gq);
|
||||||
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), true);
|
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(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(random), true);
|
||||||
test_equal(gtk_toggle_button_get_active(repeat), 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(random_img), true);
|
||||||
test_equal(gtk_widget_get_sensitive(repeat_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(search)), false);
|
||||||
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), 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(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(random), false);
|
||||||
test_equal(gtk_toggle_button_get_active(repeat), 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(random_img), false);
|
||||||
test_equal(gtk_widget_get_sensitive(repeat_img), false);
|
test_equal(gtk_widget_get_sensitive(repeat_img), false);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue