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
;
41 public class SettingsDialog
43 public static void Main (string[] args
)
45 SettingsDialog settings
= new SettingsDialog ();
49 ////////////////////////////////////////////////////////////////
52 [Widget
] CheckButton autostart_toggle
;
54 [Widget
] CheckButton press_ctrl_toggle
;
55 [Widget
] CheckButton press_alt_toggle
;
56 [Widget
] Entry show_search_window_entry
;
58 [Widget
] CheckButton index_home_toggle
;
59 [Widget
] Button remove_include_button
;
60 [Widget
] Button remove_exclude_button
;
62 [Widget
] Button display_up_button
;
63 [Widget
] Button display_down_button
;
65 [Widget
] Gtk
.Window settings_dialog
;
67 [Widget
] ScrolledWindow display_sw
;
69 [Widget
] ScrolledWindow include_sw
;
70 [Widget
] ScrolledWindow exclude_sw
;
73 DisplayView display_view
;
76 IncludeView include_view
;
77 ExcludeView exclude_view
;
79 ////////////////////////////////////////////////////////////////
82 [Widget
] VBox networking_box
;
83 [Widget
] CheckButton allow_global_access_toggle
;
84 [Widget
] Button remove_publicfolder_button
;
85 [Widget
] Button remove_netbeagle_button
;
87 [Widget
] ScrolledWindow publicfolder_sw
;
88 [Widget
] ScrolledWindow netbeagle_sw
;
90 [Widget
] Dialog netbeagle_entry_dialog
;
91 [Widget
] Entry netbeagle_textentry
;
93 PublicfolderView publicfolder_view
;
94 NetbeagleView netbeagle_view
;
96 ////////////////////////////////////////////////////////////////
99 public SettingsDialog ()
103 Catalog
.Init ("beagle", ExternalStringsHack
.LocaleDir
);
105 Glade
.XML glade
= new Glade
.XML (null, "settings.glade", "settings_dialog", "beagle");
106 glade
.Autoconnect (this);
109 display_view
= new DisplayView ();
110 display_view
.Selection
.Changed
+= new EventHandler (OnDisplaySelected
);
111 display_view
.Show ();
112 // The display sorting stuff is something i have been testing locally, Best CVS wont use it
113 display_sw
.Child
= display_view
;
115 include_view
= new IncludeView ();
116 include_view
.Selection
.Changed
+= new EventHandler (OnIncludeSelected
);
117 include_view
.Show ();
118 include_sw
.Child
= include_view
;
120 exclude_view
= new ExcludeView ();
121 exclude_view
.Selection
.Changed
+= new EventHandler (OnExcludeSelected
);
122 exclude_view
.Show ();
123 exclude_sw
.Child
= exclude_view
;
125 #if ENABLE_WEBSERVICES
126 networking_box
.Visible
= true;
128 publicfolder_view
= new PublicfolderView ();
129 publicfolder_view
.Selection
.Changed
+= new EventHandler (OnPublicfolderSelected
);
130 publicfolder_view
.Show ();
131 publicfolder_sw
.Child
= publicfolder_view
;
133 netbeagle_view
= new NetbeagleView ();
134 netbeagle_view
.Selection
.Changed
+= new EventHandler (OnNetbeagleSelected
);
135 netbeagle_view
.Show ();
136 netbeagle_sw
.Child
= netbeagle_view
;
138 LoadConfiguration ();
140 Conf
.Subscribe (typeof (Conf
.IndexingConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
141 Conf
.Subscribe (typeof (Conf
.SearchingConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
143 #if ENABLE_WEBSERVICES
144 Conf
.Subscribe (typeof (Conf
.NetworkingConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
145 Conf
.Subscribe (typeof (Conf
.WebServicesConfig
), new Conf
.ConfigUpdateHandler (OnConfigurationChanged
));
154 ////////////////////////////////////////////////////////////////
157 private void LoadConfiguration ()
159 autostart_toggle
.Active
= Conf
.Searching
.Autostart
;
161 KeyBinding show_binding
= Conf
.Searching
.ShowSearchWindowBinding
;
162 press_ctrl_toggle
.Active
= show_binding
.Ctrl
;
163 press_alt_toggle
.Active
= show_binding
.Alt
;
164 show_search_window_entry
.Text
= show_binding
.Key
;
166 if (Conf
.Indexing
.IndexHomeDir
)
167 index_home_toggle
.Active
= true;
169 foreach (string include
in Conf
.Indexing
.Roots
)
170 include_view
.AddPath (include
);
172 foreach (ExcludeItem exclude_item
in Conf
.Indexing
.Excludes
)
173 exclude_view
.AddItem (exclude_item
);
175 #if ENABLE_WEBSERVICES
176 foreach (string netbeagle
in Conf
.Networking
.NetBeagleNodes
)
177 netbeagle_view
.AddNode (netbeagle
);
179 if (Conf
.WebServices
.AllowGlobalAccess
)
180 allow_global_access_toggle
.Active
= true;
182 foreach (string publicfolder
in Conf
.WebServices
.PublicFolders
)
183 publicfolder_view
.AddPath (publicfolder
);
187 private void SaveConfiguration ()
189 Conf
.Searching
.Autostart
= autostart_toggle
.Active
;
191 Conf
.Searching
.ShowSearchWindowBinding
= new KeyBinding (show_search_window_entry
.Text
,
192 press_ctrl_toggle
.Active
,
193 press_alt_toggle
.Active
);
195 Conf
.Indexing
.IndexHomeDir
= index_home_toggle
.Active
;
197 Conf
.Indexing
.Roots
= include_view
.Includes
;
198 Conf
.Indexing
.Excludes
= exclude_view
.Excludes
;
200 #if ENABLE_WEBSERVICES
201 Conf
.Networking
.NetBeagleNodes
= netbeagle_view
.Netbeagles
;
202 Conf
.WebServices
.AllowGlobalAccess
= allow_global_access_toggle
.Active
;
203 Conf
.WebServices
.PublicFolders
= publicfolder_view
.Publicfolders
;
208 private void OnConfigurationChanged (Conf
.Section section
)
210 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
212 MessageType
.Question
,
214 Catalog
.GetString ("Reload configuration"),
215 Catalog
.GetString ("The configuration file has been modified by another application. " +
216 "Do you wish to discard the currently displayed values and reload configuration from disk?"));
218 ResponseType response
= (ResponseType
) dialog
.Run ();
220 if (response
== ResponseType
.Yes
)
221 LoadConfiguration ();
226 ////////////////////////////////////////////////////////////////
229 private void OnDialogResponse (object o
, ResponseArgs args
)
231 switch (args
.ResponseId
) {
232 case ResponseType
.Help
:
233 Gnome
.Url
.Show ("http://www.beagle-project.org/Configuration_Help");
235 case ResponseType
.Ok
:
236 SaveConfiguration ();
245 private void OnDisplaySelected (object o
, EventArgs args
)
247 display_up_button
.Sensitive
= true;
248 display_down_button
.Sensitive
= true;
251 private void OnAddIncludeClicked (object o
, EventArgs args
)
253 CompatFileChooserDialog fs_dialog
= new CompatFileChooserDialog (Catalog
.GetString ("Select Path"),
255 CompatFileChooserDialog
.Action
.SelectFolder
);
256 fs_dialog
.SelectMultiple
= false;
258 ResponseType fs_response
= (ResponseType
) fs_dialog
.Run ();
259 string new_include
= fs_dialog
.Filename
;
260 fs_dialog
.Destroy ();
262 if (fs_response
== ResponseType
.Ok
) {
263 string error_message
= "";
264 bool throw_error
= false;
265 ArrayList obsolete_includes
= new ArrayList ();
267 // Check and see if the current data collides with the new path in any way
268 // FIXME: Do this with System.IO.Path or something
269 foreach (string old_include
in include_view
.Includes
) {
270 if (new_include
== old_include
) {
272 error_message
= Catalog
.GetString ("The selected path is already selected for indexing and wasn't added.");
273 } else if (new_include
.StartsWith (old_include
)) {
275 error_message
= Catalog
.GetString ("The selected path wasn't added. The list contains items that supercedes it and the data is already being indexed.");
276 } else if (old_include
.StartsWith (new_include
)) {
277 obsolete_includes
.Add (old_include
);
282 HigMessageDialog
.RunHigMessageDialog (settings_dialog
,
286 Catalog
.GetString ("Path not added"),
289 // Confirm the removal of obsolete includes
290 if (obsolete_includes
.Count
!= 0) {
291 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
293 MessageType
.Question
,
295 Catalog
.GetString ("Remove obsolete paths"),
296 Catalog
.GetString ("Adding this path will obsolete some of the existing include paths. " +
297 "This will result in the removal of the old obsolete paths. Do you still wish to add it?"));
299 ResponseType confirm_response
= (ResponseType
) dialog
.Run ();
301 if (confirm_response
!= ResponseType
.Yes
)
304 foreach (string obsolete_include
in obsolete_includes
)
305 include_view
.RemovePath (obsolete_include
);
310 include_view
.AddPath (new_include
);
315 private void OnRemoveIncludeClicked (object o
, EventArgs args
)
318 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
320 MessageType
.Question
,
322 Catalog
.GetString ("Remove path"),
323 Catalog
.GetString ("Are you sure you wish to remove this path from the list of directories to be included for indexing?"));
324 ResponseType response
= (ResponseType
) dialog
.Run ();
327 if (response
!= ResponseType
.Yes
)
330 include_view
.RemoveSelectedPath ();
331 remove_include_button
.Sensitive
= false;
334 private void OnIncludeSelected (object o
, EventArgs args
)
336 remove_include_button
.Sensitive
= true;
339 private void OnAddExcludeClicked (object o
, EventArgs args
)
341 AddExcludeDialog dialog
= new AddExcludeDialog (settings_dialog
);
342 dialog
.ExcludeItemAddedEvent
+= new ExcludeItemAddedHandler (OnExcludeItemAdded
);
346 private void OnRemoveExcludeClicked (object o
, EventArgs args
)
348 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
350 MessageType
.Question
,
352 Catalog
.GetString ("Remove item"),
353 Catalog
.GetString ("Are you sure you wish to remove this item from the list of data to be excluded from indexing?"));
355 ResponseType response
= (ResponseType
) dialog
.Run ();
358 if (response
!= ResponseType
.Yes
)
361 exclude_view
.RemoveSelectedItem ();
362 remove_exclude_button
.Sensitive
= false;
365 private void OnExcludeSelected (object o
, EventArgs args
)
367 remove_exclude_button
.Sensitive
= true;
370 private void OnExcludeItemAdded (ExcludeItem exclude_item
)
372 exclude_view
.AddItem (exclude_item
);
375 //Netbeagle: Add, Remove operations
376 private void OnAddNetbeagleClicked (object o
, EventArgs args
)
378 Glade
.XML glade
= new Glade
.XML (null, "settings.glade", "netbeagle_entry_dialog", "beagle");
379 glade
.Autoconnect (this);
380 ResponseType nbed_response
= (ResponseType
) netbeagle_entry_dialog
.Run ();
382 string new_node
= netbeagle_textentry
.Text
.Trim();
384 if ((new_node
.Length
> 1) && (((string[])new_node
.Split(':')).Length
< 2))
387 netbeagle_entry_dialog
.Destroy ();
389 if (nbed_response
== ResponseType
.Ok
) {
390 string error_message
= "";
391 bool throw_error
= false;
393 if (new_node
.Length
< 2)
396 error_message
= Catalog
.GetString ("Invalid host entry");
399 // Check if the new entry matches an existing netbeagle entry
400 foreach (string old_node
in netbeagle_view
.Netbeagles
) {
401 if (new_node
== old_node
) {
403 error_message
= Catalog
.GetString ("Remote host already present in the list.");
408 HigMessageDialog
.RunHigMessageDialog (settings_dialog
,
412 Catalog
.GetString ("Netbeagle Node not added"),
416 netbeagle_view
.AddNode (new_node
);
421 private void OnRemoveNetbeagleClicked (object o
, EventArgs args
)
424 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
426 MessageType
.Question
,
428 Catalog
.GetString ("Remove host"),
429 Catalog
.GetString ("Are you sure you wish to remove this host from the list?"));
431 ResponseType response
= (ResponseType
) dialog
.Run ();
434 if (response
!= ResponseType
.Yes
)
437 netbeagle_view
.RemoveSelectedNode ();
439 remove_netbeagle_button
.Sensitive
= false;
442 private void OnNetbeagleSelected (object o
, EventArgs args
)
444 remove_netbeagle_button
.Sensitive
= true;
447 //Publicfolders: Add, Remove operations
448 private void OnAddPublicfolderClicked (object o
, EventArgs args
)
450 CompatFileChooserDialog fs_dialog
= new CompatFileChooserDialog (Catalog
.GetString ("Select path"),
452 CompatFileChooserDialog
.Action
.SelectFolder
);
453 fs_dialog
.SelectMultiple
= false;
455 ResponseType fs_response
= (ResponseType
) fs_dialog
.Run ();
456 string new_pf
= fs_dialog
.Filename
;
457 fs_dialog
.Destroy ();
459 if (fs_response
== ResponseType
.Ok
) {
461 string error_message
= "";
462 bool throw_error
= false;
464 // Check and see if the current data collides with the new path in any way
465 // FIXME: Do this with System.IO.Path or something
466 foreach (string old_pf
in publicfolder_view
.Publicfolders
) {
467 if (new_pf
== old_pf
) {
469 error_message
= Catalog
.GetString ("The selected path is already configured for external access.");
474 HigMessageDialog
.RunHigMessageDialog (settings_dialog
,
478 Catalog
.GetString ("Path not added"),
482 publicfolder_view
.AddPath (new_pf
);
486 private void OnRemovePublicfolderClicked (object o
, EventArgs args
)
489 HigMessageDialog dialog
= new HigMessageDialog (settings_dialog
,
491 MessageType
.Question
,
493 Catalog
.GetString ("Remove public path"),
494 Catalog
.GetString ("Are you sure you wish to remove this entry from the list of public paths?"));
496 ResponseType response
= (ResponseType
) dialog
.Run ();
499 if (response
!= ResponseType
.Yes
)
502 publicfolder_view
.RemoveSelectedPath ();
503 remove_publicfolder_button
.Sensitive
= false;
506 private void OnPublicfolderSelected (object o
, EventArgs args
)
508 remove_publicfolder_button
.Sensitive
= true;
511 ////////////////////////////////////////////////////////////////
514 class IncludeView
: TreeView
516 private ListStore store
;
518 private ArrayList includes
= new ArrayList ();
520 public ArrayList Includes
{
521 get { return includes; }
524 private enum TargetType
{
528 private static TargetEntry
[] target_table
= new TargetEntry
[] {
529 new TargetEntry ("STRING", 0, (uint) TargetType
.Uri
),
530 new TargetEntry ("text/plain", 0, (uint) TargetType
.Uri
),
533 public IncludeView ()
535 store
= new ListStore (typeof (string));
539 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 0);
541 // Enable drag and drop folders from nautilus
542 Gtk
.Drag
.DestSet (this, DestDefaults
.All
, target_table
, DragAction
.Copy
| DragAction
.Move
);
543 DragDataReceived
+= new DragDataReceivedHandler (HandleData
);
546 public void AddPath (string path
)
549 store
.AppendValues (path
);
552 public void RemovePath (string path
)
555 found_iter
= TreeIter
.Zero
;
557 this.Model
.Foreach (new TreeModelForeachFunc (ForeachFindPath
));
559 store
.Remove (ref found_iter
);
560 includes
.Remove (path
);
563 private string find_path
;
564 private TreeIter found_iter
;
566 private bool ForeachFindPath (TreeModel model
, TreePath path
, TreeIter iter
)
568 if ((string) model
.GetValue (iter
, 0) == find_path
) {
576 public void RemoveSelectedPath ()
581 if (!this.Selection
.GetSelected(out model
, out iter
)) {
584 string path
= (string)model
.GetValue(iter
, 0);
586 store
.Remove (ref iter
);
587 includes
.Remove (path
);
590 // Handle drag and drop data. Enables users to drag a folder that he wishes
591 // to add for indexing from Nautilus.
592 // FIXME: Pass checks as in OnAddIncludeButtonClicked
593 private void HandleData (object o
, DragDataReceivedArgs args
) {
595 if (args
.SelectionData
.Length
>=0 && args
.SelectionData
.Format
== 8) {
596 uri
= new Uri (args
.SelectionData
.Text
.Trim ());
597 AddPath (uri
.LocalPath
);
598 Gtk
.Drag
.Finish (args
.Context
, true, false, args
.Time
);
600 Gtk
.Drag
.Finish (args
.Context
, false, false, args
.Time
);
604 ////////////////////////////////////////////////////////////////
607 class ExcludeView
: TreeView
609 ArrayList excludes
= new ArrayList ();
611 public ArrayList Excludes
{
612 get { return excludes; }
615 public ExcludeView ()
617 this.Model
= new ListStore (typeof (ExcludeItem
));
619 CellRendererText renderer_text
= new CellRendererText ();
621 TreeViewColumn type_column
= new TreeViewColumn ();
622 type_column
.Title
= Catalog
.GetString ("Type");
623 type_column
.PackStart (renderer_text
, false);
624 type_column
.SetCellDataFunc (renderer_text
, new TreeCellDataFunc (TypeCellDataFunc
));
625 AppendColumn (type_column
);
627 TreeViewColumn name_column
= new TreeViewColumn ();
628 name_column
.Title
= Catalog
.GetString ("Name");
629 name_column
.PackStart (renderer_text
, false);
630 name_column
.SetCellDataFunc (renderer_text
, new TreeCellDataFunc (NameCellDataFunc
));
631 AppendColumn (name_column
);
634 public void RemoveSelectedItem ()
639 if (!this.Selection
.GetSelected(out model
, out iter
)) {
642 ExcludeItem exclude_item
= (ExcludeItem
) model
.GetValue(iter
, 0);
644 ((ListStore
)this.Model
).Remove (ref iter
);
645 excludes
.Remove (exclude_item
);
648 public void AddItem (ExcludeItem exclude_item
)
650 excludes
.Add (exclude_item
);
651 ((ListStore
)this.Model
).AppendValues (exclude_item
);
654 private void NameCellDataFunc (TreeViewColumn column
,
655 CellRenderer renderer
,
659 ExcludeItem exclude_item
= (ExcludeItem
) model
.GetValue (iter
, 0);
660 if (exclude_item
.Type
== ExcludeType
.MailFolder
)
661 ((CellRendererText
)renderer
).Text
= MailFolder
.GetNameForPath (exclude_item
.Value
);
663 ((CellRendererText
)renderer
).Text
= exclude_item
.Value
;
666 private void TypeCellDataFunc (TreeViewColumn column
,
667 CellRenderer renderer
,
671 ExcludeItem exclude_item
= (ExcludeItem
) model
.GetValue (iter
, 0);
673 switch (exclude_item
.Type
) {
674 case ExcludeType
.Path
:
675 ((CellRendererText
)renderer
).Text
= Catalog
.GetString ("Path");
677 case ExcludeType
.Pattern
:
678 ((CellRendererText
)renderer
).Text
= Catalog
.GetString ("Pattern");
680 case ExcludeType
.MailFolder
:
681 ((CellRendererText
)renderer
).Text
= Catalog
.GetString ("Mail Folder");
687 ////////////////////////////////////////////////////////////////
690 class NetbeagleView
: TreeView
692 private ListStore store
;
694 private ArrayList netBeagleList
= new ArrayList ();
696 public ArrayList Netbeagles
{
697 get { return netBeagleList; }
700 public NetbeagleView ()
702 store
= new ListStore (typeof (string));
706 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 0);
709 public void AddNode (string node
)
711 netBeagleList
.Add (node
);
712 store
.AppendValues (node
);
715 public void RemoveNode (string node
)
718 found_iter
= TreeIter
.Zero
;
720 this.Model
.Foreach (new TreeModelForeachFunc (ForeachFindNode
));
722 store
.Remove (ref found_iter
);
723 netBeagleList
.Remove (node
);
726 private string find_node
;
727 private TreeIter found_iter
;
729 private bool ForeachFindNode (TreeModel model
, TreePath path
, TreeIter iter
)
731 if ((string) model
.GetValue (iter
, 0) == find_node
) {
739 public void RemoveSelectedNode ()
744 if (!this.Selection
.GetSelected(out model
, out iter
)) {
747 string node
= (string)model
.GetValue(iter
, 0);
749 store
.Remove (ref iter
);
750 netBeagleList
.Remove (node
);
754 ////////////////////////////////////////////////////////////////
757 class PublicfolderView
: TreeView
759 private ListStore store
;
761 private ArrayList publicFolders
= new ArrayList ();
763 public ArrayList Publicfolders
{
764 get { return publicFolders; }
767 private enum TargetType
{
771 private static TargetEntry
[] target_table
= new TargetEntry
[] {
772 new TargetEntry ("STRING", 0, (uint) TargetType
.Uri
),
773 new TargetEntry ("text/plain", 0, (uint) TargetType
.Uri
),
776 public PublicfolderView ()
778 store
= new ListStore (typeof (string));
782 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 0);
784 // Enable drag and drop folders from nautilus
785 Gtk
.Drag
.DestSet (this, DestDefaults
.All
, target_table
, DragAction
.Copy
| DragAction
.Move
);
786 DragDataReceived
+= new DragDataReceivedHandler (HandleData
);
789 public void AddPath (string path
)
791 publicFolders
.Add (path
);
792 store
.AppendValues (path
);
795 public void RemovePath (string path
)
798 found_iter
= TreeIter
.Zero
;
800 this.Model
.Foreach (new TreeModelForeachFunc (ForeachFindPath
));
802 store
.Remove (ref found_iter
);
803 publicFolders
.Remove (path
);
806 private string find_path
;
807 private TreeIter found_iter
;
809 private bool ForeachFindPath (TreeModel model
, TreePath path
, TreeIter iter
)
811 if ((string) model
.GetValue (iter
, 0) == find_path
) {
819 public void RemoveSelectedPath ()
824 if (!this.Selection
.GetSelected(out model
, out iter
)) {
827 string path
= (string)model
.GetValue(iter
, 0);
829 store
.Remove (ref iter
);
830 publicFolders
.Remove (path
);
833 // Handle drag and drop data. Enables users to drag a folder that he wishes
834 // to add for indexing from Nautilus.
835 // FIXME: Pass checks as in OnAddIncludeButtonClicked
836 private void HandleData (object o
, DragDataReceivedArgs args
) {
838 if (args
.SelectionData
.Length
>=0 && args
.SelectionData
.Format
== 8) {
839 uri
= new Uri (args
.SelectionData
.Text
.Trim ());
840 AddPath (uri
.LocalPath
);
841 Gtk
.Drag
.Finish (args
.Context
, true, false, args
.Time
);
843 Gtk
.Drag
.Finish (args
.Context
, false, false, args
.Time
);
847 ////////////////////////////////////////////////////////////////
848 // Mail folder dialog
850 class MailFolderDialog
853 FolderView folder_view
;
855 [Widget
] Dialog mail_folder_dialog
;
856 [Widget
] ScrolledWindow folder_sw
;
858 public event ExcludeItemAddedHandler ExcludeItemAddedEvent
;
860 public MailFolderDialog (Gtk
.Window parent
)
862 this.parent
= parent
;
864 Glade
.XML glade
= new Glade
.XML (null, "settings.glade", "mail_folder_dialog", "beagle");
865 glade
.Autoconnect (this);
867 folder_view
= new FolderView ();
869 folder_sw
.Child
= folder_view
;
872 private void OnDialogResponse (object o
, ResponseArgs args
)
874 if (args
.ResponseId
== ResponseType
.Cancel
) {
875 mail_folder_dialog
.Destroy ();
879 ExcludeItem exclude_item
;
880 object obj
= folder_view
.GetCurrentItem ();
882 if (obj
is MailAccount
) {
884 } else if (obj
is MailFolder
) {
885 MailFolder folder
= (MailFolder
) obj
;
886 exclude_item
= new ExcludeItem (ExcludeType
.MailFolder
, folder
.Path
);
888 if (ExcludeItemAddedEvent
!= null)
889 ExcludeItemAddedEvent (exclude_item
);
891 mail_folder_dialog
.Destroy ();
895 class FolderView
: TreeView
898 Gdk
.Pixbuf folder_icon
;
902 store
= new TreeStore (typeof (MailFolder
));
905 folder_icon
= this.RenderIcon (Stock
.Open
, IconSize
.Menu
, "");
907 HeadersVisible
= false;
909 TreeViewColumn column
= new TreeViewColumn ();
910 CellRendererPixbuf renderer_icon
= new CellRendererPixbuf ();
911 column
.PackStart (renderer_icon
, false);
912 column
.SetCellDataFunc (renderer_icon
, new TreeCellDataFunc (IconCellDataFunc
));
914 CellRendererText renderer_text
= new CellRendererText ();
915 column
.PackStart (renderer_text
, false);
916 column
.SetCellDataFunc (renderer_text
, new TreeCellDataFunc (NameCellDataFunc
));
917 AppendColumn (column
);
919 foreach (MailAccount account
in Beagle
.Util
.Evolution
.Accounts
) {
920 TreeIter iter
= store
.AppendValues (account
);
922 foreach (MailFolder folder
in account
.Children
) {
928 private void Add (TreeIter parent
, MailFolder folder
)
930 TreeIter current
= store
.AppendValues (parent
, folder
);
932 foreach (MailFolder child
in folder
.Children
)
933 Add (current
, child
);
936 private void IconCellDataFunc (TreeViewColumn column
,
937 CellRenderer renderer
,
941 object obj
= model
.GetValue (iter
, 0);
942 ((CellRendererPixbuf
)renderer
).Pixbuf
= (obj
is MailAccount
) ? null : folder_icon
;
945 private void NameCellDataFunc (TreeViewColumn column
,
946 CellRenderer renderer
,
950 object obj
= model
.GetValue (iter
, 0);
952 if (obj
is MailAccount
) {
953 MailAccount account
= obj
as MailAccount
;
954 ((CellRendererText
)renderer
).Markup
= String
.Format ("<b>{0}</b>",account
.Name
);
956 MailFolder folder
= obj
as MailFolder
;
957 ((CellRendererText
)renderer
).Text
= folder
.Name
;
961 public MailFolder
GetCurrentItem ()
966 if (!this.Selection
.GetSelected (out model
, out iter
)) {
970 return (MailFolder
) model
.GetValue (iter
, 0);
975 ////////////////////////////////////////////////////////////////
978 private delegate void ExcludeItemAddedHandler (ExcludeItem item
);
980 class AddExcludeDialog
984 [Widget
] Dialog add_exclude_dialog
;
985 [Widget
] Entry value_entry
;
986 [Widget
] Label value_name_label
;
987 [Widget
] Button browse_button
;
989 [Widget
] RadioButton type_path_radio
;
990 [Widget
] RadioButton type_pattern_radio
;
991 [Widget
] RadioButton type_mailfolder_radio
;
993 public event ExcludeItemAddedHandler ExcludeItemAddedEvent
;
995 private string value;
997 public string Value
{
999 if (Type
== ExcludeType
.MailFolder
)
1002 return value_entry
.Text
;
1006 public ExcludeType Type
{
1008 if (type_path_radio
.Active
)
1009 return ExcludeType
.Path
;
1010 else if (type_pattern_radio
.Active
)
1011 return ExcludeType
.Pattern
;
1013 return ExcludeType
.MailFolder
;
1017 public AddExcludeDialog (Gtk
.Window parent
)
1019 this.parent
= parent
;
1021 Glade
.XML glade
= new Glade
.XML (null, "settings.glade", "add_exclude_dialog", "beagle");
1022 glade
.Autoconnect (this);
1025 private void OnBrowseButtonClicked (object o
, EventArgs args
)
1028 case ExcludeType
.Path
:
1029 CompatFileChooserDialog fs_dialog
= new CompatFileChooserDialog (Catalog
.GetString ("Select Folder"),
1031 CompatFileChooserDialog
.Action
.SelectFolder
);
1032 fs_dialog
.SelectMultiple
= false;
1034 ResponseType response
= (ResponseType
) fs_dialog
.Run ();
1036 if (response
== ResponseType
.Ok
)
1037 value_entry
.Text
= fs_dialog
.Filename
;
1039 fs_dialog
.Destroy ();
1041 case ExcludeType
.MailFolder
:
1042 MailFolderDialog mf_dialog
= new MailFolderDialog (add_exclude_dialog
);
1043 mf_dialog
.ExcludeItemAddedEvent
+= new ExcludeItemAddedHandler (OnExcludeItemAdded
);
1048 private void OnRadioGroupChanged (object o
, EventArgs args
)
1050 value_entry
.Text
= "";
1053 case ExcludeType
.Path
:
1054 browse_button
.Sensitive
= true;
1055 value_name_label
.Text
= Catalog
.GetString ("Path");
1056 value_entry
.IsEditable
= true;
1058 case ExcludeType
.MailFolder
:
1059 browse_button
.Sensitive
= true;
1060 value_name_label
.Text
= Catalog
.GetString ("Mail Folder");
1061 value_entry
.IsEditable
= false;
1063 case ExcludeType
.Pattern
:
1064 browse_button
.Sensitive
= false;
1065 value_name_label
.Text
= Catalog
.GetString ("Pattern");
1066 value_entry
.IsEditable
= true;
1071 private void OnExcludeItemAdded (ExcludeItem item
)
1074 value_entry
.Text
= MailFolder
.GetNameForPath (item
.Value
);
1077 private void OnDialogResponse (object o
, ResponseArgs args
)
1079 if (((ResponseType
)args
.ResponseId
) == ResponseType
.Ok
) {
1080 ExcludeItem exclude_item
= new ExcludeItem (Type
, Value
);
1083 case ExcludeType
.Path
:
1084 if (!Directory
.Exists (Value
)) {
1085 HigMessageDialog
.RunHigMessageDialog(add_exclude_dialog
,
1089 Catalog
.GetString ("Error adding path"),
1090 Catalog
.GetString ("The specified path could not be found and therefore it could not be added to the list of resources excluded for indexing."));
1096 if (ExcludeItemAddedEvent
!= null)
1097 ExcludeItemAddedEvent (exclude_item
);
1099 add_exclude_dialog
.Destroy ();
1102 public void Destroy ()
1104 add_exclude_dialog
.Destroy ();
1109 ////////////////////////////////////////////////////////////////
1112 class DisplayView
: TreeView
1114 public DisplayView ()
1116 ListStore store
= new ListStore (typeof(bool),typeof(string));
1120 AppendColumn (Catalog
.GetString ("Show"), new CellRendererToggle (), "active", 0);
1121 AppendColumn (Catalog
.GetString ("Name"), new CellRendererText (), "text", 1);