gui/queue: Add a single treeview instance

And swap out the model when queues are shown.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-01-19 08:39:44 -05:00
parent c5e03d98cf
commit 13525eda22
3 changed files with 203 additions and 33 deletions

View File

@ -7,11 +7,9 @@
static struct gui_queue *gq_queue = NULL;
static void __queue_toggle_button(GtkToggleButton *button,
enum queue_flags flag)
static void __queue_toggle_flag(bool active, GtkWidget *widget,
enum queue_flags flag)
{
GtkWidget *image = gtk_button_get_image(GTK_BUTTON(button));
if (gq_queue == NULL)
return;
@ -19,34 +17,33 @@ static void __queue_toggle_button(GtkToggleButton *button,
* Some GTK themes have trouble with toggle buttons,
* so let's help users by changing image sensitivity.
*/
if (gtk_toggle_button_get_active(button)) {
if (active)
queue_set_flag(gq_queue->gq_queue, flag);
gtk_widget_set_sensitive(image, true);
} else {
else
queue_unset_flag(gq_queue->gq_queue, flag);
gtk_widget_set_sensitive(image, false);
}
gtk_widget_set_sensitive(widget, active);
}
void __queue_random(GtkToggleButton *button, gpointer data)
{
__queue_toggle_button(button, Q_RANDOM);
__queue_toggle_flag(gtk_toggle_button_get_active(button),
gtk_button_get_image(GTK_BUTTON(button)),
Q_RANDOM);
}
void __queue_repeat(GtkToggleButton *button, gpointer data)
{
__queue_toggle_button(button, Q_REPEAT);
__queue_toggle_flag(gtk_toggle_button_get_active(button),
gtk_button_get_image(GTK_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);
__queue_toggle_flag(gtk_switch_get_active(enabled),
gui_builder_widget("o_treeview"),
Q_ENABLED);
}
struct gui_queue *gui_queue_alloc(struct queue *queue, const gchar *text,
@ -64,8 +61,10 @@ struct gui_queue *gui_queue_alloc(struct queue *queue, const gchar *text,
void gui_queue_free(struct queue *queue)
{
struct gui_queue *gq = gui_queue(queue);
GtkTreeView *treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
struct gui_queue *gq = gui_queue(queue);
gtk_tree_view_set_model(treeview, NULL);
queue->q_private = NULL;
g_object_unref(gq->gq_model);
@ -75,6 +74,7 @@ void gui_queue_free(struct queue *queue)
void gui_queue_show(struct gui_queue *queue)
{
GtkTreeView *view = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
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"));
@ -91,6 +91,7 @@ void gui_queue_show(struct gui_queue *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_tree_view_set_model(view, GTK_TREE_MODEL(queue->gq_model));
}
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), has_random);
@ -103,6 +104,7 @@ void gui_queue_show(struct gui_queue *queue)
*/
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(view), is_enabled);
gtk_widget_set_sensitive(GTK_WIDGET(search), queue != NULL);
gtk_entry_set_text(search, "");

View File

@ -1097,6 +1097,167 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="o_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="enable_search">False</property>
<property name="rubber_banding">True</property>
<property name="tooltip_column">9</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection5">
<property name="mode">multiple</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn8">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">20</property>
<property name="title" translatable="yes">#</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext4"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn9">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">300</property>
<property name="title" translatable="yes">Title</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext5"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn10">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">60</property>
<property name="title" translatable="yes">Length</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext6"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn11">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Artist</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext7"/>
<attributes>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn12">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Album</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext8"/>
<attributes>
<attribute name="text">4</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn13">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">45</property>
<property name="title" translatable="yes">Year</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext9"/>
<attributes>
<attribute name="text">5</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn14">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Genre</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext10"/>
<attributes>
<attribute name="text">6</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn15">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">60</property>
<property name="title" translatable="yes">Count</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext11"/>
<attributes>
<attribute name="text">7</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn16">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">1</property>
<property name="title" translatable="yes">Played</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext12"/>
<attributes>
<attribute name="text">8</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkNotebook" id="o_notebook">
<property name="visible">True</property>
@ -1116,7 +1277,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>

View File

@ -33,6 +33,7 @@ static void test_queue()
{
GtkToggleButton *random, *repeat;
GtkWidget *random_img, *repeat_img;
GtkTreeView *treeview;
struct gui_queue *gq;
GtkSwitch *enable;
GtkEntry *search;
@ -47,6 +48,7 @@ static void test_queue()
repeat = GTK_TOGGLE_BUTTON(gui_builder_widget("o_repeat"));
random_img = gtk_button_get_image(GTK_BUTTON(random));
repeat_img = gtk_button_get_image(GTK_BUTTON(repeat));
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
/* Test initialization */
queue_init(&q, 0, &test_ops);
@ -67,9 +69,10 @@ static void test_queue()
/* 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_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_widget_get_sensitive(GTK_WIDGET(treeview)), 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);
@ -97,30 +100,34 @@ static void test_queue()
/* Test clicking enabled switch. */
gtk_switch_set_active(enable, true);
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(treeview)), true);
test_equal(queue_has_flag(&q, Q_ENABLED), (bool)true);
gtk_switch_set_active(enable, false);
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(treeview)), 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, repeat, and switch are enabled */
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 | Q_ENABLED;
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_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_widget_get_sensitive(GTK_WIDGET(treeview)), 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_switch_get_active(enable), true);
test_equal(gtk_widget_get_sensitive(random_img), true);
test_equal(gtk_widget_get_sensitive(repeat_img), true);
/* Attempt to show a NULL pointer */
gui_queue_show(NULL);
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_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_widget_get_sensitive(GTK_WIDGET(treeview)), 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);