From 3fc19275f3ee1d73e12ae1ffb32a0027b5c418ee Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 24 Aug 2016 09:06:04 -0400 Subject: [PATCH] gui/filter: Add a function for loading a track from a tree path Signed-off-by: Anna Schumaker --- gui/filter.c | 10 ++++++++++ include/gui/filter.h | 3 +++ tests/gui/filter.c | 15 +++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/gui/filter.c b/gui/filter.c index 64d115c7..05949725 100644 --- a/gui/filter.c +++ b/gui/filter.c @@ -1,6 +1,7 @@ /* * Copyright 2016 (c) Anna Schumaker. */ +#include #include #include #include @@ -124,6 +125,15 @@ struct track *gui_filter_path_get_track(GtkTreePath *path) return track; } +void gui_filter_path_load_track(GtkTreePath *path) +{ + struct track *track = gui_filter_path_get_track(path); + unsigned int index = gtk_tree_path_get_indices(path)[0]; + + audio_load(track); + queue_selected(&gui_model_get_playlist()->pl_queue, index); +} + unsigned int gui_filter_path_get_index(GtkTreePath *path) { GtkTreePath *real = __gui_filter_convert_path(path); diff --git a/include/gui/filter.h b/include/gui/filter.h index 05372feb..bcccbb3f 100644 --- a/include/gui/filter.h +++ b/include/gui/filter.h @@ -32,6 +32,9 @@ GtkTreeModelFilter *gui_filter_get(); /* Called to convert a filter model path into a track. */ struct track *gui_filter_path_get_track(GtkTreePath *); +/* Called to load the track at path. */ +void gui_filter_path_load_track(GtkTreePath *); + /* Called to convert a filter model path into a queue index. */ unsigned int gui_filter_path_get_index(GtkTreePath *); diff --git a/tests/gui/filter.c b/tests/gui/filter.c index 90b4a12b..acc0fc13 100644 --- a/tests/gui/filter.c +++ b/tests/gui/filter.c @@ -1,6 +1,7 @@ /* * Copyright 2016 (c) Anna Schumaker. */ +#include #include #include #include @@ -31,8 +32,19 @@ struct queue_ops test_ops = { .qop_updated = test_queue_update, }; +void test_on_load(struct track *track) {} +void test_on_state_change(GstState state) {} +void test_on_config_pause(int count) {} + +struct audio_ops test_audio_ops = { + .on_load = test_on_load, + .on_state_change = test_on_state_change, + .on_config_pause = test_on_config_pause, +}; + struct core_init_data init_data = { .playlist_ops = &test_ops, + .audio_ops = &test_audio_ops, }; void test_filter() @@ -70,6 +82,9 @@ void test_filter() track = gui_filter_path_get_track(path); g_assert_nonnull(track); g_assert_cmpuint(track->tr_track, ==, i + 1); + + gui_filter_path_load_track(path); + g_assert(audio_cur_track() == track); gtk_tree_path_free(path); } path = gui_filter_path_from_index(i);