diff --git a/core/tempq.c b/core/tempq.c index e444761f..b4f7256d 100644 --- a/core/tempq.c +++ b/core/tempq.c @@ -4,9 +4,11 @@ #include #include #include +#include #include #include +static struct file tempq_file = FILE_INIT("deck", 1); static struct queue_ops *tempq_ops = NULL; static GSList *tempq_list; static struct file tempq_file; @@ -55,14 +57,10 @@ static void __tempq_write_queue(struct queue *queue) file_writef(&tempq_file, "\n"); } - -void tempq_init(struct queue_ops *ops) +static void __tempq_init_idle(void *data) { unsigned int num, i; - tempq_ops = ops; - - file_init(&tempq_file, "deck", 1); if (!file_open(&tempq_file, OPEN_READ)) return; if (file_version(&tempq_file) < 1) @@ -75,6 +73,13 @@ out: file_close(&tempq_file); } + +void tempq_init(struct queue_ops *ops) +{ + tempq_ops = ops; + idle_schedule(__tempq_init_idle, NULL); +} + void tempq_deinit() { while (tempq_list) diff --git a/gui/sidebar.c b/gui/sidebar.c index 9cc8cc00..ba4927b3 100644 --- a/gui/sidebar.c +++ b/gui/sidebar.c @@ -118,7 +118,7 @@ void gui_sidebar_init() { GtkPaned *pane = GTK_PANED(gui_builder_widget("o_sidebar")); GtkTreeIter iter; - int pos, i; + int pos; /* Set up entries in the liststore. */ sb_store = GTK_LIST_STORE(gui_builder_object("o_sidebar_store")); @@ -129,9 +129,6 @@ void gui_sidebar_init() gtk_tree_model_iter_next(GTK_TREE_MODEL(sb_store), &iter); __sidebar_set_queue(&iter, gui_queue(history_get_queue())); - for (i = 0; i < tempq_count(); i++) - gui_sidebar_add(gui_queue(tempq_get(i))); - /* Set sidebar width. */ pos = gui_settings_get(SIDEBAR_SETTING); if (pos > 0) diff --git a/tests/core/tempq.c b/tests/core/tempq.c index 447bf1c2..6026fba1 100644 --- a/tests/core/tempq.c +++ b/tests/core/tempq.c @@ -20,7 +20,10 @@ static void test_init() history_init(NULL); test_equal((void *)tempq_next(), NULL); + tempq_init(NULL); + while (idle_run_task()) {}; + test_equal((void *)tempq_next(), NULL); tempq_move(NULL, 1); test_equal((void *)tempq_get(0), NULL); @@ -55,6 +58,9 @@ static void test_alloc() tempq_deinit(); test_equal(tempq_count(), 0); tempq_init(NULL); + test_equal(tempq_count(), 0); + while (idle_run_task()) {}; + test_equal(tempq_count(), 2); q0 = tempq_get(0); q1 = tempq_get(1); @@ -82,6 +88,7 @@ static void test_move() tempq_deinit(); test_equal(tempq_count(), 0); tempq_init(NULL); + while (idle_run_task()) {}; q0 = tempq_get(1); q1 = tempq_get(0); @@ -126,6 +133,7 @@ static void test_next() tempq_save(NULL, Q_ENABLED); tempq_deinit(); tempq_init(NULL); + while (idle_run_task()) {}; test_equal(tempq_count(), 2); q0 = tempq_get(0); q1 = tempq_get(1); @@ -140,6 +148,7 @@ static void test_next() tempq_deinit(); tempq_init(NULL); + while (idle_run_task()) {}; test_equal(tempq_count(), 1); q1 = tempq_get(0);