Pretty print date in query output.
[beagle.git] / tools / Settings.cs
blobc343349a2e7a1bcc8c8ad0a609cfc37a09feb76b
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.Collections;
29 using System.IO;
30 using System.Reflection;
31 using System.Threading;
33 using Mono.Unix;
34 using Mono.Unix.Native;
36 using Gtk;
37 using Gdk;
38 using Glade;
40 using Beagle;
41 using Beagle.Util;
43 public class SettingsDialog
45 public static void Main (string[] args)
47 SettingsDialog settings = new SettingsDialog ();
48 settings.Run ();
51 ////////////////////////////////////////////////////////////////
52 // Widgets
54 [Widget] VBox administration_frame;
56 [Widget] CheckButton allow_root_toggle;
57 [Widget] CheckButton autostart_toggle;
58 [Widget] CheckButton battery_toggle;
59 [Widget] CheckButton auto_search_toggle;
60 [Widget] CheckButton press_ctrl_toggle;
61 [Widget] CheckButton press_alt_toggle;
63 [Widget] Entry show_search_window_entry;
65 [Widget] CheckButton index_home_toggle;
66 [Widget] Button remove_include_button;
67 [Widget] Button remove_exclude_button;
69 [Widget] Button display_up_button;
70 [Widget] Button display_down_button;
72 [Widget] Gtk.Window settings_dialog;
74 [Widget] ScrolledWindow include_sw;
75 [Widget] ScrolledWindow exclude_sw;
77 IncludeView include_view;
78 ExcludeView exclude_view;
80 ////////////////////////////////////////////////////////////////
81 // Initialize
83 public SettingsDialog ()
85 Application.Init ();
87 Catalog.Init ("beagle", ExternalStringsHack.LocaleDir);
89 Glade.XML glade = new Glade.XML (null, "settings.glade", "settings_dialog", "beagle");
90 glade.Autoconnect (this);
92 settings_dialog.Icon = Beagle.Images.GetPixbuf ("system-search.png");
93 administration_frame.Visible = (Environment.UserName == "root");
95 include_view = new IncludeView ();
96 include_view.Selection.Changed += new EventHandler (OnIncludeSelected);
97 include_view.Show ();
98 include_sw.Child = include_view;
100 exclude_view = new ExcludeView ();
101 exclude_view.Selection.Changed += new EventHandler (OnExcludeSelected);
102 exclude_view.Show ();
103 exclude_sw.Child = exclude_view;
105 LoadConfiguration ();
107 Conf.Subscribe (typeof (Conf.IndexingConfig), new Conf.ConfigUpdateHandler (OnConfigurationChanged));
108 Conf.Subscribe (typeof (Conf.SearchingConfig), new Conf.ConfigUpdateHandler (OnConfigurationChanged));
111 public void Run ()
113 Application.Run ();
116 ////////////////////////////////////////////////////////////////
117 // Configuration
119 private void LoadConfiguration ()
121 allow_root_toggle.Active = Conf.Daemon.AllowRoot;
122 auto_search_toggle.Active = Conf.Searching.BeagleSearchAutoSearch;
123 battery_toggle.Active = Conf.Indexing.IndexOnBattery;
125 autostart_toggle.Active = IsAutostartEnabled ();
127 KeyBinding show_binding = Conf.Searching.ShowSearchWindowBinding;
128 press_ctrl_toggle.Active = show_binding.Ctrl;
129 press_alt_toggle.Active = show_binding.Alt;
130 show_search_window_entry.Text = show_binding.Key;
132 if (Conf.Indexing.IndexHomeDir)
133 index_home_toggle.Active = true;
135 foreach (string include in Conf.Indexing.Roots)
136 include_view.AddPath (include);
138 foreach (ExcludeItem exclude_item in Conf.Indexing.Excludes)
139 exclude_view.AddItem (exclude_item);
142 private void SaveConfiguration ()
144 Conf.Daemon.AllowRoot = allow_root_toggle.Active;
145 Conf.Searching.BeagleSearchAutoSearch = auto_search_toggle.Active;
146 Conf.Indexing.IndexOnBattery = battery_toggle.Active;
148 Conf.Searching.ShowSearchWindowBinding = new KeyBinding (show_search_window_entry.Text,
149 press_ctrl_toggle.Active,
150 press_alt_toggle.Active);
152 Conf.Indexing.IndexHomeDir = index_home_toggle.Active;
154 Conf.Indexing.Roots = include_view.Includes;
155 Conf.Indexing.Excludes = exclude_view.Excludes;
157 Conf.Save (true);
160 private void OnConfigurationChanged (Conf.Section section)
162 HigMessageDialog dialog = new HigMessageDialog (settings_dialog,
163 DialogFlags.Modal,
164 MessageType.Question,
165 ButtonsType.YesNo,
166 Catalog.GetString ("Reload configuration"),
167 Catalog.GetString ("The configuration file has been modified by another application. " +
168 "Do you wish to discard the currently displayed values and reload configuration from disk?"));
170 ResponseType response = (ResponseType) dialog.Run ();
172 if (response == ResponseType.Yes)
173 LoadConfiguration ();
175 dialog.Destroy ();
178 ////////////////////////////////////////////////////////////////
179 // Autostart
181 private string system_autostart_dir = Path.Combine (Path.Combine (ExternalStringsHack.SysConfDir, "xdg"), "autostart");
182 private string local_autostart_dir = Path.Combine (Path.Combine (Environment.GetEnvironmentVariable ("HOME"), ".config"), "autostart");
184 private bool IsAutostartEnabled ()
186 // FIXME: We need to do better than this.
188 string local_beagled = Path.Combine (local_autostart_dir, "beagled-autostart.desktop");
189 string system_beagled = Path.Combine (system_autostart_dir, "beagled-autostart.desktop");
191 if (File.Exists (local_beagled)) {
192 StreamReader reader = new StreamReader (local_beagled);
194 try {
195 string l;
196 while ((l = reader.ReadLine ()) != null) {
197 if (String.Compare (l, "X-GNOME-Autostart-enabled=false", true) == 0)
198 return false;
201 return true;
202 } finally {
203 reader.Close ();
205 } else if (File.Exists (system_beagled)) {
206 StreamReader reader = new StreamReader (system_beagled);
208 try {
209 string l;
210 while ((l = reader.ReadLine ()) != null) {
211 if (String.Compare (l, "X-GNOME-Autostart-enabled=false", true) == 0)
212 return false;
215 return true;
216 } finally {
217 reader.Close ();
219 } else
220 return false;
223 private void SetAutostart (bool enabled)
225 if (! Directory.Exists (local_autostart_dir)) {
226 Directory.CreateDirectory (local_autostart_dir);
227 Syscall.chmod (local_autostart_dir, (FilePermissions) 448); // 448 == 0700
230 string beagled_file = Path.Combine (local_autostart_dir, "beagled-autostart.desktop");
231 string beagle_search_file = Path.Combine (local_autostart_dir, "beagle-search-autostart.desktop");
233 Assembly assembly = Assembly.GetExecutingAssembly ();
235 StreamReader reader = new StreamReader (assembly.GetManifestResourceStream ("beagled-autostart.desktop"));
236 StreamWriter writer = new StreamWriter (beagled_file);
238 string l;
239 while ((l = reader.ReadLine ()) != null)
240 writer.WriteLine (l);
241 reader.Close ();
243 if (! enabled) {
244 writer.WriteLine ("Hidden=true");
245 writer.WriteLine ("X-GNOME-Autostart-enabled=false");
248 writer.Close ();
250 reader = new StreamReader (assembly.GetManifestResourceStream ("beagle-search-autostart.desktop"));
251 writer = new StreamWriter (beagle_search_file);
253 while ((l = reader.ReadLine ()) != null)
254 writer.WriteLine (l);
255 reader.Close ();
257 if (! enabled) {
258 writer.WriteLine ("Hidden=true");
259 writer.WriteLine ("X-GNOME-Autostart-enabled=false");
262 writer.Close ();
265 ////////////////////////////////////////////////////////////////
266 // Eventhandlers
268 private void OnAutostartToggled (object o, EventArgs args)
270 SetAutostart (((Gtk.ToggleButton) o).Active);
273 private void OnDialogResponse (object o, ResponseArgs args)
275 switch (args.ResponseId) {
276 case ResponseType.Help:
277 Gnome.Url.Show ("http://beagle-project.org/Configuring");
278 break;
279 case ResponseType.Ok:
280 SaveConfiguration ();
281 Application.Quit ();
282 break;
283 default:
284 Application.Quit ();
285 break;
289 private void OnDisplaySelected (object o, EventArgs args)
291 display_up_button.Sensitive = true;
292 display_down_button.Sensitive = true;
295 private void OnAddIncludeClicked (object o, EventArgs args)
297 CompatFileChooserDialog fs_dialog = new CompatFileChooserDialog (Catalog.GetString ("Select Path"),
298 settings_dialog,
299 CompatFileChooserDialog.Action.SelectFolder);
300 fs_dialog.SelectMultiple = false;
302 ResponseType fs_response = (ResponseType) fs_dialog.Run ();
303 string new_include = fs_dialog.Filename;
304 fs_dialog.Destroy ();
306 if (fs_response == ResponseType.Ok) {
307 string error_message = "";
308 bool throw_error = false;
309 ArrayList obsolete_includes = new ArrayList ();
311 // Check and see if the current data collides with the new path in any way
312 // FIXME: Do this with System.IO.Path or something
313 foreach (string old_include in include_view.Includes) {
314 if (new_include == old_include) {
315 throw_error = true;
316 error_message = Catalog.GetString ("The selected path is already selected for indexing and wasn't added.");
317 } else if (new_include.StartsWith (old_include)) {
318 throw_error = true;
319 error_message = Catalog.GetString ("The selected path wasn't added. The list contains items that supersedes it and the data is already being indexed.");
320 } else if (old_include.StartsWith (new_include)) {
321 obsolete_includes.Add (old_include);
325 if (throw_error) {
326 HigMessageDialog.RunHigMessageDialog (settings_dialog,
327 DialogFlags.Modal,
328 MessageType.Warning,
329 ButtonsType.Ok,
330 Catalog.GetString ("Path not added"),
331 error_message);
332 } else {
333 // Confirm the removal of obsolete includes
334 if (obsolete_includes.Count != 0) {
335 HigMessageDialog dialog = new HigMessageDialog (settings_dialog,
336 DialogFlags.Modal,
337 MessageType.Question,
338 ButtonsType.YesNo,
339 Catalog.GetString ("Remove obsolete paths"),
340 Catalog.GetString ("Adding this path will obsolete some of the existing include paths. " +
341 "This will result in the removal of the old obsolete paths. Do you still wish to add it?"));
343 ResponseType confirm_response = (ResponseType) dialog.Run ();
345 if (confirm_response != ResponseType.Yes)
346 return;
348 foreach (string obsolete_include in obsolete_includes)
349 include_view.RemovePath (obsolete_include);
351 dialog.Destroy ();
354 include_view.AddPath (new_include);
359 private void OnRemoveIncludeClicked (object o, EventArgs args)
361 // Confirm removal
362 HigMessageDialog dialog = new HigMessageDialog (settings_dialog,
363 DialogFlags.Modal,
364 MessageType.Question,
365 ButtonsType.YesNo,
366 Catalog.GetString ("Remove path"),
367 Catalog.GetString ("Are you sure you wish to remove this path from the list of directories to be included for indexing?"));
368 ResponseType response = (ResponseType) dialog.Run ();
369 dialog.Destroy ();
371 if (response != ResponseType.Yes)
372 return;
374 include_view.RemoveSelectedPath ();
375 remove_include_button.Sensitive = false;
378 private void OnIncludeSelected (object o, EventArgs args)
380 remove_include_button.Sensitive = true;
383 private void OnAddExcludeClicked (object o, EventArgs args)
385 AddExcludeDialog dialog = new AddExcludeDialog (settings_dialog);
386 dialog.ExcludeItemAddedEvent += new ExcludeItemAddedHandler (OnExcludeItemAdded);
390 private void OnRemoveExcludeClicked (object o, EventArgs args)
392 HigMessageDialog dialog = new HigMessageDialog (settings_dialog,
393 DialogFlags.Modal,
394 MessageType.Question,
395 ButtonsType.YesNo,
396 Catalog.GetString ("Remove item"),
397 Catalog.GetString ("Are you sure you wish to remove this item from the list of data to be excluded from indexing?"));
399 ResponseType response = (ResponseType) dialog.Run ();
400 dialog.Destroy ();
402 if (response != ResponseType.Yes)
403 return;
405 exclude_view.RemoveSelectedItem ();
406 remove_exclude_button.Sensitive = false;
409 private void OnExcludeSelected (object o, EventArgs args)
411 remove_exclude_button.Sensitive = true;
414 private void OnExcludeItemAdded (ExcludeItem exclude_item)
416 exclude_view.AddItem (exclude_item);
419 ////////////////////////////////////////////////////////////////
420 // IncludeView
422 class IncludeView : TreeView
424 private ListStore store;
426 private ArrayList includes = new ArrayList ();
428 public ArrayList Includes {
429 get { return includes; }
432 private enum TargetType {
433 Uri,
436 private static TargetEntry [] target_table = new TargetEntry [] {
437 new TargetEntry ("STRING", 0, (uint) TargetType.Uri ),
438 new TargetEntry ("text/plain", 0, (uint) TargetType.Uri),
441 public IncludeView ()
443 store = new ListStore (typeof (string));
445 this.Model = store;
447 AppendColumn (Catalog.GetString ("Name"), new CellRendererText (), "text", 0);
449 // Enable drag and drop folders from nautilus
450 Gtk.Drag.DestSet (this, DestDefaults.All, target_table, DragAction.Copy | DragAction.Move);
451 DragDataReceived += new DragDataReceivedHandler (HandleData);
454 public void AddPath (string path)
456 includes.Add (path);
457 store.AppendValues (path);
460 public void RemovePath (string path)
462 find_path = path;
463 found_iter = TreeIter.Zero;
465 this.Model.Foreach (new TreeModelForeachFunc (ForeachFindPath));
467 store.Remove (ref found_iter);
468 includes.Remove (path);
471 private string find_path;
472 private TreeIter found_iter;
474 private bool ForeachFindPath (TreeModel model, TreePath path, TreeIter iter)
476 if ((string) model.GetValue (iter, 0) == find_path) {
477 found_iter = iter;
478 return true;
481 return false;
484 public void RemoveSelectedPath ()
486 TreeModel model;
487 TreeIter iter;
489 if (!this.Selection.GetSelected(out model, out iter)) {
490 return;
492 string path = (string)model.GetValue(iter, 0);
494 store.Remove (ref iter);
495 includes.Remove (path);
498 // Handle drag and drop data. Enables users to drag a folder that he wishes
499 // to add for indexing from Nautilus.
500 // FIXME: Pass checks as in OnAddIncludeButtonClicked
501 private void HandleData (object o, DragDataReceivedArgs args) {
502 Uri uri;
503 if (args.SelectionData.Length >=0 && args.SelectionData.Format == 8) {
504 uri = new Uri (args.SelectionData.Text.Trim ());
505 AddPath (uri.LocalPath);
506 Gtk.Drag.Finish (args.Context, true, false, args.Time);
508 Gtk.Drag.Finish (args.Context, false, false, args.Time);
512 ////////////////////////////////////////////////////////////////
513 // Exclude view
515 class ExcludeView : TreeView
517 ArrayList excludes = new ArrayList ();
519 public ArrayList Excludes {
520 get { return excludes; }
523 public ExcludeView ()
525 this.Model = new ListStore (typeof (ExcludeItem));
527 CellRendererText renderer_text = new CellRendererText ();
529 TreeViewColumn type_column = new TreeViewColumn ();
530 type_column.Title = Catalog.GetString ("Type");
531 type_column.PackStart (renderer_text, false);
532 type_column.SetCellDataFunc (renderer_text, new TreeCellDataFunc (TypeCellDataFunc));
533 AppendColumn (type_column);
535 TreeViewColumn name_column = new TreeViewColumn ();
536 name_column.Title = Catalog.GetString ("Name");
537 name_column.PackStart (renderer_text, false);
538 name_column.SetCellDataFunc (renderer_text, new TreeCellDataFunc (NameCellDataFunc));
539 AppendColumn (name_column);
542 public void RemoveSelectedItem ()
544 TreeModel model;
545 TreeIter iter;
547 if (!this.Selection.GetSelected(out model, out iter)) {
548 return;
550 ExcludeItem exclude_item = (ExcludeItem) model.GetValue(iter, 0);
552 ((ListStore)this.Model).Remove (ref iter);
553 excludes.Remove (exclude_item);
556 public void AddItem (ExcludeItem exclude_item)
558 excludes.Add (exclude_item);
559 ((ListStore)this.Model).AppendValues (exclude_item);
562 private void NameCellDataFunc (TreeViewColumn column,
563 CellRenderer renderer,
564 TreeModel model,
565 TreeIter iter)
567 ExcludeItem exclude_item = (ExcludeItem) model.GetValue (iter, 0);
568 if (exclude_item.Type == ExcludeType.MailFolder)
569 ((CellRendererText)renderer).Text = MailFolder.GetNameForPath (exclude_item.Value);
570 else
571 ((CellRendererText)renderer).Text = exclude_item.Value;
574 private void TypeCellDataFunc (TreeViewColumn column,
575 CellRenderer renderer,
576 TreeModel model,
577 TreeIter iter)
579 ExcludeItem exclude_item = (ExcludeItem) model.GetValue (iter, 0);
581 switch (exclude_item.Type) {
582 case ExcludeType.Path:
583 ((CellRendererText)renderer).Text = Catalog.GetString ("Path:");
584 break;
585 case ExcludeType.Pattern:
586 ((CellRendererText)renderer).Text = Catalog.GetString ("Pattern:");
587 break;
588 case ExcludeType.MailFolder:
589 ((CellRendererText)renderer).Text = Catalog.GetString ("Mail folder:");
590 break;
595 ////////////////////////////////////////////////////////////////
596 // PublicfolderView
598 class PublicfolderView : TreeView
600 private ListStore store;
602 private ArrayList publicFolders = new ArrayList ();
604 public ArrayList Publicfolders {
605 get { return publicFolders; }
608 private enum TargetType {
609 Uri,
612 private static TargetEntry [] target_table = new TargetEntry [] {
613 new TargetEntry ("STRING", 0, (uint) TargetType.Uri ),
614 new TargetEntry ("text/plain", 0, (uint) TargetType.Uri),
617 public PublicfolderView ()
619 store = new ListStore (typeof (string));
621 this.Model = store;
623 AppendColumn (Catalog.GetString ("Name"), new CellRendererText (), "text", 0);
625 // Enable drag and drop folders from nautilus
626 Gtk.Drag.DestSet (this, DestDefaults.All, target_table, DragAction.Copy | DragAction.Move);
627 DragDataReceived += new DragDataReceivedHandler (HandleData);
630 public void AddPath (string path)
632 publicFolders.Add (path);
633 store.AppendValues (path);
636 public void RemovePath (string path)
638 find_path = path;
639 found_iter = TreeIter.Zero;
641 this.Model.Foreach (new TreeModelForeachFunc (ForeachFindPath));
643 store.Remove (ref found_iter);
644 publicFolders.Remove (path);
647 private string find_path;
648 private TreeIter found_iter;
650 private bool ForeachFindPath (TreeModel model, TreePath path, TreeIter iter)
652 if ((string) model.GetValue (iter, 0) == find_path) {
653 found_iter = iter;
654 return true;
657 return false;
660 public void RemoveSelectedPath ()
662 TreeModel model;
663 TreeIter iter;
665 if (!this.Selection.GetSelected(out model, out iter)) {
666 return;
668 string path = (string)model.GetValue(iter, 0);
670 store.Remove (ref iter);
671 publicFolders.Remove (path);
674 // Handle drag and drop data. Enables users to drag a folder that he wishes
675 // to add for indexing from Nautilus.
676 // FIXME: Pass checks as in OnAddIncludeButtonClicked
677 private void HandleData (object o, DragDataReceivedArgs args) {
678 Uri uri;
679 if (args.SelectionData.Length >=0 && args.SelectionData.Format == 8) {
680 uri = new Uri (args.SelectionData.Text.Trim ());
681 AddPath (uri.LocalPath);
682 Gtk.Drag.Finish (args.Context, true, false, args.Time);
684 Gtk.Drag.Finish (args.Context, false, false, args.Time);
688 ////////////////////////////////////////////////////////////////
689 // Mail folder dialog
691 class MailFolderDialog
693 Gtk.Window parent;
694 FolderView folder_view;
696 [Widget] Dialog mail_folder_dialog;
697 [Widget] ScrolledWindow folder_sw;
699 public event ExcludeItemAddedHandler ExcludeItemAddedEvent;
701 public MailFolderDialog (Gtk.Window parent)
703 this.parent = parent;
705 Glade.XML glade = new Glade.XML (null, "settings.glade", "mail_folder_dialog", "beagle");
706 glade.Autoconnect (this);
708 folder_view = new FolderView ();
709 folder_view.Show ();
710 folder_sw.Child = folder_view;
713 private void OnDialogResponse (object o, ResponseArgs args)
715 if (args.ResponseId == ResponseType.Cancel) {
716 mail_folder_dialog.Destroy ();
717 return;
720 ExcludeItem exclude_item;
721 object obj = folder_view.GetCurrentItem ();
723 if (obj is MailAccount) {
725 } else if (obj is MailFolder) {
726 MailFolder folder = (MailFolder) obj;
727 exclude_item = new ExcludeItem (ExcludeType.MailFolder, folder.Path);
729 if (ExcludeItemAddedEvent != null)
730 ExcludeItemAddedEvent (exclude_item);
732 mail_folder_dialog.Destroy ();
736 class FolderView : TreeView
738 TreeStore store;
739 Gdk.Pixbuf folder_icon;
741 public FolderView ()
743 store = new TreeStore (typeof (MailFolder));
744 this.Model = store;
746 folder_icon = this.RenderIcon (Stock.Open, IconSize.Menu, "");
748 HeadersVisible = false;
750 TreeViewColumn column = new TreeViewColumn ();
751 CellRendererPixbuf renderer_icon = new CellRendererPixbuf ();
752 column.PackStart (renderer_icon, false);
753 column.SetCellDataFunc (renderer_icon, new TreeCellDataFunc (IconCellDataFunc));
755 CellRendererText renderer_text = new CellRendererText ();
756 column.PackStart (renderer_text, false);
757 column.SetCellDataFunc (renderer_text, new TreeCellDataFunc (NameCellDataFunc));
758 AppendColumn (column);
760 foreach (MailAccount account in Beagle.Util.Evolution.Accounts) {
761 TreeIter iter = store.AppendValues (account);
763 foreach (MailFolder folder in account.Children) {
764 Add (iter, folder);
769 private void Add (TreeIter parent, MailFolder folder)
771 TreeIter current = store.AppendValues (parent, folder);
773 foreach (MailFolder child in folder.Children)
774 Add (current, child);
777 private void IconCellDataFunc (TreeViewColumn column,
778 CellRenderer renderer,
779 TreeModel model,
780 TreeIter iter)
782 object obj = model.GetValue (iter, 0);
783 ((CellRendererPixbuf)renderer).Pixbuf = (obj is MailAccount) ? null : folder_icon;
786 private void NameCellDataFunc (TreeViewColumn column,
787 CellRenderer renderer,
788 TreeModel model,
789 TreeIter iter)
791 object obj = model.GetValue (iter, 0);
793 if (obj is MailAccount) {
794 MailAccount account = obj as MailAccount;
795 ((CellRendererText)renderer).Markup = String.Format ("<b>{0}</b>",account.Name);
796 } else {
797 MailFolder folder = obj as MailFolder;
798 ((CellRendererText)renderer).Text = folder.Name;
802 public MailFolder GetCurrentItem ()
804 TreeModel model;
805 TreeIter iter;
807 if (!this.Selection.GetSelected (out model, out iter)) {
808 return null;
811 return (MailFolder) model.GetValue (iter, 0);
816 ////////////////////////////////////////////////////////////////
817 // Exclude dialog
819 private delegate void ExcludeItemAddedHandler (ExcludeItem item);
821 class AddExcludeDialog
823 Gtk.Window parent;
825 [Widget] Dialog add_exclude_dialog;
826 [Widget] Entry value_entry;
827 [Widget] Label value_name_label;
828 [Widget] Button browse_button;
830 [Widget] RadioButton type_path_radio;
831 [Widget] RadioButton type_pattern_radio;
832 [Widget] RadioButton type_mailfolder_radio;
834 public event ExcludeItemAddedHandler ExcludeItemAddedEvent;
836 private string value;
838 public string Value {
839 get {
840 if (Type == ExcludeType.MailFolder)
841 return value;
842 else
843 return value_entry.Text;
847 public ExcludeType Type {
848 get {
849 if (type_path_radio.Active)
850 return ExcludeType.Path;
851 else if (type_pattern_radio.Active)
852 return ExcludeType.Pattern;
853 else
854 return ExcludeType.MailFolder;
858 public AddExcludeDialog (Gtk.Window parent)
860 this.parent = parent;
862 Glade.XML glade = new Glade.XML (null, "settings.glade", "add_exclude_dialog", "beagle");
863 glade.Autoconnect (this);
866 private void OnBrowseButtonClicked (object o, EventArgs args)
868 switch (Type) {
869 case ExcludeType.Path:
870 CompatFileChooserDialog fs_dialog = new CompatFileChooserDialog (Catalog.GetString ("Select Folder"),
871 add_exclude_dialog,
872 CompatFileChooserDialog.Action.SelectFolder);
873 fs_dialog.SelectMultiple = false;
875 ResponseType response = (ResponseType) fs_dialog.Run ();
877 if (response == ResponseType.Ok)
878 value_entry.Text = fs_dialog.Filename;
880 fs_dialog.Destroy ();
881 break;
882 case ExcludeType.MailFolder:
883 MailFolderDialog mf_dialog = new MailFolderDialog (add_exclude_dialog);
884 mf_dialog.ExcludeItemAddedEvent += new ExcludeItemAddedHandler (OnExcludeItemAdded);
885 break;
889 private void OnRadioGroupChanged (object o, EventArgs args)
891 value_entry.Text = "";
893 switch (Type) {
894 case ExcludeType.Path:
895 browse_button.Sensitive = true;
896 value_name_label.TextWithMnemonic = Catalog.GetString ("P_ath:");
897 value_entry.IsEditable = true;
898 break;
899 case ExcludeType.MailFolder:
900 browse_button.Sensitive = true;
901 value_name_label.TextWithMnemonic = Catalog.GetString ("M_ail folder:");
902 value_entry.IsEditable = false;
903 break;
904 case ExcludeType.Pattern:
905 browse_button.Sensitive = false;
906 value_name_label.TextWithMnemonic = Catalog.GetString ("P_attern:");
907 value_entry.IsEditable = true;
908 break;
912 private void OnExcludeItemAdded (ExcludeItem item)
914 value = item.Value;
915 value_entry.Text = MailFolder.GetNameForPath (item.Value);
918 private void OnDialogResponse (object o, ResponseArgs args)
920 if (((ResponseType)args.ResponseId) == ResponseType.Ok) {
921 ExcludeItem exclude_item = new ExcludeItem (Type, Value);
923 switch (Type) {
924 case ExcludeType.Path:
925 if (!Directory.Exists (Value)) {
926 HigMessageDialog.RunHigMessageDialog(add_exclude_dialog,
927 DialogFlags.Modal,
928 MessageType.Error,
929 ButtonsType.Ok,
930 Catalog.GetString ("Error adding path"),
931 Catalog.GetString ("The specified path could not be found and therefore it could not be added to the list of resources excluded for indexing."));
932 return;
934 break;
937 if (ExcludeItemAddedEvent != null)
938 ExcludeItemAddedEvent (exclude_item);
940 add_exclude_dialog.Destroy ();
943 public void Destroy ()
945 add_exclude_dialog.Destroy ();
949 #if false
950 ////////////////////////////////////////////////////////////////
951 // Display view
953 class DisplayView : TreeView
955 public DisplayView ()
957 ListStore store = new ListStore (typeof(bool),typeof(string));
959 this.Model = store;
961 AppendColumn (Catalog.GetString ("Show"), new CellRendererToggle (), "active", 0);
962 AppendColumn (Catalog.GetString ("Name"), new CellRendererText (), "text", 1);
965 #endif