beagle r4375 - in trunk/beagle/search: . Pages Tiles



Author: llipka
Date: Mon Jan  7 09:48:55 2008
New Revision: 4375
URL: http://svn.gnome.org/viewvc/beagle?rev=4375&view=rev

Log:
Add an index information page.


Added:
   trunk/beagle/search/Pages/IndexInfo.cs
Modified:
   trunk/beagle/search/Makefile.am
   trunk/beagle/search/Pages/Base.cs
   trunk/beagle/search/Search.cs
   trunk/beagle/search/Tiles/Documentation.cs
   trunk/beagle/search/UIManager.cs

Modified: trunk/beagle/search/Makefile.am
==============================================================================
--- trunk/beagle/search/Makefile.am	(original)
+++ trunk/beagle/search/Makefile.am	Mon Jan  7 09:48:55 2008
@@ -92,6 +92,7 @@
 
 PAGES =						\
 	$(srcdir)/Pages/Base.cs			\
+	$(srcdir)/Pages/IndexInfo.cs		\
 	$(srcdir)/Pages/NoMatch.cs		\
 	$(srcdir)/Pages/QuickTips.cs		\
 	$(srcdir)/Pages/RootUser.cs		\

Modified: trunk/beagle/search/Pages/Base.cs
==============================================================================
--- trunk/beagle/search/Pages/Base.cs	(original)
+++ trunk/beagle/search/Pages/Base.cs	Mon Jan  7 09:48:55 2008
@@ -54,10 +54,15 @@
 			table.Attach (label, 1, 2, row, row + 1, Gtk.AttachOptions.Expand | Gtk.AttachOptions.Fill, 0, 0, 0);
 		}
 
-		public void Append (Gtk.Widget widget)
+		public void Append (Gtk.Widget widget, Gtk.AttachOptions x, Gtk.AttachOptions y)
 		{
 			uint row = table.NRows;
-			table.Attach (widget, 0, 2, row, row + 1, 0, 0, 0, 0);
+			table.Attach (widget, 0, 2, row, row + 1, x, y, 0, 0);
+		}
+
+		public void Append (Gtk.Widget widget)
+		{
+			Append (widget, 0, 0);
 		}
 
 		protected override void OnSizeRequested (ref Gtk.Requisition req)

Added: trunk/beagle/search/Pages/IndexInfo.cs
==============================================================================
--- (empty file)
+++ trunk/beagle/search/Pages/IndexInfo.cs	Mon Jan  7 09:48:55 2008
@@ -0,0 +1,98 @@
+//
+//  IndexInfo.cs
+//
+//  Copyright (C) 2007 Debajyoti Bera <dbera web gmail com>
+//  Copyright (C) 2007 Lukas Lipka <lukaslipka gmail com>
+//
+
+using Gtk;
+using System;
+using System.Text;
+using System.Collections.Generic;
+
+using Mono.Unix;
+
+using Beagle;
+
+namespace Search.Pages {
+
+	public class IndexInfo : Base {
+
+		private Gtk.Label note = null;
+		private Gtk.Label label = null;
+
+		public IndexInfo ()
+		{
+			HeaderIcon = WidgetFu.LoadThemeIcon ("dialog-information", 48);
+			Header = Catalog.GetString ("Index Information");
+
+			Gtk.Label description = new Gtk.Label ();
+			description.Markup = Catalog.GetString ("Number of items currently indexed:");
+			description.LineWrap = true;
+			description.Justify = Justification.Left;
+			description.SetAlignment (0.0f, 0.5f);
+
+			Append (description, Gtk.AttachOptions.Fill, 0);
+
+			label = new Gtk.Label ();
+			label.LineWrap = true;
+			label.SetAlignment (0.0f, 0.5f);
+			label.Justify = Justification.Fill;
+			
+			Append (label, Gtk.AttachOptions.Expand | Gtk.AttachOptions.Fill, 0);
+
+			note = new Gtk.Label ();
+			note.Markup = Catalog.GetString ("<i>NOTE: The search service is still indexing new data.</i>");
+			note.LineWrap = true;
+			note.Justify = Justification.Fill;
+			note.SetAlignment (0.0f, 0.5f);
+			note.NoShowAll = true;
+			
+			Append (note, Gtk.AttachOptions.Fill, 0);
+		}
+
+		internal bool Refresh ()
+		{
+			DaemonInformationRequest request = new DaemonInformationRequest (false, false, true, true);
+			DaemonInformationResponse response;
+
+			try {
+				response = (DaemonInformationResponse) request.Send ();
+			} catch (Beagle.ResponseMessageException) {
+				Console.WriteLine ("Could not connect to the daemon.");
+				return false;
+			}
+
+			if (response.IsIndexing) {
+				note.Show ();
+			} else {
+				note.Hide ();
+			}
+
+			int i = 0;
+			StringBuilder sb = new StringBuilder ();
+
+			foreach (QueryableStatus status in response.IndexStatus) {
+				if (i++ > 20)
+					break;
+
+				// Skip all those metadata and networking services backends
+				if (status.ItemCount < 0)
+					continue;
+
+				sb.AppendFormat ("<b>{0}</b>: {1}", status.Name, status.ItemCount);
+				
+				if (status.ProgressPercent > 0)
+					sb.AppendFormat (" ({0})", status.ProgressPercent);
+
+				sb.Append ("\n");
+			}
+
+			label.Markup = sb.ToString ();
+
+			label.Show ();
+
+			return true;
+		}
+	}
+}

