2 using System
.Collections
;
14 public class MainWindow
: Window
{
17 Search
.GroupView view
;
20 Search
.Spinner spinner
;
23 Search
.Pages
.QuickTips quicktips
;
24 Search
.Pages
.RootUser rootuser
;
25 Search
.Pages
.StartDaemon startdaemon
;
26 Search
.Pages
.NoMatch nomatch
;
28 Search
.Tray
.TrayIcon tray
;
33 Beagle
.Query currentQuery
;
34 Search
.ScopeType scope
= ScopeType
.Everything
;
35 Search
.SortType sort
= SortType
.Modified
;
36 Search
.TypeFilter filter
= null;
37 bool showDetails
= true;
39 XKeybinder keybinder
= new XKeybinder ();
41 public static bool IconEnabled
= false;
43 public static void Main (string [] args
)
45 SystemInformation
.SetProcessName ("beagle-search");
47 Catalog
.Init ("beagle", ExternalStringsHack
.LocaleDir
);
49 string query
= ParseArgs (args
);
51 Gnome
.Program program
= new Gnome
.Program ("search", "0.0",
52 Gnome
.Modules
.UI
, args
);
54 MainWindow window
= new MainWindow ();
56 if (query
!= null && query
!= "" && !IconEnabled
) {
57 window
.entry
.Text
= query
;
64 private static string ParseArgs (String
[] args
)
69 while (i
< args
.Length
) {
81 if (! Conf
.Searching
.Autostart
) {
82 Console
.WriteLine ("beagle-search: Autostarting is disabled, not starting");
87 // Ignore session management
88 case "--sm-config-prefix":
89 case "--sm-client-id":
91 // These all take an argument, so
97 if (args
[i
].Length
< 2 || args
[i
].Substring (0, 2) != "--") {
98 if (query
.Length
!= 0)
111 public static void PrintUsageAndExit ()
114 "beagle-search: GUI interface to the Beagle search system.\n" +
115 "Web page: http://www.beagle-project.org/\n" +
116 "Copyright (C) 2005-2006 Novell, Inc.\n\n";
119 "Usage: beagle-search [OPTIONS] [<query string>]\n\n" +
121 " --help\t\t\tPrint this usage message.\n" +
122 " --icon\t\t\tAdd an icon to the notification area rather than opening a search window.\n";
124 Console
.WriteLine (usage
);
125 System
.Environment
.Exit (0);
128 public MainWindow () : base (WindowType
.Toplevel
)
130 Title
= "Desktop Search";
131 Icon
= Beagle
.Images
.GetPixbuf ("system-search.png");
135 DeleteEvent
+= OnWindowDelete
;
137 VBox vbox
= new VBox ();
140 uim
= new UIManager (this);
141 uim
.ScopeChanged
+= OnScopeChanged
;
142 uim
.SortChanged
+= OnSortChanged
;
143 uim
.ToggleDetails
+= OnToggleDetails
;
144 uim
.ShowQuickTips
+= OnShowQuickTips
;
145 vbox
.PackStart (uim
.MenuBar
, false, false, 0);
147 HBox padding_hbox
= new HBox ();
149 HBox hbox
= new HBox (false, 6);
151 Label label
= new Label (Catalog
.GetString ("_Find:"));
152 hbox
.PackStart (label
, false, false, 0);
154 entry
= new Entry ();
155 label
.MnemonicWidget
= entry
;
156 uim
.FocusSearchEntry
+= delegate () { entry.GrabFocus (); }
;
157 entry
.Activated
+= OnEntryActivated
;
158 entry
.Changed
+= OnEntryChanged
;
159 entry
.MoveCursor
+= OnEntryMoveCursor
;
160 hbox
.PackStart (entry
, true, true, 0);
162 button
= new Gtk
.Button ();
163 Gtk
.HBox button_hbox
= new Gtk
.HBox (false, 2);
164 Gtk
.Image icon
= new Gtk
.Image (Gtk
.Stock
.Find
, Gtk
.IconSize
.Button
);
165 button_hbox
.PackStart (icon
, false, false, 0);
166 label
= new Gtk
.Label (Catalog
.GetString ("Find Now"));
167 button_hbox
.PackStart (label
, false, false, 0);
168 button
.Add (button_hbox
);
169 button
.Clicked
+= OnButtonClicked
;
171 Gtk
.VBox buttonVBox
= new Gtk
.VBox (false, 0);
172 buttonVBox
.PackStart (button
, true, false, 0);
173 hbox
.PackStart (buttonVBox
, false, false, 0);
175 spinner
= new Spinner ();
177 hbox
.PackStart (spinner
, false, false, 0);
179 padding_hbox
.PackStart (hbox
, true, true, 9);
181 vbox
.PackStart (padding_hbox
, false, true, 6);
183 pages
= new Gtk
.Notebook ();
184 pages
.ShowTabs
= false;
185 pages
.ShowBorder
= false;
186 pages
.BorderWidth
= 3;
187 vbox
.PackStart (pages
, true, true, 0);
189 quicktips
= new Pages
.QuickTips ();
191 pages
.Add (quicktips
);
193 rootuser
= new Pages
.RootUser ();
195 pages
.Add (rootuser
);
197 startdaemon
= new Pages
.StartDaemon ();
198 startdaemon
.DaemonStarted
+= OnDaemonStarted
;
200 pages
.Add (startdaemon
);
202 panes
= new Search
.Panes ();
206 view
= new GroupView ();
207 view
.TileSelected
+= ShowInformation
;
208 view
.CategoryToggled
+= OnCategoryToggled
;
209 panes
.MainContents
= view
;
213 tips
= new Gtk
.Tooltips ();
214 tips
.SetTip (entry
, Catalog
.GetString ("Type in search terms"), "");
215 tips
.SetTip (button
, Catalog
.GetString ("Start searching"), "");
218 if (Environment
.UserName
== "root" && ! Conf
.Daemon
.AllowRoot
) {
219 pages
.CurrentPage
= pages
.PageNum (rootuser
);
220 entry
.Sensitive
= button
.Sensitive
= uim
.Sensitive
= false;
222 pages
.CurrentPage
= pages
.PageNum (quicktips
);
226 tray
= new Search
.Tray
.TrayIcon ();
227 tray
.Clicked
+= OnTrayActivated
;
228 tray
.Search
+= OnTraySearch
;
230 // Attach the hide/show keybinding
231 keybinder
.Bind (Conf
.Searching
.ShowSearchWindowBinding
.ToString (), OnTrayActivated
);
237 private void SetWindowTitle (string query
)
239 Title
= String
.Format ("Desktop Search: {0}", query
);
242 // Whether we should grab focus from the text entry
243 private bool grab_focus
;
245 private void Search (bool grab_focus
)
248 GLib
.Source
.Remove (timeout
);
252 string query
= queryText
= entry
.Text
;
253 if (query
== null || query
== "")
256 SetWindowTitle (query
);
257 ShowInformation (null);
260 tray
.AddSearch (query
);
263 filter
= TypeFilter
.MakeFilter (ref query
);
268 pages
.CurrentPage
= pages
.PageNum (panes
);
270 this.grab_focus
= grab_focus
;
273 if (currentQuery
!= null) {
274 currentQuery
.HitsAddedEvent
-= OnHitsAdded
;
275 currentQuery
.HitsSubtractedEvent
-= OnHitsSubtracted
;
276 currentQuery
.Close ();
279 currentQuery
= new Query ();
280 currentQuery
.AddDomain (QueryDomain
.Neighborhood
);
282 // Don't search documentation by default
283 QueryPart_Property part
= new QueryPart_Property ();
284 part
.Logic
= QueryPartLogic
.Prohibited
;
285 part
.Type
= PropertyType
.Keyword
;
286 part
.Key
= "beagle:Source";
287 part
.Value
= "documentation";
288 currentQuery
.AddPart (part
);
290 currentQuery
.AddText (query
);
291 currentQuery
.HitsAddedEvent
+= OnHitsAdded
;
292 currentQuery
.HitsSubtractedEvent
+= OnHitsSubtracted
;
293 currentQuery
.FinishedEvent
+= OnFinished
;
295 currentQuery
.SendAsync ();
297 } catch (Beagle
.ResponseMessageException
){
298 pages
.CurrentPage
= pages
.PageNum (startdaemon
);
299 } catch (Exception e
) {
300 Console
.WriteLine ("Querying the Beagle daemon failed: {0}", e
.Message
);
304 private void OnEntryActivated (object obj
, EventArgs args
)
309 private void OnDaemonStarted ()
314 private void OnEntryChanged (object obj
, EventArgs args
)
317 GLib
.Source
.Remove (timeout
);
318 timeout
= GLib
.Timeout
.Add (1000, OnEntryTimeout
);
321 private void OnEntryMoveCursor (object obj
, EventArgs args
)
324 GLib
.Source
.Remove (timeout
);
325 timeout
= GLib
.Timeout
.Add (1000, OnEntryTimeout
);
328 private bool OnEntryTimeout ()
335 private void OnButtonClicked (object obj
, EventArgs args
)
340 private void OnWindowDelete (object o
, Gtk
.DeleteEventArgs args
)
346 Gtk
.Application
.Quit ();
350 private void OnScopeChanged (Search
.ScopeType toggled
, bool active
)
353 view
.Scope
= scope
= scope
| toggled
;
355 view
.Scope
= scope
= scope ^ toggled
;
360 private void OnCategoryToggled (ScopeType toggled
)
362 string name
= ScopeType
.GetName (typeof (ScopeType
), toggled
);
364 ToggleAction act
= (ToggleAction
) uim
.GetAction ("/ui/MenuBar/Search/Scope/" + name
);
365 act
.Active
= ! act
.Active
;
367 catch (Exception ex
) {
368 Console
.WriteLine("Exception caught when trying to deactivate menu entry {0}:",name
);
369 Console
.WriteLine(ex
);
375 private void OnSortChanged (Search
.SortType newSort
)
377 view
.Sort
= sort
= newSort
;
380 private void OnToggleDetails (bool active
)
382 showDetails
= active
;
383 if (panes
.Details
!= null)
384 panes
.ToggleDetails (showDetails
);
386 panes
.ToggleDetails (false);
389 private void OnShowQuickTips ()
391 if (currentQuery
!= null) {
392 currentQuery
.HitsAddedEvent
-= OnHitsAdded
;
393 currentQuery
.HitsSubtractedEvent
-= OnHitsSubtracted
;
394 currentQuery
.Close ();
398 pages
.CurrentPage
= pages
.PageNum (quicktips
);
401 private void ShowInformation (Tiles
.Tile tile
)
404 panes
.Details
= tile
.Details
;
405 if (tile
.Details
!= null)
406 panes
.ToggleDetails (showDetails
);
408 panes
.ToggleDetails (false);
410 panes
.Details
= null;
411 panes
.ToggleDetails (false);
415 private void OnFinished (FinishedResponse response
)
418 view
.Finished (grab_focus
);
424 private void OnHitsAdded (HitsAddedResponse response
)
426 foreach (Hit hit
in response
.Hits
) {
427 Tile tile
= TileActivatorOrg
.MakeTile (hit
, currentQuery
);
431 if (filter
!= null && !filter
.Filter (tile
))
435 if (pages
.CurrentPageWidget
!= panes
)
436 pages
.CurrentPage
= pages
.PageNum (panes
);
440 private void OnHitsSubtracted (HitsSubtractedResponse response
)
442 foreach (Uri uri
in response
.Uris
)
443 view
.SubtractHit (uri
);
448 private void CheckNoMatch ()
450 MatchType matches
= view
.MatchState
;
451 if (matches
== MatchType
.Matched
) {
452 pages
.CurrentPage
= pages
.PageNum (panes
);
458 nomatch
= new Pages
.NoMatch (queryText
, matches
== MatchType
.NoneInScope
);
461 pages
.CurrentPage
= pages
.PageNum (nomatch
);
464 /////////////////////////////////////
466 private void OnTrayActivated (object o
, EventArgs args
)
477 private void OnTraySearch (string query
)