Clean up LibraryTrackRemovedArgs.

This patch changes the definition of LibraryTrackRemovedArgs from
    { LibraryTrackInfo Track, ICollection Tracks }
to
    { ICollection<LibraryTrackInfo> Tracks }

This causes a couple of things:

The first goal was to simplify all methods handling LibraryTrackRemovedArgs.
Now they only have to handle the single Tracks attribute. This removes a lot of
duplicated code. Each method handling the TrackRemoved signal basically had to
implement itself twice, this has now been reduced to once.

While working on this, I changed Tracks to be a generic class of
LibraryTrackInfo objects. This improves type safety, with the current code, it
was possible to have both LibraryTrackInfo objects and SafeUri objects in the
Tracks attribute. Luckily, the possibility to use SafeUris isn't used anywhere,
as no code implements functionality to handle this.

 Core/Banshee.Base/Banshee.SmartPlaylist/SmartPlaylistSource.cs |   10 -
 Core/Banshee.Base/Library.cs                                   |   42 +----
 Core/Banshee.Base/Sources/LibrarySource.cs                     |    4 
 Core/Banshee.Base/Sources/PlaylistSource.cs                    |   16 --
 Plugins/Banshee.Plugins.Podcast/PodcastLibrary.cs              |   78 ++--------
 5 files changed, 39 insertions(+), 111 deletions(-)

Index: src/Plugins/Banshee.Plugins.Podcast/PodcastLibrary.cs
===================================================================
--- src/Plugins/Banshee.Plugins.Podcast/PodcastLibrary.cs	(revision 2083)
+++ src/Plugins/Banshee.Plugins.Podcast/PodcastLibrary.cs	(working copy)
@@ -800,71 +800,39 @@
 
         private void OnLibraryTrackRemoved (object sender, LibraryTrackRemovedArgs args)
         {
-            if (args.Track != null)
-            {
-                PodcastInfo pi = null;
-                TrackInfo ti = args.Track;
-               
-                if (BadTrackHash (ti))
-                {
-                    return;
-                }
+            ArrayList podcast_remove_list = new ArrayList ();
 
-                lock (TrackSync)
-                {
-                    if (tracks_keyed.ContainsKey (ti))
-                    {
-                        pi = tracks_keyed [ti] as PodcastInfo;
-                    }
-                    else
-                    {
-                        return;
-                    }
-                }
-
-                if (pi != null)
-                {
-                    Console.WriteLine (pi);
-                    RemovePodcast (pi);
-                }
-
-            }
-            else if (args.Tracks != null)
+            lock (TrackSync)
             {
-                ArrayList podcast_remove_list = new ArrayList ();
+                PodcastInfo tmpPi;
 
-                lock (TrackSync)
+                foreach (TrackInfo ti in args.Tracks)
                 {
-                    PodcastInfo tmpPi;
-
-                    foreach (TrackInfo ti in args.Tracks)
+                    if (ti != null)
                     {
-                        if (ti != null)
+                        tmpPi = null;                            
+                        
+                        if (BadTrackHash (ti))
                         {
-							tmpPi = null;                            
-                            
-                            if (BadTrackHash (ti))
-                            {
-                                continue;
-                            }
-															
-							if (tracks_keyed.ContainsKey (ti)) {
-                                tmpPi = tracks_keyed [ti] as PodcastInfo;
-                            }
-                            
-                            if (tmpPi != null)
-                            {
-                                podcast_remove_list.Add (tmpPi);
-                            }
+                            continue;
                         }
+                                                        
+                        if (tracks_keyed.ContainsKey (ti)) {
+                            tmpPi = tracks_keyed [ti] as PodcastInfo;
+                        }
+                        
+                        if (tmpPi != null)
+                        {
+                            podcast_remove_list.Add (tmpPi);
+                        }
                     }
                 }
+            }
 
-                if (podcast_remove_list.Count > 0)
-                {
-                    RemovePodcasts (podcast_remove_list);
-                    UpdateParentFeeds (podcast_remove_list);
-                }
+            if (podcast_remove_list.Count > 0)
+            {
+                RemovePodcasts (podcast_remove_list);
+                UpdateParentFeeds (podcast_remove_list);
             }
         }
 