Modified: trunk/beagle/search/Search.cs
==============================================================================
--- trunk/beagle/search/Search.cs	(original)
+++ trunk/beagle/search/Search.cs	Mon Jan  7 09:48:55 2008
@@ -38,6 +38,7 @@
 		private Search.Panes panes;
 		private Search.Tray.TrayIcon tray;
 
+		private Search.Pages.IndexInfo indexinfo;
 		private Search.Pages.QuickTips quicktips;
 		private Search.Pages.RootUser rootuser;
 		private Search.Pages.StartDaemon startdaemon;
@@ -160,6 +161,7 @@
 			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);
@@ -220,6 +222,10 @@
 			quicktips.Show ();
 			pages.Add (quicktips);
 
+			indexinfo = new Pages.IndexInfo ();
+			indexinfo.Show ();
+			pages.Add (indexinfo);
+
 			rootuser = new Pages.RootUser ();
 			rootuser.Show ();
 			pages.Add (rootuser);
@@ -311,6 +317,16 @@
 			}
 		}
 
+		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;
 
@@ -342,12 +358,8 @@
 			this.grab_focus = grab_focus;
 
 			try {
-				if (current_query != null) {
-					TotalMatches = -1;
-					current_query.HitsAddedEvent -= OnHitsAdded;
-					current_query.HitsSubtractedEvent -= OnHitsSubtracted;
-					current_query.Close ();
-				}
+				// Clean up our previous query, if any exists.
+				DetachQuery ();
 
 				TotalMatches = 0;
 
@@ -448,7 +460,6 @@
 			}
 		}
 		
-
 		private void OnSortChanged (Search.SortType newSort)
 		{
 			view.Sort = sort = newSort;
@@ -465,32 +476,35 @@
 
 		private void OnShowQuickTips ()
 		{
-			if (current_query != null) {
-				TotalMatches = -1;
-				current_query.HitsAddedEvent -= OnHitsAdded;
-				current_query.HitsSubtractedEvent -= OnHitsSubtracted;
-				current_query.Close ();
-				current_query = null;
-			}
-
+			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) {

Modified: trunk/beagle/search/Tiles/Documentation.cs
==============================================================================
--- trunk/beagle/search/Tiles/Documentation.cs	(original)
+++ trunk/beagle/search/Tiles/Documentation.cs	Mon Jan  7 09:48:55 2008
@@ -1,7 +1,7 @@
 //
 // Documentation.cs
 //
-// Copyright (C) Lukas Lipka <lukaslipka gmail com>
+// Copyright (C) 2007 Lukas Lipka <lukaslipka gmail com>
 //
 
 using System;

Modified: trunk/beagle/search/UIManager.cs
==============================================================================
--- trunk/beagle/search/UIManager.cs	(original)
+++ trunk/beagle/search/UIManager.cs	Mon Jan  7 09:48:55 2008
@@ -94,6 +94,9 @@
 				new ActionEntry ("QuickTips", null,
 						 Catalog.GetString ("Quick Tips"),
 						 null, null, QuickTips),
+				new ActionEntry ("IndexInfo", null,
+						 Catalog.GetString ("Index information"),
+						 null, null, IndexInfo),
 				new ActionEntry ("FocusSearchEntry", null, "",
 						 "<control>K", null,
 						 OnFocusSearchEntry),
@@ -313,6 +316,7 @@
 		"    <menu action='Help'>" +
 		"      <menuitem action='Contents'/>" +
 		"      <menuitem action='QuickTips'/>" +
+		"      <menuitem action='IndexInfo'/>" +
 		"      <menuitem action='About'/>" +
 		"    </menu>" +
 		"  </menubar>" +
@@ -335,24 +339,6 @@
 			}
 		}
 
