beagle r4490 - in trunk/beagle/search: . Beagle.Search Beagle.Search.Tiles



Author: llipka
Date: Fri Feb 15 14:21:49 2008
New Revision: 4490
URL: http://svn.gnome.org/viewvc/beagle?rev=4490&view=rev

Log:
A very basic implementation of instance management.

Added:
   trunk/beagle/search/Beagle.Search/SearchWindow.cs
      - copied, changed from r4479, /trunk/beagle/search/Beagle.Search/Search.cs
Modified:
   trunk/beagle/search/Beagle.Search.Tiles/Tile.cs
   trunk/beagle/search/Beagle.Search/Driver.cs
   trunk/beagle/search/Beagle.Search/ISearch.cs
   trunk/beagle/search/Beagle.Search/Search.cs
   trunk/beagle/search/Beagle.Search/UIManager.cs
   trunk/beagle/search/Makefile.am

Modified: trunk/beagle/search/Beagle.Search.Tiles/Tile.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search.Tiles/Tile.cs	(original)
+++ trunk/beagle/search/Beagle.Search.Tiles/Tile.cs	Fri Feb 15 14:21:49 2008
@@ -1,5 +1,11 @@
+//
+// Tile.cs
+//
+// Copyright (C) 2008 Lukas Lipka <lukaslipka gmail com>
+//
+
 using System;
-using System.Collections;
+using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using System.Text.RegularExpressions;
 using System.Diagnostics;
