From ea149d57df6ac6d58e257dd6a87a33824a3e3502 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 18 Jan 2016 10:14:29 -0500 Subject: [PATCH] gui/model: Convert iters and paths into tracks Signed-off-by: Anna Schumaker --- gui/model.c | 9 +++++++++ include/gui/model.h | 13 +++++++++++++ tests/gui/model.c | 12 ++++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/gui/model.c b/gui/model.c index b8bd8f4f..fde3fd23 100644 --- a/gui/model.c +++ b/gui/model.c @@ -286,6 +286,15 @@ void gui_queue_model_update(GuiQueueModel *model, unsigned int row) gtk_tree_path_free(path); } +struct track * gui_queue_model_path_get_track(GuiQueueModel *model, + GtkTreePath *path) +{ + GtkTreeIter iter; + + _queue_model_get_iter(GTK_TREE_MODEL(model), &iter, path); + return gui_queue_model_iter_get_track(model, &iter); +} + static const GTypeInfo queue_type_info = { .class_size = sizeof(GuiQueueModelClass), diff --git a/include/gui/model.h b/include/gui/model.h index a297cfc9..b5343294 100644 --- a/include/gui/model.h +++ b/include/gui/model.h @@ -59,4 +59,17 @@ 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 convert a GtkTreeIter into a struct track */ +static inline +struct track *gui_queue_model_iter_get_track(GuiQueueModel *model, + GtkTreeIter *iter) +{ + g_return_val_if_fail(iter != NULL, NULL); + g_return_val_if_fail(iter->user_data2 != NULL, NULL); + return (struct track *)iter->user_data2; +} + +/* Called to convert a GtkTreePath into a struct track */ +struct track *gui_queue_model_path_get_track(GuiQueueModel *, GtkTreePath *); + #endif /* OCARINA_GUI_MODEL_H */ diff --git a/tests/gui/model.c b/tests/gui/model.c index 8c00a896..2b879119 100644 --- a/tests/gui/model.c +++ b/tests/gui/model.c @@ -101,6 +101,8 @@ static void test_empty() test_equal(gtk_tree_model_get_iter_first(model, &iter), false); test_equal((void *)gtk_tree_model_get_path(model, &iter), NULL); + test_equal((void *)gui_queue_model_iter_get_track(GUI_QUEUE_MODEL(model), + &iter), NULL); /* These will all trigger assertion failures ... sorry */ gtk_tree_model_get_value(model, &iter, Q_MODEL_TRACK_NR, &value); @@ -163,12 +165,14 @@ static void test_model() /* ... and test again */ test_equal(gtk_tree_model_get_iter_first(model, &iter), true); - track = iter.user_data2; + track = gui_queue_model_iter_get_track(GUI_QUEUE_MODEL(model), &iter); test_equal(track->tr_track, 1); path = gtk_tree_model_get_path(model, &iter); test_not_equal((void *)path, NULL); test_equal(gtk_tree_path_get_indices(path)[0], 0); + test_equal((void *)gui_queue_model_path_get_track(GUI_QUEUE_MODEL(model), + path), (void *)track); gtk_tree_path_free(path); gtk_tree_model_get_value(model, &iter, Q_MODEL_TRACK_NR, &value); @@ -204,11 +208,11 @@ static void test_model() g_value_unset(&value); test_equal(gtk_tree_model_iter_next(model, &iter), true); - track = iter.user_data2; + track = gui_queue_model_iter_get_track(GUI_QUEUE_MODEL(model), &iter); test_equal(track->tr_track, 2); test_equal(gtk_tree_model_iter_children(model, &iter, NULL), true); - track = iter.user_data2; + track = gui_queue_model_iter_get_track(GUI_QUEUE_MODEL(model), &iter); test_equal(track->tr_track, 1); test_equal(gtk_tree_model_iter_has_child(model, &iter), false); @@ -216,7 +220,7 @@ static void test_model() test_equal(gtk_tree_model_iter_n_children(model, NULL), 13); test_equal(gtk_tree_model_iter_nth_child(model, &iter, NULL, 3), true); - track = iter.user_data2; + track = gui_queue_model_iter_get_track(GUI_QUEUE_MODEL(model), &iter); test_equal(track->tr_track, 4); test_equal(gtk_tree_model_iter_parent(model, &iter, &iter), false);