1 /*****************************************************************************
2 * preferences.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: preferences.cpp,v 1.39 2003/10/29 01:33:27 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,"chroma") )
309 return i_type == 1 ? CHROMA_TITLE : CHROMA_HELP;
310 if( !strcasecmp(psz_capability,"decoder") )
311 return i_type == 1 ? DECODER_TITLE : DECODER_HELP;
312 if( !strcasecmp(psz_capability,"demux") )
313 return i_type == 1 ? DEMUX_TITLE : DEMUX_HELP;
314 if( !strcasecmp(psz_capability,"interface") )
315 return i_type == 1 ? INTERFACE_TITLE : INTERFACE_HELP;
316 if( !strcasecmp(psz_capability,"sout access") )
317 return i_type == 1 ? SOUT_TITLE : SOUT_HELP;
318 if( !strcasecmp(psz_capability,"subtitle demux") )
319 return i_type == 1 ? SUBTITLE_DEMUX_TITLE : SUBTITLE_DEMUX_HELP;
320 if( !strcasecmp(psz_capability,"text renderer") )
321 return i_type == 1 ? TEXT_TITLE : TEXT_HELP;
322 if( !strcasecmp(psz_capability,"video output") )
323 return i_type == 1 ? VOUT__TITLE : VOUT_HELP;
324 if( !strcasecmp(psz_capability,"video filter") )
325 return i_type == 1 ? VIDEO_FILTER_TITLE : VIDEO_FILTER_HELP;
330 /*****************************************************************************
331 * PrefsTreeCtrl class definition.
332 *****************************************************************************/
333 PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
334 PrefsDialog *_p_prefs_dialog,
335 wxBoxSizer *_p_sizer )
336 : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxDefaultSize,
337 wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT |
338 wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT |
339 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER )
343 module_config_t *p_item;
346 /* Initializations */
348 p_prefs_dialog = _p_prefs_dialog;
350 p_parent = _p_parent;
351 b_advanced = VLC_FALSE;
353 root_item = AddRoot( wxT("") );
355 /* List the plugins */
356 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
357 if( !p_list ) return;
360 * Build a tree of the main options
362 ConfigTreeData *config_data = new ConfigTreeData;
363 config_data->psz_section = NULL;
364 config_data->i_object_id = GENERAL_ID;
365 config_data->psz_help = wraptext( GENERAL_HELP, WRAPCOUNT, ISUTF8 );
366 config_data->psz_section = strdup( GENERAL_TITLE );
367 general_item = AppendItem( root_item, wxU(_("General Settings")),
368 -1, -1, config_data );
370 for( i_index = 0; i_index < p_list->i_count; i_index++ )
372 p_module = (module_t *)p_list->p_values[i_index].p_object;
373 if( !strcmp( p_module->psz_object_name, "main" ) )
376 if( i_index < p_list->i_count )
378 /* We found the main module */
380 /* Enumerate config categories and store a reference so we can
381 * generate their config panel them when it is asked by the user. */
382 p_item = p_module->p_config;
386 switch( p_item->i_type )
388 case CONFIG_HINT_CATEGORY:
389 ConfigTreeData *config_data = new ConfigTreeData;
390 config_data->psz_section = strdup(p_item->psz_text);
391 if( p_item->psz_longtext )
393 config_data->psz_help =
394 wraptext( p_item->psz_longtext, WRAPCOUNT, ISUTF8 );
398 config_data->psz_help = NULL;
400 config_data->i_object_id = p_module->i_object_id;
402 /* Add the category to the tree */
403 AppendItem( general_item, wxU(p_item->psz_text),
404 -1, -1, config_data );
408 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
410 SortChildren( general_item );
415 * Build a tree of all the plugins
417 config_data = new ConfigTreeData;
418 config_data->psz_section = NULL;
419 config_data->i_object_id = PLUGIN_ID;
420 config_data->psz_help = wraptext( PLUGIN_HELP, WRAPCOUNT, ISUTF8 );
421 config_data->psz_section = strdup( PLUGIN_TITLE );
422 plugins_item = AppendItem( root_item, wxU(_("Plugins")),
425 for( i_index = 0; i_index < p_list->i_count; i_index++ )
427 p_module = (module_t *)p_list->p_values[i_index].p_object;
429 /* Exclude the main module */
430 if( !strcmp( p_module->psz_object_name, "main" ) )
433 /* Exclude empty plugins (submodules don't have config options, they
434 * are stored in the parent module) */
435 if( p_module->b_submodule )
436 p_item = ((module_t *)p_module->p_parent)->p_config;
438 p_item = p_module->p_config;
440 if( !p_item ) continue;
443 if( p_item->i_type & CONFIG_ITEM )
446 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
447 if( p_item->i_type == CONFIG_HINT_END ) continue;
449 /* Find the capability child item */
450 long cookie; size_t i_child_index;
451 wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);
452 for( i_child_index = 0;
453 i_child_index < GetChildrenCount( plugins_item, FALSE );
456 if( !GetItemText(capability_item).Cmp(
457 wxU(p_module->psz_capability ) ) )
461 capability_item = GetNextChild( plugins_item, cookie );
464 if( i_child_index == GetChildrenCount( plugins_item, FALSE ) &&
465 p_module->psz_capability && *p_module->psz_capability )
467 /* We didn't find it, add it */
468 ConfigTreeData *config_data = new ConfigTreeData;
469 config_data->psz_section =
470 wraptext( GetCapabilityHelp( p_module->psz_capability , 1 ),
472 config_data->psz_help =
473 wraptext( GetCapabilityHelp( p_module->psz_capability , 2 ),
475 config_data->i_object_id = CAPABILITY_ID;
476 capability_item = AppendItem( plugins_item,
477 wxU(p_module->psz_capability),
481 /* Add the plugin to the tree */
482 ConfigTreeData *config_data = new ConfigTreeData;
483 config_data->b_submodule = p_module->b_submodule;
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;
488 AppendItem( capability_item, wxU(p_module->psz_object_name), -1, -1,
492 /* Sort all this mess */
493 long cookie; size_t i_child_index;
494 SortChildren( plugins_item );
495 wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);
496 for( i_child_index = 0;
497 i_child_index < GetChildrenCount( plugins_item, FALSE );
500 capability_item = GetNextChild( plugins_item, cookie );
501 SortChildren( capability_item );
504 /* Clean-up everything */
505 vlc_list_release( p_list );
507 p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );
510 /* Update Tree Ctrl */
511 #ifndef WIN32 /* Workaround a bug in win32 implementation */
512 SelectItem( GetFirstChild( root_item, cookie ) );
515 Expand( general_item );
518 PrefsTreeCtrl::~PrefsTreeCtrl()
522 void PrefsTreeCtrl::ApplyChanges()
524 long cookie, cookie2;
525 ConfigTreeData *config_data;
527 /* Apply changes to the main module */
528 wxTreeItemId item = GetFirstChild( general_item, cookie );
529 for( size_t i_child_index = 0;
530 i_child_index < GetChildrenCount( general_item, FALSE );
533 config_data = (ConfigTreeData *)GetItemData( item );
534 if( config_data && config_data->panel )
536 config_data->panel->ApplyChanges();
539 item = GetNextChild( general_item, cookie );
542 /* Apply changes to the plugins */
543 item = GetFirstChild( plugins_item, cookie );
544 for( size_t i_child_index = 0;
545 i_child_index < GetChildrenCount( plugins_item, FALSE );
548 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
549 for( size_t i_child_index = 0;
550 i_child_index < GetChildrenCount( item, FALSE );
553 config_data = (ConfigTreeData *)GetItemData( item2 );
554 if( config_data && config_data->panel )
556 config_data->panel->ApplyChanges();
559 item2 = GetNextChild( item, cookie2 );
562 item = GetNextChild( plugins_item, cookie );
566 void PrefsTreeCtrl::CleanChanges()
568 long cookie, cookie2;
569 ConfigTreeData *config_data;
571 config_data = !GetSelection() ? NULL :
572 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
575 config_data->panel->Hide();
576 p_sizer->Remove( config_data->panel );
579 /* Clean changes for the main module */
580 wxTreeItemId item = GetFirstChild( general_item, cookie );
581 for( size_t i_child_index = 0;
582 i_child_index < GetChildrenCount( general_item, FALSE );
585 config_data = (ConfigTreeData *)GetItemData( item );
586 if( config_data && config_data->panel )
588 delete config_data->panel;
589 config_data->panel = NULL;
592 item = GetNextChild( general_item, cookie );
595 /* Clean changes for the plugins */
596 item = GetFirstChild( plugins_item, cookie );
597 for( size_t i_child_index = 0;
598 i_child_index < GetChildrenCount( plugins_item, FALSE );
601 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
602 for( size_t i_child_index = 0;
603 i_child_index < GetChildrenCount( item, FALSE );
606 config_data = (ConfigTreeData *)GetItemData( item2 );
608 if( config_data && config_data->panel )
610 delete config_data->panel;
611 config_data->panel = NULL;
614 item2 = GetNextChild( item, cookie2 );
617 item = GetNextChild( plugins_item, cookie );
623 OnSelectTreeItem( event );
627 ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
629 /* We need this complexity because submodules don't have their own config
630 * options. They use the parent module ones. */
632 if( !config_data || !config_data->b_submodule )
637 long cookie, cookie2;
638 ConfigTreeData *config_new;
639 wxTreeItemId item = GetFirstChild( plugins_item, cookie );
640 for( size_t i_child_index = 0;
641 i_child_index < GetChildrenCount( plugins_item, FALSE );
644 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
645 for( size_t i_child_index = 0;
646 i_child_index < GetChildrenCount( item, FALSE );
649 config_new = (ConfigTreeData *)GetItemData( item2 );
650 if( config_new && !config_new->b_submodule &&
651 config_new->i_object_id == config_data->i_object_id )
656 item2 = GetNextChild( item, cookie2 );
659 item = GetNextChild( plugins_item, cookie );
666 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
668 ConfigTreeData *config_data;
670 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
671 event.GetOldItem() ) );
672 if( config_data && config_data->panel )
674 config_data->panel->Hide();
675 p_sizer->Remove( config_data->panel );
678 /* Don't use event.GetItem() because we also send fake events */
679 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
683 if( !config_data->panel )
685 /* The panel hasn't been created yet. Let's do it. */
687 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
688 config_data->i_object_id,
689 config_data->psz_section,
690 config_data->psz_help );
691 config_data->panel->SwitchAdvanced( b_advanced );
695 config_data->panel->SwitchAdvanced( b_advanced );
696 config_data->panel->Show();
699 p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );
704 void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event )
706 b_advanced = event.GetInt();
708 ConfigTreeData *config_data = !GetSelection() ? NULL :
709 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
712 config_data->panel->Hide();
713 p_sizer->Remove( config_data->panel );
719 OnSelectTreeItem( event );
723 /*****************************************************************************
724 * PrefsPanel class definition.
725 *****************************************************************************/
726 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
727 PrefsDialog *_p_prefs_dialog,
728 int i_object_id, char *psz_section, char *psz_help )
729 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
731 module_config_t *p_item;
737 module_t *p_module = NULL;
739 /* Initializations */
741 p_prefs_dialog =_p_prefs_dialog,
743 b_advanced = VLC_TRUE;
744 SetAutoLayout( TRUE );
746 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
749 if( i_object_id == PLUGIN_ID || i_object_id == GENERAL_ID ||
750 i_object_id == CAPABILITY_ID )
752 label = new wxStaticText( this, -1,wxU(_( psz_section )));
753 wxFont heading_font = label->GetFont();
754 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
755 label->SetFont( heading_font );
756 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
757 sizer->Add( new wxStaticLine( this, 0 ), 0,
758 wxEXPAND | wxLEFT | wxRIGHT, 2 );
760 help = new wxStaticText( this, -1, wxU(_( psz_help ) ) );
761 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
763 config_sizer = NULL; config_window = NULL;
767 /* Get a pointer to the module */
768 p_module = (module_t *)vlc_object_get( p_intf, i_object_id );
769 if( p_module->i_object_type != VLC_OBJECT_MODULE )
771 /* 0OOoo something went really bad */
775 /* Enumerate config options and add corresponding config boxes
776 * (submodules don't have config options, they are stored in the
778 if( p_module->b_submodule )
779 p_item = ((module_t *)p_module->p_parent)->p_config;
781 p_item = p_module->p_config;
783 /* Find the category if it has been specified */
784 if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY )
786 while( !p_item->i_type == CONFIG_HINT_CATEGORY ||
787 strcmp( psz_section, p_item->psz_text ) )
789 if( p_item->i_type == CONFIG_HINT_END )
795 /* Add a head title to the panel */
796 label = new wxStaticText( this, -1,
797 wxU(_(psz_section ? p_item->psz_text :
798 p_module->psz_longname )));
799 wxFont heading_font = label->GetFont();
800 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
801 label->SetFont( heading_font );
802 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
803 sizer->Add( new wxStaticLine( this, 0 ), 0,
804 wxEXPAND | wxLEFT | wxRIGHT, 2 );
806 /* Now put all the config options into a scrolled window */
807 config_sizer = new wxBoxSizer( wxVERTICAL );
808 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
809 wxDefaultSize, wxSTATIC_BORDER | wxHSCROLL | wxVSCROLL );
810 config_window->SetAutoLayout( TRUE );
811 config_window->SetScrollRate( 5, 5 );
815 /* If a category has been specified, check we finished the job */
816 if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY &&
817 strcmp( psz_section, p_item->psz_text ) )
820 ConfigControl *control =
821 CreateConfigControl( VLC_OBJECT(p_intf),
822 p_item, config_window );
824 /* Don't add items that were not recognized */
825 if( control == NULL ) continue;
827 /* Add the config data to our array so we can keep a trace of it */
828 config_array.Add( control );
830 config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
832 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
834 config_sizer->Layout();
835 config_window->SetSizer( config_sizer );
836 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
838 /* And at last put a useful help string if available */
839 if( psz_help && *psz_help )
841 sizer->Add( new wxStaticLine( this, 0 ), 0,
842 wxEXPAND | wxLEFT | wxRIGHT, 2 );
843 help = new wxStaticText( this, -1, wxU(_(psz_help)),
844 wxDefaultPosition, wxDefaultSize,
847 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
855 void PrefsPanel::ApplyChanges()
859 for( size_t i = 0; i < config_array.GetCount(); i++ )
861 ConfigControl *control = config_array.Item(i);
863 switch( control->GetType() )
865 case CONFIG_ITEM_STRING:
866 case CONFIG_ITEM_FILE:
867 case CONFIG_ITEM_DIRECTORY:
868 case CONFIG_ITEM_MODULE:
869 config_PutPsz( p_intf, control->GetName().mb_str(),
870 control->GetPszValue().mb_str() );
872 case CONFIG_ITEM_KEY:
873 /* So you don't need to restart to have the changes take effect */
874 val.i_int = control->GetIntValue();
875 var_Set( p_intf->p_vlc, control->GetName().mb_str(), val );
876 case CONFIG_ITEM_INTEGER:
877 case CONFIG_ITEM_BOOL:
878 config_PutInt( p_intf, control->GetName().mb_str(),
879 control->GetIntValue() );
881 case CONFIG_ITEM_FLOAT:
882 config_PutFloat( p_intf, control->GetName().mb_str(),
883 control->GetFloatValue() );
889 void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
891 if( b_advanced == b_new_advanced ) return;
893 if( config_sizer && config_window )
895 b_advanced = b_new_advanced;
897 for( size_t i = 0; i < config_array.GetCount(); i++ )
899 ConfigControl *control = config_array.Item(i);
900 if( control->IsAdvanced() )
902 control->Show( b_advanced );
903 config_sizer->Show( control, b_advanced );
907 config_sizer->Layout();
908 config_window->FitInside();
909 config_window->Refresh();