@@ -13,20 +19,51 @@
 
 	public abstract class Tile : Gtk.EventBox {
 
+		private Beagle.Hit hit = null;
+		private Beagle.Query query = null;
+
+		private Gtk.HBox hbox = null;
+		private Gtk.Image icon = null;
+		private DetailsPane details = null;
+
+		private string title = null;
+		private string snippet = null;
+		private DateTime timestamp;
+		private double score = 0.0f;
+
+		// Default the tile group to documents, it is up
+		// to the each tile to set a specific group.
+
+		private TileGroup group = TileGroup.Documents;
+
+		// DND targets
+
+		static Gtk.TargetEntry[] targets = new Gtk.TargetEntry[] {
+			new Gtk.TargetEntry ("text/uri-list", 0, 0)
+		};
+
+		private List<TileAction> actions = new List<TileAction> ();
+
+		protected bool EnableOpenWith = false;
+
+		public event EventHandler Selected;
+
+		public delegate void GotSnippetHandler (string snippet);
+		public event GotSnippetHandler GotSnippet;
+
 		public Tile (Hit hit, Query query) : base ()
 		{
-			AboveChild = true;
-			AppPaintable = true;
-			CanFocus = true;
+			base.AboveChild = true;
+			base.AppPaintable = true;
+			base.CanFocus = true;
 
 			this.hit = hit;
 			this.timestamp = hit.Timestamp;
 			this.score = hit.Score;
 			this.query = query;
-			this.group = TileGroup.Documents;
 
-			Gtk.Drag.SourceSet (this, Gdk.ModifierType.Button1Mask,
-					    targets, Gdk.DragAction.Copy | Gdk.DragAction.Move);
+			Gtk.Drag.SourceSet (this, Gdk.ModifierType.Button1Mask, targets,
+					    Gdk.DragAction.Copy | Gdk.DragAction.Move);
 
 			hbox = new Gtk.HBox (false, 5);
 			hbox.BorderWidth = 2;
@@ -34,63 +71,57 @@
 
 			icon = new Gtk.Image ();
 			icon.Show ();
-			HBox.PackStart (icon, false, false, 0);
+			hbox.PackStart (icon, false, false, 0);
 
 			Add (hbox);
 		}
 
-		private Beagle.Hit hit;
-		public Beagle.Hit Hit {
-			get { return hit; }
-		}
-
-		private Beagle.Query query;
-		public Beagle.Query Query {
-			get { return query; }
+		protected void AddAction (TileAction action)
+		{
+			actions.Add (action);
 		}
 
-		private TileGroup group;
-		public TileGroup Group {
-			get { return group; }
-			set { group = value; }
+		protected void RemoveAction (TileAction action)
+		{
+			actions.Remove (action);
 		}
 
-		private Gtk.HBox hbox;
-		protected Gtk.HBox HBox { 
-			get { return hbox; }
-		}
+		private void ShowPopupMenu ()
+		{
+			Gtk.Menu menu = new Gtk.Menu ();
+			
+			// Add the default 'Open' menu item
 
-		private Gtk.Image icon;
-		public Gtk.Image Icon {
-			get { return icon; }
-			set { icon = value; }
-		}
+			TileAction open = new TileAction (Catalog.GetString ("Open"), Stock.Open, Open);
 
-		private string title;
-		public virtual string Title {
-			get { return title; }
-			set { title = value; }
-		}
+			ActionMenuItem open_menu_item = new ActionMenuItem (open);
+			menu.Append (open_menu_item);
 
-		private DateTime timestamp;
-		public virtual DateTime Timestamp {
-			get { return timestamp; }
-			set { timestamp = value; }
-		}
+#if ENABLE_OPEN_WITH
+			if (EnableOpenWith) {
+				// FIXME: Not sure if going with the parent is
+				// the right thing to do in all cases.
+				string mimetype = Utils.GetFirstPropertyOfParent (hit, "beagle:MimeType");
 
-		private double score;
-		public virtual double Score {
-			get { return score; }
-			set { score = value; }
-		}
+				OpenWithMenu owm = new OpenWithMenu (mimetype);
+				owm.ApplicationActivated += OpenWith;
+				owm.AppendToMenu (menu);
+			}
+#endif
 
-		protected bool EnableOpenWith = false;
+			if (Actions.Count > 0) {
+				SeparatorMenuItem separator = new SeparatorMenuItem ();
+				menu.Append (separator);
 
-		static Gtk.TargetEntry[] targets = new Gtk.TargetEntry[] {
-			new Gtk.TargetEntry ("text/uri-list", 0, 0)
-		};
+				foreach (TileAction action in Actions) {
+					ActionMenuItem item = new ActionMenuItem (action);
+					menu.Append (item);
+				}
+			}
 
-		public event EventHandler Selected;
+			menu.ShowAll ();
+			menu.Popup ();
+		}
 
 		protected override void OnDragBegin (Gdk.DragContext context)
 		{
@@ -100,34 +131,31 @@
 			WidgetFu.SetDragImage (context, icon);
 		}
 
-		protected override void OnDragDataGet (Gdk.DragContext dragContext,
-						       Gtk.SelectionData selectionData,
-						       uint info, uint time)
+		protected override void OnDragDataGet (Gdk.DragContext ctx, Gtk.SelectionData data, uint info, uint time)
 		{
-			byte[] data = System.Text.Encoding.UTF8.GetBytes (Hit.EscapedUri + "\r\n");
-			selectionData.Set (selectionData.Target, 8, data);
+			byte[] uri = System.Text.Encoding.UTF8.GetBytes (Hit.EscapedUri + "\r\n");
+			data.Set (data.Target, 8, uri);
 		}
 
 		protected override void OnSizeRequested (ref Gtk.Requisition req)
 		{
-			// FIXME: "base.OnSizeRequested (ref req)" should work,
+			// base.OnSizeRequested (ref req) should work,
 			// but it doesn't
 			req = hbox.SizeRequest ();
 
-			int pad = (int)StyleGetProperty ("focus-line-width") +
-				(int)StyleGetProperty ("focus-padding") + 1;
+			int pad = (int)StyleGetProperty ("focus-line-width") + (int)StyleGetProperty ("focus-padding") + 1;
+
 			req.Width += 2 * (pad + Style.Xthickness);
 			req.Height += 2 * (pad + Style.Ythickness);
 		}
 
 		protected override void OnSizeAllocated (Gdk.Rectangle alloc)
 		{
-			int pad = (int)StyleGetProperty ("focus-line-width") +
-				(int)StyleGetProperty ("focus-padding") + 1;
+			int pad = (int)StyleGetProperty ("focus-line-width") + (int)StyleGetProperty ("focus-padding") + 1;
 
 			alloc.X += pad + Style.Xthickness;
-			alloc.Width -= pad + Style.Xthickness;
 			alloc.Y += pad + Style.Ythickness;
+			alloc.Width -= pad + Style.Xthickness;
 			alloc.Height -= pad + Style.Ythickness;
 
 			base.OnSizeAllocated (alloc);
@@ -156,8 +184,7 @@
 				int y = focus_padding + Style.Ythickness;
 				int width = Allocation.Width - 2 * (focus_padding + Style.Xthickness);
 				int height = Allocation.Height - 2 * (focus_padding + Style.Ythickness);
-				Style.PaintFocus (Style, GdkWindow, State, evt.Area, this,
-						  null, x, y, width, height);
+				Style.PaintFocus (Style, GdkWindow, State, evt.Area, this, null, x, y, width, height);
 			}
 			
 			CairoFu.DisposeContext (gr);
@@ -168,62 +195,20 @@
 			return false;
 		}
 
-		///////////////////////////////////////////////////
-
-		public ArrayList actions = new ArrayList ();
-		public ICollection Actions {
-			get { return actions; }
-		}
-
-		protected void AddAction (TileAction action)
-		{
-			actions.Add (action);
-		}
-
-		private void ShowPopupMenu ()
-		{
-			Gtk.Menu menu = new Gtk.Menu ();
-
-			ActionMenuItem mi = new ActionMenuItem (new TileAction (Catalog.GetString ("Open"), Stock.Open, Open));
-			menu.Append (mi);
-
-#if ENABLE_OPEN_WITH
-			if (EnableOpenWith) {
-				// FIXME: Not sure if going with the parent is
-				// the right thing to do in all cases.
-				OpenWithMenu owm = new OpenWithMenu (Utils.GetFirstPropertyOfParent (hit, "beagle:MimeType"));
-				owm.ApplicationActivated += OpenWith;
-				owm.AppendToMenu (menu);
-			}
-#endif
-
-			if (Actions.Count > 0) {
-				SeparatorMenuItem si = new SeparatorMenuItem ();
-				menu.Append (si);
-
-				foreach (TileAction action in Actions) {
-					mi = new ActionMenuItem (action);
-					menu.Append (mi);
-				}
-			}
-
-			menu.ShowAll ();
-			menu.Popup ();
-		}
-
-		///////////////////////////////////////////////////
-
 		protected override bool OnButtonPressEvent (Gdk.EventButton b)
 		{
 			GrabFocus ();
 
 			if (b.Button == 3) {
 				ShowPopupMenu ();
+
 				return true;
 			} else if (b.Type == Gdk.EventType.TwoButtonPress) {
 				Open ();
+
 				if (b.Button == 2 || ((b.State & Gdk.ModifierType.ShiftMask) != 0))
 					Gtk.Application.Quit ();
+
 				return true;
 			}
 
@@ -234,6 +219,7 @@
 		{
 			if (Selected != null)
 				Selected (this, EventArgs.Empty);
+
 			return base.OnFocusInEvent (f);
 		}
 
@@ -241,8 +227,10 @@
 		{
 			if (k.Key == Gdk.Key.Return || k.Key == Gdk.Key.KP_Enter) {
 				Open ();
+
 				if ((k.State & Gdk.ModifierType.ShiftMask) != 0)
 					Gtk.Application.Quit ();
+
 				return true;
 			}
 
@@ -259,13 +247,11 @@
 			image.Pixbuf = WidgetFu.LoadMimeIcon (hit.MimeType, size);
 		}
 
-		string snippet;
-
 		protected void RequestSnippet ()
 		{
-			if (snippet != null)
+			if (snippet != null) {
 				EmitGotSnippet ();
-			else {
+			} else {
 				SnippetRequest sreq = new SnippetRequest (query, hit);
 				sreq.RegisterAsyncResponseHandler (typeof (SnippetResponse), SnippetResponseReceived);
 				sreq.SendAsync ();
@@ -274,36 +260,31 @@
 
 		private void SnippetResponseReceived (ResponseMessage response)
 		{
-			// The returned snippet uses
-			// <font color="..."><b>blah</b></font>
+			// The returned snippet uses <font color="..."><b>blah</b></font>
 			// to mark matches. The rest of the snippet might be HTML, or
 			// it might be plain text, including unescaped '<'s and '&'s.
 			// So we escape it, fix the match highlighting, and leave any
 			// other tags escaped.
 
-			// FIXME: hacky, fix the snippeting in the daemon
+			// FIXME: Use the new snippeting framework
 			
 			snippet = GLib.Markup.EscapeText (((SnippetResponse)response).Snippet);
 			snippet = Regex.Replace (snippet, "&lt;font color=&quot;.*?&quot;&gt;&lt;b&gt;(.*?)&lt;/b&gt;&lt;/font&gt;", "<b>$1</b>");
-			if(snippet.Trim().Length > 0)
+			if (snippet.Trim ().Length > 0)
 				EmitGotSnippet ();
 		}
 
 		private void EmitGotSnippet ()
 		{
-			if (!String.IsNullOrEmpty (snippet) && GotSnippet != null)
+			if (! String.IsNullOrEmpty (snippet) && GotSnippet != null)
 				GotSnippet (snippet);
 		}
 
-		public delegate void GotSnippetHandler (string snippet);
-		public event GotSnippetHandler GotSnippet;
-
 		protected virtual DetailsPane GetDetails ()
 		{
 			return null;
 		}
 
-		DetailsPane details;
 		public Gtk.Widget Details {
 			get {
 				if (details == null) {
@@ -326,7 +307,7 @@
 
 		public virtual void Open ()
 		{
-			System.Console.WriteLine ("Warning: Open method not implemented for this tile type");
+			System.Console.WriteLine ("Warning: Open method not implemented for '{0}'", this.GetType ());
 		}
 
 #if ENABLE_OPEN_WITH
@@ -454,5 +435,48 @@
 			}
 #endif
 		}
+
+		///////////////////////////////////////////////////////
+
+		public Beagle.Hit Hit {
+			get { return hit; }
+		}
+
+		public Beagle.Query Query {
+			get { return query; }
+		}
+
+		public TileGroup Group {
+			get { return group; }
+			protected set { group = value; }
+		}
+
+		protected Gtk.HBox HBox { 
+			get { return hbox; }
+		}
+
+		public Gtk.Image Icon {
+			get { return icon; }
+			set { icon = value; }
+		}
+
+		public virtual string Title {
+			get { return title; }
+			set { title = value; }
+		}
+
+		public virtual DateTime Timestamp {
+			get { return timestamp; }
+			set { timestamp = value; }
+		}
+
+		public virtual double Score {
+			get { return score; }
+			set { score = value; }
+		}
+
+		public IList<TileAction> Actions {
+			get { return actions; }
+		}
 	}
 }

Modified: trunk/beagle/search/Beagle.Search/Driver.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search/Driver.cs	(original)
+++ trunk/beagle/search/Beagle.Search/Driver.cs	Fri Feb 15 14:21:49 2008
@@ -17,9 +17,25 @@
 
 	public class Driver {
 
-		private const string INTERFACE_NAME = "org.gnome.Beagle.Search";
+		private const string BUS_NAME = "org.gnome.Beagle";
 		private const string PATH_NAME = "/org/gnome/Beagle/Search";
 
+		public static void PrintUsageAndExit ()
+		{
+			VersionFu.PrintHeader ();
+
+			string usage =
+				"Usage: beagle-search [OPTIONS] [<query string>]\n\n" +
+				"Options:\n" +
+				"  --icon\t\t\tAdd an icon to the notification area rather than opening a search window.\n" +
+				"  --search-docs\t\t\tAlso search the system-wide documentation index.\n" +
+				"  --help\t\t\tPrint this usage message.\n" +
+				"  --version\t\t\tPrint version information.\n";
+
+			Console.WriteLine (usage);
+			System.Environment.Exit (0);
+		}
+
 		private static string ParseArgs (String[] args)
 		{
 			string query = String.Empty;
@@ -69,57 +85,31 @@
 			return query;
 		}
 
-		public static void PrintUsageAndExit ()
-		{
-			VersionFu.PrintHeader ();
-
-			string usage =
-				"Usage: beagle-search [OPTIONS] [<query string>]\n\n" +
-				"Options:\n" +
-				"  --icon\t\t\tAdd an icon to the notification area rather than opening a search window.\n" +
-				"  --search-docs\t\t\tAlso search the system-wide documentation index.\n" +
-				"  --help\t\t\tPrint this usage message.\n" +
-				"  --version\t\t\tPrint version information.\n";
-
-			Console.WriteLine (usage);
-			System.Environment.Exit (0);
-		}
-
 		public static void Main (string[] args)
 		{
-			// Set our process name
-
 			SystemInformation.SetProcessName ("beagle-search");
-
-			// Initialize our translations catalog
-			
 			Catalog.Init ("beagle", ExternalStringsHack.LocaleDir);
 
-			// Set up DBus for our GLib main loop
-			
 			BusG.Init ();
 
-			// Parse arguments
-
 			string query = ParseArgs (args);
 
-			if (Bus.Session.RequestName (INTERFACE_NAME) != RequestNameReply.PrimaryOwner) {
-				Console.WriteLine ("There is already an instance of beagle-search running!");
+			// If there is already an instance of beagle-search running
+			// request our search proxy object and open up a query in
+			// that instance.
+
+			if (Bus.Session.RequestName (BUS_NAME) != RequestNameReply.PrimaryOwner) {
+				ISearch s = Bus.Session.GetObject<ISearch> (BUS_NAME, new ObjectPath (PATH_NAME));
+				s.Query (query);
 				return;
 			}
 			
-			// Init Gnome program
-
 			Gnome.Program program = new Gnome.Program ("search", "0.0", Gnome.Modules.UI, args);
 
-			Search window = new Search (query);
-
-			Bus.Session.Register (INTERFACE_NAME, new ObjectPath (PATH_NAME), window);
+			Search search = new Search (query);
+			search.Query (query);
 
-			//if (query != null && query != "" && !IconEnabled) {
-			//	window.entry.Text = query;
-			//	window.Search (true);
-			//}
+			Bus.Session.Register (new ObjectPath (PATH_NAME), search);
 
 			program.Run ();
 		}

Modified: trunk/beagle/search/Beagle.Search/ISearch.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search/ISearch.cs	(original)
+++ trunk/beagle/search/Beagle.Search/ISearch.cs	Fri Feb 15 14:21:49 2008
@@ -11,9 +11,8 @@
 
 namespace Beagle.Search {
 	
-	[Interface ("org.gnome.Beagle.Search")]
+	[Interface ("org.gnome.Beagle")]
 	public interface ISearch {
-		void Show ();
-		void Hide ();
+		void Query (string query);
 	}
 }

Modified: trunk/beagle/search/Beagle.Search/Search.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search/Search.cs	(original)
+++ trunk/beagle/search/Beagle.Search/Search.cs	Fri Feb 15 14:21:49 2008
@@ -1,7 +1,6 @@
 //
 // Search.cs
 //
-// Copyright (c) 2006 Novell, Inc.
 // Copyright (C) 2008 Lukas Lipka <lukaslipka gmail com>
 //
 
@@ -13,172 +12,18 @@
 using NDesk.DBus;
 using Mono.Unix;
 
-using Beagle;
-using Beagle.Util;
-
-using Beagle.Search.Tiles;
-using Beagle.Search.Tray;
-
 namespace Beagle.Search {
 
-	public class Search : Window, ISearch {
-
-		private Gtk.Button button;
-		private Gtk.Tooltips tips;
-		private Gtk.Notebook pages;
-		private Gtk.Statusbar statusbar;
-
-		private Beagle.Search.UIManager uim;
-		private Beagle.Search.NotificationArea notification_area;
-		private Beagle.Search.GroupView view;
-		private Beagle.Search.Entry entry;
-		private Beagle.Search.Spinner spinner;
-		private Beagle.Search.Panes panes;
-		private Beagle.Search.Tray.TrayIcon tray;
-
-		private Beagle.Search.Pages.IndexInfo indexinfo;
-		private Beagle.Search.Pages.QuickTips quicktips;
-		private Beagle.Search.Pages.RootUser rootuser;
-		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 uint timeout_id = 0;
-
-		private Beagle.Query current_query = null;
-		private string query_text = null;
-		private bool show_details = true;
-		private int total_matches = -1;
-
-		private XKeybinder keybinder = new XKeybinder ();
+	public class Search : ISearch {
 
 		public static bool IconEnabled = false;
-		private static bool search_docs = false;
-
-		public Search (string query_text) : base (WindowType.Toplevel)
-		{
-			base.Title = Catalog.GetString ("Desktop Search");
-			base.Icon = WidgetFu.LoadThemeIcon ("system-search", 16);
+		public static bool SearchDocs = false;
 
-			base.DefaultWidth = 700;
-			base.DefaultHeight = 550;
-			base.DeleteEvent += OnWindowDelete;
-			
-			VBox vbox = new VBox ();
-			vbox.Spacing = 3;
-
-			uim = new UIManager (this);
-			uim.DomainChanged += OnDomainChanged;
-			uim.ScopeChanged += OnScopeChanged;
-			uim.SortChanged += OnSortChanged;
-			uim.ToggleDetails += OnToggleDetails;
-			uim.ShowQuickTips += OnShowQuickTips;
-			uim.ShowIndexInfo += OnShowIndexInfo;
-			vbox.PackStart (uim.MenuBar, false, false, 0);
-
-			HBox hbox = new HBox (false, 6);
-			
-			Label label = new Label (Catalog.GetString ("_Find:"));
-			hbox.PackStart (label, false, false, 0);
-			
-			entry = new Entry ();
-			entry.Activated += OnEntryActivated;
-			hbox.PackStart (entry, true, true, 0);
-
-			label.MnemonicWidget = entry;
-			uim.FocusSearchEntry += delegate () { entry.GrabFocus (); };
-
-			// The auto search after timeout feauture is now optional
-			// and can be disabled.
-
-			if (Conf.BeagleSearch.GetOption (Conf.Names.BeagleSearchAutoSearch, true)) {
-				entry.Changed += OnEntryResetTimeout;
-				entry.MoveCursor += OnEntryResetTimeout;
-			}
-
-			button = new Gtk.Button ();
-			Gtk.HBox button_hbox = new Gtk.HBox (false, 2);
-			Gtk.Image icon = new Gtk.Image (Gtk.Stock.Find, Gtk.IconSize.Button);
-			button_hbox.PackStart (icon, false, false, 0);
-			label = new Gtk.Label (Catalog.GetString ("Find Now"));
-			button_hbox.PackStart (label, false, false, 0);
-			button.Add (button_hbox);
-			button.Clicked += OnButtonClicked;
-
-			Gtk.VBox buttonVBox = new Gtk.VBox (false, 0);
-			buttonVBox.PackStart (button, true, false, 0);
-			hbox.PackStart (buttonVBox, false, false, 0);
-
-			spinner = new Spinner ();
-			hbox.PackStart (spinner, false, false, 0);
-
-			HBox padding_hbox = new HBox ();
-			padding_hbox.PackStart (hbox, true, true, 9);
-			vbox.PackStart (padding_hbox, false, true, 6);
-
-			VBox view_box = new VBox (false, 3);
-			vbox.PackStart (view_box, true, true, 0);
-
-			HBox na_padding = new HBox ();
-			view_box.PackStart (na_padding, false, true, 0);
-
-			notification_area = new NotificationArea ();
-			na_padding.PackStart (notification_area, true, true, 3);
-
-			pages = new Gtk.Notebook ();
-			pages.ShowTabs = false;
-			pages.ShowBorder = false;
-			pages.BorderWidth = 3;
-			view_box.PackStart (pages, true, true, 0);
-
-			quicktips = new Pages.QuickTips ();
-			quicktips.Show ();
-			pages.Add (quicktips);
-
-			indexinfo = new Pages.IndexInfo ();
-			indexinfo.Show ();
-			pages.Add (indexinfo);
-
-			rootuser = new Pages.RootUser ();
-			rootuser.Show ();
-			pages.Add (rootuser);
-
-			startdaemon = new Pages.StartDaemon ();
-			startdaemon.DaemonStarted += OnDaemonStarted;
-			startdaemon.Show ();
-			pages.Add (startdaemon);
-
-			panes = new Beagle.Search.Panes ();
-			panes.Show ();
-			pages.Add (panes);
-
-			view = new GroupView ();
-			view.TileSelected += ShowInformation;
-			view.CategoryToggled += OnCategoryToggled;
-			panes.MainContents = view;
-
-			this.statusbar = new Gtk.Statusbar ();
-			vbox.PackEnd (this.statusbar, false, false, 0);
-			
-			Add (vbox);
-
-			tips = new Gtk.Tooltips ();
-			tips.SetTip (entry, Catalog.GetString ("Type in search terms"), "");
-			tips.SetTip (button, Catalog.GetString ("Start searching"), "");
-			tips.Enable ();
-
-			if (Environment.UserName == "root" &&
-			    ! Conf.Daemon.GetOption (Conf.Names.AllowRoot, false)) {
-				pages.CurrentPage = pages.PageNum (rootuser);
-				entry.Sensitive = button.Sensitive = uim.Sensitive = false;
-			} else {
-				pages.CurrentPage = pages.PageNum (quicktips);
-			}
+		private uint ref_count = 0;
 
-			if (IconEnabled) {
+		public Search (string query_text)
+		{
+			/*if (IconEnabled) {
 				tray = new Beagle.Search.Tray.TrayIcon ();
 				tray.Clicked += OnTrayActivated;
 				tray.Search += OnTraySearch;
@@ -199,368 +44,21 @@
 				}
 
 				tray.TooltipText = tip_text;
-			} else {
-				ShowAll ();
-			}
-
-			StartCheckingIndexingStatus ();
-
-			if (! String.IsNullOrEmpty (query_text)) {
-				entry.Text = query_text;
-				Query (true);
-			}
-		}
-
-		private void SetWindowTitle (string query)
-		{
-			Title = String.Format ( Catalog.GetString ("Desktop Search: {0}"), query);
-		}
-
-		private int TotalMatches {
-			get { return this.total_matches; }
-			set {
-				if (this.total_matches != -1)
-					this.statusbar.Pop (0);
-
-				this.total_matches = value;
-				
-				if (this.total_matches > -1) {
-					string message;
-					int tile_count = view.TileCount;
-
-					if (tile_count == this.total_matches)
-						message = String.Format (Catalog.GetPluralString ("Showing {0} match", "Showing all {0} matches", this.total_matches), this.total_matches);
-					else
-						message = String.Format (Catalog.GetPluralString ("Showing the top {0} of {1} total matches", "Showing the top {0} of {1} total matches", this.total_matches), view.TileCount, this.total_matches);
-
-					this.statusbar.Push (0, message);
-				}
-			}
-		}
-
-		private void DetachQuery ()
-		{
-			if (current_query != null) {
-				TotalMatches = -1;
-				current_query.HitsAddedEvent -= OnHitsAdded;
-				current_query.HitsSubtractedEvent -= OnHitsSubtracted;
-				current_query.Close ();
-			}
-		}
-
-		// Whether we should grab focus from the text entry
-		private bool grab_focus;
-
-		private void Query (bool grab_focus)
-		{
-			if (timeout_id != 0) {
-				GLib.Source.Remove (timeout_id);
-				timeout_id = 0;
-			}
-
-			string query = query_text = entry.Text;
-			if (query == null || query == "")
-				return;
-
-			SetWindowTitle (query);
-			ShowInformation (null);
-
-			if (tray != null) {
-				tray.AddSearch (query);
-			}
-
-			filter = TypeFilter.MakeFilter (ref query);
-
-			view.Clear ();
-			view.Scope = scope;
-			view.SortType = sort;
-			pages.CurrentPage = pages.PageNum (panes);
-
-			this.grab_focus = grab_focus;
-
-			try {
-				// Clean up our previous query, if any exists.
-				DetachQuery ();
-
-				TotalMatches = 0;
-
-				current_query = new Query ();
-				current_query.AddDomain (QueryDomain.Neighborhood);
-
-				// Don't search documentation by default
-				if (! search_docs) {
-					QueryPart_Property part = new QueryPart_Property ();
-					part.Logic = QueryPartLogic.Prohibited;
-					part.Type = PropertyType.Keyword;
-					part.Key = "beagle:Source";
-					part.Value = "documentation";
-					current_query.AddPart (part);
-				}
-
-				current_query.AddText (query);
-				current_query.HitsAddedEvent += OnHitsAdded;
-				current_query.HitsSubtractedEvent += OnHitsSubtracted;
-				current_query.FinishedEvent += OnFinished;
-
-				current_query.SendAsync ();
-				spinner.Start ();
-			} catch (Beagle.ResponseMessageException) {
-				pages.CurrentPage = pages.PageNum (startdaemon);
-			} catch (Exception e) {
-				Console.WriteLine ("Querying the Beagle daemon failed: {0}", e.Message);
-			}
-		}
-
-		private void OnEntryActivated (object obj, EventArgs args)
-		{
-			Query (true);
-		}
-
-		private void OnDaemonStarted ()
-		{
-			Query (true);
-		}
-
-		private void OnEntryResetTimeout (object o, EventArgs args)
-		{
-			if (timeout_id != 0)
-				GLib.Source.Remove (timeout_id);
-
-			timeout_id = GLib.Timeout.Add (1000, OnEntryTimeout);
-		}
-
-		private bool OnEntryTimeout ()
-		{
-			timeout_id = 0;
-			Query (false);
-
-			return false;
-		}
-
-		private void OnButtonClicked (object obj, EventArgs args)
-		{
-			Query (true);
-		}
-
-		private void OnWindowDelete (object o, Gtk.DeleteEventArgs args)
-		{
-			if (IconEnabled) {
-				Hide ();
-				args.RetVal = true;
-			} else {
-				Gtk.Application.Quit ();
-			}
-		}
-
-		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;
-		}
-
-		private void OnToggleDetails (bool active)
-		{
-			show_details = active;
-			if (panes.Details != null)
-				panes.ToggleDetails (show_details);
-			else
-				panes.ToggleDetails (false);
-		}
-
-		private void OnShowQuickTips ()
-		{
-			DetachQuery ();
-			pages.CurrentPage = pages.PageNum (quicktips);
-		}
-		
-		private void OnShowIndexInfo ()
-		{
-			DetachQuery ();
-			
-			if (! indexinfo.Refresh ())
-				pages.CurrentPage = pages.PageNum (startdaemon);
-			else
-				pages.CurrentPage = pages.PageNum (indexinfo);
-		}
-		
-		private void OnDomainChanged (QueryDomain domain, bool active)
-		{
-			if (current_query == null)
-				return;
-			
-			// FIXME: Most likely refire the query.
-			// Also keep the setting, so it can be used for future queries
-			// in this running instance.
-			
-			if (active)
-				current_query.AddDomain (domain);
-			else
-				current_query.RemoveDomain (domain);
-		}
-		
-		private void ShowInformation (Tiles.Tile tile)
-		{
-			if (tile != null) {
-				panes.Details = tile.Details;
-				if (tile.Details != null)
-					panes.ToggleDetails (show_details);
-				else
-					panes.ToggleDetails (false);
-			} else {
-				panes.Details = null;
-				panes.ToggleDetails (false);
-			}
-		}
-
-		private void OnFinished (FinishedResponse response)
-		{
-			spinner.Stop ();
-			view.Finished (grab_focus);
-			grab_focus = false;
-
-			CheckNoMatch ();
-		}
-
-		private void OnHitsAdded (HitsAddedResponse response)
-		{
-			foreach (Hit hit in response.Hits) {
-				Tile tile = TileActivatorOrg.MakeTile (hit, current_query);
-
-				if (tile == null) {
-					Console.WriteLine ("No tile found for: {0} ({1})", hit.Uri, hit.Type);
-					continue;
-				}
-
-				if (filter != null && !filter.Filter (tile))
-					continue;
-
-				view.AddHit (tile);
-
-				if (pages.CurrentPageWidget != panes)
-					pages.CurrentPage = pages.PageNum (panes);
-			}
-
-			if (response.NumMatches != -1)
-				TotalMatches += response.NumMatches;
-		}
-
-		private void OnHitsSubtracted (HitsSubtractedResponse response)
-		{
-			foreach (Uri uri in response.Uris)
-				view.SubtractHit (uri);
-
-			TotalMatches -= response.Uris.Count;
-
-			CheckNoMatch ();
-		}
-
-#if ENABLE_AVAHI
-                private void OnUnknownHostFound (object sender, AvahiEventArgs args)
-                {
-			NotificationMessage m = new NotificationMessage ();
-			m.Pixbuf = WidgetFu.LoadThemeIcon ("network-workgroup", 48);
-			m.Title = Catalog.GetString ("There are computers near you running Beagle");
-			m.Message = Catalog.GetString ("You can select to search other computers from the \"Search\" menu.");
-			m.AddAction ("Configure", OnNetworkConfigure);
-			notification_area.Display (m);
-		}
-
-		private void OnNetworkConfigure (object o, EventArgs args)
-		{
-			Process p = new Process ();
-			p.StartInfo.UseShellExecute = false;
-			p.StartInfo.FileName = "beagle-settings";
-			p.StartInfo.Arguments = "--networking";
-
-			try {
-				p.Start ();
-			} catch (Exception e) {
-				Console.WriteLine ("Could not start beagle-settings: {0}", e);
-			}
-                }
-#endif
-
-		private void CheckNoMatch ()
-		{
-			MatchType matches = view.MatchState;
-			if (matches == MatchType.Matched) {
-				pages.CurrentPage = pages.PageNum (panes);
-				return;
-			}
-
-			if (nomatch != null)
-				nomatch.Destroy ();
-			nomatch = new Pages.NoMatch (query_text, matches == MatchType.NoneInScope);
-			nomatch.Show ();
-			pages.Add (nomatch);
-			pages.CurrentPage = pages.PageNum (nomatch);
-		}
-
-		/////////////////////////////////////
-
-		private void OnTrayActivated (object o, EventArgs args)
-		{
-			if (! Visible) {
-				base.ShowAll ();
-				base.Present ();
-				entry.GrabFocus ();
-			} else {
-				base.Hide ();
-			}
+			}*/
 		}
 
-		private void OnTraySearch (string query)
+		public void Query (string query_text)
 		{
-			if (!Visible)
-				ShowAll ();
-
-			entry.Text = query;
-			Query (true);
-		}
-
-		//////////////////////////////////////
+			SearchWindow window = new SearchWindow (query_text);
+			window.DeleteEvent += OnWindowDeleteEvent;
 
-		private void StartCheckingIndexingStatus ()
-		{
-			InformationalMessagesRequest msg_request = new InformationalMessagesRequest ();
-			msg_request.IndexingStatusEvent += OnIndexingStatusEvent;
-			msg_request.SendAsync ();
+			ref_count++;
 		}
 
-		private void OnIndexingStatusEvent (IndexingStatus status)
+		private void OnWindowDeleteEvent (object o, DeleteEventArgs args)
 		{
-			if (status == IndexingStatus.Running) {
-				NotificationMessage m = new NotificationMessage ();
-				m.Icon = Gtk.Stock.DialogInfo;
-				m.Title = Catalog.GetString ("Your data is being indexed");
-				m.Message = Catalog.GetString ("The search service is in the process of indexing your data.  Search results may be incomplete until indexing has finished.");
-				notification_area.Display (m);
-			} else {
-				notification_area.Hide ();
-			}
+			if (--ref_count < 1)
+				Application.Quit ();
 		}
 	}
 }

Copied: trunk/beagle/search/Beagle.Search/SearchWindow.cs (from r4479, /trunk/beagle/search/Beagle.Search/Search.cs)
==============================================================================
--- /trunk/beagle/search/Beagle.Search/Search.cs	(original)
+++ trunk/beagle/search/Beagle.Search/SearchWindow.cs	Fri Feb 15 14:21:49 2008
@@ -1,5 +1,5 @@
 //
-// Search.cs
+// SearchWindow.cs
 //
 // Copyright (c) 2006 Novell, Inc.
 // Copyright (C) 2008 Lukas Lipka <lukaslipka gmail com>
@@ -10,7 +10,6 @@
 using System.Diagnostics;
 
 using Gtk;
-using NDesk.DBus;
 using Mono.Unix;
 
 using Beagle;
@@ -21,7 +20,7 @@
 
 namespace Beagle.Search {
 
-	public class Search : Window, ISearch {
+	public class SearchWindow : Window {
 
 		private Gtk.Button button;
 		private Gtk.Tooltips tips;
@@ -53,12 +52,7 @@
 		private bool show_details = true;
 		private int total_matches = -1;
 
-		private XKeybinder keybinder = new XKeybinder ();
-
-		public static bool IconEnabled = false;
-		private static bool search_docs = false;
-
-		public Search (string query_text) : base (WindowType.Toplevel)
+		public SearchWindow (string query_text) : base (WindowType.Toplevel)
 		{
 			base.Title = Catalog.GetString ("Desktop Search");
 			base.Icon = WidgetFu.LoadThemeIcon ("system-search", 16);
@@ -178,30 +172,7 @@
 				pages.CurrentPage = pages.PageNum (quicktips);
 			}
 
-			if (IconEnabled) {
-				tray = new Beagle.Search.Tray.TrayIcon ();
-				tray.Clicked += OnTrayActivated;
-				tray.Search += OnTraySearch;
-
-				Config config = Conf.Get (Conf.Names.BeagleSearchConfig);
-				bool binding_ctrl = config.GetOption (Conf.Names.KeyBinding_Ctrl, false);
-				bool binding_alt = config.GetOption (Conf.Names.KeyBinding_Alt, false);
-				string binding_key = config.GetOption (Conf.Names.KeyBinding_Key, "F12");
-
-				string binding = new KeyBinding (binding_key, binding_ctrl, binding_alt).ToString ();
-				string tip_text = Catalog.GetString ("Desktop Search");
-
-				if (binding != String.Empty) {
-					tip_text += String.Format (" ({0})", binding);
-
-					// Attach the hide/show keybinding
-					keybinder.Bind (binding, OnTrayActivated);
-				}
-
-				tray.TooltipText = tip_text;
-			} else {
-				ShowAll ();
-			}
+			ShowAll ();
 
 			StartCheckingIndexingStatus ();
 
@@ -288,7 +259,7 @@
 				current_query.AddDomain (QueryDomain.Neighborhood);
 
 				// Don't search documentation by default
-				if (! search_docs) {
+				if (! Search.SearchDocs) {
 					QueryPart_Property part = new QueryPart_Property ();
 					part.Logic = QueryPartLogic.Prohibited;
 					part.Type = PropertyType.Keyword;
@@ -344,12 +315,8 @@
 
 		private void OnWindowDelete (object o, Gtk.DeleteEventArgs args)
 		{
-			if (IconEnabled) {
-				Hide ();
-				args.RetVal = true;
-			} else {
-				Gtk.Application.Quit ();
-			}
+			// FIXME: Destroy window
+			Hide ();
 		}
 
 		private void OnScopeChanged (ScopeType toggled, bool active)
@@ -521,28 +488,6 @@
 
 		/////////////////////////////////////
 
-		private void OnTrayActivated (object o, EventArgs args)
-		{
-			if (! Visible) {
-				base.ShowAll ();
-				base.Present ();
-				entry.GrabFocus ();
-			} else {
-				base.Hide ();
-			}
-		}
-
-		private void OnTraySearch (string query)
-		{
-			if (!Visible)
-				ShowAll ();
-
-			entry.Text = query;
-			Query (true);
-		}
-
-		//////////////////////////////////////
-
 		private void StartCheckingIndexingStatus ()
 		{
 			InformationalMessagesRequest msg_request = new InformationalMessagesRequest ();

Modified: trunk/beagle/search/Beagle.Search/UIManager.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search/UIManager.cs	(original)
+++ trunk/beagle/search/Beagle.Search/UIManager.cs	Fri Feb 15 14:21:49 2008
@@ -33,13 +33,13 @@
 
 	public class UIManager : Gtk.UIManager {
 
-		private Search search = null;
+		private SearchWindow search = null;
 		
 		private Gtk.ActionGroup actions;
 		private Gtk.RadioActionEntry[] sort_entries;
 		private Gtk.ToggleActionEntry[] scope_entries, view_entries, domain_entries;
 
-		public UIManager (Search search)
+		public UIManager (SearchWindow search)
 		{
 			this.search = search;
 			this.actions = new ActionGroup ("Actions");

Modified: trunk/beagle/search/Makefile.am
==============================================================================
--- trunk/beagle/search/Makefile.am	(original)
+++ trunk/beagle/search/Makefile.am	Fri Feb 15 14:21:49 2008
@@ -81,6 +81,7 @@
 	$(srcdir)/Beagle.Search/NotificationArea.cs		\
 	$(srcdir)/Beagle.Search/Panes.cs			\
 	$(srcdir)/Beagle.Search/Search.cs			\
+	$(srcdir)/Beagle.Search/SearchWindow.cs			\
 	$(srcdir)/Beagle.Search/SortedTileList.cs		\
 	$(srcdir)/Beagle.Search/Spinner.cs			\
 	$(srcdir)/Beagle.Search/TileCategory.cs			\



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