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 settings_dialog
.Icon
= Beagle
.Images
.GetPixbuf ("system-search.png");
113 administration_frame
.Visible
= (Environment
.UserName
== "root");
116 display_view
= new DisplayView ();
117 display_view
.Selection
.Changed
+= new EventHandler (OnDisplaySelected
);
118 display_view
.Show ();
119 // The display sorting stuff is something i have been testing locally, Best CVS wont use it
120 display_sw
.Child
= display_view
;
122 include_view
= new IncludeView ();
123 include_view
.Selection
.Changed
+= new EventHandler (OnIncludeSelected
);
124 include_view
.Show ();
125 include_sw
.Child
= include_view
;
127 exclude_view
= new ExcludeView ();
128 exclude_view
.Selection
.Changed
+= new EventHandler (OnExcludeSelected
);
129 exclude_view
.Show ();
130 exclude_sw
.Child
= exclude_view
;
132 #if ENABLE_WEBSERVICES
133 networking_box
.Visible
= true;
135 publicfolder_view
= new PublicfolderView ();
136 publicfolder_view
.Selection
.Changed
+= new EventHandler (OnPublicfolderSelected
);
137 publicfolder_view
.Show ();
138 publicfolder_sw
.Child
= publicfolder_view
;
140 netbeagle_view
= new NetbeagleView ();
141 netbeagle_view
.Selection
.Changed
+= new EventHandler (OnNetbeagleSelected
);
142 netbeagle_view
.Show ();
143 netbeagle_sw
.Child
= netbeagle_view
;
145 LoadConfiguration ();
147 Conf
.Subscribe (typeof (Conf
.IndexingConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
148 Conf
.Subscribe (typeof (Conf
.SearchingConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
150 #if ENABLE_WEBSERVICES
151 Conf
.Subscribe (typeof (Conf
.NetworkingConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
152 Conf
.Subscribe (typeof (Conf
.WebServicesConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
161 ////////////////////////////////////////////////////////////////
164 private void LoadConfiguration ()
166 allow_root_toggle
.Active
= Conf
.Daemon
.AllowRoot
;
167 autostart_toggle
.Active
= Conf
.Searching
.Autostart
;
168 battery_toggle
.Active
= Conf
.Indexing
.IndexOnBattery
;
170 KeyBinding show_binding
= Conf
.Searching
.ShowSearchWindowBinding
;
171 press_ctrl_toggle
.Active
= show_binding
.Ctrl
;
172 press_alt_toggle
.Active
= show_binding
.Alt
;
173 show_search_window_entry
.Text
= show_binding
.Key
;
174 max_displayed_spinbutton
.Value
= (uint) Conf
.Searching
.MaxDisplayed
;
176 if (Conf
.Indexing
.IndexHomeDir
)
177 index_home_toggle
.Active
= true;
179 foreach (string include
in Conf
.Indexing
.Roots
)
180 include_view
.AddPath (include
);
182 foreach (ExcludeItem exclude_item
in Conf
.Indexing
.Excludes
)
183 exclude_view
.AddItem (exclude_item
);
185 #if ENABLE_WEBSERVICES
186 foreach (string netbeagle
in Conf
.Networking
.NetBeagleNodes
)
187 netbeagle_view
.AddNode (netbeagle
);
189 if (Conf
.WebServices
.AllowGlobalAccess
)
190 allow_global_access_toggle
.Active
= true;
192 foreach (string publicfolder
in Conf
.WebServices
.PublicFolders
)
193 publicfolder_view
.AddPath (publicfolder
);
197 private void SaveConfiguration ()
199 Conf
.Daemon
.AllowRoot
= allow_root_toggle
.Active
;
200 Conf
.Searching
.Autostart
= autostart_toggle
.Active
;
201 Conf
.Indexing
.IndexOnBattery
= battery_toggle
.Active
;
203 Conf
.Searching
.ShowSearchWindowBinding
= new KeyBinding (show_search_window_entry
.Text
,
204 press_ctrl_toggle
.Active
,
205 press_alt_toggle
.Active
);
207 Conf
.Searching
.MaxDisplayed
= (int) max_displayed_spinbutton
.Value
;
208 Conf
.Indexing
.IndexHomeDir
= index_home_toggle
.Active
;
210 Conf
.Indexing
.Roots
= include_view
.Includes
;
211 Conf
.Indexing
.Excludes
= exclude_view
.Excludes
;
213 #if ENABLE_WEBSERVICES
214 Conf
.Networking
.NetBeagleNodes
= netbeagle_view
.Netbeagles
;
215 Conf
.WebServices
.AllowGlobalAccess
= allow_global_access_toggle
.Active
;
216 Conf
.WebServices
.PublicFolders
= publicfolder_view
.Publicfolders
;
221 private void OnConfigurationChanged (Conf
.Section section
)
223 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
225 MessageType
.Question
,
227 Catalog
.GetString ("Reload configuration"),
228 Catalog
.GetString ("The configuration file has been modified by another application. " +
229 "Do you wish to discard the currently displayed values and reload configuration from disk?"));
231 ResponseType response
= (ResponseType
) dialog
.Run ();
233 if (response
== ResponseType
.Yes
)
234 LoadConfiguration ();
239 ////////////////////////////////////////////////////////////////
242 private void OnDialogResponse (object o
, ResponseArgs args
)
244 switch (args
.ResponseId
) {
245 case ResponseType
.Help
:
246 Gnome
.Url
.Show ("http://beagle-project.org/Configuring");
248 case ResponseType
.Ok
:
249 SaveConfiguration ();
258 private void OnDisplaySelected (object o
, EventArgs args
)
260 display_up_button
.Sensitive
= true;
261 display_down_button
.Sensitive
= true;
264 private void OnAddIncludeClicked (object o
, EventArgs args
)
266 CompatFileChooserDialog fs_dialog
= new CompatFileChooserDialog (Catalog
.GetString ("Select Path"),
268 CompatFileChooserDialog
.Action
.SelectFolder
);
269 fs_dialog
.SelectMultiple
= false;
271 ResponseType fs_response
= (ResponseType
) fs_dialog
.Run ();
272 string new_include
= fs_dialog
.Filename
;
273 fs_dialog
.Destroy ();
275 if (fs_response
== ResponseType
.Ok
) {
276 string error_message
= "";
277 bool throw_error
= false;
278 ArrayList obsolete_includes
= new ArrayList ();
280 // Check and see if the current data collides with the new path in any way
281 // FIXME: Do this with System.IO.Path or something
282 foreach (string old_include
in include_view
.Includes
) {
283 if (new_include
== old_include
) {
285 error_message
= Catalog
.GetString ("The selected path is already selected for indexing and wasn't added.");
286 } else if (new_include
.StartsWith (old_include
)) {
288 error_message
= Catalog
.GetString ("The selected path wasn't added. The list contains items that supercedes it and the data is already being indexed.");
289 } else if (old_include
.StartsWith (new_include
)) {
290 obsolete_includes
.Add (old_include
);
295 HigMessageDialog
.RunHigMessageDialog (settings_dialog
,
299 Catalog
.GetString ("Path not added"),
302 // Confirm the removal of obsolete includes
303 if (obsolete_includes
.Count
!= 0) {
304 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
306 MessageType
.Question
,
308 Catalog
.GetString ("Remove obsolete paths"),
309 Catalog
.GetString ("Adding this path will obsolete some of the existing include paths. " +
310 "This will result in the removal of the old obsolete paths. Do you still wish to add it?"));
312 ResponseType confirm_response
= (ResponseType
) dialog
.Run ();
314 if (confirm_response
!= ResponseType
.Yes
)
317 foreach (string obsolete_include
in obsolete_includes
)
318 include_view
.RemovePath (obsolete_include
);
323 include_view
.AddPath (new_include
);
328 private void OnRemoveIncludeClicked (object o
, EventArgs args
)
331 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
333 MessageType
.Question
,
335 Catalog
.GetString ("Remove path"),
336 Catalog
.GetString ("Are you sure you wish to remove this path from the list of directories to be included for indexing?"));
337 ResponseType response
= (ResponseType
) dialog
.Run ();
340 if (response
!= ResponseType
.Yes
)
343 include_view
.RemoveSelectedPath ();
344 remove_include_button
.Sensitive
= false;
347 private void OnIncludeSelected (object o
, EventArgs args
)
349 remove_include_button
.Sensitive
= true;
352 private void OnAddExcludeClicked (object o
, EventArgs args
)
354 AddExcludeDialog dialog
= new AddExcludeDialog (settings_dialog
);
355 dialog
.ExcludeItemAddedEvent
+= new ExcludeItemAddedHandler (OnExcludeItemAdded
);
359 private void OnRemoveExcludeClicked (object o
, EventArgs args
)
361 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
363 MessageType
.Question
,
365 Catalog
.GetString ("Remove item"),
366 Catalog
.GetString ("Are you sure you wish to remove this item from the list of data to be excluded from indexing?"));
368 ResponseType response
= (ResponseType
) dialog
.Run ();
371 if (response
!= ResponseType
.Yes
)
374 exclude_view
.RemoveSelectedItem ();
375 remove_exclude_button
.Sensitive
= false;
378 private void OnExcludeSelected (object o
, EventArgs args
)
380 remove_exclude_button
.Sensitive
= true;
383 private void OnExcludeItemAdded (ExcludeItem exclude_item
)
385 exclude_view
.AddItem (exclude_item
);
388 //Netbeagle: Add, Remove operations
389 private void OnAddNetbeagleClicked (object o
, EventArgs args
)
391 Glade
.XML glade
= new Glade
.XML (null, "settings.glade", "netbeagle_entry_dialog", "beagle");
392 glade
.Autoconnect (this);
393 ResponseType nbed_response
= (ResponseType
) netbeagle_entry_dialog
.Run ();
395 string new_node
= netbeagle_textentry
.Text
.Trim();
397 if ((new_node
.Length
> 1) && (((string[])new_node
.Split(':')).Length
< 2))
400 netbeagle_entry_dialog
.Destroy ();
402 if (nbed_response
== ResponseType
.Ok
) {
403 string error_message
= "";
404 bool throw_error
= false;
406 if (new_node
.Length
< 2)
409 error_message
= Catalog
.GetString ("Invalid host entry");
412 // Check if the new entry matches an existing netbeagle entry
413 foreach (string old_node
in netbeagle_view
.Netbeagles
) {
414 if (new_node
== old_node
) {
416 error_message
= Catalog
.GetString ("Remote host already present in the list.");
421 HigMessageDialog
.RunHigMessageDialog (settings_dialog
,
425 Catalog
.GetString ("Netbeagle Node not added"),
429 netbeagle_view
.AddNode (new_node
);
434 private void OnRemoveNetbeagleClicked (object o
, EventArgs args
)
437 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
439 MessageType
.Question
,
441 Catalog
.GetString ("Remove host"),
442 Catalog
.GetString ("Are you sure you wish to remove this host from the list?"));
444 ResponseType response
= (ResponseType
) dialog
.Run ();
447 if (response
!= ResponseType
.Yes
)
450 netbeagle_view
.RemoveSelectedNode ();
452 remove_netbeagle_button
.Sensitive
= false;
455 private void OnNetbeagleSelected (object o
, EventArgs args
)
457 remove_netbeagle_button
.Sensitive
= true;
460 //Publicfolders: Add, Remove operations
461 private void OnAddPublicfolderClicked (object o
, EventArgs args
)
463 CompatFileChooserDialog fs_dialog
= new CompatFileChooserDialog (Catalog
.GetString ("Select path"),
465 CompatFileChooserDialog
.Action
.SelectFolder
);
466 fs_dialog
.SelectMultiple
= false;
468 ResponseType fs_response
= (ResponseType
) fs_dialog
.Run ();
469 string new_pf
= fs_dialog
.Filename
;
470 fs_dialog
.Destroy ();
472 if (fs_response
== ResponseType
.Ok
) {
474 string error_message
= "";
475 bool throw_error
= false;
477 // Check and see if the current data collides with the new path in any way
478 // FIXME: Do this with System.IO.Path or something
479 foreach (string old_pf
in publicfolder_view
.Publicfolders
) {
480 if (new_pf
== old_pf
) {
482 error_message
= Catalog
.GetString ("The selected path is already configured for external access.");
487 HigMessageDialog
.RunHigMessageDialog (settings_dialog
,
491 Catalog
.GetString ("Path not added"),
495 publicfolder_view
.AddPath (new_pf
);
499 private void OnRemovePublicfolderClicked (object o
, EventArgs args
)
502 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
504 MessageType
.Question
,
506 Catalog
.GetString ("Remove public path"),
507 Catalog
.GetString ("Are you sure you wish to remove this entry from the list of public paths?"));
509 ResponseType response
= (ResponseType
) dialog
.Run ();
512 if (response
!= ResponseType
.Yes
)
515 publicfolder_view
.RemoveSelectedPath ();
516 remove_publicfolder_button
.Sensitive
= false;
519 private void OnPublicfolderSelected (object o
, EventArgs args
)
521 remove_publicfolder_button
.Sensitive
= true;
524 ////////////////////////////////////////////////////////////////
527 class IncludeView
: TreeView
529 private ListStore store
;
531 private ArrayList includes
= new ArrayList ();
533 public ArrayList Includes
{
534 get { return includes; }
537 private enum TargetType
{
541 private static TargetEntry
[] target_table
= new TargetEntry
[] {
542 new TargetEntry ("STRING", 0, (uint) TargetType
.Uri
),
543 new TargetEntry ("text/plain", 0, (uint) TargetType
.Uri
),
546 public IncludeView ()
548 store
= new ListStore (typeof (string));
552 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 0);
554 // Enable drag and drop folders from nautilus
555 Gtk
.Drag
.DestSet (this, DestDefaults
.All
, target_table
, DragAction
.Copy
| DragAction
.Move
);
556 DragDataReceived
+= new DragDataReceivedHandler (HandleData
);
559 public void AddPath (string path
)
562 store
.AppendValues (path
);
565 public void RemovePath (string path
)
568 found_iter
= TreeIter
.Zero
;
570 this.Model
.Foreach (new TreeModelForeachFunc (ForeachFindPath
));
572 store
.Remove (ref found_iter
);
573 includes
.Remove (path
);
576 private string find_path
;
577 private TreeIter found_iter
;
579 private bool ForeachFindPath (TreeModel model
, TreePath path
, TreeIter iter
)
581 if ((string) model
.GetValue (iter
, 0) == find_path
) {
589 public void RemoveSelectedPath ()
594 if (!this.Selection
.GetSelected(out model
, out iter
)) {
597 string path
= (string)model
.GetValue(iter
, 0);
599 store
.Remove (ref iter
);
600 includes
.Remove (path
);
603 // Handle drag and drop data. Enables users to drag a folder that he wishes
604 // to add for indexing from Nautilus.
605 // FIXME: Pass checks as in OnAddIncludeButtonClicked
606 private void HandleData (object o
, DragDataReceivedArgs args
) {
608 if (args
.SelectionData
.Length
>=0 && args
.SelectionData
.Format
== 8) {
609 uri
= new Uri (args
.SelectionData
.Text
.Trim ());
610 AddPath (uri
.LocalPath
);
611 Gtk
.Drag
.Finish (args
.Context
, true, false, args
.Time
);
613 Gtk
.Drag
.Finish (args
.Context
, false, false, args
.Time
);
617 ////////////////////////////////////////////////////////////////
620 class ExcludeView
: TreeView
622 ArrayList excludes
= new ArrayList ();
624 public ArrayList Excludes
{
625 get { return excludes; }
628 public ExcludeView ()
630 this.Model
= new ListStore (typeof (ExcludeItem
));
632 CellRendererText renderer_text
= new CellRendererText ();
634 TreeViewColumn type_column
= new TreeViewColumn ();
635 type_column
.Title
= Catalog
.GetString ("Type");
636 type_column
.PackStart (renderer_text
, false);
637 type_column
.SetCellDataFunc (renderer_text
, new TreeCellDataFunc (TypeCellDataFunc
));
638 AppendColumn (type_column
);
640 TreeViewColumn name_column
= new TreeViewColumn ();
641 name_column
.Title
= Catalog
.GetString ("Name");
642 name_column
.PackStart (renderer_text
, false);
643 name_column
.SetCellDataFunc (renderer_text
, new TreeCellDataFunc (NameCellDataFunc
));
644 AppendColumn (name_column
);
647 public void RemoveSelectedItem ()
652 if (!this.Selection
.GetSelected(out model
, out iter
)) {
655 ExcludeItem exclude_item
= (ExcludeItem
) model
.GetValue(iter
, 0);
657 ((ListStore
)this.Model
).Remove (ref iter
);
658 excludes
.Remove (exclude_item
);
661 public void AddItem (ExcludeItem exclude_item
)
663 excludes
.Add (exclude_item
);
664 ((ListStore
)this.Model
).AppendValues (exclude_item
);
667 private void NameCellDataFunc (TreeViewColumn column
,
668 CellRenderer renderer
,
672 ExcludeItem exclude_item
= (ExcludeItem
) model
.GetValue (iter
, 0);
673 if (exclude_item
.Type
== ExcludeType
.MailFolder
)
674 ((CellRendererText
)renderer
).Text
= MailFolder
.GetNameForPath (exclude_item
.Value
);
676 ((CellRendererText
)renderer
).Text
= exclude_item
.Value
;
679 private void TypeCellDataFunc (TreeViewColumn column
,
680 CellRenderer renderer
,
684 ExcludeItem exclude_item
= (ExcludeItem
) model
.GetValue (iter
, 0);
686 switch (exclude_item
.Type
) {
687 case ExcludeType
.Path
:
688 ((CellRendererText
)renderer
).Text
= Catalog
.GetString ("Path:");
690 case ExcludeType
.Pattern
:
691 ((CellRendererText
)renderer
).Text
= Catalog
.GetString ("Pattern:");
693 case ExcludeType
.MailFolder
:
694 ((CellRendererText
)renderer
).Text
= Catalog
.GetString ("Mail folder:");
700 ////////////////////////////////////////////////////////////////
703 class NetbeagleView
: TreeView
705 private ListStore store
;
707 private ArrayList netBeagleList
= new ArrayList ();
709 public ArrayList Netbeagles
{
710 get { return netBeagleList; }
713 public NetbeagleView ()
715 store
= new ListStore (typeof (string));
719 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 0);
722 public void AddNode (string node
)
724 netBeagleList
.Add (node
);
725 store
.AppendValues (node
);
728 public void RemoveNode (string node
)
731 found_iter
= TreeIter
.Zero
;
733 this.Model
.Foreach (new TreeModelForeachFunc (ForeachFindNode
));
735 store
.Remove (ref found_iter
);
736 netBeagleList
.Remove (node
);
739 private string find_node
;
740 private TreeIter found_iter
;
742 private bool ForeachFindNode (TreeModel model
, TreePath path
, TreeIter iter
)
744 if ((string) model
.GetValue (iter
, 0) == find_node
) {
752 public void RemoveSelectedNode ()
757 if (!this.Selection
.GetSelected(out model
, out iter
)) {
760 string node
= (string)model
.GetValue(iter
, 0);
762 store
.Remove (ref iter
);
763 netBeagleList
.Remove (node
);
767 ////////////////////////////////////////////////////////////////
770 class PublicfolderView
: TreeView
772 private ListStore store
;
774 private ArrayList publicFolders
= new ArrayList ();
776 public ArrayList Publicfolders
{
777 get { return publicFolders; }
780 private enum TargetType
{
784 private static TargetEntry
[] target_table
= new TargetEntry
[] {
785 new TargetEntry ("STRING", 0, (uint) TargetType
.Uri
),
786 new TargetEntry ("text/plain", 0, (uint) TargetType
.Uri
),
789 public PublicfolderView ()
791 store
= new ListStore (typeof (string));
795 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 0);
797 // Enable drag and drop folders from nautilus
798 Gtk
.Drag
.DestSet (this, DestDefaults
.All
, target_table
, DragAction
.Copy
| DragAction
.Move
);
799 DragDataReceived
+= new DragDataReceivedHandler (HandleData
);
802 public void AddPath (string path
)
804 publicFolders
.Add (path
);
805 store
.AppendValues (path
);
808 public void RemovePath (string path
)
811 found_iter
= TreeIter
.Zero
;
813 this.Model
.Foreach (new TreeModelForeachFunc (ForeachFindPath
));
815 store
.Remove (ref found_iter
);
816 publicFolders
.Remove (path
);
819 private string find_path
;
820 private TreeIter found_iter
;
822 private bool ForeachFindPath (TreeModel model
, TreePath path
, TreeIter iter
)
824 if ((string) model
.GetValue (iter
, 0) == find_path
) {
832 public void RemoveSelectedPath ()
837 if (!this.Selection
.GetSelected(out model
, out iter
)) {
840 string path
= (string)model
.GetValue(iter
, 0);
842 store
.Remove (ref iter
);
843 publicFolders
.Remove (path
);
846 // Handle drag and drop data. Enables users to drag a folder that he wishes
847 // to add for indexing from Nautilus.
848 // FIXME: Pass checks as in OnAddIncludeButtonClicked
849 private void HandleData (object o
, DragDataReceivedArgs args
) {
851 if (args
.SelectionData
.Length
>=0 && args
.SelectionData
.Format
== 8) {
852 uri
= new Uri (args
.SelectionData
.Text
.Trim ());
853 AddPath (uri
.LocalPath
);
854 Gtk
.Drag
.Finish (args
.Context
, true, false, args
.Time
);
856 Gtk
.Drag
.Finish (args
.Context
, false, false, args
.Time
);
860 ////////////////////////////////////////////////////////////////
861 // Mail folder dialog
863 class MailFolderDialog
866 FolderView folder_view
;
868 [Widget
] Dialog mail_folder_dialog
;
869 [Widget
] ScrolledWindow folder_sw
;
871 public event ExcludeItemAddedHandler ExcludeItemAddedEvent
;
873 public MailFolderDialog (Gtk
.Window parent
)
875 this.parent
= parent
;
877 Glade
.XML glade
= new Glade
.XML (null, "settings.glade", "mail_folder_dialog", "beagle");
878 glade
.Autoconnect (this);
880 folder_view
= new FolderView ();
882 folder_sw
.Child
= folder_view
;
885 private void OnDialogResponse (object o
, ResponseArgs args
)
887 if (args
.ResponseId
== ResponseType
.Cancel
) {
888 mail_folder_dialog
.Destroy ();
892 ExcludeItem exclude_item
;
893 object obj
= folder_view
.GetCurrentItem ();
895 if (obj
is MailAccount
) {
897 } else if (obj
is MailFolder
) {
898 MailFolder folder
= (MailFolder
) obj
;
899 exclude_item
= new ExcludeItem (ExcludeType
.MailFolder
, folder
.Path
);
901 if (ExcludeItemAddedEvent
!= null)
902 ExcludeItemAddedEvent (exclude_item
);
904 mail_folder_dialog
.Destroy ();
908 class FolderView
: TreeView
911 Gdk
.Pixbuf folder_icon
;
915 store
= new TreeStore (typeof (MailFolder
));
918 folder_icon
= this.RenderIcon (Stock
.Open
, IconSize
.Menu
, "");
920 HeadersVisible
= false;
922 TreeViewColumn column
= new TreeViewColumn ();
923 CellRendererPixbuf renderer_icon
= new CellRendererPixbuf ();
924 column
.PackStart (renderer_icon
, false);
925 column
.SetCellDataFunc (renderer_icon
, new TreeCellDataFunc (IconCellDataFunc
));
927 CellRendererText renderer_text
= new CellRendererText ();
928 column
.PackStart (renderer_text
, false);
929 column
.SetCellDataFunc (renderer_text
, new TreeCellDataFunc (NameCellDataFunc
));
930 AppendColumn (column
);
932 foreach (MailAccount account
in Beagle
.Util
.Evolution
.Accounts
) {
933 TreeIter iter
= store
.AppendValues (account
);
935 foreach (MailFolder folder
in account
.Children
) {
941 private void Add (TreeIter parent
, MailFolder folder
)
943 TreeIter current
= store
.AppendValues (parent
, folder
);
945 foreach (MailFolder child
in folder
.Children
)
946 Add (current
, child
);
949 private void IconCellDataFunc (TreeViewColumn column
,
950 CellRenderer renderer
,
954 object obj
= model
.GetValue (iter
, 0);
955 ((CellRendererPixbuf
)renderer
).Pixbuf
= (obj
is MailAccount
) ? null : folder_icon
;
958 private void NameCellDataFunc (TreeViewColumn column
,
959 CellRenderer renderer
,
963 object obj
= model
.GetValue (iter
, 0);
965 if (obj
is MailAccount
) {
966 MailAccount account
= obj
as MailAccount
;
967 ((CellRendererText
)renderer
).Markup
= String
.Format ("<b>{0}</b>",account
.Name
);
969 MailFolder folder
= obj
as MailFolder
;
970 ((CellRendererText
)renderer
).Text
= folder
.Name
;
974 public MailFolder
GetCurrentItem ()
979 if (!this.Selection
.GetSelected (out model
, out iter
)) {
983 return (MailFolder
) model
.GetValue (iter
, 0);
988 ////////////////////////////////////////////////////////////////
991 private delegate void ExcludeItemAddedHandler (ExcludeItem item
);
993 class AddExcludeDialog
997 [Widget
] Dialog add_exclude_dialog
;
998 [Widget
] Entry value_entry
;
999 [Widget
] Label value_name_label
;
1000 [Widget
] Button browse_button
;
1002 [Widget
] RadioButton type_path_radio
;
1003 [Widget
] RadioButton type_pattern_radio
;
1004 [Widget
] RadioButton type_mailfolder_radio
;
1006 public event ExcludeItemAddedHandler ExcludeItemAddedEvent
;
1008 private string value;
1010 public string Value
{
1012 if (Type
== ExcludeType
.MailFolder
)
1015 return value_entry
.Text
;
1019 public ExcludeType Type
{
1021 if (type_path_radio
.Active
)
1022 return ExcludeType
.Path
;
1023 else if (type_pattern_radio
.Active
)
1024 return ExcludeType
.Pattern
;
1026 return ExcludeType
.MailFolder
;
1030 public AddExcludeDialog (Gtk
.Window parent
)
1032 this.parent
= parent
;
1034 Glade
.XML glade
= new Glade
.XML (null, "settings.glade", "add_exclude_dialog", "beagle");
1035 glade
.Autoconnect (this);
1038 private void OnBrowseButtonClicked (object o
, EventArgs args
)
1041 case ExcludeType
.Path
:
1042 CompatFileChooserDialog fs_dialog
= new CompatFileChooserDialog (Catalog
.GetString ("Select Folder"),
1044 CompatFileChooserDialog
.Action
.SelectFolder
);
1045 fs_dialog
.SelectMultiple
= false;
1047 ResponseType response
= (ResponseType
) fs_dialog
.Run ();
1049 if (response
== ResponseType
.Ok
)
1050 value_entry
.Text
= fs_dialog
.Filename
;
1052 fs_dialog
.Destroy ();
1054 case ExcludeType
.MailFolder
:
1055 MailFolderDialog mf_dialog
= new MailFolderDialog (add_exclude_dialog
);
1056 mf_dialog
.ExcludeItemAddedEvent
+= new ExcludeItemAddedHandler (OnExcludeItemAdded
);
1061 private void OnRadioGroupChanged (object o
, EventArgs args
)
1063 value_entry
.Text
= "";
1066 case ExcludeType
.Path
:
1067 browse_button
.Sensitive
= true;
1068 value_name_label
.TextWithMnemonic
= Catalog
.GetString ("P_ath:");
1069 value_entry
.IsEditable
= true;
1071 case ExcludeType
.MailFolder
:
1072 browse_button
.Sensitive
= true;
1073 value_name_label
.TextWithMnemonic
= Catalog
.GetString ("M_ail folder:");
1074 value_entry
.IsEditable
= false;
1076 case ExcludeType
.Pattern
:
1077 browse_button
.Sensitive
= false;
1078 value_name_label
.TextWithMnemonic
= Catalog
.GetString ("P_attern:");
1079 value_entry
.IsEditable
= true;
1084 private void OnExcludeItemAdded (ExcludeItem item
)
1087 value_entry
.Text
= MailFolder
.GetNameForPath (item
.Value
);
1090 private void OnDialogResponse (object o
, ResponseArgs args
)
1092 if (((ResponseType
)args
.ResponseId
) == ResponseType
.Ok
) {
1093 ExcludeItem exclude_item
= new ExcludeItem (Type
, Value
);
1096 case ExcludeType
.Path
:
1097 if (!Directory
.Exists (Value
)) {
1098 HigMessageDialog
.RunHigMessageDialog(add_exclude_dialog
,
1102 Catalog
.GetString ("Error adding path"),
1103 Catalog
.GetString ("The specified path could not be found and therefore it could not be added to the list of resources excluded for indexing."));
1109 if (ExcludeItemAddedEvent
!= null)
1110 ExcludeItemAddedEvent (exclude_item
);
1112 add_exclude_dialog
.Destroy ();
1115 public void Destroy ()
1117 add_exclude_dialog
.Destroy ();
1122 ////////////////////////////////////////////////////////////////
1125 class DisplayView
: TreeView
1127 public DisplayView ()
1129 ListStore store
= new ListStore (typeof(bool),typeof(string));
1133 AppendColumn (Catalog
.GetString ("Show"), new CellRendererToggle (), "active", 0);
1134 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 1);