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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
35 #include <vlc_config_cat.h>
37 #include "wxwindows.h"
38 #include "preferences_widgets.h"
40 #include <wx/combobox.h>
41 #include <wx/statline.h>
42 #include <wx/clntdata.h>
43 #include <wx/dynarray.h>
44 #include <wx/imaglist.h>
46 #include "bitmaps/type_net.xpm"
47 #include "bitmaps/codec.xpm"
48 #include "bitmaps/video.xpm"
49 #include "bitmaps/type_playlist.xpm"
50 #include "bitmaps/advanced.xpm"
51 #include "bitmaps/intf.xpm"
52 #include "bitmaps/audio.xpm"
55 # define wxRB_SINGLE 0
58 #define TYPE_CATEGORY 0
59 #define TYPE_CATSUBCAT 1 /* Category with embedded subcategory */
60 #define TYPE_SUBCATEGORY 2
63 /*****************************************************************************
64 * Classes declarations.
65 *****************************************************************************/
67 class PrefsTreeCtrl : public wxTreeCtrl
72 PrefsTreeCtrl( wxWindow *parent, intf_thread_t *_p_intf,
73 PrefsDialog *p_prefs_dialog, wxBoxSizer *_p_sizer );
74 virtual ~PrefsTreeCtrl();
80 /* Event handlers (these functions should _not_ be virtual) */
81 void OnSelectTreeItem( wxTreeEvent& event );
82 void OnAdvanced( wxCommandEvent& event );
84 ConfigTreeData *FindModuleConfig( ConfigTreeData *config_data );
88 intf_thread_t *p_intf;
89 PrefsDialog *p_prefs_dialog;
92 vlc_bool_t b_advanced;
94 wxTreeItemId root_item;
95 wxTreeItemId plugins_item;
98 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
100 class PrefsPanel : public wxPanel
105 PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
106 PrefsDialog *, ConfigTreeData* );
107 virtual ~PrefsPanel() {}
110 void SwitchAdvanced( vlc_bool_t );
113 intf_thread_t *p_intf;
114 PrefsDialog *p_prefs_dialog;
116 vlc_bool_t b_advanced;
118 wxStaticText *hidden_text;
119 wxBoxSizer *config_sizer;
120 wxScrolledWindow *config_window;
122 ArrayOfConfigControls config_array;
125 class ConfigTreeData : public wxTreeItemData
129 ConfigTreeData() { b_submodule = 0; panel = NULL; psz_name = NULL;
131 virtual ~ConfigTreeData() {
132 if( panel ) delete panel;
133 if( psz_name ) free( psz_name );
134 if( psz_help ) free( psz_help );
137 vlc_bool_t b_submodule;
149 /*****************************************************************************
151 *****************************************************************************/
153 /* IDs for the controls and the menu commands */
156 Notebook_Event = wxID_HIGHEST,
162 BEGIN_EVENT_TABLE(PrefsDialog, wxFrame)
164 EVT_BUTTON(wxID_OK, PrefsDialog::OnOk)
165 EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel)
166 EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave)
167 EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll)
168 EVT_CHECKBOX(Advanced_Event, PrefsDialog::OnAdvanced)
170 /* Don't destroy the window when the user closes it */
171 EVT_CLOSE(PrefsDialog::OnClose)
174 // menu and control ids
177 PrefsTree_Ctrl = wxID_HIGHEST
180 BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
181 EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem)
182 EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced)
185 /*****************************************************************************
187 *****************************************************************************/
188 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent)
189 : wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition,
190 wxSize(700,450), wxDEFAULT_FRAME_STYLE )
192 /* Initializations */
194 SetIcon( *p_intf->p_sys->p_icon );
196 /* Create a panel to put everything in */
197 wxPanel *panel = new wxPanel( this, -1 );
198 panel->SetAutoLayout( TRUE );
200 /* Create the preferences tree control */
201 wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL );
203 new PrefsTreeCtrl( panel, p_intf, this, controls_sizer );
206 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
208 /* Create the buttons */
209 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
210 ok_button->SetDefault();
211 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
213 wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("Save")) );
214 wxButton *reset_button = new wxButton( panel, ResetAll_Event,
215 wxU(_("Reset All")) );
217 wxPanel *dummy_panel = new wxPanel( this, -1 );
218 wxCheckBox *advanced_checkbox =
219 new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) );
221 if( config_GetInt( p_intf, "advanced" ) )
223 advanced_checkbox->SetValue(TRUE);
224 wxCommandEvent dummy_event;
225 dummy_event.SetInt(TRUE);
226 OnAdvanced( dummy_event );
229 /* Place everything in sizers */
230 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
231 button_sizer->Add( ok_button, 0, wxALL, 5 );
232 button_sizer->Add( cancel_button, 0, wxALL, 5 );
233 button_sizer->Add( save_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(_("Beware 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;
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(), "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( p_module->psz_object_name, "main" ) )
362 if( i_index < p_list->i_count )
364 wxTreeItemId current_item;
366 /* We found the main module */
368 /* Enumerate config categories and store a reference so we can
369 * generate their config panel them when it is asked by the user. */
370 p_item = p_module->p_config;
374 ConfigTreeData *config_data;
375 switch( p_item->i_type )
377 case CONFIG_CATEGORY:
378 config_data = new ConfigTreeData;
379 config_data->psz_name = strdup( config_CategoryNameGet(
381 psz_help = config_CategoryHelpGet( p_item->i_value );
384 config_data->psz_help = wraptext( strdup( psz_help ),
389 config_data->psz_help = NULL;
391 config_data->i_type = TYPE_CATEGORY;
392 config_data->i_object_id = p_item->i_value;
394 /* Add the category to the tree */
395 switch( p_item->i_value )
412 current_item = AppendItem( root_item,
413 wxU( config_data->psz_name ),
414 i_image, -1, config_data );
417 case CONFIG_SUBCATEGORY:
418 if( p_item->i_value == SUBCAT_VIDEO_GENERAL ||
419 p_item->i_value == SUBCAT_AUDIO_GENERAL )
421 ConfigTreeData *cd = (ConfigTreeData *)
422 GetItemData( current_item );
423 cd->i_type = TYPE_CATSUBCAT;
424 cd->i_subcat_id = p_item->i_value;
425 if( cd->psz_name ) free( cd->psz_name );
426 cd->psz_name = strdup( config_CategoryNameGet(
428 if( cd->psz_help ) free( cd->psz_help );
429 char *psz_help = config_CategoryHelpGet( p_item->i_value );
432 cd->psz_help = wraptext( strdup( psz_help ),72 ,
442 config_data = new ConfigTreeData;
444 config_data->psz_name = strdup( config_CategoryNameGet(
446 psz_help = config_CategoryHelpGet( p_item->i_value );
449 config_data->psz_help = wraptext( strdup( psz_help ) ,
454 config_data->psz_help = NULL;
456 config_data->i_type = TYPE_SUBCATEGORY;
457 config_data->i_object_id = p_item->i_value;
458 /* WXMSW doesn't know image -1 ... FIXME */
460 switch( p_item->i_value / 100 )
480 AppendItem( current_item, wxU( config_data->psz_name ),
481 i_image, -1, config_data );
485 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
491 * Build a tree of all the plugins
493 for( i_index = 0; i_index < p_list->i_count; i_index++ )
496 int i_subcategory = -1;
499 p_module = (module_t *)p_list->p_values[i_index].p_object;
501 /* Exclude the main module */
502 if( !strcmp( p_module->psz_object_name, "main" ) )
505 /* Exclude empty plugins (submodules don't have config options, they
506 * are stored in the parent module) */
507 if( p_module->b_submodule )
509 // p_item = ((module_t *)p_module->p_parent)->p_config;
511 p_item = p_module->p_config;
514 if( !p_item ) continue;
517 if( p_item->i_type == CONFIG_CATEGORY )
519 i_category = p_item->i_value;
521 else if( p_item->i_type == CONFIG_SUBCATEGORY )
523 i_subcategory = p_item->i_value;
525 if( p_item->i_type & CONFIG_ITEM )
527 if( i_options > 0 && i_category >= 0 && i_subcategory >= 0 )
532 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
534 if( !i_options ) continue;
536 /* Find the right category item */
537 wxTreeItemIdValue cookie;
538 vlc_bool_t b_found = VLC_FALSE;
540 wxTreeItemId category_item = GetFirstChild( root_item , cookie);
541 while( category_item.IsOk() )
543 ConfigTreeData *config_data =
544 (ConfigTreeData *)GetItemData( category_item );
545 if( config_data->i_object_id == i_category )
550 category_item = GetNextChild( root_item, cookie );
553 if( !b_found ) continue;
555 /* Find subcategory item */
558 wxTreeItemId subcategory_item = GetFirstChild( category_item, cookie );
559 while( subcategory_item.IsOk() )
561 ConfigTreeData *config_data =
562 (ConfigTreeData *)GetItemData( subcategory_item );
563 if( config_data->i_object_id == i_subcategory )
568 subcategory_item = GetNextChild( category_item, cookie );
572 subcategory_item = category_item;
575 /* Add the plugin to the tree */
576 ConfigTreeData *config_data = new ConfigTreeData;
577 config_data->b_submodule = p_module->b_submodule;
578 config_data->i_type = TYPE_MODULE;
579 config_data->i_object_id = p_module->b_submodule ?
580 ((module_t *)p_module->p_parent)->i_object_id :
581 p_module->i_object_id;
582 config_data->psz_help = NULL;
584 /* WXMSW doesn't know image -1 ... FIXME */
586 switch( i_subcategory / 100 )
606 AppendItem( subcategory_item, wxU( p_module->psz_shortname ?
607 p_module->psz_shortname : p_module->psz_object_name )
612 /* Sort all this mess */
613 wxTreeItemIdValue cookie;
614 size_t i_child_index;
615 wxTreeItemId capability_item = GetFirstChild( root_item, cookie);
616 for( i_child_index = 0;
617 (capability_item.IsOk() &&
618 //(i_child_index < GetChildrenCount( plugins_item, FALSE )));
619 (i_child_index < GetChildrenCount( root_item, FALSE )));
622 SortChildren( capability_item );
623 //capability_item = GetNextChild( plugins_item, cookie );
624 capability_item = GetNextChild( root_item, cookie );
627 /* Clean-up everything */
628 vlc_list_release( p_list );
630 p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );
633 /* Update Tree Ctrl */
634 #ifndef WIN32 /* Workaround a bug in win32 implementation */
635 SelectItem( GetFirstChild( root_item, cookie ) );
638 //cannot expand hidden root item
639 //Expand( root_item );
642 PrefsTreeCtrl::~PrefsTreeCtrl(){
645 void PrefsTreeCtrl::ApplyChanges()
647 wxTreeItemIdValue cookie, cookie2, cookie3;
648 ConfigTreeData *config_data;
650 wxTreeItemId category = GetFirstChild( root_item, cookie );
651 while( category.IsOk() )
653 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
654 while( subcategory.IsOk() )
656 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
657 while( module.IsOk() )
659 config_data = (ConfigTreeData *)GetItemData( module );
660 if( config_data && config_data->panel )
662 config_data->panel->ApplyChanges();
664 module = GetNextChild( subcategory, cookie3 );
666 config_data = (ConfigTreeData *)GetItemData( subcategory );
667 if( config_data && config_data->panel )
669 config_data->panel->ApplyChanges();
671 subcategory = GetNextChild( category, cookie2 );
673 config_data = (ConfigTreeData *)GetItemData( category );
674 if( config_data && config_data->panel )
676 config_data->panel->ApplyChanges();
678 category = GetNextChild( root_item, cookie );
682 void PrefsTreeCtrl::CleanChanges()
684 wxTreeItemIdValue cookie, cookie2, cookie3;
685 ConfigTreeData *config_data;
687 config_data = !GetSelection() ? NULL :
688 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
691 config_data->panel->Hide();
692 #if (wxCHECK_VERSION(2,5,0))
693 p_sizer->Detach( config_data->panel );
695 p_sizer->Remove( config_data->panel );
699 wxTreeItemId category = GetFirstChild( root_item, cookie );
700 while( category.IsOk() )
702 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
703 while( subcategory.IsOk() )
705 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
706 while( module.IsOk() )
708 config_data = (ConfigTreeData *)GetItemData( module );
709 if( config_data && config_data->panel )
711 delete config_data->panel;
712 config_data->panel = NULL;
714 module = GetNextChild( subcategory, cookie3 );
716 config_data = (ConfigTreeData *)GetItemData( subcategory );
717 if( config_data && config_data->panel )
719 delete config_data->panel;
720 config_data->panel = NULL;
722 subcategory = GetNextChild( category, cookie2 );
724 config_data = (ConfigTreeData *)GetItemData( category );
725 if( config_data && config_data->panel )
727 delete config_data->panel;
728 config_data->panel = NULL;
730 category = GetNextChild( root_item, cookie );
736 OnSelectTreeItem( event );
740 ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
742 /* We need this complexity because submodules don't have their own config
743 * options. They use the parent module ones. */
745 if( !config_data || !config_data->b_submodule )
750 wxTreeItemIdValue cookie, cookie2, cookie3;
751 ConfigTreeData *config_new;
752 wxTreeItemId category = GetFirstChild( root_item, cookie );
753 while( category.IsOk() )
755 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
756 while( subcategory.IsOk() )
758 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
759 while( module.IsOk() )
761 config_new = (ConfigTreeData *)GetItemData( module );
762 if( config_new && !config_new->b_submodule &&
763 config_new->i_object_id == config_data->i_object_id )
767 module = GetNextChild( subcategory, cookie3 );
769 subcategory = GetNextChild( category, cookie2 );
771 category = GetNextChild( root_item, cookie );
778 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
780 ConfigTreeData *config_data = NULL;
782 if( event.GetOldItem() )
783 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
784 event.GetOldItem() ) );
785 if( config_data && config_data->panel )
787 config_data->panel->Hide();
788 #if (wxCHECK_VERSION(2,5,0))
789 p_sizer->Detach( config_data->panel );
791 p_sizer->Remove( config_data->panel );
795 /* Don't use event.GetItem() because we also send fake events */
796 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
800 if( !config_data->panel )
802 /* The panel hasn't been created yet. Let's do it. */
804 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
806 config_data->panel->SwitchAdvanced( b_advanced );
810 config_data->panel->SwitchAdvanced( b_advanced );
811 config_data->panel->Show();
814 p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );
819 void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event )
821 b_advanced = event.GetInt();
823 ConfigTreeData *config_data = !GetSelection() ? NULL :
824 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
827 config_data->panel->Hide();
828 #if (wxCHECK_VERSION(2,5,0))
829 p_sizer->Detach( config_data->panel );
831 p_sizer->Remove( config_data->panel );
838 OnSelectTreeItem( event );
842 /*****************************************************************************
843 * PrefsPanel class definition.
844 *****************************************************************************/
845 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
846 PrefsDialog *_p_prefs_dialog,
847 ConfigTreeData *config_data )
848 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
850 module_config_t *p_item;
851 vlc_list_t *p_list = NULL;;
857 module_t *p_module = NULL;
859 /* Initializations */
861 p_prefs_dialog =_p_prefs_dialog,
863 b_advanced = VLC_TRUE;
864 SetAutoLayout( TRUE );
867 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
870 if( config_data->i_type == TYPE_CATEGORY )
872 label = new wxStaticText( this, -1,wxU(_( config_data->psz_name )));
873 wxFont heading_font = label->GetFont();
874 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
875 label->SetFont( heading_font );
876 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
877 sizer->Add( new wxStaticLine( this, 0 ), 0,
878 wxEXPAND | wxLEFT | wxRIGHT, 2 );
881 help = new wxStaticText( this, -1, wxU(_( config_data->psz_help ) ) );
882 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
884 config_sizer = NULL; config_window = NULL;
888 /* Get a pointer to the module */
889 if( config_data->i_type == TYPE_MODULE )
891 p_module = (module_t *)vlc_object_get( p_intf,
892 config_data->i_object_id );
896 /* List the plugins */
898 vlc_bool_t b_found = VLC_FALSE;
899 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
900 if( !p_list ) return;
902 for( i_index = 0; i_index < p_list->i_count; i_index++ )
904 p_module = (module_t *)p_list->p_values[i_index].p_object;
905 if( !strcmp( p_module->psz_object_name, "main" ) )
911 if( !p_module && !b_found )
913 msg_Warn( p_intf, "ohoh, unable to find main module" );
918 if( p_module->i_object_type != VLC_OBJECT_MODULE )
920 /* 0OOoo something went really bad */
924 /* Enumerate config options and add corresponding config boxes
925 * (submodules don't have config options, they are stored in the
927 if( p_module->b_submodule )
928 p_item = ((module_t *)p_module->p_parent)->p_config;
930 p_item = p_module->p_config;
932 /* Find the category if it has been specified */
933 if( config_data->i_type == TYPE_SUBCATEGORY ||
934 config_data->i_type == TYPE_CATSUBCAT )
938 if( p_item->i_type == CONFIG_SUBCATEGORY &&
939 ( config_data->i_type == TYPE_SUBCATEGORY &&
940 p_item->i_value == config_data->i_object_id ) ||
941 ( config_data->i_type == TYPE_CATSUBCAT &&
942 p_item->i_value == config_data->i_subcat_id ) )
946 if( p_item->i_type == CONFIG_HINT_END )
951 /* Add a head title to the panel */
953 if( config_data->i_type == TYPE_SUBCATEGORY ||
954 config_data->i_type == TYPE_CATSUBCAT )
956 psz_head = config_data->psz_name;
961 psz_head = p_module->psz_longname;
964 label = new wxStaticText( this, -1,
965 wxU(_( psz_head ? psz_head : _("Unknown") ) ) );
966 wxFont heading_font = label->GetFont();
967 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
968 label->SetFont( heading_font );
969 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
970 sizer->Add( new wxStaticLine( this, 0 ), 0,
971 wxEXPAND | wxLEFT | wxRIGHT, 2 );
973 /* Now put all the config options into a scrolled window */
974 config_sizer = new wxBoxSizer( wxVERTICAL );
975 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
976 wxDefaultSize, wxBORDER_NONE | wxHSCROLL | wxVSCROLL );
977 config_window->SetAutoLayout( TRUE );
978 config_window->SetScrollRate( 5, 5 );
982 /* If a category has been specified, check we finished the job */
983 if( ( ( config_data->i_type == TYPE_SUBCATEGORY &&
984 p_item->i_value != config_data->i_object_id ) ||
985 ( config_data->i_type == TYPE_CATSUBCAT &&
986 p_item->i_value != config_data->i_subcat_id ) ) &&
987 (p_item->i_type == CONFIG_CATEGORY ||
988 p_item->i_type == CONFIG_SUBCATEGORY ) )
991 ConfigControl *control =
992 CreateConfigControl( VLC_OBJECT(p_intf),
993 p_item, config_window );
995 /* Don't add items that were not recognized */
996 if( control == NULL ) continue;
998 /* Add the config data to our array so we can keep a trace of it */
999 config_array.Add( control );
1001 config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
1003 while( !( p_item->i_type == CONFIG_HINT_END ||
1004 ( ( config_data->i_type == TYPE_SUBCATEGORY ||
1005 config_data->i_type == TYPE_CATSUBCAT ) &&
1006 ( p_item->i_type == CONFIG_CATEGORY ||
1007 p_item->i_type == CONFIG_SUBCATEGORY ) ) ) && p_item++ );
1010 config_sizer->Layout();
1011 config_window->SetSizer( config_sizer );
1012 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
1013 hidden_text = new wxStaticText( this, -1,
1014 wxU( _( "Some options are available but hidden. " \
1015 "Check \"Advanced options\" to see them." ) ) );
1016 sizer->Add( hidden_text );
1018 /* And at last put a useful help string if available */
1019 if( config_data->psz_help && *config_data->psz_help )
1021 sizer->Add( new wxStaticLine( this, 0 ), 0,
1022 wxEXPAND | wxLEFT | wxRIGHT, 2 );
1023 help = new wxStaticText( this, -1, wxU(_(config_data->psz_help)),
1024 wxDefaultPosition, wxDefaultSize,
1027 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
1030 if( config_data->i_type == TYPE_MODULE )
1032 vlc_object_release( p_module );
1036 vlc_list_release( p_list );
1044 void PrefsPanel::ApplyChanges()
1048 for( size_t i = 0; i < config_array.GetCount(); i++ )
1050 ConfigControl *control = config_array.Item(i);
1052 switch( control->GetType() )
1054 case CONFIG_ITEM_STRING:
1055 case CONFIG_ITEM_FILE:
1056 case CONFIG_ITEM_DIRECTORY:
1057 case CONFIG_ITEM_MODULE:
1058 case CONFIG_ITEM_MODULE_CAT:
1059 case CONFIG_ITEM_MODULE_LIST:
1060 case CONFIG_ITEM_MODULE_LIST_CAT:
1061 config_PutPsz( p_intf, control->GetName().mb_str(),
1062 control->GetPszValue().mb_str() );
1064 case CONFIG_ITEM_KEY:
1065 /* So you don't need to restart to have the changes take effect */
1066 val.i_int = control->GetIntValue();
1067 var_Set( p_intf->p_vlc, control->GetName().mb_str(), val );
1068 case CONFIG_ITEM_INTEGER:
1069 case CONFIG_ITEM_BOOL:
1070 config_PutInt( p_intf, control->GetName().mb_str(),
1071 control->GetIntValue() );
1073 case CONFIG_ITEM_FLOAT:
1074 config_PutFloat( p_intf, control->GetName().mb_str(),
1075 control->GetFloatValue() );
1081 void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
1083 bool hidden = false;
1085 if( b_advanced == b_new_advanced )
1090 if( config_sizer && config_window )
1092 b_advanced = b_new_advanced;
1094 for( size_t i = 0; i < config_array.GetCount(); i++ )
1096 ConfigControl *control = config_array.Item(i);
1097 if( control->IsAdvanced() )
1099 if( !b_advanced ) hidden = true;
1100 control->Show( b_advanced );
1101 config_sizer->Show( control, b_advanced );
1105 config_sizer->Layout();
1106 config_window->FitInside();
1107 config_window->Refresh();
1110 if( hidden && hidden_text )
1112 hidden_text->Show( true );
1113 config_sizer->Show( hidden_text, true );
1115 else if ( hidden_text )
1117 hidden_text->Show( false );
1118 config_sizer->Show( hidden_text, false );