1 /*****************************************************************************
2 * preferences.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: preferences.cpp,v 1.41 2003/10/29 21:04:55 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() */
37 #include "wxwindows.h"
38 #include "preferences_widgets.h"
39 #include <wx/notebook.h>
40 #include <wx/textctrl.h>
41 #include <wx/combobox.h>
42 #include <wx/spinctrl.h>
43 #include <wx/statline.h>
44 #include <wx/treectrl.h>
45 #include <wx/clntdata.h>
46 #include <wx/dynarray.h>
49 # define wxRB_SINGLE 0
52 #define GENERAL_ID 1242
53 #define PLUGIN_ID 1243
54 #define CAPABILITY_ID 1244
56 /*****************************************************************************
57 * Classes declarations.
58 *****************************************************************************/
60 class PrefsTreeCtrl : public wxTreeCtrl
65 PrefsTreeCtrl( wxWindow *parent, intf_thread_t *_p_intf,
66 PrefsDialog *p_prefs_dialog, wxBoxSizer *_p_sizer );
67 virtual ~PrefsTreeCtrl();
73 /* Event handlers (these functions should _not_ be virtual) */
74 void OnSelectTreeItem( wxTreeEvent& event );
75 void OnAdvanced( wxCommandEvent& event );
77 ConfigTreeData *FindModuleConfig( ConfigTreeData *config_data );
81 intf_thread_t *p_intf;
82 PrefsDialog *p_prefs_dialog;
85 vlc_bool_t b_advanced;
87 wxTreeItemId root_item;
88 wxTreeItemId general_item;
89 wxTreeItemId plugins_item;
92 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
94 class PrefsPanel : public wxPanel
99 PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
100 PrefsDialog *, int i_object_id, char *, char * );
101 virtual ~PrefsPanel() {}
104 void SwitchAdvanced( vlc_bool_t );
107 intf_thread_t *p_intf;
108 PrefsDialog *p_prefs_dialog;
110 vlc_bool_t b_advanced;
112 wxBoxSizer *config_sizer;
113 wxScrolledWindow *config_window;
115 ArrayOfConfigControls config_array;
118 class ConfigTreeData : public wxTreeItemData
122 ConfigTreeData() { b_submodule = 0; panel = NULL; psz_section = NULL; }
123 virtual ~ConfigTreeData() { if( panel ) delete panel; }
125 vlc_bool_t b_submodule;
135 /*****************************************************************************
137 *****************************************************************************/
139 /* IDs for the controls and the menu commands */
142 Notebook_Event = wxID_HIGHEST,
148 BEGIN_EVENT_TABLE(PrefsDialog, wxFrame)
150 EVT_BUTTON(wxID_OK, PrefsDialog::OnOk)
151 EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel)
152 EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave)
153 EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll)
154 EVT_CHECKBOX(Advanced_Event, PrefsDialog::OnAdvanced)
156 /* Don't destroy the window when the user closes it */
157 EVT_CLOSE(PrefsDialog::OnCancel)
160 // menu and control ids
163 PrefsTree_Ctrl = wxID_HIGHEST
166 BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
167 EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem)
168 EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced)
171 /*****************************************************************************
173 *****************************************************************************/
174 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent)
175 : wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition,
176 wxSize(700,450), wxDEFAULT_FRAME_STYLE )
178 /* Initializations */
180 SetIcon( *p_intf->p_sys->p_icon );
182 /* Create a panel to put everything in */
183 wxPanel *panel = new wxPanel( this, -1 );
184 panel->SetAutoLayout( TRUE );
186 /* Create the preferences tree control */
187 wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL );
189 new PrefsTreeCtrl( panel, p_intf, this, controls_sizer );
192 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
194 /* Create the buttons */
195 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
196 ok_button->SetDefault();
197 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
199 wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("Save")) );
200 wxButton *reset_button = new wxButton( panel, ResetAll_Event,
201 wxU(_("Reset All")) );
203 wxPanel *dummy_panel = new wxPanel( this, -1 );
204 wxCheckBox *advanced_checkbox =
205 new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) );
207 if( config_GetInt( p_intf, "advanced" ) )
209 advanced_checkbox->SetValue(TRUE);
210 wxCommandEvent dummy_event;
211 dummy_event.SetInt(TRUE);
212 OnAdvanced( dummy_event );
215 /* Place everything in sizers */
216 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
217 button_sizer->Add( ok_button, 0, wxALL, 5 );
218 button_sizer->Add( cancel_button, 0, wxALL, 5 );
219 button_sizer->Add( save_button, 0, wxALL, 5 );
220 button_sizer->Add( reset_button, 0, wxALL, 5 );
221 button_sizer->Add( dummy_panel, 1, wxALL, 5 );
222 button_sizer->Add( advanced_checkbox, 0, wxALL | wxALIGN_RIGHT |
223 wxALIGN_CENTER_VERTICAL, 0 );
224 button_sizer->Layout();
226 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
227 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
228 panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 );
229 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
230 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
231 wxALL | wxEXPAND, 5 );
232 panel_sizer->Layout();
233 panel->SetSizer( panel_sizer );
234 main_sizer->Add( panel, 1, wxEXPAND, 0 );
235 main_sizer->Layout();
236 SetSizer( main_sizer );
239 PrefsDialog::~PrefsDialog()
243 /*****************************************************************************
245 *****************************************************************************/
248 /*****************************************************************************
250 *****************************************************************************/
251 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
253 prefs_tree->ApplyChanges();
255 prefs_tree->CleanChanges();
258 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
261 prefs_tree->CleanChanges();
264 void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
266 prefs_tree->ApplyChanges();
267 config_SaveConfigFile( p_intf, NULL );
271 void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
273 wxMessageDialog dlg( this,
274 wxU(_("Beware this will reset your VLC Media Player config file.\n"
275 "Are you sure you want to continue?")),
276 wxU(_("Reset config file")), wxYES_NO|wxNO_DEFAULT|wxCENTRE );
278 if ( dlg.ShowModal() == wxID_YES )
280 /* TODO: need to reset all the controls */
281 config_ResetAll( p_intf );
282 prefs_tree->CleanChanges();
283 config_SaveConfigFile( p_intf, NULL );
287 void PrefsDialog::OnAdvanced( wxCommandEvent& event )
289 wxCommandEvent newevent( wxEVT_USER_FIRST, Advanced_Event );
290 newevent.SetInt( event.GetInt() );
292 prefs_tree->AddPendingEvent( newevent );
295 /*****************************************************************************
296 * GetCapabilityHelp: Display the help for one capability.
297 *****************************************************************************/
298 static char * GetCapabilityHelp( char *psz_capability, int i_type)
300 if( psz_capability == NULL) return "";
302 if( !strcasecmp(psz_capability,"access") )
303 return i_type == 1 ? ACCESS_TITLE : ACCESS_HELP;
304 if( !strcasecmp(psz_capability,"audio filter") )
305 return i_type == 1 ? AUDIO_FILTER_TITLE : AUDIO_FILTER_HELP;
306 if( !strcasecmp(psz_capability,"audio output") )
307 return i_type == 1 ? AOUT_TITLE : AOUT_HELP;
308 if( !strcasecmp(psz_capability,"audio encoder") )
309 return i_type == 1 ? AOUT_ENC_TITLE : AOUT_ENC_HELP;
310 if( !strcasecmp(psz_capability,"chroma") )
311 return i_type == 1 ? CHROMA_TITLE : CHROMA_HELP;
312 if( !strcasecmp(psz_capability,"decoder") )
313 return i_type == 1 ? DECODER_TITLE : DECODER_HELP;
314 if( !strcasecmp(psz_capability,"demux") )
315 return i_type == 1 ? DEMUX_TITLE : DEMUX_HELP;
316 if( !strcasecmp(psz_capability,"interface") )
317 return i_type == 1 ? INTERFACE_TITLE : INTERFACE_HELP;
318 if( !strcasecmp(psz_capability,"sout access") )
319 return i_type == 1 ? SOUT_TITLE : SOUT_HELP;
320 if( !strcasecmp(psz_capability,"subtitle demux") )
321 return i_type == 1 ? SUBTITLE_DEMUX_TITLE : SUBTITLE_DEMUX_HELP;
322 if( !strcasecmp(psz_capability,"text renderer") )
323 return i_type == 1 ? TEXT_TITLE : TEXT_HELP;
324 if( !strcasecmp(psz_capability,"video output") )
325 return i_type == 1 ? VOUT__TITLE : VOUT_HELP;
326 if( !strcasecmp(psz_capability,"video filter") )
327 return i_type == 1 ? VIDEO_FILTER_TITLE : VIDEO_FILTER_HELP;
332 /*****************************************************************************
333 * PrefsTreeCtrl class definition.
334 *****************************************************************************/
335 PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
336 PrefsDialog *_p_prefs_dialog,
337 wxBoxSizer *_p_sizer )
338 : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxDefaultSize,
339 wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT |
340 wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT |
341 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER )
345 module_config_t *p_item;
348 /* Initializations */
350 p_prefs_dialog = _p_prefs_dialog;
352 p_parent = _p_parent;
353 b_advanced = VLC_FALSE;
355 root_item = AddRoot( wxT("") );
357 /* List the plugins */
358 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
359 if( !p_list ) return;
362 * Build a tree of the main options
364 ConfigTreeData *config_data = new ConfigTreeData;
365 config_data->psz_section = NULL;
366 config_data->i_object_id = GENERAL_ID;
367 config_data->psz_help = wraptext( GENERAL_HELP, WRAPCOUNT, ISUTF8 );
368 config_data->psz_section = strdup( GENERAL_TITLE );
369 general_item = AppendItem( root_item, wxU(_("General Settings")),
370 -1, -1, config_data );
372 for( i_index = 0; i_index < p_list->i_count; i_index++ )
374 p_module = (module_t *)p_list->p_values[i_index].p_object;
375 if( !strcmp( p_module->psz_object_name, "main" ) )
378 if( i_index < p_list->i_count )
380 /* We found the main module */
382 /* Enumerate config categories and store a reference so we can
383 * generate their config panel them when it is asked by the user. */
384 p_item = p_module->p_config;
388 switch( p_item->i_type )
390 case CONFIG_HINT_CATEGORY:
391 ConfigTreeData *config_data = new ConfigTreeData;
392 config_data->psz_section = strdup(p_item->psz_text);
393 if( p_item->psz_longtext )
395 config_data->psz_help =
396 wraptext( p_item->psz_longtext, WRAPCOUNT, ISUTF8 );
400 config_data->psz_help = NULL;
402 config_data->i_object_id = p_module->i_object_id;
404 /* Add the category to the tree */
405 AppendItem( general_item, wxU(p_item->psz_text),
406 -1, -1, config_data );
410 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
412 SortChildren( general_item );
417 * Build a tree of all the plugins
419 config_data = new ConfigTreeData;
420 config_data->psz_section = NULL;
421 config_data->i_object_id = PLUGIN_ID;
422 config_data->psz_help = wraptext( PLUGIN_HELP, WRAPCOUNT, ISUTF8 );
423 config_data->psz_section = strdup( PLUGIN_TITLE );
424 plugins_item = AppendItem( root_item, wxU(_("Plugins")),
427 for( i_index = 0; i_index < p_list->i_count; i_index++ )
429 p_module = (module_t *)p_list->p_values[i_index].p_object;
431 /* Exclude the main module */
432 if( !strcmp( p_module->psz_object_name, "main" ) )
435 /* Exclude empty plugins (submodules don't have config options, they
436 * are stored in the parent module) */
437 if( p_module->b_submodule )
438 p_item = ((module_t *)p_module->p_parent)->p_config;
440 p_item = p_module->p_config;
442 if( !p_item ) continue;
445 if( p_item->i_type & CONFIG_ITEM )
448 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
449 if( p_item->i_type == CONFIG_HINT_END ) continue;
451 /* Find the capability child item */
452 long cookie; size_t i_child_index;
453 wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);
454 for( i_child_index = 0;
455 i_child_index < GetChildrenCount( plugins_item, FALSE );
458 if( !GetItemText(capability_item).Cmp(
459 wxU(p_module->psz_capability ) ) )
463 capability_item = GetNextChild( plugins_item, cookie );
466 if( i_child_index == GetChildrenCount( plugins_item, FALSE ) &&
467 p_module->psz_capability && *p_module->psz_capability )
469 /* We didn't find it, add it */
470 ConfigTreeData *config_data = new ConfigTreeData;
471 config_data->psz_section =
472 wraptext( GetCapabilityHelp( p_module->psz_capability , 1 ),
474 config_data->psz_help =
475 wraptext( GetCapabilityHelp( p_module->psz_capability , 2 ),
477 config_data->i_object_id = CAPABILITY_ID;
478 capability_item = AppendItem( plugins_item,
479 wxU(p_module->psz_capability),
483 /* Add the plugin to the tree */
484 ConfigTreeData *config_data = new ConfigTreeData;
485 config_data->b_submodule = p_module->b_submodule;
486 config_data->i_object_id = p_module->b_submodule ?
487 ((module_t *)p_module->p_parent)->i_object_id :
488 p_module->i_object_id;
489 config_data->psz_help = NULL;
490 AppendItem( capability_item, wxU(p_module->psz_object_name), -1, -1,
494 /* Sort all this mess */
495 long cookie; size_t i_child_index;
496 SortChildren( plugins_item );
497 wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);
498 for( i_child_index = 0;
499 i_child_index < GetChildrenCount( plugins_item, FALSE );
502 capability_item = GetNextChild( plugins_item, cookie );
503 SortChildren( capability_item );
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 ) );
517 Expand( general_item );
520 PrefsTreeCtrl::~PrefsTreeCtrl()
524 void PrefsTreeCtrl::ApplyChanges()
526 long cookie, cookie2;
527 ConfigTreeData *config_data;
529 /* Apply changes to the main module */
530 wxTreeItemId item = GetFirstChild( general_item, cookie );
531 for( size_t i_child_index = 0;
532 i_child_index < GetChildrenCount( general_item, FALSE );
535 config_data = (ConfigTreeData *)GetItemData( item );
536 if( config_data && config_data->panel )
538 config_data->panel->ApplyChanges();
541 item = GetNextChild( general_item, cookie );
544 /* Apply changes to the plugins */
545 item = GetFirstChild( plugins_item, cookie );
546 for( size_t i_child_index = 0;
547 i_child_index < GetChildrenCount( plugins_item, FALSE );
550 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
551 for( size_t i_child_index = 0;
552 i_child_index < GetChildrenCount( item, FALSE );
555 config_data = (ConfigTreeData *)GetItemData( item2 );
556 if( config_data && config_data->panel )
558 config_data->panel->ApplyChanges();
561 item2 = GetNextChild( item, cookie2 );
564 item = GetNextChild( plugins_item, cookie );
568 void PrefsTreeCtrl::CleanChanges()
570 long cookie, cookie2;
571 ConfigTreeData *config_data;
573 config_data = !GetSelection() ? NULL :
574 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
577 config_data->panel->Hide();
578 p_sizer->Remove( config_data->panel );
581 /* Clean changes for the main module */
582 wxTreeItemId item = GetFirstChild( general_item, cookie );
583 for( size_t i_child_index = 0;
584 i_child_index < GetChildrenCount( general_item, FALSE );
587 config_data = (ConfigTreeData *)GetItemData( item );
588 if( config_data && config_data->panel )
590 delete config_data->panel;
591 config_data->panel = NULL;
594 item = GetNextChild( general_item, cookie );
597 /* Clean changes for the plugins */
598 item = GetFirstChild( plugins_item, cookie );
599 for( size_t i_child_index = 0;
600 i_child_index < GetChildrenCount( plugins_item, FALSE );
603 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
604 for( size_t i_child_index = 0;
605 i_child_index < GetChildrenCount( item, FALSE );
608 config_data = (ConfigTreeData *)GetItemData( item2 );
610 if( config_data && config_data->panel )
612 delete config_data->panel;
613 config_data->panel = NULL;
616 item2 = GetNextChild( item, cookie2 );
619 item = GetNextChild( plugins_item, cookie );
625 OnSelectTreeItem( event );
629 ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
631 /* We need this complexity because submodules don't have their own config
632 * options. They use the parent module ones. */
634 if( !config_data || !config_data->b_submodule )
639 long cookie, cookie2;
640 ConfigTreeData *config_new;
641 wxTreeItemId item = GetFirstChild( plugins_item, cookie );
642 for( size_t i_child_index = 0;
643 i_child_index < GetChildrenCount( plugins_item, FALSE );
646 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
647 for( size_t i_child_index = 0;
648 i_child_index < GetChildrenCount( item, FALSE );
651 config_new = (ConfigTreeData *)GetItemData( item2 );
652 if( config_new && !config_new->b_submodule &&
653 config_new->i_object_id == config_data->i_object_id )
658 item2 = GetNextChild( item, cookie2 );
661 item = GetNextChild( plugins_item, cookie );
668 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
670 ConfigTreeData *config_data;
672 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
673 event.GetOldItem() ) );
674 if( config_data && config_data->panel )
676 config_data->panel->Hide();
677 p_sizer->Remove( config_data->panel );
680 /* Don't use event.GetItem() because we also send fake events */
681 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
685 if( !config_data->panel )
687 /* The panel hasn't been created yet. Let's do it. */
689 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
690 config_data->i_object_id,
691 config_data->psz_section,
692 config_data->psz_help );
693 config_data->panel->SwitchAdvanced( b_advanced );
697 config_data->panel->SwitchAdvanced( b_advanced );
698 config_data->panel->Show();
701 p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );
706 void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event )
708 b_advanced = event.GetInt();
710 ConfigTreeData *config_data = !GetSelection() ? NULL :
711 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
714 config_data->panel->Hide();
715 p_sizer->Remove( config_data->panel );
721 OnSelectTreeItem( event );
725 /*****************************************************************************
726 * PrefsPanel class definition.
727 *****************************************************************************/
728 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
729 PrefsDialog *_p_prefs_dialog,
730 int i_object_id, char *psz_section, char *psz_help )
731 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
733 module_config_t *p_item;
739 module_t *p_module = NULL;
741 /* Initializations */
743 p_prefs_dialog =_p_prefs_dialog,
745 b_advanced = VLC_TRUE;
746 SetAutoLayout( TRUE );
748 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
751 if( i_object_id == PLUGIN_ID || i_object_id == GENERAL_ID ||
752 i_object_id == CAPABILITY_ID )
754 label = new wxStaticText( this, -1,wxU(_( psz_section )));
755 wxFont heading_font = label->GetFont();
756 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
757 label->SetFont( heading_font );
758 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
759 sizer->Add( new wxStaticLine( this, 0 ), 0,
760 wxEXPAND | wxLEFT | wxRIGHT, 2 );
762 help = new wxStaticText( this, -1, wxU(_( psz_help ) ) );
763 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
765 config_sizer = NULL; config_window = NULL;
769 /* Get a pointer to the module */
770 p_module = (module_t *)vlc_object_get( p_intf, i_object_id );
771 if( p_module->i_object_type != VLC_OBJECT_MODULE )
773 /* 0OOoo something went really bad */
777 /* Enumerate config options and add corresponding config boxes
778 * (submodules don't have config options, they are stored in the
780 if( p_module->b_submodule )
781 p_item = ((module_t *)p_module->p_parent)->p_config;
783 p_item = p_module->p_config;
785 /* Find the category if it has been specified */
786 if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY )
788 while( !p_item->i_type == CONFIG_HINT_CATEGORY ||
789 strcmp( psz_section, p_item->psz_text ) )
791 if( p_item->i_type == CONFIG_HINT_END )
797 /* Add a head title to the panel */
798 label = new wxStaticText( this, -1,
799 wxU(_(psz_section ? p_item->psz_text :
800 p_module->psz_longname )));
801 wxFont heading_font = label->GetFont();
802 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
803 label->SetFont( heading_font );
804 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
805 sizer->Add( new wxStaticLine( this, 0 ), 0,
806 wxEXPAND | wxLEFT | wxRIGHT, 2 );
808 /* Now put all the config options into a scrolled window */
809 config_sizer = new wxBoxSizer( wxVERTICAL );
810 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
811 wxDefaultSize, wxSTATIC_BORDER | wxHSCROLL | wxVSCROLL );
812 config_window->SetAutoLayout( TRUE );
813 config_window->SetScrollRate( 5, 5 );
817 /* If a category has been specified, check we finished the job */
818 if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY &&
819 strcmp( psz_section, p_item->psz_text ) )
822 ConfigControl *control =
823 CreateConfigControl( VLC_OBJECT(p_intf),
824 p_item, config_window );
826 /* Don't add items that were not recognized */
827 if( control == NULL ) continue;
829 /* Add the config data to our array so we can keep a trace of it */
830 config_array.Add( control );
832 config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
834 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
836 config_sizer->Layout();
837 config_window->SetSizer( config_sizer );
838 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
840 /* And at last put a useful help string if available */
841 if( psz_help && *psz_help )
843 sizer->Add( new wxStaticLine( this, 0 ), 0,
844 wxEXPAND | wxLEFT | wxRIGHT, 2 );
845 help = new wxStaticText( this, -1, wxU(_(psz_help)),
846 wxDefaultPosition, wxDefaultSize,
849 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
857 void PrefsPanel::ApplyChanges()
861 for( size_t i = 0; i < config_array.GetCount(); i++ )
863 ConfigControl *control = config_array.Item(i);
865 switch( control->GetType() )
867 case CONFIG_ITEM_STRING:
868 case CONFIG_ITEM_FILE:
869 case CONFIG_ITEM_DIRECTORY:
870 case CONFIG_ITEM_MODULE:
871 config_PutPsz( p_intf, control->GetName().mb_str(),
872 control->GetPszValue().mb_str() );
874 case CONFIG_ITEM_KEY:
875 /* So you don't need to restart to have the changes take effect */
876 val.i_int = control->GetIntValue();
877 var_Set( p_intf->p_vlc, control->GetName().mb_str(), val );
878 case CONFIG_ITEM_INTEGER:
879 case CONFIG_ITEM_BOOL:
880 config_PutInt( p_intf, control->GetName().mb_str(),
881 control->GetIntValue() );
883 case CONFIG_ITEM_FLOAT:
884 config_PutFloat( p_intf, control->GetName().mb_str(),
885 control->GetFloatValue() );
891 void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
893 if( b_advanced == b_new_advanced ) return;
895 if( config_sizer && config_window )
897 b_advanced = b_new_advanced;
899 for( size_t i = 0; i < config_array.GetCount(); i++ )
901 ConfigControl *control = config_array.Item(i);
902 if( control->IsAdvanced() )
904 control->Show( b_advanced );
905 config_sizer->Show( control, b_advanced );
909 config_sizer->Layout();
910 config_window->FitInside();
911 config_window->Refresh();