4 using System
.Diagnostics
;
10 public enum ScopeType
: ushort {
12 Applications
= 1 << 0,
16 Conversations
= 1 << 4,
23 Everything
= UInt16
.MaxValue
// Lame but there's no way to do ~0 in a ushort way.
26 public enum SortType
{
32 public class UIManager
: Gtk
.UIManager
{
34 private MainWindow main_window
;
36 private Gtk
.ActionGroup actions
;
37 private Gtk
.RadioActionEntry
[] sort_entries
;
38 private Gtk
.ToggleActionEntry
[] scope_entries
, view_entries
;
40 public UIManager (MainWindow main_window
)
42 this.main_window
= main_window
;
44 actions
= new ActionGroup ("Actions");
46 ActionEntry quit_action_entry
;
47 if (MainWindow
.IconEnabled
) {
48 quit_action_entry
= new ActionEntry ("Quit", Gtk
.Stock
.Close
,
50 Catalog
.GetString ("Close Desktop Search"),
53 quit_action_entry
= new ActionEntry ("Quit", Gtk
.Stock
.Quit
,
55 Catalog
.GetString ("Exit Desktop Search"),
60 Gtk
.ActionEntry
[] entries
= new ActionEntry
[] {
61 new ActionEntry ("Search", null,
62 Catalog
.GetString ("_Search"),
64 new ActionEntry ("Scope", null,
65 Catalog
.GetString ("Show _Categories"),
67 new ActionEntry ("Actions", null,
68 Catalog
.GetString ("_Actions"),
70 new ActionEntry ("View", null,
71 Catalog
.GetString ("_View"),
73 new ActionEntry ("Help", null,
74 Catalog
.GetString ("_Help"),
78 new ActionEntry ("Preferences", Gtk
.Stock
.Preferences
,
80 Catalog
.GetString ("Exit Desktop Search"),
82 new ActionEntry ("Contents", Gtk
.Stock
.Help
,
83 Catalog
.GetString ("_Contents"),
85 Catalog
.GetString ("Help - Table of Contents"),
87 new ActionEntry ("About", Gnome
.Stock
.About
,
89 Catalog
.GetString ("About Desktop Search"),
91 new ActionEntry ("QuickTips", null,
92 Catalog
.GetString ("Quick Tips"),
93 null, null, QuickTips
),
94 new ActionEntry ("FocusSearchEntry", null, "",
97 new ActionEntry ("FocusSearchEntry2", null, "",
100 new ActionEntry ("HideWindow", null, "",
103 new ActionEntry ("HideWindow2", null, "",
107 actions
.Add (entries
);
109 Gtk
.ActionEntry
[] multiscope_entries
= new ActionEntry
[] {
110 new ActionEntry ("All", null,
111 Catalog
.GetString ("_All"),
114 if (ScopeChanged
!= null)
115 ScopeChanged (ScopeType
.Everything
, true);
117 foreach (ToggleActionEntry t
in scope_entries
)
118 ((ToggleAction
) actions
[t
.name
]).Active
= true;
120 new ActionEntry ("None", null,
121 Catalog
.GetString ("_None"),
124 if (ScopeChanged
!= null)
125 ScopeChanged (ScopeType
.Nothing
, true);
127 foreach (ToggleActionEntry t
in scope_entries
)
128 ((ToggleAction
) actions
[t
.name
]).Active
= false;
131 actions
.Add (multiscope_entries
);
133 scope_entries
= new ToggleActionEntry
[] {
134 new ToggleActionEntry ("Applications", null,
135 Catalog
.GetString ("A_pplications"),
137 Catalog
.GetString ("Search applications"),
140 new ToggleActionEntry ("Contacts", null,
141 Catalog
.GetString ("_Contacts"),
143 Catalog
.GetString ("Search contacts"),
146 new ToggleActionEntry ("Calendar", null,
147 Catalog
.GetString ("Ca_lendar events"),
149 Catalog
.GetString ("Search calendar events"),
152 new ToggleActionEntry ("Documents", null,
153 Catalog
.GetString ("_Documents"),
155 Catalog
.GetString ("Search documents"),
158 new ToggleActionEntry ("Conversations", null,
159 Catalog
.GetString ("Conve_rsations"),
161 Catalog
.GetString ("Search E-Mail and Instant Messaging logs"),
164 new ToggleActionEntry ("Images", null,
165 Catalog
.GetString ("_Images"),
167 Catalog
.GetString ("Search images"),
170 new ToggleActionEntry ("Media", null,
171 Catalog
.GetString ("_Media"),
173 Catalog
.GetString ("Search sound and video files"),
176 new ToggleActionEntry ("Folders", null,
177 Catalog
.GetString ("_Folders"),
179 Catalog
.GetString ("Search for folder names"),
182 new ToggleActionEntry ("Websites", null,
183 Catalog
.GetString ("_Websites"),
185 Catalog
.GetString ("Search website history"),
188 new ToggleActionEntry ("Feeds", null,
189 Catalog
.GetString ("_News Feeds"),
191 Catalog
.GetString ("Search news feeds"),
194 new ToggleActionEntry ("Archives", null,
195 Catalog
.GetString ("A_rchives"),
197 Catalog
.GetString ("Search files in Archives"),
201 actions
.Add (scope_entries
);
203 sort_entries
= new RadioActionEntry
[] {
204 new RadioActionEntry ("SortModified", null,
205 Catalog
.GetString ("Sort by Date _Modified"), null,
206 Catalog
.GetString ("Sort the most-recently-modified matches first"),
207 (int)SortType
.Modified
),
208 new RadioActionEntry ("SortName", null,
209 Catalog
.GetString ("Sort by _Name"), null,
210 Catalog
.GetString ("Sort matches by name"),
212 new RadioActionEntry ("SortRelevance", null,
213 Catalog
.GetString ("Sort by _Relevance"), null,
214 Catalog
.GetString ("Sort the best matches first"),
215 (int)SortType
.Relevance
),
217 actions
.Add (sort_entries
, (int)SortType
.Modified
, OnSortChanged
);
219 view_entries
= new ToggleActionEntry
[] {
220 new ToggleActionEntry ("ShowDetails", null,
221 Catalog
.GetString ("Show Details"), null, null,
222 OnToggleDetails
, true)
224 actions
.Add (view_entries
);
226 InsertActionGroup (actions
, 0);
227 main_window
.AddAccelGroup (AccelGroup
);
228 AddUiFromString (ui_def
);
231 public Gtk
.MenuBar MenuBar
{
233 return (Gtk
.MenuBar
)GetWidget ("/MenuBar");
237 private bool sensitive
= true;
238 public bool Sensitive
{
239 get { return this.sensitive; }
241 this.sensitive
= value;
243 actions
["QuickTips"].Sensitive
= value;
245 foreach (Gtk
.ToggleActionEntry rae
in scope_entries
)
246 actions
[rae
.name
].Sensitive
= value;
248 foreach (Gtk
.RadioActionEntry rae
in sort_entries
)
249 actions
[rae
.name
].Sensitive
= value;
253 private const string ui_def
=
255 " <menubar name='MenuBar'>" +
256 " <menu action='Search'>" +
257 " <menu action='Scope'>" +
258 " <menuitem action='All'/>" +
259 " <menuitem action='None'/>" +
261 " <menuitem action='Applications'/>" +
262 " <menuitem action='Contacts'/>" +
263 " <menuitem action='Calendar'/>" +
264 " <menuitem action='Documents'/>" +
265 " <menuitem action='Conversations'/>" +
266 " <menuitem action='Images'/>" +
267 " <menuitem action='Media'/>" +
268 " <menuitem action='Folders'/>" +
269 " <menuitem action='Websites'/>" +
270 " <menuitem action='Feeds'/>" +
271 // You can't search inside archives, so turn this off for now
272 //" <menuitem action='Archives'/>" +
275 " <menuitem action='Preferences'/>" +
276 " <menuitem action='Quit'/>" +
278 " <menu action='Actions'>" +
280 " <menu action='View'>" +
281 " <menuitem action='SortModified'/>" +
282 " <menuitem action='SortName'/>" +
283 " <menuitem action='SortRelevance'/>" +
285 " <menuitem action='ShowDetails'/>" +
287 " <menu action='Help'>" +
288 " <menuitem action='Contents'/>" +
289 " <menuitem action='QuickTips'/>" +
290 " <menuitem action='About'/>" +
293 " <accelerator action='FocusSearchEntry'/>" +
294 " <accelerator action='FocusSearchEntry2'/>" +
295 " <accelerator action='HideWindow'/>" +
296 " <accelerator action='HideWindow2'/>" +
299 private void Preferences (object obj
, EventArgs args
)
301 Process p
= new Process ();
302 p
.StartInfo
.UseShellExecute
= false;
303 p
.StartInfo
.FileName
= "beagle-settings";
307 } catch (Exception e
) {
308 Console
.WriteLine ("Could not start beagle-settings: {0}", e
);
312 public delegate void ToggleDetailsDelegate (bool active
);
313 public event ToggleDetailsDelegate ToggleDetails
;
315 private void OnToggleDetails (object obj
, EventArgs args
)
317 if (ToggleDetails
!= null)
318 ToggleDetails (((ToggleAction
) obj
).Active
);
321 public delegate void ShowQuickTipsDelegate ();
322 public event ShowQuickTipsDelegate ShowQuickTips
;
324 private void QuickTips (object obj
, EventArgs args
)
326 if (ShowQuickTips
!= null)
330 private void OnHideWindow (object obj
, EventArgs args
)
332 if (MainWindow
.IconEnabled
)
336 private void Quit (object obj
, EventArgs args
)
338 if (MainWindow
.IconEnabled
) {
341 Gtk
.Application
.Quit ();
345 private void Help (object obj
, EventArgs args
)
347 string address
= "http://www.beagle-project.org/Getting_Started";
350 Gnome
.Url
.Show (address
);
352 HigMessageDialog md
= new HigMessageDialog (main_window
, Gtk
.DialogFlags
.DestroyWithParent
,
353 Gtk
.MessageType
.Error
, Gtk
.ButtonsType
.Close
,
354 Catalog
.GetString ("Couldn't launch web browser"),
355 Catalog
.GetString (String
.Format ("Please point your web browser to '{0}' manually", address
)));
361 private void About (object obj
, EventArgs args
)
363 Gdk
.Pixbuf logo
= Beagle
.Images
.GetPixbuf ("system-search.png");
365 string[] people
= new string[] { "Anna Dirks <anna@novell.com>",
366 "Fredrik Hedberg <fredrik@avafan.com>",
367 "Lukas Lipka <lukas@pmad.net>",
368 "Joe Shaw <joeshaw@novell.com>",
369 "Jakub Steiner <jimmac@novell.com>",
370 "Dan Winship <danw@novell.com>" };
372 #pragma warning disable 612 // don't warn that Gnome.About is deprecated
373 Gnome
.About about
= new Gnome
.About ("Beagle Search",
374 Beagle
.Util
.ExternalStringsHack
.Version
,
375 "Copyright 2005-2006 Novell, Inc.",
376 null, people
, null, null,
380 #pragma warning restore 612
383 private void OnFocusSearchEntry (object obj
, EventArgs args
)
385 if (FocusSearchEntry
!= null)
389 public delegate void FocusSearchEntryDelegate ();
390 public event FocusSearchEntryDelegate FocusSearchEntry
;
392 private void OnScopeChanged (object obj
, EventArgs args
)
394 if (ScopeChanged
== null)
397 ScopeType scope
= (ScopeType
) System
.Enum
.Parse (typeof (ScopeType
), ((Action
) obj
).Name
);
399 ScopeChanged (scope
, ((ToggleAction
) obj
).Active
);
402 public delegate void ScopeChangedDelegate (ScopeType scope
, bool active
);
403 public event ScopeChangedDelegate ScopeChanged
;
405 private void OnSortChanged (object obj
, Gtk
.ChangedArgs args
)
407 if (SortChanged
!= null)
408 SortChanged ((SortType
)args
.Current
.CurrentValue
);
411 public delegate void SortChangedDelegate (SortType scope
);
412 public event SortChangedDelegate SortChanged
;