gui/audio: Add position and duration label accessor functions
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
869e83b7bd
commit
943ab02aa5
|
@ -14,7 +14,7 @@ static cairo_surface_t *__artwork_scale_pixbuf(GdkPixbuf *pix)
|
|||
{
|
||||
int old_h = gdk_pixbuf_get_height(pix);
|
||||
int old_w = gdk_pixbuf_get_width(pix);
|
||||
int new_h = gui_builder_widget_height("o_position") +
|
||||
int new_h = gui_builder_widget_height("position") +
|
||||
gui_builder_widget_height("o_tags");
|
||||
int new_w = (old_w * new_h) / old_h;
|
||||
int scale = gtk_widget_get_scale_factor(gui_builder_widget("o_cover"));
|
||||
|
|
18
gui/audio.c
18
gui/audio.c
|
@ -23,28 +23,23 @@ static inline void __gui_audio_set_label_markup(GtkLabel *label,
|
|||
g_free(markup);
|
||||
}
|
||||
|
||||
static inline void __audio_set_time_label(const gchar *label, unsigned int time)
|
||||
{
|
||||
gchar *str = string_sec2str(time);
|
||||
__gui_audio_set_label_markup(GTK_LABEL(gui_builder_widget(label)),
|
||||
"large",str);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
static void __audio_load(struct track *track)
|
||||
{
|
||||
gchar *duration = string_sec2str(track->tr_length);
|
||||
|
||||
__gui_audio_set_label_markup(gui_title_tag(), "xx-large",
|
||||
track->tr_title);
|
||||
__gui_audio_set_label_markup(gui_album_tag(), "x-large",
|
||||
track->tr_album->al_name);
|
||||
__gui_audio_set_label_markup(gui_artist_tag(), "x-large",
|
||||
track->tr_album->al_artist->ar_name);
|
||||
__audio_set_time_label("o_duration", track->tr_length);
|
||||
__gui_audio_set_label_markup(gui_duration(), "large", duration);
|
||||
|
||||
gui_pl_system_track_loaded(track);
|
||||
gui_treeview_scroll();
|
||||
gui_artwork_set_cover();
|
||||
gui_idle_enable();
|
||||
g_free(duration);
|
||||
}
|
||||
|
||||
static void __audio_change_state(GstState state)
|
||||
|
@ -82,11 +77,14 @@ void __audio_volume_changed(GtkScaleButton *button, gdouble value, gpointer data
|
|||
|
||||
static int __audio_timeout(gpointer data)
|
||||
{
|
||||
gchar *position = string_sec2str(audio_position() / GST_SECOND);
|
||||
GtkAdjustment *progress = data;
|
||||
|
||||
gtk_adjustment_set_upper(progress, audio_duration() / GST_SECOND);
|
||||
gtk_adjustment_set_value(progress, audio_position() / GST_SECOND);
|
||||
__audio_set_time_label("o_position", audio_position() / GST_SECOND);
|
||||
__gui_audio_set_label_markup(gui_position(), "large", position);
|
||||
|
||||
g_free(position);
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,18 @@ static inline GtkLabel *gui_title_tag(void)
|
|||
return GTK_LABEL(gui_builder_widget("title_tag"));
|
||||
}
|
||||
|
||||
/* Called to get the label displaying the track's position. */
|
||||
static inline GtkLabel *gui_position(void)
|
||||
{
|
||||
return GTK_LABEL(gui_builder_widget("position"));
|
||||
}
|
||||
|
||||
/* Called to get the label displaying the track's duration. */
|
||||
static inline GtkLabel *gui_duration(void)
|
||||
{
|
||||
return GTK_LABEL(gui_builder_widget("duration"));
|
||||
}
|
||||
|
||||
#ifdef CONFIG_TESTING
|
||||
void test_gui_audio_timeout();
|
||||
#endif /* CONFIG_TESTING */
|
||||
|
|
|
@ -487,7 +487,7 @@ audio-volume-medium</property>
|
|||
<property name="hexpand">True</property>
|
||||
<property name="spacing">3</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="o_position">
|
||||
<object class="GtkLabel" id="position">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="has_tooltip">True</property>
|
||||
|
@ -521,7 +521,7 @@ audio-volume-medium</property>
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="o_duration">
|
||||
<object class="GtkLabel" id="duration">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
|
|
|
@ -20,11 +20,6 @@ struct core_init_data init_data = {
|
|||
.audio_ops = &audio_ops,
|
||||
};
|
||||
|
||||
static inline const gchar *test_get_label_text(const gchar *name)
|
||||
{
|
||||
return gtk_label_get_text(GTK_LABEL(gui_builder_widget(name)));
|
||||
}
|
||||
|
||||
static inline bool test_get_toggle_state(const gchar *name)
|
||||
{
|
||||
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui_builder_widget(name)));
|
||||
|
@ -62,11 +57,14 @@ static void test_audio_init()
|
|||
g_assert_cmpstr(gtk_label_get_text(gui_album_tag()), ==, " ");
|
||||
g_assert_cmpstr(gtk_label_get_text(gui_artist_tag()), ==, " ");
|
||||
g_assert_cmpstr(gtk_label_get_text(gui_title_tag()), ==, " ");
|
||||
g_assert_cmpstr(gtk_label_get_text(gui_position()), ==, "0:00");
|
||||
g_assert_cmpstr(gtk_label_get_text(gui_duration()), ==, "0:00");
|
||||
}
|
||||
|
||||
static void test_audio_load()
|
||||
{
|
||||
struct track *track = track_get(0);
|
||||
struct track *track = track_get(0);
|
||||
gchar *length = string_sec2str(track->tr_length);
|
||||
|
||||
audio_load(track);
|
||||
g_assert_cmpstr(gtk_label_get_text(gui_album_tag()), ==,
|
||||
|
@ -75,13 +73,16 @@ static void test_audio_load()
|
|||
track->tr_album->al_artist->ar_name);
|
||||
g_assert_cmpstr(gtk_label_get_text(gui_title_tag()), ==,
|
||||
track->tr_title);
|
||||
g_assert_cmpstr(gtk_label_get_text(gui_duration()), ==, length);
|
||||
g_assert_cmpstr(gtk_label_get_text(gui_position()), ==, "0:00");
|
||||
|
||||
g_free(length);
|
||||
}
|
||||
|
||||
static void test_audio()
|
||||
{
|
||||
struct db_entry *dbe, *next;
|
||||
struct track *track;
|
||||
gchar *duration;
|
||||
|
||||
audio_load(track_get(1));
|
||||
audio_pause();
|
||||
|
@ -104,12 +105,8 @@ static void test_audio()
|
|||
audio_load(track);
|
||||
g_assert_cmpuint(audio_cur_track()->tr_track, ==, track->tr_track);
|
||||
|
||||
duration = string_sec2str(track->tr_length);
|
||||
g_assert_cmpstr(test_get_label_text("o_position"), ==, "0:00");
|
||||
g_assert_cmpstr(test_get_label_text("o_duration"), ==, duration);
|
||||
g_assert_true(test_get_toggle_state("favorite_button"));
|
||||
g_assert_true(test_get_toggle_state("hide_button"));
|
||||
g_free(duration);
|
||||
|
||||
test_click_button("o_play");
|
||||
g_assert_false(gtk_widget_is_visible(gui_builder_widget("o_play")));
|
||||
|
@ -146,9 +143,10 @@ static void test_audio()
|
|||
test_click_button("o_pause");
|
||||
test_audio_seek(71 * GST_SECOND);
|
||||
test_gui_audio_timeout();
|
||||
g_assert_cmpstr(test_get_label_text("o_position"), ==, "1:11");
|
||||
g_assert_cmpuint(gtk_adjustment_get_upper(GTK_ADJUSTMENT(gui_builder_object("o_progress"))),
|
||||
==, audio_cur_track()->tr_length);
|
||||
test_audio_seek(0);
|
||||
test_gui_audio_timeout();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
Loading…
Reference in New Issue