From f58cc8da4622b86894ed5142c942492a5d159eb9 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 2 Aug 2016 14:28:05 -0400 Subject: [PATCH] gui/model: Add a function for getting the current queue Signed-off-by: Anna Schumaker --- gui/model.c | 5 +++++ gui/view.c | 26 ++++++-------------------- include/gui/model.h | 4 ++++ tests/gui/audio.c | 3 +++ tests/gui/model.c | 4 +++- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/gui/model.c b/gui/model.c index 214f5b21..ce3c30b4 100644 --- a/gui/model.c +++ b/gui/model.c @@ -321,6 +321,11 @@ void gui_queue_model_set_queue(GuiQueueModel *model, struct queue *queue) gui_queue_model_add(model, 0); } +struct queue *gui_queue_model_get_queue(void) +{ + return queue_model->gqm_queue; +} + struct track * gui_queue_model_path_get_track(GuiQueueModel *model, GtkTreePath *path) { diff --git a/gui/view.c b/gui/view.c index e3e77e46..b19d7e23 100644 --- a/gui/view.c +++ b/gui/view.c @@ -42,20 +42,6 @@ static GtkTreeModelFilter *view_filter = NULL; static unsigned int view_sort_count = 0; static bool view_no_scroll = false; -static inline GuiQueueModel *__view_filter_get_model() -{ - if (view_filter == NULL) - return NULL; - return GUI_QUEUE_MODEL(gtk_tree_model_filter_get_model(view_filter)); -} - -static inline struct queue *__view_filter_get_queue() -{ - if (view_filter == NULL) - return NULL; - return __view_filter_get_model()->gqm_queue; -} - static inline GtkTreePath *__view_filter_convert_path(GtkTreePath *orig) { return gtk_tree_model_filter_convert_path_to_child_path(view_filter, orig); @@ -63,7 +49,7 @@ static inline GtkTreePath *__view_filter_convert_path(GtkTreePath *orig) static struct track *__view_filter_get_track(GtkTreePath *orig) { - GuiQueueModel *model = __view_filter_get_model(); + GuiQueueModel *model = gui_queue_model_get(); GtkTreePath *real = __view_filter_convert_path(orig); struct track *track = gui_queue_model_path_get_track(model, real); @@ -109,7 +95,7 @@ static int __view_dec_sort(gpointer data) static void __view_set_column_sort_indicator(GtkTreeViewColumn *col, unsigned int index) { - struct queue *queue = __view_filter_get_queue(); + struct queue *queue = gui_queue_model_get_queue(); GSList *cur = queue ? queue->q_sort : NULL; unsigned int order = GTK_SORT_ASCENDING; bool show = false; @@ -149,7 +135,7 @@ void __view_row_activated(GtkTreeView *treeview, GtkTreePath *path, { view_no_scroll = true; audio_load(__view_filter_get_track(path)); - queue_selected(__view_filter_get_model()->gqm_queue, + queue_selected(gui_queue_model_get_queue(), gtk_tree_path_get_indices(path)[0]); view_no_scroll = false; } @@ -165,7 +151,7 @@ void __view_column_resized(GtkTreeViewColumn *col, GParamSpec *pspec, void __view_column_clicked(GtkTreeViewColumn *col, gpointer data) { - struct queue *queue = __view_filter_get_queue(); + struct queue *queue = gui_queue_model_get_queue(); unsigned int index = __view_get_column_index(col); bool reset = view_sort_count == 0; gchar *text; @@ -205,7 +191,7 @@ static void __view_add_to_playlist(GtkTreeModel *model, GtkTreePath *path, static void __view_delete_selection(GtkTreeSelection *selection) { - struct queue *queue = __view_filter_get_queue(); + struct queue *queue = gui_queue_model_get_queue(); GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL); GList *cur = g_list_reverse(rows); @@ -355,7 +341,7 @@ void gui_view_set_model(GtkTreeModelFilter *filter) void gui_view_scroll() { - struct queue *queue = __view_filter_get_queue(); + struct queue *queue = gui_queue_model_get_queue(); GtkTreePath *real, *path; if (!queue || (int)queue->q_cur.it_pos < 0 || view_no_scroll) diff --git a/include/gui/model.h b/include/gui/model.h index cbcf619c..fe6370ce 100644 --- a/include/gui/model.h +++ b/include/gui/model.h @@ -69,6 +69,10 @@ void gui_queue_model_update(GuiQueueModel *, unsigned int); /* Called to change the queue represented by the model. */ void gui_queue_model_set_queue(GuiQueueModel *, struct queue *); +/* Called to get the queue currently attached to the model. */ +struct queue *gui_queue_model_get_queue(void); + + /* Called to convert a GtkTreeIter into a struct track */ static inline struct track *gui_queue_model_iter_get_track(GuiQueueModel *model, diff --git a/tests/gui/audio.c b/tests/gui/audio.c index de22cff8..9f0e7bea 100644 --- a/tests/gui/audio.c +++ b/tests/gui/audio.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -61,6 +62,7 @@ static void test_audio() gtk_init(&argc, NULL); gui_builder_init("share/ocarina/ocarina6.glade"); + gui_queue_model_init(); test_equal(gtk_widget_is_visible(gui_builder_widget("o_play")), true); test_equal(gtk_widget_is_visible(gui_builder_widget("o_pause")), false); @@ -136,6 +138,7 @@ static void test_audio() audio_cur_track()->tr_length); gui_window_deinit(); + gui_queue_model_deinit(); gui_builder_deinit(); } diff --git a/tests/gui/model.c b/tests/gui/model.c index 7b6ced0e..418df6b7 100644 --- a/tests/gui/model.c +++ b/tests/gui/model.c @@ -70,10 +70,12 @@ static void test_init() gui_queue_model_init(); model = gui_queue_model_get(); + test_equal((void *)gui_queue_model_get_queue(), NULL); gui_queue_model_set_queue(model, playlist_get_queue(PL_SYSTEM, "Collection")); test_not_equal((void *)model, NULL); test_equal(GTK_IS_TREE_MODEL(model), true); - test_equal((void *)model->gqm_queue, (void *)playlist_get_queue(PL_SYSTEM, "Collection")); + test_equal((void *)gui_queue_model_get_queue(), + (void *)playlist_get_queue(PL_SYSTEM, "Collection")); treemodel = GTK_TREE_MODEL(model); test_equal(gtk_tree_model_get_flags(treemodel), GTK_TREE_MODEL_LIST_ONLY);