gui/queue: Only allocate a single GtkTreeModelFilter
The view is now responsible for allocating the filter, but the gui_queue still needs to set the filter function during an init step. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
0255522340
commit
313c4914df
|
@ -54,9 +54,10 @@ static void __ocarina_startup(GApplication *application, gpointer data)
|
||||||
|
|
||||||
gui_builder_init(ui);
|
gui_builder_init(ui);
|
||||||
gui_settings_init();
|
gui_settings_init();
|
||||||
gui_queue_model_init();
|
|
||||||
core_init(&startup_argc, &startup_argv, &init_data);
|
core_init(&startup_argc, &startup_argv, &init_data);
|
||||||
|
gui_queue_model_init();
|
||||||
gui_view_init();
|
gui_view_init();
|
||||||
|
gui_queue_init();
|
||||||
gui_window_init(icon);
|
gui_window_init(icon);
|
||||||
gui_sidebar_init();
|
gui_sidebar_init();
|
||||||
gui_collection_init();
|
gui_collection_init();
|
||||||
|
|
25
gui/queue.c
25
gui/queue.c
|
@ -131,6 +131,14 @@ void __queue_filter_how_changed(int n)
|
||||||
__queue_filter(GTK_SEARCH_ENTRY(gui_builder_widget("o_search")), NULL);
|
__queue_filter(GTK_SEARCH_ENTRY(gui_builder_widget("o_search")), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gui_queue_init(void)
|
||||||
|
{
|
||||||
|
gtk_tree_model_filter_set_visible_func(gui_view_get_filter(),
|
||||||
|
__queue_visible_func,
|
||||||
|
gui_builder_object("o_search"),
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
struct gui_queue *gui_queue_alloc(struct playlist *playlist, struct queue *queue,
|
struct gui_queue *gui_queue_alloc(struct playlist *playlist, struct queue *queue,
|
||||||
const gchar *text, unsigned int flags)
|
const gchar *text, unsigned int flags)
|
||||||
{
|
{
|
||||||
|
@ -140,17 +148,10 @@ struct gui_queue *gui_queue_alloc(struct playlist *playlist, struct queue *queue
|
||||||
gq->gq_text = g_strdup(text);
|
gq->gq_text = g_strdup(text);
|
||||||
gq->gq_search = NULL;
|
gq->gq_search = NULL;
|
||||||
gq->gq_model = g_object_ref(gui_queue_model_get());
|
gq->gq_model = g_object_ref(gui_queue_model_get());
|
||||||
gui_queue_model_set_queue(queue);
|
gq->gq_filter = GTK_TREE_MODEL(gui_view_get_filter());
|
||||||
gq->gq_filter = gtk_tree_model_filter_new(
|
|
||||||
GTK_TREE_MODEL(gq->gq_model), NULL);
|
|
||||||
gq->gq_playlist = playlist;
|
gq->gq_playlist = playlist;
|
||||||
gq->gq_queue = queue;
|
gq->gq_queue = queue;
|
||||||
|
|
||||||
gtk_tree_model_filter_set_visible_func(
|
|
||||||
GTK_TREE_MODEL_FILTER(gq->gq_filter),
|
|
||||||
__queue_visible_func,
|
|
||||||
gui_builder_object("o_search"), NULL);
|
|
||||||
|
|
||||||
return gq;
|
return gq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +162,7 @@ void gui_queue_free(struct queue *queue)
|
||||||
queue->q_private = NULL;
|
queue->q_private = NULL;
|
||||||
|
|
||||||
if (gq_queue == gq)
|
if (gq_queue == gq)
|
||||||
gui_view_set_model(NULL);
|
gui_view_set_queue(NULL);
|
||||||
if (gq->gq_search)
|
if (gq->gq_search)
|
||||||
g_strfreev(gq->gq_search);
|
g_strfreev(gq->gq_search);
|
||||||
g_object_unref(gq->gq_model);
|
g_object_unref(gq->gq_model);
|
||||||
|
@ -176,7 +177,6 @@ void gui_queue_show(struct gui_queue *queue)
|
||||||
GtkButton *repeat = GTK_BUTTON(gui_builder_widget("o_repeat"));
|
GtkButton *repeat = GTK_BUTTON(gui_builder_widget("o_repeat"));
|
||||||
GtkSwitch *enabled = GTK_SWITCH(gui_builder_widget("o_enable"));
|
GtkSwitch *enabled = GTK_SWITCH(gui_builder_widget("o_enable"));
|
||||||
GtkEntry *search = GTK_ENTRY(gui_builder_widget("o_search"));
|
GtkEntry *search = GTK_ENTRY(gui_builder_widget("o_search"));
|
||||||
GtkLabel *runtime = GTK_LABEL(gui_builder_widget("o_runtime"));
|
|
||||||
bool has_random = false, has_repeat = false, is_enabled = false;;
|
bool has_random = false, has_repeat = false, is_enabled = false;;
|
||||||
gchar *text;
|
gchar *text;
|
||||||
|
|
||||||
|
@ -190,10 +190,9 @@ void gui_queue_show(struct gui_queue *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);
|
is_enabled = queue_has_flag(queue->gq_queue, Q_ENABLED);
|
||||||
gui_queue_model_set_queue(queue->gq_queue);
|
gui_view_set_queue(queue->gq_queue);
|
||||||
gui_view_set_model(GTK_TREE_MODEL_FILTER(queue->gq_filter));
|
|
||||||
} else
|
} else
|
||||||
gtk_label_set_text(runtime, "");
|
gui_view_set_queue(NULL);
|
||||||
|
|
||||||
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);
|
||||||
|
|
14
gui/view.c
14
gui/view.c
|
@ -317,6 +317,8 @@ void gui_view_init()
|
||||||
int i, pos;
|
int i, pos;
|
||||||
|
|
||||||
view_treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
view_treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
||||||
|
view_filter = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(
|
||||||
|
GTK_TREE_MODEL(gui_queue_model_get()), NULL));
|
||||||
|
|
||||||
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
|
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
|
||||||
col = gtk_tree_view_get_column(view_treeview, i);
|
col = gtk_tree_view_get_column(view_treeview, i);
|
||||||
|
@ -324,12 +326,18 @@ void gui_view_init()
|
||||||
if (col && pos > 0)
|
if (col && pos > 0)
|
||||||
gtk_tree_view_column_set_fixed_width(col, pos);
|
gtk_tree_view_column_set_fixed_width(col, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gtk_tree_view_set_model(view_treeview, GTK_TREE_MODEL(view_filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_view_set_model(GtkTreeModelFilter *filter)
|
GtkTreeModelFilter *gui_view_get_filter(void)
|
||||||
{
|
{
|
||||||
view_filter = filter;
|
return view_filter;
|
||||||
gtk_tree_view_set_model(view_treeview, GTK_TREE_MODEL(filter));
|
}
|
||||||
|
|
||||||
|
void gui_view_set_queue(struct queue *queue)
|
||||||
|
{
|
||||||
|
gui_queue_model_set_queue(queue);
|
||||||
|
|
||||||
view_sort_count = 0;
|
view_sort_count = 0;
|
||||||
__view_display_sorting("");
|
__view_display_sorting("");
|
||||||
|
|
|
@ -26,6 +26,9 @@ struct gui_queue {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Called to initialize the gui_queue code. */
|
||||||
|
void gui_queue_init(void);
|
||||||
|
|
||||||
/* Called to allocate a new struct gui_queue. */
|
/* Called to allocate a new struct gui_queue. */
|
||||||
struct gui_queue *gui_queue_alloc(struct playlist *, struct queue *,
|
struct gui_queue *gui_queue_alloc(struct playlist *, struct queue *,
|
||||||
const gchar *, unsigned int);
|
const gchar *, unsigned int);
|
||||||
|
|
|
@ -4,13 +4,18 @@
|
||||||
#ifndef OCARINA_GUI_VIEW_H
|
#ifndef OCARINA_GUI_VIEW_H
|
||||||
#define OCARINA_GUI_VIEW_H
|
#define OCARINA_GUI_VIEW_H
|
||||||
|
|
||||||
|
#include <core/queue.h>
|
||||||
|
|
||||||
/* Called to initialize structures needed by the treeview. */
|
/* Called to initialize structures needed by the treeview. */
|
||||||
void gui_view_init();
|
void gui_view_init();
|
||||||
|
|
||||||
/* Called to scroll the GUI treeview to the queue's current position. */
|
/* Called to scroll the GUI treeview to the queue's current position. */
|
||||||
void gui_view_scroll();
|
void gui_view_scroll();
|
||||||
|
|
||||||
|
/* Called to get the GtkTreeModelFilter */
|
||||||
|
GtkTreeModelFilter *gui_view_get_filter(void);
|
||||||
|
|
||||||
/* Called to set the currently displayed model. */
|
/* Called to set the currently displayed model. */
|
||||||
void gui_view_set_model(GtkTreeModelFilter *);
|
void gui_view_set_queue(struct queue *);
|
||||||
|
|
||||||
#endif /* OCARINA_GUI_VIEW_H */
|
#endif /* OCARINA_GUI_VIEW_H */
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <core/core.h>
|
#include <core/core.h>
|
||||||
#include <core/idle.h>
|
#include <core/idle.h>
|
||||||
#include <gui/builder.h>
|
#include <gui/builder.h>
|
||||||
|
#include <gui/model.h>
|
||||||
#include <gui/playlist.h>
|
#include <gui/playlist.h>
|
||||||
#include <tests/gui.h>
|
#include <tests/gui.h>
|
||||||
#include <tests/test.h>
|
#include <tests/test.h>
|
||||||
|
@ -23,6 +24,7 @@ static void test_playlist_sidebar()
|
||||||
|
|
||||||
gtk_init(&argc, NULL);
|
gtk_init(&argc, NULL);
|
||||||
gui_builder_init("share/ocarina/ocarina6.glade");
|
gui_builder_init("share/ocarina/ocarina6.glade");
|
||||||
|
gui_queue_model_init();
|
||||||
core_init(&argc, NULL, &init_data);
|
core_init(&argc, NULL, &init_data);
|
||||||
gui_playlist_init();
|
gui_playlist_init();
|
||||||
while (idle_run_task()) {}
|
while (idle_run_task()) {}
|
||||||
|
|
|
@ -52,6 +52,7 @@ static void test_queue()
|
||||||
gui_builder_init("share/ocarina/ocarina6.glade");
|
gui_builder_init("share/ocarina/ocarina6.glade");
|
||||||
gui_queue_model_init();
|
gui_queue_model_init();
|
||||||
gui_view_init();
|
gui_view_init();
|
||||||
|
gui_queue_init();
|
||||||
while (idle_run_task()) {};
|
while (idle_run_task()) {};
|
||||||
|
|
||||||
search = GTK_ENTRY(gui_builder_widget("o_search"));
|
search = GTK_ENTRY(gui_builder_widget("o_search"));
|
||||||
|
|
|
@ -57,9 +57,9 @@ static int test_on_idle(gpointer data)
|
||||||
|
|
||||||
static void test_treeview()
|
static void test_treeview()
|
||||||
{
|
{
|
||||||
GtkTreeModel *model, *filter;
|
|
||||||
GtkTreeViewColumn *col;
|
GtkTreeViewColumn *col;
|
||||||
GtkTreeView *treeview;
|
GtkTreeView *treeview;
|
||||||
|
GtkTreeModel *filter;
|
||||||
GtkTreePath *path;
|
GtkTreePath *path;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
@ -71,13 +71,12 @@ static void test_treeview()
|
||||||
gui_settings_init();
|
gui_settings_init();
|
||||||
gui_queue_model_init();
|
gui_queue_model_init();
|
||||||
gui_view_init();
|
gui_view_init();
|
||||||
while (idle_run_task()) {}
|
while (idle_run_task() == true) {}
|
||||||
|
|
||||||
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||||
while (idle_run_task() == true) {}
|
while (idle_run_task() == true) {}
|
||||||
model = GTK_TREE_MODEL(gui_queue_model_get());
|
|
||||||
gui_queue_model_set_queue(playlist_get_queue(PL_SYSTEM, "Collection"));
|
gui_queue_model_set_queue(playlist_get_queue(PL_SYSTEM, "Collection"));
|
||||||
filter = gtk_tree_model_filter_new(model, NULL);
|
filter = GTK_TREE_MODEL(gui_view_get_filter());
|
||||||
|
|
||||||
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
||||||
main_loop = g_main_loop_new(NULL, FALSE);
|
main_loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
@ -116,8 +115,8 @@ static void test_treeview()
|
||||||
test_loop_equal(gtk_tree_view_column_get_fixed_width(col), 42, i);
|
test_loop_equal(gtk_tree_view_column_get_fixed_width(col), 42, i);
|
||||||
} test_loop_passed();
|
} test_loop_passed();
|
||||||
|
|
||||||
gui_view_set_model(GTK_TREE_MODEL_FILTER(filter));
|
test_equal((void *)gtk_tree_view_get_model(treeview),
|
||||||
test_equal((void *)gtk_tree_view_get_model(treeview), (void *)filter);
|
(void *)gui_view_get_filter());
|
||||||
|
|
||||||
gtk_tree_model_iter_nth_child(filter, &iter, NULL, 3);
|
gtk_tree_model_iter_nth_child(filter, &iter, NULL, 3);
|
||||||
path = gtk_tree_model_get_path(filter, &iter);
|
path = gtk_tree_model_get_path(filter, &iter);
|
||||||
|
@ -125,8 +124,7 @@ static void test_treeview()
|
||||||
test_equal(load_count, 1);
|
test_equal(load_count, 1);
|
||||||
gtk_tree_path_free(path);
|
gtk_tree_path_free(path);
|
||||||
|
|
||||||
gui_view_set_model(NULL);
|
gui_view_set_queue(NULL);
|
||||||
test_equal((void *)gtk_tree_view_get_model(treeview), NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLARE_UNIT_TESTS(
|
DECLARE_UNIT_TESTS(
|
||||||
|
|
Loading…
Reference in New Issue