gui/artwork: Split out album art functions into a new file
I think this is cleaner, and it should make it easier to maintain this code. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
8893cdb58b
commit
83724c5f6f
|
@ -1,4 +1,5 @@
|
||||||
6.4.16:
|
6.4.16:
|
||||||
|
- Split album art code into a new file
|
||||||
- Fix PKGBUILD dependencies
|
- Fix PKGBUILD dependencies
|
||||||
|
|
||||||
6.4.16-rc:
|
6.4.16-rc:
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#include <core/audio.h>
|
||||||
|
#include <gui/builder.h>
|
||||||
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
|
static struct album *__artwork_cur_album = NULL;
|
||||||
|
|
||||||
|
static GdkPixbuf *__artwork_get_pixbuf(struct track *track)
|
||||||
|
{
|
||||||
|
gchar *path = album_artwork_path(track->tr_album);
|
||||||
|
GdkPixbuf *pix;
|
||||||
|
int height;
|
||||||
|
|
||||||
|
if (!path)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
height = gui_builder_widget_height("o_position") +
|
||||||
|
gui_builder_widget_height("o_tags");
|
||||||
|
pix = gdk_pixbuf_new_from_file_at_scale(path, -1, height, true, NULL);
|
||||||
|
g_free(path);
|
||||||
|
|
||||||
|
return pix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_artwork_set_cover(void)
|
||||||
|
{
|
||||||
|
GtkImage *cover = GTK_IMAGE(gui_builder_widget("o_cover"));
|
||||||
|
struct track *track = audio_cur_track();
|
||||||
|
GdkPixbuf *pix;
|
||||||
|
|
||||||
|
if (!track || track->tr_album == __artwork_cur_album)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pix = __artwork_get_pixbuf(track);
|
||||||
|
if (pix) {
|
||||||
|
gtk_image_set_from_pixbuf(cover, pix);
|
||||||
|
g_object_unref(G_OBJECT(pix));
|
||||||
|
} else
|
||||||
|
gtk_image_set_from_icon_name(cover, "image-missing", GTK_ICON_SIZE_DIALOG);
|
||||||
|
|
||||||
|
gtk_widget_set_sensitive(GTK_WIDGET(cover), pix != NULL);
|
||||||
|
__artwork_cur_album = pix ? track->tr_album : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __artwork_select_cover(GtkButton *button)
|
||||||
|
{
|
||||||
|
struct track *track = audio_cur_track();
|
||||||
|
GtkFileFilter *filter;
|
||||||
|
GtkWidget *dialog;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
|
if (!track)
|
||||||
|
return;
|
||||||
|
|
||||||
|
filter = gtk_file_filter_new();
|
||||||
|
dialog = gtk_file_chooser_dialog_new("Choose an image",
|
||||||
|
GTK_WINDOW(gui_builder_widget("o_window")),
|
||||||
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
||||||
|
_("_Open"), GTK_RESPONSE_ACCEPT,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
gtk_file_filter_add_mime_type(filter, "image/*");
|
||||||
|
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
|
||||||
|
gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(dialog), true);
|
||||||
|
|
||||||
|
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||||
|
path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||||
|
album_artwork_import(track->tr_album, path);
|
||||||
|
gui_artwork_set_cover();
|
||||||
|
g_free(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_widget_destroy(dialog);
|
||||||
|
g_object_unref(filter);
|
||||||
|
}
|
74
gui/audio.c
74
gui/audio.c
|
@ -5,13 +5,11 @@
|
||||||
#include <core/collection.h>
|
#include <core/collection.h>
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
#include <core/string.h>
|
#include <core/string.h>
|
||||||
|
#include <gui/artwork.h>
|
||||||
#include <gui/audio.h>
|
#include <gui/audio.h>
|
||||||
#include <gui/builder.h>
|
#include <gui/builder.h>
|
||||||
#include <gui/idle.h>
|
#include <gui/idle.h>
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
#include <glib/gi18n.h>
|
|
||||||
|
|
||||||
static bool __audio_have_cover = false;
|
|
||||||
|
|
||||||
static inline void __audio_set_label(const gchar *label, const gchar *size,
|
static inline void __audio_set_label(const gchar *label, const gchar *size,
|
||||||
const gchar *text)
|
const gchar *text)
|
||||||
|
@ -29,71 +27,6 @@ static inline void __audio_set_time_label(const gchar *label, unsigned int time)
|
||||||
g_free(str);
|
g_free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GdkPixbuf *__audio_get_pixbuf(struct track *track)
|
|
||||||
{
|
|
||||||
gchar *path = album_artwork_path(track->tr_album);
|
|
||||||
GdkPixbuf *pix;
|
|
||||||
int height;
|
|
||||||
|
|
||||||
if (!path)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
height = gui_builder_widget_height("o_position") +
|
|
||||||
gui_builder_widget_height("o_tags");
|
|
||||||
pix = gdk_pixbuf_new_from_file_at_scale(path, -1, height, true, NULL);
|
|
||||||
g_free(path);
|
|
||||||
|
|
||||||
return pix;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __audio_set_cover(void)
|
|
||||||
{
|
|
||||||
GtkImage *cover = GTK_IMAGE(gui_builder_widget("o_cover"));
|
|
||||||
GdkPixbuf *pix = __audio_get_pixbuf(audio_cur_track());
|
|
||||||
|
|
||||||
if (pix) {
|
|
||||||
gtk_image_set_from_pixbuf(cover, pix);
|
|
||||||
g_object_unref(G_OBJECT(pix));
|
|
||||||
} else
|
|
||||||
gtk_image_set_from_icon_name(cover, "image-missing", GTK_ICON_SIZE_DIALOG);
|
|
||||||
|
|
||||||
gtk_widget_set_sensitive(GTK_WIDGET(cover), pix != NULL);
|
|
||||||
__audio_have_cover = (pix != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void __audio_select_cover(GtkButton *button)
|
|
||||||
{
|
|
||||||
struct track *track = audio_cur_track();
|
|
||||||
GtkFileFilter *filter;
|
|
||||||
GtkWidget *dialog;
|
|
||||||
gchar *path;
|
|
||||||
|
|
||||||
if (!track)
|
|
||||||
return;
|
|
||||||
|
|
||||||
filter = gtk_file_filter_new();
|
|
||||||
dialog = gtk_file_chooser_dialog_new("Choose an image",
|
|
||||||
GTK_WINDOW(gui_builder_widget("o_window")),
|
|
||||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
||||||
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
||||||
_("_Open"), GTK_RESPONSE_ACCEPT,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
gtk_file_filter_add_mime_type(filter, "image/*");
|
|
||||||
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
|
|
||||||
gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(dialog), true);
|
|
||||||
|
|
||||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
|
||||||
path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
|
||||||
album_artwork_import(track->tr_album, path);
|
|
||||||
__audio_set_cover();
|
|
||||||
g_free(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_widget_destroy(dialog);
|
|
||||||
g_object_unref(filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __audio_load(struct track *track)
|
static void __audio_load(struct track *track)
|
||||||
{
|
{
|
||||||
__audio_set_label("o_title", "xx-large", track->tr_title);
|
__audio_set_label("o_title", "xx-large", track->tr_title);
|
||||||
|
@ -107,7 +40,7 @@ static void __audio_load(struct track *track)
|
||||||
playlist_has("Favorites", track));
|
playlist_has("Favorites", track));
|
||||||
|
|
||||||
gui_view_scroll();
|
gui_view_scroll();
|
||||||
__audio_set_cover();
|
gui_artwork_set_cover();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __audio_change_state(GstState state)
|
static void __audio_change_state(GstState state)
|
||||||
|
@ -163,8 +96,7 @@ static int __audio_timeout(gpointer data)
|
||||||
gtk_adjustment_set_value(progress, audio_position() / GST_SECOND);
|
gtk_adjustment_set_value(progress, audio_position() / GST_SECOND);
|
||||||
__audio_set_time_label("o_position", audio_position() / GST_SECOND);
|
__audio_set_time_label("o_position", audio_position() / GST_SECOND);
|
||||||
|
|
||||||
if (audio_cur_track() && !__audio_have_cover)
|
gui_artwork_set_cover();
|
||||||
__audio_set_cover();
|
|
||||||
|
|
||||||
return G_SOURCE_CONTINUE;
|
return G_SOURCE_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#ifndef OCARINA_GUI_ARTWORK_H
|
||||||
|
#define OCARINA_GUI_ARTWORK_H
|
||||||
|
|
||||||
|
/* Called to set artwork for a track. */
|
||||||
|
void gui_artwork_set_cover(void);
|
||||||
|
|
||||||
|
#endif /* OCARINA_GUI_ARTWORK_H */
|
|
@ -10,7 +10,8 @@ void __audio_favorite() {}
|
||||||
void __audio_hide() {}
|
void __audio_hide() {}
|
||||||
void __audio_pause_changed() {}
|
void __audio_pause_changed() {}
|
||||||
void __audio_seek() {}
|
void __audio_seek() {}
|
||||||
void __audio_select_cover() {}
|
|
||||||
|
void _artwork_select_cover() {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TEST_NEED_SIDEBAR
|
#ifdef TEST_NEED_SIDEBAR
|
||||||
|
|
|
@ -461,7 +461,7 @@
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
<property name="image">o_cover</property>
|
<property name="image">o_cover</property>
|
||||||
<property name="relief">none</property>
|
<property name="relief">none</property>
|
||||||
<signal name="clicked" handler="__audio_select_cover" swapped="no"/>
|
<signal name="clicked" handler="__artwork_select_cover" swapped="no"/>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left_attach">1</property>
|
<property name="left_attach">1</property>
|
||||||
|
|
|
@ -34,6 +34,7 @@ res += [ GuiTest("idle") ]
|
||||||
res += [ GuiTest("sidebar") ]
|
res += [ GuiTest("sidebar") ]
|
||||||
res += [ GuiTest("collection") ]
|
res += [ GuiTest("collection") ]
|
||||||
res += [ GuiTest("playlist") ]
|
res += [ GuiTest("playlist") ]
|
||||||
|
gui_objs += [ env.Object("../../gui/artwork.c") ]
|
||||||
res += [ GuiTest("audio") ]
|
res += [ GuiTest("audio") ]
|
||||||
|
|
||||||
ignore.close()
|
ignore.close()
|
||||||
|
|
Loading…
Reference in New Issue