[blam] Use ItemStore as central storage for entries



commit ab727412861a7ad9e31da1d520234601f57e4055
Author: Carlos Martín Nieto <carlos cmartin tk>
Date:   Thu Sep 16 19:24:22 2010 +0100

    Use ItemStore as central storage for entries

 src/Channel.cs      |   76 +++++++++++++++++++++++++++------------------------
 src/ChannelGroup.cs |   12 +++-----
 src/ChannelList.cs  |    5 ++-
 src/ItemList.cs     |    9 +++---
 src/ItemStore.cs    |    7 ++++-
 5 files changed, 57 insertions(+), 52 deletions(-)
---
diff --git a/src/Channel.cs b/src/Channel.cs
index 1202856..8e0df22 100644
--- a/src/Channel.cs
+++ b/src/Channel.cs
@@ -18,7 +18,7 @@ namespace Imendio.Blam {
         int NrOfUnreadItems {get; }
         string Name {get; set; }
         string Url {get; set; }
-        Hashtable Items {get; set; }
+        ArrayList ItemList {get; set; }
         Gtk.TreeIter Iter {get; set; }
         bool MarkAsRead();
         Item GetItem(string id);
@@ -40,6 +40,7 @@ namespace Imendio.Blam {
 		[XmlAttribute] public string http_password = "";
 
         ItemStore store = null;
+        ArrayList item_list = null;
 
         private Gtk.TreeIter mIter;
 
@@ -63,7 +64,7 @@ namespace Imendio.Blam {
 
 		public int NrOfItems {
 			get {
-				return mItems.Count;
+				return item_list.Count;
 			}
 		}
 
@@ -71,8 +72,8 @@ namespace Imendio.Blam {
 			get {
 				int unread = 0;
 
-				foreach (Item item in mItems) {
-					if (item.Unread == true) {
+				foreach (string id in item_list) {
+					if ((store.Items[id] as Item).Unread == true) {
 						unread++;
 					}
 				}
@@ -84,8 +85,9 @@ namespace Imendio.Blam {
         public int NrOfNewItems {
             get {
                 int new_items = 0;
-
-                foreach(Item item in mItems){
+                Item item;
+                foreach(string id in item_list){
+                    item = store.Items[id] as Item;
                     if(item.Unread && !item.Old){
                         ++new_items;
                     }
@@ -95,16 +97,14 @@ namespace Imendio.Blam {
             }
         }
 
-		Hashtable mItems;
-        [XmlIgnore]
-		public Hashtable Items {
-			get {
-				return mItems;
-			}
-			set {
-				mItems = value;
-			}
-		}
+        public ArrayList ItemList {
+            get {
+                return item_list;
+            }
+            set {
+                item_list = value;
+            }
+        }
 
 		[XmlIgnore]
         public Gtk.TreeIter Iter {
@@ -118,14 +118,14 @@ namespace Imendio.Blam {
 
         public Channel ()
         {
-            mItems = new Hashtable ();
+            item_list = new ArrayList();
             mIter = new Gtk.TreeIter();
             store = ItemStore.GetInstance();
         }
 
         public Channel (string name, string url)
         {
-            mItems = new Hashtable ();
+            item_list = new ArrayList();
             mIter = new Gtk.TreeIter();
             store = ItemStore.GetInstance();
             Name = name;
@@ -134,14 +134,16 @@ namespace Imendio.Blam {
 
         public Item GetItem (string id)
         {
-            return mItems[id] as Item;
+            return store.Items[id] as Item;
         }
 
 		public bool MarkAsRead ()
 		{
 			bool updated = false;
+            Item item;
 
-			foreach (Item item in mItems) {
+			foreach(string id in item_list){
+                item = store.Items[id] as Item;
 				if (item.Unread) {
 					item.SetUnread (false, false);
 					updated = true;
@@ -157,7 +159,11 @@ namespace Imendio.Blam {
 		public void StartRefresh ()
 		{
 			this.LastRefreshed = DateTime.Now;
-			mUnupdatedItems = (ArrayList) mItems.Clone ();
+            ArrayList tmp = new ArrayList();
+            foreach(string id in item_list){
+                tmp.Add(store.Items[id]);
+            }
+			mUnupdatedItems = tmp;
 		}
 
 		// Removes any items not being part of the RSS feed any more
@@ -170,28 +176,26 @@ namespace Imendio.Blam {
 					continue;
 				}
 
-				mItems.Remove (item);
+                item_list.Remove(item.Id);
+                store.Remove(item);
 			}
 		}
 
         public void Add(Item item)
         {
-            Items.Add(item.Id, item);
+            store.Add(item);
+            item_list.Add(item.Id);
         }
 
-		/* Used to cross-mark as read */
-		public void MarkItemIdAsRead (string id)
-		{
-			foreach (Item item in mItems) {
-				if (item.Id.Equals (id)) {
-					if (item.Unread) {
-						item.Unread = false;
-						Application.TheApp.CCollection.Update (this);
-					}
-					break;
-				}
-			}
-		}
+        /* Used to cross-mark as read */
+        public void MarkItemIdAsRead (string id)
+        {
+            Item item = store.Items[id] as Item;
+            if (item.Unread) {
+                item.Unread = false;
+                Application.TheApp.CCollection.Update (this);
+            }
+        }
 
 		public bool GetHasKeyword (string keyword)
 		{
diff --git a/src/ChannelGroup.cs b/src/ChannelGroup.cs
index 78f88ac..27edd8c 100644
--- a/src/ChannelGroup.cs
+++ b/src/ChannelGroup.cs
@@ -16,21 +16,17 @@ namespace Imendio.Blam
         [XmlAttribute("Name")] public string Int_Name = null;
         [XmlAttribute("Url")] public string Int_Url = null;
         [XmlElement("Channel", typeof(Channel))] public ArrayList Channels;
-        private Hashtable dummy;
         private Gtk.TreeIter mIter;
 
-        public Hashtable Items {
+        public ArrayList ItemList {
             get { /* FIXME: Cache this value. */
-                Hashtable tmp = new Hashtable();
+                ArrayList tmp = new ArrayList();
                 foreach(Channel chan in Channels){
-                    foreach(DictionaryEntry de in chan.Items)
-                    tmp.Add(de.Key, de.Value);
+                    tmp.AddRange(chan.ItemList);
                 }
                 return tmp;
             }
-            set {
-                dummy = value;
-            }
+            set {}
         }
         
         public int NrOfUnreadItems {
diff --git a/src/ChannelList.cs b/src/ChannelList.cs
index b9c516e..1a0da9e 100644
--- a/src/ChannelList.cs
+++ b/src/ChannelList.cs
@@ -420,11 +420,12 @@ namespace Imendio.Blam {
 
         private void EmitChannelSelected(IChannel channel)
         {
-            if(LastChannel != null){
+            /* FIXME: Add a function to IChannel to do this */
+            /*if(LastChannel != null){
                 foreach(Item item in LastChannel.Items){
                     item.Old = true;
                 }
-            }
+            }*/
 
             LastChannel = channel;
 
diff --git a/src/ItemList.cs b/src/ItemList.cs
index 2920669..f1ff6e7 100644
--- a/src/ItemList.cs
+++ b/src/ItemList.cs
@@ -169,14 +169,13 @@ namespace Imendio.Blam {
 	public void UpdateList ()
 	{
 	    ((ListStore)this.Model).Clear();
-
+            ItemStore store = ItemStore.GetInstance();
 	    if (this.channel == null) {
 		return;
 	    }
-
-	    foreach (Imendio.Blam.Item item in this.channel.Items) {
-		((ListStore)this.Model).AppendValues (item);
-	    }
+            foreach(string id in channel.ItemList){
+                (Model as ListStore).AppendValues(store.Items[id]);
+            }
 
 	    GLib.Timeout.Add (100, new GLib.TimeoutHandler (IdleScrollCb));
 	}
diff --git a/src/ItemStore.cs b/src/ItemStore.cs
index 4825ac5..65074d2 100644
--- a/src/ItemStore.cs
+++ b/src/ItemStore.cs
@@ -21,11 +21,16 @@ namespace Imendio.Blam
             }
         }
 
-        void Add(SyndicationItem item)
+        public void Add(Item item)
         {
             items.Add(item.Id, item);
         }
 
+        public void Remove(Item item)
+        {
+            items.Remove(item.Id);
+        }
+
         public static ItemStore GetInstance()
         {
             if(instance == null){



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