* beagled/QueryDriver.cs,beagled/PropertyKeywordFu.cs,
[beagle.git] / tools / Settings.cs
blobed55efdcfe98244dc29dc5201758516a168f8058
1 //
2 // Settings.cs
3 //
4 // Copyright (C) 2005 Novell, Inc.
5 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
27 using System;
28 using System.IO;
29 using System.Collections;
30 using System.Threading;
32 using Gtk;
33 using Gdk;
34 using Glade;
35 using Mono.Unix;
37 using Beagle;
38 using Beagle.Util;
40 public class SettingsDialog
42 public static void Main (string[] args)
44 SettingsDialog settings = new SettingsDialog ();
45 settings.Run ();
48 ////////////////////////////////////////////////////////////////
49 // Widgets
51 [Widget] VBox administration_frame;
52 [Widget] CheckButton allow_root_toggle;
54 [Widget] CheckButton autostart_toggle;
56 [Widget] CheckButton press_ctrl_toggle;
57 [Widget] CheckButton press_alt_toggle;
58 [Widget] Entry show_search_window_entry;
59 [Widget] SpinButton max_displayed_spinbutton;
61 [Widget] CheckButton index_home_toggle;
62 [Widget] Button remove_include_button;
63 [Widget] Button remove_exclude_button;
65 [Widget] Button display_up_button;
66 [Widget] Button display_down_button;
68 [Widget] Gtk.Window settings_dialog;
70 [Widget] ScrolledWindow display_sw;
72 [Widget] ScrolledWindow include_sw;
73 [Widget] ScrolledWindow exclude_sw;
75 #if false
76 DisplayView display_view;
77 #endif
79 IncludeView include_view;
80 ExcludeView exclude_view;
82 ////////////////////////////////////////////////////////////////
83 // WebServices
85 [Widget] VBox networking_box;
86 [Widget] CheckButton allow_global_access_toggle;
87 [Widget] Button remove_publicfolder_button;
88 [Widget] Button remove_netbeagle_button;
90 [Widget] ScrolledWindow publicfolder_sw;
91 [Widget] ScrolledWindow netbeagle_sw;
93 [Widget] Dialog netbeagle_entry_dialog;
94 [Widget] Entry netbeagle_textentry;
96 PublicfolderView publicfolder_view;
97 NetbeagleView netbeagle_view;
99 ////////////////////////////////////////////////////////////////
100 // Initialize
102 public SettingsDialog ()
104 Application.Init ();
106 Catalog.Init ("beagle", ExternalStringsHack.LocaleDir);
108 Glade.XML glade = new Glade.XML (null, "settings.glade", "settings_dialog", "beagle");
109 glade.Autoconnect (this);
111 administration_frame.Visible = (Environment.UserName == "root");
113 #if false
114 display_view = new DisplayView ();
115 display_view.Selection.Changed += new EventHandler (OnDisplaySelected);
116 display_view.Show ();
117 // The display sorting stuff is something i have been testing locally, Best CVS wont use it
118 display_sw.Child = display_view;
119 #endif
120 include_view = new IncludeView ();
121 include_view.Selection.Changed += new EventHandler (OnIncludeSelected);
122 include_view.Show ();
123 include_sw.Child = include_view;
125 exclude_view = new ExcludeView ();
126 exclude_view.Selection.Changed += new EventHandler (OnExcludeSelected);
127 exclude_view.Show ();
128 exclude_sw.Child = exclude_view;
130 #if ENABLE_WEBSERVICES
131 networking_box.Visible = true;
133 publicfolder_view = new PublicfolderView ();
134 publicfolder_view.Selection.Changed += new EventHandler (OnPublicfolderSelected);
135 publicfolder_view.Show ();
136 publicfolder_sw.Child = publicfolder_view;
138 netbeagle_view = new NetbeagleView ();
139 netbeagle_view.Selection.Changed += new EventHandler (OnNetbeagleSelected);
140 netbeagle_view.Show ();
141 netbeagle_sw.Child = netbeagle_view;
142 #endif
143 LoadConfiguration ();
145 Conf.Subscribe (typeof (Conf.IndexingConfig), new Conf.ConfigUpdateHandler (OnConfigurationChanged));
146 Conf.Subscribe (typeof (Conf.SearchingConfig), new Conf.ConfigUpdateHandler (OnConfigurationChanged));
148 #if ENABLE_WEBSERVICES
149 Conf.Subscribe (typeof (Conf.NetworkingConfig), new Conf.ConfigUpdateHandler (OnConfigurationChanged));
150 Conf.Subscribe (typeof (Conf.WebServicesConfig), new Conf.ConfigUpdateHandler (OnConfigurationChanged));
151 #endif
154 public void Run ()
156 Application.Run ();
159 ////////////////////////////////////////////////////////////////
160 // Configuration
162 private void LoadConfiguration ()
164 allow_root_toggle.Active = Conf.Daemon.AllowRoot;
165 autostart_toggle.Active = Conf.Searching.Autostart;
167 KeyBinding show_binding = Conf.Searching.ShowSearchWindowBinding;
168 press_ctrl_toggle.Active = show_binding.Ctrl;
169 press_alt_toggle.Active = show_binding.Alt;
170 show_search_window_entry.Text = show_binding.Key;
171 max_displayed_spinbutton.Value = (uint) Conf.Searching.MaxDisplayed;
173 if (Conf.Indexing.IndexHomeDir)
174 index_home_toggle.Active = true;
176 foreach (string include in Conf.Indexing.Roots)
177 include_view.AddPath (include);
179 foreach (ExcludeItem exclude_item in Conf.Indexing.Excludes)
180 exclude_view.AddItem (exclude_item);
182 #if ENABLE_WEBSERVICES
183 foreach (string netbeagle in Conf.Networking.NetBeagleNodes)
184 netbeagle_view.AddNode (netbeagle);
186 if (Conf.WebServices.AllowGlobalAccess)
187 allow_global_access_toggle.Active = true;
189 foreach (string publicfolder in Conf.WebServices.PublicFolders)
190 publicfolder_view.AddPath (publicfolder);
191 #endif
194 private void SaveConfiguration ()
196 Conf.Daemon.AllowRoot = allow_root_toggle.Active;
197 Conf.Searching.Autostart = autostart_toggle.Active;
199 Conf.Searching.ShowSearchWindowBinding = new KeyBinding (show_search_window_entry.Text,
200 press_ctrl_toggle.Active,
201 press_alt_toggle.Active);
203 Conf.Searching.MaxDisplayed = (int) max_displayed_spinbutton.Value;
204 Conf.Indexing.IndexHomeDir = index_home_toggle.Active;
206 Conf.Indexing.Roots = include_view.Includes;
207 Conf.Indexing.Excludes = exclude_view.Excludes;
209 #if ENABLE_WEBSERVICES
210 Conf.Networking.NetBeagleNodes = netbeagle_view.Netbeagles;
211 Conf.WebServices.AllowGlobalAccess = allow_global_access_toggle.Active;
212 Conf.WebServices.PublicFolders = publicfolder_view.Publicfolders;
213 #endif
214 Conf.Save (true);
217 private void OnConfigurationChanged (Conf.Section section)
219 HigMessageDialog dialog = new HigMessageDialog (settings_dialog,
220 DialogFlags.Modal,
221 MessageType.Question,
222 ButtonsType.YesNo,
223 Catalog.GetString ("Reload configuration"),
224 Catalog.GetString ("The configuration file has been modified by another application. " +
225 "Do you wish to discard the currently displayed values and reload configuration from disk?"));
227 ResponseType response = (ResponseType) dialog.Run ();
229 if (response == ResponseType.Yes)
230 LoadConfiguration ();
232 dialog.Destroy ();
235 ////////////////////////////////////////////////////////////////
236 // Eventhandlers
238 private void OnDialogResponse (object o, ResponseArgs args)
240 switch (args.ResponseId) {
241 case ResponseType.Help:
242 Gnome.Url.Show ("http://www.beagle-project.org/Configuration_Help");
243 break;
244 case ResponseType.Ok:
245 SaveConfiguration ();
246 Application.Quit ();
247 break;
248 default:
249 Application.Quit ();
250 break;
254 private void OnDisplaySelected (object o, EventArgs args)
256 display_up_button.Sensitive = true;
257 display_down_button.Sensitive = true;
260 private void OnAddIncludeClicked (object o, EventArgs args)
262 CompatFileChooserDialog fs_dialog = new CompatFileChooserDialog (Catalog.GetString ("Select Path"),
263 settings_dialog,
264 CompatFileChooserDialog.Action.SelectFolder);
265 fs_dialog.SelectMultiple = false;
267 ResponseType fs_response = (ResponseType) fs_dialog.Run ();
268 string new_include = fs_dialog.Filename;
269 fs_dialog.Destroy ();
271 if (fs_response == ResponseType.Ok) {
272 string error_message = "";
273 bool throw_error = false;
274 ArrayList obsolete_includes = new ArrayList ();
276 // Check and see if the current data collides with the new path in any way
277 // FIXME: Do this with System.IO.Path or something
278 foreach (string old_include in include_view.Includes) {
279 if (new_include == old_include) {
280 throw_error = true;
281 error_message = Catalog.GetString ("The selected path is already selected for indexing and wasn't added.");
282 } else if (new_include.StartsWith (old_include)) {
283 throw_error = true;
284 error_message = Catalog.GetString ("The selected path wasn't added. The list contains items that supercedes it and the data is already being indexed.");
285 } else if (old_include.StartsWith (new_include)) {
286 obsolete_includes.Add (old_include);
290 if (throw_error) {
291 HigMessageDialog.RunHigMessageDialog (settings_dialog,
292 DialogFlags.Modal,
293 MessageType.Warning,
294 ButtonsType.Ok,
295 Catalog.GetString ("Path not added"),
296 error_message);
297 } else {
298 // Confirm the removal of obsolete includes
299 if (obsolete_includes.Count != 0) {
300 HigMessageDialog dialog = new HigMessageDialog (settings_dialog,
301 DialogFlags.Modal,
302 MessageType.Question,
303 ButtonsType.YesNo,
304 Catalog.GetString ("Remove obsolete paths"),
305 Catalog.GetString ("Adding this path will obsolete some of the existing include paths. " +
306 "This will result in the removal of the old obsolete paths. Do you still wish to add it?"));
308 ResponseType confirm_response = (ResponseType) dialog.Run ();
310 if (confirm_response != ResponseType.Yes)
311 return;
313 foreach (string obsolete_include in obsolete_includes)
314 include_view.RemovePath (obsolete_include);
316 dialog.Destroy ();
319 include_view.AddPath (new_include);
324 private void OnRemoveIncludeClicked (object o, EventArgs args)
326 // Confirm removal
327 HigMessageDialog dialog = new HigMessageDialog (settings_dialog,
328 DialogFlags.Modal,
329 MessageType.Question,
330 ButtonsType.YesNo,
331 Catalog.GetString ("Remove path"),
332 Catalog.GetString ("Are you sure you wish to remove this path from the list of directories to be included for indexing?"));
333 ResponseType response = (ResponseType) dialog.Run ();
334 dialog.Destroy ();
336 if (response != ResponseType.Yes)
337 return;
339 include_view.RemoveSelectedPath ();
340 remove_include_button.Sensitive = false;
343 private void OnIncludeSelected (object o, EventArgs args)
345 remove_include_button.Sensitive = true;
348 private void OnAddExcludeClicked (object o, EventArgs args)
350 AddExcludeDialog dialog = new AddExcludeDialog (settings_dialog);
351 dialog.ExcludeItemAddedEvent += new ExcludeItemAddedHandler (OnExcludeItemAdded);
355 private void OnRemoveExcludeClicked (object o, EventArgs args)
357 HigMessageDialog dialog = new HigMessageDialog (settings_dialog,
358 DialogFlags.Modal,
359 MessageType.Question,
360 ButtonsType.YesNo,
361 Catalog.GetString ("Remove item"),
362 Catalog.GetString ("Are you sure you wish to remove this item from the list of data to be excluded from indexing?"));
364 ResponseType response = (ResponseType) dialog.Run ();
365 dialog.Destroy ();
367 if (response != ResponseType.Yes)
368 return;
370 exclude_view.RemoveSelectedItem ();
371 remove_exclude_button.Sensitive = false;
374 private void OnExcludeSelected (object o, EventArgs args)
376 remove_exclude_button.Sensitive = true;
379 private void OnExcludeItemAdded (ExcludeItem exclude_item)
381 exclude_view.AddItem (exclude_item);
384 //Netbeagle: Add, Remove operations
385 private void OnAddNetbeagleClicked (object o, EventArgs args)
387 Glade.XML glade = new Glade.XML (null, "settings.glade", "netbeagle_entry_dialog", "beagle");
388 glade.Autoconnect (this);
389 ResponseType nbed_response = (ResponseType) netbeagle_entry_dialog.Run ();
391 string new_node = netbeagle_textentry.Text.Trim();
393 if ((new_node.Length > 1) && (((string[])new_node.Split(':')).Length < 2))
394 new_node += ":8888";
396 netbeagle_entry_dialog.Destroy ();
398 if (nbed_response == ResponseType.Ok) {
399 string error_message = "";
400 bool throw_error = false;
402 if (new_node.Length < 2)
404 throw_error = true;
405 error_message = Catalog.GetString ("Invalid host entry");
407 else
408 // Check if the new entry matches an existing netbeagle entry
409 foreach (string old_node in netbeagle_view.Netbeagles) {
410 if (new_node == old_node) {
411 throw_error = true;
412 error_message = Catalog.GetString ("Remote host already present in the list.");
416 if (throw_error) {
417 HigMessageDialog.RunHigMessageDialog (settings_dialog,
418 DialogFlags.Modal,
419 MessageType.Warning,
420 ButtonsType.Ok,
421 Catalog.GetString ("Netbeagle Node not added"),
422 error_message);
424 else
425 netbeagle_view.AddNode (new_node);
430 private void OnRemoveNetbeagleClicked (object o, EventArgs args)
432 // Confirm removal
433 HigMessageDialog dialog = new HigMessageDialog (settings_dialog,
434 DialogFlags.Modal,
435 MessageType.Question,
436 ButtonsType.YesNo,
437 Catalog.GetString ("Remove host"),
438 Catalog.GetString ("Are you sure you wish to remove this host from the list?"));
440 ResponseType response = (ResponseType) dialog.Run ();
441 dialog.Destroy ();
443 if (response != ResponseType.Yes)
444 return;
446 netbeagle_view.RemoveSelectedNode ();
448 remove_netbeagle_button.Sensitive = false;
451 private void OnNetbeagleSelected (object o, EventArgs args)
453 remove_netbeagle_button.Sensitive = true;
456 //Publicfolders: Add, Remove operations
457 private void OnAddPublicfolderClicked (object o, EventArgs args)
459 CompatFileChooserDialog fs_dialog = new CompatFileChooserDialog (Catalog.GetString ("Select path"),
460 settings_dialog,
461 CompatFileChooserDialog.Action.SelectFolder);
462 fs_dialog.SelectMultiple = false;
464 ResponseType fs_response = (ResponseType) fs_dialog.Run ();
465 string new_pf = fs_dialog.Filename;
466 fs_dialog.Destroy ();
468 if (fs_response == ResponseType.Ok) {
470 string error_message = "";
471 bool throw_error = false;
473 // Check and see if the current data collides with the new path in any way
474 // FIXME: Do this with System.IO.Path or something
475 foreach (string old_pf in publicfolder_view.Publicfolders) {
476 if (new_pf == old_pf) {
477 throw_error = true;
478 error_message = Catalog.GetString ("The selected path is already configured for external access.");
482 if (throw_error) {
483 HigMessageDialog.RunHigMessageDialog (settings_dialog,
484 DialogFlags.Modal,
485 MessageType.Warning,
486 ButtonsType.Ok,
487 Catalog.GetString ("Path not added"),
488 error_message);
490 else
491 publicfolder_view.AddPath (new_pf);
495 private void OnRemovePublicfolderClicked (object o, EventArgs args)
497 // Confirm removal
498 HigMessageDialog dialog = new HigMessageDialog (settings_dialog,
499 DialogFlags.Modal,
500 MessageType.Question,
501 ButtonsType.YesNo,
502 Catalog.GetString ("Remove public path"),
503 Catalog.GetString ("Are you sure you wish to remove this entry from the list of public paths?"));
505 ResponseType response = (ResponseType) dialog.Run ();
506 dialog.Destroy ();
508 if (response != ResponseType.Yes)
509 return;
511 publicfolder_view.RemoveSelectedPath ();
512 remove_publicfolder_button.Sensitive = false;
515 private void OnPublicfolderSelected (object o, EventArgs args)
517 remove_publicfolder_button.Sensitive = true;
520 ////////////////////////////////////////////////////////////////
521 // IncludeView
523 class IncludeView : TreeView
525 private ListStore store;
527 private ArrayList includes = new ArrayList ();
529 public ArrayList Includes {
530 get { return includes; }
533 private enum TargetType {
534 Uri,
537 private static TargetEntry [] target_table = new TargetEntry [] {
538 new TargetEntry ("STRING", 0, (uint) TargetType.Uri ),
539 new TargetEntry ("text/plain", 0, (uint) TargetType.Uri),
542 public IncludeView ()
544 store = new ListStore (typeof (string));
546 this.Model = store;
548 AppendColumn (Catalog.GetString ("Name"), new CellRendererText (), "text", 0);
550 // Enable drag and drop folders from nautilus
551 Gtk.Drag.DestSet (this, DestDefaults.All, target_table, DragAction.Copy | DragAction.Move);
552 DragDataReceived += new DragDataReceivedHandler (HandleData);
555 public void AddPath (string path)
557 includes.Add (path);
558 store.AppendValues (path);
561 public void RemovePath (string path)
563 find_path = path;
564 found_iter = TreeIter.Zero;
566 this.Model.Foreach (new TreeModelForeachFunc (ForeachFindPath));
568 store.Remove (ref found_iter);
569 includes.Remove (path);
572 private string find_path;
573 private TreeIter found_iter;
575 private bool ForeachFindPath (TreeModel model, TreePath path, TreeIter iter)
577 if ((string) model.GetValue (iter, 0) == find_path) {
578 found_iter = iter;
579 return true;
582 return false;
585 public void RemoveSelectedPath ()
587 TreeModel model;
588 TreeIter iter;
590 if (!this.Selection.GetSelected(out model, out iter)) {
591 return;
593 string path = (string)model.GetValue(iter, 0);
595 store.Remove (ref iter);
596 includes.Remove (path);
599 // Handle drag and drop data. Enables users to drag a folder that he wishes
600 // to add for indexing from Nautilus.
601 // FIXME: Pass checks as in OnAddIncludeButtonClicked
602 private void HandleData (object o, DragDataReceivedArgs args) {
603 Uri uri;
604 if (args.SelectionData.Length >=0 && args.SelectionData.Format == 8) {
605 uri = new Uri (args.SelectionData.Text.Trim ());
606 AddPath (uri.LocalPath);
607 Gtk.Drag.Finish (args.Context, true, false, args.Time);
609 Gtk.Drag.Finish (args.Context, false, false, args.Time);
613 ////////////////////////////////////////////////////////////////
614 // Exclude view
616 class ExcludeView : TreeView
618 ArrayList excludes = new ArrayList ();
620 public ArrayList Excludes {
621 get { return excludes; }
624 public ExcludeView ()
626 this.Model = new ListStore (typeof (ExcludeItem));
628 CellRendererText renderer_text = new CellRendererText ();
630 TreeViewColumn type_column = new TreeViewColumn ();
631 type_column.Title = Catalog.GetString ("Type");
632 type_column.PackStart (renderer_text, false);
633 type_column.SetCellDataFunc (renderer_text, new TreeCellDataFunc (TypeCellDataFunc));
634 AppendColumn (type_column);
636 TreeViewColumn name_column = new TreeViewColumn ();
637 name_column.Title = Catalog.GetString ("Name");
638 name_column.PackStart (renderer_text, false);
639 name_column.SetCellDataFunc (renderer_text, new TreeCellDataFunc (NameCellDataFunc));
640 AppendColumn (name_column);
643 public void RemoveSelectedItem ()
645 TreeModel model;
646 TreeIter iter;
648 if (!this.Selection.GetSelected(out model, out iter)) {
649 return;
651 ExcludeItem exclude_item = (ExcludeItem) model.GetValue(iter, 0);
653 ((ListStore)this.Model).Remove (ref iter);
654 excludes.Remove (exclude_item);
657 public void AddItem (ExcludeItem exclude_item)
659 excludes.Add (exclude_item);
660 ((ListStore)this.Model).AppendValues (exclude_item);
663 private void NameCellDataFunc (TreeViewColumn column,
664 CellRenderer renderer,
665 TreeModel model,
666 TreeIter iter)
668 ExcludeItem exclude_item = (ExcludeItem) model.GetValue (iter, 0);
669 if (exclude_item.Type == ExcludeType.MailFolder)
670 ((CellRendererText)renderer).Text = MailFolder.GetNameForPath (exclude_item.Value);
671 else
672 ((CellRendererText)renderer).Text = exclude_item.Value;
675 private void TypeCellDataFunc (TreeViewColumn column,
676 CellRenderer renderer,
677 TreeModel model,
678 TreeIter iter)
680 ExcludeItem exclude_item = (ExcludeItem) model.GetValue (iter, 0);
682 switch (exclude_item.Type) {
683 case ExcludeType.Path:
684 ((CellRendererText)renderer).Text = Catalog.GetString ("Path:");
685 break;
686 case ExcludeType.Pattern:
687 ((CellRendererText)renderer).Text = Catalog.GetString ("Pattern:");
688 break;
689 case ExcludeType.MailFolder:
690 ((CellRendererText)renderer).Text = Catalog.GetString ("Mail folder:");
691 break;
696 ////////////////////////////////////////////////////////////////
698 // NetbeagleView
699 class NetbeagleView : TreeView
701 private ListStore store;
703 private ArrayList netBeagleList = new ArrayList ();
705 public ArrayList Netbeagles {
706 get { return netBeagleList; }
709 public NetbeagleView ()
711 store = new ListStore (typeof (string));
713 this.Model = store;
715 AppendColumn (Catalog.GetString ("Name"), new CellRendererText (), "text", 0);
718 public void AddNode (string node)
720 netBeagleList.Add (node);
721 store.AppendValues (node);
724 public void RemoveNode (string node)
726 find_node = node;
727 found_iter = TreeIter.Zero;
729 this.Model.Foreach (new TreeModelForeachFunc (ForeachFindNode));
731 store.Remove (ref found_iter);
732 netBeagleList.Remove (node);
735 private string find_node;
736 private TreeIter found_iter;
738 private bool ForeachFindNode (TreeModel model, TreePath path, TreeIter iter)
740 if ((string) model.GetValue (iter, 0) == find_node) {
741 found_iter = iter;
742 return true;
745 return false;
748 public void RemoveSelectedNode ()
750 TreeModel model;
751 TreeIter iter;
753 if (!this.Selection.GetSelected(out model, out iter)) {
754 return;
756 string node = (string)model.GetValue(iter, 0);
758 store.Remove (ref iter);
759 netBeagleList.Remove (node);
763 ////////////////////////////////////////////////////////////////
764 // PublicfolderView
766 class PublicfolderView: TreeView
768 private ListStore store;
770 private ArrayList publicFolders = new ArrayList ();
772 public ArrayList Publicfolders {
773 get { return publicFolders; }
776 private enum TargetType {
777 Uri,
780 private static TargetEntry [] target_table = new TargetEntry [] {
781 new TargetEntry ("STRING", 0, (uint) TargetType.Uri ),
782 new TargetEntry ("text/plain", 0, (uint) TargetType.Uri),
785 public PublicfolderView ()
787 store = new ListStore (typeof (string));
789 this.Model = store;
791 AppendColumn (Catalog.GetString ("Name"), new CellRendererText (), "text", 0);
793 // Enable drag and drop folders from nautilus
794 Gtk.Drag.DestSet (this, DestDefaults.All, target_table, DragAction.Copy | DragAction.Move);
795 DragDataReceived += new DragDataReceivedHandler (HandleData);
798 public void AddPath (string path)
800 publicFolders.Add (path);
801 store.AppendValues (path);
804 public void RemovePath (string path)
806 find_path = path;
807 found_iter = TreeIter.Zero;
809 this.Model.Foreach (new TreeModelForeachFunc (ForeachFindPath));
811 store.Remove (ref found_iter);
812 publicFolders.Remove (path);
815 private string find_path;
816 private TreeIter found_iter;
818 private bool ForeachFindPath (TreeModel model, TreePath path, TreeIter iter)
820 if ((string) model.GetValue (iter, 0) == find_path) {
821 found_iter = iter;
822 return true;
825 return false;
828 public void RemoveSelectedPath ()
830 TreeModel model;
831 TreeIter iter;
833 if (!this.Selection.GetSelected(out model, out iter)) {
834 return;
836 string path = (string)model.GetValue(iter, 0);
838 store.Remove (ref iter);
839 publicFolders.Remove (path);
842 // Handle drag and drop data. Enables users to drag a folder that he wishes
843 // to add for indexing from Nautilus.
844 // FIXME: Pass checks as in OnAddIncludeButtonClicked
845 private void HandleData (object o, DragDataReceivedArgs args) {
846 Uri uri;
847 if (args.SelectionData.Length >=0 && args.SelectionData.Format == 8) {
848 uri = new Uri (args.SelectionData.Text.Trim ());
849 AddPath (uri.LocalPath);
850 Gtk.Drag.Finish (args.Context, true, false, args.Time);
852 Gtk.Drag.Finish (args.Context, false, false, args.Time);
856 ////////////////////////////////////////////////////////////////
857 // Mail folder dialog
859 class MailFolderDialog
861 Gtk.Window parent;
862 FolderView folder_view;
864 [Widget] Dialog mail_folder_dialog;
865 [Widget] ScrolledWindow folder_sw;
867 public event ExcludeItemAddedHandler ExcludeItemAddedEvent;
869 public MailFolderDialog (Gtk.Window parent)
871 this.parent = parent;
873 Glade.XML glade = new Glade.XML (null, "settings.glade", "mail_folder_dialog", "beagle");
874 glade.Autoconnect (this);
876 folder_view = new FolderView ();
877 folder_view.Show ();
878 folder_sw.Child = folder_view;
881 private void OnDialogResponse (object o, ResponseArgs args)
883 if (args.ResponseId == ResponseType.Cancel) {
884 mail_folder_dialog.Destroy ();
885 return;
888 ExcludeItem exclude_item;
889 object obj = folder_view.GetCurrentItem ();
891 if (obj is MailAccount) {
893 } else if (obj is MailFolder) {
894 MailFolder folder = (MailFolder) obj;
895 exclude_item = new ExcludeItem (ExcludeType.MailFolder, folder.Path);
897 if (ExcludeItemAddedEvent != null)
898 ExcludeItemAddedEvent (exclude_item);
900 mail_folder_dialog.Destroy ();
904 class FolderView : TreeView
906 TreeStore store;
907 Gdk.Pixbuf folder_icon;
909 public FolderView ()
911 store = new TreeStore (typeof (MailFolder));
912 this.Model = store;
914 folder_icon = this.RenderIcon (Stock.Open, IconSize.Menu, "");
916 HeadersVisible = false;
918 TreeViewColumn column = new TreeViewColumn ();
919 CellRendererPixbuf renderer_icon = new CellRendererPixbuf ();
920 column.PackStart (renderer_icon, false);
921 column.SetCellDataFunc (renderer_icon, new TreeCellDataFunc (IconCellDataFunc));
923 CellRendererText renderer_text = new CellRendererText ();
924 column.PackStart (renderer_text, false);
925 column.SetCellDataFunc (renderer_text, new TreeCellDataFunc (NameCellDataFunc));
926 AppendColumn (column);
928 foreach (MailAccount account in Beagle.Util.Evolution.Accounts) {
929 TreeIter iter = store.AppendValues (account);
931 foreach (MailFolder folder in account.Children) {
932 Add (iter, folder);
937 private void Add (TreeIter parent, MailFolder folder)
939 TreeIter current = store.AppendValues (parent, folder);
941 foreach (MailFolder child in folder.Children)
942 Add (current, child);
945 private void IconCellDataFunc (TreeViewColumn column,
946 CellRenderer renderer,
947 TreeModel model,
948 TreeIter iter)
950 object obj = model.GetValue (iter, 0);
951 ((CellRendererPixbuf)renderer).Pixbuf = (obj is MailAccount) ? null : folder_icon;
954 private void NameCellDataFunc (TreeViewColumn column,
955 CellRenderer renderer,
956 TreeModel model,
957 TreeIter iter)
959 object obj = model.GetValue (iter, 0);
961 if (obj is MailAccount) {
962 MailAccount account = obj as MailAccount;
963 ((CellRendererText)renderer).Markup = String.Format ("<b>{0}</b>",account.Name);
964 } else {
965 MailFolder folder = obj as MailFolder;
966 ((CellRendererText)renderer).Text = folder.Name;
970 public MailFolder GetCurrentItem ()
972 TreeModel model;
973 TreeIter iter;
975 if (!this.Selection.GetSelected (out model, out iter)) {
976 return null;
979 return (MailFolder) model.GetValue (iter, 0);
984 ////////////////////////////////////////////////////////////////
985 // Exclude dialog
987 private delegate void ExcludeItemAddedHandler (ExcludeItem item);
989 class AddExcludeDialog
991 Gtk.Window parent;
993 [Widget] Dialog add_exclude_dialog;
994 [Widget] Entry value_entry;
995 [Widget] Label value_name_label;
996 [Widget] Button browse_button;
998 [Widget] RadioButton type_path_radio;
999 [Widget] RadioButton type_pattern_radio;
1000 [Widget] RadioButton type_mailfolder_radio;
1002 public event ExcludeItemAddedHandler ExcludeItemAddedEvent;
1004 private string value;
1006 public string Value {
1007 get {
1008 if (Type == ExcludeType.MailFolder)
1009 return value;
1010 else
1011 return value_entry.Text;
1015 public ExcludeType Type {
1016 get {
1017 if (type_path_radio.Active)
1018 return ExcludeType.Path;
1019 else if (type_pattern_radio.Active)
1020 return ExcludeType.Pattern;
1021 else
1022 return ExcludeType.MailFolder;
1026 public AddExcludeDialog (Gtk.Window parent)
1028 this.parent = parent;
1030 Glade.XML glade = new Glade.XML (null, "settings.glade", "add_exclude_dialog", "beagle");
1031 glade.Autoconnect (this);
1034 private void OnBrowseButtonClicked (object o, EventArgs args)
1036 switch (Type) {
1037 case ExcludeType.Path:
1038 CompatFileChooserDialog fs_dialog = new CompatFileChooserDialog (Catalog.GetString ("Select Folder"),
1039 add_exclude_dialog,
1040 CompatFileChooserDialog.Action.SelectFolder);
1041 fs_dialog.SelectMultiple = false;
1043 ResponseType response = (ResponseType) fs_dialog.Run ();
1045 if (response == ResponseType.Ok)
1046 value_entry.Text = fs_dialog.Filename;
1048 fs_dialog.Destroy ();
1049 break;
1050 case ExcludeType.MailFolder:
1051 MailFolderDialog mf_dialog = new MailFolderDialog (add_exclude_dialog);
1052 mf_dialog.ExcludeItemAddedEvent += new ExcludeItemAddedHandler (OnExcludeItemAdded);
1053 break;
1057 private void OnRadioGroupChanged (object o, EventArgs args)
1059 value_entry.Text = "";
1061 switch (Type) {
1062 case ExcludeType.Path:
1063 browse_button.Sensitive = true;
1064 value_name_label.TextWithMnemonic = Catalog.GetString ("P_ath:");
1065 value_entry.IsEditable = true;
1066 break;
1067 case ExcludeType.MailFolder:
1068 browse_button.Sensitive = true;
1069 value_name_label.TextWithMnemonic = Catalog.GetString ("M_ail folder:");
1070 value_entry.IsEditable = false;
1071 break;
1072 case ExcludeType.Pattern:
1073 browse_button.Sensitive = false;
1074 value_name_label.TextWithMnemonic = Catalog.GetString ("P_attern:");
1075 value_entry.IsEditable = true;
1076 break;
1080 private void OnExcludeItemAdded (ExcludeItem item)
1082 value = item.Value;
1083 value_entry.Text = MailFolder.GetNameForPath (item.Value);
1086 private void OnDialogResponse (object o, ResponseArgs args)
1088 if (((ResponseType)args.ResponseId) == ResponseType.Ok) {
1089 ExcludeItem exclude_item = new ExcludeItem (Type, Value);
1091 switch (Type) {
1092 case ExcludeType.Path:
1093 if (!Directory.Exists (Value)) {
1094 HigMessageDialog.RunHigMessageDialog(add_exclude_dialog,
1095 DialogFlags.Modal,
1096 MessageType.Error,
1097 ButtonsType.Ok,
1098 Catalog.GetString ("Error adding path"),
1099 Catalog.GetString ("The specified path could not be found and therefore it could not be added to the list of resources excluded for indexing."));
1100 return;
1102 break;
1105 if (ExcludeItemAddedEvent != null)
1106 ExcludeItemAddedEvent (exclude_item);
1108 add_exclude_dialog.Destroy ();
1111 public void Destroy ()
1113 add_exclude_dialog.Destroy ();
1117 #if false
1118 ////////////////////////////////////////////////////////////////
1119 // Display view
1121 class DisplayView : TreeView
1123 public DisplayView ()
1125 ListStore store = new ListStore (typeof(bool),typeof(string));
1127 this.Model = store;
1129 AppendColumn (Catalog.GetString ("Show"), new CellRendererToggle (), "active", 0);
1130 AppendColumn (Catalog.GetString ("Name"), new CellRendererText (), "text", 1);
1133 #endif