nemo r14 - in trunk: . broker common gtk gtk-gui metadata uicommon



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

Log:
Add support for beagle



Added:
   trunk/broker/Tracker.cs
   trunk/broker/Xesam.cs
Modified:
   trunk/Makefile
   trunk/NEWS
   trunk/broker/Broker.cs
   trunk/common/Common.cs
   trunk/common/Configuration.cs
   trunk/gtk-gui/MainWindow.cs
   trunk/gtk-gui/gui.stetic
   trunk/gtk/Main.cs
   trunk/gtk/MainWindow.cs
   trunk/gtk/Tray.cs
   trunk/metadata/MetadataStore.cs
   trunk/nemo.mdp
   trunk/uicommon/Categories.cs
   trunk/uicommon/DocumentItem.cs
   trunk/uicommon/PictureItem.cs
   trunk/uicommon/TypeLabels.cs

Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile	(original)
+++ trunk/Makefile	Mon Jan  7 10:27:57 2008
@@ -2,7 +2,7 @@
 
 all:
 	make -C po/
-	gmcs -debug -unsafe dbus/*.cs broker/Broker.cs metadata/MetadataStore.cs common/*.cs gtk/*.cs uicommon/*.cs gtk-gui/*.cs -resource:images/no-preview.png,no-preview.png -resource:images/close.png,close.png -resource:images/zip.png,zip.png -resource:images/stock_about.png,stock_about.png -resource:images/image-x-generic.png,image-x-generic.png -resource:images/pdf.png,pdf.png -resource:images/text-html.png,text-html.png -resource:images/text-x-generic.png,text-x-generic.png -resource:images/dot.png,dot.png -resource:images/video-x-generic.png,video-x-generic.png -resource:images/x-office-document.png,x-office-document.png -resource:images/x-office-presentation.png,x-office-presentation.png -resource:images/x-office-spreadsheet.png,x-office-spreadsheet.png -resource:images/starred_right.png,starred_right.png -resource:images/big_star.png,big_star.png -resource:images/blue_guy.png,blue_guy.png -resource:images/blue_guy_med.png,blue_guy_med.png -resource:images/small_blue_guy.pn
 g,small_blue_guy.png -r:System.Data -r:Mono.Data.Sqlite -r:Mono.Posix -r:Mono.Cairo -pkg:gtk-sharp-2.0 -pkg:gnome-sharp-2.0 -pkg:stetic -out:$(PRG)
+	gmcs -debug -unsafe dbus/*.cs broker/*.cs metadata/MetadataStore.cs common/*.cs gtk/*.cs uicommon/*.cs gtk-gui/*.cs -resource:images/no-preview.png,no-preview.png -resource:images/close.png,close.png -resource:images/zip.png,zip.png -resource:images/stock_about.png,stock_about.png -resource:images/image-x-generic.png,image-x-generic.png -resource:images/pdf.png,pdf.png -resource:images/text-html.png,text-html.png -resource:images/text-x-generic.png,text-x-generic.png -resource:images/dot.png,dot.png -resource:images/video-x-generic.png,video-x-generic.png -resource:images/x-office-document.png,x-office-document.png -resource:images/x-office-presentation.png,x-office-presentation.png -resource:images/x-office-spreadsheet.png,x-office-spreadsheet.png -resource:images/starred_right.png,starred_right.png -resource:images/big_star.png,big_star.png -resource:images/blue_guy.png,blue_guy.png -resource:images/blue_guy_med.png,blue_guy_med.png -resource:images/small_blue_guy.png,sma
 ll_blue_guy.png -r:System.Data -r:Mono.Data.Sqlite -r:Mono.Posix -r:Mono.Cairo -pkg:gtk-sharp-2.0 -pkg:gnome-sharp-2.0 -pkg:stetic -out:$(PRG)
 
 clean:
 	@if test -f $(PRG); then rm $(PRG); fi

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Mon Jan  7 10:27:57 2008
@@ -1,4 +1,9 @@
-.1.2 alpha
+0.2
+---
+
+- Support Beagle through the Xesam adaptor
+
+0.1.2 alpha
 -----------
 	
  - Fix Mono.Data.SqliteClient -> Mono.Data.Sqlite bugs

Modified: trunk/broker/Broker.cs
==============================================================================
--- trunk/broker/Broker.cs	(original)
+++ trunk/broker/Broker.cs	Mon Jan  7 10:27:57 2008
@@ -1,319 +1,218 @@
 using System;
 using System.Collections.Generic;
 using System.Threading;
-using NDesk.DBus;
 
-using Nemo;
-
-[Interface("org.freedesktop.Tracker.Metadata")]
-public interface Metadata
-{
-    string[] GetRegisteredTypes(string metadata_class);
-	void RegisterType(string name, string datatype);
-    string[] Get(string service, string id, string[] keys);
-//    void Set(string service, string id, string[] keys, string[] values);
-}
-
-[Interface("org.freedesktop.Tracker.Search")]
-public interface Search
-{
-//    string[] Text(int live_query_id, string service, string search_text, int offset, int max_hits);
-    string GetSnippet(string service, string id, string search_text);
-    string[][] Query(int live_query_id, string service, string[] fields, string search_text, string keywords,
-                     string query_condition, bool sort_by_service, int offset, int max_hits);
-    string[][] TextDetailed(int live_query_id, string service, string search_text, int offset, int max_hits);
-}
-
-[Interface("org.freedesktop.Tracker")]
-public interface ITracker
+namespace Nemo
 {
-    int GetVersion();
-}
-
-public sealed class Broker
-{
-    private ITracker bus;
-    private Search bus_search;
-    private Metadata bus_metadata;
-    private Connection con;
-
-	MetadataStore meta;	
-	
-    private bool iterating;
-
-    private string[] registered_fields;
-
-    private Broker()
-    {
-		// tracker specific
-		
-		finished = false;
+	public abstract class Broker
+	{
+		protected MetadataStore meta;	
 		
-		cur_search_id = 0;
-
-		callbacks = new List<VoidFunction>();
+	    protected string[] registered_fields;
 
-        con = Bus.Session;
+		protected Dictionary<string, string> types;
 
-		//string addr = "unix:path=/tmp/dbus-ABCDEFGHIJ";
-        //con = new Connection (addr);
-
-        ObjectPath opath = new ObjectPath("/org/freedesktop/tracker");
-
-        bus = con.GetObject<ITracker>("org.freedesktop.Tracker", opath);
-        bus_search = con.GetObject<Search>("org.freedesktop.Tracker", opath);
-        bus_metadata = con.GetObject<Metadata>("org.freedesktop.Tracker", opath);
-
-        registered_fields = new string[] { "File:Path", "File:Modified", "File:Accessed", "File:Size", "File:Name", "File:Mime" }; // "File:Rank", 
-
-        start_iterating();
-
-		// metadata store
-		if (meta == null) {
-			meta = new MetadataStore(Singleton<Configuration>.Instance.data.watch_dir);
-        	meta.start(System.IO.Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), ".nemo/"));
-        }
-	}
-
-	bool finished;
+	    protected Broker(bool reindex)
+	    {
+			types = new Dictionary<string,string>();	    
+	    
+			System.Console.WriteLine("reindex: {0}, first run {1}", reindex, Singleton<Configuration>.Instance.data.first_run);
+			
+			if (reindex || Singleton<Configuration>.Instance.data.first_run)
+			{
+				reindex_metadata_store();
+				Singleton<Configuration>.Instance.data.first_run = false;
+				Singleton<Configuration>.Instance.save_configuration();
+			}
+	    
+			cur_search_id = 0;
 
-    public void start_iterating() 
-    {
-        if (iterating) // re-entrance protection
-            return;
-
-		ThreadPool.QueueUserWorkItem(delegate(Object stateInfo) {
-            while (!finished)
-                con.Iterate();
-		});
-
-		own_thread_pool();
-
-        iterating = true;
-    }
-
-    public void stop() 
-    {
-        meta.stop();
-        finished = true;
-        bus.GetVersion(); // final iteration
-        iterating = false;
-    }
+			callbacks = new List<VoidFunction>();
 
-	public void reindex_metadata_store()
-	{
-	    System.Console.WriteLine("Reindexing filesystem!");
+			own_thread_pool();
 
-		if (meta == null) {
-			meta = new MetadataStore(Singleton<Configuration>.Instance.data.watch_dir);
-        	meta.start(System.IO.Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), ".nemo/"));
-        }
+			// metadata store
+			if (meta == null) {
+				meta = new MetadataStore(Singleton<Configuration>.Instance.data.watch_dir);
+	        	meta.start(System.IO.Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), ".nemo/"));
+	        }
+		}
 
-		System.Console.WriteLine(Singleton<Configuration>.Instance.data.watch_dir);
+		public abstract void stop();
 
-        meta.sync_with_filesystem();
-	}
+	    protected void stop_broker() 
+	    {
+	        meta.stop();
+	    }
 
- 	public int RegisterItemType(string[] fields) 
-	{
-		string[] new_registered_fields = new string[fields.Length + registered_fields.Length]; 
-		
-		int i = 0;
-		
-		foreach (string field in registered_fields)
+		public void reindex_metadata_store()
 		{
-			new_registered_fields[i++] = field;
-		}
-		
-		foreach (string field in fields)
-		{
-			new_registered_fields[i++] = field;
-		}
-		
-		int registered_index = registered_fields.Length;  
-		
-		registered_fields = new_registered_fields;
-		
-		return registered_index;
-	}
- 
- 	public void get_metadata_from_tracker(string filename, VoidFunction<string[]> callback)
- 	{
-	 	ThreadPool.QueueUserWorkItem(delegate {
- 			callback(bus_metadata.Get("Files", filename, registered_fields));
- 		});
- 	}
- 
- 	public void get_file_from_metadata_store(string filename, VoidFunction<File> callback)
- 	{
-	 	ThreadPool.QueueUserWorkItem(delegate {
- 			meta.get_file_from_path(filename, callback);
- 		});
- 	}
- 
- 	private int cur_search_id;
-
-	// result returned as array of [type, uri]
-	public void SearchForText(string search_string, bool fast, VoidFunction<List<Tuple<string[], File>>> callback)
-	{
-		ThreadPool.QueueUserWorkItem(delegate {
-            ++cur_search_id;
+		    System.Console.WriteLine("Reindexing filesystem!");
 
-            int search_id = cur_search_id;
+			if (meta == null) {
+				meta = new MetadataStore(Singleton<Configuration>.Instance.data.watch_dir);
+	        	meta.start(System.IO.Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), ".nemo/"));
+	        }
 
-            if (!fast)
-                Thread.Sleep(1000);
+			System.Console.WriteLine(Singleton<Configuration>.Instance.data.watch_dir);
 
-            if (cur_search_id == search_id)
-            {
-				// the interface for searching using tracker is borken so we need to get 500 to make sure we get some we like...
-				string[][] result = bus_search.TextDetailed(-1, "Files", search_string, 0, 500);
+	        meta.sync_with_filesystem();
+		}
 
-				if (cur_search_id == search_id) {
+	 	public int RegisterItemTypes(string[] fields) 
+		{
+			string[] new_registered_fields = new string[fields.Length + registered_fields.Length]; 
+			
+			int i = 0;
+			
+			foreach (string field in registered_fields)
+			{
+				new_registered_fields[i++] = field;
+			}
+			
+			foreach (string field in fields)
+			{
+				new_registered_fields[i++] = types[field];
+			}
+			
+			int registered_index = registered_fields.Length;  
+			
+			registered_fields = new_registered_fields;
 
-					List<string> filenames = new List<string>();
+			System.Console.WriteLine("registering item type! {0}", registered_fields.Length);
+			
+			return registered_index;
+		}
 
-					foreach (string[] r in result) {
+		public abstract void get_metadata(List<string> filenames, List<VoidFunction<string[]>> callback);
+	 
+	 	public void get_file_from_metadata_store(string filename, VoidFunction<File> callback)
+	 	{
+		 	ThreadPool.QueueUserWorkItem(delegate {
+	 			meta.get_file_from_path(filename, callback);
+	 		});
+	 	}
+	 
+	 	protected int cur_search_id;
+
+		public abstract void SearchForText(string search_string, bool fast, VoidFunction<List<Tuple<string[], File>>> callback);
+
+	    public void Search(List<MetaLabel> keywords, List<long> types, DateTime date_start, DateTime date_end, bool starred, 
+	    				   VoidFunction<List<File>> callback)
+	    {
+			Query q = new Query();
+			q.labels = keywords;
+			q.types = types;
+			q.date_start = date_start;
+			q.date_end = date_end;
+			q.starred = starred;
+
+	#if false
+			meta.set_query_result_callback(delegate (List<File> files) { 
+				meta.set_query_result_callback(null); 
+				callback(files);
+			});
 
-						System.Console.WriteLine("{0} - {1}", r[0], r[1]);
+			meta.set_query_result_callback(callback);
 			
-						if (r[1] == "Folders") // sigh, skip folders
-							continue;
-
-						filenames.Add(r[0]);
-					}
-					
-					System.Console.WriteLine("search metadata store for {0} files", filenames.Count);
-					
-					meta.get_files_from_paths(filenames, Helpers.RunInMainThread<List<File>>(delegate (List<File> files) {
+			meta.set_query(q);
+	#endif		
 
-						System.Console.WriteLine("got {0} files from metadata store", files.Count);
+	        ++cur_search_id;
 
-						List<Tuple<string[], File>> real_results = new List<Tuple<string[], File>>();
+	        int search_id = cur_search_id;
 
-						foreach (File file in files)
-							real_results.Add(new Tuple<string[], File>(bus_metadata.Get("Files", file.path, registered_fields), file));
+			meta.search(q, delegate(List<File> files) { 
+				if (cur_search_id == search_id)
+					callback(files);
+			});
+
+	//        meta.trigger_query_result_changed();
+	    }
+
+	    public void get_all_labels(VoidFunction<List<MetaLabel>> callback)
+	    {
+			meta.set_labels_changed_callback(callback);
+			meta.trigger_labels_changed();
+	    }
+
+	    public void get_type_labels(VoidFunction<List<Tuple<FileTypeCategory, int>>> callback)
+	    {
+			meta.set_type_labels_changed_callback(callback);
+			meta.trigger_type_labels_changed();
+	    }
 
-						callback(real_results);
-					}));
+		private void own_thread_pool()
+		{
+			ThreadPool.QueueUserWorkItem(delegate(Object stateInfo) {
+				while (true) {
+					System.Threading.Monitor.Enter(callback_lock);
+					System.Threading.Monitor.Wait(callback_lock);
+					if (callbacks.Count > 0) {
+						callbacks[0]();
+						callbacks.RemoveAt(0);
+					}
+					System.Threading.Monitor.Exit(callback_lock);
 				}
-            }
-        });
-	}
-	
-    public void Search(List<MetaLabel> keywords, List<long> types, DateTime date_start, DateTime date_end, bool starred, 
-    				   VoidFunction<List<File>> callback)
-    {
-		Query q = new Query();
-		q.labels = keywords;
-		q.types = types;
-		q.date_start = date_start;
-		q.date_end = date_end;
-		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);
+		// own threadpool implementation because the one in mono is broken
+	    private static object callback_lock = new Object();
+		private List<VoidFunction> callbacks;
+
+	    public void add_label(long parent_id, string label)
+	    {
+	        MetaLabel new_label = new MetaLabel();
+	        new_label.label = label;
+	        new_label.parent_db_id = parent_id;
+
+			meta.add_label(new_label, delegate {});
+	    }	
+		
+		public void remove_label(MetaLabel label)
+	    {
+			meta.remove_label(label, delegate {});
+	    }
+	    
+		public void rename_label(MetaLabel label, string new_name)
+		{
+			meta.rename_label(label, new_name);
+		}
 		
-		meta.set_query(q);
-#endif		
-
-        ++cur_search_id;
-
-        int search_id = cur_search_id;
-
-		meta.search(q, delegate(List<File> files) { 
-			if (cur_search_id == search_id)
-				callback(files);
-		});
-
-//        meta.trigger_query_result_changed();
-    }
-
-    public void get_all_labels(VoidFunction<List<MetaLabel>> callback)
-    {
-		meta.set_labels_changed_callback(callback);
-		meta.trigger_labels_changed();
-    }
-
-    public void get_type_labels(VoidFunction<List<Tuple<FileTypeCategory, int>>> callback)
-    {
-		meta.set_type_labels_changed_callback(callback);
-		meta.trigger_type_labels_changed();
-    }
-
-	private void own_thread_pool()
-	{
-		ThreadPool.QueueUserWorkItem(delegate(Object stateInfo) {
-			while (true) {
-				System.Threading.Monitor.Enter(callback_lock);
-				System.Threading.Monitor.Wait(callback_lock);
-				if (callbacks.Count > 0) {
-					callbacks[0]();
-					callbacks.RemoveAt(0);
-				}
-				System.Threading.Monitor.Exit(callback_lock);
-			}
-		});
-	}
-
-	// own threadpool implementation because the one in mono is broken
-    private static object callback_lock = new Object();
-	private List<VoidFunction> callbacks;
-
-    public void add_label(long parent_id, string label)
-    {
-        MetaLabel new_label = new MetaLabel();
-        new_label.label = label;
-        new_label.parent_db_id = parent_id;
-
-		meta.add_label(new_label, delegate {});
-    }	
-	
-	public void remove_label(MetaLabel label)
-    {
-		meta.remove_label(label, delegate {});
-    }
-    
-	public void rename_label(MetaLabel label, string new_name)
-	{
-		meta.rename_label(label, new_name);
-	}
-	
-    public void add_label_to_file(File file, MetaLabel label)
-	{
-        meta.add_label_to_file(file, label, delegate {});		
-    }
+	    public void add_label_to_file(File file, MetaLabel label)
+		{
+	        meta.add_label_to_file(file, label, delegate {});		
+	    }
 
-	public void remove_label_from_file(File file, MetaLabel label)
-	{
-        meta.remove_label_from_file(file, label, delegate {});
-    }
+		public void remove_label_from_file(File file, MetaLabel label)
+		{
+	        meta.remove_label_from_file(file, label, delegate {});
+	    }
+			
+		public void set_starred(File file, bool starred)
+		{
+		    meta.set_starred(file, starred, delegate {});	
+	    }	
 		
-	public void set_starred(File file, bool starred)
-	{
-	    meta.set_starred(file, starred, delegate {});	
-    }	
-	
-    public void search_snippet(string uri, string search_string, VoidFunction<string> callback)
-    {
-		ThreadPool.QueueUserWorkItem(delegate {
-			string result = "";
-			if (search_string.Length != 0)
-				result = bus_search.GetSnippet("Files", uri, search_string);
-			callback(result);
-		});
-    }
-
-    public void get_text(string uri, VoidFunction<string> callback)
-    {
-    	// FIXME: remember thread pool
-//    	System.Console.WriteLine("TRACKER IS FUBARED");
-		//string result = bus_files.GetTextContents(uri, 0, 100);
-		callback(""); // result
-    }
-} 
+	#if false
+	    public void search_snippet(string uri, string search_string, VoidFunction<string> callback)
+	    {
+			ThreadPool.QueueUserWorkItem(delegate {
+				string result = "";
+				if (search_string.Length != 0)
+					result = bus_search.GetSnippet("Files", uri, search_string);
+				callback(result);
+			});
+	    }
+
+	    public void get_text(string uri, VoidFunction<string> callback)
+	    {
+	    	// FIXME: remember thread pool
+	//    	System.Console.WriteLine("TRACKER IS FUBARED");
+			//string result = bus_files.GetTextContents(uri, 0, 100);
+			callback(""); // result
+	    }
+	#endif
+	}
+}
\ No newline at end of file

Added: trunk/broker/Tracker.cs
==============================================================================
--- (empty file)
+++ trunk/broker/Tracker.cs	Mon Jan  7 10:27:57 2008
@@ -0,0 +1,148 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using NDesk.DBus;
+
+[Interface("org.freedesktop.Tracker.Metadata")]
+public interface Metadata
+{
+    string[] GetRegisteredTypes(string metadata_class);
+	void RegisterType(string name, string datatype);
+    string[] Get(string service, string id, string[] keys);
+//    void Set(string service, string id, string[] keys, string[] values);
+}
+
+[Interface("org.freedesktop.Tracker.Search")]
+public interface Search
+{
+//    string[] Text(int live_query_id, string service, string search_text, int offset, int max_hits);
+    string GetSnippet(string service, string id, string search_text);
+    string[][] Query(int live_query_id, string service, string[] fields, string search_text, string keywords,
+                     string query_condition, bool sort_by_service, int offset, int max_hits);
+    string[][] TextDetailed(int live_query_id, string service, string search_text, int offset, int max_hits);
+}
+
+[Interface("org.freedesktop.Tracker")]
+public interface ITracker
+{
+    int GetVersion();
+}
+
+namespace Nemo
+{
+	public class Tracker : Broker
+	{
+	    private ITracker bus;
+	    private Search bus_search;
+	    private Metadata bus_metadata;
+	    private Connection con;
+		
+	    private bool iterating;
+
+		public Tracker(bool reindex) : base(reindex)
+		{
+			types.Add("height", "Image:Height");
+			types.Add("width", "Image:Width");
+			types.Add("title", "Doc:Title");
+			types.Add("pagecount", "Doc:PageCount");
+		
+			finished = false;
+			iterating = false;
+			
+	        con = Bus.Session;
+
+			//string addr = "unix:path=/tmp/dbus-ABCDEFGHIJ";
+	        //con = new Connection (addr);
+
+	        ObjectPath opath = new ObjectPath("/org/freedesktop/tracker");
+
+	        bus = con.GetObject<ITracker>("org.freedesktop.Tracker", opath);
+	        bus_search = con.GetObject<Search>("org.freedesktop.Tracker", opath);
+	        bus_metadata = con.GetObject<Metadata>("org.freedesktop.Tracker", opath);
+
+	        registered_fields = new string[] { "File:Mime" }; 
+
+	        start_iterating();
+		}
+
+		bool finished;
+
+	    public void start_iterating() 
+	    {
+	        if (iterating) // re-entrance protection
+	            return;
+
+			ThreadPool.QueueUserWorkItem(delegate(Object stateInfo) {
+	            while (!finished)
+	                con.Iterate();
+			});
+
+	        iterating = true;
+	    }
+
+	    public override void stop() 
+	    {
+	    	stop_broker();
+	        finished = true;
+	        bus.GetVersion(); // final iteration
+	        iterating = false;
+	    }
+
+	 	public override void get_metadata(List<string> filenames, List<VoidFunction<string[]>> callbacks)
+	 	{
+	 		int index = 0;
+	 		foreach (string filename in filenames)
+			 	ThreadPool.QueueUserWorkItem(delegate {
+		 			callbacks[index](bus_metadata.Get("Files", filename, registered_fields));
+		 		});
+	 	}
+
+		// result returned as array of [type, uri]
+		public override void SearchForText(string search_string, bool fast, VoidFunction<List<Tuple<string[], File>>> callback)
+		{
+			ThreadPool.QueueUserWorkItem(delegate {
+	            ++cur_search_id;
+
+	            int search_id = cur_search_id;
+
+	            if (!fast)
+	                Thread.Sleep(1000);
+
+	            if (cur_search_id == search_id)
+	            {
+					// the interface for searching using tracker is borken so we need to get 500 to make sure we get some we like...
+					string[][] result = bus_search.TextDetailed(-1, "Files", search_string, 0, 500);
+
+					if (cur_search_id == search_id) {
+
+						List<string> filenames = new List<string>();
+
+						foreach (string[] r in result) {
+
+							System.Console.WriteLine("{0} - {1}", r[0], r[1]);
+				
+							if (r[1] == "Folders") // sigh, skip folders
+								continue;
+
+							filenames.Add(r[0]);
+						}
+						
+						System.Console.WriteLine("search metadata store for {0} files", filenames.Count);
+						
+						meta.get_files_from_paths(filenames, Helpers.RunInMainThread<List<File>>(delegate (List<File> files) {
+
+							System.Console.WriteLine("got {0} files from metadata store", files.Count);
+
+							List<Tuple<string[], File>> real_results = new List<Tuple<string[], File>>();
+
+							foreach (File file in files)
+								real_results.Add(new Tuple<string[], File>(bus_metadata.Get("Files", file.path, registered_fields), file));
+
+							callback(real_results);
+						}));
+					}
+	            }
+	        });
+		}
+	}
+}

Added: trunk/broker/Xesam.cs
==============================================================================
--- (empty file)
+++ trunk/broker/Xesam.cs	Mon Jan  7 10:27:57 2008
@@ -0,0 +1,328 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using NDesk.DBus;
+
+[Interface("org.freedesktop.xesam.Search")]
+public interface IXesamSearch
+{
+    string NewSession();
+    void CloseSession(string id);
+    object GetProperty(string id, string prop);
+    object SetProperty(string id, string prop, object val);
+    string NewSearch(string id, string xml);
+    object[][] GetHits(string id, UInt32 amount);
+    void StartSearch(string id);
+
+    event Nemo.VoidFunction<string, UInt32> HitsAdded;
+    event Nemo.VoidFunction<string> SearchDone;
+}
+
+namespace Nemo
+{
+	public class Xesam : Broker
+	{
+	    private IXesamSearch bus_search;
+	    private Connection con;
+
+	    private bool iterating;
+	    
+	    private string[] supported_mimetypes;
+
+		public Xesam(bool reindex) : base(reindex)
+		{
+			types.Add("height", "xesam:height");
+			types.Add("width", "xesam:width");
+			types.Add("title", "xesam:title");
+			types.Add("pagecount", "xesam:pageCount");
+
+			finished = false;
+			iterating = false;
+			
+			session_id = "";
+			
+	        con = Bus.Session;
+			
+	        ObjectPath opath = new ObjectPath("/org/freedesktop/xesam/searcher/main");
+
+	        bus_search = con.GetObject<IXesamSearch>("org.freedesktop.xesam.searcher", opath);
+
+			bus_search.HitsAdded += hits_callback_handler;
+			bus_search.SearchDone += hits_done_handler;
+			
+	        registered_fields = new string[] { "xesam:url", "xesam:mimeType" }; 
+	        
+	        supported_mimetypes = new string[] { "application/msword", "application/vnd.oasis.opendocument.text",
+	        									 "application/pdf", "application/vnd.ms-excel", "application/vnd.oasis.opendocument.spreadsheet",
+	        									 "application/vnd.sun.xml.writer", "application/vnd.ms-powerpoint", 
+	        									 "application/vnd.oasis.opendocument.presentation", "image/png", "image/jpeg", "image/gif",
+												 "video/mpeg", "video/avi", "video/x-avi", "video/x-matroska", "application/x-bzip-compressed-tar",
+												 "application/x-bzip", "application/x-compressed-tar", "application/x-gzip", "application/zip" };  
+
+			hits_added_callbacks = new Dictionary<string, Callback>();
+			hits_done_callbacks = new Dictionary<string, VoidFunction>();
+
+	        start_iterating();
+		}
+
+		private class Callback
+		{
+			public int number_of_expected_results;
+			public int cur_number_of_results;
+
+			// Hurray for generics...
+		    public delegate void get_results_callback(ref int count, UInt32 amount);
+		    public get_results_callback get_results;
+		    
+			public Callback(int number_of_expected_results, get_results_callback get_results)
+			{
+				cur_number_of_results = 0;
+				this.number_of_expected_results = number_of_expected_results;
+				this.get_results = get_results;
+			}
+			
+			public bool done()
+			{
+				return cur_number_of_results >= number_of_expected_results;
+			}
+		}
+
+		private void hits_callback_handler(string session_id, UInt32 amount)
+		{
+			System.Console.WriteLine("the handler is handling");
+			Callback callback = hits_added_callbacks[session_id];
+			
+			callback.get_results(ref callback.cur_number_of_results, amount);
+		}
+
+		private void hits_done_handler(string session_id)
+		{
+			VoidFunction callback = hits_done_callbacks[session_id];
+			callback();
+			hits_done_callbacks.Remove(session_id);
+		}
+
+		private Dictionary<string, Callback> hits_added_callbacks;
+		private Dictionary<string, VoidFunction> hits_done_callbacks;
+
+		bool finished;
+		
+		string session_id;
+
+	    public void start_iterating() 
+	    {
+	        if (iterating) // re-entrance protection
+	            return;
+
+			ThreadPool.QueueUserWorkItem(delegate(Object stateInfo) {
+	            while (!finished) {
+	                con.Iterate();
+	            }
+			});
+
+	        iterating = true;
+	    }
+
+	    public override void stop() 
+	    {
+	    	stop_broker();
+	        finished = true;
+	        bus_search.CloseSession(session_id); // final iteration
+	        iterating = false;
+	    }
+
+	 	public override void get_metadata(List<string> all_filenames, List<VoidFunction<string[]>> callbacks)
+	 	{
+	 		int offset = 0;
+
+	 		// split into queries of 100 since that's all that beagle will return to us
+	 		foreach (List<string> filenames in Helpers.split_list<string>(all_filenames, 100))
+			{
+				int tmp_offset = offset; // go lambda
+				List<string> tmp_filenames = filenames; // go lambda
+
+				ThreadPool.QueueUserWorkItem(delegate {
+
+					System.Console.WriteLine("trying to get new session id");
+
+					string this_session_id = bus_search.NewSession();
+
+					System.Console.WriteLine("got session id {0} -- registered_fields {1}", this_session_id, registered_fields.Length);
+
+					bus_search.SetProperty(this_session_id, "hit.fields", registered_fields);
+					
+					System.Console.WriteLine("search xesam for {0} files with session id {1}, trying to get {2}", tmp_filenames.Count, this_session_id, tmp_filenames.Count);
+
+					hits_added_callbacks.Add(this_session_id, new Callback(tmp_filenames.Count, delegate(ref int count, UInt32 amount) {
+						System.Console.WriteLine("hits added  in get metadata: {0} - {1}", amount, this_session_id);
+
+						object[][] results = bus_search.GetHits(this_session_id, amount);
+						
+						System.Console.WriteLine("ze hits in get metadata!");
+					
+						foreach (object[] result in results) {
+							string[] s = new string[result.Length];
+							int si = 0;
+							foreach (object r in result)
+								s[si++] = r as string;
+							callbacks[tmp_offset + count](s);
+							++count;
+						}
+					}));
+
+					string xml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+						"<request xmlns=\"http://freedesktop.org/standards/xesam/1.0/query\";>" +
+						"  <query>" +
+						"    <inSet> " +
+						"      <field name=\"xesam:url\"/> ";
+
+					foreach (string filename in tmp_filenames)
+						xml_string += "      <string>" + "file://" + filename + "</string> ";
+
+					xml_string += "    </inSet> ";
+					xml_string += "  </query> ";
+					xml_string += "</request> ";
+
+					System.Console.WriteLine(xml_string);
+
+					hits_done_callbacks.Add(this_session_id, delegate  { 
+						System.Console.WriteLine("closing session {0}", this_session_id);
+						bus_search.CloseSession(this_session_id);
+						hits_added_callbacks.Remove(this_session_id);
+					});
+
+					bus_search.NewSearch(this_session_id, xml_string); 
+
+					bus_search.StartSearch(this_session_id);
+		        });
+
+				offset += 100;
+			}
+	 	}
+
+		// delagates not mighty enough to support yield
+		public static IEnumerable<string> string_start()
+		{
+			while (true)
+				yield return "<string>";
+		}
+
+		public static IEnumerable<string> string_end()
+		{
+			while (true)
+				yield return "</string>";
+		}
+
+		// result returned as array of [type, uri]
+		public override void SearchForText(string search_string, bool fast, VoidFunction<List<Tuple<string[], File>>> callback)
+		{
+			System.Console.WriteLine("searching for text");
+		
+			ThreadPool.QueueUserWorkItem(delegate {
+	            ++cur_search_id;
+
+	            int search_id = cur_search_id;
+
+	            if (!fast)
+	                Thread.Sleep(1000);
+
+				System.Console.WriteLine("searching for text 2");
+
+	            if (cur_search_id == search_id)
+	            {
+					System.Console.WriteLine("new session?");
+            		session_id = bus_search.NewSession();
+					System.Console.WriteLine("just before hit fields are called");
+					bus_search.SetProperty(session_id, "hit.fields", registered_fields);
+					System.Console.WriteLine("got session id {0}", session_id);
+				
+					System.Console.WriteLine("searching for text 3");
+
+					bool got_results = false;
+	
+					hits_added_callbacks.Add(session_id, new Callback(10, delegate(ref int count, UInt32 amount) {
+						System.Console.WriteLine("hits added: {0} - {1}", amount, session_id);
+
+						object[][] result = bus_search.GetHits(session_id, amount);
+						
+						System.Console.WriteLine("ze hits!");
+
+						if (cur_search_id == search_id) {
+
+							System.Console.WriteLine("hits ok");
+
+							List<string> filenames = new List<string>();
+
+							foreach (object[] r in result) {
+								filenames.Add((r[0] as string).Substring(7)); // cut file://
+								System.Console.WriteLine((r[0] as string).Substring(7));
+							}
+							
+							System.Console.WriteLine("search metadata store for {0} files", filenames.Count);
+							
+							meta.get_files_from_paths(filenames, Helpers.RunInMainThread<List<File>>(delegate (List<File> files) {
+
+								System.Console.WriteLine("got {0} files from metadata store", files.Count);
+
+								List<Tuple<string[], File>> real_results = new List<Tuple<string[], File>>();
+
+								int nr = 0;
+
+								foreach (File file in files) {
+									string[] s = new string[result[nr].Length];
+									int si = 0;
+									foreach (object r in result[nr])
+										s[si++] = r as string;
+
+									nr++;
+
+									real_results.Add(new Tuple<string[], File>(s, file));
+								}
+
+								got_results = true;
+
+								callback(real_results);
+								
+								hits_added_callbacks.Remove(session_id);
+							}));
+						}
+					}));
+
+					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);
+					});
+
+					System.Console.WriteLine("yes!");
+
+					string xml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+"<request xmlns=\"http://freedesktop.org/standards/xesam/1.0/query\";>" +
+"  <query>" +
+"    <and> " +
+"    <inSet> " +
+"      <field name=\"mime\"/> " +
+Helpers.reduce_to_string(Helpers.map_strings(string_start(), supported_mimetypes, string_end()))  +
+"    </inSet> " +
+"    <fullText> " +
+"      <string>" + search_string + "</string> " +
+"    </fullText> " +
+"    </and> " +
+"  </query> " +
+"</request> ";
+
+					System.Console.WriteLine(xml_string);
+
+					bus_search.NewSearch(session_id, xml_string);
+
+					bus_search.StartSearch(session_id);
+	            }
+	        });
+		}
+	}
+}

Modified: trunk/common/Common.cs
==============================================================================
--- trunk/common/Common.cs	(original)
+++ trunk/common/Common.cs	Mon Jan  7 10:27:57 2008
@@ -50,6 +50,23 @@
 			w.Close();
 		}
 
+		public static List<List<T>> split_list<T>(List<T> l, int split_size)
+		{
+			List<List<T>> lists = new List<List<T>>();
+
+			int index = 0;
+			while (index < l.Count)
+			{
+				if (index + split_size > l.Count)
+					split_size = l.Count - index; 
+
+				lists.Add(l.GetRange(index, split_size));
+				index += split_size;
+			}
+			
+			return lists;
+		}
+
         public static T[] to_array<T>(List<T> list)
         {
             T[] t = new T[list.Count];
@@ -79,6 +96,63 @@
 		    }
 		}
 
+		static List<IEnumerator<T>> to_enumerators<T>(params IEnumerable<T>[] l)
+		{
+			List<IEnumerator<T>> r = new List<IEnumerator<T>>(); 
+			foreach (IEnumerable<T> i in l)
+				r.Add(i.GetEnumerator());
+			return r;
+		}
+
+		static IEnumerable<bool> to_bool(IEnumerable<IEnumerator<string>> l)
+		{
+            IEnumerator<IEnumerator<string>> i = l.GetEnumerator();
+			while (i.MoveNext())
+				yield return i.Current.MoveNext();
+		}
+
+		static IEnumerable<string> to_value(IEnumerable<IEnumerator<string>> l)
+		{
+            IEnumerator<IEnumerator<string>> i = l.GetEnumerator();
+			while (i.MoveNext())
+				yield return i.Current.Current;
+		}
+
+		public static IEnumerable<string> map_strings(params IEnumerable<string>[] l)
+		{
+			List<IEnumerator<string>> enumerators = to_enumerators<string>(l);
+
+            while (reduce(to_bool(enumerators)))
+                yield return reduce_to_string(to_value(enumerators));
+		}
+
+		public static string reduce_to_string(IEnumerable<string> l)
+		{
+            IEnumerator<string> i = l.GetEnumerator();
+
+			System.Text.StringBuilder builder = new System.Text.StringBuilder();
+
+            while (i.MoveNext())
+                builder.Append(i.Current);
+            
+            return builder.ToString();
+		}
+		
+		public static bool reduce(IEnumerable<bool> l)
+		{
+            IEnumerator<bool> i = l.GetEnumerator();
+
+			bool status = true;
+
+			while (i.MoveNext()) {
+			    status = i.Current;
+			    if (!status)
+				break;
+			}
+            
+            return status;
+		}
+
         public static IEnumerable<Tuple<T1,T2>> zip<T1, T2>(IEnumerable<T1> l1, IEnumerable<T2> l2)
         {
             IEnumerator<T1> i1 = l1.GetEnumerator();

Modified: trunk/common/Configuration.cs
==============================================================================
--- trunk/common/Configuration.cs	(original)
+++ trunk/common/Configuration.cs	Mon Jan  7 10:27:57 2008
@@ -41,6 +41,7 @@
 		public string exclude_dirs;
 		public string exclude_files;
 		public string include_files;
+		public string search_tool;
 		public bool first_run;
 		
 		public void default_values()
@@ -53,6 +54,7 @@
 			exclude_dirs = "/. /CVS/ /CVSROOT/";
 			exclude_files = "~ .db .o";
 			include_files = ".txt .doc .docx .pdf .png .jpg .gif .ppt .xls .xlsx .avi .mpg .mkv .tar.gz .tar.bz2 .zip";
+			search_tool = "tracker";
 			first_run = true;
 		}
 	}

Modified: trunk/gtk-gui/MainWindow.cs
==============================================================================
--- trunk/gtk-gui/MainWindow.cs	(original)
+++ trunk/gtk-gui/MainWindow.cs	Mon Jan  7 10:27:57 2008
@@ -237,14 +237,14 @@
         this.prev_button.UseUnderline = true;
         // Container child prev_button.Gtk.Container+ContainerChild
         Gtk.Alignment w22 = new Gtk.Alignment(0.5F, 0.5F, 0F, 0F);
-        // Container child GtkAlignment.Gtk.Container+ContainerChild
+        // Container child GtkAlignment1.Gtk.Container+ContainerChild
         Gtk.HBox w23 = new Gtk.HBox();
         w23.Spacing = 2;
-        // Container child GtkHBox.Gtk.Container+ContainerChild
+        // Container child GtkHBox1.Gtk.Container+ContainerChild
         Gtk.Image w24 = new Gtk.Image();
         w24.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-go-back", Gtk.IconSize.Menu, 16);
         w23.Add(w24);
-        // Container child GtkHBox.Gtk.Container+ContainerChild
+        // Container child GtkHBox1.Gtk.Container+ContainerChild
         Gtk.Label w26 = new Gtk.Label();
         w26.LabelProp = "";
         w23.Add(w26);
@@ -262,14 +262,14 @@
         this.next_button.UseUnderline = true;
         // Container child next_button.Gtk.Container+ContainerChild
         Gtk.Alignment w31 = new Gtk.Alignment(0.5F, 0.5F, 0F, 0F);
-        // Container child GtkAlignment.Gtk.Container+ContainerChild
+        // Container child GtkAlignment2.Gtk.Container+ContainerChild
         Gtk.HBox w32 = new Gtk.HBox();
         w32.Spacing = 2;
-        // Container child GtkHBox.Gtk.Container+ContainerChild
+        // Container child GtkHBox2.Gtk.Container+ContainerChild
         Gtk.Image w33 = new Gtk.Image();
         w33.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-go-forward", Gtk.IconSize.Menu, 16);
         w32.Add(w33);
-        // Container child GtkHBox.Gtk.Container+ContainerChild
+        // Container child GtkHBox2.Gtk.Container+ContainerChild
         Gtk.Label w35 = new Gtk.Label();
         w35.LabelProp = "";
         w32.Add(w35);
@@ -392,16 +392,10 @@
         this.DefaultWidth = 701;
         this.DefaultHeight = 512;
         this.Show();
-        this.FocusInEvent += new Gtk.FocusInEventHandler(this.GotFocus);
-        this.FocusOutEvent += new Gtk.FocusOutEventHandler(this.FocusLeave);
-        this.KeyReleaseEvent += new Gtk.KeyReleaseEventHandler(this.MainKeyRelease);
-        this.all_files_button.Pressed += new System.EventHandler(this.OnAllFilesPressed);
-        this.starred_button.Pressed += new System.EventHandler(this.OnStarredPressed);
         this.search_input.KeyReleaseEvent += new Gtk.KeyReleaseEventHandler(this.on_key_release);
         this.search_button.Clicked += new System.EventHandler(this.on_search_button_click);
         this.prev_button.Clicked += new System.EventHandler(this.OnPrevious);
         this.next_button.Clicked += new System.EventHandler(this.OnNext);
-        this.today_button.Pressed += new System.EventHandler(this.OnTodayPressed);
         this.day_button.Pressed += new System.EventHandler(this.OnDayClick);
         this.week_button.Pressed += new System.EventHandler(this.OnWeekClick);
         this.month_button.Pressed += new System.EventHandler(this.OnMonthClick);

Modified: trunk/gtk-gui/gui.stetic
==============================================================================
--- trunk/gtk-gui/gui.stetic	(original)
+++ trunk/gtk-gui/gui.stetic	Mon Jan  7 10:27:57 2008
@@ -9,9 +9,6 @@
     <property name="Title" translatable="yes">MainWindow</property>
     <property name="Icon">resource:blue_guy.png</property>
     <property name="WindowPosition">CenterOnParent</property>
-    <signal name="FocusInEvent" handler="GotFocus" />
-    <signal name="FocusOutEvent" handler="FocusLeave" />
-    <signal name="KeyReleaseEvent" handler="MainKeyRelease" />
     <child>
       <widget class="Gtk.HBox" id="main_box">
         <property name="MemberName" />
@@ -30,7 +27,6 @@
                 <property name="UseUnderline">True</property>
                 <property name="Relief">None</property>
                 <property name="Xalign">0</property>
-                <signal name="Pressed" handler="OnAllFilesPressed" />
               </widget>
               <packing>
                 <property name="Position">0</property>
@@ -49,7 +45,6 @@
                 <property name="UseUnderline">True</property>
                 <property name="Relief">None</property>
                 <property name="Xalign">0</property>
-                <signal name="Pressed" handler="OnStarredPressed" />
               </widget>
               <packing>
                 <property name="Position">1</property>
@@ -250,7 +245,6 @@
                         <property name="Type">TextOnly</property>
                         <property name="Label" translatable="yes">Today</property>
                         <property name="UseUnderline">True</property>
-                        <signal name="Pressed" handler="OnTodayPressed" />
                       </widget>
                       <packing>
                         <property name="Position">2</property>

Modified: trunk/gtk/Main.cs
==============================================================================
--- trunk/gtk/Main.cs	(original)
+++ trunk/gtk/Main.cs	Mon Jan  7 10:27:57 2008
@@ -8,26 +8,16 @@
 		public static void Main (string[] args)
 		{
 			Application.Init ();
-			bool reindexing = false;
+
+			bool reindex = false;
+
 			if (args.Length > 0)
 				if (args[0] == "--reindex")
-				{
-					Singleton<Broker>.Instance.reindex_metadata_store();
-					reindexing = true;
-					Singleton<Configuration>.Instance.data.first_run = false;
-					Singleton<Configuration>.Instance.save_configuration();
-				}
+					reindex = true;
 				else
 					System.Console.WriteLine(args[0]);
-
-			if (!reindexing && Singleton<Configuration>.Instance.data.first_run)
-			{
-				Singleton<Broker>.Instance.reindex_metadata_store();
-				Singleton<Configuration>.Instance.data.first_run = false;
-				Singleton<Configuration>.Instance.save_configuration();
-			}
 			
-			MainWindow win = new MainWindow ();
+			MainWindow win = new MainWindow(reindex);
 			win.Show ();
 			Application.Run ();
 		}

Modified: trunk/gtk/MainWindow.cs
==============================================================================
--- trunk/gtk/MainWindow.cs	(original)
+++ trunk/gtk/MainWindow.cs	Mon Jan  7 10:27:57 2008
@@ -11,7 +11,7 @@
 
 public partial class MainWindow: Gtk.Window
 {
-	static private string version = "Nemo 0.1.1 alpha";
+	static private string version = "Nemo 0.2.0 alpha";
 
 	// helper classes
 	Tray tray;
@@ -19,10 +19,14 @@
 	// restrictions
 	CalendarDriver calendar_driver;
 	Categories categories;
+	
+	TypeLabels typelabels;
 
 	bool starred_button_active;
 	
-	public MainWindow (): base ("")
+	private Broker broker;
+	
+	public MainWindow(bool reindex): base ("")
 	{
 		// gettext
 		Mono.Unix.Catalog.Init("nemo", "/usr/share/locale");
@@ -57,13 +61,27 @@
 
 		GtkCommon.tooltip = new Gtk.Tooltips();
 
+		if (Singleton<Configuration>.Instance.data.search_tool == "tracker")
+			broker = new Tracker(reindex);
+		else if (Singleton<Configuration>.Instance.data.search_tool == "xesam")
+			broker = new Xesam(reindex);
+		else {
+			System.Console.WriteLine("unknown search tool token found in configuration: {0}", Singleton<Configuration>.Instance.data.search_tool);
+			throw new Exception("die");
+		}
+
+		System.Console.WriteLine("search tool is: {0}", Singleton<Configuration>.Instance.data.search_tool);
+		
 		// tray
 		tray = new Tray(this);
+		tray.main_quit = delegate {
+			broker.stop();
+		};
 		
 		// helpers
 		starred_button_active = false;
 
-		categories = Singleton<Categories>.Instance;
+		categories = new Categories(broker);
 		categories.set_drawer(new CategoriesDrawer(categories_event_box));
 		calendar_driver = new CalendarDriver(new CalendarDrawer(calendar_event_box, day_button, week_button, month_button, 
 																year_button, today_button, current_date));
@@ -76,8 +94,10 @@
 		// update callbacks
 		categories.set_search_func(do_search);
 
-		Singleton<TypeLabels>.Instance.update_func = update_type_labels;
-		Singleton<TypeLabels>.Instance.search_func = do_search;
+		typelabels = new TypeLabels(broker);
+
+		typelabels.update_func = update_type_labels;
+		typelabels.search_func = do_search;
 
 		calendar_driver.search_func = do_search;
 		calendar_driver.set_active_view = set_active_view;
@@ -85,8 +105,8 @@
 		System.Console.WriteLine("doing initial search");
 		
 		// register result types
-		DocumentItem.set_fields_index(Singleton<Broker>.Instance.RegisterItemType(DocumentItem.ItemTypes()));
-		PictureItem.set_fields_index(Singleton<Broker>.Instance.RegisterItemType(PictureItem.ItemTypes()));
+		DocumentItem.set_fields_index(broker.RegisterItemTypes(DocumentItem.ItemTypes()));
+		PictureItem.set_fields_index(broker.RegisterItemTypes(PictureItem.ItemTypes()));
 	}
 
 	// Tray
@@ -175,7 +195,9 @@
 
     protected void do_search_text(bool quick_search)
     {
-		Singleton<Broker>.Instance.SearchForText(search_input.Text, quick_search, 
+    	System.Console.WriteLine("searching using text");
+    
+		broker.SearchForText(search_input.Text, quick_search, 
 			Helpers.RunInMainThread<List<Tuple<string[], File>>>(delegate (List<Tuple<string[], File>> search_results) {  
 				on_search_text_results(search_results, search_input.Text); 
 			})
@@ -186,13 +208,13 @@
 	{
 		Tuple<DateTime, DateTime> dates = calendar_driver.restriction();
 
-		List<long> types = Singleton<TypeLabels>.Instance.restrictions();
+		List<long> types = typelabels.restrictions();
         List<MetaLabel> keywords = categories.restrictions(); 
 
 		System.Console.WriteLine("searching for results: {0}, {1} keywords, {2} types", search_input.Text, keywords.Count, types.Count);
 		
-		Singleton<Broker>.Instance.Search(keywords, types, dates.first, dates.second, starred_button_active, 
-										  Helpers.RunInMainThread<List<File>>(on_search_results));
+		broker.Search(keywords, types, dates.first, dates.second, starred_button_active, 
+					  Helpers.RunInMainThread<List<File>>(on_search_results));
     }
 
 	protected void on_search_results(List<File> search_results)
@@ -203,15 +225,26 @@
 
 		List<ItemWrapper> items = new List<ItemWrapper>();
 
+		// must be map, dang
+
+		List<string> files = new List<string>();
+		List<VoidFunction<string[]>> callbacks = new List<VoidFunction<string[]>>(); 
+
 		foreach (File file in search_results) 
 		{
 			ItemWrapper wrapper = new ItemWrapper(new Nemo.Item(file));
 			
-			File tmp_file = file; // go lambda bug, go
+			files.Add(file.path);
 			
-			Singleton<Broker>.Instance.get_metadata_from_tracker(tmp_file.path, Helpers.RunInMainThread<string[]>(delegate(string[] result) {
+			callbacks.Add(Helpers.RunInMainThread<string[]>(delegate(string[] result) {
 				
-				if (Nemo.DocumentItem.is_document(result[5]))
+				System.Console.WriteLine("results: {0}", result.Length);
+				System.Console.WriteLine("result: {0}", result[1]);
+
+				foreach (string t in result)
+					System.Console.WriteLine(t);
+
+				if (Nemo.DocumentItem.is_document(result[1]))
 				{
 					Nemo.VoidFunction callback = wrapper.item.on_got_data_from_tracker;
 					
@@ -221,14 +254,13 @@
 						wrapper.item.file.labels.Add(l.metalabel);
 
 					wrapper.item = new Nemo.DocumentItem(wrapper.item.file, result, search_input.Text); 
-					wrapper.item.mime_type = result[5];
 					if (callback != null) {
 						wrapper.item.on_got_data_from_tracker = callback;
 						wrapper.item.on_labels_callback = callback;
 						wrapper.item.on_got_data_from_tracker();
 					}
 				} 
-				else if (Nemo.PictureItem.is_image(result[5])) 
+				else if (Nemo.PictureItem.is_image(result[1])) 
 				{
 					Nemo.VoidFunction callback = wrapper.item.on_got_data_from_tracker;
 
@@ -238,21 +270,22 @@
 						wrapper.item.file.labels.Add(l.metalabel);
 
 					wrapper.item = new Nemo.PictureItem(wrapper.item.file, result); 
-					wrapper.item.mime_type = result[5];
 					if (callback != null) {
 						wrapper.item.on_got_data_from_tracker = callback;
 						wrapper.item.on_labels_callback = callback;
 						wrapper.item.on_got_data_from_tracker();
 					}
 				} else 
-					wrapper.item.mime_type = result[5];
+					wrapper.item.mime_type = result[1];
 			}));
-			
+
 			wrapper.item.search_func = do_search;
 
 			items.Add(wrapper);
 		}
 
+		broker.get_metadata(files, callbacks); 
+
 		calendar_driver.new_elements_in_view(items);
     }
 
@@ -268,21 +301,22 @@
 		{
 			Nemo.Item item;
 			
-			string filename = result.second.path;
+			System.Console.WriteLine("number of values: {0}", result.first.Length);
 			
-			if (DocumentItem.is_document(result.first[5]))
+			if (DocumentItem.is_document(result.first[0]))
 			{
-				item = new DocumentItem(filename, result.first, search_input.Text);
+				item = new DocumentItem(result.second, result.first, search_input.Text);
 				height_left -= 75;
 			} 
-			else if (PictureItem.is_image(result.first[5])) 
+			else if (PictureItem.is_image(result.first[0])) 
 			{
-				item = new PictureItem(filename, result.first);
+				item = new PictureItem(result.second, result.first);
 				height_left -= 55; 
 			} 
 			else 
 			{
-				item = new Nemo.Item(filename, result.first);
+				item = new Nemo.Item(result.second);
+				item.mime_type = result.first[0];
 				height_left -= 55; 
 			}
 
@@ -318,7 +352,7 @@
 
 		foreach (TypeLabel label in labels) 
 		{
-			Gtk.ToggleButton b = label.representation(Singleton<TypeLabels>.Instance);
+			Gtk.ToggleButton b = label.representation(typelabels);
 
        		type_labels.PackStart(b, false, false, 0);
 		}
@@ -370,7 +404,7 @@
 	{
 		search_input.Text = "";
 
-		Singleton<TypeLabels>.Instance.clear_restrictions();
+		typelabels.clear_restrictions();
 		categories.clear_restrictions(); 
 
 		do_search();

Modified: trunk/gtk/Tray.cs
==============================================================================
--- trunk/gtk/Tray.cs	(original)
+++ trunk/gtk/Tray.cs	Mon Jan  7 10:27:57 2008
@@ -116,13 +116,15 @@
 			Singleton<Configuration>.Instance.data.main_window_height = h;
 		}
 		
+		public VoidFunction main_quit;
+		
 		private void OnPopupClick(object o, EventArgs args)
 		{
 			if (!hidden)  
 				save_main_window_pos();
 
 			Singleton<Configuration>.Instance.save_configuration();
-			Singleton<Broker>.Instance.stop();
+			main_quit();
 			Application.Quit();
 		}
 	}

Modified: trunk/metadata/MetadataStore.cs
==============================================================================
--- trunk/metadata/MetadataStore.cs	(original)
+++ trunk/metadata/MetadataStore.cs	Mon Jan  7 10:27:57 2008
@@ -175,6 +175,18 @@
 			return true;
 		}
 
+		private bool directory_is_good(string dir)
+		{
+			foreach (string v in exclude_dirs)
+				if (dir.Contains(v))
+					return false;
+
+			// regex slow
+			// return include_regex.IsMatch(filename) && !exclude_regex.IsMatch(filename);
+
+			return true;
+		}
+
 		private void watcher_runner()
 		{
 			watcher = new FileSystemWatcher(watch_path);
@@ -758,13 +770,23 @@
         
         private void db_sync_with_filesystem(string directory_path)
         {
+        	// performance
+        	database.start_transaction();
+        
             // fix files in this dir
             db_sync_directory_with_filesystem(directory_path);
             
+        	database.end_transaction();
+
             // then recurse
             string[] subdirs = Directory.GetDirectories(directory_path);
             foreach (string subdir in subdirs) {
+
+            	if (!directory_is_good(subdir))
+					continue;
+
             	string tmp_subdir = subdir;
+
 	            if ((System.IO.File.GetAttributes(subdir) & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
 					add_low_priority_db_work(delegate() { db_sync_with_filesystem(tmp_subdir); } );
 			}
@@ -806,7 +828,7 @@
                         }
                     }
                 }
-                catch (SqliteSyntaxException) {
+                catch (Exception) {
                 }
 
                 if (version == 0) {
@@ -821,6 +843,26 @@
             db_connection.Close();
         }
 
+		IDbTransaction current_transaction;
+		
+		public void start_transaction()
+		{
+			if (current_transaction != null) {
+				System.Console.WriteLine("double begin transaction");
+				throw new Exception("die");
+			}
+		
+			current_transaction = db_connection.BeginTransaction();
+		}
+
+		public void end_transaction()
+		{
+			if (current_transaction != null) {
+				current_transaction.Commit();
+				current_transaction = null;
+			}
+		}		
+
         public IDbCommand get_command()
         {
             return db_connection.CreateCommand();
@@ -924,7 +966,7 @@
         
         private void add_par(IDbCommand cmd, string name, DbType type, object value)
         {
-            SqliteParameter p = (SqliteParameter) cmd.CreateParameter();
+            SqliteParameter p = cmd.CreateParameter() as SqliteParameter;
             p.ParameterName = name;
             p.DbType = type;
             p.Value = value;
@@ -987,8 +1029,8 @@
                     
                 cmd.Parameters.Clear();
                 add_par(cmd, "@path", DbType.String, path);
-                add_par(cmd, "@last_accessed", DbType.DateTime, last_accessed);
-                add_par(cmd, "@last_modified", DbType.DateTime, last_modified);
+                add_par(cmd, "@last_accessed", DbType.Int64, last_accessed.ToFileTime());
+                add_par(cmd, "@last_modified", DbType.Int64, last_modified.ToFileTime());
                 add_par(cmd, "@size", DbType.Int64, size);
                 add_par(cmd, "@filetype_id", DbType.Int64, filetype_id);
                 System.Console.WriteLine("inserting {0}", path);
@@ -1021,8 +1063,8 @@
                     "where id = @id";
                 cmd.Parameters.Clear();
                 add_par(cmd, "@id", DbType.Int64, id);
-                add_par(cmd, "@last_accessed", DbType.DateTime, last_accessed);
-                add_par(cmd, "@last_modified", DbType.DateTime, last_modified);
+                add_par(cmd, "@last_accessed", DbType.Int64, last_accessed.ToFileTime());
+                add_par(cmd, "@last_modified", DbType.Int64, last_modified.ToFileTime());
                 add_par(cmd, "@size", DbType.Int64, size);
                 add_par(cmd, "@filetype_id", DbType.Int64, filetype_id);
                 System.Console.WriteLine("updating {0}", path);
@@ -1534,7 +1576,7 @@
                 using (IDataReader reader = cmd.ExecuteReader()) {
 	                while (reader.Read()) {
     	                Tuple<FileTypeCategory, int> t;
-    	                t.first = (FileTypeCategory) reader.GetInt32(0);
+    	                t.first = (FileTypeCategory)reader.GetInt32(0);
     	                t.second = reader.GetInt32(1);
     	                res.Add(t);
     	            }

Modified: trunk/nemo.mdp
==============================================================================
--- trunk/nemo.mdp	(original)
+++ trunk/nemo.mdp	Mon Jan  7 10:27:57 2008
@@ -98,6 +98,8 @@
     <File name="dbus/UnixNativeTransport.cs" subtype="Code" buildaction="Compile" />
     <File name="dbus/UnixTransport.cs" subtype="Code" buildaction="Compile" />
     <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" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
@@ -123,4 +125,4 @@
     <ProjectRefVar />
   </MonoDevelop.Autotools.MakefileInfo>
   <GtkDesignInfo gtkVersion="2.10.2" />
-</Project>
+</Project>
\ No newline at end of file

Modified: trunk/uicommon/Categories.cs
==============================================================================
--- trunk/uicommon/Categories.cs	(original)
+++ trunk/uicommon/Categories.cs	Mon Jan  7 10:27:57 2008
@@ -107,11 +107,14 @@
 			drawer.set_categories(categories);
 		}
 		
-		private Categories()
+		public Categories(Broker broker)
 		{
 			categories = new List<Category>();
 
-			Singleton<Broker>.Instance.get_all_labels(Helpers.RunInMainThread<List<MetaLabel>>(got_labels));	
+			if (broker == null)
+				System.Console.WriteLine("boo boo");
+
+			broker.get_all_labels(Helpers.RunInMainThread<List<MetaLabel>>(got_labels));	
 		}
 	}
 }

Modified: trunk/uicommon/DocumentItem.cs
==============================================================================
--- trunk/uicommon/DocumentItem.cs	(original)
+++ trunk/uicommon/DocumentItem.cs	Mon Jan  7 10:27:57 2008
@@ -33,19 +33,10 @@
 			parse_fields_and_update(fields);
 		}
         
-		public DocumentItem(string path, string[] fields, string search_text) : base(path, fields)
-		{
-			on_snippet_callback = null;
-		
-			populate(search_text);
-
-			parse_fields_and_update(fields);
-		}
-
         // Broker specific
         public static string[] ItemTypes()
         {
-        	return new string[] { "Doc:Title", "Doc:PageCount" };
+        	return new string[] { "title", "pagecount" };
         }
         
 		// used when parsing the fields array returned from broker
@@ -58,6 +49,8 @@
         
         private void parse_fields_and_update(string[] fields)
         {
+        	mime_type = fields[1];
+
 			set_title(fields[fields_index]);
 
 			display_item = new DisplayDocumentItem(pages, title, this);
@@ -69,11 +62,13 @@
         
 		protected void populate(string search_text)
 		{
+#if false
 			if (search_text != "") {
 				Singleton<Broker>.Instance.search_snippet(path, search_text, 
 														  Helpers.RunInMainThread<string>(on_snippet_result));
 			} else
 				Singleton<Broker>.Instance.get_text(path, Helpers.RunInMainThread<string>(on_snippet_result));
+#endif
  		}
         
         protected int set_page_count(string page_count)

Modified: trunk/uicommon/PictureItem.cs
==============================================================================
--- trunk/uicommon/PictureItem.cs	(original)
+++ trunk/uicommon/PictureItem.cs	Mon Jan  7 10:27:57 2008
@@ -25,15 +25,10 @@
 			parse_fields_and_update(fields);
 		}
         
-		public PictureItem(string path, string[] fields) : base(path, fields)
-		{
-			parse_fields_and_update(fields);
-		}
-
         // Broker specific
         public static string[] ItemTypes()
         {
-        	return new string[] { "Image:Height", "Image:Width" };
+        	return new string[] { "width", "height" };
         }
         
 		// used when parsing the fields array returned from broker
@@ -46,11 +41,18 @@
         
         private void parse_fields_and_update(string[] fields)
         {
+        	mime_type = fields[1];
+        	
 			height = fields[fields_index];
 			width = fields[fields_index+1];
 			
+//			foreach (string t in fields)
+//				System.Console.WriteLine(t);
+			
 			string resolution = width + "x" + height;
 			
+        	System.Console.WriteLine("resolution for file {0} is {1}", file.path, resolution);
+        
 			display_item = (DisplayItem) new DisplayPictureItem(resolution, this);
 			register_starred_change(display_item.update_starred);
 			display_item.set_labels();

Modified: trunk/uicommon/TypeLabels.cs
==============================================================================
--- trunk/uicommon/TypeLabels.cs	(original)
+++ trunk/uicommon/TypeLabels.cs	Mon Jan  7 10:27:57 2008
@@ -95,11 +95,11 @@
 			search_func();
 		}
 
-        private TypeLabels() 
+        public TypeLabels(Broker broker) 
         {
             labels = new List<TypeLabel>();
 			
-            Singleton<Broker>.Instance.get_type_labels(Helpers.RunInMainThread<List<Tuple<FileTypeCategory, int>>>(on_broker_labels_result));
+            broker.get_type_labels(Helpers.RunInMainThread<List<Tuple<FileTypeCategory, int>>>(on_broker_labels_result));
         }
     }
 }



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