[banshee] [Banshee.Moblin] Make the grid interactive



commit 5a6ed930ed69a617ec44bf27b82d4ba229cc4e23
Author: Aaron Bockover <abockover novell com>
Date:   Thu Oct 15 05:14:08 2009 -0400

    [Banshee.Moblin] Make the grid interactive

 .../Banshee.Moblin/RecentAlbumsView.cs             |   72 ++++++++++++++++----
 1 files changed, 58 insertions(+), 14 deletions(-)
---
diff --git a/src/Extensions/Banshee.Moblin/Banshee.Moblin/RecentAlbumsView.cs b/src/Extensions/Banshee.Moblin/Banshee.Moblin/RecentAlbumsView.cs
index 928ccf5..a7de025 100644
--- a/src/Extensions/Banshee.Moblin/Banshee.Moblin/RecentAlbumsView.cs
+++ b/src/Extensions/Banshee.Moblin/Banshee.Moblin/RecentAlbumsView.cs
@@ -31,6 +31,7 @@ using Gtk;
 
 using Banshee.Gui;
 using Banshee.Gui.Widgets;
+using Banshee.Collection;
 using Banshee.Collection.Gui;
 using Banshee.ServiceStack;
 
@@ -41,9 +42,48 @@ namespace Banshee.Moblin
         const int icon_size = 98;
         const int cols = 5;
         const int rows = 3;
+        
+        private class AlbumButton : Button
+        {
+            private Image image = new Image ();
+            private AlbumInfo album;
+            
+            public AlbumButton ()
+            {
+                Relief = ReliefStyle.None;
+                Add (image);
+                image.Show ();
+            }
+            
+            protected override void OnClicked ()
+            {
+                var source = ServiceManager.SourceManager.MusicLibrary;
+                if (source != null) {
+                    source.FilterType = TrackFilterType.None;
+                    source.FilterQuery = String.Format ("artist=\"{0}\" album=\"{1}\"", Album.ArtistName, Album.Title);
+                    ServiceManager.SourceManager.SetActiveSource (source);
+                    ServiceManager.Get<MoblinService> ().PresentPrimaryInterface ();
+                }
+            }
+            
+            public Gdk.Pixbuf Pixbuf {
+                get { return image.Pixbuf; }
+                set { image.Pixbuf = value; }
+            }
+            
+            public AlbumInfo Album {
+                get { return album; }
+                set {
+                    album = value;
+                    TooltipMarkup = String.Format ("<b><big>{0}</big></b>\n<i>{1}</i>",
+                        GLib.Markup.EscapeText (album.DisplayTitle),
+                        GLib.Markup.EscapeText (album.DisplayArtistName));
+                }
+            }
+        }
 
         private RecentAlbumsList recent;
-        private List<Image> images;
+        private List<AlbumButton> buttons;
 
         public RecentAlbumsView () : base (5, 3, false)
         {
@@ -53,35 +93,39 @@ namespace Banshee.Moblin
             recent = new RecentAlbumsList (cols * rows);
             recent.Changed += (o, a) => Reload ();
             Reload ();
+            
+            NoShowAll = true;
         }
 
         private void Build ()
         {
-            images = new List<Image> ();
+            buttons = new List<AlbumButton> ();
 
             for (uint j = 0; j < rows; j++) {
                 for (uint i = 0; i < cols; i++) {
-                    var image = new Image ();
-                    images.Add (image);
-                    Attach (image, i, i + 1, j, j + 1);
+                    var button = new AlbumButton ();
+                    buttons.Add (button);
+                    Attach (button, i, i + 1, j, j + 1);
                 }
             }
-
-            ShowAll ();
+            
+            Show ();
         }
 
         public void Reload ()
         {
             var artwork = ServiceManager.Get<ArtworkManager> ();
 
-            for (int i = 0; i < recent.Albums.Count; i++) {
+            for (int i = 0; i < cols * rows; i++) {
+                if (i >= recent.Albums.Count) {
+                    buttons[i].Hide ();
+                    continue;
+                }
+                
                 var album = recent.Albums[i];
-                images[i].Pixbuf = artwork.LookupScalePixbuf (album.ArtworkId, icon_size);
-                images[i].Show ();
-            }
-
-            for (int i = recent.Albums.Count; i < cols * rows; i++) {
-                images[i].Hide ();
+                buttons[i].Album = album;
+                buttons[i].Pixbuf = artwork.LookupScalePixbuf (album.ArtworkId, icon_size);
+                buttons[i].Show ();
             }
         }
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]