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 <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-08-21 10:03:50 -04:00
parent 619ea0b559
commit 27a1e2e12a
4 changed files with 16 additions and 8 deletions

View File

@ -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);
}

View File

@ -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 */

View File

@ -1086,7 +1086,7 @@ audio-volume-medium</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="o_runtime">
<object class="GtkLabel" id="runtime">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>

View File

@ -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);