gui/artwork: Add a preview widget to the file chooser dialog
This lets users actually see images before selecting them for ablum art. Implements #59: Add preview widget to album art chooser Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
343dec5d8d
commit
160295a6cc
|
@ -5,6 +5,8 @@
|
|||
#include <gui/builder.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#define ARTWORK_PREVIEW_SIZE 150
|
||||
|
||||
static struct album *__artwork_cur_album = NULL;
|
||||
static unsigned int __artwork_timeo_id = 0;
|
||||
|
||||
|
@ -88,18 +90,41 @@ void gui_artwork_set_cover(void)
|
|||
__artwork_timeo_id = g_timeout_add(2000, __artwork_timeout, NULL);
|
||||
}
|
||||
|
||||
void __artwork_update_preview(GtkFileChooser *chooser, gpointer data)
|
||||
{
|
||||
GtkWidget *preview = gtk_file_chooser_get_preview_widget(chooser);
|
||||
gchar *path = gtk_file_chooser_get_preview_filename(chooser);
|
||||
GdkPixbuf *pix = gdk_pixbuf_new_from_file(path, NULL);
|
||||
unsigned int old_w, scale;
|
||||
cairo_surface_t *surface;
|
||||
|
||||
if (pix) {
|
||||
old_w = gdk_pixbuf_get_width(pix);
|
||||
scale = old_w / ARTWORK_PREVIEW_SIZE;
|
||||
surface = gdk_cairo_surface_create_from_pixbuf(pix, scale, NULL);
|
||||
if (surface) {
|
||||
gtk_image_set_from_surface(GTK_IMAGE(preview), surface);
|
||||
cairo_surface_destroy(surface);
|
||||
}
|
||||
}
|
||||
|
||||
g_free(path);
|
||||
}
|
||||
|
||||
void __artwork_select_cover(GtkButton *button)
|
||||
{
|
||||
struct track *track = audio_cur_track();
|
||||
GtkFileFilter *filter;
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *preview;
|
||||
gchar *path;
|
||||
|
||||
if (!track)
|
||||
return;
|
||||
|
||||
filter = gtk_file_filter_new();
|
||||
dialog = gtk_file_chooser_dialog_new("Choose an image",
|
||||
filter = gtk_file_filter_new();
|
||||
preview = gtk_image_new_from_icon_name("", GTK_ICON_SIZE_DIALOG);
|
||||
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,
|
||||
|
@ -108,7 +133,10 @@ void __artwork_select_cover(GtkButton *button)
|
|||
|
||||
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);
|
||||
gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog), preview);
|
||||
gtk_file_chooser_set_use_preview_label(GTK_FILE_CHOOSER(dialog), false);
|
||||
|
||||
g_signal_connect(dialog, "update-preview", (GCallback)__artwork_update_preview, NULL);
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
|
@ -118,5 +146,6 @@ void __artwork_select_cover(GtkButton *button)
|
|||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
gtk_widget_destroy(preview);
|
||||
g_object_unref(filter);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue