2016-01-12 08:19:05 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-01-20 08:33:24 -05:00
|
|
|
#include <core/filter.h>
|
|
|
|
#include <core/string.h>
|
2016-01-14 08:59:26 -05:00
|
|
|
#include <gui/builder.h>
|
2016-01-18 09:07:00 -05:00
|
|
|
#include <gui/model.h>
|
2016-01-12 08:19:05 -05:00
|
|
|
#include <gui/queue.h>
|
2016-01-21 15:18:37 -05:00
|
|
|
#include <gui/view.h>
|
2016-01-12 08:19:05 -05:00
|
|
|
|
2016-01-14 10:24:10 -05:00
|
|
|
static struct gui_queue *gq_queue = NULL;
|
|
|
|
|
2016-01-19 08:39:44 -05:00
|
|
|
static void __queue_toggle_flag(bool active, GtkWidget *widget,
|
|
|
|
enum queue_flags flag)
|
2016-01-14 10:24:10 -05:00
|
|
|
{
|
|
|
|
if (gq_queue == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some GTK themes have trouble with toggle buttons,
|
|
|
|
* so let's help users by changing image sensitivity.
|
|
|
|
*/
|
2016-01-19 08:39:44 -05:00
|
|
|
if (active)
|
2016-01-14 10:24:10 -05:00
|
|
|
queue_set_flag(gq_queue->gq_queue, flag);
|
2016-01-19 08:39:44 -05:00
|
|
|
else
|
2016-01-14 10:24:10 -05:00
|
|
|
queue_unset_flag(gq_queue->gq_queue, flag);
|
2016-01-19 08:39:44 -05:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive(widget, active);
|
2016-01-14 10:24:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void __queue_random(GtkToggleButton *button, gpointer data)
|
|
|
|
{
|
2016-01-19 08:39:44 -05:00
|
|
|
__queue_toggle_flag(gtk_toggle_button_get_active(button),
|
|
|
|
gtk_button_get_image(GTK_BUTTON(button)),
|
|
|
|
Q_RANDOM);
|
2016-01-14 10:24:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void __queue_repeat(GtkToggleButton *button, gpointer data)
|
|
|
|
{
|
2016-01-19 08:39:44 -05:00
|
|
|
__queue_toggle_flag(gtk_toggle_button_get_active(button),
|
|
|
|
gtk_button_get_image(GTK_BUTTON(button)),
|
|
|
|
Q_REPEAT);
|
2016-01-14 10:24:10 -05:00
|
|
|
}
|
|
|
|
|
2016-01-15 12:12:12 -05:00
|
|
|
void __queue_disabled(GtkSwitch *enabled, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
2016-01-19 08:39:44 -05:00
|
|
|
__queue_toggle_flag(gtk_switch_get_active(enabled),
|
|
|
|
gui_builder_widget("o_treeview"),
|
|
|
|
Q_ENABLED);
|
2016-01-15 12:12:12 -05:00
|
|
|
}
|
|
|
|
|
2016-01-20 08:33:24 -05:00
|
|
|
static gboolean __queue_visible_func(GtkTreeModel *model, GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
struct track *track;
|
|
|
|
|
|
|
|
if (!gq_queue || (strlen(gtk_entry_get_text(GTK_ENTRY(data))) == 0))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
track = gui_queue_model_iter_get_track(gq_queue->gq_model, iter);
|
|
|
|
return set_has(&gq_queue->gq_visible, track->tr_dbe.dbe_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __queue_filter(GtkSearchEntry *entry, gpointer data)
|
|
|
|
{
|
|
|
|
const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
|
|
|
|
|
|
|
|
if (!gq_queue)
|
|
|
|
return;
|
|
|
|
if (strlen(text) > 0)
|
|
|
|
filter_search(text, &gq_queue->gq_visible);
|
|
|
|
gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(gq_queue->gq_filter));
|
|
|
|
}
|
|
|
|
|
2016-01-14 08:00:04 -05:00
|
|
|
struct gui_queue *gui_queue_alloc(struct queue *queue, const gchar *text,
|
|
|
|
unsigned int flags)
|
2016-01-12 08:19:05 -05:00
|
|
|
{
|
|
|
|
struct gui_queue *gq = g_malloc(sizeof(struct gui_queue));
|
|
|
|
|
2016-01-20 08:33:24 -05:00
|
|
|
gq->gq_flags = flags;
|
|
|
|
gq->gq_text = g_strdup(text);
|
|
|
|
gq->gq_model = gui_queue_model_new(queue);
|
|
|
|
gq->gq_filter = gtk_tree_model_filter_new(
|
|
|
|
GTK_TREE_MODEL(gq->gq_model), NULL);
|
|
|
|
gq->gq_queue = queue;
|
|
|
|
|
|
|
|
set_init(&gq->gq_visible);
|
|
|
|
gtk_tree_model_filter_set_visible_func(
|
|
|
|
GTK_TREE_MODEL_FILTER(gq->gq_filter),
|
|
|
|
__queue_visible_func,
|
|
|
|
gui_builder_object("o_search"), NULL);
|
2016-01-14 08:00:04 -05:00
|
|
|
|
2016-01-12 08:19:05 -05:00
|
|
|
return gq;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_queue_free(struct queue *queue)
|
|
|
|
{
|
2016-01-19 08:39:44 -05:00
|
|
|
struct gui_queue *gq = gui_queue(queue);
|
2016-01-12 08:19:05 -05:00
|
|
|
|
2016-01-20 08:33:24 -05:00
|
|
|
set_deinit(&gq->gq_visible);
|
2016-01-12 08:19:05 -05:00
|
|
|
queue->q_private = NULL;
|
2016-01-13 16:48:43 -05:00
|
|
|
|
2016-01-21 15:18:37 -05:00
|
|
|
if (gq_queue == gq)
|
|
|
|
gui_view_set_model(NULL);
|
2016-01-18 08:54:24 -05:00
|
|
|
g_object_unref(gq->gq_model);
|
2016-01-13 16:48:43 -05:00
|
|
|
g_free(gq->gq_text);
|
2016-01-12 08:19:05 -05:00
|
|
|
g_free(gq);
|
|
|
|
}
|
2016-01-14 08:59:26 -05:00
|
|
|
|
|
|
|
void gui_queue_show(struct gui_queue *queue)
|
|
|
|
{
|
2016-01-19 08:39:44 -05:00
|
|
|
GtkTreeView *view = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
2016-01-15 12:12:12 -05:00
|
|
|
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;;
|
2016-01-14 08:59:26 -05:00
|
|
|
|
2016-01-14 10:24:10 -05:00
|
|
|
gq_queue = queue;
|
|
|
|
|
2016-01-15 12:12:12 -05:00
|
|
|
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));
|
2016-01-14 08:59:26 -05:00
|
|
|
|
|
|
|
if (queue) {
|
|
|
|
has_random = queue_has_flag(queue->gq_queue, Q_RANDOM);
|
|
|
|
has_repeat = queue_has_flag(queue->gq_queue, Q_REPEAT);
|
2016-01-15 12:12:12 -05:00
|
|
|
is_enabled = queue_has_flag(queue->gq_queue, Q_ENABLED);
|
2016-01-21 15:18:37 -05:00
|
|
|
gui_view_set_model(GTK_TREE_MODEL_FILTER(queue->gq_filter));
|
2016-01-14 08:59:26 -05:00
|
|
|
}
|
|
|
|
|
2016-01-15 12:12:12 -05:00
|
|
|
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);
|
2016-01-14 08:59:26 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
2016-01-19 08:39:44 -05:00
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(view), is_enabled);
|
2016-01-15 09:35:25 -05:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(search), queue != NULL);
|
|
|
|
gtk_entry_set_text(search, "");
|
2016-01-14 08:59:26 -05:00
|
|
|
}
|
2016-01-18 09:07:00 -05:00
|
|
|
|
|
|
|
void gui_queue_added(struct queue *queue, unsigned int row)
|
|
|
|
{
|
|
|
|
gui_queue_model_add(gui_queue(queue)->gq_model, row);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_queue_removed(struct queue *queue, unsigned int row)
|
|
|
|
{
|
|
|
|
gui_queue_model_remove(gui_queue(queue)->gq_model, row);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_queue_cleared(struct queue *queue, unsigned int n)
|
|
|
|
{
|
|
|
|
gui_queue_model_clear(gui_queue(queue)->gq_model, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_queue_updated(struct queue *queue, unsigned int row)
|
|
|
|
{
|
|
|
|
gui_queue_model_update(gui_queue(queue)->gq_model, row);
|
|
|
|
}
|