1 /*****************************************************************************
2 * preferences.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include "dialogs/preferences.hpp"
29 #include <vlc_config_cat.h>
30 #include "dialogs/preferences_widgets.h"
32 #include <wx/combobox.h>
33 #include <wx/statline.h>
34 #include <wx/clntdata.h>
35 #include <wx/dynarray.h>
36 #include <wx/imaglist.h>
37 #include <wx/treectrl.h>
39 #include "bitmaps/type_net.xpm"
40 #include "bitmaps/codec.xpm"
41 #include "bitmaps/video.xpm"
42 #include "bitmaps/type_playlist.xpm"
43 #include "bitmaps/advanced.xpm"
44 #include "bitmaps/intf.xpm"
45 #include "bitmaps/audio.xpm"
48 # define wxRB_SINGLE 0
51 #define TYPE_CATEGORY 0
52 #define TYPE_CATSUBCAT 1 /* Category with embedded subcategory */
53 #define TYPE_SUBCATEGORY 2
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;
89 wxTreeItemId root_item;
90 wxTreeItemId plugins_item;
93 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
95 class PrefsPanel : public wxPanel
100 PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
101 PrefsDialog *, ConfigTreeData* );
102 virtual ~PrefsPanel() {}
105 void SwitchAdvanced( vlc_bool_t );
108 intf_thread_t *p_intf;
109 PrefsDialog *p_prefs_dialog;
111 vlc_bool_t b_advanced;
113 wxStaticText *hidden_text;
114 wxBoxSizer *config_sizer;
115 wxScrolledWindow *config_window;
117 ArrayOfConfigControls config_array;
120 class ConfigTreeData : public wxTreeItemData
124 ConfigTreeData() { b_submodule = 0; panel = NULL; psz_name = NULL;
126 virtual ~ConfigTreeData() {
127 if( panel ) delete panel;
128 if( psz_name ) free( psz_name );
129 if( psz_help ) free( psz_help );
132 vlc_bool_t b_submodule;
144 /*****************************************************************************
146 *****************************************************************************/
148 /* IDs for the controls and the menu commands */
151 Notebook_Event = wxID_HIGHEST,
157 BEGIN_EVENT_TABLE(PrefsDialog, wxFrame)
159 EVT_BUTTON(wxID_OK, PrefsDialog::OnOk)
160 EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel)
161 EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave)
162 EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll)
163 EVT_CHECKBOX(Advanced_Event, PrefsDialog::OnAdvanced)
165 /* Don't destroy the window when the user closes it */
166 EVT_CLOSE(PrefsDialog::OnClose)
169 // menu and control ids
172 PrefsTree_Ctrl = wxID_HIGHEST
175 BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
176 EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem)
177 EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced)
180 /*****************************************************************************
182 *****************************************************************************/
183 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent)
184 : wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition,
185 wxSize(700,450), wxDEFAULT_FRAME_STYLE )
187 /* Initializations */
189 SetIcon( *p_intf->p_sys->p_icon );
191 /* Create a panel to put everything in */
192 wxPanel *panel = new wxPanel( this, -1 );
193 panel->SetAutoLayout( TRUE );
195 /* Create the preferences tree control */
196 wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL );
198 new PrefsTreeCtrl( panel, p_intf, this, controls_sizer );
201 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
204 /* Create the buttons */
205 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
206 ok_button->SetDefault();
208 wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("&Save")) );
209 save_button->SetDefault();
210 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
212 wxButton *reset_button = new wxButton( panel, ResetAll_Event,
213 wxU(_("Reset All")) );
215 wxPanel *dummy_panel = new wxPanel( this, -1 );
216 wxCheckBox *advanced_checkbox =
217 new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) );
219 if( config_GetInt( p_intf, "advanced" ) )
221 advanced_checkbox->SetValue(TRUE);
222 wxCommandEvent dummy_event;
223 dummy_event.SetInt(TRUE);
224 OnAdvanced( dummy_event );
227 /* Place everything in sizers */
228 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
230 button_sizer->Add( ok_button, 0, wxALL, 5 );
232 button_sizer->Add( save_button, 0, wxALL, 5 );
233 button_sizer->Add( cancel_button, 0, wxALL, 5 );
234 button_sizer->Add( reset_button, 0, wxALL, 5 );
235 button_sizer->Add( dummy_panel, 1, wxALL, 5 );
236 button_sizer->Add( advanced_checkbox, 0, wxALL | wxALIGN_RIGHT |
237 wxALIGN_CENTER_VERTICAL, 0 );
238 button_sizer->Layout();
240 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
241 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
242 panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 );
243 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
244 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
245 wxALL | wxEXPAND, 5 );
246 panel_sizer->Layout();
247 panel->SetSizer( panel_sizer );
248 main_sizer->Add( panel, 1, wxEXPAND, 0 );
249 main_sizer->Layout();
250 SetSizer( main_sizer );
253 PrefsDialog::~PrefsDialog()
257 /*****************************************************************************
259 *****************************************************************************/
262 /*****************************************************************************
264 *****************************************************************************/
265 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
267 prefs_tree->ApplyChanges();
269 prefs_tree->CleanChanges();
272 void PrefsDialog::OnClose( wxCloseEvent& WXUNUSED(event) )
274 wxCommandEvent cevent;
278 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
281 prefs_tree->CleanChanges();
284 void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
286 prefs_tree->ApplyChanges();
287 config_SaveConfigFile( p_intf, NULL );
291 void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
293 wxMessageDialog dlg( this,
294 wxU(_("This will reset your VLC media player preferences.\n"
295 "Are you sure you want to continue?")),
296 wxU(_("Reset Preferences")), wxYES_NO|wxNO_DEFAULT|wxCENTRE );
298 if ( dlg.ShowModal() == wxID_YES )
300 /* TODO: need to reset all the controls */
301 config_ResetAll( p_intf );
302 prefs_tree->CleanChanges();
303 config_SaveConfigFile( p_intf, NULL );
307 void PrefsDialog::OnAdvanced( wxCommandEvent& event )
309 wxCommandEvent newevent( wxEVT_USER_FIRST, Advanced_Event );
310 newevent.SetInt( event.GetInt() );
312 prefs_tree->AddPendingEvent( newevent );
315 /*****************************************************************************
316 * PrefsTreeCtrl class definition.
317 *****************************************************************************/
318 PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
319 PrefsDialog *_p_prefs_dialog,
320 wxBoxSizer *_p_sizer )
321 : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxSize(200,-1),
322 wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT |
323 wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT |
324 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER )
326 vlc_list_t *p_list = NULL;;
328 module_config_t *p_item, *p_end;
329 int i_index, i_image=0;
331 /* Initializations */
333 p_prefs_dialog = _p_prefs_dialog;
335 p_parent = _p_parent;
336 b_advanced = VLC_FALSE;
338 root_item = AddRoot( wxT("") );
339 wxASSERT_MSG(root_item.IsOk(), wxT("Could not add root item"));
341 wxImageList *p_images = new wxImageList( 16,16,TRUE );
342 p_images->Add( wxIcon( audio_xpm ) );
343 p_images->Add( wxIcon( video_xpm ) );
344 p_images->Add( wxIcon( codec_xpm ) );
345 p_images->Add( wxIcon( type_net_xpm ) );
346 p_images->Add( wxIcon( advanced_xpm ) );
347 p_images->Add( wxIcon( type_playlist_xpm ) );
348 p_images->Add( wxIcon( intf_xpm ) );
349 AssignImageList( p_images );
351 /* List the plugins */
352 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
353 if( !p_list ) return;
355 /* Build the categories list */
356 for( i_index = 0; i_index < p_list->i_count; i_index++ )
358 p_module = (module_t *)p_list->p_values[i_index].p_object;
359 if( !strcmp( module_GetObjName(p_module), "main" ) )
362 if( i_index < p_list->i_count )
364 wxTreeItemId current_item;
365 const char *psz_help;
366 unsigned int i_confsize;
367 module_config_t *p_config;
369 /* We found the main module */
371 /* Enumerate config categories and store a reference so we can
372 * generate their config panel them when it is asked by the user. */
374 p_config = module_GetConfig( p_module, &i_confsize );
375 for( size_t i = 0; i < i_confsize; i++ )
377 module_config_t *p_item = p_config + i;
378 ConfigTreeData *config_data;
379 switch( p_item->i_type )
381 case CONFIG_CATEGORY:
382 if( p_item->value.i == -1 ) break; // Don't display it
384 config_data = new ConfigTreeData;
385 config_data->psz_name = strdup( config_CategoryNameGet(
387 psz_help = config_CategoryHelpGet( p_item->value.i );
390 config_data->psz_help = wraptext( strdup( psz_help ), 72 );
394 config_data->psz_help = NULL;
396 config_data->i_type = TYPE_CATEGORY;
397 config_data->i_object_id = p_item->value.i;
399 /* Add the category to the tree */
400 switch( p_item->value.i )
417 current_item = AppendItem( root_item,
418 wxU( _(config_data->psz_name) ),
419 i_image, -1, config_data );
422 case CONFIG_SUBCATEGORY:
423 if( p_item->value.i == -1 ) break; // Don't display it
424 /* Special case: move the "general" subcategories to their
426 if( p_item->value.i == SUBCAT_VIDEO_GENERAL ||
427 p_item->value.i == SUBCAT_ADVANCED_MISC ||
428 p_item->value.i == SUBCAT_INPUT_GENERAL ||
429 p_item->value.i == SUBCAT_INTERFACE_GENERAL ||
430 p_item->value.i == SUBCAT_SOUT_GENERAL||
431 p_item->value.i == SUBCAT_PLAYLIST_GENERAL||
432 p_item->value.i == SUBCAT_AUDIO_GENERAL )
434 ConfigTreeData *cd = (ConfigTreeData *)
435 GetItemData( current_item );
436 cd->i_type = TYPE_CATSUBCAT;
437 cd->i_subcat_id = p_item->value.i;
438 if( cd->psz_name ) free( cd->psz_name );
439 cd->psz_name = strdup( config_CategoryNameGet(
441 if( cd->psz_help ) free( cd->psz_help );
442 const char *psz_help = config_CategoryHelpGet( p_item->value.i );
445 cd->psz_help = wraptext( strdup( psz_help ), 72 );
454 config_data = new ConfigTreeData;
456 config_data->psz_name = strdup( config_CategoryNameGet(
458 psz_help = config_CategoryHelpGet( p_item->value.i );
461 config_data->psz_help = wraptext( strdup( psz_help ), 72 );
465 config_data->psz_help = NULL;
467 config_data->i_type = TYPE_SUBCATEGORY;
468 config_data->i_object_id = p_item->value.i;
469 /* WXMSW doesn't know image -1 ... FIXME */
471 switch( p_item->value.i / 100 )
491 AppendItem( current_item, wxU( _(config_data->psz_name) ),
492 i_image, -1, config_data );
497 module_PutConfig( p_config );
502 * Build a tree of all the plugins
504 for( i_index = 0; i_index < p_list->i_count; i_index++ )
506 int i_category = -1, i_subcategory = -1, i_options = 0;
507 unsigned int i_confsize;
508 module_config_t *p_config;
510 p_module = (module_t *)p_list->p_values[i_index].p_object;
512 /* Exclude the main module */
513 if( !strcmp( module_GetObjName(p_module), "main" ) )
516 /* Exclude empty plugins (submodules don't have config options, they
517 * are stored in the parent module) */
518 if( module_IsSubModule(p_module) )
521 p_config = module_GetConfig( p_module, &i_confsize );
522 for( size_t i = 0; i < i_confsize; i++ )
524 module_config_t *p_item = p_config + i;
525 if( p_item->i_type == CONFIG_CATEGORY )
527 i_category = p_item->value.i;
529 else if( p_item->i_type == CONFIG_SUBCATEGORY )
531 i_subcategory = p_item->value.i;
533 if( p_item->i_type & CONFIG_ITEM )
535 if( i_options > 0 && i_category >= 0 && i_subcategory >= 0 )
541 if( !i_options ) continue;
543 /* Find the right category item */
544 wxTreeItemIdValue cookie;
545 vlc_bool_t b_found = VLC_FALSE;
547 wxTreeItemId category_item = GetFirstChild( root_item , cookie);
548 while( category_item.IsOk() )
550 ConfigTreeData *config_data =
551 (ConfigTreeData *)GetItemData( category_item );
552 if( config_data->i_object_id == i_category )
557 category_item = GetNextChild( root_item, cookie );
559 if( !b_found ) continue;
561 /* Find subcategory item */
564 wxTreeItemId subcategory_item = GetFirstChild( category_item, cookie );
565 while( subcategory_item.IsOk() )
567 ConfigTreeData *config_data =
568 (ConfigTreeData *)GetItemData( subcategory_item );
569 if( config_data->i_object_id == i_subcategory )
574 subcategory_item = GetNextChild( category_item, cookie );
578 subcategory_item = category_item;
581 /* Add the plugin to the tree */
582 ConfigTreeData *config_data = new ConfigTreeData;
584 config_data->b_submodule = module_IsSubModule(p_module);
586 config_data->i_type = TYPE_MODULE;
587 config_data->i_object_id = config_data->b_submodule ?
588 ((vlc_object_t *)p_module)->p_parent->i_object_id :
589 ((vlc_object_t *)p_module)->i_object_id;
590 config_data->psz_help = NULL;
592 /* WXMSW doesn't know image -1 ... FIXME */
594 switch( i_subcategory / 100 )
614 AppendItem( subcategory_item, wxU( module_GetName(p_module, 0) ),
615 i_image, -1, config_data );
618 /* Sort all this mess */
619 wxTreeItemIdValue cookie;
620 size_t i_child_index;
621 wxTreeItemId capability_item = GetFirstChild( root_item, cookie);
622 for( i_child_index = 0;
623 (capability_item.IsOk() &&
624 //(i_child_index < GetChildrenCount( plugins_item, FALSE )));
625 (i_child_index < GetChildrenCount( root_item, FALSE )));
628 SortChildren( capability_item );
629 //capability_item = GetNextChild( plugins_item, cookie );
630 capability_item = GetNextChild( root_item, cookie );
633 /* Clean-up everything */
634 vlc_list_release( p_list );
636 p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );
641 /* Update Tree Ctrl */
642 #ifndef WIN32 /* Workaround a bug in win32 implementation */
643 SelectItem( GetFirstChild( root_item, cookie ) );
646 //cannot expand hidden root item
647 //Expand( root_item );
650 PrefsTreeCtrl::~PrefsTreeCtrl(){
653 void PrefsTreeCtrl::ApplyChanges()
655 wxTreeItemIdValue cookie, cookie2, cookie3;
656 ConfigTreeData *config_data;
658 wxTreeItemId category = GetFirstChild( root_item, cookie );
659 while( category.IsOk() )
661 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
662 while( subcategory.IsOk() )
664 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
665 while( module.IsOk() )
667 config_data = (ConfigTreeData *)GetItemData( module );
668 if( config_data && config_data->panel )
670 config_data->panel->ApplyChanges();
672 module = GetNextChild( subcategory, cookie3 );
674 config_data = (ConfigTreeData *)GetItemData( subcategory );
675 if( config_data && config_data->panel )
677 config_data->panel->ApplyChanges();
679 subcategory = GetNextChild( category, cookie2 );
681 config_data = (ConfigTreeData *)GetItemData( category );
682 if( config_data && config_data->panel )
684 config_data->panel->ApplyChanges();
686 category = GetNextChild( root_item, cookie );
690 void PrefsTreeCtrl::CleanChanges()
692 wxTreeItemIdValue cookie, cookie2, cookie3;
693 ConfigTreeData *config_data;
695 config_data = !GetSelection() ? NULL :
696 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
699 config_data->panel->Hide();
700 #if (wxCHECK_VERSION(2,5,0))
701 p_sizer->Detach( config_data->panel );
703 p_sizer->Remove( config_data->panel );
708 wxTreeItemId category = GetFirstChild( root_item, cookie );
709 while( category.IsOk() )
711 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
712 while( subcategory.IsOk() )
714 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
715 while( module.IsOk() )
717 config_data = (ConfigTreeData *)GetItemData( module );
718 if( config_data && config_data->panel )
720 delete config_data->panel;
721 config_data->panel = NULL;
723 module = GetNextChild( subcategory, cookie3 );
725 config_data = (ConfigTreeData *)GetItemData( subcategory );
726 if( config_data && config_data->panel )
728 delete config_data->panel;
729 config_data->panel = NULL;
731 subcategory = GetNextChild( category, cookie2 );
733 config_data = (ConfigTreeData *)GetItemData( category );
734 if( config_data && config_data->panel )
736 delete config_data->panel;
737 config_data->panel = NULL;
739 category = GetNextChild( root_item, cookie );
745 OnSelectTreeItem( event );
749 ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
751 /* We need this complexity because submodules don't have their own config
752 * options. They use the parent module ones. */
754 if( !config_data || !config_data->b_submodule )
759 wxTreeItemIdValue cookie, cookie2, cookie3;
760 ConfigTreeData *config_new;
761 wxTreeItemId category = GetFirstChild( root_item, cookie );
762 while( category.IsOk() )
764 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
765 while( subcategory.IsOk() )
767 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
768 while( module.IsOk() )
770 config_new = (ConfigTreeData *)GetItemData( module );
771 if( config_new && !config_new->b_submodule &&
772 config_new->i_object_id == config_data->i_object_id )
776 module = GetNextChild( subcategory, cookie3 );
778 subcategory = GetNextChild( category, cookie2 );
780 category = GetNextChild( root_item, cookie );
787 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
789 ConfigTreeData *config_data = NULL;
794 #if (wxCHECK_VERSION(2,5,0))
795 p_sizer->Detach( p_current );
797 p_sizer->Remove( p_current );
802 /* Don't use event.GetItem() because we also send fake events */
803 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
807 if( !config_data->panel )
809 /* The panel hasn't been created yet. Let's do it. */
811 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
813 config_data->panel->SwitchAdvanced( b_advanced );
817 config_data->panel->SwitchAdvanced( b_advanced );
818 config_data->panel->Show();
821 p_current = config_data->panel;
823 p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );
828 void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event )
830 b_advanced = event.GetInt();
832 ConfigTreeData *config_data = !GetSelection() ? NULL :
833 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
836 config_data->panel->Hide();
837 #if (wxCHECK_VERSION(2,5,0))
838 p_sizer->Detach( config_data->panel );
840 p_sizer->Remove( config_data->panel );
848 OnSelectTreeItem( event );
852 /*****************************************************************************
853 * PrefsPanel class definition.
854 *****************************************************************************/
855 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
856 PrefsDialog *_p_prefs_dialog,
857 ConfigTreeData *config_data )
858 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
860 module_config_t *p_item, *p_start, *p_end;
861 unsigned int i_confsize;
862 vlc_list_t *p_list = NULL;;
868 module_t *p_module = NULL;
870 /* Initializations */
872 p_prefs_dialog =_p_prefs_dialog,
874 b_advanced = VLC_TRUE;
875 SetAutoLayout( TRUE );
878 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
881 if( config_data->i_type == TYPE_CATEGORY )
883 label = new wxStaticText( this, -1,wxU(_( config_data->psz_name )));
884 wxFont heading_font = label->GetFont();
885 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
886 label->SetFont( heading_font );
887 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
888 sizer->Add( new wxStaticLine( this, 0 ), 0,
889 wxEXPAND | wxLEFT | wxRIGHT, 2 );
892 help = new wxStaticText( this, -1, wxU(_( config_data->psz_help ) ) );
893 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
895 config_sizer = NULL; config_window = NULL;
899 /* Get a pointer to the module */
900 if( config_data->i_type == TYPE_MODULE )
902 p_module = (module_t *)
903 vlc_object_get( config_data->i_object_id );
907 /* List the plugins */
909 vlc_bool_t b_found = VLC_FALSE;
910 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
911 if( !p_list ) return;
913 for( i_index = 0; i_index < p_list->i_count; i_index++ )
915 p_module = (module_t *)p_list->p_values[i_index].p_object;
916 if( !strcmp( module_GetObjName(p_module), "main" ) )
922 if( !p_module && !b_found )
924 msg_Warn( p_intf, "unable to create preferences "
925 "(main module not found)" );
930 /* Enumerate config options and add corresponding config boxes
931 * (submodules don't have config options, they are stored in the
934 if( module_IsSubModule(p_module) )
935 p_start = module_GetConfig((module_t *)(((vlc_object_t *)p_module)->p_parent), &i_confsize);
938 p_start = module_GetConfig(p_module, &i_confsize);
941 p_end = p_start + i_confsize;
943 /* Find the category if it has been specified */
944 if( config_data->i_type == TYPE_SUBCATEGORY ||
945 config_data->i_type == TYPE_CATSUBCAT )
947 for( ; p_item && p_item < p_end; p_item++ )
949 if( p_item->i_type == CONFIG_SUBCATEGORY &&
950 ( config_data->i_type == TYPE_SUBCATEGORY &&
951 p_item->value.i == config_data->i_object_id ) ||
952 ( config_data->i_type == TYPE_CATSUBCAT &&
953 p_item->value.i == config_data->i_subcat_id ) )
960 /* Add a head title to the panel */
961 const char *psz_head;
962 if( config_data->i_type == TYPE_SUBCATEGORY ||
963 config_data->i_type == TYPE_CATSUBCAT )
965 psz_head = config_data->psz_name;
970 psz_head = module_GetLongName(p_module);
973 label = new wxStaticText( this, -1,
974 wxU(_( psz_head ? psz_head : _("Unknown") ) ) );
975 wxFont heading_font = label->GetFont();
976 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
977 label->SetFont( heading_font );
978 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
979 sizer->Add( new wxStaticLine( this, 0 ), 0,
980 wxEXPAND | wxLEFT | wxRIGHT, 2 );
982 /* Now put all the config options into a scrolled window */
983 config_sizer = new wxBoxSizer( wxVERTICAL );
984 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
985 wxDefaultSize, wxBORDER_NONE | wxHSCROLL | wxVSCROLL );
986 config_window->SetAutoLayout( TRUE );
987 config_window->SetScrollRate( 5, 5 );
989 for( ; p_item && p_item < p_end; p_item++ )
991 /* If a category has been specified, check we finished the job */
992 if( ( ( config_data->i_type == TYPE_SUBCATEGORY &&
993 p_item->value.i != config_data->i_object_id ) ||
994 ( config_data->i_type == TYPE_CATSUBCAT &&
995 p_item->value.i != config_data->i_subcat_id ) ) &&
996 (p_item->i_type == CONFIG_CATEGORY ||
997 p_item->i_type == CONFIG_SUBCATEGORY ) )
1000 ConfigControl *control =
1001 CreateConfigControl( VLC_OBJECT(p_intf),
1002 p_item, config_window );
1004 /* Don't add items that were not recognized */
1005 if( control == NULL ) continue;
1007 /* Add the config data to our array so we can keep a trace of it */
1008 config_array.Add( control );
1010 config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
1013 module_PutConfig( p_start );
1015 config_sizer->Layout();
1016 config_window->SetSizer( config_sizer );
1017 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
1018 hidden_text = new wxStaticText( this, -1,
1019 wxU( _( "Some options are available but hidden. " \
1020 "Check \"Advanced options\" to see them." ) ) );
1021 sizer->Add( hidden_text );
1023 /* And at last put a useful help string if available */
1024 if( config_data->psz_help && *config_data->psz_help )
1026 sizer->Add( new wxStaticLine( this, 0 ), 0,
1027 wxEXPAND | wxLEFT | wxRIGHT, 2 );
1028 help = new wxStaticText( this, -1, wxU(_(config_data->psz_help)),
1029 wxDefaultPosition, wxDefaultSize,
1032 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
1035 if( config_data->i_type == TYPE_MODULE )
1037 module_Put( p_module );
1041 vlc_list_release( p_list );
1049 void PrefsPanel::ApplyChanges()
1053 for( size_t i = 0; i < config_array.GetCount(); i++ )
1055 ConfigControl *control = config_array.Item(i);
1057 switch( control->GetType() )
1059 case CONFIG_ITEM_STRING:
1060 case CONFIG_ITEM_FILE:
1061 case CONFIG_ITEM_DIRECTORY:
1062 case CONFIG_ITEM_MODULE:
1063 case CONFIG_ITEM_MODULE_CAT:
1064 case CONFIG_ITEM_MODULE_LIST:
1065 case CONFIG_ITEM_MODULE_LIST_CAT:
1066 config_PutPsz( p_intf, control->GetName().mb_str(wxConvUTF8),
1067 control->GetPszValue().mb_str(wxConvUTF8) );
1069 case CONFIG_ITEM_KEY:
1070 /* So you don't need to restart to have the changes take effect */
1071 val.i_int = control->GetIntValue();
1072 var_Set( p_intf->p_libvlc, control->GetName().mb_str(wxConvUTF8), val );
1073 case CONFIG_ITEM_INTEGER:
1074 case CONFIG_ITEM_BOOL:
1075 config_PutInt( p_intf, control->GetName().mb_str(wxConvUTF8),
1076 control->GetIntValue() );
1078 case CONFIG_ITEM_FLOAT:
1079 config_PutFloat( p_intf, control->GetName().mb_str(wxConvUTF8),
1080 control->GetFloatValue() );
1086 void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
1088 bool hidden = false;
1090 if( b_advanced == b_new_advanced )
1095 if( config_sizer && config_window )
1097 b_advanced = b_new_advanced;
1099 for( size_t i = 0; i < config_array.GetCount(); i++ )
1101 ConfigControl *control = config_array.Item(i);
1102 if( control->IsAdvanced() )
1104 if( !b_advanced ) hidden = true;
1105 control->Show( b_advanced );
1106 config_sizer->Show( control, b_advanced );
1110 config_sizer->Layout();
1111 config_window->FitInside();
1112 config_window->Refresh();
1115 if( hidden && hidden_text )
1117 hidden_text->Show( true );
1118 config_sizer->Show( hidden_text, true );
1120 else if ( hidden_text )
1122 hidden_text->Show( false );
1123 config_sizer->Show( hidden_text, false );