1 /*****************************************************************************
2 * preferences.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
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() */
35 #include <vlc_config_cat.h>
37 #include "wxwindows.h"
38 #include "preferences_widgets.h"
40 #include <wx/combobox.h>
41 #include <wx/statline.h>
42 #include <wx/clntdata.h>
43 #include <wx/dynarray.h>
46 # define wxRB_SINGLE 0
49 #define TYPE_CATEGORY 0
50 #define TYPE_CATSUBCAT 1 /* Category with embedded subcategory */
51 #define TYPE_SUBCATEGORY 2
54 /*****************************************************************************
55 * Classes declarations.
56 *****************************************************************************/
58 class PrefsTreeCtrl : public wxTreeCtrl
63 PrefsTreeCtrl( wxWindow *parent, intf_thread_t *_p_intf,
64 PrefsDialog *p_prefs_dialog, wxBoxSizer *_p_sizer );
65 virtual ~PrefsTreeCtrl();
71 /* Event handlers (these functions should _not_ be virtual) */
72 void OnSelectTreeItem( wxTreeEvent& event );
73 void OnAdvanced( wxCommandEvent& event );
75 ConfigTreeData *FindModuleConfig( ConfigTreeData *config_data );
79 intf_thread_t *p_intf;
80 PrefsDialog *p_prefs_dialog;
83 vlc_bool_t b_advanced;
85 wxTreeItemId root_item;
86 wxTreeItemId plugins_item;
89 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
91 class PrefsPanel : public wxPanel
96 PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
97 PrefsDialog *, ConfigTreeData* );
98 virtual ~PrefsPanel() {}
101 void SwitchAdvanced( vlc_bool_t );
104 intf_thread_t *p_intf;
105 PrefsDialog *p_prefs_dialog;
107 vlc_bool_t b_advanced;
109 wxStaticText *hidden_text;
110 wxBoxSizer *config_sizer;
111 wxScrolledWindow *config_window;
113 ArrayOfConfigControls config_array;
116 class ConfigTreeData : public wxTreeItemData
120 ConfigTreeData() { b_submodule = 0; panel = NULL; psz_name = NULL;
122 virtual ~ConfigTreeData() {
123 if( panel ) delete panel;
124 if( psz_name ) free( psz_name );
125 if( psz_help ) free( psz_help );
128 vlc_bool_t b_submodule;
140 /*****************************************************************************
142 *****************************************************************************/
144 /* IDs for the controls and the menu commands */
147 Notebook_Event = wxID_HIGHEST,
153 BEGIN_EVENT_TABLE(PrefsDialog, wxFrame)
155 EVT_BUTTON(wxID_OK, PrefsDialog::OnOk)
156 EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel)
157 EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave)
158 EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll)
159 EVT_CHECKBOX(Advanced_Event, PrefsDialog::OnAdvanced)
161 /* Don't destroy the window when the user closes it */
162 EVT_CLOSE(PrefsDialog::OnCancel)
165 // menu and control ids
168 PrefsTree_Ctrl = wxID_HIGHEST
171 BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
172 EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem)
173 EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced)
176 /*****************************************************************************
178 *****************************************************************************/
179 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent)
180 : wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition,
181 wxSize(700,450), wxDEFAULT_FRAME_STYLE )
183 /* Initializations */
185 SetIcon( *p_intf->p_sys->p_icon );
187 /* Create a panel to put everything in */
188 wxPanel *panel = new wxPanel( this, -1 );
189 panel->SetAutoLayout( TRUE );
191 /* Create the preferences tree control */
192 wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL );
194 new PrefsTreeCtrl( panel, p_intf, this, controls_sizer );
197 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
199 /* Create the buttons */
200 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
201 ok_button->SetDefault();
202 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
204 wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("Save")) );
205 wxButton *reset_button = new wxButton( panel, ResetAll_Event,
206 wxU(_("Reset All")) );
208 wxPanel *dummy_panel = new wxPanel( this, -1 );
209 wxCheckBox *advanced_checkbox =
210 new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) );
212 if( config_GetInt( p_intf, "advanced" ) )
214 advanced_checkbox->SetValue(TRUE);
215 wxCommandEvent dummy_event;
216 dummy_event.SetInt(TRUE);
217 OnAdvanced( dummy_event );
220 /* Place everything in sizers */
221 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
222 button_sizer->Add( ok_button, 0, wxALL, 5 );
223 button_sizer->Add( cancel_button, 0, wxALL, 5 );
224 button_sizer->Add( save_button, 0, wxALL, 5 );
225 button_sizer->Add( reset_button, 0, wxALL, 5 );
226 button_sizer->Add( dummy_panel, 1, wxALL, 5 );
227 button_sizer->Add( advanced_checkbox, 0, wxALL | wxALIGN_RIGHT |
228 wxALIGN_CENTER_VERTICAL, 0 );
229 button_sizer->Layout();
231 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
232 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
233 panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 );
234 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
235 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
236 wxALL | wxEXPAND, 5 );
237 panel_sizer->Layout();
238 panel->SetSizer( panel_sizer );
239 main_sizer->Add( panel, 1, wxEXPAND, 0 );
240 main_sizer->Layout();
241 SetSizer( main_sizer );
244 PrefsDialog::~PrefsDialog()
248 /*****************************************************************************
250 *****************************************************************************/
253 /*****************************************************************************
255 *****************************************************************************/
256 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
258 prefs_tree->ApplyChanges();
260 prefs_tree->CleanChanges();
263 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
266 prefs_tree->CleanChanges();
269 void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
271 prefs_tree->ApplyChanges();
272 config_SaveConfigFile( p_intf, NULL );
276 void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
278 wxMessageDialog dlg( this,
279 wxU(_("Beware this will reset your VLC media player preferences.\n"
280 "Are you sure you want to continue?")),
281 wxU(_("Reset Preferences")), wxYES_NO|wxNO_DEFAULT|wxCENTRE );
283 if ( dlg.ShowModal() == wxID_YES )
285 /* TODO: need to reset all the controls */
286 config_ResetAll( p_intf );
287 prefs_tree->CleanChanges();
288 config_SaveConfigFile( p_intf, NULL );
292 void PrefsDialog::OnAdvanced( wxCommandEvent& event )
294 wxCommandEvent newevent( wxEVT_USER_FIRST, Advanced_Event );
295 newevent.SetInt( event.GetInt() );
297 prefs_tree->AddPendingEvent( newevent );
300 /*****************************************************************************
301 * PrefsTreeCtrl class definition.
302 *****************************************************************************/
303 PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
304 PrefsDialog *_p_prefs_dialog,
305 wxBoxSizer *_p_sizer )
306 : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxSize(200,-1),
307 wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT |
308 wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT |
309 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER )
311 vlc_list_t *p_list = NULL;;
313 module_config_t *p_item;
316 /* Initializations */
318 p_prefs_dialog = _p_prefs_dialog;
320 p_parent = _p_parent;
321 b_advanced = VLC_FALSE;
323 root_item = AddRoot( wxT("") );
325 /* List the plugins */
326 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
327 if( !p_list ) return;
329 /* Build the categories list */
330 for( i_index = 0; i_index < p_list->i_count; i_index++ )
332 p_module = (module_t *)p_list->p_values[i_index].p_object;
333 if( !strcmp( p_module->psz_object_name, "main" ) )
336 if( i_index < p_list->i_count )
338 wxTreeItemId current_item;
340 /* We found the main module */
342 /* Enumerate config categories and store a reference so we can
343 * generate their config panel them when it is asked by the user. */
344 p_item = p_module->p_config;
348 ConfigTreeData *config_data;
349 switch( p_item->i_type )
351 case CONFIG_CATEGORY:
352 config_data = new ConfigTreeData;
353 config_data->psz_name = strdup( config_CategoryNameGet(
355 psz_help = config_CategoryHelpGet( p_item->i_value );
358 config_data->psz_help = wraptext( strdup( psz_help ),
363 config_data->psz_help = NULL;
365 config_data->i_type = TYPE_CATEGORY;
366 config_data->i_object_id = p_item->i_value;
368 /* Add the category to the tree */
369 current_item = AppendItem( root_item,
370 wxU( config_data->psz_name ),
371 -1, -1, config_data );
373 case CONFIG_SUBCATEGORY:
374 if( p_item->i_value == SUBCAT_VIDEO_GENERAL ||
375 p_item->i_value == SUBCAT_AUDIO_GENERAL )
377 ConfigTreeData *cd = (ConfigTreeData *)
378 GetItemData( current_item );
379 cd->i_type = TYPE_CATSUBCAT;
380 cd->i_subcat_id = p_item->i_value;
381 if( cd->psz_name ) free( cd->psz_name );
382 cd->psz_name = strdup( config_CategoryNameGet(
384 if( cd->psz_help ) free( cd->psz_help );
385 char *psz_help = config_CategoryHelpGet( p_item->i_value );
388 cd->psz_help = wraptext( strdup( psz_help ),72 ,
398 config_data = new ConfigTreeData;
400 config_data->psz_name = strdup( config_CategoryNameGet(
402 psz_help = config_CategoryHelpGet( p_item->i_value );
405 config_data->psz_help = wraptext( strdup( psz_help ) ,
410 config_data->psz_help = NULL;
412 config_data->i_type = TYPE_SUBCATEGORY;
413 config_data->i_object_id = p_item->i_value;
414 AppendItem( current_item, wxU( config_data->psz_name ),
415 -1, -1, config_data );
419 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
425 * Build a tree of all the plugins
427 for( i_index = 0; i_index < p_list->i_count; i_index++ )
430 int i_subcategory = -1;
433 p_module = (module_t *)p_list->p_values[i_index].p_object;
435 /* Exclude the main module */
436 if( !strcmp( p_module->psz_object_name, "main" ) )
439 /* Exclude empty plugins (submodules don't have config options, they
440 * are stored in the parent module) */
441 if( p_module->b_submodule )
443 // p_item = ((module_t *)p_module->p_parent)->p_config;
445 p_item = p_module->p_config;
448 if( !p_item ) continue;
451 if( p_item->i_type == CONFIG_CATEGORY )
453 i_category = p_item->i_value;
455 else if( p_item->i_type == CONFIG_SUBCATEGORY )
457 i_subcategory = p_item->i_value;
459 if( p_item->i_type & CONFIG_ITEM )
461 if( i_options > 0 && i_category >= 0 && i_subcategory >= 0 )
466 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
468 if( !i_options ) continue;
470 /* Find the right category item */
472 vlc_bool_t b_found = VLC_FALSE;
473 wxTreeItemId category_item = GetFirstChild( root_item , cookie);
474 while( category_item.IsOk() )
476 ConfigTreeData *config_data =
477 (ConfigTreeData *)GetItemData( category_item );
478 if( config_data->i_object_id == i_category )
483 category_item = GetNextChild( root_item, cookie );
486 if( !b_found ) continue;
488 /* Find subcategory item */
491 wxTreeItemId subcategory_item = GetFirstChild( category_item, cookie );
492 while( subcategory_item.IsOk() )
494 ConfigTreeData *config_data =
495 (ConfigTreeData *)GetItemData( subcategory_item );
496 if( config_data->i_object_id == i_subcategory )
501 subcategory_item = GetNextChild( category_item, cookie );
505 subcategory_item = category_item;
508 /* Add the plugin to the tree */
509 ConfigTreeData *config_data = new ConfigTreeData;
510 config_data->b_submodule = p_module->b_submodule;
511 config_data->i_type = TYPE_MODULE;
512 config_data->i_object_id = p_module->b_submodule ?
513 ((module_t *)p_module->p_parent)->i_object_id :
514 p_module->i_object_id;
515 config_data->psz_help = NULL;
517 AppendItem( subcategory_item, wxU( p_module->psz_shortname ?
518 p_module->psz_shortname : p_module->psz_object_name )
523 /* Sort all this mess */
524 long cookie; size_t i_child_index;
525 wxTreeItemId capability_item = GetFirstChild( root_item, cookie);
526 for( i_child_index = 0;
527 i_child_index < GetChildrenCount( plugins_item, FALSE );
530 SortChildren( capability_item );
531 capability_item = GetNextChild( plugins_item, cookie );
534 /* Clean-up everything */
535 vlc_list_release( p_list );
537 p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );
540 /* Update Tree Ctrl */
541 #ifndef WIN32 /* Workaround a bug in win32 implementation */
542 SelectItem( GetFirstChild( root_item, cookie ) );
548 PrefsTreeCtrl::~PrefsTreeCtrl()
552 void PrefsTreeCtrl::ApplyChanges()
554 long cookie, cookie2, cookie3;
555 ConfigTreeData *config_data;
557 wxTreeItemId category = GetFirstChild( root_item, cookie );
558 while( category.IsOk() )
560 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
561 while( subcategory.IsOk() )
563 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
564 while( module.IsOk() )
566 config_data = (ConfigTreeData *)GetItemData( module );
567 if( config_data && config_data->panel )
569 config_data->panel->ApplyChanges();
571 module = GetNextChild( subcategory, cookie3 );
573 config_data = (ConfigTreeData *)GetItemData( subcategory );
574 if( config_data && config_data->panel )
576 config_data->panel->ApplyChanges();
578 subcategory = GetNextChild( category, cookie2 );
580 config_data = (ConfigTreeData *)GetItemData( category );
581 if( config_data && config_data->panel )
583 config_data->panel->ApplyChanges();
585 category = GetNextChild( root_item, cookie );
589 void PrefsTreeCtrl::CleanChanges()
591 long cookie, cookie2, cookie3;
592 ConfigTreeData *config_data;
594 config_data = !GetSelection() ? NULL :
595 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
598 config_data->panel->Hide();
599 p_sizer->Remove( config_data->panel );
602 wxTreeItemId category = GetFirstChild( root_item, cookie );
603 while( category.IsOk() )
605 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
606 while( subcategory.IsOk() )
608 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
609 while( module.IsOk() )
611 config_data = (ConfigTreeData *)GetItemData( module );
612 if( config_data && config_data->panel )
614 delete config_data->panel;
615 config_data->panel = NULL;
617 module = GetNextChild( subcategory, cookie3 );
619 config_data = (ConfigTreeData *)GetItemData( subcategory );
620 if( config_data && config_data->panel )
622 delete config_data->panel;
623 config_data->panel = NULL;
625 subcategory = GetNextChild( category, cookie2 );
627 config_data = (ConfigTreeData *)GetItemData( category );
628 if( config_data && config_data->panel )
630 delete config_data->panel;
631 config_data->panel = NULL;
633 category = GetNextChild( root_item, cookie );
639 OnSelectTreeItem( event );
643 ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
645 /* We need this complexity because submodules don't have their own config
646 * options. They use the parent module ones. */
648 if( !config_data || !config_data->b_submodule )
653 long cookie, cookie2, cookie3;
654 ConfigTreeData *config_new;
655 wxTreeItemId category = GetFirstChild( root_item, cookie );
656 while( category.IsOk() )
658 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
659 while( subcategory.IsOk() )
661 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
662 while( module.IsOk() )
664 config_new = (ConfigTreeData *)GetItemData( module );
665 if( config_new && !config_new->b_submodule &&
666 config_new->i_object_id == config_data->i_object_id )
670 module = GetNextChild( subcategory, cookie3 );
672 subcategory = GetNextChild( category, cookie2 );
674 category = GetNextChild( root_item, cookie );
681 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
683 ConfigTreeData *config_data = NULL;
685 if( event.GetOldItem() )
686 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
687 event.GetOldItem() ) );
688 if( config_data && config_data->panel )
690 config_data->panel->Hide();
691 p_sizer->Remove( config_data->panel );
694 /* Don't use event.GetItem() because we also send fake events */
695 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
699 if( !config_data->panel )
701 /* The panel hasn't been created yet. Let's do it. */
703 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
705 config_data->panel->SwitchAdvanced( b_advanced );
709 config_data->panel->SwitchAdvanced( b_advanced );
710 config_data->panel->Show();
713 p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );
718 void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event )
720 b_advanced = event.GetInt();
722 ConfigTreeData *config_data = !GetSelection() ? NULL :
723 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
726 config_data->panel->Hide();
727 p_sizer->Remove( config_data->panel );
733 OnSelectTreeItem( event );
737 /*****************************************************************************
738 * PrefsPanel class definition.
739 *****************************************************************************/
740 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
741 PrefsDialog *_p_prefs_dialog,
742 ConfigTreeData *config_data )
743 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
745 module_config_t *p_item;
746 vlc_list_t *p_list = NULL;;
752 module_t *p_module = NULL;
754 /* Initializations */
756 p_prefs_dialog =_p_prefs_dialog,
758 b_advanced = VLC_TRUE;
759 SetAutoLayout( TRUE );
762 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
765 if( config_data->i_type == TYPE_CATEGORY )
767 label = new wxStaticText( this, -1,wxU(_( config_data->psz_name )));
768 wxFont heading_font = label->GetFont();
769 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
770 label->SetFont( heading_font );
771 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
772 sizer->Add( new wxStaticLine( this, 0 ), 0,
773 wxEXPAND | wxLEFT | wxRIGHT, 2 );
776 help = new wxStaticText( this, -1, wxU(_( config_data->psz_help ) ) );
777 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
779 config_sizer = NULL; config_window = NULL;
783 /* Get a pointer to the module */
784 if( config_data->i_type == TYPE_MODULE )
786 p_module = (module_t *)vlc_object_get( p_intf,
787 config_data->i_object_id );
791 /* List the plugins */
793 vlc_bool_t b_found = VLC_FALSE;
794 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
795 if( !p_list ) return;
797 for( i_index = 0; i_index < p_list->i_count; i_index++ )
799 p_module = (module_t *)p_list->p_values[i_index].p_object;
800 if( !strcmp( p_module->psz_object_name, "main" ) )
806 if( !p_module && !b_found )
808 msg_Warn( p_intf, "ohoh, unable to find main module" );
813 if( p_module->i_object_type != VLC_OBJECT_MODULE )
815 /* 0OOoo something went really bad */
819 /* Enumerate config options and add corresponding config boxes
820 * (submodules don't have config options, they are stored in the
822 if( p_module->b_submodule )
823 p_item = ((module_t *)p_module->p_parent)->p_config;
825 p_item = p_module->p_config;
827 /* Find the category if it has been specified */
828 if( config_data->i_type == TYPE_SUBCATEGORY ||
829 config_data->i_type == TYPE_CATSUBCAT )
833 if( p_item->i_type == CONFIG_SUBCATEGORY &&
834 ( config_data->i_type == TYPE_SUBCATEGORY &&
835 p_item->i_value == config_data->i_object_id ) ||
836 ( config_data->i_type == TYPE_CATSUBCAT &&
837 p_item->i_value == config_data->i_subcat_id ) )
841 if( p_item->i_type == CONFIG_HINT_END )
846 /* Add a head title to the panel */
848 if( config_data->i_type == TYPE_SUBCATEGORY ||
849 config_data->i_type == TYPE_CATSUBCAT )
851 psz_head = config_data->psz_name;
856 psz_head = p_module->psz_longname;
859 label = new wxStaticText( this, -1,
860 wxU(_( psz_head ? psz_head : _("Unknown") ) ) );
861 wxFont heading_font = label->GetFont();
862 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
863 label->SetFont( heading_font );
864 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
865 sizer->Add( new wxStaticLine( this, 0 ), 0,
866 wxEXPAND | wxLEFT | wxRIGHT, 2 );
868 /* Now put all the config options into a scrolled window */
869 config_sizer = new wxBoxSizer( wxVERTICAL );
870 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
871 wxDefaultSize, wxBORDER_NONE | wxHSCROLL | wxVSCROLL );
872 config_window->SetAutoLayout( TRUE );
873 config_window->SetScrollRate( 5, 5 );
877 /* If a category has been specified, check we finished the job */
878 if( ( ( config_data->i_type == TYPE_SUBCATEGORY &&
879 p_item->i_value != config_data->i_object_id ) ||
880 ( config_data->i_type == TYPE_CATSUBCAT &&
881 p_item->i_value != config_data->i_subcat_id ) ) &&
882 (p_item->i_type == CONFIG_CATEGORY ||
883 p_item->i_type == CONFIG_SUBCATEGORY ) )
886 ConfigControl *control =
887 CreateConfigControl( VLC_OBJECT(p_intf),
888 p_item, config_window );
890 /* Don't add items that were not recognized */
891 if( control == NULL ) continue;
893 /* Add the config data to our array so we can keep a trace of it */
894 config_array.Add( control );
896 config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
898 while( !( p_item->i_type == CONFIG_HINT_END ||
899 ( ( config_data->i_type == TYPE_SUBCATEGORY ||
900 config_data->i_type == TYPE_CATSUBCAT ) &&
901 ( p_item->i_type == CONFIG_CATEGORY ||
902 p_item->i_type == CONFIG_SUBCATEGORY ) ) ) && p_item++ );
905 config_sizer->Layout();
906 config_window->SetSizer( config_sizer );
907 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
908 hidden_text = new wxStaticText( this, -1,
909 wxU( _( "Some options are available but hidden. " \
910 "Check \"Advanced options\" to see them." ) ) );
911 sizer->Add( hidden_text );
913 /* And at last put a useful help string if available */
914 if( config_data->psz_help && *config_data->psz_help )
916 sizer->Add( new wxStaticLine( this, 0 ), 0,
917 wxEXPAND | wxLEFT | wxRIGHT, 2 );
918 help = new wxStaticText( this, -1, wxU(_(config_data->psz_help)),
919 wxDefaultPosition, wxDefaultSize,
922 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
925 if( config_data->i_type == TYPE_MODULE )
927 vlc_object_release( p_module );
931 vlc_list_release( p_list );
939 void PrefsPanel::ApplyChanges()
943 for( size_t i = 0; i < config_array.GetCount(); i++ )
945 ConfigControl *control = config_array.Item(i);
947 switch( control->GetType() )
949 case CONFIG_ITEM_STRING:
950 case CONFIG_ITEM_FILE:
951 case CONFIG_ITEM_DIRECTORY:
952 case CONFIG_ITEM_MODULE:
953 case CONFIG_ITEM_MODULE_LIST:
954 case CONFIG_ITEM_MODULE_LIST_CAT:
955 config_PutPsz( p_intf, control->GetName().mb_str(),
956 control->GetPszValue().mb_str() );
958 case CONFIG_ITEM_KEY:
959 /* So you don't need to restart to have the changes take effect */
960 val.i_int = control->GetIntValue();
961 var_Set( p_intf->p_vlc, control->GetName().mb_str(), val );
962 case CONFIG_ITEM_INTEGER:
963 case CONFIG_ITEM_BOOL:
964 config_PutInt( p_intf, control->GetName().mb_str(),
965 control->GetIntValue() );
967 case CONFIG_ITEM_FLOAT:
968 config_PutFloat( p_intf, control->GetName().mb_str(),
969 control->GetFloatValue() );
975 void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
979 if( b_advanced == b_new_advanced )
984 if( config_sizer && config_window )
986 b_advanced = b_new_advanced;
988 for( size_t i = 0; i < config_array.GetCount(); i++ )
990 ConfigControl *control = config_array.Item(i);
991 if( control->IsAdvanced() )
993 if( !b_advanced ) hidden = true;
994 control->Show( b_advanced );
995 config_sizer->Show( control, b_advanced );
999 config_sizer->Layout();
1000 config_window->FitInside();
1001 config_window->Refresh();
1004 if( hidden && hidden_text )
1006 hidden_text->Show( true );
1007 config_sizer->Show( hidden_text, true );
1009 else if ( hidden_text )
1011 hidden_text->Show( false );
1012 config_sizer->Show( hidden_text, false );