From dbc1df154a1e2fdcbc748eb6971004151740b521 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 24 Aug 2016 09:06:43 -0400 Subject: [PATCH] gui/treeview: Add a row-activated signal handler Signed-off-by: Anna Schumaker --- gui/audio.c | 3 ++- gui/treeview.c | 15 +++++++++++++-- gui/view.c | 17 ----------------- include/gui/view.h | 3 --- share/ocarina/ocarina.ui | 2 +- tests/gui/treeview.c | 19 ++++++++++++++++++- 6 files changed, 34 insertions(+), 25 deletions(-) diff --git a/gui/audio.c b/gui/audio.c index 34cb3360..3030888e 100644 --- a/gui/audio.c +++ b/gui/audio.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -38,7 +39,7 @@ static void __audio_load(struct track *track) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_favorite")), playlist_has(PL_SYSTEM, "Favorites", track)); - gui_view_scroll(); + gui_treeview_scroll(); gui_artwork_set_cover(); gui_idle_enable(); } diff --git a/gui/treeview.c b/gui/treeview.c index dcabf222..9997862b 100644 --- a/gui/treeview.c +++ b/gui/treeview.c @@ -20,6 +20,7 @@ static const enum compare_t GUI_COL_MAP[GUI_MODEL_N_COLUMNS] = { static unsigned int sort_count = 0; static gchar *sort_text = NULL; +static bool can_scroll = true; static int __gui_treeview_colum_match_sort(enum compare_t compare) { @@ -138,6 +139,14 @@ static void __gui_treeview_column_clicked(GtkTreeViewColumn *col, g_timeout_add_seconds(3, __gui_treeview_dec_sort, NULL); } +void __gui_treeview_row_activated(GtkTreeView *treeview, GtkTreePath *path, + GtkTreeViewColumn *col, gpointer data) +{ + can_scroll = false; + gui_filter_path_load_track(path); + can_scroll = true; +} + void gui_treeview_init() { GtkTreeViewColumn *col; @@ -175,11 +184,13 @@ void gui_treeview_scroll() { struct playlist *playlist = gui_model_get_playlist(); GtkTreePath *path; + int pos; - if (!playlist || (int)playlist->pl_queue.q_cur.it_pos < 0) + pos = playlist ? playlist->pl_queue.q_cur.it_pos : -1; + if (!can_scroll || pos < 0) return; - path = gui_filter_path_from_index(playlist->pl_queue.q_cur.it_pos); + path = gui_filter_path_from_index(pos); if (!path) return; diff --git a/gui/view.c b/gui/view.c index 4f331791..6ad37fa9 100644 --- a/gui/view.c +++ b/gui/view.c @@ -25,7 +25,6 @@ static const gchar *QUEUE_SETTINGS[GUI_MODEL_N_COLUMNS] = { }; static GtkTreeView *view_treeview = NULL; -static bool view_no_scroll = false; static unsigned int __view_get_column_index(GtkTreeViewColumn *col) { @@ -42,16 +41,6 @@ static unsigned int __view_get_column_index(GtkTreeViewColumn *col) return GUI_MODEL_N_COLUMNS; } -void __view_row_activated(GtkTreeView *treeview, GtkTreePath *path, - GtkTreeViewColumn *col, gpointer data) -{ - view_no_scroll = true; - audio_load(gui_filter_path_get_track(path)); - queue_selected(&gui_model_get_playlist()->pl_queue, - gtk_tree_path_get_indices(path)[0]); - view_no_scroll = false; -} - void __view_column_resized(GtkTreeViewColumn *col, GParamSpec *pspec, gpointer data) { @@ -302,9 +291,3 @@ void gui_view_set_playlist(struct playlist *playlist) { gui_treeview_set_playlist(playlist); } - -void gui_view_scroll() -{ - if (!view_no_scroll) - gui_treeview_scroll(); -} diff --git a/include/gui/view.h b/include/gui/view.h index 26ccfddb..e630364a 100644 --- a/include/gui/view.h +++ b/include/gui/view.h @@ -9,9 +9,6 @@ /* 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 set the currently displayed model. */ void gui_view_set_playlist(struct playlist *); diff --git a/share/ocarina/ocarina.ui b/share/ocarina/ocarina.ui index 06cbd28e..8cf6535f 100644 --- a/share/ocarina/ocarina.ui +++ b/share/ocarina/ocarina.ui @@ -885,7 +885,7 @@ audio-volume-medium 9 - + multiple diff --git a/tests/gui/treeview.c b/tests/gui/treeview.c index 1f6b668f..c902eb21 100644 --- a/tests/gui/treeview.c +++ b/tests/gui/treeview.c @@ -1,6 +1,7 @@ /* * Copyright 2016 (c) Anna Schumaker. */ +#include #include #include #include @@ -8,7 +9,19 @@ #include #include -struct core_init_data init_data = {}; +static void test_load(struct track *track) { } +static void test_state_change(GstState state) {} +static void test_config_pause(int count) {} + +struct audio_ops test_audio_ops = { + .on_load = test_load, + .on_state_change = test_state_change, + .on_config_pause = test_config_pause, +}; + +struct core_init_data init_data = { + .audio_ops = &test_audio_ops, +}; void test_treeview_init() { @@ -39,6 +52,10 @@ void test_treeview_init() gtk_tree_view_get_cursor(gui_treeview(), &path, NULL); g_assert_nonnull(path); g_assert_cmpuint(gui_filter_path_get_track(path)->tr_track, ==, 5); + + gtk_tree_view_row_activated(gui_treeview(), path, NULL); + g_assert_cmpuint(audio_cur_track()->tr_track, ==, 5); + gtk_tree_path_free(path); } void test_treeview_sort()