4 // Copyright (C) 2005 Novell, Inc.
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
29 using System
.Collections
;
30 using System
.Threading
;
40 public class SettingsDialog
42 public static void Main (string[] args
)
44 SettingsDialog settings
= new SettingsDialog ();
48 ////////////////////////////////////////////////////////////////
51 [Widget
] VBox administration_frame
;
52 [Widget
] CheckButton allow_root_toggle
;
54 [Widget
] CheckButton autostart_toggle
;
55 [Widget
] CheckButton battery_toggle
;
57 [Widget
] CheckButton press_ctrl_toggle
;
58 [Widget
] CheckButton press_alt_toggle
;
59 [Widget
] Entry show_search_window_entry
;
60 [Widget
] SpinButton max_displayed_spinbutton
;
62 [Widget
] CheckButton index_home_toggle
;
63 [Widget
] Button remove_include_button
;
64 [Widget
] Button remove_exclude_button
;
66 [Widget
] Button display_up_button
;
67 [Widget
] Button display_down_button
;
69 [Widget
] Gtk
.Window settings_dialog
;
71 [Widget
] ScrolledWindow display_sw
;
73 [Widget
] ScrolledWindow include_sw
;
74 [Widget
] ScrolledWindow exclude_sw
;
77 DisplayView display_view
;
80 IncludeView include_view
;
81 ExcludeView exclude_view
;
83 ////////////////////////////////////////////////////////////////
86 [Widget
] VBox networking_box
;
87 [Widget
] CheckButton allow_global_access_toggle
;
88 [Widget
] Button remove_publicfolder_button
;
89 [Widget
] Button remove_netbeagle_button
;
91 [Widget
] ScrolledWindow publicfolder_sw
;
92 [Widget
] ScrolledWindow netbeagle_sw
;
94 [Widget
] Dialog netbeagle_entry_dialog
;
95 [Widget
] Entry netbeagle_textentry
;
97 PublicfolderView publicfolder_view
;
98 NetbeagleView netbeagle_view
;
100 ////////////////////////////////////////////////////////////////
103 public SettingsDialog ()
107 Catalog
.Init ("beagle", ExternalStringsHack
.LocaleDir
);
109 Glade
.XML glade
= new Glade
.XML (null, "settings.glade", "settings_dialog", "beagle");
110 glade
.Autoconnect (this);
112 administration_frame
.Visible
= (Environment
.UserName
== "root");
115 display_view
= new DisplayView ();
116 display_view
.Selection
.Changed
+= new EventHandler (OnDisplaySelected
);
117 display_view
.Show ();
118 // The display sorting stuff is something i have been testing locally, Best CVS wont use it
119 display_sw
.Child
= display_view
;
121 include_view
= new IncludeView ();
122 include_view
.Selection
.Changed
+= new EventHandler (OnIncludeSelected
);
123 include_view
.Show ();
124 include_sw
.Child
= include_view
;
126 exclude_view
= new ExcludeView ();
127 exclude_view
.Selection
.Changed
+= new EventHandler (OnExcludeSelected
);
128 exclude_view
.Show ();
129 exclude_sw
.Child
= exclude_view
;
131 #if ENABLE_WEBSERVICES
132 networking_box
.Visible
= true;
134 publicfolder_view
= new PublicfolderView ();
135 publicfolder_view
.Selection
.Changed
+= new EventHandler (OnPublicfolderSelected
);
136 publicfolder_view
.Show ();
137 publicfolder_sw
.Child
= publicfolder_view
;
139 netbeagle_view
= new NetbeagleView ();
140 netbeagle_view
.Selection
.Changed
+= new EventHandler (OnNetbeagleSelected
);
141 netbeagle_view
.Show ();
142 netbeagle_sw
.Child
= netbeagle_view
;
144 LoadConfiguration ();
146 Conf
.Subscribe (typeof (Conf
.IndexingConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
147 Conf
.Subscribe (typeof (Conf
.SearchingConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
149 #if ENABLE_WEBSERVICES
150 Conf
.Subscribe (typeof (Conf
.NetworkingConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
151 Conf
.Subscribe (typeof (Conf
.WebServicesConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
160 ////////////////////////////////////////////////////////////////
163 private void LoadConfiguration ()
165 allow_root_toggle
.Active
= Conf
.Daemon
.AllowRoot
;
166 autostart_toggle
.Active
= Conf
.Searching
.Autostart
;
167 battery_toggle
.Active
= Conf
.Indexing
.IndexOnBattery
;
169 KeyBinding show_binding
= Conf
.Searching
.ShowSearchWindowBinding
;
170 press_ctrl_toggle
.Active
= show_binding
.Ctrl
;
171 press_alt_toggle
.Active
= show_binding
.Alt
;
172 show_search_window_entry
.Text
= show_binding
.Key
;
173 max_displayed_spinbutton
.Value
= (uint) Conf
.Searching
.MaxDisplayed
;
175 if (Conf
.Indexing
.IndexHomeDir
)
176 index_home_toggle
.Active
= true;
178 foreach (string include
in Conf
.Indexing
.Roots
)
179 include_view
.AddPath (include
);
181 foreach (ExcludeItem exclude_item
in Conf
.Indexing
.Excludes
)
182 exclude_view
.AddItem (exclude_item
);
184 #if ENABLE_WEBSERVICES
185 foreach (string netbeagle
in Conf
.Networking
.NetBeagleNodes
)
186 netbeagle_view
.AddNode (netbeagle
);
188 if (Conf
.WebServices
.AllowGlobalAccess
)
189 allow_global_access_toggle
.Active
= true;
191 foreach (string publicfolder
in Conf
.WebServices
.PublicFolders
)
192 publicfolder_view
.AddPath (publicfolder
);
196 private void SaveConfiguration ()
198 Conf
.Daemon
.AllowRoot
= allow_root_toggle
.Active
;
199 Conf
.Searching
.Autostart
= autostart_toggle
.Active
;
200 Conf
.Indexing
.IndexOnBattery
= battery_toggle
.Active
;
202 Conf
.Searching
.ShowSearchWindowBinding
= new KeyBinding (show_search_window_entry
.Text
,
203 press_ctrl_toggle
.Active
,
204 press_alt_toggle
.Active
);
206 Conf
.Searching
.MaxDisplayed
= (int) max_displayed_spinbutton
.Value
;
207 Conf
.Indexing
.IndexHomeDir
= index_home_toggle
.Active
;
209 Conf
.Indexing
.Roots
= include_view
.Includes
;
210 Conf
.Indexing
.Excludes
= exclude_view
.Excludes
;
212 #if ENABLE_WEBSERVICES
213 Conf
.Networking
.NetBeagleNodes
= netbeagle_view
.Netbeagles
;
214 Conf
.WebServices
.AllowGlobalAccess
= allow_global_access_toggle
.Active
;
215 Conf
.WebServices
.PublicFolders
= publicfolder_view
.Publicfolders
;
220 private void OnConfigurationChanged (Conf
.Section section
)
222 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
224 MessageType
.Question
,
226 Catalog
.GetString ("Reload configuration"),
227 Catalog
.GetString ("The configuration file has been modified by another application. " +
228 "Do you wish to discard the currently displayed values and reload configuration from disk?"));
230 ResponseType response
= (ResponseType
) dialog
.Run ();
232 if (response
== ResponseType
.Yes
)
233 LoadConfiguration ();
238 ////////////////////////////////////////////////////////////////
241 private void OnDialogResponse (object o
, ResponseArgs args
)
243 switch (args
.ResponseId
) {
244 case ResponseType
.Help
:
245 Gnome
.Url
.Show ("http://beagle-project.org/Configuring");
247 case ResponseType
.Ok
:
248 SaveConfiguration ();
257 private void OnDisplaySelected (object o
, EventArgs args
)
259 display_up_button
.Sensitive
= true;
260 display_down_button
.Sensitive
= true;
263 private void OnAddIncludeClicked (object o
, EventArgs args
)
265 CompatFileChooserDialog fs_dialog
= new CompatFileChooserDialog (Catalog
.GetString ("Select Path"),
267 CompatFileChooserDialog
.Action
.SelectFolder
);
268 fs_dialog
.SelectMultiple
= false;
270 ResponseType fs_response
= (ResponseType
) fs_dialog
.Run ();
271 string new_include
= fs_dialog
.Filename
;
272 fs_dialog
.Destroy ();
274 if (fs_response
== ResponseType
.Ok
) {
275 string error_message
= "";
276 bool throw_error
= false;
277 ArrayList obsolete_includes
= new ArrayList ();
279 // Check and see if the current data collides with the new path in any way
280 // FIXME: Do this with System.IO.Path or something
281 foreach (string old_include
in include_view
.Includes
) {
282 if (new_include
== old_include
) {
284 error_message
= Catalog
.GetString ("The selected path is already selected for indexing and wasn't added.");
285 } else if (new_include
.StartsWith (old_include
)) {
287 error_message
= Catalog
.GetString ("The selected path wasn't added. The list contains items that supercedes it and the data is already being indexed.");
288 } else if (old_include
.StartsWith (new_include
)) {
289 obsolete_includes
.Add (old_include
);
294 HigMessageDialog
.RunHigMessageDialog (settings_dialog
,
298 Catalog
.GetString ("Path not added"),
301 // Confirm the removal of obsolete includes
302 if (obsolete_includes
.Count
!= 0) {
303 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
305 MessageType
.Question
,
307 Catalog
.GetString ("Remove obsolete paths"),
308 Catalog
.GetString ("Adding this path will obsolete some of the existing include paths. " +
309 "This will result in the removal of the old obsolete paths. Do you still wish to add it?"));
311 ResponseType confirm_response
= (ResponseType
) dialog
.Run ();
313 if (confirm_response
!= ResponseType
.Yes
)
316 foreach (string obsolete_include
in obsolete_includes
)
317 include_view
.RemovePath (obsolete_include
);
322 include_view
.AddPath (new_include
);
327 private void OnRemoveIncludeClicked (object o
, EventArgs args
)
330 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
332 MessageType
.Question
,
334 Catalog
.GetString ("Remove path"),
335 Catalog
.GetString ("Are you sure you wish to remove this path from the list of directories to be included for indexing?"));
336 ResponseType response
= (ResponseType
) dialog
.Run ();
339 if (response
!= ResponseType
.Yes
)
342 include_view
.RemoveSelectedPath ();
343 remove_include_button
.Sensitive
= false;
346 private void OnIncludeSelected (object o
, EventArgs args
)
348 remove_include_button
.Sensitive
= true;
351 private void OnAddExcludeClicked (object o
, EventArgs args
)
353 AddExcludeDialog dialog
= new AddExcludeDialog (settings_dialog
);
354 dialog
.ExcludeItemAddedEvent
+= new ExcludeItemAddedHandler (OnExcludeItemAdded
);
358 private void OnRemoveExcludeClicked (object o
, EventArgs args
)
360 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
362 MessageType
.Question
,
364 Catalog
.GetString ("Remove item"),
365 Catalog
.GetString ("Are you sure you wish to remove this item from the list of data to be excluded from indexing?"));
367 ResponseType response
= (ResponseType
) dialog
.Run ();
370 if (response
!= ResponseType
.Yes
)
373 exclude_view
.RemoveSelectedItem ();
374 remove_exclude_button
.Sensitive
= false;
377 private void OnExcludeSelected (object o
, EventArgs args
)
379 remove_exclude_button
.Sensitive
= true;
382 private void OnExcludeItemAdded (ExcludeItem exclude_item
)
384 exclude_view
.AddItem (exclude_item
);
387 //Netbeagle: Add, Remove operations
388 private void OnAddNetbeagleClicked (object o
, EventArgs args
)
390 Glade
.XML glade
= new Glade
.XML (null, "settings.glade", "netbeagle_entry_dialog", "beagle");
391 glade
.Autoconnect (this);
392 ResponseType nbed_response
= (ResponseType
) netbeagle_entry_dialog
.Run ();
394 string new_node
= netbeagle_textentry
.Text
.Trim();
396 if ((new_node
.Length
> 1) && (((string[])new_node
.Split(':')).Length
< 2))
399 netbeagle_entry_dialog
.Destroy ();
401 if (nbed_response
== ResponseType
.Ok
) {
402 string error_message
= "";
403 bool throw_error
= false;
405 if (new_node
.Length
< 2)
408 error_message
= Catalog
.GetString ("Invalid host entry");
411 // Check if the new entry matches an existing netbeagle entry
412 foreach (string old_node
in netbeagle_view
.Netbeagles
) {
413 if (new_node
== old_node
) {
415 error_message
= Catalog
.GetString ("Remote host already present in the list.");
420 HigMessageDialog
.RunHigMessageDialog (settings_dialog
,
424 Catalog
.GetString ("Netbeagle Node not added"),
428 netbeagle_view
.AddNode (new_node
);
433 private void OnRemoveNetbeagleClicked (object o
, EventArgs args
)
436 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
438 MessageType
.Question
,
440 Catalog
.GetString ("Remove host"),
441 Catalog
.GetString ("Are you sure you wish to remove this host from the list?"));
443 ResponseType response
= (ResponseType
) dialog
.Run ();
446 if (response
!= ResponseType
.Yes
)
449 netbeagle_view
.RemoveSelectedNode ();
451 remove_netbeagle_button
.Sensitive
= false;
454 private void OnNetbeagleSelected (object o
, EventArgs args
)
456 remove_netbeagle_button
.Sensitive
= true;
459 //Publicfolders: Add, Remove operations
460 private void OnAddPublicfolderClicked (object o
, EventArgs args
)
462 CompatFileChooserDialog fs_dialog
= new CompatFileChooserDialog (Catalog
.GetString ("Select path"),
464 CompatFileChooserDialog
.Action
.SelectFolder
);
465 fs_dialog
.SelectMultiple
= false;
467 ResponseType fs_response
= (ResponseType
) fs_dialog
.Run ();
468 string new_pf
= fs_dialog
.Filename
;
469 fs_dialog
.Destroy ();
471 if (fs_response
== ResponseType
.Ok
) {
473 string error_message
= "";
474 bool throw_error
= false;
476 // Check and see if the current data collides with the new path in any way
477 // FIXME: Do this with System.IO.Path or something
478 foreach (string old_pf
in publicfolder_view
.Publicfolders
) {
479 if (new_pf
== old_pf
) {
481 error_message
= Catalog
.GetString ("The selected path is already configured for external access.");
486 HigMessageDialog
.RunHigMessageDialog (settings_dialog
,
490 Catalog
.GetString ("Path not added"),
494 publicfolder_view
.AddPath (new_pf
);
498 private void OnRemovePublicfolderClicked (object o
, EventArgs args
)
501 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
503 MessageType
.Question
,
505 Catalog
.GetString ("Remove public path"),
506 Catalog
.GetString ("Are you sure you wish to remove this entry from the list of public paths?"));
508 ResponseType response
= (ResponseType
) dialog
.Run ();
511 if (response
!= ResponseType
.Yes
)
514 publicfolder_view
.RemoveSelectedPath ();
515 remove_publicfolder_button
.Sensitive
= false;
518 private void OnPublicfolderSelected (object o
, EventArgs args
)
520 remove_publicfolder_button
.Sensitive
= true;
523 ////////////////////////////////////////////////////////////////
526 class IncludeView
: TreeView
528 private ListStore store
;
530 private ArrayList includes
= new ArrayList ();
532 public ArrayList Includes
{
533 get { return includes; }
536 private enum TargetType
{
540 private static TargetEntry
[] target_table
= new TargetEntry
[] {
541 new TargetEntry ("STRING", 0, (uint) TargetType
.Uri
),
542 new TargetEntry ("text/plain", 0, (uint) TargetType
.Uri
),
545 public IncludeView ()
547 store
= new ListStore (typeof (string));
551 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 0);
553 // Enable drag and drop folders from nautilus
554 Gtk
.Drag
.DestSet (this, DestDefaults
.All
, target_table
, DragAction
.Copy
| DragAction
.Move
);
555 DragDataReceived
+= new DragDataReceivedHandler (HandleData
);
558 public void AddPath (string path
)
561 store
.AppendValues (path
);
564 public void RemovePath (string path
)
567 found_iter
= TreeIter
.Zero
;
569 this.Model
.Foreach (new TreeModelForeachFunc (ForeachFindPath
));
571 store
.Remove (ref found_iter
);
572 includes
.Remove (path
);
575 private string find_path
;
576 private TreeIter found_iter
;
578 private bool ForeachFindPath (TreeModel model
, TreePath path
, TreeIter iter
)
580 if ((string) model
.GetValue (iter
, 0) == find_path
) {
588 public void RemoveSelectedPath ()
593 if (!this.Selection
.GetSelected(out model
, out iter
)) {
596 string path
= (string)model
.GetValue(iter
, 0);
598 store
.Remove (ref iter
);
599 includes
.Remove (path
);
602 // Handle drag and drop data. Enables users to drag a folder that he wishes
603 // to add for indexing from Nautilus.
604 // FIXME: Pass checks as in OnAddIncludeButtonClicked
605 private void HandleData (object o
, DragDataReceivedArgs args
) {
607 if (args
.SelectionData
.Length
>=0 && args
.SelectionData
.Format
== 8) {
608 uri
= new Uri (args
.SelectionData
.Text
.Trim ());
609 AddPath (uri
.LocalPath
);
610 Gtk
.Drag
.Finish (args
.Context
, true, false, args
.Time
);
612 Gtk
.Drag
.Finish (args
.Context
, false, false, args
.Time
);
616 ////////////////////////////////////////////////////////////////
619 class ExcludeView
: TreeView
621 ArrayList excludes
= new ArrayList ();
623 public ArrayList Excludes
{
624 get { return excludes; }
627 public ExcludeView ()
629 this.Model
= new ListStore (typeof (ExcludeItem
));
631 CellRendererText renderer_text
= new CellRendererText ();
633 TreeViewColumn type_column
= new TreeViewColumn ();
634 type_column
.Title
= Catalog
.GetString ("Type");
635 type_column
.PackStart (renderer_text
, false);
636 type_column
.SetCellDataFunc (renderer_text
, new TreeCellDataFunc (TypeCellDataFunc
));
637 AppendColumn (type_column
);
639 TreeViewColumn name_column
= new TreeViewColumn ();
640 name_column
.Title
= Catalog
.GetString ("Name");
641 name_column
.PackStart (renderer_text
, false);
642 name_column
.SetCellDataFunc (renderer_text
, new TreeCellDataFunc (NameCellDataFunc
));
643 AppendColumn (name_column
);
646 public void RemoveSelectedItem ()
651 if (!this.Selection
.GetSelected(out model
, out iter
)) {
654 ExcludeItem exclude_item
= (ExcludeItem
) model
.GetValue(iter
, 0);
656 ((ListStore
)this.Model
).Remove (ref iter
);
657 excludes
.Remove (exclude_item
);
660 public void AddItem (ExcludeItem exclude_item
)
662 excludes
.Add (exclude_item
);
663 ((ListStore
)this.Model
).AppendValues (exclude_item
);
666 private void NameCellDataFunc (TreeViewColumn column
,
667 CellRenderer renderer
,
671 ExcludeItem exclude_item
= (ExcludeItem
) model
.GetValue (iter
, 0);
672 if (exclude_item
.Type
== ExcludeType
.MailFolder
)
673 ((CellRendererText
)renderer
).Text
= MailFolder
.GetNameForPath (exclude_item
.Value
);
675 ((CellRendererText
)renderer
).Text
= exclude_item
.Value
;
678 private void TypeCellDataFunc (TreeViewColumn column
,
679 CellRenderer renderer
,
683 ExcludeItem exclude_item
= (ExcludeItem
) model
.GetValue (iter
, 0);
685 switch (exclude_item
.Type
) {
686 case ExcludeType
.Path
:
687 ((CellRendererText
)renderer
).Text
= Catalog
.GetString ("Path:");
689 case ExcludeType
.Pattern
:
690 ((CellRendererText
)renderer
).Text
= Catalog
.GetString ("Pattern:");
692 case ExcludeType
.MailFolder
:
693 ((CellRendererText
)renderer
).Text
= Catalog
.GetString ("Mail folder:");
699 ////////////////////////////////////////////////////////////////
702 class NetbeagleView
: TreeView
704 private ListStore store
;
706 private ArrayList netBeagleList
= new ArrayList ();
708 public ArrayList Netbeagles
{
709 get { return netBeagleList; }
712 public NetbeagleView ()
714 store
= new ListStore (typeof (string));
718 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 0);
721 public void AddNode (string node
)
723 netBeagleList
.Add (node
);
724 store
.AppendValues (node
);
727 public void RemoveNode (string node
)
730 found_iter
= TreeIter
.Zero
;
732 this.Model
.Foreach (new TreeModelForeachFunc (ForeachFindNode
));
734 store
.Remove (ref found_iter
);
735 netBeagleList
.Remove (node
);
738 private string find_node
;
739 private TreeIter found_iter
;
741 private bool ForeachFindNode (TreeModel model
, TreePath path
, TreeIter iter
)
743 if ((string) model
.GetValue (iter
, 0) == find_node
) {
751 public void RemoveSelectedNode ()
756 if (!this.Selection
.GetSelected(out model
, out iter
)) {
759 string node
= (string)model
.GetValue(iter
, 0);
761 store
.Remove (ref iter
);
762 netBeagleList
.Remove (node
);
766 ////////////////////////////////////////////////////////////////
769 class PublicfolderView
: TreeView
771 private ListStore store
;
773 private ArrayList publicFolders
= new ArrayList ();
775 public ArrayList Publicfolders
{
776 get { return publicFolders; }
779 private enum TargetType
{
783 private static TargetEntry
[] target_table
= new TargetEntry
[] {
784 new TargetEntry ("STRING", 0, (uint) TargetType
.Uri
),
785 new TargetEntry ("text/plain", 0, (uint) TargetType
.Uri
),
788 public PublicfolderView ()
790 store
= new ListStore (typeof (string));
794 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 0);
796 // Enable drag and drop folders from nautilus
797 Gtk
.Drag
.DestSet (this, DestDefaults
.All
, target_table
, DragAction
.Copy
| DragAction
.Move
);
798 DragDataReceived
+= new DragDataReceivedHandler (HandleData
);
801 public void AddPath (string path
)
803 publicFolders
.Add (path
);
804 store
.AppendValues (path
);
807 public void RemovePath (string path
)
810 found_iter
= TreeIter
.Zero
;
812 this.Model
.Foreach (new TreeModelForeachFunc (ForeachFindPath
));
814 store
.Remove (ref found_iter
);
815 publicFolders
.Remove (path
);
818 private string find_path
;
819 private TreeIter found_iter
;
821 private bool ForeachFindPath (TreeModel model
, TreePath path
, TreeIter iter
)
823 if ((string) model
.GetValue (iter
, 0) == find_path
) {
831 public void RemoveSelectedPath ()
836 if (!this.Selection
.GetSelected(out model
, out iter
)) {
839 string path
= (string)model
.GetValue(iter
, 0);
841 store
.Remove (ref iter
);
842 publicFolders
.Remove (path
);
845 // Handle drag and drop data. Enables users to drag a folder that he wishes
846 // to add for indexing from Nautilus.
847 // FIXME: Pass checks as in OnAddIncludeButtonClicked
848 private void HandleData (object o
, DragDataReceivedArgs args
) {
850 if (args
.SelectionData
.Length
>=0 && args
.SelectionData
.Format
== 8) {
851 uri
= new Uri (args
.SelectionData
.Text
.Trim ());
852 AddPath (uri
.LocalPath
);
853 Gtk
.Drag
.Finish (args
.Context
, true, false, args
.Time
);
855 Gtk
.Drag
.Finish (args
.Context
, false, false, args
.Time
);
859 ////////////////////////////////////////////////////////////////
860 // Mail folder dialog
862 class MailFolderDialog
865 FolderView folder_view
;
867 [Widget
] Dialog mail_folder_dialog
;
868 [Widget
] ScrolledWindow folder_sw
;
870 public event ExcludeItemAddedHandler ExcludeItemAddedEvent
;
872 public MailFolderDialog (Gtk
.Window parent
)
874 this.parent
= parent
;
876 Glade
.XML glade
= new Glade
.XML (null, "settings.glade", "mail_folder_dialog", "beagle");
877 glade
.Autoconnect (this);
879 folder_view
= new FolderView ();
881 folder_sw
.Child
= folder_view
;
884 private void OnDialogResponse (object o
, ResponseArgs args
)
886 if (args
.ResponseId
== ResponseType
.Cancel
) {
887 mail_folder_dialog
.Destroy ();
891 ExcludeItem exclude_item
;
892 object obj
= folder_view
.GetCurrentItem ();
894 if (obj
is MailAccount
) {
896 } else if (obj
is MailFolder
) {
897 MailFolder folder
= (MailFolder
) obj
;
898 exclude_item
= new ExcludeItem (ExcludeType
.MailFolder
, folder
.Path
);
900 if (ExcludeItemAddedEvent
!= null)
901 ExcludeItemAddedEvent (exclude_item
);
903 mail_folder_dialog
.Destroy ();
907 class FolderView
: TreeView
910 Gdk
.Pixbuf folder_icon
;
914 store
= new TreeStore (typeof (MailFolder
));
917 folder_icon
= this.RenderIcon (Stock
.Open
, IconSize
.Menu
, "");
919 HeadersVisible
= false;
921 TreeViewColumn column
= new TreeViewColumn ();
922 CellRendererPixbuf renderer_icon
= new CellRendererPixbuf ();
923 column
.PackStart (renderer_icon
, false);
924 column
.SetCellDataFunc (renderer_icon
, new TreeCellDataFunc (IconCellDataFunc
));
926 CellRendererText renderer_text
= new CellRendererText ();
927 column
.PackStart (renderer_text
, false);
928 column
.SetCellDataFunc (renderer_text
, new TreeCellDataFunc (NameCellDataFunc
));
929 AppendColumn (column
);
931 foreach (MailAccount account
in Beagle
.Util
.Evolution
.Accounts
) {
932 TreeIter iter
= store
.AppendValues (account
);
934 foreach (MailFolder folder
in account
.Children
) {
940 private void Add (TreeIter parent
, MailFolder folder
)
942 TreeIter current
= store
.AppendValues (parent
, folder
);
944 foreach (MailFolder child
in folder
.Children
)
945 Add (current
, child
);
948 private void IconCellDataFunc (TreeViewColumn column
,
949 CellRenderer renderer
,
953 object obj
= model
.GetValue (iter
, 0);
954 ((CellRendererPixbuf
)renderer
).Pixbuf
= (obj
is MailAccount
) ? null : folder_icon
;
957 private void NameCellDataFunc (TreeViewColumn column
,
958 CellRenderer renderer
,
962 object obj
= model
.GetValue (iter
, 0);
964 if (obj
is MailAccount
) {
965 MailAccount account
= obj
as MailAccount
;
966 ((CellRendererText
)renderer
).Markup
= String
.Format ("<b>{0}</b>",account
.Name
);
968 MailFolder folder
= obj
as MailFolder
;
969 ((CellRendererText
)renderer
).Text
= folder
.Name
;
973 public MailFolder
GetCurrentItem ()
978 if (!this.Selection
.GetSelected (out model
, out iter
)) {
982 return (MailFolder
) model
.GetValue (iter
, 0);
987 ////////////////////////////////////////////////////////////////
990 private delegate void ExcludeItemAddedHandler (ExcludeItem item
);
992 class AddExcludeDialog
996 [Widget
] Dialog add_exclude_dialog
;
997 [Widget
] Entry value_entry
;
998 [Widget
] Label value_name_label
;
999 [Widget
] Button browse_button
;
1001 [Widget
] RadioButton type_path_radio
;
1002 [Widget
] RadioButton type_pattern_radio
;
1003 [Widget
] RadioButton type_mailfolder_radio
;
1005 public event ExcludeItemAddedHandler ExcludeItemAddedEvent
;
1007 private string value;
1009 public string Value
{
1011 if (Type
== ExcludeType
.MailFolder
)
1014 return value_entry
.Text
;
1018 public ExcludeType Type
{
1020 if (type_path_radio
.Active
)
1021 return ExcludeType
.Path
;
1022 else if (type_pattern_radio
.Active
)
1023 return ExcludeType
.Pattern
;
1025 return ExcludeType
.MailFolder
;
1029 public AddExcludeDialog (Gtk
.Window parent
)
1031 this.parent
= parent
;
1033 Glade
.XML glade
= new Glade
.XML (null, "settings.glade", "add_exclude_dialog", "beagle");
1034 glade
.Autoconnect (this);
1037 private void OnBrowseButtonClicked (object o
, EventArgs args
)
1040 case ExcludeType
.Path
:
1041 CompatFileChooserDialog fs_dialog
= new CompatFileChooserDialog (Catalog
.GetString ("Select Folder"),
1043 CompatFileChooserDialog
.Action
.SelectFolder
);
1044 fs_dialog
.SelectMultiple
= false;
1046 ResponseType response
= (ResponseType
) fs_dialog
.Run ();
1048 if (response
== ResponseType
.Ok
)
1049 value_entry
.Text
= fs_dialog
.Filename
;
1051 fs_dialog
.Destroy ();
1053 case ExcludeType
.MailFolder
:
1054 MailFolderDialog mf_dialog
= new MailFolderDialog (add_exclude_dialog
);
1055 mf_dialog
.ExcludeItemAddedEvent
+= new ExcludeItemAddedHandler (OnExcludeItemAdded
);
1060 private void OnRadioGroupChanged (object o
, EventArgs args
)
1062 value_entry
.Text
= "";
1065 case ExcludeType
.Path
:
1066 browse_button
.Sensitive
= true;
1067 value_name_label
.TextWithMnemonic
= Catalog
.GetString ("P_ath:");
1068 value_entry
.IsEditable
= true;
1070 case ExcludeType
.MailFolder
:
1071 browse_button
.Sensitive
= true;
1072 value_name_label
.TextWithMnemonic
= Catalog
.GetString ("M_ail folder:");
1073 value_entry
.IsEditable
= false;
1075 case ExcludeType
.Pattern
:
1076 browse_button
.Sensitive
= false;
1077 value_name_label
.TextWithMnemonic
= Catalog
.GetString ("P_attern:");
1078 value_entry
.IsEditable
= true;
1083 private void OnExcludeItemAdded (ExcludeItem item
)
1086 value_entry
.Text
= MailFolder
.GetNameForPath (item
.Value
);
1089 private void OnDialogResponse (object o
, ResponseArgs args
)
1091 if (((ResponseType
)args
.ResponseId
) == ResponseType
.Ok
) {
1092 ExcludeItem exclude_item
= new ExcludeItem (Type
, Value
);
1095 case ExcludeType
.Path
:
1096 if (!Directory
.Exists (Value
)) {
1097 HigMessageDialog
.RunHigMessageDialog(add_exclude_dialog
,
1101 Catalog
.GetString ("Error adding path"),
1102 Catalog
.GetString ("The specified path could not be found and therefore it could not be added to the list of resources excluded for indexing."));
1108 if (ExcludeItemAddedEvent
!= null)
1109 ExcludeItemAddedEvent (exclude_item
);
1111 add_exclude_dialog
.Destroy ();
1114 public void Destroy ()
1116 add_exclude_dialog
.Destroy ();
1121 ////////////////////////////////////////////////////////////////
1124 class DisplayView
: TreeView
1126 public DisplayView ()
1128 ListStore store
= new ListStore (typeof(bool),typeof(string));
1132 AppendColumn (Catalog
.GetString ("Show"), new CellRendererToggle (), "active", 0);
1133 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 1);