ocarina/gui/queue.c

92 lines
2.3 KiB
C

/*
* Copyright 2016 (c) Anna Schumaker.
*/
#include <gui/builder.h>
#include <gui/queue.h>
static struct gui_queue *gq_queue = NULL;
static void __queue_toggle_button(GtkToggleButton *button,
enum queue_flags flag)
{
GtkWidget *image = gtk_button_get_image(GTK_BUTTON(button));
if (gq_queue == NULL)
return;
/*
* Some GTK themes have trouble with toggle buttons,
* so let's help users by changing image sensitivity.
*/
if (gtk_toggle_button_get_active(button)) {
queue_set_flag(gq_queue->gq_queue, flag);
gtk_widget_set_sensitive(image, true);
} else {
queue_unset_flag(gq_queue->gq_queue, flag);
gtk_widget_set_sensitive(image, false);
}
}
void __queue_random(GtkToggleButton *button, gpointer data)
{
__queue_toggle_button(button, Q_RANDOM);
}
void __queue_repeat(GtkToggleButton *button, gpointer data)
{
__queue_toggle_button(button, Q_REPEAT);
}
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_flags = flags;
gq->gq_text = g_strdup(text);
gq->gq_queue = queue;
return gq;
}
void gui_queue_free(struct queue *queue)
{
struct gui_queue *gq = gui_queue(queue);
queue->q_private = NULL;
g_free(gq->gq_text);
g_free(gq);
}
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;
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));
if (queue) {
has_random = queue_has_flag(queue->gq_queue, Q_RANDOM);
has_repeat = queue_has_flag(queue->gq_queue, Q_REPEAT);
}
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), has_random);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(repeat), has_repeat);
/*
* Some GTK themes have trouble with toggle buttons,
* so let's help users know what the current state is.
*/
gtk_widget_set_sensitive(gtk_button_get_image(random), has_random);
gtk_widget_set_sensitive(gtk_button_get_image(repeat), has_repeat);
gtk_widget_set_sensitive(GTK_WIDGET(search), queue != NULL);
gtk_entry_set_text(search, "");
}