nemo r25 - in trunk: . broker dbus gtk



Author: arj
Date: Mon Jan  7 10:40:10 2008
New Revision: 25
URL: http://svn.gnome.org/viewvc/nemo?rev=25&view=rev

Log:
Fix some problems with Xesam 
  
- results not mapped properly
- searching for text



Added:
   trunk/dbus/GLib.cs
Modified:
   trunk/broker/Broker.cs
   trunk/broker/Tracker.cs
   trunk/broker/Xesam.cs
   trunk/dbus/Introspection.cs
   trunk/gtk/MainWindow.cs
   trunk/nemo.mdp

Modified: trunk/broker/Broker.cs
==============================================================================
--- trunk/broker/Broker.cs	(original)
+++ trunk/broker/Broker.cs	Mon Jan  7 10:40:10 2008
@@ -84,7 +84,7 @@
 			return registered_index;
 		}
 
-		public abstract void get_metadata(List<string> filenames, List<VoidFunction<string[]>> callback);
+		public abstract void get_metadata(List<string> filenames, Dictionary<string, VoidFunction<string[]>> callback);
 	 
 	 	public void get_file_from_metadata_store(string filename, VoidFunction<File> callback)
 	 	{
@@ -108,15 +108,18 @@
 			q.starred = starred;
 
 	#if false
-			meta.set_query_result_callback(delegate (List<File> files) { 
-				meta.set_query_result_callback(null); 
-				callback(files);
-			});
-
 			meta.set_query_result_callback(callback);
-			
+
 			meta.set_query(q);
-	#endif		
+			meta.trigger_query_result_changed();
+			
+	#endif
+
+	#if true
+			meta.set_query_result_callback(delegate (List<File> files) {
+				meta.set_query_result_callback(null);
+				callback(files);
+			});
 
 	        ++cur_search_id;
 
@@ -126,8 +129,7 @@
 				if (cur_search_id == search_id)
 					callback(files);
 			});
-
-	//        meta.trigger_query_result_changed();
+	#endif		
 	    }
 
 	    public void get_all_labels(VoidFunction<List<MetaLabel>> callback)

Modified: trunk/broker/Tracker.cs
==============================================================================
--- trunk/broker/Tracker.cs	(original)
+++ trunk/broker/Tracker.cs	Mon Jan  7 10:40:10 2008
@@ -88,13 +88,14 @@
 	        iterating = false;
 	    }
 
-	 	public override void get_metadata(List<string> filenames, List<VoidFunction<string[]>> callbacks)
+	 	public override void get_metadata(List<string> filenames, Dictionary<string, VoidFunction<string[]>> callbacks)
 	 	{
-	 		int index = 0;
-	 		foreach (string filename in filenames)
+	 		foreach (string filename in filenames) {
+				string tmp_filename = filename;
 			 	ThreadPool.QueueUserWorkItem(delegate {
-		 			callbacks[index](bus_metadata.Get("Files", filename, registered_fields));
+		 			callbacks[tmp_filename](bus_metadata.Get("Files", filename, registered_fields));
 		 		});
+		 	}
 	 	}
 
 		// result returned as array of [type, uri]

Modified: trunk/broker/Xesam.cs
==============================================================================
--- trunk/broker/Xesam.cs	(original)
+++ trunk/broker/Xesam.cs	Mon Jan  7 10:40:10 2008
@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Threading;
 using NDesk.DBus;
+using org.freedesktop.DBus;
 
 [Interface("org.freedesktop.xesam.Search")]
 public interface IXesamSearch
@@ -41,6 +42,8 @@
 			
 			session_id = "";
 			
+			BusG.Init ();
+
 	        con = Bus.Session;
 			
 	        ObjectPath opath = new ObjectPath("/org/freedesktop/xesam/searcher/main");
@@ -62,7 +65,7 @@
 			hits_added_callbacks = new Dictionary<string, Callback>();
 			hits_done_callbacks = new Dictionary<string, VoidFunction>();
 
