Re: [Muine] [PATCH] incomplete albums



On Mon, 2005-01-10 at 00:00 +0100, Jorn Baayen wrote:
> You convinced me. Base your new patch on 0.8 though, probably much more
> up to date than cvs. My brain is so foggy after a few days of Very
> intensive hacking. Just a few more comments on your patch.. you probably
> dont want to make a call to gconf to get the dirs for every new album,
> better cache it, and hook up to a gconf NotifyEvent.

Attached.

> Also, making properties for FakeLength and MinQueryLength seems
> overkill. Just two "protected int" fake_length and min_query_length
> should do.

This is unavoidable I think, AFAIK it is not possible to override
fields. (you can't make them either virtual or abstract and new is not
sufficient, as the field must be accessed from the base class).

I didn't remove the code in Song.cs for attaching covers to songs -- I
wasn't sure if you wanted to use that for anything else (let me know if
not and you want me to make a new patch).

Anyway, thanks for all the hard work, muine seems to be coming along in
leaps and bounds, and the codebase is looking cleaner by the day.

Cheers, 
Tom

> Off to get some rest.
> 
> Jorn
> 
> On Mon, 2005-01-10 at 09:38 +1100, Tom Coleman wrote:
> > > Moving Search to AddWindow doesn't seem like a good idea to me, as now
> > > with the PotentialItems stuff the list of Albums/Songs will be iterated
> > > twice for every search. 
> > 
> > True, although I think this is more a deficiency in my implementation
> > than a deficiency in the design.. now I think about it, I should have
> > added something like a IsRelevantItem method that would return say
> > album.FitsCriteria (SearchBits) && album.Complete in AddAlbumWindow's
> > case, and then I could have called that from search, thus removing the
> > need for two iterations over the list. Also that way there would be no
> > need for the OnAlbum* (or OnSong*) handlers inside the two either. I can
> > code up the changes easily enough and send them to you if you are
> > interested 
> > 
> > > Also, the search limiting stuff is really only
> > > relevant for the AddSongWindow.
> > 
> > Also true, but I figured having the option of doing the same thing for
> > AddAlbumWindow was probably sensible.
> > 
> > Cheers,
> > Tom
> > 
> > _______________________________________________
> > muine-list mailing list
> > muine-list gnome org
> > http://mail.gnome.org/mailman/listinfo/muine-list
> 
diff -aur muine-0.8.0/src/AddAlbumWindow.cs muine-0.8.0-hacking/src/AddAlbumWindow.cs
--- muine-0.8.0/src/AddAlbumWindow.cs	2005-01-09 23:59:20.000000000 +1100
+++ muine-0.8.0-hacking/src/AddAlbumWindow.cs	2005-01-13 06:22:12.000000000 +1100
@@ -73,15 +73,35 @@
 
 			Global.CoverDB.DoneLoading += new CoverDatabase.DoneLoadingHandler (OnCoversDoneLoading);
 
-			lock (Global.DB) {
-				foreach (Album a in Global.DB.Albums.Values) 
-					base.List.Append (a.Handle);
-			}
+                        Search ();
 
 			if (!Global.CoverDB.Loading)
 				EnableDragDest ();
 		}
 
+                // Properties
+                protected override ICollection PotentialItems {
+                        get { return Global.DB.Albums.Values; }
+                }
+
+		private const int fake_length = 0;
+                protected override int FakeLength {
+                        get { return fake_length; }
+                }
+		private const int min_query_length = -1;
+                protected override int MinQueryLength {
+                        get { return min_query_length; }
+                }
+
+                // Protected Methods
+                protected override bool IsMatch (Item item) 
+                {
+                        Album album = (Album) item;
+                        return album.FitsCriteria (base.Entry.SearchBits) && album.Complete;
+                }
+                        
+
+                // Private Methods
 		private int SortFunc (IntPtr a_ptr,
 				      IntPtr b_ptr)
 		{
@@ -124,43 +144,15 @@
 						   false, true, false);
 		}
 
