diff --git a/gui/model.c b/gui/model.c index c68fb087..2ff4f20b 100644 --- a/gui/model.c +++ b/gui/model.c @@ -299,6 +299,19 @@ void gui_queue_model_update(GuiQueueModel *model, unsigned int row) gtk_tree_path_free(path); } +void gui_queue_model_set_queue(GuiQueueModel *model, struct queue *queue) +{ + struct queue *cur = model->gqm_queue; + + if (cur) + gui_queue_model_clear(model, queue_size(cur)); + + model->gqm_queue = queue; + + if (queue && queue_size(queue) > 0) + gui_queue_model_add(model, 0); +} + struct track * gui_queue_model_path_get_track(GuiQueueModel *model, GtkTreePath *path) { diff --git a/include/gui/model.h b/include/gui/model.h index ece04285..3bd0aa48 100644 --- a/include/gui/model.h +++ b/include/gui/model.h @@ -60,6 +60,9 @@ void gui_queue_model_clear(GuiQueueModel *, unsigned int); /* Called to update a row in the model */ void gui_queue_model_update(GuiQueueModel *, unsigned int); +/* Called to change the queue represented by the model. */ +void gui_queue_model_set_queue(GuiQueueModel *, struct queue *); + /* Called to convert a GtkTreeIter into a struct track */ static inline struct track *gui_queue_model_iter_get_track(GuiQueueModel *model, diff --git a/tests/gui/model.c b/tests/gui/model.c index e6e6490c..5ec4584d 100644 --- a/tests/gui/model.c +++ b/tests/gui/model.c @@ -185,6 +185,10 @@ static void test_model() test_equal(count_insert, 13); queue_resort(playlist_get_queue(PL_SYSTEM, "Collection")); test_equal(count_update, 13); + playlist_add(PL_SYSTEM, "Favorites", track_get(0)); + playlist_add(PL_SYSTEM, "Favorites", track_get(1)); + playlist_add(PL_SYSTEM, "Favorites", track_get(2)); + test_equal(playlist_size(PL_SYSTEM, "Favorites"), 3); /* ... and test again */ test_equal(gtk_tree_model_get_iter_first(model, &iter), true); @@ -249,6 +253,16 @@ static void test_model() test_equal(gtk_tree_model_iter_n_children(model, &iter), 0); test_equal(gtk_tree_model_iter_n_children(model, NULL), 13); + gui_queue_model_set_queue(GUI_QUEUE_MODEL(model), + playlist_get_queue(PL_SYSTEM, "Favorites")); + test_equal(count_delete, 13); + test_equal(count_insert, 14); + test_equal(gtk_tree_model_iter_n_children(model, NULL), 3); + gui_queue_model_set_queue(GUI_QUEUE_MODEL(model), + playlist_get_queue(PL_SYSTEM, "Collection")); + test_equal(count_delete, 16); + test_equal(count_insert, 15); + test_equal(gtk_tree_model_iter_nth_child(model, &iter, NULL, 3), true); track = gui_queue_model_iter_get_track(GUI_QUEUE_MODEL(model), &iter); test_equal(track->tr_track, 4); @@ -257,7 +271,7 @@ static void test_model() db_for_each(dbe, next, track_db_get()) playlist_remove(PL_SYSTEM, "Collection", TRACK(dbe)); - test_equal(count_delete, 13); + test_equal(count_delete, 29); core_deinit(); g_object_unref(model);