2 using System
.Collections
;
14 public class MainWindow
: Window
{
16 Search
.GroupView view
;
19 Search
.Spinner spinner
;
22 Search
.Pages
.QuickTips quicktips
;
23 Search
.Pages
.RootUser rootuser
;
24 Search
.Pages
.StartDaemon startdaemon
;
25 Search
.Pages
.NoMatch nomatch
;
27 Search
.Tray
.TrayIcon tray
;
32 Beagle
.Query currentQuery
;
33 Search
.ScopeType scope
= ScopeType
.Everywhere
;
34 Search
.SortType sort
= SortType
.Modified
;
35 Search
.TypeFilter filter
= null;
37 XKeybinder keybinder
= new XKeybinder ();
39 public static bool IconEnabled
= false;
41 public static void Main (string [] args
)
43 SystemInformation
.SetProcessName ("beagle-search");
45 Catalog
.Init ("beagle", ExternalStringsHack
.LocaleDir
);
47 string query
= ParseArgs (args
);
49 Gnome
.Program program
= new Gnome
.Program ("search", "0.0",
50 Gnome
.Modules
.UI
, args
);
52 MainWindow window
= new MainWindow ();
54 if (query
!= null && query
!= "" && !IconEnabled
) {
55 window
.entry
.Text
= query
;
62 private static string ParseArgs (String
[] args
)
67 while (i
< args
.Length
) {
79 if (! Conf
.Searching
.Autostart
) {
80 Console
.WriteLine ("beagle-search: Autostarting is disabled, not starting");
85 // Ignore session management
86 case "--sm-config-prefix":
87 case "--sm-client-id":
89 // These all take an argument, so
95 if (args
[i
].Length
< 2 || args
[i
].Substring (0, 2) != "--") {
96 if (query
.Length
!= 0)
109 public static void PrintUsageAndExit ()
112 "beagle-search: GUI interface to the Beagle search system.\n" +
113 "Web page: http://www.beagle-project.org/\n" +
114 "Copyright (C) 2005-2006 Novell, Inc.\n\n";
117 "Usage: beagle-search [OPTIONS] [<query string>]\n\n" +
119 " --help\t\t\tPrint this usage message.\n" +
120 " --icon\t\t\tAdd an icon to the notification area rather than opening a search window.\n";
122 Console
.WriteLine (usage
);
123 System
.Environment
.Exit (0);
126 public MainWindow () : base (WindowType
.Toplevel
)
128 Title
= "Desktop Search";
129 Icon
= Beagle
.Images
.GetPixbuf ("system-search.png");
134 DeleteEvent
+= OnWindowDelete
;
136 VBox vbox
= new VBox ();
139 UIManager uim
= new UIManager (this);
140 uim
.ScopeChanged
+= OnScopeChanged
;
141 uim
.SortChanged
+= OnSortChanged
;
142 uim
.ShowQuickTips
+= OnShowQuickTips
;
143 vbox
.PackStart (uim
.MenuBar
, false, false, 0);
145 HBox padding_hbox
= new HBox ();
147 HBox hbox
= new HBox (false, 6);
149 Label label
= new Label (Catalog
.GetString ("_Find:"));
150 hbox
.PackStart (label
, false, false, 0);
152 entry
= new Entry ();
153 label
.MnemonicWidget
= entry
;
154 uim
.FocusSearchEntry
+= delegate () { entry.GrabFocus (); }
;
155 entry
.Activated
+= OnEntryActivated
;
156 entry
.Changed
+= OnEntryChanged
;
157 hbox
.PackStart (entry
, true, true, 0);
159 button
= new Gtk
.Button ();
160 Gtk
.HBox button_hbox
= new Gtk
.HBox (false, 2);
161 Gtk
.Image icon
= new Gtk
.Image (Gtk
.Stock
.Find
, Gtk
.IconSize
.Button
);
162 button_hbox
.PackStart (icon
, false, false, 0);
163 label
= new Gtk
.Label (Catalog
.GetString ("Find Now"));
164 button_hbox
.PackStart (label
, false, false, 0);
165 button
.Add (button_hbox
);
166 button
.Clicked
+= OnButtonClicked
;
168 Gtk
.VBox buttonVBox
= new Gtk
.VBox (false, 0);
169 buttonVBox
.PackStart (button
, true, false, 0);
170 hbox
.PackStart (buttonVBox
, false, false, 0);
172 spinner
= new Spinner ();
174 hbox
.PackStart (spinner
, false, false, 0);
176 padding_hbox
.PackStart (hbox
, true, true, 9);
178 vbox
.PackStart (padding_hbox
, false, true, 6);
180 pages
= new Gtk
.Notebook ();
181 pages
.ShowTabs
= false;
182 pages
.ShowBorder
= false;
183 vbox
.PackStart (pages
, true, true, 0);
185 quicktips
= new Pages
.QuickTips ();
187 pages
.Add (quicktips
);
189 rootuser
= new Pages
.RootUser ();
191 pages
.Add (rootuser
);
193 startdaemon
= new Pages
.StartDaemon ();
194 startdaemon
.DaemonStarted
+= OnDaemonStarted
;
196 pages
.Add (startdaemon
);
198 panes
= new Search
.Panes ();
202 view
= new GroupView ();
203 view
.TileSelected
+= ShowInformation
;
204 panes
.MainContents
= view
;
208 tips
= new Gtk
.Tooltips ();
209 tips
.SetTip (entry
, Catalog
.GetString ("Type in search terms"), "");
210 tips
.SetTip (button
, Catalog
.GetString ("Start searching"), "");
213 if (Environment
.UserName
== "root" && ! Conf
.Daemon
.AllowRoot
) {
214 pages
.CurrentPage
= pages
.PageNum (rootuser
);
215 entry
.Sensitive
= button
.Sensitive
= uim
.Sensitive
= false;
217 pages
.CurrentPage
= pages
.PageNum (quicktips
);
221 tray
= new TrayIcon ();
222 tray
.Clicked
+= OnTrayActivated
;
223 tray
.Search
+= OnTraySearch
;
225 // Attach the hide/show keybinding
226 keybinder
.Bind (Conf
.Searching
.ShowSearchWindowBinding
.ToString (), OnTrayActivated
);
234 private void SetWindowTitle (string query
)
236 Title
= String
.Format ("Desktop Search: {0}", query
);
239 private void Search (bool grabFocus
)
242 GLib
.Source
.Remove (timeout
);
246 string query
= queryText
= entry
.Text
;
247 if (query
== null || query
== "")
250 SetWindowTitle (query
);
251 ShowInformation (null);
254 tray
.AddSearch (query
);
257 filter
= TypeFilter
.MakeFilter (ref query
);
262 pages
.CurrentPage
= pages
.PageNum (panes
);
264 oldFocus
= grabFocus
? Focus
: null;
267 if (currentQuery
!= null) {
268 currentQuery
.HitsAddedEvent
-= OnHitsAdded
;
269 currentQuery
.HitsSubtractedEvent
-= OnHitsSubtracted
;
270 currentQuery
.Close ();
273 currentQuery
= new Query ();
274 currentQuery
.AddDomain (QueryDomain
.Neighborhood
);
276 // Don't search documentation by default
277 QueryPart_Property part
= new QueryPart_Property ();
278 part
.Logic
= QueryPartLogic
.Prohibited
;
279 part
.Type
= PropertyType
.Keyword
;
280 part
.Key
= "beagle:Source";
281 part
.Value
= "documentation";
282 currentQuery
.AddPart (part
);
284 currentQuery
.AddText (query
);
285 currentQuery
.HitsAddedEvent
+= OnHitsAdded
;
286 currentQuery
.HitsSubtractedEvent
+= OnHitsSubtracted
;
287 currentQuery
.FinishedEvent
+= OnFinished
;
289 currentQuery
.SendAsync ();
291 } catch (Beagle
.ResponseMessageException e
){
292 pages
.CurrentPage
= pages
.PageNum (startdaemon
);
293 } catch (Exception e
) {
294 Console
.WriteLine ("Querying the Beagle daemon failed: {0}", e
.Message
);
298 private void OnEntryActivated (object obj
, EventArgs args
)
303 private void OnDaemonStarted ()
308 private void OnEntryChanged (object obj
, EventArgs args
)
311 GLib
.Source
.Remove (timeout
);
312 timeout
= GLib
.Timeout
.Add (1000, OnEntryTimeout
);
315 private bool OnEntryTimeout ()
322 private void OnButtonClicked (object obj
, EventArgs args
)
327 private void OnWindowDelete (object o
, Gtk
.DeleteEventArgs args
)
333 Gtk
.Application
.Quit ();
337 private void OnScopeChanged (Search
.ScopeType newScope
)
339 view
.Scope
= scope
= newScope
;
343 private void OnSortChanged (Search
.SortType newSort
)
345 view
.Sort
= sort
= newSort
;
348 private void OnShowQuickTips ()
350 if (currentQuery
!= null) {
351 currentQuery
.HitsAddedEvent
-= OnHitsAdded
;
352 currentQuery
.HitsSubtractedEvent
-= OnHitsSubtracted
;
353 currentQuery
.Close ();
357 pages
.CurrentPage
= pages
.PageNum (quicktips
);
360 private void ShowInformation (Tiles
.Tile tile
)
363 panes
.Details
= tile
.Details
;
365 panes
.Details
= null;
368 private void OnFinished (FinishedResponse response
)
371 view
.Finished (oldFocus
== Focus
);
376 private void OnHitsAdded (HitsAddedResponse response
)
378 foreach (Hit hit
in response
.Hits
) {
379 Tile tile
= TileActivatorOrg
.MakeTile (hit
, currentQuery
);
383 if (filter
!= null && !filter
.Filter (tile
))
387 if (pages
.CurrentPageWidget
!= panes
)
388 pages
.CurrentPage
= pages
.PageNum (panes
);
392 private void OnHitsSubtracted (HitsSubtractedResponse response
)
394 foreach (Uri uri
in response
.Uris
)
395 view
.SubtractHit (uri
);
400 private void CheckNoMatch ()
402 MatchType matches
= view
.MatchState
;
403 if (matches
== MatchType
.Matched
) {
404 pages
.CurrentPage
= pages
.PageNum (panes
);
410 nomatch
= new Pages
.NoMatch (queryText
, matches
== MatchType
.NoneInScope
);
413 pages
.CurrentPage
= pages
.PageNum (nomatch
);
416 /////////////////////////////////////
418 private void OnTrayActivated (object o
, EventArgs args
)
428 private void OnTraySearch (string query
)