beagle r4792 - trunk/beagle/search/Beagle.Search



Author: dbera
Date: Sun Jun 29 16:09:33 2008
New Revision: 4792
URL: http://svn.gnome.org/viewvc/beagle?rev=4792&view=rev

Log:
An attempt to address the "too many matches" problem. Replace the oft-unnoticed/multiple-choice scope menu by a short(!) combo box displaying the common search scopes. In the earlier implementation the selected scope menu was used to filter results after a query against all data. In this implementation, use the scope option to search against only the selected type of data. Remove the use of TypeFilter.cs which was asked in the FIXME "it would be nicer to create QueryParts to do the filtering beagled-side".

One problem with this approach is that there are just too many categories (currently ~ 15). Ideally, only the most common categories can be put here and the rest moved to the "Custom search" dialog. Oh right, someone has to create the Custom-search/Advanced-search dialog.

To allow users to add custom scopes, use the environment variables BEAGLE_SCOPE="label1=query-string1;label2=query-string2" and the appropriate query-string is appended to the query when one of these labels are selected in the combobox.


Modified:
   trunk/beagle/search/Beagle.Search/SearchWindow.cs
   trunk/beagle/search/Beagle.Search/UIManager.cs

Modified: trunk/beagle/search/Beagle.Search/SearchWindow.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search/SearchWindow.cs	(original)
+++ trunk/beagle/search/Beagle.Search/SearchWindow.cs	Sun Jun 29 16:09:33 2008
@@ -30,6 +30,7 @@
 		private Gtk.Tooltips tips;
 		private Gtk.Notebook pages;
 		private Gtk.Statusbar statusbar;
+		private Gtk.ComboBox scope_list;
 
 		private Beagle.Search.UIManager uim;
 		private Beagle.Search.NotificationArea notification_area;
@@ -44,9 +45,7 @@
 		private Beagle.Search.Pages.StartDaemon startdaemon;
 		private Beagle.Search.Pages.NoMatch nomatch;
 
-		private Beagle.Search.ScopeType scope = ScopeType.Everything;
 		private Beagle.Search.SortType sort = SortType.Modified;
-		private Beagle.Search.TypeFilter filter = null;
 		private QueryDomain domain = QueryDomain.Local | QueryDomain.System; // default
 
 		// Whether we should grab focus from the text entry
@@ -60,6 +59,57 @@
 
 		public event QueryEventDelegate QueryEvent;
 
