For writable files, if previously attributes were stored in sqlite db, remove it...
[beagle.git] / search / UIManager.cs
blob2c1ced29fb9b8713f8caad7a23a329eaf044494b
1 using Gtk;
2 using Mono.Unix;
3 using System;
4 using System.Diagnostics;
6 namespace Search {
8 public enum ScopeType {
9 Everywhere,
10 Applications,
11 Calendar,
12 Contacts,
13 Documents,
14 Conversations,
15 Images,
16 Media
19 public enum SortType {
20 Relevance,
21 Name,
22 Modified
25 public class UIManager : Gtk.UIManager {
27 private MainWindow main_window;
29 private Gtk.ActionGroup actions;
30 private Gtk.RadioActionEntry[] scope_entries, sort_entries;
32 public UIManager (MainWindow main_window)
34 this.main_window = main_window;
36 actions = new ActionGroup ("Actions");
38 ActionEntry quit_action_entry;
39 if (MainWindow.IconEnabled) {
40 quit_action_entry = new ActionEntry ("Quit", Gtk.Stock.Close,
41 null, "<control>Q",
42 Catalog.GetString ("Close Desktop Search"),
43 Quit);
44 } else {
45 quit_action_entry = new ActionEntry ("Quit", Gtk.Stock.Quit,
46 null, "<control>Q",
47 Catalog.GetString ("Exit Desktop Search"),
48 Quit);
52 Gtk.ActionEntry[] entries = new ActionEntry[] {
53 new ActionEntry ("Search", null,
54 Catalog.GetString ("_Search"),
55 null, null, null),
56 new ActionEntry ("Actions", null,
57 Catalog.GetString ("_Actions"),
58 null, null, null),
59 new ActionEntry ("SortBy", null,
60 Catalog.GetString ("Sor_t"),
61 null, null, null),
62 new ActionEntry ("Help", null,
63 Catalog.GetString ("_Help"),
64 null, null, null),
66 quit_action_entry,
67 new ActionEntry ("Preferences", Gtk.Stock.Preferences,
68 null, null,
69 Catalog.GetString ("Exit Desktop Search"),
70 Preferences),
71 new ActionEntry ("Contents", Gtk.Stock.Help,
72 Catalog.GetString ("_Contents"),
73 "F1",
74 Catalog.GetString ("Help - Table of Contents"),
75 Help),
76 new ActionEntry ("About", Gnome.Stock.About,
77 null, null,
78 Catalog.GetString ("About Desktop Search"),
79 About),
80 new ActionEntry ("QuickTips", null,
81 Catalog.GetString ("Quick Tips"),
82 null, null, QuickTips),
83 new ActionEntry ("FocusSearchEntry", null, "",
84 "<control>K", null,
85 OnFocusSearchEntry),
86 new ActionEntry ("FocusSearchEntry2", null, "",
87 "<control>L", null,
88 OnFocusSearchEntry),
89 new ActionEntry ("HideWindow", null, "",
90 "Escape", null,
91 OnHideWindow),
92 new ActionEntry ("HideWindow2", null, "",
93 "<control>W", null,
94 OnHideWindow)
96 actions.Add (entries);
98 scope_entries = new RadioActionEntry[] {
99 new RadioActionEntry ("Everywhere", null,
100 Catalog.GetString ("_Everywhere"),
101 "<control>E",
102 Catalog.GetString ("Search everywhere"),
103 (int)ScopeType.Everywhere),
104 new RadioActionEntry ("Applications", null,
105 Catalog.GetString ("_Applications"),
106 null,
107 Catalog.GetString ("Search applications"),
108 (int)ScopeType.Applications),
109 new RadioActionEntry ("Contacts", null,
110 Catalog.GetString ("_Contacts"),
111 null,
112 Catalog.GetString ("Search contacts"),
113 (int)ScopeType.Contacts),
114 new RadioActionEntry ("Calendar", null,
115 Catalog.GetString ("Ca_lendar events"),
116 null,
117 Catalog.GetString ("Search calendar events"),
118 (int)ScopeType.Contacts),
119 new RadioActionEntry ("Documents", null,
120 Catalog.GetString ("_Documents"),
121 null,
122 Catalog.GetString ("Search documents"),
123 (int)ScopeType.Documents),
124 new RadioActionEntry ("Conversations", null,
125 Catalog.GetString ("Conve_rsations"),
126 null,
127 Catalog.GetString ("Search E-Mail and Instant Messaging logs"),
128 (int)ScopeType.Conversations),
129 new RadioActionEntry ("Images", null,
130 Catalog.GetString ("_Images"),
131 null,
132 Catalog.GetString ("Search images"),
133 (int)ScopeType.Images),
134 new RadioActionEntry ("Media", null,
135 Catalog.GetString ("_Media"),
136 null,
137 Catalog.GetString ("Search sound and video files"),
138 (int)ScopeType.Media),
140 actions.Add (scope_entries, (int)ScopeType.Everywhere, OnScopeChanged);
142 sort_entries = new RadioActionEntry[] {
143 new RadioActionEntry ("Modified", null,
144 Catalog.GetString ("Date _Modified"), null,
145 Catalog.GetString ("Sort the most-recently-modified matches first"),
146 (int)SortType.Modified),
147 new RadioActionEntry ("Name", null,
148 Catalog.GetString ("_Name"), null,
149 Catalog.GetString ("Sort matches by name"),
150 (int)SortType.Name),
151 new RadioActionEntry ("Relevance", null,
152 Catalog.GetString ("_Relevance"), null,
153 Catalog.GetString ("Sort the best matches first"),
154 (int)SortType.Relevance),
156 actions.Add (sort_entries, (int)SortType.Modified, OnSortChanged);
158 InsertActionGroup (actions, 0);
159 main_window.AddAccelGroup (AccelGroup);
160 AddUiFromString (ui_def);
163 public Gtk.MenuBar MenuBar {
164 get {
165 return (Gtk.MenuBar)GetWidget ("/MenuBar");
169 private bool sensitive = true;
170 public bool Sensitive {
171 get { return this.sensitive; }
172 set {
173 this.sensitive = value;
175 actions ["QuickTips"].Sensitive = value;
177 foreach (Gtk.RadioActionEntry rae in scope_entries)
178 actions [rae.name].Sensitive = value;
180 foreach (Gtk.RadioActionEntry rae in sort_entries)
181 actions [rae.name].Sensitive = value;
185 private const string ui_def =
186 "<ui>" +
187 " <menubar name='MenuBar'>" +
188 " <menu action='Search'>" +
189 " <menuitem action='Everywhere'/>" +
190 " <menuitem action='Applications'/>" +
191 " <menuitem action='Contacts'/>" +
192 " <menuitem action='Calendar'/>" +
193 " <menuitem action='Documents'/>" +
194 " <menuitem action='Conversations'/>" +
195 " <menuitem action='Images'/>" +
196 " <menuitem action='Media'/>" +
197 " <separator/>" +
198 " <menuitem action='Preferences'/>" +
199 " <menuitem action='Quit'/>" +
200 " </menu>" +
201 " <menu action='Actions'>" +
202 " </menu>" +
203 " <menu action='SortBy'>" +
204 " <menuitem action='Modified'/>" +
205 " <menuitem action='Name'/>" +
206 " <menuitem action='Relevance'/>" +
207 " </menu>" +
208 " <menu action='Help'>" +
209 " <menuitem action='Contents'/>" +
210 " <menuitem action='QuickTips'/>" +
211 " <menuitem action='About'/>" +
212 " </menu>" +
213 " </menubar>" +
214 " <accelerator action='FocusSearchEntry'/>" +
215 " <accelerator action='FocusSearchEntry2'/>" +
216 " <accelerator action='HideWindow'/>" +
217 " <accelerator action='HideWindow2'/>" +
218 "</ui>";
220 private void Preferences (object obj, EventArgs args)
222 Process p = new Process ();
223 p.StartInfo.UseShellExecute = false;
224 p.StartInfo.FileName = "beagle-settings";
226 try {
227 p.Start ();
228 } catch (Exception e) {
229 Console.WriteLine ("Could not start beagle-settings: {0}", e);
233 public delegate void ShowQuickTipsDelegate ();
234 public event ShowQuickTipsDelegate ShowQuickTips;
236 private void QuickTips (object obj, EventArgs args)
238 if (ShowQuickTips != null)
239 ShowQuickTips ();
242 private void OnHideWindow (object obj, EventArgs args)
244 if (MainWindow.IconEnabled)
245 main_window.Hide ();
248 private void Quit (object obj, EventArgs args)
250 if (MainWindow.IconEnabled) {
251 main_window.Hide ();
252 } else {
253 Gtk.Application.Quit ();
257 private void Help (object obj, EventArgs args)
259 Gnome.Url.Show ("http://www.beagle-project.org/Getting_Started");
262 private void About (object obj, EventArgs args)
264 Gdk.Pixbuf logo = Beagle.Images.GetPixbuf ("system-search.png");
266 string[] people = new string[] { "Anna Dirks <anna@novell.com>",
267 "Fredrik Hedberg <fredrik@avafan.com>",
268 "Lukas Lipka <lukas@pmad.net>",
269 "Joe Shaw <joeshaw@novell.com>",
270 "Jakub Steiner <jimmac@novell.com>",
271 "Dan Winship <danw@novell.com>" };
273 #pragma warning disable 612 // don't warn that Gnome.About is deprecated
274 Gnome.About about = new Gnome.About ("Beagle Search",
275 Beagle.Util.ExternalStringsHack.Version,
276 "Copyright 2005-2006 Novell, Inc.",
277 null, people, null, null,
278 logo);
279 about.Run ();
280 about.Dispose ();
281 #pragma warning restore 612
284 private void OnFocusSearchEntry (object obj, EventArgs args)
286 if (FocusSearchEntry != null)
287 FocusSearchEntry ();
290 public delegate void FocusSearchEntryDelegate ();
291 public event FocusSearchEntryDelegate FocusSearchEntry;
293 private void OnScopeChanged (object obj, Gtk.ChangedArgs args)
295 if (ScopeChanged != null)
296 ScopeChanged ((ScopeType)args.Current.CurrentValue);
299 public delegate void ScopeChangedDelegate (ScopeType scope);
300 public event ScopeChangedDelegate ScopeChanged;
302 private void OnSortChanged (object obj, Gtk.ChangedArgs args)
304 if (SortChanged != null)
305 SortChanged ((SortType)args.Current.CurrentValue);
308 public delegate void SortChangedDelegate (SortType scope);
309 public event SortChangedDelegate SortChanged;