diff --git a/gui/model.c b/gui/model.c index e2e2af5c..f8a26601 100644 --- a/gui/model.c +++ b/gui/model.c @@ -32,7 +32,7 @@ static gboolean __queue_model_iter_nth(GuiQueueModel *model, GtkTreeIter *iter, gint n) { - if (n >= queue_size(model->gqm_queue)) + if (!model->gqm_queue || n >= queue_size(model->gqm_queue)) return FALSE; queue_iter_set(model->gqm_queue, &model->gqm_iter, n); @@ -175,7 +175,7 @@ static gboolean _queue_model_iter_has_child(GtkTreeModel *model, static gint _queue_model_iter_n_children(GtkTreeModel *model, GtkTreeIter *iter) { - if (iter != NULL) + if (iter != NULL || !queue_model->gqm_queue) return 0; return queue_size(GUI_QUEUE_MODEL(model)->gqm_queue); } @@ -236,7 +236,11 @@ static void _queue_tree_model_init(GtkTreeModelIface *iface) static void __gui_queue_model_set_runtime(void) { - gchar *len = string_sec2str_long(queue_model->gqm_queue->q_length); + gchar *len = NULL; + + if (queue_model->gqm_queue) + len = string_sec2str_long(queue_model->gqm_queue->q_length); + gtk_label_set_text(GTK_LABEL(gui_builder_widget("o_runtime")), len); g_free(len); } diff --git a/tests/gui/model.c b/tests/gui/model.c index abc5a97c..df232c9e 100644 --- a/tests/gui/model.c +++ b/tests/gui/model.c @@ -261,6 +261,12 @@ static void test_model() test_equal(gtk_tree_model_iter_n_children(model, NULL), 3); test_equal(gtk_label_get_text(label), "10 minutes, 46 seconds"); + gui_queue_model_set_queue(NULL); + test_equal(count_delete, 16); + test_equal(count_insert, 14); + test_equal(gtk_tree_model_iter_n_children(model, NULL), 0); + test_equal(gtk_label_get_text(label), ""); + gui_queue_model_set_queue(playlist_get_queue(PL_SYSTEM, "Collection")); test_equal(gtk_label_get_text(label), "42 minutes, 45 seconds"); test_equal(count_delete, 16);