1 /*****************************************************************************
2 * preferences.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
5 * $Id: preferences.cpp,v 1.46 2004/01/25 03:29:01 hartman 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"
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 GENERAL_ID 1242
50 #define PLUGIN_ID 1243
51 #define CAPABILITY_ID 1244
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 general_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 *, int i_object_id, char *, char * );
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 wxBoxSizer *config_sizer;
110 wxScrolledWindow *config_window;
112 ArrayOfConfigControls config_array;
115 class ConfigTreeData : public wxTreeItemData
119 ConfigTreeData() { b_submodule = 0; panel = NULL; psz_section = NULL;
121 virtual ~ConfigTreeData() { if( panel ) delete panel;
122 if( psz_section) free(psz_section);
123 if( psz_help) free(psz_help); }
125 vlc_bool_t b_submodule;
134 /*****************************************************************************
136 *****************************************************************************/
138 /* IDs for the controls and the menu commands */
141 Notebook_Event = wxID_HIGHEST,
147 BEGIN_EVENT_TABLE(PrefsDialog, wxFrame)
149 EVT_BUTTON(wxID_OK, PrefsDialog::OnOk)
150 EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel)
151 EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave)
152 EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll)
153 EVT_CHECKBOX(Advanced_Event, PrefsDialog::OnAdvanced)
155 /* Don't destroy the window when the user closes it */
156 EVT_CLOSE(PrefsDialog::OnCancel)
159 // menu and control ids
162 PrefsTree_Ctrl = wxID_HIGHEST
165 BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
166 EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem)
167 EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced)
170 /*****************************************************************************
172 *****************************************************************************/
173 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent)
174 : wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition,
175 wxSize(700,450), wxDEFAULT_FRAME_STYLE )
177 /* Initializations */
179 SetIcon( *p_intf->p_sys->p_icon );
181 /* Create a panel to put everything in */
182 wxPanel *panel = new wxPanel( this, -1 );
183 panel->SetAutoLayout( TRUE );
185 /* Create the preferences tree control */
186 wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL );
188 new PrefsTreeCtrl( panel, p_intf, this, controls_sizer );
191 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
193 /* Create the buttons */
194 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
195 ok_button->SetDefault();
196 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
198 wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("Save")) );
199 wxButton *reset_button = new wxButton( panel, ResetAll_Event,
200 wxU(_("Reset All")) );
202 wxPanel *dummy_panel = new wxPanel( this, -1 );
203 wxCheckBox *advanced_checkbox =
204 new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) );
206 if( config_GetInt( p_intf, "advanced" ) )
208 advanced_checkbox->SetValue(TRUE);
209 wxCommandEvent dummy_event;
210 dummy_event.SetInt(TRUE);
211 OnAdvanced( dummy_event );
214 /* Place everything in sizers */
215 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
216 button_sizer->Add( ok_button, 0, wxALL, 5 );
217 button_sizer->Add( cancel_button, 0, wxALL, 5 );
218 button_sizer->Add( save_button, 0, wxALL, 5 );
219 button_sizer->Add( reset_button, 0, wxALL, 5 );
220 button_sizer->Add( dummy_panel, 1, wxALL, 5 );
221 button_sizer->Add( advanced_checkbox, 0, wxALL | wxALIGN_RIGHT |
222 wxALIGN_CENTER_VERTICAL, 0 );
223 button_sizer->Layout();
225 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
226 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
227 panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 );
228 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
229 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
230 wxALL | wxEXPAND, 5 );
231 panel_sizer->Layout();
232 panel->SetSizer( panel_sizer );
233 main_sizer->Add( panel, 1, wxEXPAND, 0 );
234 main_sizer->Layout();
235 SetSizer( main_sizer );
238 PrefsDialog::~PrefsDialog()
242 /*****************************************************************************
244 *****************************************************************************/
247 /*****************************************************************************
249 *****************************************************************************/
250 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
252 prefs_tree->ApplyChanges();
254 prefs_tree->CleanChanges();
257 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
260 prefs_tree->CleanChanges();
263 void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
265 prefs_tree->ApplyChanges();
266 config_SaveConfigFile( p_intf, NULL );
270 void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
272 wxMessageDialog dlg( this,
273 wxU(_("Beware this will reset your VLC media player preferences.\n"
274 "Are you sure you want to continue?")),
275 wxU(_("Reset Preferences")), wxYES_NO|wxNO_DEFAULT|wxCENTRE );
277 if ( dlg.ShowModal() == wxID_YES )
279 /* TODO: need to reset all the controls */
280 config_ResetAll( p_intf );
281 prefs_tree->CleanChanges();
282 config_SaveConfigFile( p_intf, NULL );
286 void PrefsDialog::OnAdvanced( wxCommandEvent& event )
288 wxCommandEvent newevent( wxEVT_USER_FIRST, Advanced_Event );
289 newevent.SetInt( event.GetInt() );
291 prefs_tree->AddPendingEvent( newevent );
294 /*****************************************************************************
295 * GetCapabilityHelp: Display the help for one capability.
296 *****************************************************************************/
297 static char * GetCapabilityHelp( char *psz_capability, int i_type)
299 if( psz_capability == NULL) return "";
301 if( !strcasecmp(psz_capability,"access") )
302 return i_type == 1 ? ACCESS_TITLE : ACCESS_HELP;
303 if( !strcasecmp(psz_capability,"audio filter") )
304 return i_type == 1 ? AUDIO_FILTER_TITLE : AUDIO_FILTER_HELP;
305 if( !strcasecmp(psz_capability,"audio output") )
306 return i_type == 1 ? AOUT_TITLE : AOUT_HELP;
307 if( !strcasecmp(psz_capability,"audio encoder") )
308 return i_type == 1 ? AOUT_ENC_TITLE : AOUT_ENC_HELP;
309 if( !strcasecmp(psz_capability,"chroma") )
310 return i_type == 1 ? CHROMA_TITLE : CHROMA_HELP;
311 if( !strcasecmp(psz_capability,"decoder") )
312 return i_type == 1 ? DECODER_TITLE : DECODER_HELP;
313 if( !strcasecmp(psz_capability,"demux") )
314 return i_type == 1 ? DEMUX_TITLE : DEMUX_HELP;
315 if( !strcasecmp(psz_capability,"interface") )
316 return i_type == 1 ? INTERFACE_TITLE : INTERFACE_HELP;
317 if( !strcasecmp(psz_capability,"sout access") )
318 return i_type == 1 ? SOUT_TITLE : SOUT_HELP;
319 if( !strcasecmp(psz_capability,"subtitle demux") )
320 return i_type == 1 ? SUBTITLE_DEMUX_TITLE : SUBTITLE_DEMUX_HELP;
321 if( !strcasecmp(psz_capability,"text renderer") )
322 return i_type == 1 ? TEXT_TITLE : TEXT_HELP;
323 if( !strcasecmp(psz_capability,"video output") )
324 return i_type == 1 ? VOUT__TITLE : VOUT_HELP;
325 if( !strcasecmp(psz_capability,"video filter") )
326 return i_type == 1 ? VIDEO_FILTER_TITLE : VIDEO_FILTER_HELP;
331 /*****************************************************************************
332 * PrefsTreeCtrl class definition.
333 *****************************************************************************/
334 PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
335 PrefsDialog *_p_prefs_dialog,
336 wxBoxSizer *_p_sizer )
337 : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxDefaultSize,
338 wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT |
339 wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT |
340 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER )
344 module_config_t *p_item;
347 /* Initializations */
349 p_prefs_dialog = _p_prefs_dialog;
351 p_parent = _p_parent;
352 b_advanced = VLC_FALSE;
354 root_item = AddRoot( wxT("") );
356 /* List the plugins */
357 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
358 if( !p_list ) return;
361 * Build a tree of the main options
363 ConfigTreeData *config_data = new ConfigTreeData;
364 config_data->i_object_id = GENERAL_ID;
365 config_data->psz_help = wraptext( GENERAL_HELP, 72 , 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, 72 , 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->i_object_id = PLUGIN_ID;
419 config_data->psz_help = wraptext( PLUGIN_HELP, 72, ISUTF8 );
420 config_data->psz_section = strdup( PLUGIN_TITLE );
421 plugins_item = AppendItem( root_item, wxU(_("Modules")),
422 -1, -1,config_data );
424 for( i_index = 0; i_index < p_list->i_count; i_index++ )
426 p_module = (module_t *)p_list->p_values[i_index].p_object;
428 /* Exclude the main module */
429 if( !strcmp( p_module->psz_object_name, "main" ) )
432 /* Exclude empty plugins (submodules don't have config options, they
433 * are stored in the parent module) */
434 if( p_module->b_submodule )
435 p_item = ((module_t *)p_module->p_parent)->p_config;
437 p_item = p_module->p_config;
439 if( !p_item ) continue;
442 if( p_item->i_type & CONFIG_ITEM )
445 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
446 if( p_item->i_type == CONFIG_HINT_END ) continue;
448 /* Find the capability child item */
449 long cookie; size_t i_child_index;
450 wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);
451 for( i_child_index = 0;
452 i_child_index < GetChildrenCount( plugins_item, FALSE );
455 if( !GetItemText(capability_item).Cmp(
456 wxU(p_module->psz_capability ) ) )
460 capability_item = GetNextChild( plugins_item, cookie );
463 if( i_child_index == GetChildrenCount( plugins_item, FALSE ) &&
464 p_module->psz_capability && *p_module->psz_capability )
466 /* We didn't find it, add it */
467 ConfigTreeData *config_data = new ConfigTreeData;
468 config_data->psz_section =
469 wraptext( GetCapabilityHelp( p_module->psz_capability , 1 ),
471 config_data->psz_help =
472 wraptext( GetCapabilityHelp( p_module->psz_capability , 2 ),
474 config_data->i_object_id = CAPABILITY_ID;
475 capability_item = AppendItem( plugins_item,
476 wxU(p_module->psz_capability),
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_object_id = p_module->b_submodule ?
484 ((module_t *)p_module->p_parent)->i_object_id :
485 p_module->i_object_id;
486 config_data->psz_help = NULL;
487 AppendItem( capability_item, wxU(p_module->psz_object_name), -1, -1,
491 /* Sort all this mess */
492 long cookie; size_t i_child_index;
493 SortChildren( plugins_item );
494 wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);
495 for( i_child_index = 0;
496 i_child_index < GetChildrenCount( plugins_item, FALSE );
499 capability_item = GetNextChild( plugins_item, cookie );
500 SortChildren( capability_item );
503 /* Clean-up everything */
504 vlc_list_release( p_list );
506 p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );
509 /* Update Tree Ctrl */
510 #ifndef WIN32 /* Workaround a bug in win32 implementation */
511 SelectItem( GetFirstChild( root_item, cookie ) );
514 Expand( general_item );
517 PrefsTreeCtrl::~PrefsTreeCtrl()
521 void PrefsTreeCtrl::ApplyChanges()
523 long cookie, cookie2;
524 ConfigTreeData *config_data;
526 /* Apply changes to the main module */
527 wxTreeItemId item = GetFirstChild( general_item, cookie );
528 for( size_t i_child_index = 0;
529 i_child_index < GetChildrenCount( general_item, FALSE );
532 config_data = (ConfigTreeData *)GetItemData( item );
533 if( config_data && config_data->panel )
535 config_data->panel->ApplyChanges();
538 item = GetNextChild( general_item, cookie );
541 /* Apply changes to the plugins */
542 item = GetFirstChild( plugins_item, cookie );
543 for( size_t i_child_index = 0;
544 i_child_index < GetChildrenCount( plugins_item, FALSE );
547 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
548 for( size_t i_child_index = 0;
549 i_child_index < GetChildrenCount( item, FALSE );
552 config_data = (ConfigTreeData *)GetItemData( item2 );
553 if( config_data && config_data->panel )
555 config_data->panel->ApplyChanges();
558 item2 = GetNextChild( item, cookie2 );
561 item = GetNextChild( plugins_item, cookie );
565 void PrefsTreeCtrl::CleanChanges()
567 long cookie, cookie2;
568 ConfigTreeData *config_data;
570 config_data = !GetSelection() ? NULL :
571 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
574 config_data->panel->Hide();
575 p_sizer->Remove( config_data->panel );
578 /* Clean changes for the main module */
579 wxTreeItemId item = GetFirstChild( general_item, cookie );
580 for( size_t i_child_index = 0;
581 i_child_index < GetChildrenCount( general_item, FALSE );
584 config_data = (ConfigTreeData *)GetItemData( item );
585 if( config_data && config_data->panel )
587 delete config_data->panel;
588 config_data->panel = NULL;
591 item = GetNextChild( general_item, cookie );
594 /* Clean changes for the plugins */
595 item = GetFirstChild( plugins_item, cookie );
596 for( size_t i_child_index = 0;
597 i_child_index < GetChildrenCount( plugins_item, FALSE );
600 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
601 for( size_t i_child_index = 0;
602 i_child_index < GetChildrenCount( item, FALSE );
605 config_data = (ConfigTreeData *)GetItemData( item2 );
607 if( config_data && config_data->panel )
609 delete config_data->panel;
610 config_data->panel = NULL;
613 item2 = GetNextChild( item, cookie2 );
616 item = GetNextChild( plugins_item, cookie );
622 OnSelectTreeItem( event );
626 ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
628 /* We need this complexity because submodules don't have their own config
629 * options. They use the parent module ones. */
631 if( !config_data || !config_data->b_submodule )
636 long cookie, cookie2;
637 ConfigTreeData *config_new;
638 wxTreeItemId item = GetFirstChild( plugins_item, cookie );
639 for( size_t i_child_index = 0;
640 i_child_index < GetChildrenCount( plugins_item, FALSE );
643 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
644 for( size_t i_child_index = 0;
645 i_child_index < GetChildrenCount( item, FALSE );
648 config_new = (ConfigTreeData *)GetItemData( item2 );
649 if( config_new && !config_new->b_submodule &&
650 config_new->i_object_id == config_data->i_object_id )
655 item2 = GetNextChild( item, cookie2 );
658 item = GetNextChild( plugins_item, cookie );
665 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
667 ConfigTreeData *config_data;
669 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
670 event.GetOldItem() ) );
671 if( config_data && config_data->panel )
673 config_data->panel->Hide();
674 p_sizer->Remove( config_data->panel );
677 /* Don't use event.GetItem() because we also send fake events */
678 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
682 if( !config_data->panel )
684 /* The panel hasn't been created yet. Let's do it. */
686 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
687 config_data->i_object_id,
688 config_data->psz_section,
689 config_data->psz_help );
690 config_data->panel->SwitchAdvanced( b_advanced );
694 config_data->panel->SwitchAdvanced( b_advanced );
695 config_data->panel->Show();
698 p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );
703 void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event )
705 b_advanced = event.GetInt();
707 ConfigTreeData *config_data = !GetSelection() ? NULL :
708 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
711 config_data->panel->Hide();
712 p_sizer->Remove( config_data->panel );
718 OnSelectTreeItem( event );
722 /*****************************************************************************
723 * PrefsPanel class definition.
724 *****************************************************************************/
725 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
726 PrefsDialog *_p_prefs_dialog,
727 int i_object_id, char *psz_section, char *psz_help )
728 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
730 module_config_t *p_item;
736 module_t *p_module = NULL;
738 /* Initializations */
740 p_prefs_dialog =_p_prefs_dialog,
742 b_advanced = VLC_TRUE;
743 SetAutoLayout( TRUE );
745 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
748 if( i_object_id == PLUGIN_ID || i_object_id == GENERAL_ID ||
749 i_object_id == CAPABILITY_ID )
751 label = new wxStaticText( this, -1,wxU(_( psz_section )));
752 wxFont heading_font = label->GetFont();
753 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
754 label->SetFont( heading_font );
755 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
756 sizer->Add( new wxStaticLine( this, 0 ), 0,
757 wxEXPAND | wxLEFT | wxRIGHT, 2 );
759 help = new wxStaticText( this, -1, wxU(_( psz_help ) ) );
760 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
762 config_sizer = NULL; config_window = NULL;
766 /* Get a pointer to the module */
767 p_module = (module_t *)vlc_object_get( p_intf, i_object_id );
768 if( p_module->i_object_type != VLC_OBJECT_MODULE )
770 /* 0OOoo something went really bad */
774 /* Enumerate config options and add corresponding config boxes
775 * (submodules don't have config options, they are stored in the
777 if( p_module->b_submodule )
778 p_item = ((module_t *)p_module->p_parent)->p_config;
780 p_item = p_module->p_config;
782 /* Find the category if it has been specified */
783 if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY )
785 while( !p_item->i_type == CONFIG_HINT_CATEGORY ||
786 strcmp( psz_section, p_item->psz_text ) )
788 if( p_item->i_type == CONFIG_HINT_END )
794 /* Add a head title to the panel */
795 label = new wxStaticText( this, -1,
796 wxU(_(psz_section ? p_item->psz_text :
797 p_module->psz_longname )));
798 wxFont heading_font = label->GetFont();
799 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
800 label->SetFont( heading_font );
801 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
802 sizer->Add( new wxStaticLine( this, 0 ), 0,
803 wxEXPAND | wxLEFT | wxRIGHT, 2 );
805 /* Now put all the config options into a scrolled window */
806 config_sizer = new wxBoxSizer( wxVERTICAL );
807 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
808 wxDefaultSize, wxSTATIC_BORDER | wxHSCROLL | wxVSCROLL );
809 config_window->SetAutoLayout( TRUE );
810 config_window->SetScrollRate( 5, 5 );
814 /* If a category has been specified, check we finished the job */
815 if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY &&
816 strcmp( psz_section, p_item->psz_text ) )
819 ConfigControl *control =
820 CreateConfigControl( VLC_OBJECT(p_intf),
821 p_item, config_window );
823 /* Don't add items that were not recognized */
824 if( control == NULL ) continue;
826 /* Add the config data to our array so we can keep a trace of it */
827 config_array.Add( control );
829 config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
831 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
833 config_sizer->Layout();
834 config_window->SetSizer( config_sizer );
835 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
837 /* And at last put a useful help string if available */
838 if( psz_help && *psz_help )
840 sizer->Add( new wxStaticLine( this, 0 ), 0,
841 wxEXPAND | wxLEFT | wxRIGHT, 2 );
842 help = new wxStaticText( this, -1, wxU(_(psz_help)),
843 wxDefaultPosition, wxDefaultSize,
846 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
854 void PrefsPanel::ApplyChanges()
858 for( size_t i = 0; i < config_array.GetCount(); i++ )
860 ConfigControl *control = config_array.Item(i);
862 switch( control->GetType() )
864 case CONFIG_ITEM_STRING:
865 case CONFIG_ITEM_FILE:
866 case CONFIG_ITEM_DIRECTORY:
867 case CONFIG_ITEM_MODULE:
868 config_PutPsz( p_intf, control->GetName().mb_str(),
869 control->GetPszValue().mb_str() );
871 case CONFIG_ITEM_KEY:
872 /* So you don't need to restart to have the changes take effect */
873 val.i_int = control->GetIntValue();
874 var_Set( p_intf->p_vlc, control->GetName().mb_str(), val );
875 case CONFIG_ITEM_INTEGER:
876 case CONFIG_ITEM_BOOL:
877 config_PutInt( p_intf, control->GetName().mb_str(),
878 control->GetIntValue() );
880 case CONFIG_ITEM_FLOAT:
881 config_PutFloat( p_intf, control->GetName().mb_str(),
882 control->GetFloatValue() );
888 void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
890 if( b_advanced == b_new_advanced ) return;
892 if( config_sizer && config_window )
894 b_advanced = b_new_advanced;
896 for( size_t i = 0; i < config_array.GetCount(); i++ )
898 ConfigControl *control = config_array.Item(i);
899 if( control->IsAdvanced() )
901 control->Show( b_advanced );
902 config_sizer->Show( control, b_advanced );
906 config_sizer->Layout();
907 config_window->FitInside();
908 config_window->Refresh();