beagle r4569 - trunk/beagle/beagled



Author: dbera
Date: Sat Mar  1 01:37:30 2008
New Revision: 4569
URL: http://svn.gnome.org/viewvc/beagle?rev=4569&view=rev

Log:
Fix our filter matching code to deal with multiple filters matching a file. Now we give more priority to a Uri match, then to an extension match. Also, fix the flavor IComparer to never 0 (i.e. the flavors are same) if they are not the same. This would prevent different flavors but with same weight from removing one another from the sortedlist.


Modified:
   trunk/beagle/beagled/Flavor.cs

Modified: trunk/beagle/beagled/Flavor.cs
==============================================================================
--- trunk/beagle/beagled/Flavor.cs	(original)
+++ trunk/beagle/beagled/Flavor.cs	Sat Mar  1 01:37:30 2008
@@ -96,10 +96,14 @@
 			get {
 				int weight = priority;
 
+				/* Uri matches are very important, next are extensions and then mimetype.
+				 * This allows filters to override everything else by specifying matching Uris,
+				 * and override mimetype by matching extensions.
+				 */
 				if (Uri != null)
-					weight += 1;				
+					weight += 3;
 				if (Extension != null)
-					weight += 1;
+					weight += 2;
 				if (MimeType != null)
 					weight += 1;
 
@@ -128,12 +132,17 @@
 		public class FlavorComparer : IComparer 
 		{
 			// flav [larger wt] < flav [smaller wt]
+			// for same wt, use hashcode (never return obj1 == obj2 unless they are actually same)
 			public int Compare (object obj1, object obj2) 
 			{
 				FilterFlavor flav1 = (FilterFlavor) obj1;
 				FilterFlavor flav2 = (FilterFlavor) obj2;
 
-				return flav2.Weight.CompareTo (flav1.Weight);
+				int ret = flav2.Weight.CompareTo (flav1.Weight);
+				if (ret != 0)
+					return ret;
+				else
+					return obj1.GetHashCode () - obj2.GetHashCode ();
 			} 
 		}
 



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