-	        start_iterating();
+//	        start_iterating();
 		}
 
 		private class Callback
@@ -89,7 +92,12 @@
 
 		private void hits_callback_handler(string session_id, UInt32 amount)
 		{
-			System.Console.WriteLine("the handler is handling");
+			System.Console.WriteLine("the handler is handling {0}", session_id);
+
+			// for text search, we only want the first results so we need this hack 
+			if (!hits_added_callbacks.ContainsKey(session_id))
+				return;
+
 			Callback callback = hits_added_callbacks[session_id];
 			
 			callback.get_results(ref callback.cur_number_of_results, amount);
@@ -97,6 +105,7 @@
 
 		private void hits_done_handler(string session_id)
 		{
+			System.Console.WriteLine("is done {0}", session_id);
 			VoidFunction callback = hits_done_callbacks[session_id];
 			callback();
 			hits_done_callbacks.Remove(session_id);
@@ -109,6 +118,7 @@
 		
 		string session_id;
 
+#if false
 	    public void start_iterating() 
 	    {
 	        if (iterating) // re-entrance protection
@@ -116,22 +126,28 @@
 
 			ThreadPool.QueueUserWorkItem(delegate(Object stateInfo) {
 	            while (!finished) {
+	            	System.Console.WriteLine("iterating");
 	                con.Iterate();
+	            	System.Console.WriteLine("iterating done");
 	            }
+            	System.Console.WriteLine("finished iterating");
 			});
 
 	        iterating = true;
 	    }
+#endif
 
 	    public override void stop() 
 	    {
+#if false
 	    	stop_broker();
 	        finished = true;
 	        bus_search.CloseSession(session_id); // final iteration
 	        iterating = false;
+#endif
 	    }
 
-	 	public override void get_metadata(List<string> all_filenames, List<VoidFunction<string[]>> callbacks)
+	 	public override void get_metadata(List<string> all_filenames, Dictionary<string, VoidFunction<string[]>> callbacks)
 	 	{
 	 		int offset = 0;
 
@@ -165,7 +181,10 @@
 							int si = 0;
 							foreach (object r in result)
 								s[si++] = r as string;
-							callbacks[tmp_offset + count](s);
+							if (!callbacks.ContainsKey(s[0]))
+								System.Console.WriteLine("warning, file not found in calllback {0}", s[0]);
+							else
+								callbacks[s[0]](s);
 							++count;
 						}
 					}));
@@ -283,6 +302,7 @@
 
 								callback(real_results);
 								
+								// We don't want more results
 								hits_added_callbacks.Remove(session_id);
 							}));
 						}
@@ -291,12 +311,12 @@
 					System.Console.WriteLine("yes");
 
 					hits_done_callbacks.Add(session_id, delegate  { 
-						if (!got_results) // no results
-							callback(new List<Tuple<string[], File>>());
-
 						System.Console.WriteLine("closing session {0}", session_id);
 						bus_search.CloseSession(session_id);
 						hits_added_callbacks.Remove(session_id);
+
+						if (!got_results) // no results
+							callback(new List<Tuple<string[], File>>());
 					});
 
 					System.Console.WriteLine("yes!");

