4 using System
.Diagnostics
;
10 public enum ScopeType
{
21 public enum SortType
{
27 public class UIManager
: Gtk
.UIManager
{
29 private MainWindow main_window
;
31 private Gtk
.ActionGroup actions
;
32 private Gtk
.RadioActionEntry
[] scope_entries
, sort_entries
;
34 public UIManager (MainWindow main_window
)
36 this.main_window
= main_window
;
38 actions
= new ActionGroup ("Actions");
40 ActionEntry quit_action_entry
;
41 if (MainWindow
.IconEnabled
) {
42 quit_action_entry
= new ActionEntry ("Quit", Gtk
.Stock
.Close
,
44 Catalog
.GetString ("Close Desktop Search"),
47 quit_action_entry
= new ActionEntry ("Quit", Gtk
.Stock
.Quit
,
49 Catalog
.GetString ("Exit Desktop Search"),
54 Gtk
.ActionEntry
[] entries
= new ActionEntry
[] {
55 new ActionEntry ("Search", null,
56 Catalog
.GetString ("_Search"),
58 new ActionEntry ("Actions", null,
59 Catalog
.GetString ("_Actions"),
61 new ActionEntry ("SortBy", null,
62 Catalog
.GetString ("Sor_t"),
64 new ActionEntry ("Help", null,
65 Catalog
.GetString ("_Help"),
69 new ActionEntry ("Preferences", Gtk
.Stock
.Preferences
,
71 Catalog
.GetString ("Exit Desktop Search"),
73 new ActionEntry ("Contents", Gtk
.Stock
.Help
,
74 Catalog
.GetString ("_Contents"),
76 Catalog
.GetString ("Help - Table of Contents"),
78 new ActionEntry ("About", Gnome
.Stock
.About
,
80 Catalog
.GetString ("About Desktop Search"),
82 new ActionEntry ("QuickTips", null,
83 Catalog
.GetString ("Quick Tips"),
84 null, null, QuickTips
),
85 new ActionEntry ("FocusSearchEntry", null, "",
88 new ActionEntry ("FocusSearchEntry2", null, "",
91 new ActionEntry ("HideWindow", null, "",
94 new ActionEntry ("HideWindow2", null, "",
98 actions
.Add (entries
);
100 scope_entries
= new RadioActionEntry
[] {
101 new RadioActionEntry ("Everywhere", null,
102 Catalog
.GetString ("_Everywhere"),
104 Catalog
.GetString ("Search everywhere"),
105 (int)ScopeType
.Everywhere
),
106 new RadioActionEntry ("Applications", null,
107 Catalog
.GetString ("_Applications"),
109 Catalog
.GetString ("Search applications"),
110 (int)ScopeType
.Applications
),
111 new RadioActionEntry ("Contacts", null,
112 Catalog
.GetString ("_Contacts"),
114 Catalog
.GetString ("Search contacts"),
115 (int)ScopeType
.Contacts
),
116 new RadioActionEntry ("Calendar", null,
117 Catalog
.GetString ("Ca_lendar events"),
119 Catalog
.GetString ("Search calendar events"),
120 (int)ScopeType
.Contacts
),
121 new RadioActionEntry ("Documents", null,
122 Catalog
.GetString ("_Documents"),
124 Catalog
.GetString ("Search documents"),
125 (int)ScopeType
.Documents
),
126 new RadioActionEntry ("Conversations", null,
127 Catalog
.GetString ("Conve_rsations"),
129 Catalog
.GetString ("Search E-Mail and Instant Messaging logs"),
130 (int)ScopeType
.Conversations
),
131 new RadioActionEntry ("Images", null,
132 Catalog
.GetString ("_Images"),
134 Catalog
.GetString ("Search images"),
135 (int)ScopeType
.Images
),
136 new RadioActionEntry ("Media", null,
137 Catalog
.GetString ("_Media"),
139 Catalog
.GetString ("Search sound and video files"),
140 (int)ScopeType
.Media
),
142 actions
.Add (scope_entries
, (int)ScopeType
.Everywhere
, OnScopeChanged
);
144 sort_entries
= new RadioActionEntry
[] {
145 new RadioActionEntry ("Modified", null,
146 Catalog
.GetString ("Date _Modified"), null,
147 Catalog
.GetString ("Sort the most-recently-modified matches first"),
148 (int)SortType
.Modified
),
149 new RadioActionEntry ("Name", null,
150 Catalog
.GetString ("_Name"), null,
151 Catalog
.GetString ("Sort matches by name"),
153 new RadioActionEntry ("Relevance", null,
154 Catalog
.GetString ("_Relevance"), null,
155 Catalog
.GetString ("Sort the best matches first"),
156 (int)SortType
.Relevance
),
158 actions
.Add (sort_entries
, (int)SortType
.Modified
, OnSortChanged
);
160 InsertActionGroup (actions
, 0);
161 main_window
.AddAccelGroup (AccelGroup
);
162 AddUiFromString (ui_def
);
165 public Gtk
.MenuBar MenuBar
{
167 return (Gtk
.MenuBar
)GetWidget ("/MenuBar");
171 private bool sensitive
= true;
172 public bool Sensitive
{
173 get { return this.sensitive; }
175 this.sensitive
= value;
177 actions
["QuickTips"].Sensitive
= value;
179 foreach (Gtk
.RadioActionEntry rae
in scope_entries
)
180 actions
[rae
.name
].Sensitive
= value;
182 foreach (Gtk
.RadioActionEntry rae
in sort_entries
)
183 actions
[rae
.name
].Sensitive
= value;
187 private const string ui_def
=
189 " <menubar name='MenuBar'>" +
190 " <menu action='Search'>" +
191 " <menuitem action='Everywhere'/>" +
192 " <menuitem action='Applications'/>" +
193 " <menuitem action='Contacts'/>" +
194 " <menuitem action='Calendar'/>" +
195 " <menuitem action='Documents'/>" +
196 " <menuitem action='Conversations'/>" +
197 " <menuitem action='Images'/>" +
198 " <menuitem action='Media'/>" +
200 " <menuitem action='Preferences'/>" +
201 " <menuitem action='Quit'/>" +
203 " <menu action='Actions'>" +
205 " <menu action='SortBy'>" +
206 " <menuitem action='Modified'/>" +
207 " <menuitem action='Name'/>" +
208 " <menuitem action='Relevance'/>" +
210 " <menu action='Help'>" +
211 " <menuitem action='Contents'/>" +
212 " <menuitem action='QuickTips'/>" +
213 " <menuitem action='About'/>" +
216 " <accelerator action='FocusSearchEntry'/>" +
217 " <accelerator action='FocusSearchEntry2'/>" +
218 " <accelerator action='HideWindow'/>" +
219 " <accelerator action='HideWindow2'/>" +
222 private void Preferences (object obj
, EventArgs args
)
224 Process p
= new Process ();
225 p
.StartInfo
.UseShellExecute
= false;
226 p
.StartInfo
.FileName
= "beagle-settings";
230 } catch (Exception e
) {
231 Console
.WriteLine ("Could not start beagle-settings: {0}", e
);
235 public delegate void ShowQuickTipsDelegate ();
236 public event ShowQuickTipsDelegate ShowQuickTips
;
238 private void QuickTips (object obj
, EventArgs args
)
240 if (ShowQuickTips
!= null)
244 private void OnHideWindow (object obj
, EventArgs args
)
246 if (MainWindow
.IconEnabled
)
250 private void Quit (object obj
, EventArgs args
)
252 if (MainWindow
.IconEnabled
) {
255 Gtk
.Application
.Quit ();
259 private void Help (object obj
, EventArgs args
)
261 string address
= "http://www.beagle-project.org/Getting_Started";
264 Gnome
.Url
.Show (address
);
266 HigMessageDialog md
= new HigMessageDialog (main_window
, Gtk
.DialogFlags
.DestroyWithParent
,
267 Gtk
.MessageType
.Error
, Gtk
.ButtonsType
.Close
,
268 Catalog
.GetString ("Couldn't launch web browser"),
269 Catalog
.GetString (String
.Format ("Please point your web browser to '{0}' manually", address
)));
275 private void About (object obj
, EventArgs args
)
277 Gdk
.Pixbuf logo
= Beagle
.Images
.GetPixbuf ("system-search.png");
279 string[] people
= new string[] { "Anna Dirks <anna@novell.com>",
280 "Fredrik Hedberg <fredrik@avafan.com>",
281 "Lukas Lipka <lukas@pmad.net>",
282 "Joe Shaw <joeshaw@novell.com>",
283 "Jakub Steiner <jimmac@novell.com>",
284 "Dan Winship <danw@novell.com>" };
286 #pragma warning disable 612 // don't warn that Gnome.About is deprecated
287 Gnome
.About about
= new Gnome
.About ("Beagle Search",
288 Beagle
.Util
.ExternalStringsHack
.Version
,
289 "Copyright 2005-2006 Novell, Inc.",
290 null, people
, null, null,
294 #pragma warning restore 612
297 private void OnFocusSearchEntry (object obj
, EventArgs args
)
299 if (FocusSearchEntry
!= null)
303 public delegate void FocusSearchEntryDelegate ();
304 public event FocusSearchEntryDelegate FocusSearchEntry
;
306 private void OnScopeChanged (object obj
, Gtk
.ChangedArgs args
)
308 if (ScopeChanged
!= null)
309 ScopeChanged ((ScopeType
)args
.Current
.CurrentValue
);
312 public delegate void ScopeChangedDelegate (ScopeType scope
);
313 public event ScopeChangedDelegate ScopeChanged
;
315 private void OnSortChanged (object obj
, Gtk
.ChangedArgs args
)
317 if (SortChanged
!= null)
318 SortChanged ((SortType
)args
.Current
.CurrentValue
);
321 public delegate void SortChangedDelegate (SortType scope
);
322 public event SortChangedDelegate SortChanged
;