[blam] Remove references to TheApp.



commit 7eafa06a7d324164a7008ca1a0b9b20cd7e83f7a
Author: Carlos Martín Nieto <carlos cmartin tk>
Date:   Sun Oct 10 18:56:48 2010 +0100

    Remove references to TheApp.
    
    Use events and delegates instead.

 src/Application.cs       |    4 +---
 src/Channel.cs           |   27 ++++++++++++++++++++++++++-
 src/ChannelCollection.cs |   15 +++++++++++++--
 src/ChannelDialog.cs     |    3 +--
 src/ChannelGroup.cs      |    2 ++
 src/Item.cs              |    2 --
 6 files changed, 43 insertions(+), 10 deletions(-)
---
diff --git a/src/Application.cs b/src/Application.cs
index 26a00a3..f127d23 100644
--- a/src/Application.cs
+++ b/src/Application.cs
@@ -605,9 +605,7 @@ namespace Imendio.Blam {
 
         public void MarkChannelAsReadActivated (IChannel channel)
         {
-            if (channel.MarkAsRead ()) {
-                CCollection.Update (channel);
-            }
+            channel.MarkAsRead();
         }
 
         public void MarkChannelAsReadActivated (object obj, EventArgs args)
diff --git a/src/Channel.cs b/src/Channel.cs
index c277f86..619f941 100644
--- a/src/Channel.cs
+++ b/src/Channel.cs
@@ -22,6 +22,7 @@ namespace Imendio.Blam {
         Gtk.TreeIter Iter {get; set; }
         bool MarkAsRead();
         Item GetItem(string id);
+        event ChannelEventHandler Updated;
     }
 
     public class Channel : IChannel {
@@ -42,6 +43,8 @@ namespace Imendio.Blam {
         ItemStore store = null;
         ArrayList item_list = null;
 
+        public event ChannelEventHandler Updated;
+
         private Gtk.TreeIter mIter;
 
         public string Name {
@@ -105,6 +108,7 @@ namespace Imendio.Blam {
             }
             set {
                 item_list = value;
+                Setup();
             }
         }
 
@@ -136,6 +140,13 @@ namespace Imendio.Blam {
             return store.Items[id] as Item;
         }
 
+        public void Setup()
+        {
+            foreach(string id in item_list){
+                (store.Items[id] as Item).Updated += ItemUpdated;
+            }
+        }
+
 		public bool MarkAsRead ()
 		{
 			bool updated = false;
@@ -146,12 +157,20 @@ namespace Imendio.Blam {
 				if (item.Unread) {
 					item.SetUnread (false, false);
 					updated = true;
+                    EmitUpdated();
 				}
 			}
 
 			return updated;
 		}
 
+        public void EmitUpdated()
+        {
+            if(Updated != null){
+                Updated(this);
+            }
+        }
+
 		private ArrayList mUnupdatedItems;
 
 		// Sets the channel in update mode. 
@@ -180,10 +199,16 @@ namespace Imendio.Blam {
 			}
 		}
 
+        public void ItemUpdated(Item item)
+        {
+            EmitUpdated();
+        }
+
         public void Add(Item item)
         {
             store.Add(item);
             item_list.Add(item.Id);
+            item.Updated += ItemUpdated;
         }
 
         /* Used to cross-mark as read */
@@ -192,7 +217,7 @@ namespace Imendio.Blam {
             Item item = store.Items[id] as Item;
             if (item.Unread) {
                 item.Unread = false;
-                Application.TheApp.CCollection.Update (this);
+                EmitUpdated();
             }
         }
 
diff --git a/src/ChannelCollection.cs b/src/ChannelCollection.cs
index b4dede1..b1062c5 100644
--- a/src/ChannelCollection.cs
+++ b/src/ChannelCollection.cs
@@ -104,8 +104,18 @@ namespace Imendio.Blam {
 	    }
 
 	    collection.FileName = file;
+            /*
+             * FIXME: Each chan should listen to each of its items
+             */
+            foreach(ChannelGroup chan in collection.Groups){
+                chan.Updated += collection.Updated;
+            }
+            foreach(Channel chan in collection.mChannels){
+                chan.Updated += collection.Updated;
+                chan.Setup();
+            }
 
-	    return collection;
+            return collection;
 	}
 
 	private static ChannelCollection RealLoadFromFile (string file)
@@ -188,6 +198,7 @@ namespace Imendio.Blam {
 		group.Add(channel);
 		Refresh(channel);
 
+            channel.Updated += Updated;
 		if(ChannelGroupAdded != null){
 			ChannelGroupAdded(group, channel);
 		}
@@ -195,7 +206,7 @@ namespace Imendio.Blam {
 		MarkAsDirty(true);
 	}
 
-	public void Update (IChannel channel)
+	public void Updated (IChannel channel)
 	{
 	    MarkAsDirty (true);
 
diff --git a/src/ChannelDialog.cs b/src/ChannelDialog.cs
index 3a30930..55a1050 100644
--- a/src/ChannelDialog.cs
+++ b/src/ChannelDialog.cs
@@ -89,8 +89,7 @@ namespace Imendio.Blam {
 	    mChannel.Keywords = keywordEntry.Text;
 	    mChannel.http_username = usernameEntry.Text;
 	    mChannel.http_password = passwordEntry.Text;
-
-	    mApp.CCollection.Update (mChannel);
+            mChannel.EmitUpdated();
 
 	    channelDialog.Hide ();
 	}
diff --git a/src/ChannelGroup.cs b/src/ChannelGroup.cs
index 27edd8c..83a1e8c 100644
--- a/src/ChannelGroup.cs
+++ b/src/ChannelGroup.cs
@@ -18,6 +18,8 @@ namespace Imendio.Blam
         [XmlElement("Channel", typeof(Channel))] public ArrayList Channels;
         private Gtk.TreeIter mIter;
 
+        public event ChannelEventHandler Updated;
+
         public ArrayList ItemList {
             get { /* FIXME: Cache this value. */
                 ArrayList tmp = new ArrayList();
diff --git a/src/Item.cs b/src/Item.cs
index 0c26f7f..788f1da 100644
--- a/src/Item.cs
+++ b/src/Item.cs
@@ -107,8 +107,6 @@ namespace Imendio.Blam {
                 if(Updated != null){
                     Updated(this);
                 }
-                /* FIXME: Re-implement this */
-				Application.TheApp.ItemList.Update (this);
             }
         }
     }



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