beagle r4540 - in trunk/beagle/search: Beagle.Search Beagle.Search.Tiles
- From: llipka svn gnome org
- To: svn-commits-list gnome org
- Subject: beagle r4540 - in trunk/beagle/search: Beagle.Search Beagle.Search.Tiles
- Date: Wed, 27 Feb 2008 22:08:12 +0000 (GMT)
Author: llipka
Date: Wed Feb 27 22:08:12 2008
New Revision: 4540
URL: http://svn.gnome.org/viewvc/beagle?rev=4540&view=rev
Log:
Get all previous functionality along with instance managment working. Fix a crasher for nautilus emblems on file tiles.
Modified:
trunk/beagle/search/Beagle.Search.Tiles/File.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/SearchWindow.cs
trunk/beagle/search/Beagle.Search/UIManager.cs
Modified: trunk/beagle/search/Beagle.Search.Tiles/File.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search.Tiles/File.cs (original)
+++ trunk/beagle/search/Beagle.Search.Tiles/File.cs Wed Feb 27 22:08:12 2008
@@ -21,6 +21,8 @@
public class TileFile : TileTemplate {
+ private static ThumbnailFactory thumbnailer = new ThumbnailFactory ();
+
public TileFile (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
{
Title = GetTitle (hit);
@@ -35,42 +37,37 @@
// AddAction (new TileAction (Catalog.GetString ("Instant-Message"), InstantMessage));
AddAction (new TileAction (Catalog.GetString ("Move to Trash"), Gtk.Stock.Delete, MoveToTrash));
- if (! String.IsNullOrEmpty (Hit.GetFirstProperty("dc:author"))) {
- AddAction(new TileAction ("Find Documents From Same Author", Gtk.Stock.Find, FindSameAuthor));
+ if (! String.IsNullOrEmpty (Hit.GetFirstProperty ("dc:author"))) {
+ AddAction(new TileAction (Catalog.GetString ("Find Documents From Same Author"), Gtk.Stock.Find, FindSameAuthor));
}
EnableOpenWith = true;
}
- static ThumbnailFactory thumbnailer = new ThumbnailFactory ();
-
protected override void LoadIcon (Gtk.Image image, int size)
{
// The File tile doesn't respect the icon size because
// 48 is too small for thumbnails
+
if (!thumbnailer.SetThumbnailIcon (image, Hit, size))
base.LoadIcon (image, size);
// FIXME: Multiple emblems
string emblem = Hit.GetFirstProperty ("nautilus:emblem");
- if (emblem == null)
+
+ if (String.IsNullOrEmpty (emblem))
return;
- Gdk.Pixbuf icon_pixbuf = image.Pixbuf.Copy ();
Gdk.Pixbuf emblem_pixbuf = WidgetFu.LoadThemeIcon ("emblem-" + emblem, 24);
- if (icon_pixbuf == null || emblem_pixbuf == null) {
- if (icon_pixbuf != null)
- icon_pixbuf.Dispose ();
-
- if (emblem_pixbuf == null)
- emblem_pixbuf.Dispose ();
-
+ if (emblem_pixbuf == null)
return;
- }
+
+ Gdk.Pixbuf icon_pixbuf = image.Pixbuf.Copy ();
// If the icon itself is smaller than our requested
// emblem, just display the emblem.
+
if (icon_pixbuf.Height < emblem_pixbuf.Height || icon_pixbuf.Width < emblem_pixbuf.Width) {
icon_pixbuf.Dispose ();
image.Pixbuf.Dispose ();
@@ -78,9 +75,10 @@
return;
}
- emblem_pixbuf.Composite (icon_pixbuf, 0, 0,
- emblem_pixbuf.Width, emblem_pixbuf.Height,
+ emblem_pixbuf.Composite (icon_pixbuf, 0, 0, emblem_pixbuf.Width, emblem_pixbuf.Height,
0, 0, 1, 1, Gdk.InterpType.Bilinear, 255);
+ emblem_pixbuf.Dispose ();
+
image.Pixbuf.Dispose ();
image.Pixbuf = icon_pixbuf;
}
Modified: trunk/beagle/search/Beagle.Search/Driver.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search/Driver.cs (original)
+++ trunk/beagle/search/Beagle.Search/Driver.cs Wed Feb 27 22:08:12 2008
@@ -20,6 +20,9 @@
private const string BUS_NAME = "org.gnome.Beagle";
private const string PATH_NAME = "/org/gnome/Beagle/Search";
+ private static bool icon_enabled = false;
+ private static bool docs_enabled = false;
+
public static void PrintUsageAndExit ()
{
VersionFu.PrintHeader ();
@@ -33,13 +36,14 @@
" --version\t\t\tPrint version information.\n";
Console.WriteLine (usage);
+
System.Environment.Exit (0);
}
private static string ParseArgs (String[] args)
{
- string query = String.Empty;
int i = 0;
+ string query = String.Empty;
while (i < args.Length) {
switch (args [i]) {
@@ -53,13 +57,13 @@
Environment.Exit (0);
break;
- //case "--icon":
- //IconEnabled = true;
- //break;
-
- //case "--search-docs":
- //search_docs = true;
- //break;
+ case "--icon":
+ icon_enabled = true;
+ break;
+
+ case "--search-docs":
+ docs_enabled = true;
+ break;
// Ignore session management
case "--sm-config-prefix":
@@ -87,9 +91,6 @@
public static void Main (string[] args)
{
- SystemInformation.SetProcessName ("beagle-search");
- Catalog.Init ("beagle", ExternalStringsHack.LocaleDir);
-
BusG.Init ();
string query = ParseArgs (args);
@@ -99,15 +100,29 @@
// that instance.
if (Bus.Session.RequestName (BUS_NAME) != RequestNameReply.PrimaryOwner) {
+ if (icon_enabled == true) {
+ Console.WriteLine ("There is already an instance of beagle-search running.");
+ Console.WriteLine ("Cannot run in --icon mode! Exiting...");
+ Environment.Exit (1);
+ }
+
ISearch s = Bus.Session.GetObject<ISearch> (BUS_NAME, new ObjectPath (PATH_NAME));
s.Query (query);
+
return;
}
+
+ SystemInformation.SetProcessName ("beagle-search");
+ Catalog.Init ("beagle", ExternalStringsHack.LocaleDir);
Gnome.Program program = new Gnome.Program ("search", "0.0", Gnome.Modules.UI, args);
- Search search = new Search (query);
- search.Query (query);
+ // FIXME: Passing these icon and docs enabled properties
+ // sucks. We really need to do something about them.
+ Search search = new Search (icon_enabled, docs_enabled);
+
+ if (!String.IsNullOrEmpty (query) || !icon_enabled)
+ search.Query (query);
Bus.Session.Register (new ObjectPath (PATH_NAME), search);
Modified: trunk/beagle/search/Beagle.Search/ISearch.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search/ISearch.cs (original)
+++ trunk/beagle/search/Beagle.Search/ISearch.cs Wed Feb 27 22:08:12 2008
@@ -13,6 +13,10 @@
[Interface ("org.gnome.Beagle")]
public interface ISearch {
+
+ bool IconEnabled { get; }
+ bool DocsEnabled { get; }
+
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 Wed Feb 27 22:08:12 2008
@@ -8,57 +8,117 @@
using System.Collections;
using System.Diagnostics;
-using Gtk;
using NDesk.DBus;
using Mono.Unix;
+using Beagle.Util;
+using Beagle.Search.Tray;
+
namespace Beagle.Search {
public class Search : ISearch {
- public static bool IconEnabled = false;
- public static bool SearchDocs = false;
+ // The reference count is only valid when
+ // we don't run in icon mode.
private uint ref_count = 0;
- public Search (string query_text)
+ private bool icon_enabled = false;
+ private bool docs_enabled = false;
+
+ private SearchWindow icon_window = null;
+ private TrayIcon tray = null;
+
+ public Search (bool icon_enabled, bool docs_enabled)
{
- /*if (IconEnabled) {
- tray = new Beagle.Search.Tray.TrayIcon ();
+ this.icon_enabled = icon_enabled;
+ this.docs_enabled = docs_enabled;
+
+ if (icon_enabled) {
+ icon_window = new SearchWindow (this);
+ icon_window.QueryEvent += OnQueryEvent;
+
+ tray = new 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");
+ string binding = new KeyBinding (binding_key, binding_ctrl, binding_alt).ToString ();
- if (binding != String.Empty) {
+ if (!String.IsNullOrEmpty (binding)) {
tip_text += String.Format (" ({0})", binding);
-
- // Attach the hide/show keybinding
+ XKeybinder keybinder = new XKeybinder ();
keybinder.Bind (binding, OnTrayActivated);
}
tray.TooltipText = tip_text;
- }*/
+ }
}
public void Query (string query_text)
{
- SearchWindow window = new SearchWindow (query_text);
- window.DeleteEvent += OnWindowDeleteEvent;
-
- ref_count++;
+ if (icon_enabled) {
+ if (!String.IsNullOrEmpty (query_text))
+ icon_window.Search (query_text);
+
+ icon_window.ShowAll ();
+ } else {
+ SearchWindow window = new SearchWindow (this);
+ window.DeleteEvent += OnWindowDeleteEvent;
+
+ if (!String.IsNullOrEmpty (query_text))
+ window.Search (query_text);
+
+ window.ShowAll ();
+ ref_count++;
+ }
}
- private void OnWindowDeleteEvent (object o, DeleteEventArgs args)
+ private void OnWindowDeleteEvent (object o, Gtk.DeleteEventArgs args)
{
if (--ref_count < 1)
- Application.Quit ();
+ Gtk.Application.Quit ();
+ }
+
+ private void OnTrayActivated (object o, EventArgs args)
+ {
+ if (! icon_window.Visible) {
+ icon_window.ShowAll ();
+ icon_window.Present ();
+ icon_window.GrabEntryFocus ();
+ } else {
+ icon_window.Hide ();
+ }
+ }
+
+ private void OnTraySearch (string query)
+ {
+ if (!icon_window.Visible)
+ icon_window.ShowAll ();
+
+ icon_window.Search (query);
+ }
+
+ private void OnQueryEvent (string query)
+ {
+ // Update the list of searches in the tray
+ // icon menu.
+
+ tray.AddSearch (query);
+ }
+
+ public bool IconEnabled {
+ get { return icon_enabled; }
+ }
+
+ public bool DocsEnabled {
+ get { return docs_enabled; }
}
}
}
Modified: trunk/beagle/search/Beagle.Search/SearchWindow.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search/SearchWindow.cs (original)
+++ trunk/beagle/search/Beagle.Search/SearchWindow.cs Wed Feb 27 22:08:12 2008
@@ -16,12 +16,15 @@
using Beagle.Util;
using Beagle.Search.Tiles;
-using Beagle.Search.Tray;
namespace Beagle.Search {
+ public delegate void QueryEventDelegate (string query);
+
public class SearchWindow : Window {
+ private ISearch search = null;
+
private Gtk.Button button;
private Gtk.Tooltips tips;
private Gtk.Notebook pages;
@@ -33,7 +36,6 @@
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;
@@ -45,6 +47,8 @@
private Beagle.Search.SortType sort = SortType.Modified;
private Beagle.Search.TypeFilter filter = null;
+ // Whether we should grab focus from the text entry
+ private bool grab_focus = false;
private uint timeout_id = 0;
private Beagle.Query current_query = null;
@@ -52,11 +56,14 @@
private bool show_details = true;
private int total_matches = -1;
- public SearchWindow (string query_text) : base (WindowType.Toplevel)
+ public event QueryEventDelegate QueryEvent;
+
+ public SearchWindow (ISearch search) : base (WindowType.Toplevel)
{
+ this.search = search;
+
base.Title = Catalog.GetString ("Desktop Search");
base.Icon = WidgetFu.LoadThemeIcon ("system-search", 16);
-
base.DefaultWidth = 700;
base.DefaultHeight = 550;
base.DeleteEvent += OnWindowDelete;
@@ -164,63 +171,42 @@
tips.SetTip (button, Catalog.GetString ("Start searching"), "");
tips.Enable ();
- if (Environment.UserName == "root" &&
- ! Conf.Daemon.GetOption (Conf.Names.AllowRoot, false)) {
+ 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);
}
- 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);
+ 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);
+ public void GrabEntryFocus ()
+ {
+ entry.GrabFocus ();
+ }
- this.statusbar.Push (0, message);
- }
- }
+ public void Search (string query)
+ {
+ entry.Text = query;
+ Query (true);
}
private void DetachQuery ()
{
- if (current_query != null) {
- TotalMatches = -1;
- current_query.HitsAddedEvent -= OnHitsAdded;
- current_query.HitsSubtractedEvent -= OnHitsSubtracted;
- current_query.Close ();
- }
- }
+ if (current_query == null)
+ return;
- // Whether we should grab focus from the text entry
- private bool grab_focus;
+ current_query.HitsAddedEvent -= OnHitsAdded;
+ current_query.HitsSubtractedEvent -= OnHitsSubtracted;
+ current_query.Close ();
+ TotalMatches = -1;
+ }
private void Query (bool grab_focus)
{
@@ -230,15 +216,15 @@
}
string query = query_text = entry.Text;
- if (query == null || query == "")
+
+ if (String.IsNullOrEmpty (query))
return;
SetWindowTitle (query);
ShowInformation (null);
- if (tray != null) {
- tray.AddSearch (query);
- }
+ if (QueryEvent != null)
+ QueryEvent (query);
filter = TypeFilter.MakeFilter (ref query);
@@ -257,9 +243,13 @@
current_query = new Query ();
current_query.AddDomain (QueryDomain.Neighborhood);
+ current_query.AddText (query);
+ current_query.HitsAddedEvent += OnHitsAdded;
+ current_query.HitsSubtractedEvent += OnHitsSubtracted;
+ current_query.FinishedEvent += OnFinished;
// Don't search documentation by default
- if (! Search.SearchDocs) {
+ if (!search.DocsEnabled) {
QueryPart_Property part = new QueryPart_Property ();
part.Logic = QueryPartLogic.Prohibited;
part.Type = PropertyType.Keyword;
@@ -268,12 +258,8 @@
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);
@@ -367,10 +353,11 @@
{
DetachQuery ();
- if (! indexinfo.Refresh ())
+ if (! indexinfo.Refresh ()) {
pages.CurrentPage = pages.PageNum (startdaemon);
- else
+ } else {
pages.CurrentPage = pages.PageNum (indexinfo);
+ }
}
private void OnDomainChanged (QueryDomain domain, bool active)
@@ -452,20 +439,19 @@
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";
+ SafeProcess p = new SafeProcess ();
+ p.Arguments = new string[] { "beagle-settings", "--networking" };
try {
p.Start ();
} catch (Exception e) {
- Console.WriteLine ("Could not start beagle-settings: {0}", e);
+ Console.WriteLine ("Could not start beagle-settings:\n{0}", e);
}
}
#endif
@@ -473,6 +459,7 @@
private void CheckNoMatch ()
{
MatchType matches = view.MatchState;
+
if (matches == MatchType.Matched) {
pages.CurrentPage = pages.PageNum (panes);
return;
@@ -480,8 +467,10 @@
if (nomatch != null)
nomatch.Destroy ();
+
nomatch = new Pages.NoMatch (query_text, matches == MatchType.NoneInScope);
nomatch.Show ();
+
pages.Add (nomatch);
pages.CurrentPage = pages.PageNum (nomatch);
}
@@ -507,5 +496,33 @@
notification_area.Hide ();
}
}
+
+ /////////////////////////////////////
+
+ public bool IconEnabled {
+ get { return search.IconEnabled; }
+ }
+
+ 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);
+ }
+ }
+ }
}
}
Modified: trunk/beagle/search/Beagle.Search/UIManager.cs
==============================================================================
--- trunk/beagle/search/Beagle.Search/UIManager.cs (original)
+++ trunk/beagle/search/Beagle.Search/UIManager.cs Wed Feb 27 22:08:12 2008
@@ -46,7 +46,7 @@
ActionEntry quit_action_entry;
- if (Search.IconEnabled) {
+ if (search.IconEnabled) {
quit_action_entry = new ActionEntry ("Quit", Gtk.Stock.Close,
null, "<control>Q",
Catalog.GetString ("Close Desktop Search"),
@@ -340,13 +340,13 @@
private void OnHideWindow (object obj, EventArgs args)
{
- if (Search.IconEnabled)
+ if (search.IconEnabled)
search.Hide ();
}
private void Quit (object obj, EventArgs args)
{
- if (Search.IconEnabled) {
+ if (search.IconEnabled) {
search.Hide ();
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]