commit fa8046b6dc659595c6454529842bb604d3d5b780
Author: Hubert Figuière <hub@figuiere.net>
Date:   Mon Sep 29 22:57:01 2014 -0400

    Bug 737167 - Part 1: View the album art in song-info

diff --git a/data/ui/song-info.ui b/data/ui/song-info.ui
index b8a7c82..1531110 100644
--- a/data/ui/song-info.ui
+++ b/data/ui/song-info.ui
@@ -17,8 +17,8 @@
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="border_width">12</property>
-            <property name="n_rows">8</property>
-            <property name="n_columns">4</property>
+            <property name="n_rows">11</property>
+            <property name="n_columns">5</property>
             <property name="column_spacing">12</property>
             <property name="row_spacing">6</property>
             <child>
@@ -169,7 +169,7 @@
               </object>
               <packing>
                 <property name="left_attach">1</property>
-                <property name="right_attach">4</property>
+                <property name="right_attach">5</property>
                 <property name="top_attach">5</property>
                 <property name="bottom_attach">6</property>
                 <property name="y_options"/>
@@ -201,8 +201,8 @@
                 <property name="xalign">0</property>
               </object>
               <packing>
-                <property name="top_attach">7</property>
-                <property name="bottom_attach">8</property>
+                <property name="top_attach">6</property>
+                <property name="bottom_attach">9</property>
                 <property name="x_options">GTK_FILL</property>
                 <property name="y_options"/>
               </packing>
@@ -240,7 +240,7 @@
               </object>
               <packing>
                 <property name="left_attach">1</property>
-                <property name="right_attach">4</property>
+                <property name="right_attach">5</property>
                 <property name="top_attach">8</property>
                 <property name="bottom_attach">9</property>
                 <property name="y_options"/>
@@ -274,7 +274,7 @@
               </object>
               <packing>
                 <property name="left_attach">1</property>
-                <property name="right_attach">4</property>
+                <property name="right_attach">5</property>
                 <property name="top_attach">9</property>
                 <property name="bottom_attach">10</property>
                 <property name="y_options"/>
@@ -326,7 +326,7 @@
               </object>
               <packing>
                 <property name="left_attach">1</property>
-                <property name="right_attach">4</property>
+                <property name="right_attach">5</property>
                 <property name="top_attach">10</property>
                 <property name="bottom_attach">11</property>
               </packing>
@@ -341,8 +341,8 @@
                 <property name="xalign">0</property>
               </object>
               <packing>
-                <property name="top_attach">3</property>
-                <property name="bottom_attach">4</property>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">5</property>
                 <property name="x_options">GTK_FILL</property>
                 <property name="y_options"/>
               </packing>
@@ -355,7 +355,7 @@
               </object>
               <packing>
                 <property name="left_attach">1</property>
-                <property name="right_attach">4</property>
+                <property name="right_attach">5</property>
                 <property name="top_attach">3</property>
                 <property name="bottom_attach">4</property>
                 <property name="y_options"/>
@@ -385,7 +385,7 @@
               </object>
               <packing>
                 <property name="left_attach">1</property>
-                <property name="right_attach">4</property>
+                <property name="right_attach">5</property>
                 <property name="top_attach">4</property>
                 <property name="bottom_attach">5</property>
                 <property name="y_options"/>
@@ -426,7 +426,7 @@
               </object>
               <packing>
                 <property name="left_attach">3</property>
-                <property name="right_attach">4</property>
+                <property name="right_attach">5</property>
                 <property name="top_attach">6</property>
                 <property name="bottom_attach">7</property>
                 <property name="x_options">GTK_FILL</property>
@@ -442,13 +442,26 @@
               </object>
               <packing>
                 <property name="left_attach">3</property>
-                <property name="right_attach">4</property>
+                <property name="right_attach">5</property>
                 <property name="top_attach">7</property>
                 <property name="bottom_attach">8</property>
                 <property name="x_options">GTK_FILL</property>
                 <property name="y_options"/>
               </packing>
             </child>
+            <child>
+              <object class="GtkImage" id="song_info_cover">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="stock">gtk-missing-image</property>
+                <property name="icon_size">6</property>
+              </object>
+              <packing>
+                <property name="left_attach">4</property>
+                <property name="right_attach">5</property>
+                <property name="bottom_attach">3</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
diff --git a/widgets/rb-song-info.c b/widgets/rb-song-info.c
index 79f18cf..1b611f1 100644
--- a/widgets/rb-song-info.c
+++ b/widgets/rb-song-info.c
@@ -53,6 +53,9 @@
 #include "rb-shell.h"
 #include "rb-file-helpers.h"
 #include "rb-util.h"
+#include "rb-debug.h"
+#include "rb-stock-icons.h"
+#include "rb-ext-db.h"
 
 static void rb_song_info_class_init (RBSongInfoClass *klass);
 static void rb_song_info_init (RBSongInfo *song_info);