-		protected override bool Search ()
-		{
-			List l = new List (IntPtr.Zero, typeof (int));
-
-			lock (Global.DB) {
-				if (base.Entry.Text.Length > 0) {
-					foreach (Album a in Global.DB.Albums.Values) {
-						if (a.FitsCriteria (base.Entry.SearchBits))
-							l.Append (a.Handle);
-					}
-				} else {
-					foreach (Album a in Global.DB.Albums.Values)
-						l.Append (a.Handle);
-				}
-			}
-
-			base.List.RemoveDelta (l);
-
-			foreach (int i in l) {
-				IntPtr ptr = new IntPtr (i);
-
-				base.List.Append (ptr);
-			}
-
-			base.List.SelectFirst ();
-
-			return false;
-		}
-		
+                // is there some way we can generalise these?
 		private void OnAlbumAdded (Album album)
 		{
-			base.List.HandleAdded (album.Handle, album.FitsCriteria (base.Entry.SearchBits));
+			base.List.HandleAdded (album.Handle, IsMatch (album));
 		}
 
 		private void OnAlbumChanged (Album album)
 		{
-			base.List.HandleChanged (album.Handle, album.FitsCriteria (base.Entry.SearchBits));
+			base.List.HandleChanged (album.Handle, IsMatch (album));
 		}
 
 		private void OnAlbumRemoved (Album album)
diff -aur muine-0.8.0/src/AddSongWindow.cs muine-0.8.0-hacking/src/AddSongWindow.cs
--- muine-0.8.0/src/AddSongWindow.cs	2005-01-09 23:58:48.000000000 +1100
+++ muine-0.8.0-hacking/src/AddSongWindow.cs	2005-01-13 06:22:20.000000000 +1100
@@ -30,9 +30,6 @@
 	public class AddSongWindow : AddWindow
 	{
 		// Constants
-		private const int FakeLength = 150;
-		private const int MinQueryLength = 3;
-
 	        private const string GConfKeyWidth = "/apps/muine/add_song_window/width";
 	        private const int GConfDefaultWidth = 500;
 	        
@@ -67,19 +64,30 @@
 			Global.DB.SongChanged += new SongDatabase.SongChangedHandler (OnSongChanged);
 			Global.DB.SongRemoved += new SongDatabase.SongRemovedHandler (OnSongRemoved);
 
-			lock (Global.DB) {
-				int i = 0;
-
-				foreach (Song s in Global.DB.Songs.Values) {
-					base.List.Append (s.Handle);
-
-					i++;
-					if (i >= FakeLength)
-						break;
-				}
-			}
+                        Search ();
 		}
+                
+                // Properties
+                protected override ICollection PotentialItems {
+                        get { return Global.DB.Songs.Values; }
+                }
+
+		private const int fake_length = 150;
+                protected override int FakeLength {
+                        get { return fake_length; }
+                }
+		private const int min_query_length = 3;
+                protected override int MinQueryLength {
+                        get { return min_query_length; }
+                }
+
+                // Protected Methods
+		protected override bool IsMatch (Item item)
+                {
+                        return item.FitsCriteria (base.Entry.SearchBits);
+                }
 
+                // Private Methods
 		private int SortFunc (IntPtr a_ptr,
 				      IntPtr b_ptr)
 		{
@@ -102,60 +110,15 @@
 						   false, true, false);
 		}
 
-		protected override bool Search ()
-		{
-			List l = new List (IntPtr.Zero, typeof (int));
-
-			int max_len = -1;
-
-			/* show max. FakeLength songs if < MinQueryLength chars are entered. this is to fake speed. */
-			if (base.Entry.Text.Length < MinQueryLength)
-				max_len = FakeLength;
-
-			lock (Global.DB) {
-				int i = 0;
-				if (base.Entry.Text.Length > 0) {
-					foreach (Song s in Global.DB.Songs.Values) {
-						if (!s.FitsCriteria (base.Entry.SearchBits))
-							continue;
-
-						l.Append (s.Handle);
-					
-						i++;
-						if (max_len > 0 && i >= max_len)
-							break;
-					}
-				} else {
-					foreach (Song s in Global.DB.Songs.Values) {
-						l.Append (s.Handle);
-					
-						i++;
-						if (max_len > 0 && i >= max_len)
-							break;
-					}
-				}
-			}
-
-			base.List.RemoveDelta (l);
-
-			foreach (int p in l) {
-				IntPtr ptr = new IntPtr (p);
-
-				base.List.Append (ptr);
-			}
-
-			base.List.SelectFirst ();
-
-			return false;
-		}
-
 		private void OnSongAdded (Song song)
 		{
+                        // is this really necessary?
+                        // if so it should be in AddWindow somehow
 			if (base.Entry.Text.Length < MinQueryLength &&
 			    base.List.Length >= FakeLength)
 				return;
 
-			base.List.HandleAdded (song.Handle, song.FitsCriteria (base.Entry.SearchBits));
+			base.List.HandleAdded (song.Handle, IsMatch (song));
 		}
 
 		private void OnSongChanged (Song song)
@@ -163,7 +126,7 @@
 			bool may_append = (base.Entry.Text.Length >= MinQueryLength ||
 			                   base.List.Length < FakeLength);
 			
