1 /*****************************************************************************
2 * preferences.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: preferences.cpp,v 1.14 2003/05/12 21:55:01 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
34 #ifdef WIN32 /* mingw32 hack */
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
42 #include <wx/wxprec.h>
44 #include <wx/window.h>
45 #include <wx/notebook.h>
46 #include <wx/textctrl.h>
47 #include <wx/combobox.h>
48 #include <wx/spinctrl.h>
49 #include <wx/statline.h>
50 #include <wx/treectrl.h>
51 #include <wx/clntdata.h>
52 #include <wx/dynarray.h>
56 #if defined MODULE_NAME_IS_skins
57 # include "../skins/src/skin_common.h"
60 #include "wxwindows.h"
63 # define wxRB_SINGLE 0
66 /*****************************************************************************
67 * Classes declarations.
68 *****************************************************************************/
69 class PrefsTreeCtrl : public wxTreeCtrl
74 PrefsTreeCtrl( wxWindow *parent, intf_thread_t *_p_intf,
75 PrefsDialog *p_prefs_dialog, wxBoxSizer *_p_sizer );
76 virtual ~PrefsTreeCtrl();
82 /* Event handlers (these functions should _not_ be virtual) */
83 void OnSelectTreeItem( wxTreeEvent& event );
87 intf_thread_t *p_intf;
88 PrefsDialog *p_prefs_dialog;
92 wxTreeItemId root_item;
93 wxTreeItemId plugins_item;
98 ConfigData( wxPanel *_panel, int _i_conf_type,
99 vlc_bool_t _b_advanced, char *psz_name )
100 { panel = _panel; b_advanced = _b_advanced; b_config_list = VLC_FALSE;
101 i_config_type = _i_conf_type; option_name = wxU(psz_name); }
103 vlc_bool_t b_advanced;
105 vlc_bool_t b_config_list;
109 wxComboBox *combobox;
110 wxRadioButton *radio;
111 wxSpinCtrl *spinctrl;
112 wxCheckBox *checkbox;
113 wxTextCtrl *textctrl;
118 wxString option_name;
121 WX_DEFINE_ARRAY(ConfigData *, ArrayOfConfigData);
123 class PrefsPanel : public wxPanel
128 PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
129 PrefsDialog *_p_prefs_dialog, int i_object_id, char * );
130 virtual ~PrefsPanel() {}
135 void OnAdvanced( wxCommandEvent& WXUNUSED(event) );
136 DECLARE_EVENT_TABLE()
138 intf_thread_t *p_intf;
139 PrefsDialog *p_prefs_dialog;
141 vlc_bool_t b_advanced;
143 wxBoxSizer *config_sizer;
144 wxScrolledWindow *config_window;
146 ArrayOfConfigData config_array;
149 class ConfigTreeData : public wxTreeItemData
153 ConfigTreeData() { panel = NULL; psz_section = NULL; }
154 virtual ~ConfigTreeData() { if( panel ) delete panel; }
162 class ConfigEvtHandler : public wxEvtHandler
165 ConfigEvtHandler( intf_thread_t *p_intf, PrefsDialog *p_prefs_dialog );
166 virtual ~ConfigEvtHandler();
168 void ConfigEvtHandler::OnCommandEvent( wxCommandEvent& event );
172 DECLARE_EVENT_TABLE()
174 intf_thread_t *p_intf;
175 PrefsDialog *p_prefs_dialog;
178 /*****************************************************************************
180 *****************************************************************************/
182 /* IDs for the controls and the menu commands */
185 Notebook_Event = wxID_HIGHEST,
191 BEGIN_EVENT_TABLE(PrefsDialog, wxFrame)
193 EVT_BUTTON(wxID_OK, PrefsDialog::OnOk)
194 EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel)
195 EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave)
196 EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll)
198 /* Don't destroy the window when the user closes it */
199 EVT_CLOSE(PrefsDialog::OnCancel)
202 // menu and control ids
205 PrefsTree_Ctrl = wxID_HIGHEST
208 BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
209 EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem)
212 BEGIN_EVENT_TABLE(PrefsPanel, wxPanel)
214 EVT_BUTTON(Advanced_Event, PrefsPanel::OnAdvanced)
218 BEGIN_EVENT_TABLE(ConfigEvtHandler, wxEvtHandler)
219 EVT_BUTTON(-1, ConfigEvtHandler::OnCommandEvent)
220 EVT_TEXT(-1, ConfigEvtHandler::OnCommandEvent)
221 EVT_RADIOBOX(-1, ConfigEvtHandler::OnCommandEvent)
222 EVT_SPINCTRL(-1, ConfigEvtHandler::OnCommandEvent)
225 /*****************************************************************************
227 *****************************************************************************/
228 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, Interface *_p_main_interface)
229 : wxFrame( _p_main_interface, -1, wxU(_("Preferences")), wxDefaultPosition,
230 wxSize(650,450), wxDEFAULT_FRAME_STYLE )
232 /* Initializations */
234 p_main_interface = _p_main_interface;
235 SetIcon( *p_intf->p_sys->p_icon );
237 /* Create a panel to put everything in */
238 wxPanel *panel = new wxPanel( this, -1 );
239 panel->SetAutoLayout( TRUE );
241 /* Create the preferences tree control */
242 wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL );
244 new PrefsTreeCtrl( panel, p_intf, this, controls_sizer );
247 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
249 /* Create the buttons */
250 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
251 ok_button->SetDefault();
252 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
254 wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("Save")) );
255 wxButton *reset_button = new wxButton( panel, ResetAll_Event,
256 wxU(_("Reset All")) );
258 /* Place everything in sizers */
259 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
260 button_sizer->Add( ok_button, 0, wxALL, 5 );
261 button_sizer->Add( cancel_button, 0, wxALL, 5 );
262 button_sizer->Add( save_button, 0, wxALL, 5 );
263 button_sizer->Add( reset_button, 0, wxALL, 5 );
264 button_sizer->Layout();
266 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
267 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
268 panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 );
269 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
270 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
272 panel_sizer->Layout();
273 panel->SetSizer( panel_sizer );
274 main_sizer->Add( panel, 1, wxEXPAND, 0 );
275 main_sizer->Layout();
276 SetSizer( main_sizer );
279 PrefsDialog::~PrefsDialog()
283 /*****************************************************************************
285 *****************************************************************************/
288 /*****************************************************************************
290 *****************************************************************************/
291 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
293 prefs_tree->ApplyChanges();
295 prefs_tree->CleanChanges();
298 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
301 prefs_tree->CleanChanges();
304 void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
306 prefs_tree->ApplyChanges();
307 config_SaveConfigFile( p_intf, NULL );
310 void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
312 wxMessageDialog dlg( this,
313 wxU(_("Beware this will reset your VLC Media Player config file.\n"
314 "Are you sure you want to continue?")),
315 wxU(_("Reset config file")), wxYES_NO|wxNO_DEFAULT|wxCENTRE );
317 if ( dlg.ShowModal() == wxID_YES )
319 /* TODO: need to reset all the controls */
320 config_ResetAll( p_intf );
321 prefs_tree->CleanChanges();
322 config_SaveConfigFile( p_intf, NULL );
326 /*****************************************************************************
327 * PrefsTreeCtrl class definition.
328 *****************************************************************************/
329 PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
330 PrefsDialog *_p_prefs_dialog,
331 wxBoxSizer *_p_sizer )
332 : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxDefaultSize,
333 wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT |
334 wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT |
335 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER )
339 module_config_t *p_item;
342 /* Initializations */
344 p_prefs_dialog = _p_prefs_dialog;
346 p_parent = _p_parent;
348 root_item = AddRoot( wxT("") );
350 /* List the plugins */
351 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
352 if( !p_list ) return;
355 * Build a tree of the main options
357 for( i_index = 0; i_index < p_list->i_count; i_index++ )
359 p_module = (module_t *)p_list->p_values[i_index].p_object;
360 if( !strcmp( p_module->psz_object_name, "main" ) )
363 if( i_index < p_list->i_count )
365 /* We found the main module */
367 /* Enumerate config categories and store a reference so we can
368 * generate their config panel them when it is asked by the user. */
369 p_item = p_module->p_config;
373 switch( p_item->i_type )
375 case CONFIG_HINT_CATEGORY:
376 ConfigTreeData *config_data = new ConfigTreeData;
377 config_data->psz_section = strdup(p_item->psz_text);
378 config_data->i_object_id = p_module->i_object_id;
380 /* Add the category to the tree */
381 AppendItem( root_item, wxU(p_item->psz_text),
382 -1, -1, config_data );
386 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
388 SortChildren( root_item );
393 * Build a tree of all the plugins
395 plugins_item = AppendItem( root_item, wxU(_("Plugins")) );
397 for( i_index = 0; i_index < p_list->i_count; i_index++ )
399 p_module = (module_t *)p_list->p_values[i_index].p_object;
401 /* Exclude the main module */
402 if( !strcmp( p_module->psz_object_name, "main" ) )
405 /* Exclude empty plugins */
406 p_item = p_module->p_config;
407 if( !p_item ) continue;
410 if( p_item->i_type & CONFIG_ITEM )
413 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
414 if( p_item->i_type == CONFIG_HINT_END ) continue;
416 /* Find the capability child item */
417 long cookie; size_t i_child_index;
418 wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);
419 for( i_child_index = 0;
420 i_child_index < GetChildrenCount( plugins_item, FALSE );
423 if( !GetItemText(capability_item).Cmp(
424 wxU(p_module->psz_capability ) ) )
428 capability_item = GetNextChild( plugins_item, cookie );
431 if( i_child_index == GetChildrenCount( plugins_item, FALSE ) &&
432 p_module->psz_capability && *p_module->psz_capability )
434 /* We didn't find it, add it */
435 capability_item = AppendItem( plugins_item,
436 wxU(p_module->psz_capability) );
439 /* Add the plugin to the tree */
440 ConfigTreeData *config_data = new ConfigTreeData;
441 config_data->i_object_id = p_module->i_object_id;
442 AppendItem( capability_item, wxU(p_module->psz_object_name), -1, -1,
446 /* Sort all this mess */
447 long cookie; size_t i_child_index;
448 SortChildren( plugins_item );
449 wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);
450 for( i_child_index = 0;
451 i_child_index < GetChildrenCount( plugins_item, FALSE );
454 capability_item = GetNextChild( plugins_item, cookie );
455 SortChildren( capability_item );
458 /* Clean-up everything */
459 vlc_list_release( p_list );
461 p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );
464 /* Update Tree Ctrl */
465 #ifndef WIN32 /* Workaround a bug in win32 implementation */
466 SelectItem( GetFirstChild( root_item, cookie ) );
470 PrefsTreeCtrl::~PrefsTreeCtrl()
474 void PrefsTreeCtrl::ApplyChanges()
476 long cookie, cookie2;
477 ConfigTreeData *config_data;
479 /* Apply changes to the main module */
480 wxTreeItemId item = GetFirstChild( root_item, cookie );
481 for( size_t i_child_index = 0;
482 i_child_index < GetChildrenCount( root_item, FALSE );
485 config_data = (ConfigTreeData *)GetItemData( item );
486 if( config_data && config_data->panel )
488 config_data->panel->ApplyChanges();
491 item = GetNextChild( root_item, cookie );
494 /* Apply changes to the plugins */
495 item = GetFirstChild( plugins_item, cookie );
496 for( size_t i_child_index = 0;
497 i_child_index < GetChildrenCount( plugins_item, FALSE );
500 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
501 for( size_t i_child_index = 0;
502 i_child_index < GetChildrenCount( item, FALSE );
505 config_data = (ConfigTreeData *)GetItemData( item2 );
506 if( config_data && config_data->panel )
508 config_data->panel->ApplyChanges();
511 item2 = GetNextChild( item, cookie2 );
514 item = GetNextChild( plugins_item, cookie );
518 void PrefsTreeCtrl::CleanChanges()
520 long cookie, cookie2;
521 ConfigTreeData *config_data;
523 /* Clean changes for the main module */
524 wxTreeItemId item = GetFirstChild( root_item, cookie );
525 for( size_t i_child_index = 0;
526 i_child_index < GetChildrenCount( root_item, FALSE );
529 config_data = (ConfigTreeData *)GetItemData( item );
530 if( config_data && config_data->panel )
532 if( item == GetSelection() )
534 config_data->panel->Hide();
535 p_sizer->Remove( config_data->panel );
538 delete config_data->panel;
539 config_data->panel = NULL;
541 if( item == GetSelection() )
546 OnSelectTreeItem( event );
550 item = GetNextChild( root_item, cookie );
553 /* Clean changes for the plugins */
554 item = GetFirstChild( plugins_item, cookie );
555 for( size_t i_child_index = 0;
556 i_child_index < GetChildrenCount( plugins_item, FALSE );
559 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
560 for( size_t i_child_index = 0;
561 i_child_index < GetChildrenCount( item, FALSE );
564 config_data = (ConfigTreeData *)GetItemData( item2 );
566 if( config_data && config_data->panel )
568 if( item2 == GetSelection() )
570 config_data->panel->Hide();
571 p_sizer->Remove( config_data->panel );
574 delete config_data->panel;
575 config_data->panel = NULL;
577 if( item2 == GetSelection() )
580 event.SetItem(item2);
582 OnSelectTreeItem( event );
586 item2 = GetNextChild( item, cookie2 );
589 item = GetNextChild( plugins_item, cookie );
593 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
595 ConfigTreeData *config_data;
597 config_data = (ConfigTreeData *)GetItemData( event.GetOldItem() );
598 if( config_data && config_data->panel )
600 config_data->panel->Hide();
601 p_sizer->Remove( config_data->panel );
604 config_data = (ConfigTreeData *)GetItemData( event.GetItem() );
607 if( !config_data->panel )
609 /* The panel hasn't been created yet. Let's do it. */
611 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
612 config_data->i_object_id,
613 config_data->psz_section );
617 config_data->panel->Show();
620 p_sizer->Add( config_data->panel, 2, wxEXPAND | wxALL, 0 );
625 /*****************************************************************************
626 * PrefsPanel class definition.
627 *****************************************************************************/
628 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
629 PrefsDialog *_p_prefs_dialog,
630 int i_object_id, char *psz_section )
631 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
633 module_config_t *p_item;
640 wxCheckBox *checkbox;
641 wxTextCtrl *textctrl;
645 /* Initializations */
647 p_prefs_dialog =_p_prefs_dialog,
649 b_advanced = VLC_TRUE;
650 SetAutoLayout( TRUE );
652 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
654 /* Get a pointer to the module */
655 module_t *p_module = (module_t *)vlc_object_get( p_intf, i_object_id );
656 if( p_module->i_object_type != VLC_OBJECT_MODULE )
658 /* 0OOoo something went really bad */
662 /* Enumerate config options and add corresponding config boxes */
663 p_item = p_module->p_config;
665 /* Find the category if it has been specified */
666 if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY )
668 while( !p_item->i_type == CONFIG_HINT_CATEGORY ||
669 strcmp( psz_section, p_item->psz_text ) )
671 if( p_item->i_type == CONFIG_HINT_END )
677 /* Add a head title to the panel */
678 wxStaticBox *static_box = new wxStaticBox( this, -1, wxT("") );
679 wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( static_box,
681 label = new wxStaticText( this, -1,
682 wxU(psz_section ? p_item->psz_text :
683 p_module->psz_longname) );
685 box_sizer->Add( label, 1, wxALL, 5 );
686 sizer->Add( box_sizer, 0, wxEXPAND | wxALL, 5 );
688 /* Now put all the config options into a scrolled window */
689 config_sizer = new wxBoxSizer( wxVERTICAL );
690 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
692 config_window->SetAutoLayout( TRUE );
693 config_window->SetScrollRate( 5, 5 );
697 /* If a category has been specified, check we finished the job */
698 if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY &&
699 strcmp( psz_section, p_item->psz_text ) )
702 /* put each config option in a separate panel so we can hide advanced
704 wxPanel *panel = new wxPanel( config_window, -1, wxDefaultPosition,
706 wxBoxSizer *panel_sizer = new wxBoxSizer( wxHORIZONTAL );
707 ConfigData *config_data =
708 new ConfigData( panel, p_item->i_type,
709 p_item->b_advanced, p_item->psz_name );
711 switch( p_item->i_type )
713 case CONFIG_ITEM_MODULE:
714 label = new wxStaticText(panel, -1, wxU(p_item->psz_text));
715 combo = new wxComboBox( panel, -1, wxU(p_item->psz_value),
716 wxDefaultPosition, wxDefaultSize,
717 0, NULL, wxCB_READONLY | wxCB_SORT );
719 /* build a list of available modules */
720 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
721 combo->Append( wxU(_("Default")), (void *)NULL );
722 combo->SetSelection( 0 );
723 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
725 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
727 if( !strcmp( p_parser->psz_capability,
730 combo->Append( wxU(p_parser->psz_longname),
731 p_parser->psz_object_name );
732 if( p_item->psz_value &&
733 !strcmp(p_item->psz_value, p_parser->psz_object_name) )
734 combo->SetValue( wxU(p_parser->psz_longname) );
738 combo->SetToolTip( wxU(p_item->psz_longtext) );
739 config_data->control.combobox = combo;
740 panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
741 panel_sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
744 case CONFIG_ITEM_STRING:
745 case CONFIG_ITEM_FILE:
746 case CONFIG_ITEM_DIRECTORY:
747 label = new wxStaticText(panel, -1, wxU(p_item->psz_text));
748 panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
750 if( !p_item->ppsz_list )
752 textctrl = new wxTextCtrl( panel, -1, wxU(p_item->psz_value),
753 wxDefaultPosition, wxDefaultSize,
755 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
756 config_data->control.textctrl = textctrl;
757 panel_sizer->Add( textctrl, 1, wxALL, 5 );
761 combo = new wxComboBox( panel, -1, wxU(p_item->psz_value),
762 wxDefaultPosition, wxDefaultSize,
763 0, NULL, wxCB_READONLY | wxCB_SORT );
765 /* build a list of available options */
766 for( int i_index = 0; p_item->ppsz_list[i_index]; i_index++ )
768 combo->Append( wxU(p_item->ppsz_list[i_index]) );
771 if( p_item->psz_value )
772 combo->SetValue( wxU(p_item->psz_value) );
773 combo->SetToolTip( wxU(p_item->psz_longtext) );
774 config_data->control.combobox = combo;
775 config_data->b_config_list = VLC_TRUE;
776 panel_sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
779 if( p_item->i_type == CONFIG_ITEM_FILE )
781 button = new wxButton( panel, -1, wxU(_("Browse...")) );
782 panel_sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
783 button->SetClientData((void *)config_data);
787 case CONFIG_ITEM_INTEGER:
788 label = new wxStaticText(panel, -1, wxU(p_item->psz_text));
789 spin = new wxSpinCtrl( panel, -1,
790 wxString::Format(wxT("%d"),p_item->i_value),
791 wxDefaultPosition, wxDefaultSize,
793 0, 16000, p_item->i_value);
794 spin->SetToolTip( wxU(p_item->psz_longtext) );
795 config_data->control.spinctrl = spin;
796 panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
797 panel_sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
799 spin->SetClientData((void *)config_data);
802 case CONFIG_ITEM_FLOAT:
803 label = new wxStaticText(panel, -1, wxU(p_item->psz_text));
804 spin = new wxSpinCtrl( panel, -1,
805 wxString::Format(wxT("%f"),p_item->f_value),
806 wxDefaultPosition, wxDefaultSize,
808 0, 16000, (int)p_item->f_value);
809 spin->SetToolTip( wxU(p_item->psz_longtext) );
810 config_data->control.spinctrl = spin;
811 panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
812 panel_sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
815 case CONFIG_ITEM_BOOL:
816 checkbox = new wxCheckBox( panel, -1, wxU(p_item->psz_text) );
817 if( p_item->i_value ) checkbox->SetValue(TRUE);
818 checkbox->SetToolTip( wxU(p_item->psz_longtext) );
819 config_data->control.checkbox = checkbox;
820 panel_sizer->Add( checkbox, 0, wxALL, 5 );
824 delete panel; panel = NULL;
830 /* Don't add items that were not recognized */
831 if( panel == NULL ) continue;
833 panel_sizer->Layout();
834 panel->SetSizerAndFit( panel_sizer );
836 /* Add the config data to our array so we can keep a trace of it */
837 config_array.Add( config_data );
839 config_sizer->Add( panel, 0, wxEXPAND | wxALL, 2 );
841 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
843 /* Display a nice message if no configuration options are available */
844 if( !config_array.GetCount() )
846 config_sizer->Add( new wxStaticText( config_window, -1,
847 wxU(_("No configuration options available")) ), 1,
848 wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER, 2 );
851 config_sizer->Layout();
852 config_window->SetSizer( config_sizer );
853 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
855 /* Intercept all menu events in our custom event handler */
856 config_window->PushEventHandler(
857 new ConfigEvtHandler( p_intf, p_prefs_dialog ) );
860 wxCommandEvent dummy_event;
861 b_advanced = !config_GetInt( p_intf, "advanced" );
862 OnAdvanced( dummy_event );
864 /* Create advanced button */
865 if( config_array.GetCount() )
867 wxButton *advanced_button = new wxButton( this, Advanced_Event,
868 wxU(_("Advanced...")) );
869 sizer->Add( advanced_button, 0, wxALL, 5 );
876 void PrefsPanel::ApplyChanges()
878 for( size_t i = 0; i < config_array.GetCount(); i++ )
880 ConfigData *config_data = config_array.Item(i);
882 switch( config_data->i_config_type )
884 case CONFIG_ITEM_MODULE:
885 config_PutPsz( p_intf, config_data->option_name.mb_str(), (char *)
886 config_data->control.combobox->GetClientData(
887 config_data->control.combobox->GetSelection() ) );
889 case CONFIG_ITEM_STRING:
890 case CONFIG_ITEM_FILE:
891 case CONFIG_ITEM_DIRECTORY:
892 if( !config_data->b_config_list )
893 config_PutPsz( p_intf, config_data->option_name.mb_str(),
894 config_data->control.textctrl->GetValue().mb_str() );
896 config_PutPsz( p_intf, config_data->option_name.mb_str(),
897 config_data->control.combobox->GetValue().mb_str() );
899 case CONFIG_ITEM_BOOL:
900 config_PutInt( p_intf, config_data->option_name.mb_str(),
901 config_data->control.checkbox->IsChecked() );
903 case CONFIG_ITEM_INTEGER:
904 config_PutInt( p_intf, config_data->option_name.mb_str(),
905 config_data->control.spinctrl->GetValue() );
907 case CONFIG_ITEM_FLOAT:
908 config_PutFloat( p_intf, config_data->option_name.mb_str(),
909 config_data->control.spinctrl->GetValue() );
915 void PrefsPanel::OnAdvanced( wxCommandEvent& WXUNUSED(event) )
917 b_advanced = !b_advanced;
919 for( size_t i = 0; i < config_array.GetCount(); i++ )
921 ConfigData *config_data = config_array.Item(i);
922 if( config_data->b_advanced )
924 config_data->panel->Show( b_advanced );
925 config_sizer->Show( config_data->panel, b_advanced );
929 config_sizer->Layout();
930 config_window->FitInside();
933 /*****************************************************************************
934 * A small helper class which intercepts all events
935 *****************************************************************************/
936 ConfigEvtHandler::ConfigEvtHandler( intf_thread_t *_p_intf,
937 PrefsDialog *_p_prefs_dialog )
939 /* Initializations */
941 p_prefs_dialog = _p_prefs_dialog;
944 ConfigEvtHandler::~ConfigEvtHandler()
948 void ConfigEvtHandler::OnCommandEvent( wxCommandEvent& event )
950 if( !event.GetEventObject() )
956 ConfigData *config_data = (ConfigData *)
957 ((wxEvtHandler *)event.GetEventObject())->GetClientData();
965 if( config_data->i_config_type == CONFIG_ITEM_FILE )
967 wxFileDialog dialog( p_prefs_dialog, wxU(_("Open file")),
968 wxT(""), wxT(""), wxT("*.*"), wxOPEN | wxSAVE );
970 if( dialog.ShowModal() == wxID_OK )
972 config_data->control.textctrl->SetValue( dialog.GetPath() );
976 switch( config_data->i_config_type )
978 case CONFIG_ITEM_MODULE:
980 case CONFIG_ITEM_STRING:
982 case CONFIG_ITEM_FILE:
984 case CONFIG_ITEM_INTEGER:
986 case CONFIG_ITEM_FLOAT:
988 case CONFIG_ITEM_BOOL: