[banshee] [Lastfm] Ellipsize artist names (bgo#585011)



commit 02df0521b15c0d739d1f3d8361364717483419a9
Author: Kevin Duffus <KevinDuffus gmail com>
Date:   Thu Apr 8 15:31:57 2010 +1000

    [Lastfm] Ellipsize artist names (bgo#585011)
    
    Ellipsize recommended artist names if number of characters
    for an artist name is > 2 * (average number of characters
    for the currently suggested artists)
    
    Signed-off-by: Alexander Kojevnikov <alexander kojevnikov com>

 src/Core/Banshee.Widgets/Banshee.Widgets/Tile.cs   |   43 ++++++++++---------
 .../RecommendationPane.cs                          |   20 ++++++---
 .../Banshee.Lastfm/Banshee.Lastfm.csproj           |    1 +
 3 files changed, 38 insertions(+), 26 deletions(-)
---
diff --git a/src/Core/Banshee.Widgets/Banshee.Widgets/Tile.cs b/src/Core/Banshee.Widgets/Banshee.Widgets/Tile.cs
index 363920e..5a760be 100644
--- a/src/Core/Banshee.Widgets/Banshee.Widgets/Tile.cs
+++ b/src/Core/Banshee.Widgets/Banshee.Widgets/Tile.cs
@@ -35,9 +35,9 @@ namespace Banshee.Widgets
     {
         private static readonly int pixbuf_size = 40;
 
-        private Image image = new Image();
-        private Label primary_label = new Label();
-        private Label secondary_label = new Label();
+        private Image image = new Image ();
+        public Label PrimaryLabel { get; private set; }
+        public Label SecondaryLabel { get; private set; }
 
         private string primary_text;
         private string secondary_text;
@@ -47,33 +47,36 @@ namespace Banshee.Widgets
             PrimaryText = primaryText;
         }
 
-        public Tile()
+        public Tile ()
         {
-            Table table = new Table(2, 2, false);
+            Table table = new Table (2, 2, false);
             table.ColumnSpacing = 6;
             table.RowSpacing = 2;
             table.BorderWidth = 2;
 
-            table.Attach(image, 0, 1, 0, 2, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
-            table.Attach(primary_label, 1, 2, 0, 1,
+            PrimaryLabel = new Label ();
+            SecondaryLabel = new Label ();
+
+            table.Attach (image, 0, 1, 0, 2, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
+            table.Attach (PrimaryLabel, 1, 2, 0, 1,
                 AttachOptions.Fill | AttachOptions.Expand,
                 AttachOptions.Shrink, 0, 0);
-            table.Attach(secondary_label, 1, 2, 1, 2,
+            table.Attach (SecondaryLabel, 1, 2, 1, 2,
                 AttachOptions.Fill | AttachOptions.Expand,
                 AttachOptions.Fill | AttachOptions.Expand, 0, 0);
 
-            table.ShowAll();
-            Add(table);
+            table.ShowAll ();
+            Add (table);
 
-            primary_label.Xalign = 0.0f;
-            primary_label.Yalign = 0.0f;
+            PrimaryLabel.Xalign = 0.0f;
+            PrimaryLabel.Yalign = 0.0f;
 
-            secondary_label.Xalign = 0.0f;
-            secondary_label.Yalign = 0.0f;
+            SecondaryLabel.Xalign = 0.0f;
+            SecondaryLabel.Yalign = 0.0f;
 
             StyleSet += delegate {
-                primary_label.ModifyFg (StateType.Normal, Style.Text (StateType.Normal));
-                secondary_label.ModifyFg (StateType.Normal, Hyena.Gui.GtkUtilities.ColorBlend (
+                PrimaryLabel.ModifyFg (StateType.Normal, Style.Text (StateType.Normal));
+                SecondaryLabel.ModifyFg (StateType.Normal, Hyena.Gui.GtkUtilities.ColorBlend (
                     Style.Foreground (StateType.Normal), Style.Background (StateType.Normal)));
             };
 
@@ -84,7 +87,7 @@ namespace Banshee.Widgets
             get { return primary_text; }
             set {
                 primary_text = value;
-                primary_label.Text = value;
+                PrimaryLabel.Text = value;
             }
         }
 
@@ -92,8 +95,8 @@ namespace Banshee.Widgets
             get { return secondary_text; }
             set {
                 secondary_text = value;
-                secondary_label.Markup = String.Format("<small>{0}</small>",
-                    GLib.Markup.EscapeText(value));
+                SecondaryLabel.Markup = String.Format ("<small>{0}</small>",
+                    GLib.Markup.EscapeText (value));
             }
         }
 
@@ -109,7 +112,7 @@ namespace Banshee.Widgets
                     return;
                 }
 
-                image.Pixbuf = value.ScaleSimple(pixbuf_size, pixbuf_size,
+                image.Pixbuf = value.ScaleSimple (pixbuf_size, pixbuf_size,
                     Gdk.InterpType.Bilinear);
             }
         }
diff --git a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Recommendations/RecommendationPane.cs b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Recommendations/RecommendationPane.cs
index 1726a57..25a1735 100644
--- a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Recommendations/RecommendationPane.cs
+++ b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Recommendations/RecommendationPane.cs
@@ -30,6 +30,7 @@
 //
 
 using System;
+using System.Linq;
 using System.IO;
 using System.Net;
 using System.Text;
@@ -278,13 +279,20 @@ namespace Banshee.Lastfm.Recommendations
                 ClearBox (track_list);
 
                 // Similar Artists
-                for (int i = 0; i < Math.Min (20, similar_artists.Count); i++) {
-                    SimilarArtistTile tile = new SimilarArtistTile (similar_artists[i]);
-                    tile.ShowAll ();
-                    similar_artists_view.AddWidget (tile);
-                }
+                var artists = similar_artists.Take (20);
+
+                if (artists.Count () > 0) {
+                    int artist_name_max_len = 2 * (int) artists.Select (a => a.Name.Length).Average ();
+                    foreach (var similar_artist in artists) {
+                        SimilarArtistTile tile = new SimilarArtistTile (similar_artist);
+
+                        tile.PrimaryLabel.WidthChars = artist_name_max_len;
+                        tile.PrimaryLabel.Ellipsize = Pango.EllipsizeMode.End;
+
+                        tile.ShowAll ();
+                        similar_artists_view.AddWidget (tile);
+                    }
 
-                if (similar_artists.Count > 0) {
                     no_artists_pane.Hide ();
                     similar_artists_view_sw.ShowAll ();
                 } else {
diff --git a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.csproj b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.csproj
index 601ab41..602311f 100644
--- a/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.csproj
+++ b/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.csproj
@@ -38,6 +38,7 @@
     <Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
     <Reference Include="pango-sharp" />
     <Reference Include="System" />
+    <Reference Include="System.Core" />
     <Reference Include="System.Data" />
     <Reference Include="Mono.Posix" />
     <Reference Include="Banshee.Base, Version=0.13.2.36411, Culture=neutral" />



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