changeset 1964:f027afc2ca2e trunk

[svn] - avoid freeing a NULL pointer in ui_fileinfo.c - add some hooks for newui - implement album art support in newui
author nenolod
date Sun, 12 Nov 2006 03:09:28 -0800
parents 8cca76c8f5c3
children b17f7a09fdd3
files ChangeLog audacious/glade/newui.glade audacious/newui/newui_window.c audacious/playlist.c audacious/ui_fileinfo.c
diffstat 5 files changed, 124 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Nov 12 02:37:32 2006 -0800
+++ b/ChangeLog	Sun Nov 12 03:09:28 2006 -0800
@@ -1,3 +1,12 @@
+2006-11-12 10:37:32 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [2901]
+  - show_newui_window() implementation
+  
+  trunk/audacious/newui/newui_window.c |    6 ++++++
+  trunk/audacious/newui/newui_window.h |    1 +
+  2 files changed, 7 insertions(+)
+
+
 2006-11-12 10:36:47 +0000  William Pitcock <nenolod@nenolod.net>
   revision [2899]
   - some code
--- a/audacious/glade/newui.glade	Sun Nov 12 02:37:32 2006 -0800
+++ b/audacious/glade/newui.glade	Sun Nov 12 03:09:28 2006 -0800
@@ -338,7 +338,7 @@
 		      </child>
 
 		      <child>
-			<widget class="GtkLabel" id="label15">
+			<widget class="GtkLabel" id="newui_label_tracklen">
 			  <property name="visible">True</property>
 			  <property name="label" translatable="yes"></property>
 			  <property name="use_underline">False</property>
@@ -365,7 +365,7 @@
 		      </child>
 
 		      <child>
-			<widget class="GtkLabel" id="label14">
+			<widget class="GtkLabel" id="newui_label_tracknum">
 			  <property name="visible">True</property>
 			  <property name="label" translatable="yes"></property>
 			  <property name="use_underline">False</property>
@@ -392,7 +392,7 @@
 		      </child>
 
 		      <child>
-			<widget class="GtkLabel" id="label13">
+			<widget class="GtkLabel" id="newui_label_year">
 			  <property name="visible">True</property>
 			  <property name="label" translatable="yes"></property>
 			  <property name="use_underline">False</property>
@@ -419,7 +419,7 @@
 		      </child>
 
 		      <child>
-			<widget class="GtkLabel" id="label12">
+			<widget class="GtkLabel" id="newui_label_genre">
 			  <property name="visible">True</property>
 			  <property name="label" translatable="yes"></property>
 			  <property name="use_underline">False</property>
@@ -446,7 +446,7 @@
 		      </child>
 
 		      <child>
-			<widget class="GtkLabel" id="label11">
+			<widget class="GtkLabel" id="newui_label_album">
 			  <property name="visible">True</property>
 			  <property name="label" translatable="yes"></property>
 			  <property name="use_underline">False</property>
@@ -473,7 +473,7 @@
 		      </child>
 
 		      <child>
-			<widget class="GtkLabel" id="label10">
+			<widget class="GtkLabel" id="newui_label_artist">
 			  <property name="visible">True</property>
 			  <property name="label" translatable="yes"></property>
 			  <property name="use_underline">False</property>
@@ -500,7 +500,7 @@
 		      </child>
 
 		      <child>
-			<widget class="GtkLabel" id="label9">
+			<widget class="GtkLabel" id="newui_label_title">
 			  <property name="visible">True</property>
 			  <property name="label" translatable="yes"></property>
 			  <property name="use_underline">False</property>
--- a/audacious/newui/newui_window.c	Sun Nov 12 02:37:32 2006 -0800
+++ b/audacious/newui/newui_window.c	Sun Nov 12 03:09:28 2006 -0800
@@ -56,6 +56,7 @@
 #include "audacious/playlist.h"
 
 #include "audacious/mainwin.h"
+#include "audacious/ui_fileinfo.h"
 
 GtkWidget *newui_win;
 
@@ -85,15 +86,114 @@
 	gtk_widget_show(newui_win);
 }
 