+		private struct ScopeMapping {
+			internal string label;
+			internal string query_mapping;
+			internal ScopeMapping (string label, string query_mapping)
+			{
+				this.label = label;
+				this.query_mapping = query_mapping;
+			}
+		};
+		private static List<ScopeMapping> scope_mappings;
+
+		static SearchWindow ()
+		{
+			// FIXME: Currently hardcoded list is bit too long! Need to hire some usability expert.
+			scope_mappings = new List<ScopeMapping> (16);
+
+			/* Translators: This labels are used in a combo-box to allow
+			 * the user to select which kind of data he wants to search.
+			 */
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("All"), String.Empty)); // Default search scope. Should be at the first
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("My Files"), "source:Files"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Applications"), "filetype:application OR source:applications"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Documents"), "filetype:document"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Pictures"), "filetype:image"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Media"), "filetype:audio OR filetype:video"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Source Code"), "filetype:source"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Archives"), "inarchive:true"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Emails"), "type:MailMessage OR filetype:mail"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("News Feeds"), "type:FeedItem"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Websites"), "type:WebHistory OR type:Bookmark"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Chat Logs"), "type:IMLog"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Contacts"), "type:Contact"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Notes"), "type:Note"));
+			scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Calendar Events"), "type:Task OR type:Calendar"));
+			//scope_mappings.Add (new ScopeMapping (Catalog.GetString ("Custom"), ""));
+
+			// Allow users to define custom scope choices by defining envirionment var:
+			// export BEAGLE_SCOPE="mymusic=source:music;win=tag:windows";
+			string user_scopes = Environment.GetEnvironmentVariable ("BEAGLE_SCOPE");
+			if (String.IsNullOrEmpty (user_scopes))
+				return;
+
+			string[] user_scope_list = user_scopes.Split (';');
+			foreach (string s in user_scope_list) {
+				string[] key_value = s.Split ('=');
+				if (key_value.Length != 2)
+					continue;
+				scope_mappings.Add (new ScopeMapping (key_value [0], key_value [1]));
+			}
+		}
+
 		public SearchWindow (ISearch search) : base (WindowType.Toplevel)
 		{
 			this.search = search;
@@ -75,7 +125,6 @@
 
 			uim = new UIManager (this);
 			uim.DomainChanged += OnDomainChanged;
-			uim.ScopeChanged += OnScopeChanged;
 			uim.SortChanged += OnSortChanged;
 			uim.ToggleDetails += OnToggleDetails;
 			uim.ShowQuickTips += OnShowQuickTips;
@@ -84,9 +133,24 @@
 
 			HBox hbox = new HBox (false, 6);
 			
-			Label label = new Label (Catalog.GetString ("_Find:"));
+			Label label = new Label (Catalog.GetString ("_Find in:"));
 			hbox.PackStart (label, false, false, 0);
 			
+			scope_list = ComboBox.NewText ();
+			foreach (ScopeMapping mapping in scope_mappings)
+				scope_list.AppendText (mapping.label);
+			scope_list.Active = 0;
+
+			scope_list.Changed += new EventHandler (delegate (object o, EventArgs args) {
+									ComboBox combo = o as ComboBox;
+									if (o == null)
+										return;
+									int active = combo.Active;
+									Log.Debug ("Scope changed: {0} maps to '{1}'", combo.ActiveText, scope_mappings [active].query_mapping);
+									Query (true);
+								});
+			hbox.PackStart (scope_list, false, false, 0);
+
 			entry = new Entry ();
 			entry.Activated += OnEntryActivated;
 			hbox.PackStart (entry, true, true, 0);
@@ -160,7 +224,6 @@
 
 			view = new GroupView ();
 			view.TileSelected += ShowInformation;
-			view.CategoryToggled += OnCategoryToggled;
 			panes.MainContents = view;
 
 			this.statusbar = new Gtk.Statusbar ();
@@ -228,10 +291,8 @@
 			if (QueryEvent != null)
 				QueryEvent (query);
 
-			filter = TypeFilter.MakeFilter (ref query);
-
 			view.Clear ();
-			view.Scope = scope;
+			view.Scope = ScopeType.Everything;
 			view.SortType = sort;
 			pages.CurrentPage = pages.PageNum (panes);
 
@@ -261,6 +322,11 @@
 					current_query.AddPart (part);
 				}
 
+				// set scope from scope list
+				ScopeMapping mapping = scope_mappings [scope_list.Active];
+				if (! String.IsNullOrEmpty (mapping.query_mapping))
+					current_query.AddText (mapping.query_mapping);
+
 				current_query.SendAsync ();
 
 				spinner.Start ();
@@ -309,30 +375,6 @@
 			args.RetVal = true;
 		}
 
-		private void OnScopeChanged (ScopeType toggled, bool active)
-		{
-			if (active) {
-				view.Scope = scope = scope | toggled;
-			} else {
-				view.Scope = scope = scope ^ toggled;
-			}
-			
-			CheckNoMatch ();
-		}
-		
-		private void OnCategoryToggled (ScopeType toggled)
-		{
-			string name =  ScopeType.GetName (typeof (ScopeType), toggled);
-
-			try {
-				ToggleAction act = (ToggleAction) uim.GetAction ("/ui/MenuBar/Search/Scope/" +  name);
-				act.Active = !act.Active;
-			} catch (Exception e) {
-				Console.WriteLine ("Exception caught when trying to deactivate menu entry {0}:",name);
-				Console.WriteLine (e);
-			}
-		}
-		
 		private void OnSortChanged (SortType value)
 		{
 			view.SortType = sort = value;
@@ -407,9 +449,6 @@
 					continue;
 				}
 
