diff --git a/gui/playlist.c b/gui/playlist.c index 525f769c..1583ab83 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -16,6 +16,7 @@ enum playlist_sidebar_columns { static GtkTreeStore *p_store; static gchar *p_name = NULL; +static bool p_filter_enable = true; static bool p_init_done = false; static void __playlist_update_sizes(struct queue *); @@ -182,6 +183,22 @@ void __playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path, g_free(name); } +static gboolean __playlist_visible_func(GtkTreeModel *model, GtkTreeIter *iter, + gpointer data) +{ + gchar *name; + bool show; + + if (!p_filter_enable) + return true; + + name = __playlist_name(iter); + show = !playlist_get_queue(__playlist_type(iter), name) || + (playlist_size(__playlist_type(iter), name) > 0); + g_free(name); + return show; +} + static bool __playlist_queue_set_size(struct queue *queue, GtkTreeIter *iter) { struct gui_queue *gq = gui_queue(queue); @@ -200,6 +217,7 @@ static bool __playlist_queue_set_size(struct queue *queue, GtkTreeIter *iter) static void __playlist_update_sizes(struct queue *queue) { GtkTreeModel *model = GTK_TREE_MODEL(p_store); + GtkTreeModelFilter *filter; GtkTreeIter parent, iter; if (!gtk_tree_model_get_iter_first(model, &parent)) @@ -207,14 +225,18 @@ static void __playlist_update_sizes(struct queue *queue) do { if (__playlist_queue_set_size(queue, &parent)) - return; + goto out; if (gtk_tree_model_iter_children(model, &iter, &parent)) { do { if (__playlist_queue_set_size(queue, &iter)) - return; + goto out; } while (gtk_tree_model_iter_next(model, &iter)); } } while (gtk_tree_model_iter_next(model, &parent)); + +out: + filter = GTK_TREE_MODEL_FILTER(gui_builder_object("o_playlist_filter")); + gtk_tree_model_filter_refilter(filter); } static void *__playlist_init(struct queue *queue, void *data) @@ -226,8 +248,11 @@ static void *__playlist_init(struct queue *queue, void *data) flags = GQ_CAN_RANDOM; if (string_match(playlist->pl_name, "Queued Tracks")) flags = GQ_CAN_REPEAT; - if (p_init_done && playlist->pl_type == PL_ARTIST) + if (p_init_done && playlist->pl_type == PL_ARTIST) { + p_filter_enable = false; gui_playlist_add_artist(artist_find(playlist->pl_name)); + p_filter_enable = true; + } return gui_queue_alloc(playlist, queue, playlist->pl_name, flags); } @@ -263,9 +288,20 @@ static bool __playlist_erase(struct queue *queue, struct track *track) bool __gui_playlist_init_idle() { struct db_entry *artist, *next; + GtkTreeSelection *selection; + GtkTreeModel *filter; + GtkTreeIter iter; + filter = GTK_TREE_MODEL(gui_builder_object("o_playlist_filter")); + selection = gtk_tree_view_get_selection( + GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"))); + gtk_tree_model_get_iter_first(filter, &iter); + gtk_tree_selection_select_iter(selection, &iter); + + p_filter_enable = false; db_for_each(artist, next, artist_db_get()) gui_playlist_add_artist(ARTIST(artist)); + p_filter_enable = true; p_init_done = true; gui_queue_show(gui_queue(playlist_get_queue(PL_SYSTEM, "Collection"))); @@ -274,14 +310,16 @@ bool __gui_playlist_init_idle() void gui_playlist_init() { - GtkTreeSelection *selection; + GtkTreeModelFilter *filter; GtkTreeView *treeview; GtkTreeIter parent; - GtkTreePath *path; + filter = GTK_TREE_MODEL_FILTER(gui_builder_object("o_playlist_filter")); p_store = GTK_TREE_STORE(gui_builder_object("o_playlist_store")); treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view")); - selection = gtk_tree_view_get_selection(treeview); + + gtk_tree_model_filter_set_visible_func(filter, __playlist_visible_func, + NULL, NULL); gtk_tree_store_insert(p_store, &parent, NULL, -1); __playlist_set(&parent, "Queued Tracks", "audio-x-generic", PL_SYSTEM); @@ -291,10 +329,6 @@ void gui_playlist_init() __playlist_set(&parent, "Collection", "media-optical", PL_SYSTEM); __playlist_set_size(&parent, "Collection"); - path = gtk_tree_model_get_path(GTK_TREE_MODEL(p_store), &parent); - gtk_tree_selection_select_path(selection, path); - gtk_tree_path_free(path); - gtk_tree_store_insert(p_store, &parent, NULL, -1); __playlist_set(&parent, "History", "document-open-recent", PL_SYSTEM); __playlist_set_size(&parent, "History"); diff --git a/tests/gui/playlist.c b/tests/gui/playlist.c index ee09d709..73326968 100644 --- a/tests/gui/playlist.c +++ b/tests/gui/playlist.c @@ -14,6 +14,7 @@ struct core_init_data init_data; static void test_playlist_sidebar() { GtkTreeSelection *selection; + GtkTreeModelFilter *filter; GtkTreeView *treeview; GtkTreeModel *model; GtkTreePath *path; @@ -23,8 +24,16 @@ static void test_playlist_sidebar() treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view")); selection = gtk_tree_view_get_selection(treeview); + filter = GTK_TREE_MODEL_FILTER(gui_builder_object("o_playlist_filter")); model = GTK_TREE_MODEL(gui_builder_object("o_playlist_store")); + playlist_add(PL_SYSTEM, "Queued Tracks", track_get(0)); + playlist_add(PL_SYSTEM, "History", track_get(0)); + playlist_add(PL_SYSTEM, "Favorites", track_get(0)); + playlist_add(PL_SYSTEM, "Hidden", track_get(1)); + gtk_tree_model_filter_refilter(filter); + gtk_tree_view_expand_all(treeview); + g_assert_true(gtk_tree_model_get_iter_first(model, &iter)); path = gtk_tree_model_get_path(model, &iter); gtk_tree_selection_select_path(selection, path); @@ -34,16 +43,15 @@ static void test_playlist_sidebar() gtk_tree_path_next(path); gtk_tree_selection_select_path(selection, path); g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1); - gtk_tree_selection_unselect_all(selection); g_assert_cmpstr(gui_playlist_cur(), ==, "Collection"); gtk_tree_path_next(path); gtk_tree_selection_select_path(selection, path); g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1); - gtk_tree_selection_unselect_all(selection); g_assert_cmpstr(gui_playlist_cur(), ==, "History"); gtk_tree_path_next(path); + gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_path(selection, path); g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 0); @@ -61,16 +69,7 @@ static void test_playlist_sidebar() g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1); g_assert_cmpstr(gui_playlist_cur(), ==, "Hidden"); - gtk_tree_path_next(path); - gtk_tree_selection_select_path(selection, path); - g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1); - g_assert_cmpstr(gui_playlist_cur(), ==, "Most Played"); - - gtk_tree_path_next(path); - gtk_tree_selection_select_path(selection, path); - g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1); - g_assert_cmpstr(gui_playlist_cur(), ==, "Least Played"); - + /* Most played and least played are both filtered out */ gtk_tree_path_next(path); gtk_tree_selection_select_path(selection, path); g_assert_cmpuint(gtk_tree_selection_count_selected_rows(selection), ==, 1); @@ -89,6 +88,7 @@ int main(int argc, char **argv) gui_view_init(); core_init(&argc, NULL, &init_data); gui_playlist_init(); + playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); while (idle_run_task()) {} g_test_init(&argc, &argv, NULL);