-			base.List.HandleChanged (song.Handle, song.FitsCriteria (base.Entry.SearchBits),
+			base.List.HandleChanged (song.Handle, IsMatch (song),
 				may_append);
 		}
 
diff -aur muine-0.8.0/src/AddWindow.cs muine-0.8.0-hacking/src/AddWindow.cs
--- muine-0.8.0/src/AddWindow.cs	2005-01-10 02:11:31.000000000 +1100
+++ muine-0.8.0-hacking/src/AddWindow.cs	2005-01-12 02:10:26.000000000 +1100
@@ -19,7 +19,10 @@
  */
 
 using System;
+using System.Collections;
+
 using Gtk;
+using GLib;
 
 namespace Muine
 {
@@ -83,6 +86,8 @@
 
 			entry.Show ();
 			list.Show ();
+
+                       
 		}
 
 		// Properties
@@ -97,9 +102,21 @@
 		public CellRenderer TextRenderer {
 			get { return text_renderer; }
 		}
-		
-		// Abstract methods
-		protected abstract bool Search ();
+
+                // Abstract Properties
+                protected abstract ICollection PotentialItems {
+                        get;
+                }
+
+		protected abstract int FakeLength {
+                        get;
+                }
+		protected abstract int MinQueryLength {
+                        get;
+                }
+
+                // Abstract Methods
+                protected abstract bool IsMatch (Item item);
 
 		// Public Methods
 		public void Run ()
@@ -110,7 +127,7 @@
 
 			window.Present ();
 		}
-			
+
 		// Protected Methods
 		protected void SetGConfSize (string key_width, string key_height, 
 					     int default_width, int default_height)
@@ -143,6 +160,44 @@
 
 			process_changes_immediately = false;
 		}
+
+                protected bool Search ()
+                {
+			List l = new List (IntPtr.Zero, typeof (int));
+
+			int max_len = -1;
+
+			/* show max. FakeLength songs if < MinQueryLength chars are entered. this is to fake speed. */
+			if (entry.Text.Length < MinQueryLength)
+				max_len = FakeLength;
+
+			int i = 0;
+                        lock (Global.DB) {
+                                foreach (Item item in PotentialItems) {
+                                        if (!IsMatch (item))
+                                                continue;
+
+                                        l.Append (item.Handle);
+                                        
+                                        i++;
+                                        if (max_len != -1 && i >= max_len)
+                                                break;
+                                }
+                        }
+
+			List.RemoveDelta (l);
+
+			foreach (int p in l) {
+				IntPtr ptr = new IntPtr (p);
+
+				List.Append (ptr);
+			}
+
+			List.SelectFirst ();
+
+			return false;
+
+                }
 		
 		// Private Methods
 		// Private Methods :: Assertions
diff -aur muine-0.8.0/src/Album.cs muine-0.8.0-hacking/src/Album.cs
--- muine-0.8.0/src/Album.cs	2005-01-10 08:44:54.000000000 +1100
+++ muine-0.8.0-hacking/src/Album.cs	2005-01-13 07:05:37.854958280 +1100
@@ -35,6 +35,10 @@
 		private static readonly string [] prefixes = 
 			Catalog.GetString ("the dj").Split (' ');
 
+                private const string GConfKeyNonAlbumFolders = "/apps/muine/non_album_folders";
+                private static readonly string [] GConfDefaultNonAlbumFolders = new string [0];
+                private static string [] non_album_folders;
+
 		// Properties
 		private string name;
 		public string Name {
@@ -115,6 +119,11 @@
 			pointers [cur_ptr] = this;
 			base.handle = cur_ptr;
 
+                        // check that this is a complete album
+                        foreach (string check_folder in non_album_folders)
+                                if (folder.StartsWith (check_folder))
+                                        complete = false;
+
 			if (check_cover) {
 				cover_image = GetCover (initial_song);
 
@@ -122,11 +131,35 @@
 			}
 		}
 
+                // Static Constructor
+                static Album ()
+                {       
+                        non_album_folders = (string []) 
+                                Config.Get (GConfKeyNonAlbumFolders, GConfDefaultNonAlbumFolders);
+
+                        Config.AddNotify (GConfKeyNonAlbumFolders, 
+                                new GConf.NotifyEventHandler (OnNonAlbumFoldersChanged));
+                }
+                
+                // Properties
+                // is this album from a 'non_album_folders' directory?
+                private bool complete = true;
+                public bool Complete {
+                        get { return complete; }
+                }
+
+                // Static Methods
+		private static void OnNonAlbumFoldersChanged (object o, GConf.NotifyEventArgs args)
+                {
+                        non_album_folders = (string []) args.Value;
+                }
+
 		public static Album FromHandle (IntPtr handle)
 		{


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