changeset 1710:43ae2a1bfdee trunk

[svn] improvement of filepopup: - now filepopup respects aspect ratio of each image. - it caches scaled image while the same path is being referred. - its image size and delay until coming up is configurable. (no GUI currently.)
author yaz
date Fri, 15 Sep 2006 20:21:35 -0700
parents 950b24509828
children c7c1e346bb55
files ChangeLog audacious/main.c audacious/main.h audacious/ui_fileinfo.c
diffstat 4 files changed, 66 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Sep 15 20:10:47 2006 -0700
+++ b/ChangeLog	Fri Sep 15 20:21:35 2006 -0700
@@ -1,3 +1,11 @@
+2006-09-16 03:10:47 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [2355]
+  - actually on second thought, i don't see the point in this
+  
+
+  Changes:        Modified:
+
+
 2006-09-16 02:59:32 +0000  William Pitcock <nenolod@nenolod.net>
   revision [2353]
   - change Makefile / filename
--- a/audacious/main.c	Fri Sep 15 20:10:47 2006 -0700
+++ b/audacious/main.c	Fri Sep 15 20:21:35 2006 -0700
@@ -206,6 +206,8 @@
     FALSE,
     0,
     NULL,			/* default session uri base (non-NULL = custom session uri base) */
+    150,			/* short side length of the picture in the filepopup */
+    20,				/* delay until the filepopup comes up */
 };
 
 typedef struct bmp_cfg_boolent_t {
@@ -330,7 +332,9 @@
     {"titlestring_preset", &cfg.titlestring_preset, TRUE},
     {"resume_playback_on_startup_time", &cfg.resume_playback_on_startup_time, TRUE},
     {"output_buffer_size", &cfg.output_buffer_size, TRUE},
-    {"recurse_for_cover_depth", &cfg.recurse_for_cover_depth, TRUE}
+    {"recurse_for_cover_depth", &cfg.recurse_for_cover_depth, TRUE},
+    {"filepopup_pixelsize", &cfg.filepopup_pixelsize, TRUE},
+    {"filepopup_delay", &cfg.filepopup_delay, TRUE},
 };
 
 static gint ncfgient = G_N_ELEMENTS(bmp_numents);
--- a/audacious/main.h	Fri Sep 15 20:10:47 2006 -0700
+++ b/audacious/main.h	Fri Sep 15 20:21:35 2006 -0700
@@ -119,6 +119,8 @@
     gboolean recurse_for_cover;
     gint recurse_for_cover_depth;
     gchar *session_uri_base;
+    gint filepopup_pixelsize;
+    gint filepopup_delay;
 };
 
 typedef struct _BmpConfig BmpConfig;
--- a/audacious/ui_fileinfo.c	Fri Sep 15 20:10:47 2006 -0700
+++ b/audacious/ui_fileinfo.c	Fri Sep 15 20:21:35 2006 -0700
@@ -98,6 +98,8 @@
 	GladeXML *xml = g_object_get_data(G_OBJECT(fileinfo_win), "glade-xml");
 	GtkWidget *widget = glade_xml_get_widget(xml, entry);
 	GdkPixbuf *pixbuf;
+	int width, height;
+	double aspect;
 
 	if (xml == NULL || widget == NULL)
 		return;
@@ -107,9 +109,22 @@
 	if (pixbuf == NULL)
 		return;
 
-	if (gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf)) > 150)
+	width  = gdk_pixbuf_get_width(GDK_PIXBUF(pixbuf));
+	height = gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf));
+
+	if(strcmp(DATA_DIR "/images/audio.png", text))
 	{
-		GdkPixbuf *pixbuf2 = gdk_pixbuf_scale_simple(GDK_PIXBUF(pixbuf), 150, 150, GDK_INTERP_BILINEAR);
+		if(width == 0)
+			width = 1;
+		aspect = (double)height / (double)width;
+		if(aspect > 1.0) {
+			height = (int)(cfg.filepopup_pixelsize * aspect);
+			width = cfg.filepopup_pixelsize;
+		} else {
+			height = cfg.filepopup_pixelsize;
+			width = (int)(cfg.filepopup_pixelsize / aspect);
+		}
+		GdkPixbuf *pixbuf2 = gdk_pixbuf_scale_simple(GDK_PIXBUF(pixbuf), width, height, GDK_INTERP_BILINEAR);
 		g_object_unref(G_OBJECT(pixbuf));
 		pixbuf = pixbuf2;
 	}
