From cb6d451fb19a9ba8c778c45c225e7f594420fc65 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 29 Apr 2016 17:03:44 -0400 Subject: [PATCH] gui/collection: Add library paths through an idle task Signed-off-by: Anna Schumaker --- gui/collection.c | 27 ++++++++++++++++++++------- tests/gui/collection.c | 2 ++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/gui/collection.c b/gui/collection.c index 5b8b4deb..0bc5e9ba 100644 --- a/gui/collection.c +++ b/gui/collection.c @@ -2,6 +2,7 @@ * Copyright 2015 (c) Anna Schumaker. */ #include +#include #include #include #include @@ -190,9 +191,26 @@ static void __collection_removed(struct queue *queue, unsigned int pos) gui_sidebar_set_size(gui_queue(queue)); } -void gui_collection_init() +void __gui_collection_init_idle() { struct db_entry *library, *next; + GtkTreeIter parent, iter, last; + + gtk_tree_model_get_iter_first(c_model, &parent); + while (!gtk_tree_model_iter_has_child(c_model, &parent)) + gtk_tree_model_iter_next(c_model, &parent); + gtk_tree_model_iter_nth_child(c_model, &last, &parent, 0); + + /* Add library paths. */ + db_for_each(library, next, library_db_get()) { + gtk_tree_store_insert_before(GTK_TREE_STORE(c_model), &iter, &parent, &last); + __collection_set_library(&iter, LIBRARY(library)); + } +} + + +void gui_collection_init() +{ GtkTreeIter parent, iter; GtkTreeView *treeview; @@ -202,12 +220,6 @@ void gui_collection_init() gtk_tree_store_insert(GTK_TREE_STORE(c_model), &parent, NULL, -1); __collection_set_header(&parent, "system-file-manager", "Collection"); - /* Add library paths. */ - db_for_each(library, next, library_db_get()) { - gtk_tree_store_insert(GTK_TREE_STORE(c_model), &iter, &parent, -1); - __collection_set_library(&iter, LIBRARY(library)); - } - /* Add "Add new Library" entry. */ gtk_tree_store_insert(GTK_TREE_STORE(c_model), &iter, &parent, -1); __collection_set_header(&iter, "folder-new", @@ -219,6 +231,7 @@ void gui_collection_init() gtk_tree_view_get_selection(treeview), gui_sidebar_on_select, NULL, NULL); + idle_schedule(__gui_collection_init_idle, NULL); gui_sidebar_set_size(gui_queue(collection_get_queue())); gui_idle_enable(); } diff --git a/tests/gui/collection.c b/tests/gui/collection.c index b2615cdc..b0c72045 100644 --- a/tests/gui/collection.c +++ b/tests/gui/collection.c @@ -4,6 +4,7 @@ #define TEST_NEED_AUDIO #define TEST_NEED_PLAYLIST #include +#include #include #include #include @@ -80,6 +81,7 @@ static void test_collection_sidebar() gtk_tree_store_clear(GTK_TREE_STORE(model)); gui_collection_init(); + while (idle_run_task()) {} gtk_tree_model_get_iter_first(model, &iter); test_equal(gtk_tree_model_iter_n_children(model, &iter), 2); gtk_tree_model_iter_nth_child(model, &child, &iter, 0);