gui/collection: Add library paths through an idle task

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-04-29 17:03:44 -04:00
parent f01cce3b47
commit cb6d451fb1
2 changed files with 22 additions and 7 deletions

View File

@ -2,6 +2,7 @@
* Copyright 2015 (c) Anna Schumaker.
*/
#include <core/collection.h>
#include <core/idle.h>
#include <core/playlist.h>
#include <core/tempq.h>
#include <gui/builder.h>
@ -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", "<big>Collection</big>");
/* 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();
}

View File

@ -4,6 +4,7 @@
#define TEST_NEED_AUDIO
#define TEST_NEED_PLAYLIST
#include <core/core.h>
#include <core/idle.h>
#include <gui/builder.h>
#include <gui/collection.h>
#include <gui/view.h>
@ -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);