banshee r4618 - in trunk/banshee: . src/Extensions/Banshee.Podcasting/Banshee.Podcasting src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data src/Libraries/Hyena.Gui/Hyena.Data.Gui src/Libraries/Hyena/Hyena src/Libraries/Hyena/Hyena/Tests src/Libraries/Migo src/Libraries/Migo/Migo.Syndication



Author: gburt
Date: Thu Sep 25 21:35:57 2008
New Revision: 4618
URL: http://svn.gnome.org/viewvc/banshee?rev=4618&view=rev

Log:
2008-09-25  Gabriel Burt  <gabriel burt gmail com>

	This patch adds a Description column to podcasts.

	* src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs:
	Fix newline removing migration (remove \r\n first then \n), and add a new
	migration to initialize the new Item.StrippedDescription property.

	* src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs:
	Add a Description column that is stripped of HTML and newlines and
	HtmlDecoded (BGO #503481).

	* src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs:
	Add a Description property, proxying the item.StrippedDescription.

	* src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackListModel.cs:
	Handle sorting by description.

	* src/Libraries/Hyena/Hyena/Tests/StringUtilTests.cs: Test the new
	RemoveHtml method.

	* src/Libraries/Hyena/Hyena/StringUtil.cs: Add RemoveHtml method, very
	simple, removes anything that looks like a tag, eg <*>.

	* src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs:
	* src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs: Move the
	clipping to the ColumnCellText itself so that all text columns get
	properly clipped (was an issue for very long descriptions).

	* src/Libraries/Migo/Migo.csproj: Reference System.Web.

	* src/Libraries/Migo/Migo.Syndication/FeedItem.cs: Add StrippedDescription
	property and UpdateStrippedDescription that handles removing the HTML and
	HtmlDecoding.

	* src/Libraries/Migo/Migo.Syndication/RssParser.cs: Call
	StringUtil.RemoveNewlines here when setting item and feed
	title/descriptions.

	* src/Libraries/Migo/Migo.Syndication/Feed.cs: The RemoveNewlines call is
	now done in RssParser.



Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs
   trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs
   trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackListModel.cs
   trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs
   trunk/banshee/src/Libraries/Hyena/Hyena/StringUtil.cs
   trunk/banshee/src/Libraries/Hyena/Hyena/Tests/StringUtilTests.cs
   trunk/banshee/src/Libraries/Migo/Migo.Syndication/Feed.cs
   trunk/banshee/src/Libraries/Migo/Migo.Syndication/FeedItem.cs
   trunk/banshee/src/Libraries/Migo/Migo.Syndication/RssParser.cs
   trunk/banshee/src/Libraries/Migo/Migo.csproj

Modified: trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs	Thu Sep 25 21:35:57 2008
@@ -121,6 +121,12 @@
                       <column modify-default=""AlbumColumn"">
                         <title>{0}</title>
                       </column>
+                      <column>
+                          <visible>true</visible>
+                          <title>{4}</title>
+                          <renderer type=""Hyena.Data.Gui.ColumnCellText"" property=""Description"" />
+                          <sort-key>Description</sort-key>
+                      </column>
                       <column modify-default=""FileSizeColumn"">
                           <visible>true</visible>
                       </column>
@@ -145,7 +151,8 @@
                       <sort-column direction=""desc"">published_date</sort-column>
                     </column-controller>
                 ",
-                Catalog.GetString ("Podcast"), Catalog.GetString ("Published"), Catalog.GetString ("New"), Catalog.GetString ("Downloaded")
+                Catalog.GetString ("Podcast"), Catalog.GetString ("Published"), Catalog.GetString ("New"),
+                Catalog.GetString ("Downloaded"), Catalog.GetString ("Description")
             ));
         }
         

Modified: trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs	Thu Sep 25 21:35:57 2008
@@ -90,6 +90,10 @@
         public DateTime PublishedDate {
             get { return Item.PubDate; }
         }
