gui/audio: Add album art support

Also add the "o_cover" widget to the glade file for setting album art.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-02-05 15:31:17 -05:00
parent d0dddeacdb
commit 54af68a57f
2 changed files with 65 additions and 11 deletions

View File

@ -7,8 +7,10 @@
#include <core/string.h>
#include <gui/audio.h>
#include <gui/builder.h>
#include <gui/idle.h>
#include <gui/view.h>
static bool __audio_have_cover = false;
static inline void __audio_set_label(const gchar *label, const gchar *size,
const gchar *text)
@ -26,6 +28,33 @@ static inline void __audio_set_time_label(const gchar *label, unsigned int time)
g_free(str);
}
static void __audio_set_cover(gchar *path)
{
GtkImage *image = GTK_IMAGE(gui_builder_widget("o_cover"));
GtkWidget *tags = gui_builder_widget("o_tags");
int height = gtk_widget_get_allocated_height(tags);
GdkPixbuf *pix = gdk_pixbuf_new_from_file_at_size(path, height,
height, NULL);
gtk_image_set_from_pixbuf(image, pix);
gtk_widget_show(GTK_WIDGET(image));
__audio_have_cover = true;
}
static void __audio_get_cover(struct track *track)
{
gchar *path = album_artwork_path(track->tr_album);
if (path) {
__audio_set_cover(path);
g_free(path);
} else {
gtk_widget_hide(gui_builder_widget("o_cover"));
gui_idle_enable();
__audio_have_cover = false;
}
}
static void __audio_load(struct track *track)
{
__audio_set_label("o_title", "xx-large", track->tr_title);
@ -37,7 +66,9 @@ static void __audio_load(struct track *track)
playlist_has(PL_HIDDEN, track));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_favorite")),
playlist_has(PL_FAVORITED, track));
gui_view_scroll();
__audio_get_cover(track);
}
static void __audio_change_state(GstState state)
@ -87,12 +118,21 @@ void __audio_hide(GtkToggleButton *toggle, gpointer data)
static int __audio_timeout(gpointer data)
{
struct track *track = audio_cur_track();
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);
if (track && !__audio_have_cover) {
gchar *path = album_artwork_path(track->tr_album);
if (path) {
__audio_set_cover(path);
g_free(path);
}
}
return G_SOURCE_CONTINUE;
}

View File

@ -303,7 +303,7 @@
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="column_homogeneous">True</property>
<property name="column_spacing">5</property>
<child>
<object class="GtkButtonBox" id="buttonbox1">
<property name="visible">True</property>
@ -453,12 +453,11 @@
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">2</property>
<property name="height">3</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow2">
<object class="GtkScrolledWindow" id="o_tags">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_top">5</property>
@ -551,7 +550,6 @@
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
<property name="width">4</property>
<property name="height">2</property>
</packing>
</child>
@ -559,6 +557,7 @@
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="spacing">5</property>
<child>
<object class="GtkLabel" id="o_position">
@ -571,7 +570,7 @@
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
@ -580,6 +579,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="adjustment">o_progress</property>
<property name="round_digits">0</property>
<property name="draw_value">False</property>
@ -597,12 +597,13 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="margin_right">15</property>
<property name="label" translatable="yes">&lt;span size='large'&gt;0:00&lt;/span&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
@ -610,7 +611,6 @@
<packing>
<property name="left_attach">2</property>
<property name="top_attach">2</property>
<property name="width">3</property>
</packing>
</child>
<child>
@ -754,9 +754,8 @@
</child>
</object>
<packing>
<property name="left_attach">5</property>
<property name="left_attach">3</property>
<property name="top_attach">1</property>
<property name="width">2</property>
<property name="height">2</property>
</packing>
</child>
@ -806,7 +805,7 @@
</child>
</object>
<packing>
<property name="left_attach">6</property>
<property name="left_attach">3</property>
<property name="top_attach">0</property>
</packing>
</child>
@ -1437,7 +1436,21 @@
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="width">7</property>
<property name="width">4</property>
</packing>
</child>
<child>
<object class="GtkImage" id="o_cover">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="height">3</property>
</packing>
</child>
</object>
@ -1452,6 +1465,7 @@
</widgets>
</object>
<object class="GtkSizeGroup" id="sizegroup1">
<property name="ignore_hidden">True</property>
<widgets>
<widget name="buttonbox1"/>
<widget name="o_idle_progress"/>