banshee r5165 - in trunk/banshee: . src/Core/Banshee.ThickClient/Banshee.Gui.Widgets src/Libraries/Hyena/Hyena src/Libraries/Hyena/Hyena/Tests



Author: jmillikin
Date: Thu Mar 26 01:33:28 2009
New Revision: 5165
URL: http://svn.gnome.org/viewvc/banshee?rev=5165&view=rev

Log:
2009-03-25  John Millikin  <jmillikin gmail com>

	* src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/LargeTrackInfoDisplay.cs:
	* src/Libraries/Hyena/Hyena/Tests/StringUtilTests.cs:
	* src/Libraries/Hyena/Hyena/StringUtil.cs:
	When splitting the "Now playing" info text into lines, only split
	if there are at least two info sections (BGO #560886).



Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/LargeTrackInfoDisplay.cs
   trunk/banshee/src/Libraries/Hyena/Hyena/StringUtil.cs
   trunk/banshee/src/Libraries/Hyena/Hyena/Tests/StringUtilTests.cs

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/LargeTrackInfoDisplay.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/LargeTrackInfoDisplay.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Widgets/LargeTrackInfoDisplay.cs	Thu Mar 26 01:33:28 2009
@@ -32,6 +32,7 @@
 using Gtk;
 using Cairo;
 
+using Hyena;
 using Hyena.Gui;
 using Banshee.Collection;
 using Banshee.Collection.Gui;
@@ -192,7 +193,11 @@
             string line = GetSecondLineText (track);
             string second_line = line, third_line = line;
             int split_pos = line.LastIndexOf ("<span");
-            if (split_pos >= 0) {
+            if (split_pos >= 0
+                // Check that there are at least 3 spans in the string, else this
+                // will break for tracks with missing artist or album info.
+                && StringUtil.SubstringCount (line, "<span") >= 3) {
+                
                 second_line = line.Substring (0, Math.Max (0, split_pos - 1)) + "</span>";
                 third_line = String.Format ("<span color=\"{0}\">{1}",
                     CairoExtensions.ColorGetHex (TextColor, false),

Modified: trunk/banshee/src/Libraries/Hyena/Hyena/StringUtil.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena/StringUtil.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena/StringUtil.cs	Thu Mar 26 01:33:28 2009
@@ -268,5 +268,23 @@
             string trimmed = input == null ? null : input.Trim ();
             return String.IsNullOrEmpty (trimmed) ? fallback : trimmed;
         }
+        
+        public static uint SubstringCount (string haystack, string needle)
+        {
+            if (String.IsNullOrEmpty (haystack) || String.IsNullOrEmpty (needle)) {
+                return 0;
+            }
+            
+            int position = 0;
+            uint count = 0;
+            while (true) {
+                int index = haystack.IndexOf (needle, position);
+                if (index < 0) {
+                    return count;
+                }
+                count++;
+                position = index + 1;
+            }
+        }
     }
 }

Modified: trunk/banshee/src/Libraries/Hyena/Hyena/Tests/StringUtilTests.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena/Tests/StringUtilTests.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena/Tests/StringUtilTests.cs	Thu Mar 26 01:33:28 2009
@@ -321,6 +321,37 @@
             AssertSortKey ("\u0104", new byte[] {14, 2, 1, 27, 1, 1, 1, 0,});
         }
     }
+    
+    [TestFixture]
+    public class SubstringCountTests
+    {
+        private void AssertCount (string haystack, string needle, uint expected)
+        {
+            Assert.AreEqual (expected, StringUtil.SubstringCount (haystack, needle));
+        }
+        
+        [Test]
+        public void TestEmpty ()
+        {
+            AssertCount ("", "a", 0);
+            AssertCount ("a", "", 0);
+        }
+        
+        [Test]
+        public void TestNoMatches ()
+        {
+            AssertCount ("a", "b", 0);
+            AssertCount ("with needle in", "long needle", 0);
+        }
+        
+        [Test]
+        public void TestMatches ()
+        {
+            AssertCount ("abbcbba", "a", 2);
+            AssertCount ("abbcbba", "b", 4);
+            AssertCount ("with needle in", "needle", 1);
+        }
+    }
 }
 
 #endif



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