Show total number of results for google driver too. Helps to know if my query resulte...
[beagle.git] / search / UIManager.cs
blob1f59ef597c21826d9ff9fc84fd6c4bba2ea808af
1 using Gtk;
2 using Mono.Unix;
3 using System;
4 using System.Diagnostics;
6 using Beagle.Util;
8 namespace Search {
9 [Flags]
10 public enum ScopeType : ushort {
11 Nothing = 0,
12 Applications = 1 << 0,
13 Calendar = 1 << 1,
14 Contacts = 1 << 2,
15 Documents = 1 << 3,
16 Conversations = 1 << 4,
17 Images = 1 << 5,
18 Media = 1 << 6,
19 Folders = 1 << 7,
20 Websites = 1 << 8,
21 Feeds = 1 << 9,
22 Archives = 1 << 10,
23 Everything = UInt16.MaxValue // Lame but there's no way to do ~0 in a ushort way.
26 public enum SortType {
27 Relevance,
28 Name,
29 Modified
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,
49 null, "<control>Q",
50 Catalog.GetString ("Close Desktop Search"),
51 Quit);
52 } else {
53 quit_action_entry = new ActionEntry ("Quit", Gtk.Stock.Quit,
54 null, "<control>Q",
55 Catalog.GetString ("Exit Desktop Search"),
56 Quit);
60 Gtk.ActionEntry[] entries = new ActionEntry[] {
61 new ActionEntry ("Search", null,
62 Catalog.GetString ("_Search"),
63 null, null, null),
64 new ActionEntry ("Scope", null,
65 Catalog.GetString ("Show _Categories"),
66 null, null, null),
67 new ActionEntry ("Actions", null,
68 Catalog.GetString ("_Actions"),
69 null, null, null),
70 new ActionEntry ("View", null,
71 Catalog.GetString ("_View"),
72 null, null, null),
73 new ActionEntry ("Help", null,
74 Catalog.GetString ("_Help"),
75 null, null, null),
77 quit_action_entry,
78 new ActionEntry ("Preferences", Gtk.Stock.Preferences,
79 null, null,
80 Catalog.GetString ("Exit Desktop Search"),
81 Preferences),
82 new ActionEntry ("Contents", Gtk.Stock.Help,
83 Catalog.GetString ("_Contents"),
84 "F1",
85 Catalog.GetString ("Help - Table of Contents"),
86 Help),
87 new ActionEntry ("About", Gnome.Stock.About,
88 null, null,
89 Catalog.GetString ("About Desktop Search"),
90 About),
91 new ActionEntry ("QuickTips", null,
92 Catalog.GetString ("Quick Tips"),
93 null, null, QuickTips),
94 new ActionEntry ("FocusSearchEntry", null, "",
95 "<control>K", null,
96 OnFocusSearchEntry),
97 new ActionEntry ("FocusSearchEntry2", null, "",
98 "<control>L", null,
99 OnFocusSearchEntry),
100 new ActionEntry ("HideWindow", null, "",
101 "Escape", null,
102 OnHideWindow),
103 new ActionEntry ("HideWindow2", null, "",
104 "<control>W", null,
105 OnHideWindow)
107 actions.Add (entries);
109 Gtk.ActionEntry[] multiscope_entries = new ActionEntry[] {
110 new ActionEntry ("All", null,
111 Catalog.GetString ("_All"),
112 null, null,
113 delegate {
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"),
122 null, null,
123 delegate {
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"),
136 null,
137 Catalog.GetString ("Search applications"),
138 OnScopeChanged,
139 true),
140 new ToggleActionEntry ("Contacts", null,
141 Catalog.GetString ("_Contacts"),
142 null,
143 Catalog.GetString ("Search contacts"),
144 OnScopeChanged,
145 true),
146 new ToggleActionEntry ("Calendar", null,
147 Catalog.GetString ("Ca_lendar events"),
148 null,
149 Catalog.GetString ("Search calendar events"),
150 OnScopeChanged,
151 true),
152 new ToggleActionEntry ("Documents", null,
153 Catalog.GetString ("_Documents"),
154 null,
155 Catalog.GetString ("Search documents"),
156 OnScopeChanged,
157 true),
158 new ToggleActionEntry ("Conversations", null,
159 Catalog.GetString ("Conve_rsations"),
160 null,
161 Catalog.GetString ("Search E-Mail and Instant Messaging logs"),
162 OnScopeChanged,
163 true),
164 new ToggleActionEntry ("Images", null,
165 Catalog.GetString ("_Images"),
166 null,
167 Catalog.GetString ("Search images"),
168 OnScopeChanged,
169 true),
170 new ToggleActionEntry ("Media", null,
171 Catalog.GetString ("_Media"),
172 null,
173 Catalog.GetString ("Search sound and video files"),
174 OnScopeChanged,
175 true),
176 new ToggleActionEntry ("Folders", null,
177 Catalog.GetString ("_Folders"),
178 null,
179 Catalog.GetString ("Search for folder names"),
180 OnScopeChanged,
181 true),
182 new ToggleActionEntry ("Websites", null,
183 Catalog.GetString ("_Websites"),
184 null,
185 Catalog.GetString ("Search website history"),
186 OnScopeChanged,
187 true),
188 new ToggleActionEntry ("Feeds", null,
189 Catalog.GetString ("_News Feeds"),
190 null,
191 Catalog.GetString ("Search news feeds"),
192 OnScopeChanged,
193 true),
194 new ToggleActionEntry ("Archives", null,
195 Catalog.GetString ("A_rchives"),
196 null,
197 Catalog.GetString ("Search files in Archives"),
198 OnScopeChanged,
199 true)
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"),
211 (int)SortType.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 {
232 get {
233 return (Gtk.MenuBar)GetWidget ("/MenuBar");
237 private bool sensitive = true;
238 public bool Sensitive {
239 get { return this.sensitive; }
240 set {
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 =
254 "<ui>" +
255 " <menubar name='MenuBar'>" +
256 " <menu action='Search'>" +
257 " <menu action='Scope'>" +
258 " <menuitem action='All'/>" +
259 " <menuitem action='None'/>" +
260 " <separator/>" +
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'/>" +
273 " </menu>" +
274 " <separator/>" +
275 " <menuitem action='Preferences'/>" +
276 " <menuitem action='Quit'/>" +
277 " </menu>" +
278 " <menu action='Actions'>" +
279 " </menu>" +
280 " <menu action='View'>" +
281 " <menuitem action='SortModified'/>" +
282 " <menuitem action='SortName'/>" +
283 " <menuitem action='SortRelevance'/>" +
284 " <separator/>" +
285 " <menuitem action='ShowDetails'/>" +
286 " </menu>" +
287 " <menu action='Help'>" +
288 " <menuitem action='Contents'/>" +
289 " <menuitem action='QuickTips'/>" +
290 " <menuitem action='About'/>" +
291 " </menu>" +
292 " </menubar>" +
293 " <accelerator action='FocusSearchEntry'/>" +
294 " <accelerator action='FocusSearchEntry2'/>" +
295 " <accelerator action='HideWindow'/>" +
296 " <accelerator action='HideWindow2'/>" +
297 "</ui>";
299 private void Preferences (object obj, EventArgs args)
301 Process p = new Process ();
302 p.StartInfo.UseShellExecute = false;
303 p.StartInfo.FileName = "beagle-settings";
305 try {
306 p.Start ();
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)
327 ShowQuickTips ();
330 private void OnHideWindow (object obj, EventArgs args)
332 if (MainWindow.IconEnabled)
333 main_window.Hide ();
336 private void Quit (object obj, EventArgs args)
338 if (MainWindow.IconEnabled) {
339 main_window.Hide ();
340 } else {
341 Gtk.Application.Quit ();
345 private void Help (object obj, EventArgs args)
347 string address = "http://www.beagle-project.org/Getting_Started";
349 try {
350 Gnome.Url.Show (address);
351 } catch {
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)));
356 md.Run ();
357 md.Destroy ();
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,
377 logo);
378 about.Run ();
379 about.Dispose ();
380 #pragma warning restore 612
383 private void OnFocusSearchEntry (object obj, EventArgs args)
385 if (FocusSearchEntry != null)
386 FocusSearchEntry ();
389 public delegate void FocusSearchEntryDelegate ();
390 public event FocusSearchEntryDelegate FocusSearchEntry;
392 private void OnScopeChanged (object obj, EventArgs args)
394 if (ScopeChanged == null)
395 return;
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;