PATCH: Nautilus Emblems utility in beagle



Hi all, I fixed up my Nautilus Emblem patch for beagle so that it can be its
own utility class.  If you have any problems with it, or know of a better way
to do some of the code (since I don't claim to be any sort of C# expert)
please email.  Attached is the patch talked about above.

-- Joe Gasiorek
gasiorek yakko cs wmich edu

diff -u --recursive --exclude=CVS --new-file clean/beagle/Util/Makefile.am beagle/Util/Makefile.am
--- clean/beagle/Util/Makefile.am	2004-06-24 14:31:25.369730576 -0400
+++ beagle/Util/Makefile.am	2004-06-24 14:34:07.018156280 -0400
@@ -19,6 +19,7 @@
 	$(srcdir)/ImLog.cs		\
 	$(srcdir)/Logger.cs		\
 	$(srcdir)/MultiReader.cs	\
+	$(srcdir)/NautilusTools.cs	\
 	$(srcdir)/PullingReader.cs	\
 	$(srcdir)/StringFu.cs
 
diff -u --recursive --exclude=CVS --new-file clean/beagle/Util/NautilusTools.cs beagle/Util/NautilusTools.cs
--- clean/beagle/Util/NautilusTools.cs	1969-12-31 19:00:00.000000000 -0500
+++ beagle/Util/NautilusTools.cs	2004-06-24 14:33:54.952990464 -0400
@@ -0,0 +1,53 @@
+// created on 06/24/2004 at 11:57
+using System;
+using System.IO;
+using System.Text;
+using System.Xml;
+using System.Collections;
+using System.Text.RegularExpressions;
+using System.Runtime.InteropServices;
+
+namespace Beagle.Util {
+
+	public class NautilusTools {
+		
+		[DllImport ("libgnomeui-2")]
+			extern static string gnome_vfs_escape_string (string uri);
+			
+		public static string GetEmblem (string path) {
+			
+			FileInfo info = new FileInfo (path);
+			StringBuilder newpath = new StringBuilder (Environment.GetEnvironmentVariable ("HOME"));
+			newpath.Append ("/.nautilus/metafiles/file:%2F%2F");
+		
+			path = Path.GetDirectoryName (path);
+			path = gnome_vfs_escape_string (path);
+		
+			newpath.Append (path);
+			newpath.Append (".xml");
+				
+			XmlDocument doc = new XmlDocument ();
+			StreamReader sr = null;
+//			Console.WriteLine ("FILE:  {0}", newpath.ToString ());
+			try {
+				sr = new StreamReader(newpath.ToString ());
+				doc.Load (sr);
+				} catch (Exception e) {
+//					Console.WriteLine ("Nautlius: {0}, {1}", newpath.ToString (), e.Message);
+					return null;
+			}
+			XmlNodeList nodes = doc.SelectNodes ("/directory/file");
+			foreach (XmlNode node in nodes) {
+//				Console.WriteLine ("{0} :: {1}", info.Name, node.Attributes[0].Value);	
+				if (info.Name.CompareTo (node.Attributes[0].Value) == 0) {
+					if (node.FirstChild.Name.CompareTo("keyword") == 0) {
+//						Console.WriteLine ("{0}", node.FirstChild.Attributes[0].Value);
+						return node.FirstChild.Attributes[0].Value;
+					}
+				}
+			}
+			return null;
+	 	}
+	 	
+	}
+}
diff -u --recursive --exclude=CVS --new-file clean/beagle/indexer/IndexableFile.cs beagle/indexer/IndexableFile.cs
--- clean/beagle/indexer/IndexableFile.cs	2004-06-24 14:31:25.400725864 -0400
+++ beagle/indexer/IndexableFile.cs	2004-06-24 14:34:20.986032840 -0400
@@ -40,6 +40,8 @@
 		Flavor flavor;
 		Filter filter;
 		String path;
+		String emblem = null;
+		
 
 		public IndexableFile (String _path)
 		{
@@ -63,6 +65,11 @@
 
 		static string[] longExtensions = {".html" };
 
+		public String Emblem {
+			get { return emblem; }
+			set { emblem = value; }
+		}
+
 		override protected void DoBuild ()
 		{
 			if (filter != null) {
@@ -112,10 +119,11 @@
 			else
 				name = Path.GetFileName (path);
 			this ["SplitName"] = String.Join (" ", BU.StringFu.FuzzySplit (name));
-
+			this ["Emblem"] = BU.NautilusTools.GetEmblem (path);
+			
 			// FIXME: there is more information that we could attach
 			// * Filesystem-level metadata
-			// * Nautilus emblems
+			
 		}
 	}
 


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