diff --git a/gui/filter.c b/gui/filter.c index fdd801da..4fe5479d 100644 --- a/gui/filter.c +++ b/gui/filter.c @@ -37,3 +37,11 @@ struct track *gui_filter_path_get_track(GtkTreePath *path) gtk_tree_path_free(real); return track; } + +unsigned int gui_filter_path_get_index(GtkTreePath *path) +{ + GtkTreePath *real = __gui_filter_convert_path(path); + unsigned int ret = gtk_tree_path_get_indices(real)[0]; + gtk_tree_path_free(real); + return ret; +} diff --git a/gui/view.c b/gui/view.c index e4dc01cc..4efc2aec 100644 --- a/gui/view.c +++ b/gui/view.c @@ -40,21 +40,6 @@ static GtkTreeView *view_treeview = NULL; static unsigned int view_sort_count = 0; static bool view_no_scroll = false; -static inline GtkTreePath *__view_filter_convert_path(GtkTreePath *orig) -{ - return gtk_tree_model_filter_convert_path_to_child_path( - gui_filter_get(), orig); -} - -static unsigned int __view_filter_get_index(GtkTreePath *orig) -{ - GtkTreePath *real = __view_filter_convert_path(orig); - unsigned int ret = gtk_tree_path_get_indices(real)[0]; - - gtk_tree_path_free(real); - return ret; -} - static unsigned int __view_get_column_index(GtkTreeViewColumn *col) { unsigned int i; @@ -189,7 +174,7 @@ static void __view_delete_selection(GtkTreeSelection *selection) GList *cur = g_list_reverse(rows); while (cur) { - queue_erase(queue, __view_filter_get_index(cur->data)); + queue_erase(queue, gui_filter_path_get_index(cur->data)); cur = g_list_next(cur); } diff --git a/include/gui/filter.h b/include/gui/filter.h index 40919194..976429a5 100644 --- a/include/gui/filter.h +++ b/include/gui/filter.h @@ -17,4 +17,7 @@ GtkTreeModelFilter *gui_filter_get(); /* Called to convert a filter model path into a track. */ struct track *gui_filter_path_get_track(GtkTreePath *); +/* Called to convert a filter model path into a queue index. */ +unsigned int gui_filter_path_get_index(GtkTreePath *); + #endif /* OCARINA_GUI_FILTER_H */ diff --git a/tests/gui/filter.c b/tests/gui/filter.c index dc453982..cd0d8512 100644 --- a/tests/gui/filter.c +++ b/tests/gui/filter.c @@ -62,10 +62,11 @@ void test_filter() g_assert_true(gtk_tree_model_get_iter_first(model, &iter)); path = gtk_tree_model_get_path(model, &iter); - for (i = 1; i <= 13; i++) { + for (i = 0; i < 13; i++) { track = gui_filter_path_get_track(path); g_assert_nonnull(track); - g_assert_cmpuint(track->tr_track, ==, i); + g_assert_cmpuint(track->tr_track, ==, i + 1); + g_assert_cmpuint(gui_filter_path_get_index(path), ==, i); gtk_tree_path_next(path); } g_assert_null(gui_filter_path_get_track(path));