-				if (filter != null && !filter.Filter (tile))
-					continue;
-
 				view.AddHit (tile);
 
 				if (pages.CurrentPageWidget != panes)

Modified: trunk/beagle/search/Beagle.Search/UIManager.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search/UIManager.cs	(original)
+++ trunk/beagle/search/Beagle.Search/UIManager.cs	Sun Jun 29 16:09:33 2008
@@ -8,6 +8,7 @@
 
 namespace Beagle.Search {
 
+	//FIXME: This way of handling scope needs to change since now we provide a direct combo box to set query scope
 	[Flags]
 	public enum ScopeType : ushort {
 		Nothing       = 0,
@@ -37,7 +38,7 @@
 		
 		private Gtk.ActionGroup actions;
 		private Gtk.RadioActionEntry[] sort_entries;
-		private Gtk.ToggleActionEntry[] scope_entries, view_entries, domain_entries;
+		private Gtk.ToggleActionEntry[] view_entries, domain_entries;
 
 		public UIManager (SearchWindow search)
 		{
@@ -63,9 +64,6 @@
 				new ActionEntry ("Search", null,
 						 Catalog.GetString ("_Search"),
 						 null, null, null),
-				new ActionEntry ("Scope", null,
-						 Catalog.GetString ("Show _Categories"),
-						 null, null, null),
 				new ActionEntry ("Domain", null,
 						 Catalog.GetString ("Search _Domains"),
 						 null, null, null),
@@ -113,100 +111,6 @@
 			};
 			actions.Add (entries);
 
-			Gtk.ActionEntry[] multiscope_entries = new ActionEntry[] {
-				new ActionEntry ("All", null,
-						 Catalog.GetString ("_All"),
-						 null, null,
-						 delegate {
-							 if (ScopeChanged != null)
-								 ScopeChanged (ScopeType.Everything, true);
-
-							 foreach (ToggleActionEntry t in scope_entries)
-								 ((ToggleAction) actions [t.name]).Active = true;
-						 }),
-				new ActionEntry ("None", null,
-						 Catalog.GetString ("_None"),
-						 null, null,
-						 delegate {
-							 if (ScopeChanged != null)
-								 ScopeChanged (ScopeType.Nothing, true);
-
-							 foreach (ToggleActionEntry t in scope_entries)
-								 ((ToggleAction) actions [t.name]).Active = false;
-						 })
-			};
-			actions.Add (multiscope_entries);
-
-			scope_entries = new ToggleActionEntry[] {
-				new ToggleActionEntry ("Applications", null,
-						      Catalog.GetString ("A_pplications"),
-						      null,
-						      Catalog.GetString ("Search applications"),
-						      OnScopeChanged,
-						      true),
-				new ToggleActionEntry ("Contacts", null,
-						      Catalog.GetString ("_Contacts"),
-						      null,
-						      Catalog.GetString ("Search contacts"),
-						      OnScopeChanged,
-						      true),
-				new ToggleActionEntry ("Calendar", null,
-						      Catalog.GetString ("Ca_lendar events"),
-						      null,
-						      Catalog.GetString ("Search calendar events"),
-						      OnScopeChanged,
-						      true),
-				new ToggleActionEntry ("Documents", null,
-						      Catalog.GetString ("_Documents"),
-						      null,
-						      Catalog.GetString ("Search documents"),
-						      OnScopeChanged,
-						      true),
-				new ToggleActionEntry ("Conversations", null,
-						      Catalog.GetString ("Conve_rsations"),
-						      null,
-						      Catalog.GetString ("Search E-Mail and Instant Messaging logs"),
-						      OnScopeChanged,
-						      true),
-				new ToggleActionEntry ("Images", null,
-						      Catalog.GetString ("_Images"),
-						      null,
-						      Catalog.GetString ("Search images"),
-						      OnScopeChanged,
-						      true),
-				new ToggleActionEntry ("Media", null,
-						      Catalog.GetString ("_Media"),
-						      null,
-						      Catalog.GetString ("Search sound and video files"),
-						      OnScopeChanged,
-						      true),
-				new ToggleActionEntry ("Folders", null,
-						      Catalog.GetString ("_Folders"),
-						      null,
-						      Catalog.GetString ("Search for folder names"),
-						      OnScopeChanged,
-						      true),
-				new ToggleActionEntry ("Websites", null,
-						      Catalog.GetString ("_Websites"),
-						      null,
-						      Catalog.GetString ("Search website history"),
-						      OnScopeChanged,
-						      true),
-				new ToggleActionEntry ("Feeds", null,
-						      Catalog.GetString ("_News Feeds"),
-						      null,
-						      Catalog.GetString ("Search news feeds"),
-						      OnScopeChanged,
-						      true),
-				new ToggleActionEntry ("Archives", null,
-						      Catalog.GetString ("A_rchives"),
-						      null,
-						      Catalog.GetString ("Search files in Archives"),
-						      OnScopeChanged,
-						      true)
-			};
-			actions.Add (scope_entries);
-
 			sort_entries = new RadioActionEntry[] {
 				new RadioActionEntry ("SortModified", null,
 						      Catalog.GetString ("Sort by Date _Modified"), null,
@@ -275,9 +179,6 @@
 
 				actions ["QuickTips"].Sensitive = value;
 
-				foreach (Gtk.ToggleActionEntry rae in scope_entries)
-					actions [rae.name].Sensitive = value;
-
 				foreach (Gtk.RadioActionEntry rae in sort_entries)
 					actions [rae.name].Sensitive = value;
 			}
@@ -287,22 +188,6 @@
 		"<ui>" +
 		"  <menubar name='MenuBar'>" +
 		"    <menu action='Search'>" +
-		"      <menu action='Scope'>" +
-		"        <menuitem action='All'/>" +
-		"        <menuitem action='None'/>" +
-		"        <separator/>" +
-		"        <menuitem action='Applications'/>" +
-		"        <menuitem action='Contacts'/>" +
-		"        <menuitem action='Calendar'/>" +
-		"        <menuitem action='Documents'/>" +
-		"        <menuitem action='Conversations'/>" +
-		"        <menuitem action='Images'/>" +
-		"        <menuitem action='Media'/>" +
-		"        <menuitem action='Folders'/>" +
-		"        <menuitem action='Websites'/>" +
-		"        <menuitem action='Feeds'/>" +
-		"        <menuitem action='Archives'/>" +
-		"      </menu>" +
 		"      <menu action='Domain'>" +
 		"        <menuitem action='Local'/>" +
 		"        <menuitem action='System'/>" +
@@ -387,11 +272,13 @@
 			Gdk.Pixbuf logo = WidgetFu.LoadThemeIcon ("system-search", 48);
 
 			string[] people = new string[] { "Anna Dirks <anna novell com>",
+							 "Dan Winship <danw novell com>",
+							 "D Bera <dbera web gmail com>",
 							 "Fredrik Hedberg <fredrik avafan com>",
-							 "Lukas Lipka <lukaslipka gmail com>",
 							 "Joe Shaw <joeshaw novell com>", 
 							 "Jakub Steiner <jimmac novell com>",
-							 "Dan Winship <danw novell com>" };
+							 "Lukas Lipka <lukaslipka gmail com>",
+					    };
 			
 #pragma warning disable 612 // don't warn that Gnome.About is deprecated
 			Gnome.About about = new Gnome.About ("Beagle Search",
@@ -413,18 +300,6 @@
 				FocusSearchEntry ();
 		}
 
-		public delegate void ScopeChangedDelegate (ScopeType scope, bool active);
-		public event ScopeChangedDelegate ScopeChanged;
-
-		private void OnScopeChanged (object o, EventArgs args)
-		{
-			if (ScopeChanged == null)
-				return;
-
-			ScopeType scope = (ScopeType) System.Enum.Parse (typeof (ScopeType), ((Gtk.Action) o).Name);
-			ScopeChanged (scope, ((ToggleAction) o).Active);
-		}
-
 		public delegate void SortChangedDelegate (SortType scope);
 		public event SortChangedDelegate SortChanged;
 



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