PATCH: nautilus notes for beagle



Hi all, I noticed that Nautilus also provides the ability to create 'Notes'
for files.  This gave me a chance to rework the code in NautilusUtils.cs to
provide a simple helper function to get the appropriate meta file.  I didn't
include any of the code for IndexableFile.cs becaue of trow's re-indexing
concerns.  Anyway, the code is attached.  As always, please bug me in IRC
(slackr) or by email if it doesn't work or you see some better way of doing it.

-- Joe Gasiorek
gasiorek yakko cs wmich edu

diff -u --recursive --exclude=CVS --new-file clean/beagle/Util/NautilusTools.cs beagle/Util/NautilusTools.cs
--- clean/beagle/Util/NautilusTools.cs	2004-06-24 20:55:16.000000000 -0400
+++ beagle/Util/NautilusTools.cs	2004-06-25 11:59:19.446285328 -0400
@@ -42,12 +42,50 @@
 			extern static string gnome_vfs_escape_string (string uri);
 			
 		public static string GetEmblem (string path) {
+					
+			XmlDocument doc = new XmlDocument ();
+			doc = GetMetaFile (path);
+			if (doc == null)
+				return null;
+			FileInfo info = new FileInfo (path);
+			
+			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;
+	 	}
+
+		public static string GetNotes (string path) {
 
+			XmlDocument doc = new XmlDocument ();
+			doc = GetMetaFile (path);
+			if (doc == null)
+				return null;
+			FileInfo info = new FileInfo (path);
+
+			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) {
+					return node.Attributes.GetNamedItem ("annotation").Value;
+				}
+			}
+			return null;
+		}
+
+		private static XmlDocument GetMetaFile (string path) {
+			
 			// Allow us to pass in file:// Uris.
 			if (path.StartsWith ("file://"))
 				path = path.Substring ("file://".Length);
 			
-			FileInfo info = new FileInfo (path);
 			StringBuilder newpath = new StringBuilder (Environment.GetEnvironmentVariable ("HOME"));
 			newpath.Append ("/.nautilus/metafiles/file:%2F%2F");
 		
@@ -56,7 +94,7 @@
 		
 			newpath.Append (path);
 			newpath.Append (".xml");
-				
+ 	
 			XmlDocument doc = new XmlDocument ();
 			StreamReader sr = null;
 			//Console.WriteLine ("FILE:  {0}", newpath.ToString ());
@@ -67,18 +105,8 @@
 					//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;
-	 	}
-	 	
+
+			return doc;
+		}
 	}
 }


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