-		public delegate void ToggleDetailsDelegate (bool active);
-		public event ToggleDetailsDelegate ToggleDetails;
-
-		private void OnToggleDetails (object obj, EventArgs args)
-		{
-			if (ToggleDetails != null)
-				ToggleDetails (((ToggleAction) obj).Active);
-		}
-
-		public delegate void ShowQuickTipsDelegate ();
-		public event ShowQuickTipsDelegate ShowQuickTips;
-
-		private void QuickTips (object obj, EventArgs args)
-		{
-			if (ShowQuickTips != null)
-				ShowQuickTips ();
-		}
-
 		private void OnHideWindow (object obj, EventArgs args)
 		{
 			if (MainWindow.IconEnabled)
@@ -406,14 +392,17 @@
 #pragma warning restore 612
 		}
 
+		public delegate void FocusSearchEntryDelegate ();
+		public event FocusSearchEntryDelegate FocusSearchEntry;
+
 		private void OnFocusSearchEntry (object obj, EventArgs args)
 		{
 			if (FocusSearchEntry != null)
 				FocusSearchEntry ();
 		}
 
-		public delegate void FocusSearchEntryDelegate ();
-		public event FocusSearchEntryDelegate FocusSearchEntry;
+		public delegate void ScopeChangedDelegate (ScopeType scope, bool active);
+		public event ScopeChangedDelegate ScopeChanged;
 
 		private void OnScopeChanged (object obj, EventArgs args)
 		{
@@ -424,8 +413,8 @@
 			ScopeChanged (scope, ((ToggleAction) obj).Active);
 		}
 
-		public delegate void ScopeChangedDelegate (ScopeType scope, bool active);
-		public event ScopeChangedDelegate ScopeChanged;
+		public delegate void SortChangedDelegate (SortType scope);
+		public event SortChangedDelegate SortChanged;
 
 		private void OnSortChanged (object obj, Gtk.ChangedArgs args)
 		{
@@ -433,8 +422,8 @@
 				SortChanged ((SortType)args.Current.CurrentValue);
 		}
 
-		public delegate void SortChangedDelegate (SortType scope);
-		public event SortChangedDelegate SortChanged;
+		public delegate void DomainChangedDelegate (QueryDomain domain, bool active);
+		public event DomainChangedDelegate DomainChanged;
 
 		private void OnDomainChanged (object o, EventArgs args)
 		{
@@ -444,7 +433,31 @@
 				DomainChanged (domain, ((ToggleAction)o).Active);
 		}
 
-		public delegate void DomainChangedDelegate (QueryDomain domain, bool active);
-		public event DomainChangedDelegate DomainChanged;
+		public delegate void ToggleDetailsDelegate (bool active);
+		public event ToggleDetailsDelegate ToggleDetails;
+
+		private void OnToggleDetails (object obj, EventArgs args)
+		{
+			if (ToggleDetails != null)
+				ToggleDetails (((ToggleAction) obj).Active);
+		}
+
+		public delegate void ShowQuickTipsDelegate ();
+		public event ShowQuickTipsDelegate ShowQuickTips;
+
+		private void QuickTips (object obj, EventArgs args)
+		{
+			if (ShowQuickTips != null)
+				ShowQuickTips ();
+		}
+
+		public delegate void ShowIndexInfoDelegate ();
+		public event ShowIndexInfoDelegate ShowIndexInfo;
+		
+		private void IndexInfo (object obj, EventArgs args)
+		{
+			if (ShowIndexInfo != null)
+				ShowIndexInfo ();
+		}
 	}
 }



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