+
+        public string Description {
+            get { return Item.StrippedDescription; }
+        }
         
         public bool IsNew {
             get { return !Item.IsRead; }

Modified: trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackListModel.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackListModel.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackListModel.cs	Thu Sep 25 21:35:57 2008
@@ -101,6 +101,11 @@
                     sort_query = String.Format (@"
                         PodcastEnclosures.LocalPath IS NOT NULL {0}, PodcastItems.PubDate DESC", ascDesc);
                     break;
+
+                case "Description":
+                    sort_query = String.Format (@"
+                        PodcastItems.StrippedDescription {0}, PodcastItems.PubDate DESC", ascDesc);
+                    break;
             }
 
             return sort_query ?? Banshee.Query.BansheeQuery.GetSort (key, asc);

Modified: trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs	Thu Sep 25 21:35:57 2008
@@ -81,14 +81,6 @@
             download_manager_iface.Initialize ();    
     
             feeds_manager = new FeedsManager (ServiceManager.DbConnection, download_manager, Path.Combine (Banshee.Base.Paths.CachedLibraryLocation, "Podcasts"));
-            
-            feeds_manager.FeedManager.ItemAdded += OnItemAdded;
-            feeds_manager.FeedManager.ItemChanged += OnItemChanged;
-            feeds_manager.FeedManager.ItemRemoved += OnItemRemoved;
-            feeds_manager.FeedManager.FeedsChanged += OnFeedsChanged;
-
-            ServiceManager.PlayerEngine.ConnectEvent (OnPlayerEvent, PlayerEvent.StateChange);
-            ServiceManager.Get<DBusCommandService> ().ArgumentPushed += OnCommandLineArgument;
 
             InitializeInterface ();
         }
@@ -190,20 +182,32 @@
                 DatabaseConfigurationClient.Client.Set<int> ("Podcast", "Version", 3);
             }
 
-            if (DatabaseConfigurationClient.Client.Get<int> ("Podcast", "Version", 0) < 4) {
+            // Intentionally skpping 4 here because this needs to get run again for anybody who ran it
+            // before it was fixed, but only once if you never ran it
+            if (DatabaseConfigurationClient.Client.Get<int> ("Podcast", "Version", 0) < 5) {
                 ReplaceNewlines ("CoreTracks", "Title");
                 ReplaceNewlines ("CoreTracks", "TitleLowered");
                 ReplaceNewlines ("PodcastItems", "Title");
                 ReplaceNewlines ("PodcastItems", "Description");
-                DatabaseConfigurationClient.Client.Set<int> ("Podcast", "Version", 4);
+                DatabaseConfigurationClient.Client.Set<int> ("Podcast", "Version", 5);
+            }
+
+            // Initialize the new StrippedDescription field
+            if (DatabaseConfigurationClient.Client.Get<int> ("Podcast", "Version", 0) < 6) {
+                foreach (FeedItem item in FeedItem.Provider.FetchAll ()) {
+                    item.UpdateStrippedDescription ();
+                    item.Save ();
+                }
+                DatabaseConfigurationClient.Client.Set<int> ("Podcast", "Version", 6);
             }
         }
 
         private void ReplaceNewlines (string table, string column)
         {
             string cmd = String.Format ("UPDATE {0} SET {1}=replace({1}, ?, ?)", table, column);
-            ServiceManager.DbConnection.Execute (cmd, "\n", String.Empty);
             ServiceManager.DbConnection.Execute (cmd, "\r\n", String.Empty);
+            ServiceManager.DbConnection.Execute (cmd, "\n", String.Empty);
+            ServiceManager.DbConnection.Execute (cmd, "\r", String.Empty);
         }
         
         public void Initialize ()
