2006-02-27 Gabor Kelemen <kelemeng@gnome.hu>
[beagle.git] / search / UIManager.cs
blobd2b19743af78209fb645e9c0a51b14204e3c29c5
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 Contacts,
12 Documents,
13 Conversations,
14 Images,
15 Media
18 public enum SortType {
19 Relevance,
20 Name,
21 Modified
24 public class UIManager : Gtk.UIManager {
26 public UIManager (Gtk.Window mainWindow)
28 Gtk.ActionGroup actions = new ActionGroup ("Actions");
30 Gtk.ActionEntry[] entries = new ActionEntry[] {
31 new ActionEntry ("Search", null,
32 Catalog.GetString ("_Search"),
33 null, null, null),
34 new ActionEntry ("Actions", null,
35 Catalog.GetString ("_Actions"),
36 null, null, null),
37 new ActionEntry ("SortBy", null,
38 Catalog.GetString ("Sor_t"),
39 null, null, null),
40 new ActionEntry ("Help", null,
41 Catalog.GetString ("_Help"),
42 null, null, null),
44 new ActionEntry ("Quit", Gtk.Stock.Quit,
45 null, "<control>Q",
46 Catalog.GetString ("Exit Desktop Search"),
47 Quit),
48 new ActionEntry ("Preferences", Gtk.Stock.Preferences,
49 null, null,
50 Catalog.GetString ("Exit Desktop Search"),
51 Preferences),
52 new ActionEntry ("Contents", Gtk.Stock.Help,
53 Catalog.GetString ("_Contents"),
54 "F1",
55 Catalog.GetString ("Help - Table of Contents"),
56 Help),
57 new ActionEntry ("About", Gnome.Stock.About,
58 null, null,
59 Catalog.GetString ("About Desktop Search"),
60 About),
61 new ActionEntry ("QuickTips", null,
62 Catalog.GetString ("Quick Tips"),
63 null, null, QuickTips),
64 new ActionEntry ("FocusSearchEntry", null, "",
65 "<control>K", null,
66 OnFocusSearchEntry)
68 actions.Add (entries);
70 Gtk.RadioActionEntry[] scope_entries = new RadioActionEntry[] {
71 new RadioActionEntry ("Everywhere", null,
72 Catalog.GetString ("_Everywhere"),
73 "<control>E",
74 Catalog.GetString ("Search everywhere"),
75 (int)ScopeType.Everywhere),
76 new RadioActionEntry ("Applications", null,
77 Catalog.GetString ("_Applications"),
78 null,
79 Catalog.GetString ("Search applications"),
80 (int)ScopeType.Applications),
81 new RadioActionEntry ("Contacts", null,
82 Catalog.GetString ("_Contacts"),
83 null,
84 Catalog.GetString ("Search contacts"),
85 (int)ScopeType.Contacts),
86 new RadioActionEntry ("Documents", null,
87 Catalog.GetString ("_Documents"),
88 null,
89 Catalog.GetString ("Search documents"),
90 (int)ScopeType.Documents),
91 new RadioActionEntry ("Conversations", null,
92 Catalog.GetString ("Conve_rsations"),
93 null,
94 Catalog.GetString ("Search E-Mail and Instant Messaging logs"),
95 (int)ScopeType.Conversations),
96 new RadioActionEntry ("Images", null,
97 Catalog.GetString ("Images"),
98 null,
99 Catalog.GetString ("Search images"),
100 (int)ScopeType.Images),
101 new RadioActionEntry ("Media", null,
102 Catalog.GetString ("Media"),
103 null,
104 Catalog.GetString ("Search sound and video files"),
105 (int)ScopeType.Media),
107 actions.Add (scope_entries, (int)ScopeType.Everywhere, OnScopeChanged);
109 Gtk.RadioActionEntry[] sort_entries = new RadioActionEntry[] {
110 new RadioActionEntry ("Modified", null,
111 Catalog.GetString ("Date _Modified"), null,
112 Catalog.GetString ("Sort the most-recently-modified matches first"),
113 (int)SortType.Modified),
114 new RadioActionEntry ("Name", null,
115 Catalog.GetString ("_Name"), null,
116 Catalog.GetString ("Sort matches by name"),
117 (int)SortType.Name),
118 new RadioActionEntry ("Relevance", null,
119 Catalog.GetString ("_Relevance"), null,
120 Catalog.GetString ("Sort the best matches first"),
121 (int)SortType.Relevance),
123 actions.Add (sort_entries, (int)SortType.Modified, OnSortChanged);
125 InsertActionGroup (actions, 0);
126 mainWindow.AddAccelGroup (AccelGroup);
127 AddUiFromString (ui_def);
130 public Gtk.MenuBar MenuBar {
131 get {
132 return (Gtk.MenuBar)GetWidget ("/MenuBar");
136 private const string ui_def =
137 "<ui>" +
138 " <menubar name='MenuBar'>" +
139 " <menu action='Search'>" +
140 " <menuitem action='Everywhere'/>" +
141 " <menuitem action='Applications'/>" +
142 " <menuitem action='Contacts'/>" +
143 " <menuitem action='Documents'/>" +
144 " <menuitem action='Conversations'/>" +
145 " <menuitem action='Images'/>" +
146 " <menuitem action='Media'/>" +
147 " <separator/>" +
148 " <menuitem action='Preferences'/>" +
149 " <menuitem action='Quit'/>" +
150 " </menu>" +
151 " <menu action='Actions'>" +
152 " </menu>" +
153 " <menu action='SortBy'>" +
154 " <menuitem action='Modified'/>" +
155 " <menuitem action='Name'/>" +
156 " <menuitem action='Relevance'/>" +
157 " </menu>" +
158 " <menu action='Help'>" +
159 " <menuitem action='Contents'/>" +
160 " <menuitem action='QuickTips'/>" +
161 " <menuitem action='About'/>" +
162 " </menu>" +
163 " </menubar>" +
164 " <accelerator action='FocusSearchEntry'/>" +
165 "</ui>";
167 private void Preferences (object obj, EventArgs args)
169 Process p = new Process ();
170 p.StartInfo.UseShellExecute = false;
171 p.StartInfo.FileName = "beagle-settings";
173 try {
174 p.Start ();
175 } catch (Exception e) {
176 Console.WriteLine ("Could not start beagle-settings: {0}", e);
180 public delegate void ShowQuickTipsDelegate ();
181 public event ShowQuickTipsDelegate ShowQuickTips;
183 private void QuickTips (object obj, EventArgs args)
185 if (ShowQuickTips != null)
186 ShowQuickTips ();
189 private void Quit (object obj, EventArgs args)
191 Gtk.Application.Quit ();
194 private void Help (object obj, EventArgs args)
196 Gnome.Url.Show ("http://www.beagle-project.org/Getting_Started");
199 private void About (object obj, EventArgs args)
201 Gdk.Pixbuf logo = Beagle.Images.GetPixbuf ("system-search.png");
203 string[] people = new string[] {"Dan Winship <danw@novell.com>", "Lukas Lipka <lukas@pmad.net>",
204 "Fredrik Hedberg <fredrik@avafan.com>", "Joe Shaw <joeshaw@novell.com>"};
205 string[] documentors = new string[] {""};
207 Gnome.About about = new Gnome.About ("Desktop Search", "0.0",
208 "Copyright 2005 Novell, Inc.",
209 null, people, documentors, null,
210 logo);
211 about.Run ();
212 about.Dispose ();
215 private void OnFocusSearchEntry (object obj, EventArgs args)
217 if (FocusSearchEntry != null)
218 FocusSearchEntry ();
221 public delegate void FocusSearchEntryDelegate ();
222 public event FocusSearchEntryDelegate FocusSearchEntry;
224 private void OnScopeChanged (object obj, Gtk.ChangedArgs args)
226 if (ScopeChanged != null)
227 ScopeChanged ((ScopeType)args.Current.CurrentValue);
230 public delegate void ScopeChangedDelegate (ScopeType scope);
231 public event ScopeChangedDelegate ScopeChanged;
233 private void OnSortChanged (object obj, Gtk.ChangedArgs args)
235 if (SortChanged != null)
236 SortChanged ((SortType)args.Current.CurrentValue);
239 public delegate void SortChangedDelegate (SortType scope);
240 public event SortChangedDelegate SortChanged;