Index: src/Core/Banshee.Base/Sources/PlaylistSource.cs
===================================================================
--- src/Core/Banshee.Base/Sources/PlaylistSource.cs	(revision 2083)
+++ src/Core/Banshee.Base/Sources/PlaylistSource.cs	(working copy)
@@ -326,22 +326,6 @@
         
         private void OnLibraryTrackRemoved(object o, LibraryTrackRemovedArgs args)
         {
-            if(args.Track != null) {
-                if(tracks.Contains(args.Track)) {
-                    RemoveTrack(args.Track);
-                    
-                    if(Count == 0) {
-                        Unmap();
-                    } else {
-                        Commit();
-                    }
-                }
-                
-                return;
-            } else if(args.Tracks == null) {
-                return;
-            }
-            
             int removed_count = 0;
             
             lock(TracksMutex) {
Index: src/Core/Banshee.Base/Sources/LibrarySource.cs
===================================================================
--- src/Core/Banshee.Base/Sources/LibrarySource.cs	(revision 2083)
+++ src/Core/Banshee.Base/Sources/LibrarySource.cs	(working copy)
@@ -52,7 +52,9 @@
         private LibrarySource() : base(Catalog.GetString("Music Library"), 0)
         {
             Globals.Library.TrackRemoved += delegate(object o, LibraryTrackRemovedArgs args) {
-                OnTrackRemoved(args.Track);
+                foreach(TrackInfo track in args.Tracks) {
+                    OnTrackRemoved(track);
+                }
                 OnUpdated();
             };
               
Index: src/Core/Banshee.Base/Library.cs
===================================================================
--- src/Core/Banshee.Base/Library.cs	(revision 2083)
+++ src/Core/Banshee.Base/Library.cs	(working copy)
@@ -48,8 +48,7 @@
     
     public class LibraryTrackRemovedArgs : EventArgs
     {
-        public LibraryTrackInfo Track;
-        public ICollection Tracks;
+        public ICollection<LibraryTrackInfo> Tracks;
     }
 
     public class Library
@@ -221,40 +220,19 @@
             if(track == null) {
                 return;
             }
-            
-            CollectionRemove(track);
-            
-            Db.Execute(new DbCommand(
-                @"DELETE FROM Tracks
-                    WHERE TrackID = :track_id",
-                    "track_id", track.TrackId
-            ));
-                        
-            LibraryTrackRemovedHandler removed_handler = TrackRemoved;
-            if(removed_handler != null) {
-                LibraryTrackRemovedArgs args = new LibraryTrackRemovedArgs();
-                args.Track = track;
-                ThreadAssist.ProxyToMain(delegate {
-                    removed_handler(this, args);
-                });
-            }
+
+            List<LibraryTrackInfo> tracks = new List<LibraryTrackInfo>();
+            tracks.Add(track);
+            Remove(tracks);
         }
         
-        public void Remove(ICollection tracks)
+        public void Remove(ICollection<LibraryTrackInfo> tracks)
         {
             string query = "DELETE FROM Tracks WHERE ";
             int remove_count = 0;
             int invalid_count = 0;
             
-            foreach(object o in tracks) {
-                LibraryTrackInfo track = null;
-                
-                if(o is SafeUri) {
-                    track = TracksFnKeyed[MakeFilenameKey(o as SafeUri)] as LibraryTrackInfo;
-                } else if(o is LibraryTrackInfo) {
-                    track = o as LibraryTrackInfo;
-                } 
-                
+            foreach(LibraryTrackInfo track in tracks) {
                 if(track == null) {
                     invalid_count++;
                     continue;
@@ -283,16 +261,16 @@
             }
         }
         
-        private ArrayList remove_queue = new ArrayList();
+        private List<LibraryTrackInfo> remove_queue = new List<LibraryTrackInfo>();
         
         public void QueueRemove(TrackInfo track)
         {
-            remove_queue.Add(track);
+            remove_queue.Add(track as LibraryTrackInfo);
         }
         
         public void QueueRemove(SafeUri trackSafeUri)
         {
-            remove_queue.Add(trackSafeUri);
+            remove_queue.Add(TracksFnKeyed[MakeFilenameKey(trackSafeUri)] as LibraryTrackInfo);
         }
         
         public void CommitRemoveQueue()
Index: src/Core/Banshee.Base/Banshee.SmartPlaylist/SmartPlaylistSource.cs
===================================================================
--- src/Core/Banshee.Base/Banshee.SmartPlaylist/SmartPlaylistSource.cs	(revision 2083)
+++ src/Core/Banshee.Base/Banshee.SmartPlaylist/SmartPlaylistSource.cs	(working copy)
@@ -509,13 +509,9 @@
         private void OnLibraryTrackRemoved(object o, LibraryTrackRemovedArgs args)
         {
             lock(this) {
-                if (args.Track != null && tracks.Contains(args.Track))
-                    remove_queue.Add(args.Track);
-
-                if (args.Tracks != null)
-                    foreach(TrackInfo track in args.Tracks)
-                        if (track != null && tracks.Contains(track))
-                            remove_queue.Add(track);
+                foreach(TrackInfo track in args.Tracks)
+                    if (track != null && tracks.Contains(track))
+                        remove_queue.Add(track);
             
                 if(remove_queue.Count > 0 && remove_queue_timeout == 0) {
                     remove_queue_timeout = GLib.Timeout.Add(500, FlushRemoveQueue);
