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_SUBCATEGORY 1
53 /*****************************************************************************
54 * Classes declarations.
55 *****************************************************************************/
57 class PrefsTreeCtrl : public wxTreeCtrl
62 PrefsTreeCtrl( wxWindow *parent, intf_thread_t *_p_intf,
63 PrefsDialog *p_prefs_dialog, wxBoxSizer *_p_sizer );
64 virtual ~PrefsTreeCtrl();
70 /* Event handlers (these functions should _not_ be virtual) */
71 void OnSelectTreeItem( wxTreeEvent& event );
72 void OnAdvanced( wxCommandEvent& event );
74 ConfigTreeData *FindModuleConfig( ConfigTreeData *config_data );
78 intf_thread_t *p_intf;
79 PrefsDialog *p_prefs_dialog;
82 vlc_bool_t b_advanced;
84 wxTreeItemId root_item;
85 wxTreeItemId plugins_item;
88 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
90 class PrefsPanel : public wxPanel
95 PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
96 PrefsDialog *, ConfigTreeData* );
97 virtual ~PrefsPanel() {}
100 void SwitchAdvanced( vlc_bool_t );
103 intf_thread_t *p_intf;
104 PrefsDialog *p_prefs_dialog;
106 vlc_bool_t b_advanced;
108 wxStaticText *hidden_text;
109 wxBoxSizer *config_sizer;
110 wxScrolledWindow *config_window;
112 ArrayOfConfigControls config_array;
115 class ConfigTreeData : public wxTreeItemData
119 ConfigTreeData() { b_submodule = 0; panel = NULL; psz_name = NULL;
121 virtual ~ConfigTreeData() {
122 if( panel ) delete panel;
123 if( psz_name ) free( psz_name );
124 if( psz_help ) free( psz_help );
127 vlc_bool_t b_submodule;
138 /*****************************************************************************
140 *****************************************************************************/
142 /* IDs for the controls and the menu commands */
145 Notebook_Event = wxID_HIGHEST,
151 BEGIN_EVENT_TABLE(PrefsDialog, wxFrame)
153 EVT_BUTTON(wxID_OK, PrefsDialog::OnOk)
154 EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel)
155 EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave)
156 EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll)
157 EVT_CHECKBOX(Advanced_Event, PrefsDialog::OnAdvanced)
159 /* Don't destroy the window when the user closes it */
160 EVT_CLOSE(PrefsDialog::OnCancel)
163 // menu and control ids
166 PrefsTree_Ctrl = wxID_HIGHEST
169 BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
170 EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem)
171 EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced)
174 /*****************************************************************************
176 *****************************************************************************/
177 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent)
178 : wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition,
179 wxSize(700,450), wxDEFAULT_FRAME_STYLE )
181 /* Initializations */
183 SetIcon( *p_intf->p_sys->p_icon );
185 /* Create a panel to put everything in */
186 wxPanel *panel = new wxPanel( this, -1 );
187 panel->SetAutoLayout( TRUE );
189 /* Create the preferences tree control */
190 wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL );
192 new PrefsTreeCtrl( panel, p_intf, this, controls_sizer );
195 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
197 /* Create the buttons */
198 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
199 ok_button->SetDefault();
200 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
202 wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("Save")) );
203 wxButton *reset_button = new wxButton( panel, ResetAll_Event,
204 wxU(_("Reset All")) );
206 wxPanel *dummy_panel = new wxPanel( this, -1 );
207 wxCheckBox *advanced_checkbox =
208 new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) );
210 if( config_GetInt( p_intf, "advanced" ) )
212 advanced_checkbox->SetValue(TRUE);
213 wxCommandEvent dummy_event;
214 dummy_event.SetInt(TRUE);
215 OnAdvanced( dummy_event );
218 /* Place everything in sizers */
219 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
220 button_sizer->Add( ok_button, 0, wxALL, 5 );
221 button_sizer->Add( cancel_button, 0, wxALL, 5 );
222 button_sizer->Add( save_button, 0, wxALL, 5 );
223 button_sizer->Add( reset_button, 0, wxALL, 5 );
224 button_sizer->Add( dummy_panel, 1, wxALL, 5 );
225 button_sizer->Add( advanced_checkbox, 0, wxALL | wxALIGN_RIGHT |
226 wxALIGN_CENTER_VERTICAL, 0 );
227 button_sizer->Layout();
229 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
230 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
231 panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 );
232 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
233 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
234 wxALL | wxEXPAND, 5 );
235 panel_sizer->Layout();
236 panel->SetSizer( panel_sizer );
237 main_sizer->Add( panel, 1, wxEXPAND, 0 );
238 main_sizer->Layout();
239 SetSizer( main_sizer );
242 PrefsDialog::~PrefsDialog()
246 /*****************************************************************************
248 *****************************************************************************/
251 /*****************************************************************************
253 *****************************************************************************/
254 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
256 prefs_tree->ApplyChanges();
258 prefs_tree->CleanChanges();
261 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
264 prefs_tree->CleanChanges();
267 void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
269 prefs_tree->ApplyChanges();
270 config_SaveConfigFile( p_intf, NULL );
274 void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
276 wxMessageDialog dlg( this,
277 wxU(_("Beware this will reset your VLC media player preferences.\n"
278 "Are you sure you want to continue?")),
279 wxU(_("Reset Preferences")), wxYES_NO|wxNO_DEFAULT|wxCENTRE );
281 if ( dlg.ShowModal() == wxID_YES )
283 /* TODO: need to reset all the controls */
284 config_ResetAll( p_intf );
285 prefs_tree->CleanChanges();
286 config_SaveConfigFile( p_intf, NULL );
290 void PrefsDialog::OnAdvanced( wxCommandEvent& event )
292 wxCommandEvent newevent( wxEVT_USER_FIRST, Advanced_Event );
293 newevent.SetInt( event.GetInt() );
295 prefs_tree->AddPendingEvent( newevent );
298 /*****************************************************************************
299 * PrefsTreeCtrl class definition.
300 *****************************************************************************/
301 PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
302 PrefsDialog *_p_prefs_dialog,
303 wxBoxSizer *_p_sizer )
304 : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxDefaultSize,
305 wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT |
306 wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT |
307 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER )
309 vlc_list_t *p_list = NULL;;
311 module_config_t *p_item;
314 /* Initializations */
316 p_prefs_dialog = _p_prefs_dialog;
318 p_parent = _p_parent;
319 b_advanced = VLC_FALSE;
321 root_item = AddRoot( wxT("") );
323 /* List the plugins */
324 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
325 if( !p_list ) return;
327 /* Build the categories list */
328 for( i_index = 0; i_index < p_list->i_count; i_index++ )
330 p_module = (module_t *)p_list->p_values[i_index].p_object;
331 if( !strcmp( p_module->psz_object_name, "main" ) )
334 if( i_index < p_list->i_count )
336 wxTreeItemId current_item;
338 /* We found the main module */
340 /* Enumerate config categories and store a reference so we can
341 * generate their config panel them when it is asked by the user. */
342 p_item = p_module->p_config;
346 ConfigTreeData *config_data;
347 switch( p_item->i_type )
349 case CONFIG_CATEGORY:
350 config_data = new ConfigTreeData;
351 config_data->psz_name = strdup( config_CategoryNameGet(
353 psz_help = config_CategoryHelpGet( p_item->i_value );
356 config_data->psz_help = wraptext( strdup( psz_help ),
361 config_data->psz_help = NULL;
363 config_data->i_type = TYPE_CATEGORY;
364 config_data->i_object_id = p_item->i_value;
366 /* Add the category to the tree */
367 current_item = AppendItem( root_item,
368 wxU( config_data->psz_name ),
369 -1, -1, config_data );
371 case CONFIG_SUBCATEGORY:
372 config_data = new ConfigTreeData;
373 config_data->psz_name = strdup( config_CategoryNameGet(
375 psz_help = config_CategoryHelpGet( p_item->i_value );
378 config_data->psz_help = wraptext( strdup( psz_help ) ,
383 config_data->psz_help = NULL;
385 config_data->i_type = TYPE_SUBCATEGORY;
386 config_data->i_object_id = p_item->i_value;
387 AppendItem( current_item, wxU( config_data->psz_name ),
388 -1, -1, config_data );
392 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
398 * Build a tree of all the plugins
400 for( i_index = 0; i_index < p_list->i_count; i_index++ )
403 int i_subcategory = -1;
406 p_module = (module_t *)p_list->p_values[i_index].p_object;
408 /* Exclude the main module */
409 if( !strcmp( p_module->psz_object_name, "main" ) )
412 /* Exclude empty plugins (submodules don't have config options, they
413 * are stored in the parent module) */
414 if( p_module->b_submodule )
416 // p_item = ((module_t *)p_module->p_parent)->p_config;
418 p_item = p_module->p_config;
420 if( !p_item ) continue;
423 if( p_item->i_type == CONFIG_CATEGORY )
425 i_category = p_item->i_value;
427 else if( p_item->i_type == CONFIG_SUBCATEGORY )
429 i_subcategory = p_item->i_value;
431 if( p_item->i_type & CONFIG_ITEM )
433 if( i_options > 0 && i_category >= 0 && i_subcategory >= 0 )
438 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
440 if( !i_options ) continue;
442 /* Find the right category item */
444 vlc_bool_t b_found = VLC_FALSE;
445 wxTreeItemId category_item = GetFirstChild( root_item , cookie);
446 while( category_item.IsOk() )
448 ConfigTreeData *config_data =
449 (ConfigTreeData *)GetItemData( category_item );
450 if( config_data->i_object_id == i_category )
455 category_item = GetNextChild( root_item, cookie );
458 if( !b_found ) continue;
460 /* Find subcategory item */
463 wxTreeItemId subcategory_item = GetFirstChild( category_item, cookie );
464 while( subcategory_item.IsOk() )
466 ConfigTreeData *config_data =
467 (ConfigTreeData *)GetItemData( subcategory_item );
468 if( config_data->i_object_id == i_subcategory )
473 subcategory_item = GetNextChild( category_item, cookie );
477 subcategory_item = category_item;
480 /* Add the plugin to the tree */
481 ConfigTreeData *config_data = new ConfigTreeData;
482 config_data->b_submodule = p_module->b_submodule;
483 config_data->i_type = TYPE_MODULE;
484 config_data->i_object_id = p_module->b_submodule ?
485 ((module_t *)p_module->p_parent)->i_object_id :
486 p_module->i_object_id;
487 config_data->psz_help = NULL;
489 AppendItem( subcategory_item, wxU( p_module->psz_name ?
490 p_module->psz_name : p_module->psz_object_name)
495 /* Sort all this mess */
496 long cookie; size_t i_child_index;
497 wxTreeItemId capability_item = GetFirstChild( root_item, cookie);
498 for( i_child_index = 0;
499 i_child_index < GetChildrenCount( plugins_item, FALSE );
502 SortChildren( capability_item );
503 capability_item = GetNextChild( plugins_item, cookie );
506 /* Clean-up everything */
507 vlc_list_release( p_list );
509 p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );
512 /* Update Tree Ctrl */
513 #ifndef WIN32 /* Workaround a bug in win32 implementation */
514 SelectItem( GetFirstChild( root_item, cookie ) );
520 PrefsTreeCtrl::~PrefsTreeCtrl()
524 void PrefsTreeCtrl::ApplyChanges()
526 long cookie, cookie2, cookie3;
527 ConfigTreeData *config_data;
529 wxTreeItemId category = GetFirstChild( root_item, cookie );
530 while( category.IsOk() )
532 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
533 while( subcategory.IsOk() )
535 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
536 while( module.IsOk() )
538 config_data = (ConfigTreeData *)GetItemData( module );
539 if( config_data && config_data->panel )
541 config_data->panel->ApplyChanges();
543 module = GetNextChild( subcategory, cookie3 );
545 config_data = (ConfigTreeData *)GetItemData( subcategory );
546 if( config_data && config_data->panel )
548 config_data->panel->ApplyChanges();
550 subcategory = GetNextChild( category, cookie2 );
552 config_data = (ConfigTreeData *)GetItemData( category );
553 if( config_data && config_data->panel )
555 config_data->panel->ApplyChanges();
557 category = GetNextChild( root_item, cookie );
561 void PrefsTreeCtrl::CleanChanges()
563 long cookie, cookie2, cookie3;
564 ConfigTreeData *config_data;
566 config_data = !GetSelection() ? NULL :
567 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
570 config_data->panel->Hide();
571 p_sizer->Remove( config_data->panel );
574 wxTreeItemId category = GetFirstChild( root_item, cookie );
575 while( category.IsOk() )
577 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
578 while( subcategory.IsOk() )
580 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
581 while( module.IsOk() )
583 config_data = (ConfigTreeData *)GetItemData( module );
584 if( config_data && config_data->panel )
586 delete config_data->panel;
587 config_data->panel = NULL;
589 module = GetNextChild( subcategory, cookie3 );
591 config_data = (ConfigTreeData *)GetItemData( subcategory );
592 if( config_data && config_data->panel )
594 delete config_data->panel;
595 config_data->panel = NULL;
597 subcategory = GetNextChild( category, cookie2 );
599 config_data = (ConfigTreeData *)GetItemData( category );
600 if( config_data && config_data->panel )
602 delete config_data->panel;
603 config_data->panel = NULL;
605 category = GetNextChild( root_item, cookie );
609 /* Clean changes for the main module */
610 wxTreeItemId item = GetFirstChild( root_item, cookie );
611 for( size_t i_child_index = 0;
612 i_child_index < GetChildrenCount( root_item, FALSE );
615 config_data = (ConfigTreeData *)GetItemData( item );
616 if( config_data && config_data->panel )
618 delete config_data->panel;
619 config_data->panel = NULL;
622 item = GetNextChild( root_item, cookie );
624 /* Clean changes for the plugins */
625 item = GetFirstChild( plugins_item, cookie );
626 for( size_t i_child_index = 0;
627 i_child_index < GetChildrenCount( plugins_item, FALSE );
630 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
631 for( size_t i_child_index = 0;
632 i_child_index < GetChildrenCount( item, FALSE );
635 config_data = (ConfigTreeData *)GetItemData( item2 );
637 if( config_data && config_data->panel )
639 delete config_data->panel;
640 config_data->panel = NULL;
643 item2 = GetNextChild( item, cookie2 );
646 item = GetNextChild( plugins_item, cookie );
652 OnSelectTreeItem( event );
656 ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
658 /* We need this complexity because submodules don't have their own config
659 * options. They use the parent module ones. */
661 if( !config_data || !config_data->b_submodule )
666 long cookie, cookie2, cookie3;
667 ConfigTreeData *config_new;
668 wxTreeItemId category = GetFirstChild( root_item, cookie );
669 while( category.IsOk() )
671 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
672 while( subcategory.IsOk() )
674 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
675 while( module.IsOk() )
677 config_new = (ConfigTreeData *)GetItemData( module );
678 if( config_new && !config_new->b_submodule &&
679 config_new->i_object_id == config_data->i_object_id )
683 module = GetNextChild( subcategory, cookie3 );
685 subcategory = GetNextChild( category, cookie2 );
687 category = GetNextChild( root_item, cookie );
694 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
696 ConfigTreeData *config_data = NULL;
698 if( event.GetOldItem() )
699 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
700 event.GetOldItem() ) );
701 if( config_data && config_data->panel )
703 config_data->panel->Hide();
704 p_sizer->Remove( config_data->panel );
707 /* Don't use event.GetItem() because we also send fake events */
708 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
712 if( !config_data->panel )
714 /* The panel hasn't been created yet. Let's do it. */
716 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
718 config_data->panel->SwitchAdvanced( b_advanced );
722 config_data->panel->SwitchAdvanced( b_advanced );
723 config_data->panel->Show();
726 p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );
731 void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event )
733 b_advanced = event.GetInt();
735 ConfigTreeData *config_data = !GetSelection() ? NULL :
736 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
739 config_data->panel->Hide();
740 p_sizer->Remove( config_data->panel );
746 OnSelectTreeItem( event );
750 /*****************************************************************************
751 * PrefsPanel class definition.
752 *****************************************************************************/
753 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
754 PrefsDialog *_p_prefs_dialog,
755 ConfigTreeData *config_data )
756 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
758 module_config_t *p_item;
759 vlc_list_t *p_list = NULL;;
765 module_t *p_module = NULL;
767 /* Initializations */
769 p_prefs_dialog =_p_prefs_dialog,
771 b_advanced = VLC_TRUE;
772 SetAutoLayout( TRUE );
775 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
778 if( config_data->i_type == TYPE_CATEGORY )
780 label = new wxStaticText( this, -1,wxU(_( config_data->psz_name )));
781 wxFont heading_font = label->GetFont();
782 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
783 label->SetFont( heading_font );
784 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
785 sizer->Add( new wxStaticLine( this, 0 ), 0,
786 wxEXPAND | wxLEFT | wxRIGHT, 2 );
789 help = new wxStaticText( this, -1, wxU(_( config_data->psz_help ) ) );
790 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
792 config_sizer = NULL; config_window = NULL;
796 /* Get a pointer to the module */
797 if( config_data->i_type == TYPE_MODULE )
799 p_module = (module_t *)vlc_object_get( p_intf,
800 config_data->i_object_id );
804 /* List the plugins */
806 vlc_bool_t b_found = VLC_FALSE;
807 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
808 if( !p_list ) return;
810 for( i_index = 0; i_index < p_list->i_count; i_index++ )
812 p_module = (module_t *)p_list->p_values[i_index].p_object;
813 if( !strcmp( p_module->psz_object_name, "main" ) )
819 if( !p_module && !b_found )
821 msg_Warn( p_intf, "ohoh, unable to find main module");
826 if( p_module->i_object_type != VLC_OBJECT_MODULE )
828 /* 0OOoo something went really bad */
832 /* Enumerate config options and add corresponding config boxes
833 * (submodules don't have config options, they are stored in the
835 if( p_module->b_submodule )
836 p_item = ((module_t *)p_module->p_parent)->p_config;
838 p_item = p_module->p_config;
840 /* Find the category if it has been specified */
841 if( config_data->i_type == TYPE_SUBCATEGORY )
845 if( p_item->i_type == CONFIG_SUBCATEGORY &&
846 p_item->i_value == config_data->i_object_id )
850 if( p_item->i_type == CONFIG_HINT_END )
855 /* Add a head title to the panel */
857 if( config_data->i_type == TYPE_SUBCATEGORY )
859 psz_head = config_data->psz_name;
864 psz_head = p_module->psz_longname;
867 label = new wxStaticText( this, -1,
868 wxU(_( psz_head ? psz_head : _("Unknown") ) ) );
869 wxFont heading_font = label->GetFont();
870 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
871 label->SetFont( heading_font );
872 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
873 sizer->Add( new wxStaticLine( this, 0 ), 0,
874 wxEXPAND | wxLEFT | wxRIGHT, 2 );
876 /* Now put all the config options into a scrolled window */
877 config_sizer = new wxBoxSizer( wxVERTICAL );
878 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
879 wxDefaultSize, wxBORDER_NONE | wxHSCROLL | wxVSCROLL );
880 config_window->SetAutoLayout( TRUE );
881 config_window->SetScrollRate( 5, 5 );
885 /* If a category has been specified, check we finished the job */
886 if( config_data->i_type == TYPE_SUBCATEGORY &&
887 (p_item->i_type == CONFIG_CATEGORY ||
888 p_item->i_type == CONFIG_SUBCATEGORY ) &&
889 p_item->i_value != config_data->i_object_id )
892 ConfigControl *control =
893 CreateConfigControl( VLC_OBJECT(p_intf),
894 p_item, config_window );
896 /* Don't add items that were not recognized */
897 if( control == NULL ) continue;
899 /* Add the config data to our array so we can keep a trace of it */
900 config_array.Add( control );
902 config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
904 while( !( p_item->i_type == CONFIG_HINT_END ||
905 ( config_data->i_type == TYPE_SUBCATEGORY &&
906 ( p_item->i_type == CONFIG_CATEGORY ||
907 p_item->i_type == CONFIG_SUBCATEGORY ) ) ) && p_item++ );
910 config_sizer->Layout();
911 config_window->SetSizer( config_sizer );
912 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
913 hidden_text = new wxStaticText( this, -1,
914 wxU( _( "Some options are available but hidden. " \
915 "Check \"Advanced options\" to see them." ) ) );
916 sizer->Add( hidden_text );
918 /* And at last put a useful help string if available */
919 if( config_data->psz_help && *config_data->psz_help )
921 sizer->Add( new wxStaticLine( this, 0 ), 0,
922 wxEXPAND | wxLEFT | wxRIGHT, 2 );
923 help = new wxStaticText( this, -1, wxU(_(config_data->psz_help)),
924 wxDefaultPosition, wxDefaultSize,
927 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
930 if( config_data->i_type == TYPE_MODULE )
932 vlc_object_release( p_module );
936 vlc_list_release( p_list );
944 void PrefsPanel::ApplyChanges()
948 for( size_t i = 0; i < config_array.GetCount(); i++ )
950 ConfigControl *control = config_array.Item(i);
952 switch( control->GetType() )
954 case CONFIG_ITEM_STRING:
955 case CONFIG_ITEM_FILE:
956 case CONFIG_ITEM_DIRECTORY:
957 case CONFIG_ITEM_MODULE:
958 case CONFIG_ITEM_MODULE_LIST:
959 case CONFIG_ITEM_MODULE_LIST_CAT:
960 config_PutPsz( p_intf, control->GetName().mb_str(),
961 control->GetPszValue().mb_str() );
963 case CONFIG_ITEM_KEY:
964 /* So you don't need to restart to have the changes take effect */
965 val.i_int = control->GetIntValue();
966 var_Set( p_intf->p_vlc, control->GetName().mb_str(), val );
967 case CONFIG_ITEM_INTEGER:
968 case CONFIG_ITEM_BOOL:
969 config_PutInt( p_intf, control->GetName().mb_str(),
970 control->GetIntValue() );
972 case CONFIG_ITEM_FLOAT:
973 config_PutFloat( p_intf, control->GetName().mb_str(),
974 control->GetFloatValue() );
980 void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
984 if( b_advanced == b_new_advanced )
989 if( config_sizer && config_window )
991 b_advanced = b_new_advanced;
993 for( size_t i = 0; i < config_array.GetCount(); i++ )
995 ConfigControl *control = config_array.Item(i);
996 if( control->IsAdvanced() )
998 if( !b_advanced ) hidden = true;
999 control->Show( b_advanced );
1000 config_sizer->Show( control, b_advanced );
1004 config_sizer->Layout();
1005 config_window->FitInside();
1006 config_window->Refresh();
1009 if( hidden && hidden_text )
1011 hidden_text->Show( true );
1012 config_sizer->Show( hidden_text, true );
1014 else if ( hidden_text )
1016 hidden_text->Show( false );
1017 config_sizer->Show( hidden_text, false );