@@ -105,6 +108,7 @@ static void rb_song_info_sync_entries (RBSongInfo *dialog);
 struct RBSongInfoPrivate
 {
 	RhythmDB *db;
+	RBExtDB *art_store;
 	RBSource *source;
 	RBEntryView *entry_view;
 	RhythmDBQueryModel *query_model;
@@ -121,6 +125,7 @@ struct RBSongInfoPrivate
 	GtkWidget   *forward;
 	GtkWidget   *notebook;
 
+	GtkWidget   *cover;
 	GtkWidget   *title;
 	GtkWidget   *artist;
 	GtkWidget   *album;
@@ -372,6 +377,7 @@ rb_song_info_construct_single (RBSongInfo *song_info, GtkBuilder *builder, gbool
 
 	/* get the widgets from the XML */
 	song_info->priv->notebook      = GTK_WIDGET (gtk_builder_get_object (builder, "song_info_vbox"));
+	song_info->priv->cover         = GTK_WIDGET (gtk_builder_get_object (builder, "song_info_cover"));
 	song_info->priv->title         = GTK_WIDGET (gtk_builder_get_object (builder, "song_info_title"));
 	song_info->priv->track_cur     = GTK_WIDGET (gtk_builder_get_object (builder, "song_info_track_cur"));
 	song_info->priv->bitrate       = GTK_WIDGET (gtk_builder_get_object (builder, "song_info_bitrate"));
@@ -494,6 +500,8 @@ rb_song_info_constructed (GObject *object)
 				   GTK_WIDGET (gtk_builder_get_object (builder, "song_info_notebook")));
 	}
 
+	song_info->priv->art_store = rb_ext_db_new ("album-art");
+
 	song_info->priv->artist = GTK_WIDGET (gtk_builder_get_object (builder, "song_info_artist"));
 	song_info->priv->composer = GTK_WIDGET (gtk_builder_get_object (builder, "song_info_composer"));
 	song_info->priv->album = GTK_WIDGET (gtk_builder_get_object (builder, "song_info_album"));
@@ -584,7 +592,7 @@ rb_song_info_constructed (GObject *object)
 				 G_CALLBACK (rb_song_info_mnemonic_cb),
 				 NULL, 0);
 
-	/* this widget has to be customly created */
+	/* rating: this widget has to be customly created */
 	song_info->priv->rating = GTK_WIDGET (rb_rating_new ());
 	g_signal_connect_object (song_info->priv->rating, "rated",
 				 G_CALLBACK (rb_song_info_rated_cb),
@@ -593,7 +601,7 @@ rb_song_info_constructed (GObject *object)
 			   song_info->priv->rating);
 	g_object_set (gtk_builder_get_object (builder, "rating_label"), "mnemonic-widget", song_info->priv->rating, NULL);
 
-	/* add relationship between the rating label and the rating widget */
+	/* rating: add relationship between the rating label and the rating widget */
 	lobj = gtk_widget_get_accessible (GTK_WIDGET (gtk_builder_get_object (builder, "rating_label")));
 	robj = gtk_widget_get_accessible (song_info->priv->rating);
 
@@ -658,6 +666,10 @@ rb_song_info_dispose (GObject *object)
 		song_info->priv->genres = NULL;
 	}
 
+	if (song_info->priv->art_store != NULL) {
+		g_object_unref (song_info->priv->art_store);
+		song_info->priv->art_store = NULL;
+	}
 	if (song_info->priv->db != NULL) {
 		g_object_unref (song_info->priv->db);
 		song_info->priv->db = NULL;
@@ -1132,6 +1144,35 @@ rb_song_info_populate_dialog_multiple (RBSongInfo *song_info)
 }
 
 static void
+art_cb (RBExtDBKey *key, RBExtDBKey *store_key,
+	const char *filename, GValue *data,
+	RBSongInfo *song_info)
+{
+
+	if (filename) {
+		GError *error = NULL;
+		GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size (filename,
+							   96, 96, &error);
+		if (error) {
+			rb_debug ("error getting pixbuf for cover file %s",
+				  error->message);
+			g_error_free (error);
+		} else {
+			gtk_image_set_from_pixbuf (GTK_IMAGE (song_info->priv->cover),
+						   pixbuf);
+			g_object_unref (pixbuf);
+			/* we are done here */
+			return;
+		}
+	}
+	/* this is a fall back in case of any error */
+	gtk_image_set_from_icon_name (GTK_IMAGE (song_info->priv->cover),
+				      RB_STOCK_MISSING_ARTWORK,
+				      GTK_ICON_SIZE_DIALOG);
+
+}
+
+static void
 rb_song_info_populate_dialog (RBSongInfo *song_info)
 {
 	const char *text;
@@ -1141,6 +1182,25 @@ rb_song_info_populate_dialog (RBSongInfo *song_info)
 
 	g_assert (song_info->priv->current_entry);
 
+	gtk_image_set_from_icon_name (GTK_IMAGE (song_info->priv->cover),
+				      RB_STOCK_MISSING_ARTWORK,
+				      GTK_ICON_SIZE_DIALOG);
+
+	/* cover art: async */
+	if (song_info->priv->art_store) {
+		RBExtDBKey *key;
+		key = rhythmdb_entry_create_ext_db_key (song_info->priv->current_entry,
+							RHYTHMDB_PROP_ALBUM);
+		rb_ext_db_request (song_info->priv->art_store, key,
+				   (RBExtDBRequestCallback) art_cb,
+				   g_object_ref (song_info), g_object_unref);
+		rb_ext_db_key_free (key);
+	} else {
+		gtk_image_set_from_icon_name (GTK_IMAGE (song_info->priv->cover),
+					      RB_STOCK_MISSING_ARTWORK,
+					      GTK_ICON_SIZE_DIALOG);
+	}
+
 	/* update the buttons sensitivity */
 	rb_song_info_update_buttons (song_info);
 