@@ -214,6 +218,14 @@
         {
             // Migrate data from 0.13.2 podcast tables, if they exist
             MigrateLegacyIfNeeded ();
+
+            feeds_manager.FeedManager.ItemAdded += OnItemAdded;
+            feeds_manager.FeedManager.ItemChanged += OnItemChanged;
+            feeds_manager.FeedManager.ItemRemoved += OnItemRemoved;
+            feeds_manager.FeedManager.FeedsChanged += OnFeedsChanged;
+
+            ServiceManager.PlayerEngine.ConnectEvent (OnPlayerEvent, PlayerEvent.StateChange);
+            ServiceManager.Get<DBusCommandService> ().ArgumentPushed += OnCommandLineArgument;
             
             Banshee.Kernel.Scheduler.Schedule (new Banshee.Kernel.DelegateJob (delegate {
                 DateTime now = DateTime.Now;

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs	Thu Sep 25 21:35:57 2008
@@ -88,7 +88,9 @@
             }
             
             context.Layout.GetPixelSize (out text_width, out text_height);
-            
+
+            context.Context.Rectangle (0, 0, cellWidth, cellHeight);
+            context.Context.Clip ();
             context.Context.MoveTo (Spacing, ((int)cellHeight - text_height) / 2);
             Cairo.Color color = context.Theme.Colors.GetWidgetColor (
                 context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, state);
@@ -96,6 +98,7 @@
             context.Context.Color = color;
 
             PangoCairoHelper.ShowLayout (context.Context, context.Layout);
+            context.Context.ResetClip ();
         }
         
         protected virtual string GetText (object obj)

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnHeaderCellText.cs	Thu Sep 25 21:35:57 2008
@@ -63,10 +63,7 @@
 
             double textWidth = arrow_alloc.X - Spacing;
             if (textWidth > 0) {
-                context.Context.Rectangle (0, 0, textWidth, cellHeight);
-                context.Context.Clip ();
                 base.Render (context, state, textWidth, cellHeight);
-                context.Context.ResetClip ();
             }
 
             SortType sort_type = ((ISortableColumn)data_handler ()).SortType;

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 Sep 25 21:35:57 2008
@@ -126,6 +126,16 @@
             return null;
         }
 
+        private static Regex tags = new Regex ("<[^>]+>", RegexOptions.Compiled | RegexOptions.Multiline);
+        public static string RemoveHtml (string input)
+        {
+            if (input == null) {
+                return input;
+            }
+
+            return tags.Replace (input, String.Empty);
+        }
+
         public static string DoubleToTenthsPrecision (double num)
         {
             return DoubleToTenthsPrecision (num, false);

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 Sep 25 21:35:57 2008
@@ -123,6 +123,8 @@
         [Test]
         public void RemovesNewlines ()
         {
+            Assert.AreEqual ("", StringUtil.RemoveNewlines (""));
+            Assert.AreEqual (null, StringUtil.RemoveNewlines (null));
             Assert.AreEqual ("foobar", StringUtil.RemoveNewlines (@"foo
 bar"));
             Assert.AreEqual ("foobar baz", StringUtil.RemoveNewlines (@"foo
@@ -133,6 +135,20 @@
  newline 
 andunix"));
         }
+
+        [Test]
+        public void RemovesHtml ()
+        {
+            Assert.AreEqual ("", StringUtil.RemoveHtml (""));
+            Assert.AreEqual (null, StringUtil.RemoveHtml (null));
+            Assert.AreEqual ("foobar", StringUtil.RemoveHtml ("foobar"));
+            Assert.AreEqual ("foobar", StringUtil.RemoveHtml ("foo<baz>bar"));
+            Assert.AreEqual ("foobar", StringUtil.RemoveHtml ("foo<baz/>bar"));
+            Assert.AreEqual ("foobar", StringUtil.RemoveHtml ("foo</baz>bar"));
+            Assert.AreEqual ("foobazbar", StringUtil.RemoveHtml ("foo<a href=\"http://lkjdflkjdflkjj\";>baz</a>bar"));
+            Assert.AreEqual ("foobaz foo bar", StringUtil.RemoveHtml (@"foo<a 
+href=http://lkjdflkjdflkjj>baz foo< /a> bar"));
+        }
     }
 }
 

Modified: trunk/banshee/src/Libraries/Migo/Migo.Syndication/Feed.cs
==============================================================================
--- trunk/banshee/src/Libraries/Migo/Migo.Syndication/Feed.cs	(original)
+++ trunk/banshee/src/Libraries/Migo/Migo.Syndication/Feed.cs	Thu Sep 25 21:35:57 2008
@@ -147,13 +147,13 @@
         [DatabaseColumn]
         public string Title {
             get { return title ?? Catalog.GetString ("Unknown Podcast"); }
-            set { title = StringUtil.RemoveNewlines (value); }
+            set { title = value; }
         }
         
         [DatabaseColumn]
         public string Description { 
             get { return description; }
-            set { description = StringUtil.RemoveNewlines (value); }
+            set { description = value; }
         }
 
         [DatabaseColumn]

Modified: trunk/banshee/src/Libraries/Migo/Migo.Syndication/FeedItem.cs
==============================================================================
--- trunk/banshee/src/Libraries/Migo/Migo.Syndication/FeedItem.cs	(original)
+++ trunk/banshee/src/Libraries/Migo/Migo.Syndication/FeedItem.cs	Thu Sep 25 21:35:57 2008
@@ -66,6 +66,7 @@
         private string author;
         private string comments;
         private string description;
+        private string stripped_description;
         private FeedEnclosure enclosure;
         private string guid;
         private bool isRead;
@@ -119,7 +120,15 @@
         [DatabaseColumn]
         public string Description {
             get { return description; }
-            set { description = value; }
+            set {
+                description = value;
+            }
+        }
+
+        [DatabaseColumn]
+        public string StrippedDescription {
+            get { return stripped_description; }
+            set { stripped_description = value; }
         }
         
         [DatabaseColumn("Guid", Index = "PodcastItemsGuidIndex")]
@@ -217,6 +226,14 @@
 
 #region Public Methods
 
+        public void UpdateStrippedDescription ()
+        {
+            StrippedDescription = Hyena.StringUtil.RemoveHtml (Description);
+            if (StrippedDescription != null) {
+                StrippedDescription = System.Web.HttpUtility.HtmlDecode (StrippedDescription);
+            }
+        }
+
         public void Save ()
         {
             bool is_new = DbId < 1;

Modified: trunk/banshee/src/Libraries/Migo/Migo.Syndication/RssParser.cs
==============================================================================
--- trunk/banshee/src/Libraries/Migo/Migo.Syndication/RssParser.cs	(original)
+++ trunk/banshee/src/Libraries/Migo/Migo.Syndication/RssParser.cs	Thu Sep 25 21:35:57 2008
@@ -33,6 +33,8 @@
 using System.Text;
 using System.Collections.Generic;
 
+using Hyena;
+
 namespace Migo.Syndication
 {
     public class RssParser
@@ -89,8 +91,8 @@
         public Feed UpdateFeed (Feed feed)
         {
             try {
-                feed.Title            = GetXmlNodeText (doc, "/rss/channel/title");
-                feed.Description      = GetXmlNodeText (doc, "/rss/channel/description");
+                feed.Title            = StringUtil.RemoveNewlines (GetXmlNodeText (doc, "/rss/channel/title"));
+                feed.Description      = StringUtil.RemoveNewlines (GetXmlNodeText (doc, "/rss/channel/description"));
                 feed.Copyright        = GetXmlNodeText (doc, "/rss/channel/copyright");
                 feed.ImageUrl         = GetXmlNodeText (doc, "/rss/channel/itunes:image/@href");
                 if (String.IsNullOrEmpty (feed.ImageUrl)) {
@@ -144,8 +146,9 @@
         {
             try {
                 FeedItem item = new FeedItem ();
-                item.Description = GetXmlNodeText (node, "description");                        
-                item.Title = GetXmlNodeText (node, "title");                        
+                item.Description = StringUtil.RemoveNewlines (GetXmlNodeText (node, "description"));
+                item.UpdateStrippedDescription ();
+                item.Title = StringUtil.RemoveNewlines (GetXmlNodeText (node, "title"));
             
                 if (String.IsNullOrEmpty (item.Description) && String.IsNullOrEmpty (item.Title)) {
                     throw new FormatException ("node:  Either 'title' or 'description' node must exist.");

Modified: trunk/banshee/src/Libraries/Migo/Migo.csproj
==============================================================================
--- trunk/banshee/src/Libraries/Migo/Migo.csproj	(original)
+++ trunk/banshee/src/Libraries/Migo/Migo.csproj	Thu Sep 25 21:35:57 2008
@@ -23,6 +23,7 @@
     <Reference Include="System" />
     <Reference Include="System.Data" />
     <Reference Include="System.Xml" />
+    <Reference Include="System.Web" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Hyena\Hyena.csproj">



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