gui/artwork: Add an accessor function for the artwork image
This patch also adds a unit test checking that the image is initialized properly. In addition, I simplify things by changing the image widget to be a direct child of the GtkButton. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
8fd4e4c637
commit
bc1c462d36
|
@ -2,6 +2,7 @@
|
|||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/audio.h>
|
||||
#include <gui/artwork.h>
|
||||
#include <gui/window.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
|
@ -17,7 +18,7 @@ static cairo_surface_t *__artwork_scale_pixbuf(GdkPixbuf *pix)
|
|||
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"));
|
||||
int scale = gtk_widget_get_scale_factor(GTK_WIDGET(gui_artwork()));
|
||||
cairo_surface_t *orig = gdk_cairo_surface_create_from_pixbuf(pix, 0,
|
||||
NULL);
|
||||
cairo_content_t content = cairo_surface_get_content(orig);
|
||||
|
@ -56,7 +57,6 @@ static cairo_surface_t *__artwork_get_surface(struct track *track)
|
|||
|
||||
static bool __artwork_set_pixbuf(void)
|
||||
{
|
||||
GtkImage *cover = GTK_IMAGE(gui_builder_widget("o_cover"));
|
||||
struct track *track = audio_cur_track();
|
||||
cairo_surface_t *surface;
|
||||
|
||||
|
@ -65,12 +65,13 @@ static bool __artwork_set_pixbuf(void)
|
|||
|
||||
surface = __artwork_get_surface(track);
|
||||
if (surface) {
|
||||
gtk_image_set_from_surface(cover, surface);
|
||||
gtk_image_set_from_surface(gui_artwork(), surface);
|
||||
cairo_surface_destroy(surface);
|
||||
} else
|
||||
gtk_image_set_from_icon_name(cover, "image-missing", GTK_ICON_SIZE_DIALOG);
|
||||
gtk_image_set_from_icon_name(gui_artwork(), "image-missing",
|
||||
GTK_ICON_SIZE_DIALOG);
|
||||
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(cover), surface != NULL);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(gui_artwork()), surface != NULL);
|
||||
__artwork_cur_album = surface ? track->tr_album : NULL;
|
||||
return (surface != NULL);
|
||||
}
|
||||
|
|
|
@ -3,8 +3,15 @@
|
|||
*/
|
||||
#ifndef OCARINA_GUI_ARTWORK_H
|
||||
#define OCARINA_GUI_ARTWORK_H
|
||||
#include <gui/builder.h>
|
||||
|
||||
/* Called to set artwork for a track. */
|
||||
void gui_artwork_set_cover(void);
|
||||
|
||||
/* Called to get the cover image. */
|
||||
static inline GtkImage *gui_artwork(void)
|
||||
{
|
||||
return GTK_IMAGE(gui_builder_widget("artwork"));
|
||||
}
|
||||
|
||||
#endif /* OCARINA_GUI_ARTWORK_H */
|
||||
|
|
|
@ -158,8 +158,8 @@
|
|||
<property name="icon_name">media-skip-backward</property>
|
||||
</object>
|
||||
</child>
|
||||
<accelerator key="n" signal="clicked" modifiers="GDK_SHIFT_MASK"/>
|
||||
<accelerator key="AudioPrev" signal="clicked"/>
|
||||
<accelerator key="n" signal="clicked" modifiers="GDK_SHIFT_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -193,8 +193,8 @@
|
|||
<property name="icon_size">5</property>
|
||||
</object>
|
||||
</child>
|
||||
<accelerator key="space" signal="clicked"/>
|
||||
<accelerator key="AudioPlay" signal="clicked"/>
|
||||
<accelerator key="space" signal="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -227,8 +227,8 @@
|
|||
<property name="icon_size">5</property>
|
||||
</object>
|
||||
</child>
|
||||
<accelerator key="space" signal="clicked"/>
|
||||
<accelerator key="AudioPlay" signal="clicked"/>
|
||||
<accelerator key="space" signal="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -261,8 +261,8 @@
|
|||
<property name="icon_name">media-skip-forward</property>
|
||||
</object>
|
||||
</child>
|
||||
<accelerator key="n" signal="clicked"/>
|
||||
<accelerator key="AudioNext" signal="clicked"/>
|
||||
<accelerator key="n" signal="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -286,9 +286,10 @@
|
|||
<property name="relief">none</property>
|
||||
<signal name="clicked" handler="__artwork_select_cover" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkImage" id="o_cover">
|
||||
<object class="GtkImage" id="artwork">
|
||||
<property name="height_request">100</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">image-missing</property>
|
||||
<property name="icon_size">6</property>
|
||||
|
|
|
@ -6,4 +6,5 @@ filter
|
|||
treeview
|
||||
sidebar
|
||||
playlist
|
||||
artwork
|
||||
audio
|
||||
|
|
|
@ -14,4 +14,5 @@ gui_unit_test(Sidebar)
|
|||
|
||||
add_subdirectory(playlists/)
|
||||
gui_unit_test(Playlist)
|
||||
gui_unit_test(Artwork)
|
||||
gui_unit_test(Audio)
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/core.h>
|
||||
#include <core/idle.h>
|
||||
#include <gui/artwork.h>
|
||||
#include <gui/filter.h>
|
||||
#include <gui/model.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/sidebar.h>
|
||||
#include <gui/treeview.h>
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.playlist_ops = &playlist_ops,
|
||||
};
|
||||
|
||||
static void test_artwork(void)
|
||||
{
|
||||
const gchar *name;
|
||||
GtkIconSize size;
|
||||
|
||||
g_assert_true(GTK_IS_IMAGE(gui_artwork()));
|
||||
|
||||
gtk_image_get_icon_name(gui_artwork(), &name, &size);
|
||||
g_assert_cmpuint(gtk_image_get_storage_type(gui_artwork()), ==,
|
||||
GTK_IMAGE_ICON_NAME);
|
||||
g_assert_cmpstr(name, ==, "image-missing");
|
||||
g_assert_cmpuint(size, ==, GTK_ICON_SIZE_DIALOG);
|
||||
g_assert_false(gtk_widget_is_sensitive(GTK_WIDGET(gui_artwork())));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
|
||||
gtk_init(&argc, NULL);
|
||||
core_init(&argc, NULL, &init_data);
|
||||
gui_builder_init("share/ocarina/ocarina.ui");
|
||||
gui_model_init();
|
||||
gui_filter_init();
|
||||
gui_treeview_init();
|
||||
gui_sidebar_init();
|
||||
gui_playlist_init();
|
||||
gui_pl_library_add("tests/Music/Hyrule Symphony");
|
||||
while (idle_run_task()) {}
|
||||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
g_test_add_func("/Gui/Artwork", test_artwork);
|
||||
ret = g_test_run();
|
||||
|
||||
core_deinit();
|
||||
gui_treeview_deinit();
|
||||
gui_filter_deinit();
|
||||
gui_model_deinit();
|
||||
gui_builder_deinit();
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue