[blam] Make Blam.Item inherit from SyndicationItem



commit 9262e150ea97a61f7094aeb783a0c3bcb3a83b2f
Author: Carlos Martín Nieto <carlos cmartin tk>
Date:   Tue Sep 14 20:25:27 2010 +0100

    Make Blam.Item inherit from SyndicationItem
    
    Some functionality has been lost

 src/Channel.cs           |   10 +--------
 src/ChannelCollection.cs |    4 ---
 src/Item.cs              |   51 ++++++++++-----------------------------------
 src/ItemList.cs          |    9 ++++---
 src/ItemView.cs          |   14 +++++++-----
 5 files changed, 26 insertions(+), 62 deletions(-)
---
diff --git a/src/Channel.cs b/src/Channel.cs
index 5bbc867..fa9f32d 100644
--- a/src/Channel.cs
+++ b/src/Channel.cs
@@ -128,13 +128,6 @@ namespace Imendio.Blam {
 			Url = url;
 		}
 
-		public void Setup ()
-		{
-			foreach (Item item in mItems) {
-				item.Channel = this;
-			}
-		}
-
 		public Item GetItem (string id)
 		{
 			foreach (Item item in mItems) {
@@ -188,9 +181,8 @@ namespace Imendio.Blam {
             Item item = GetItem(id);
 
             if(item == null){
-                item = new Item(id, SyndItem);
+                item = new Item(SyndItem);
 
-                item.Channel = this;
                 item.Unread = !Application.TheApp.CCollection.CheckItemIdReadInAllChannels(id);
                 mItems.Add(item);
 
diff --git a/src/ChannelCollection.cs b/src/ChannelCollection.cs
index f5ff5c5..07fee0c 100644
--- a/src/ChannelCollection.cs
+++ b/src/ChannelCollection.cs
@@ -126,10 +126,6 @@ namespace Imendio.Blam {
                 collection.mChannels = new ArrayList ();
             }
 
-            foreach (Channel channel in collection.Channels) {
-		channel.Setup ();
-	    }
-
 	    return collection;
 	}
 	
diff --git a/src/Item.cs b/src/Item.cs
index ca61200..11b7e0f 100644
--- a/src/Item.cs
+++ b/src/Item.cs
@@ -9,21 +9,14 @@ using System;
 using System.ServiceModel.Syndication;
 
 namespace Imendio.Blam {
-	public class Item {
-		[XmlAttribute] public string   Id = "";
+	public class Item : SyndicationItem {
 		[XmlAttribute] public bool     Unread = true;
 		[XmlAttribute] public bool     Old = false;
 		[XmlAttribute] public bool     Permanent = false;
 
-		[XmlAttribute] public string   Title = "";
-		[XmlAttribute] public string   Text = "";
-		[XmlAttribute] public string   Link = "";
-		[XmlAttribute] public DateTime PubDate;
-		[XmlAttribute] public string   Author = "";
-
 		[XmlAttribute] public string   keywords = "";
 
-		[XmlIgnore]    public Channel  Channel;
+        public SyndicationContent exposed_text;
 
 		public string Keywords {
 			get {
@@ -44,48 +37,27 @@ namespace Imendio.Blam {
 		{
 		}
 
-        public Item(string id, SyndicationItem item)
+        public Item(SyndicationItem item) : base(item)
         {
-            this.Id = id;
-            if(item.Title.Text != null){
-                this.Title = HtmlUtils.StripHtml(item.Title.Text.Trim());
-            }
-
             if(item.Summary != null && item.Summary.Text != ""){
-                this.Text = item.Summary.Text.Trim();
+                this.exposed_text = item.Summary;
             }
 
             if(item.Content != null){
-                this.Text = (item.Content as TextSyndicationContent).Text;
+                this.exposed_text = item.Content;
             }
 
             /* Get <content:encoded> elements, overwriting <content> */
-            foreach(SyndicationElementExtension ext in item.ElementExtensions){
+            foreach(SyndicationElementExtension ext in this.ElementExtensions){
                 if(ext.OuterName == "encoded"){
-                    this.Text = ext.GetObject<string>();
+                    this.exposed_text = ext.GetObject<SyndicationContent>();
                 }
             }
-
-            /* FIXME: Actually search for the "self" link */
-            if(item.Links[0].Uri.ToString() != ""){
-                this.Link = item.Links[0].Uri.ToString();
-            }
-
-            if(item.Authors.Count >= 1 && item.Authors[0] != null){
-                this.Author = item.Authors[0].Name;
-            }
-
-            this.PubDate = item.PublishDate.LocalDateTime;
         }
 
         public bool Update(SyndicationItem SyndItem)
         {
-            if(this.Title != HtmlUtils.StripHtml(SyndItem.Title.Text.Trim())){
-                this.Title = HtmlUtils.StripHtml(SyndItem.Title.Text.Trim());
-                this.SetUnread(true, true);
-                return true;
-            }
-            //TODO: Same as above with the content, and possibly add a changed state
+            //TODO: Implement item updating
             return true;
         }
 
@@ -93,12 +65,13 @@ namespace Imendio.Blam {
 		{
 			if (Unread != unread) {
 				Unread = unread;
-				Application.TheApp.CCollection.Update (this.Channel);
+                /* FIXME: Re-implement this */
+				//Application.TheApp.CCollection.Update (this.Channel);
 				Application.TheApp.ItemList.Update (this);
 
 				if (unread != true && inAllChannels) {
-					Application.TheApp.CCollection.MarkItemIdAsReadInAllChannels (this.Channel,
-																				  this.Id);
+					//Application.TheApp.CCollection.MarkItemIdAsReadInAllChannels (this.Channel,
+					//															  this.Id);
 				}
 			}
 		}
diff --git a/src/ItemList.cs b/src/ItemList.cs
index da4763c..2920669 100644
--- a/src/ItemList.cs
+++ b/src/ItemList.cs
@@ -12,6 +12,7 @@ using GLib;
 using GtkSharp;
 using System;
 using System.Collections;
+using System.ServiceModel.Syndication;
 
 namespace Imendio.Blam {
     
@@ -75,10 +76,10 @@ namespace Imendio.Blam {
 	}
 	
 	public void ItemAdded (Imendio.Blam.Item item)
-	{
+	{/*
 	    if (channel != null && channel == item.Channel) {
 		((ListStore)this.Model).AppendValues(item);
-	    }
+	    }*/
 	}
 
 	public bool NextUnread()
@@ -243,7 +244,7 @@ namespace Imendio.Blam {
         Item ia = Model.GetValue(a, 0) as Item;
         Item ib = Model.GetValue(b, 0) as Item;
 
-        return ia.PubDate.CompareTo(ib.PubDate);
+        return ia.PublishDate.CompareTo(ib.PublishDate);
     }
 
 	protected override bool OnKeyPressEvent (EventKey kEvent)
@@ -273,7 +274,7 @@ namespace Imendio.Blam {
 		weight = (int) Pango.Weight.Bold;
 	    }
 
-        ((CellRendererText)cell).Text = item.Title;
+        ((CellRendererText)cell).Text = (item.Title as TextSyndicationContent).Text.Trim();
         ((CellRendererText)cell).Weight = weight;
         ((CellRendererText)cell).Ellipsize = Pango.EllipsizeMode.End;
 	}
diff --git a/src/ItemView.cs b/src/ItemView.cs
index 3daf450..b288556 100644
--- a/src/ItemView.cs
+++ b/src/ItemView.cs
@@ -17,6 +17,7 @@ using System.Reflection;
 using System.IO;
 using System.Net;
 using System.Text;
+using System.ServiceModel.Syndication;
 
 namespace Imendio.Blam {
     public class ItemView : Gtk.EventBox {
@@ -96,13 +97,14 @@ namespace Imendio.Blam {
         {
 			Theme theme = Application.TheApp.ThemeManager.CurrentTheme;
 
-            string author  = (!"".Equals(currentItem.Author)) ? String.Format(Catalog.GetString("by {0}"), currentItem.Author) : "&nbsp;";
+            string author  = (!currentItem.Authors[0].Name.Equals(string.Empty)) ?
+                String.Format(Catalog.GetString("by {0}"), currentItem.Authors[0].Name) : "&nbsp;";
             string link    = Catalog.GetString("Show in browser");
-            string pubdate = (!currentItem.PubDate.Equals(DateTime.MinValue)) ?
-                currentItem.PubDate.ToString("D", System.Globalization.CultureInfo.CurrentUICulture) : "&nbsp;";
-            string text    = HtmlUtils.EncodeUnicode(HtmlUtils.FixMarkup(currentItem.Text));
-            string title   = HtmlUtils.Escape(currentItem.Title);
-            string url     = currentItem.Link;
+            string pubdate = (!currentItem.PublishDate.Equals(DateTime.MinValue)) ?
+                currentItem.PublishDate.ToString("D", System.Globalization.CultureInfo.CurrentUICulture) : "&nbsp;";
+            string text    = HtmlUtils.EncodeUnicode(HtmlUtils.FixMarkup((currentItem.exposed_text as TextSyndicationContent).Text));
+            string title   = HtmlUtils.Escape(currentItem.Title.Text);
+            string url     = currentItem.Links[0].Uri.ToString();
             baseDir        = "file://" + theme.Path;
 
             string[] replaces = {



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