From 27a1e2e12aff6ecdd3d7b240ad22bedd231fb2c2 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sun, 21 Aug 2016 10:03:50 -0400 Subject: [PATCH] gui/model: Add a function for accessing the runtime label And rename the widget from "o_runtime" to just "runtime" Signed-off-by: Anna Schumaker --- gui/model.c | 2 +- include/gui/model.h | 6 ++++++ share/ocarina/ocarina.ui | 2 +- tests/gui/model.c | 14 ++++++++------ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/gui/model.c b/gui/model.c index f11940c9..87a9959b 100644 --- a/gui/model.c +++ b/gui/model.c @@ -253,7 +253,7 @@ static void __gui_model_set_runtime(void) if (cur_playlist) len = string_sec2str_long(cur_playlist->pl_queue.q_length); - gtk_label_set_text(GTK_LABEL(gui_builder_widget("o_runtime")), len); + gtk_label_set_text(gui_model_runtime(), len); g_free(len); } diff --git a/include/gui/model.h b/include/gui/model.h index 817ed6b1..51c1b26c 100644 --- a/include/gui/model.h +++ b/include/gui/model.h @@ -80,4 +80,10 @@ static inline struct track *gui_model_iter_get_track(GtkTreeIter *iter) /* Called to convert a GtkTreePath into a struct track */ struct track *gui_model_path_get_track(GtkTreePath *); +/* Called to get the runtime label. */ +static inline GtkLabel *gui_model_runtime() +{ + return GTK_LABEL(gui_builder_widget("runtime")); +} + #endif /* OCARINA_GUI_MODEL_H */ diff --git a/share/ocarina/ocarina.ui b/share/ocarina/ocarina.ui index 68f8b555..c6e6f276 100644 --- a/share/ocarina/ocarina.ui +++ b/share/ocarina/ocarina.ui @@ -1086,7 +1086,7 @@ audio-volume-medium - + True False end diff --git a/tests/gui/model.c b/tests/gui/model.c index e2c002c1..12b96d9c 100644 --- a/tests/gui/model.c +++ b/tests/gui/model.c @@ -164,7 +164,6 @@ static void test_empty() static void test_model() { - GtkLabel *label = GTK_LABEL(gui_builder_widget("o_runtime")); GtkTreeModel *model = GTK_TREE_MODEL(gui_model_get()); struct db_entry *dbe, *next; struct track *track; @@ -173,7 +172,7 @@ static void test_model() GValue value; gui_model_set_playlist(playlist_get(PL_SYSTEM, "Collection")); - g_assert_cmpstr(gtk_label_get_text(label), ==, ""); + g_assert_cmpstr(gtk_label_get_text(gui_model_runtime()), ==, ""); memset(&value, 0, sizeof(GValue)); g_signal_connect(model, "row-inserted", (GCallback)on_row_inserted, NULL); @@ -193,7 +192,8 @@ static void test_model() playlist_add(PL_SYSTEM, "Favorites", track_get(1)); playlist_add(PL_SYSTEM, "Favorites", track_get(2)); g_assert_cmpuint(playlist_size(PL_SYSTEM, "Favorites"), ==, 3); - g_assert_cmpstr(gtk_label_get_text(label), ==, "42 minutes, 45 seconds"); + g_assert_cmpstr(gtk_label_get_text(gui_model_runtime()), ==, + "42 minutes, 45 seconds"); /* ... and test again */ g_assert_true(gtk_tree_model_get_iter_first(model, &iter)); @@ -261,18 +261,20 @@ static void test_model() g_assert_cmpuint(count_delete, ==, 13); g_assert_cmpuint(count_insert, ==, 14); g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 3); - g_assert_cmpstr(gtk_label_get_text(label), ==, "10 minutes, 46 seconds"); + g_assert_cmpstr(gtk_label_get_text(gui_model_runtime()), ==, + "10 minutes, 46 seconds"); gui_model_set_playlist(NULL); g_assert_cmpuint(count_delete, ==, 16); g_assert_cmpuint(count_insert, ==, 14); g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 0); - g_assert_cmpstr(gtk_label_get_text(label), ==, ""); + g_assert_cmpstr(gtk_label_get_text(gui_model_runtime()), ==, ""); gui_model_set_playlist(playlist_get(PL_SYSTEM, "Collection")); g_assert_cmpuint(count_delete, ==, 16); g_assert_cmpuint(count_insert, ==, 15); - g_assert_cmpstr(gtk_label_get_text(label), ==, "42 minutes, 45 seconds"); + g_assert_cmpstr(gtk_label_get_text(gui_model_runtime()), ==, + "42 minutes, 45 seconds"); g_assert_true(gtk_tree_model_iter_nth_child(model, &iter, NULL, 3)); track = gui_model_iter_get_track(&iter);