Added: trunk/dbus/GLib.cs
==============================================================================
--- (empty file)
+++ trunk/dbus/GLib.cs	Mon Jan  7 10:40:10 2008
@@ -0,0 +1,53 @@
+// Copyright 2006 Alp Toker <alp atoker com>
+// This software is made available under the MIT License
+// See COPYING for details
+
+using System;
+using NDesk.DBus;
+using GLib;
+using org.freedesktop.DBus;
+
+namespace NDesk.DBus
+{
+	//FIXME: this API needs review and de-unixification. It is horrid, but gets the job done.
+	public static class BusG
+	{
+		static bool initialized = false;
+		public static void Init ()
+		{
+			if (initialized)
+				return;
+
+			Init (Bus.System);
+			Init (Bus.Session);
+			//TODO: consider starter bus?
+
+			initialized = true;
+		}
+
+		public static void Init (Connection conn)
+		{
+			IOFunc dispatchHandler = delegate (IOChannel source, IOCondition condition) {
+				if ((condition & IOCondition.Hup) == IOCondition.Hup) {
+					if (Protocol.Verbose)
+						Console.Error.WriteLine ("Warning: Connection was probably hung up (" + condition + ")");
+
+					//TODO: handle disconnection properly, consider memory management
+					return false;
+				}
+
+				//this may not provide expected behaviour all the time, but works for now
+				conn.Iterate ();
+				return true;
+			};
+
+			Init (conn, dispatchHandler);
+		}
+
+		static void Init (Connection conn, IOFunc dispatchHandler)
+		{
+			IOChannel channel = new IOChannel ((int)conn.Transport.SocketHandle);
+			channel.AddWatch(0, IOCondition.In | IOCondition.Hup, dispatchHandler);
+		}
+	}
+}

Modified: trunk/dbus/Introspection.cs
==============================================================================
--- trunk/dbus/Introspection.cs	(original)
+++ trunk/dbus/Introspection.cs	Mon Jan  7 10:40:10 2008
@@ -36,12 +36,28 @@
 			writer = XmlWriter.Create (sb, settings);
 		}
 
+		static string GetProductDescription ()
+		{
+			String version;
+
+			Assembly assembly = Assembly.GetExecutingAssembly ();
+			AssemblyName aname = assembly.GetName ();
+
+			AssemblyInformationalVersionAttribute iversion = Attribute.GetCustomAttribute (assembly, typeof (AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute;
+
+			if (iversion != null)
+				version = iversion.InformationalVersion;
+			else
+				version = aname.Version.ToString ();
+
+			return aname.Name + " " + version;
+		}
+
 		public void WriteStart ()
 		{
 			writer.WriteDocType ("node", PUBLIC_IDENTIFIER, SYSTEM_IDENTIFIER, null);
 
-			AssemblyName aname = Assembly.GetExecutingAssembly().GetName ();
-			writer.WriteComment (" " + aname.Name + " " + aname.Version.ToString (3) + " ");
+			writer.WriteComment (" " + GetProductDescription () + " ");
 
 			//the root node element
 			writer.WriteStartElement ("node");

Modified: trunk/gtk/MainWindow.cs
==============================================================================
--- trunk/gtk/MainWindow.cs	(original)
+++ trunk/gtk/MainWindow.cs	Mon Jan  7 10:40:10 2008
@@ -228,7 +228,7 @@
 		// must be map, dang
 
 		List<string> files = new List<string>();
-		List<VoidFunction<string[]>> callbacks = new List<VoidFunction<string[]>>(); 
+		Dictionary<string, VoidFunction<string[]>> callbacks = new Dictionary<string, VoidFunction<string[]>>(); 
 
 		foreach (File file in search_results) 
 		{
@@ -236,7 +236,7 @@
 			
 			files.Add(file.path);
 			
-			callbacks.Add(Helpers.RunInMainThread<string[]>(delegate(string[] result) {
+			callbacks.Add("file://" + file.path, Helpers.RunInMainThread<string[]>(delegate(string[] result) {
 				
 				System.Console.WriteLine("results: {0}", result.Length);
 				System.Console.WriteLine("result: {0}", result[1]);

Modified: trunk/nemo.mdp
==============================================================================
--- trunk/nemo.mdp	(original)
+++ trunk/nemo.mdp	Mon Jan  7 10:40:10 2008
@@ -100,6 +100,7 @@
     <File name="dbus/Wrapper.cs" subtype="Code" buildaction="Compile" />
     <File name="broker/Tracker.cs" subtype="Code" buildaction="Compile" />
     <File name="broker/Xesam.cs" subtype="Code" buildaction="Compile" />
+    <File name="dbus/GLib.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />



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