+static void
+newui_entry_set_image(const char *text)
+{
+        GladeXML *xml = g_object_get_data(G_OBJECT(newui_win), "glade-xml");
+        GtkWidget *widget = glade_xml_get_widget(xml, "newui_albumart_img");
+        GdkPixbuf *pixbuf;
+        int width, height;
+        double aspect;
+
+        if (xml == NULL || widget == NULL)
+                return;
+
+        pixbuf = gdk_pixbuf_new_from_file(text, NULL);
+
+        if (pixbuf == NULL)
+                return;
+
+        width  = gdk_pixbuf_get_width(GDK_PIXBUF(pixbuf));
+        height = gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf));
+
+        if(strcmp(DATA_DIR "/images/audio.png", text))
+        {
+                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;
+        }
+
+        gtk_image_set_from_pixbuf(GTK_IMAGE(widget), GDK_PIXBUF(pixbuf));
+        g_object_unref(G_OBJECT(pixbuf));
+}
+
 void
 newui_update_nowplaying_from_entry(PlaylistEntry *entry)
 {
 	GladeXML *xml = g_object_get_data(G_OBJECT(newui_win), "glade-xml");
 	GtkWidget *widget;
 	gchar *tmp;
+	static gchar *last_artwork = NULL;
+	gchar *fullpath;
 
 	widget = glade_xml_get_widget(xml, "newui_titlestring");
 	tmp = g_strdup_printf("<span size='x-large'>%s</span>", entry->title);
 	gtk_label_set_markup(GTK_LABEL(widget), tmp);
 	g_free(tmp);
+
+	if (entry->tuple == NULL)
+		return;
+
+	widget = glade_xml_get_widget(xml, "newui_label_title");
+	gtk_label_set_text(GTK_LABEL(widget), entry->tuple->track_name);
+
+	widget = glade_xml_get_widget(xml, "newui_label_artist");
+	gtk_label_set_text(GTK_LABEL(widget), entry->tuple->performer);
+
+	widget = glade_xml_get_widget(xml, "newui_label_album");
+	gtk_label_set_text(GTK_LABEL(widget), entry->tuple->album_name);
+
+	widget = glade_xml_get_widget(xml, "newui_label_genre");
+	gtk_label_set_text(GTK_LABEL(widget), entry->tuple->genre);
+
+	widget = glade_xml_get_widget(xml, "newui_label_year");
+	tmp = g_strdup_printf("%d", entry->tuple->year);
+	gtk_label_set_text(GTK_LABEL(widget), tmp);
+	g_free(tmp);
+
+	widget = glade_xml_get_widget(xml, "newui_label_tracknum");
+	tmp = g_strdup_printf("%d", entry->tuple->track_number);
+	gtk_label_set_text(GTK_LABEL(widget), tmp);
+	g_free(tmp);
+
+	widget = glade_xml_get_widget(xml, "newui_label_tracklen");
+	tmp = g_strdup_printf("%d:%02d", entry->tuple->length / 60000, (entry->tuple->length / 1000) % 60);
+	gtk_label_set_text(GTK_LABEL(widget), tmp);
+	g_free(tmp);
+
+        if (cfg.use_file_cover) {
+                /* Use the file name */
+                fullpath = g_strconcat(entry->tuple->file_path, "/", entry->tuple->file_name, NULL);
+        } else {
+                fullpath = g_strconcat(entry->tuple->file_path, "/", NULL);
+        }
+
+        if (!last_artwork || strcmp(last_artwork, fullpath))
+	{
+		if (last_artwork != NULL)
+	                g_free(last_artwork);
+
+                last_artwork = g_strdup(fullpath);
+
+                tmp = fileinfo_recursive_get_image(entry->tuple->file_path, entry->tuple->file_name, 0);
+                if (tmp)
+                {
+                        newui_entry_set_image(tmp);
+                        g_free(tmp);
+                } else {
+                        newui_entry_set_image(DATA_DIR "/images/audio.png");
+                }
+        }
+
+        g_free(fullpath);
 }
--- a/audacious/playlist.c	Sun Nov 12 02:37:32 2006 -0800
+++ b/audacious/playlist.c	Sun Nov 12 03:09:28 2006 -0800
@@ -57,6 +57,8 @@
 
 #include "debug.h"
 
+#include "newui/newui_window.h"
+
 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b);
 typedef void (*PlaylistSaveFunc) (FILE * file);
 
@@ -847,6 +849,7 @@
     playlist_recalc_total_time();
 
     mainwin_set_song_info(rate, freq, nch);
+    newui_update_nowplaying_from_entry(playlist_position);
 }
 
 void
--- a/audacious/ui_fileinfo.c	Sun Nov 12 02:37:32 2006 -0800
+++ b/audacious/ui_fileinfo.c	Sun Nov 12 03:09:28 2006 -0800
@@ -586,8 +586,11 @@
 		fullpath = g_strconcat(tuple->file_path, "/", NULL);
 	}
 
-	if (!last_artwork || strcmp(last_artwork, fullpath)){
-		g_free(last_artwork);
+	if (!last_artwork || strcmp(last_artwork, fullpath))
+	{
+		if (last_artwork != NULL)
+			g_free(last_artwork);
+
 		last_artwork = g_strdup(fullpath);
 
 		tmp = fileinfo_recursive_get_image(tuple->file_path, tuple->file_name, 0);