diff --git a/gui/ocarina.c b/gui/ocarina.c index c887a4d2..7bed720d 100644 --- a/gui/ocarina.c +++ b/gui/ocarina.c @@ -54,9 +54,10 @@ static void __ocarina_startup(GApplication *application, gpointer data) gui_builder_init(ui); gui_settings_init(); - gui_queue_model_init(); core_init(&startup_argc, &startup_argv, &init_data); + gui_queue_model_init(); gui_view_init(); + gui_queue_init(); gui_window_init(icon); gui_sidebar_init(); gui_collection_init(); diff --git a/gui/queue.c b/gui/queue.c index 08af985e..384ebe0b 100644 --- a/gui/queue.c +++ b/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); } +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, 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_search = NULL; gq->gq_model = g_object_ref(gui_queue_model_get()); - gui_queue_model_set_queue(queue); - gq->gq_filter = gtk_tree_model_filter_new( - GTK_TREE_MODEL(gq->gq_model), NULL); + gq->gq_filter = GTK_TREE_MODEL(gui_view_get_filter()); gq->gq_playlist = playlist; 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; } @@ -161,7 +162,7 @@ void gui_queue_free(struct queue *queue) queue->q_private = NULL; if (gq_queue == gq) - gui_view_set_model(NULL); + gui_view_set_queue(NULL); if (gq->gq_search) g_strfreev(gq->gq_search); 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")); GtkSwitch *enabled = GTK_SWITCH(gui_builder_widget("o_enable")); 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;; 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_repeat = queue_has_flag(queue->gq_queue, Q_REPEAT); is_enabled = queue_has_flag(queue->gq_queue, Q_ENABLED); - gui_queue_model_set_queue(queue->gq_queue); - gui_view_set_model(GTK_TREE_MODEL_FILTER(queue->gq_filter)); + gui_view_set_queue(queue->gq_queue); } 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(repeat), has_repeat); diff --git a/gui/view.c b/gui/view.c index 88067768..265e5452 100644 --- a/gui/view.c +++ b/gui/view.c @@ -317,6 +317,8 @@ void gui_view_init() int i, pos; 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++) { col = gtk_tree_view_get_column(view_treeview, i); @@ -324,12 +326,18 @@ void gui_view_init() if (col && pos > 0) 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; - gtk_tree_view_set_model(view_treeview, GTK_TREE_MODEL(filter)); + return view_filter; +} + +void gui_view_set_queue(struct queue *queue) +{ + gui_queue_model_set_queue(queue); view_sort_count = 0; __view_display_sorting(""); diff --git a/include/gui/queue.h b/include/gui/queue.h index 5132a5fa..f649a58b 100644 --- a/include/gui/queue.h +++ b/include/gui/queue.h @@ -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. */ struct gui_queue *gui_queue_alloc(struct playlist *, struct queue *, const gchar *, unsigned int); diff --git a/include/gui/view.h b/include/gui/view.h index 6d8255b6..1569c3df 100644 --- a/include/gui/view.h +++ b/include/gui/view.h @@ -4,13 +4,18 @@ #ifndef OCARINA_GUI_VIEW_H #define OCARINA_GUI_VIEW_H +#include + /* Called to initialize structures needed by the treeview. */ void gui_view_init(); /* Called to scroll the GUI treeview to the queue's current position. */ void gui_view_scroll(); +/* Called to get the GtkTreeModelFilter */ +GtkTreeModelFilter *gui_view_get_filter(void); + /* 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 */ diff --git a/tests/gui/playlist.c b/tests/gui/playlist.c index 0784d1ec..8522d960 100644 --- a/tests/gui/playlist.c +++ b/tests/gui/playlist.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ static void test_playlist_sidebar() gtk_init(&argc, NULL); gui_builder_init("share/ocarina/ocarina6.glade"); + gui_queue_model_init(); core_init(&argc, NULL, &init_data); gui_playlist_init(); while (idle_run_task()) {} diff --git a/tests/gui/queue.c b/tests/gui/queue.c index f64f804c..e0b8575f 100644 --- a/tests/gui/queue.c +++ b/tests/gui/queue.c @@ -52,6 +52,7 @@ static void test_queue() gui_builder_init("share/ocarina/ocarina6.glade"); gui_queue_model_init(); gui_view_init(); + gui_queue_init(); while (idle_run_task()) {}; search = GTK_ENTRY(gui_builder_widget("o_search")); diff --git a/tests/gui/view.c b/tests/gui/view.c index 1d142528..063f399c 100644 --- a/tests/gui/view.c +++ b/tests/gui/view.c @@ -57,9 +57,9 @@ static int test_on_idle(gpointer data) static void test_treeview() { - GtkTreeModel *model, *filter; GtkTreeViewColumn *col; GtkTreeView *treeview; + GtkTreeModel *filter; GtkTreePath *path; GtkTreeIter iter; unsigned int i; @@ -71,13 +71,12 @@ static void test_treeview() gui_settings_init(); gui_queue_model_init(); gui_view_init(); - while (idle_run_task()) {} + while (idle_run_task() == true) {} playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); while (idle_run_task() == true) {} - model = GTK_TREE_MODEL(gui_queue_model_get()); 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")); 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_passed(); - gui_view_set_model(GTK_TREE_MODEL_FILTER(filter)); - test_equal((void *)gtk_tree_view_get_model(treeview), (void *)filter); + test_equal((void *)gtk_tree_view_get_model(treeview), + (void *)gui_view_get_filter()); gtk_tree_model_iter_nth_child(filter, &iter, NULL, 3); path = gtk_tree_model_get_path(filter, &iter); @@ -125,8 +124,7 @@ static void test_treeview() test_equal(load_count, 1); gtk_tree_path_free(path); - gui_view_set_model(NULL); - test_equal((void *)gtk_tree_view_get_model(treeview), NULL); + gui_view_set_queue(NULL); } DECLARE_UNIT_TESTS(