@@ -136,6 +151,8 @@
 	GladeXML *xml = g_object_get_data(G_OBJECT(filepopup_win), "glade-xml");
 	GtkWidget *widget = glade_xml_get_widget(xml, entry);
 	GdkPixbuf *pixbuf;
+	int width, height;
+	double aspect;
 
 	if (xml == NULL || widget == NULL)
 		return;
@@ -145,9 +162,22 @@
 	if (pixbuf == NULL)
 		return;
 
-	if (gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf)) > 150)
+	width  = gdk_pixbuf_get_width(GDK_PIXBUF(pixbuf));
+	height = gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf));
+
+	if(strcmp(DATA_DIR "/images/audio.png", text))
 	{
-		GdkPixbuf *pixbuf2 = gdk_pixbuf_scale_simple(GDK_PIXBUF(pixbuf), 150, 150, GDK_INTERP_BILINEAR);
+		if(width == 0)
+			width = 1;
+		aspect = (double)height / (double)width;
+		if(aspect > 1.0) {
+			height = (int)(cfg.filepopup_pixelsize * aspect);
+			width = cfg.filepopup_pixelsize;
+		} else {
+			height = cfg.filepopup_pixelsize;
+			width = (int)(cfg.filepopup_pixelsize / aspect);
+		}
+		GdkPixbuf *pixbuf2 = gdk_pixbuf_scale_simple(GDK_PIXBUF(pixbuf), width, height, GDK_INTERP_BILINEAR);
 		g_object_unref(G_OBJECT(pixbuf));
 		pixbuf = pixbuf2;
 	}
@@ -212,7 +242,7 @@
 	if (filepopup_win->window == NULL)
 		skip = TRUE;
 
-        if (ctr >= 20 && (skip == TRUE || gdk_window_is_viewable(GDK_WINDOW(filepopup_win->window)) != TRUE))
+        if (ctr >= cfg.filepopup_delay && (skip == TRUE || gdk_window_is_viewable(GDK_WINDOW(filepopup_win->window)) != TRUE))
         {
 		if (pos == -1)
   		{
@@ -258,7 +288,6 @@
 	filepopup_entry_set_text("label_year", "");
 	filepopup_entry_set_text("label_length", "");
 
-	filepopup_entry_set_image("image_artwork", DATA_DIR "/images/audio.png");
 
 	gtk_window_resize(GTK_WINDOW(filepopup_win), 1, 1);
 }
@@ -462,9 +491,11 @@
 void
 filepopup_show_for_tuple(TitleInput *tuple)
 {
-	gchar *tmp;
+	gchar *tmp = NULL;
 	gint x, y, x_off = 3, y_off = 3, h, w;
 
+	static gchar *lastpath = NULL;
+
 	if (tuple == NULL)
 		return;
 
@@ -484,14 +515,21 @@
 	if (tuple->track_number != 0)
 		filepopup_entry_set_text_free("label_track", g_strdup_printf("%d", tuple->track_number));
 
-	tmp = fileinfo_recursive_get_image(tuple->file_path, 0);
+	if(strcmp(lastpath?lastpath:"", tuple->file_path)){
+		tmp = fileinfo_recursive_get_image(tuple->file_path, 0);
 	
-	if(tmp)
-	{
-		filepopup_entry_set_image("image_artwork", tmp);
-		g_free(tmp);
+		if(tmp)
+		{
+			filepopup_entry_set_image("image_artwork", tmp);
+			g_free(tmp);
+			g_free(lastpath);
+			lastpath = g_strdup(tuple->file_path);
+		} else {
+			filepopup_entry_set_image("image_artwork", DATA_DIR "/images/audio.png");
+			g_free(lastpath);
+			lastpath = g_strdup(tuple->file_path);
+		}
 	}
-	
 	gdk_window_get_pointer(NULL, &x, &y, NULL);
 	gtk_window_get_size(GTK_WINDOW(filepopup_win), &w, &h);
 	if (gdk_screen_width()-(w+3) < x) x_off = (w*-1)-3;