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 *****************************************************************************/
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;
87 wxTreeItemId root_item;
88 wxTreeItemId plugins_item;
91 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
93 class PrefsPanel : public wxPanel
98 PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
99 PrefsDialog *, ConfigTreeData* );
100 virtual ~PrefsPanel() {}
103 void SwitchAdvanced( vlc_bool_t );
106 intf_thread_t *p_intf;
107 PrefsDialog *p_prefs_dialog;
109 vlc_bool_t b_advanced;
111 wxStaticText *hidden_text;
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_name = NULL;
124 virtual ~ConfigTreeData() {
125 if( panel ) delete panel;
126 if( psz_name ) free( psz_name );
127 if( psz_help ) free( psz_help );
130 vlc_bool_t b_submodule;
142 /*****************************************************************************
144 *****************************************************************************/
146 /* IDs for the controls and the menu commands */
149 Notebook_Event = wxID_HIGHEST,
155 BEGIN_EVENT_TABLE(PrefsDialog, wxFrame)
157 EVT_BUTTON(wxID_OK, PrefsDialog::OnOk)
158 EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel)
159 EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave)
160 EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll)
161 EVT_CHECKBOX(Advanced_Event, PrefsDialog::OnAdvanced)
163 /* Don't destroy the window when the user closes it */
164 EVT_CLOSE(PrefsDialog::OnClose)
167 // menu and control ids
170 PrefsTree_Ctrl = wxID_HIGHEST
173 BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
174 EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem)
175 EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced)
178 /*****************************************************************************
180 *****************************************************************************/
181 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent)
182 : wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition,
183 wxSize(700,450), wxDEFAULT_FRAME_STYLE )
185 /* Initializations */
187 SetIcon( *p_intf->p_sys->p_icon );
189 /* Create a panel to put everything in */
190 wxPanel *panel = new wxPanel( this, -1 );
191 panel->SetAutoLayout( TRUE );
193 /* Create the preferences tree control */
194 wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL );
196 new PrefsTreeCtrl( panel, p_intf, this, controls_sizer );
199 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
201 /* Create the buttons */
202 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
203 ok_button->SetDefault();
204 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
206 wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("Save")) );
207 wxButton *reset_button = new wxButton( panel, ResetAll_Event,
208 wxU(_("Reset All")) );
210 wxPanel *dummy_panel = new wxPanel( this, -1 );
211 wxCheckBox *advanced_checkbox =
212 new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) );
214 if( config_GetInt( p_intf, "advanced" ) )
216 advanced_checkbox->SetValue(TRUE);
217 wxCommandEvent dummy_event;
218 dummy_event.SetInt(TRUE);
219 OnAdvanced( dummy_event );
222 /* Place everything in sizers */
223 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
224 button_sizer->Add( ok_button, 0, wxALL, 5 );
225 button_sizer->Add( cancel_button, 0, wxALL, 5 );
226 button_sizer->Add( save_button, 0, wxALL, 5 );
227 button_sizer->Add( reset_button, 0, wxALL, 5 );
228 button_sizer->Add( dummy_panel, 1, wxALL, 5 );
229 button_sizer->Add( advanced_checkbox, 0, wxALL | wxALIGN_RIGHT |
230 wxALIGN_CENTER_VERTICAL, 0 );
231 button_sizer->Layout();
233 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
234 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
235 panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 );
236 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
237 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
238 wxALL | wxEXPAND, 5 );
239 panel_sizer->Layout();
240 panel->SetSizer( panel_sizer );
241 main_sizer->Add( panel, 1, wxEXPAND, 0 );
242 main_sizer->Layout();
243 SetSizer( main_sizer );
246 PrefsDialog::~PrefsDialog()
250 /*****************************************************************************
252 *****************************************************************************/
255 /*****************************************************************************
257 *****************************************************************************/
258 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
260 prefs_tree->ApplyChanges();
262 prefs_tree->CleanChanges();
265 void PrefsDialog::OnClose( wxCloseEvent& WXUNUSED(event) )
267 wxCommandEvent cevent;
271 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
274 prefs_tree->CleanChanges();
277 void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
279 prefs_tree->ApplyChanges();
280 config_SaveConfigFile( p_intf, NULL );
284 void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
286 wxMessageDialog dlg( this,
287 wxU(_("Beware this will reset your VLC media player preferences.\n"
288 "Are you sure you want to continue?")),
289 wxU(_("Reset Preferences")), wxYES_NO|wxNO_DEFAULT|wxCENTRE );
291 if ( dlg.ShowModal() == wxID_YES )
293 /* TODO: need to reset all the controls */
294 config_ResetAll( p_intf );
295 prefs_tree->CleanChanges();
296 config_SaveConfigFile( p_intf, NULL );
300 void PrefsDialog::OnAdvanced( wxCommandEvent& event )
302 wxCommandEvent newevent( wxEVT_USER_FIRST, Advanced_Event );
303 newevent.SetInt( event.GetInt() );
305 prefs_tree->AddPendingEvent( newevent );
308 /*****************************************************************************
309 * PrefsTreeCtrl class definition.
310 *****************************************************************************/
311 PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
312 PrefsDialog *_p_prefs_dialog,
313 wxBoxSizer *_p_sizer )
314 : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxSize(200,-1),
315 wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT |
316 wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT |
317 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER )
319 vlc_list_t *p_list = NULL;;
321 module_config_t *p_item;
322 int i_index, i_image=0;
324 /* Initializations */
326 p_prefs_dialog = _p_prefs_dialog;
328 p_parent = _p_parent;
329 b_advanced = VLC_FALSE;
331 root_item = AddRoot( wxT("") );
332 wxASSERT_MSG(root_item.IsOk(), wxT("Could not add root item"));
334 wxImageList *p_images = new wxImageList( 16,16,TRUE );
335 p_images->Add( wxIcon( audio_xpm ) );
336 p_images->Add( wxIcon( video_xpm ) );
337 p_images->Add( wxIcon( codec_xpm ) );
338 p_images->Add( wxIcon( type_net_xpm ) );
339 p_images->Add( wxIcon( advanced_xpm ) );
340 p_images->Add( wxIcon( type_playlist_xpm ) );
341 p_images->Add( wxIcon( intf_xpm ) );
342 AssignImageList( p_images );
344 /* List the plugins */
345 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
346 if( !p_list ) return;
348 /* Build the categories list */
349 for( i_index = 0; i_index < p_list->i_count; i_index++ )
351 p_module = (module_t *)p_list->p_values[i_index].p_object;
352 if( !strcmp( p_module->psz_object_name, "main" ) )
355 if( i_index < p_list->i_count )
357 wxTreeItemId current_item;
359 /* We found the main module */
361 /* Enumerate config categories and store a reference so we can
362 * generate their config panel them when it is asked by the user. */
363 p_item = p_module->p_config;
367 ConfigTreeData *config_data;
368 switch( p_item->i_type )
370 case CONFIG_CATEGORY:
371 config_data = new ConfigTreeData;
372 config_data->psz_name = strdup( config_CategoryNameGet(
374 psz_help = config_CategoryHelpGet( p_item->i_value );
377 config_data->psz_help = wraptext( strdup( psz_help ),
382 config_data->psz_help = NULL;
384 config_data->i_type = TYPE_CATEGORY;
385 config_data->i_object_id = p_item->i_value;
387 /* Add the category to the tree */
388 switch( p_item->i_value )
405 current_item = AppendItem( root_item,
406 wxU( config_data->psz_name ),
407 i_image, -1, config_data );
410 case CONFIG_SUBCATEGORY:
411 if( p_item->i_value == SUBCAT_VIDEO_GENERAL ||
412 p_item->i_value == SUBCAT_AUDIO_GENERAL )
414 ConfigTreeData *cd = (ConfigTreeData *)
415 GetItemData( current_item );
416 cd->i_type = TYPE_CATSUBCAT;
417 cd->i_subcat_id = p_item->i_value;
418 if( cd->psz_name ) free( cd->psz_name );
419 cd->psz_name = strdup( config_CategoryNameGet(
421 if( cd->psz_help ) free( cd->psz_help );
422 char *psz_help = config_CategoryHelpGet( p_item->i_value );
425 cd->psz_help = wraptext( strdup( psz_help ),72 ,
435 config_data = new ConfigTreeData;
437 config_data->psz_name = strdup( config_CategoryNameGet(
439 psz_help = config_CategoryHelpGet( p_item->i_value );
442 config_data->psz_help = wraptext( strdup( psz_help ) ,
447 config_data->psz_help = NULL;
449 config_data->i_type = TYPE_SUBCATEGORY;
450 config_data->i_object_id = p_item->i_value;
451 /* WXMSW doesn't know image -1 ... FIXME */
453 switch( p_item->i_value / 100 )
473 AppendItem( current_item, wxU( config_data->psz_name ),
474 i_image, -1, config_data );
478 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
484 * Build a tree of all the plugins
486 for( i_index = 0; i_index < p_list->i_count; i_index++ )
489 int i_subcategory = -1;
492 p_module = (module_t *)p_list->p_values[i_index].p_object;
494 /* Exclude the main module */
495 if( !strcmp( p_module->psz_object_name, "main" ) )
498 /* Exclude empty plugins (submodules don't have config options, they
499 * are stored in the parent module) */
500 if( p_module->b_submodule )
502 // p_item = ((module_t *)p_module->p_parent)->p_config;
504 p_item = p_module->p_config;
507 if( !p_item ) continue;
510 if( p_item->i_type == CONFIG_CATEGORY )
512 i_category = p_item->i_value;
514 else if( p_item->i_type == CONFIG_SUBCATEGORY )
516 i_subcategory = p_item->i_value;
518 if( p_item->i_type & CONFIG_ITEM )
520 if( i_options > 0 && i_category >= 0 && i_subcategory >= 0 )
525 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
527 if( !i_options ) continue;
529 /* Find the right category item */
530 wxTreeItemIdValue cookie;
531 vlc_bool_t b_found = VLC_FALSE;
533 wxTreeItemId category_item = GetFirstChild( root_item , cookie);
534 while( category_item.IsOk() )
536 ConfigTreeData *config_data =
537 (ConfigTreeData *)GetItemData( category_item );
538 if( config_data->i_object_id == i_category )
543 category_item = GetNextChild( root_item, cookie );
546 if( !b_found ) continue;
548 /* Find subcategory item */
551 wxTreeItemId subcategory_item = GetFirstChild( category_item, cookie );
552 while( subcategory_item.IsOk() )
554 ConfigTreeData *config_data =
555 (ConfigTreeData *)GetItemData( subcategory_item );
556 if( config_data->i_object_id == i_subcategory )
561 subcategory_item = GetNextChild( category_item, cookie );
565 subcategory_item = category_item;
568 /* Add the plugin to the tree */
569 ConfigTreeData *config_data = new ConfigTreeData;
570 config_data->b_submodule = p_module->b_submodule;
571 config_data->i_type = TYPE_MODULE;
572 config_data->i_object_id = p_module->b_submodule ?
573 ((module_t *)p_module->p_parent)->i_object_id :
574 p_module->i_object_id;
575 config_data->psz_help = NULL;
577 /* WXMSW doesn't know image -1 ... FIXME */
579 switch( i_subcategory / 100 )
599 AppendItem( subcategory_item, wxU( p_module->psz_shortname ?
600 p_module->psz_shortname : p_module->psz_object_name )
605 /* Sort all this mess */
606 wxTreeItemIdValue cookie;
607 size_t i_child_index;
608 wxTreeItemId capability_item = GetFirstChild( root_item, cookie);
609 for( i_child_index = 0;
610 (capability_item.IsOk() &&
611 //(i_child_index < GetChildrenCount( plugins_item, FALSE )));
612 (i_child_index < GetChildrenCount( root_item, FALSE )));
615 SortChildren( capability_item );
616 //capability_item = GetNextChild( plugins_item, cookie );
617 capability_item = GetNextChild( root_item, cookie );
620 /* Clean-up everything */
621 vlc_list_release( p_list );
623 p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );
626 /* Update Tree Ctrl */
627 #ifndef WIN32 /* Workaround a bug in win32 implementation */
628 SelectItem( GetFirstChild( root_item, cookie ) );
631 //cannot expand hidden root item
632 //Expand( root_item );
635 PrefsTreeCtrl::~PrefsTreeCtrl(){
638 void PrefsTreeCtrl::ApplyChanges()
640 wxTreeItemIdValue cookie, cookie2, cookie3;
641 ConfigTreeData *config_data;
643 wxTreeItemId category = GetFirstChild( root_item, cookie );
644 while( category.IsOk() )
646 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
647 while( subcategory.IsOk() )
649 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
650 while( module.IsOk() )
652 config_data = (ConfigTreeData *)GetItemData( module );
653 if( config_data && config_data->panel )
655 config_data->panel->ApplyChanges();
657 module = GetNextChild( subcategory, cookie3 );
659 config_data = (ConfigTreeData *)GetItemData( subcategory );
660 if( config_data && config_data->panel )
662 config_data->panel->ApplyChanges();
664 subcategory = GetNextChild( category, cookie2 );
666 config_data = (ConfigTreeData *)GetItemData( category );
667 if( config_data && config_data->panel )
669 config_data->panel->ApplyChanges();
671 category = GetNextChild( root_item, cookie );
675 void PrefsTreeCtrl::CleanChanges()
677 wxTreeItemIdValue cookie, cookie2, cookie3;
678 ConfigTreeData *config_data;
680 config_data = !GetSelection() ? NULL :
681 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
684 config_data->panel->Hide();
685 #if (wxCHECK_VERSION(2,5,0))
686 p_sizer->Detach( config_data->panel );
688 p_sizer->Remove( config_data->panel );
692 wxTreeItemId category = GetFirstChild( root_item, cookie );
693 while( category.IsOk() )
695 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
696 while( subcategory.IsOk() )
698 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
699 while( module.IsOk() )
701 config_data = (ConfigTreeData *)GetItemData( module );
702 if( config_data && config_data->panel )
704 delete config_data->panel;
705 config_data->panel = NULL;
707 module = GetNextChild( subcategory, cookie3 );
709 config_data = (ConfigTreeData *)GetItemData( subcategory );
710 if( config_data && config_data->panel )
712 delete config_data->panel;
713 config_data->panel = NULL;
715 subcategory = GetNextChild( category, cookie2 );
717 config_data = (ConfigTreeData *)GetItemData( category );
718 if( config_data && config_data->panel )
720 delete config_data->panel;
721 config_data->panel = NULL;
723 category = GetNextChild( root_item, cookie );
729 OnSelectTreeItem( event );
733 ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
735 /* We need this complexity because submodules don't have their own config
736 * options. They use the parent module ones. */
738 if( !config_data || !config_data->b_submodule )
743 wxTreeItemIdValue cookie, cookie2, cookie3;
744 ConfigTreeData *config_new;
745 wxTreeItemId category = GetFirstChild( root_item, cookie );
746 while( category.IsOk() )
748 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
749 while( subcategory.IsOk() )
751 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
752 while( module.IsOk() )
754 config_new = (ConfigTreeData *)GetItemData( module );
755 if( config_new && !config_new->b_submodule &&
756 config_new->i_object_id == config_data->i_object_id )
760 module = GetNextChild( subcategory, cookie3 );
762 subcategory = GetNextChild( category, cookie2 );
764 category = GetNextChild( root_item, cookie );
771 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
773 ConfigTreeData *config_data = NULL;
775 if( event.GetOldItem() )
776 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
777 event.GetOldItem() ) );
778 if( config_data && config_data->panel )
780 config_data->panel->Hide();
781 #if (wxCHECK_VERSION(2,5,0))
782 p_sizer->Detach( config_data->panel );
784 p_sizer->Remove( config_data->panel );
788 /* Don't use event.GetItem() because we also send fake events */
789 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
793 if( !config_data->panel )
795 /* The panel hasn't been created yet. Let's do it. */
797 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
799 config_data->panel->SwitchAdvanced( b_advanced );
803 config_data->panel->SwitchAdvanced( b_advanced );
804 config_data->panel->Show();
807 p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );
812 void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event )
814 b_advanced = event.GetInt();
816 ConfigTreeData *config_data = !GetSelection() ? NULL :
817 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
820 config_data->panel->Hide();
821 #if (wxCHECK_VERSION(2,5,0))
822 p_sizer->Detach( config_data->panel );
824 p_sizer->Remove( config_data->panel );
831 OnSelectTreeItem( event );
835 /*****************************************************************************
836 * PrefsPanel class definition.
837 *****************************************************************************/
838 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
839 PrefsDialog *_p_prefs_dialog,
840 ConfigTreeData *config_data )
841 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
843 module_config_t *p_item;
844 vlc_list_t *p_list = NULL;;
850 module_t *p_module = NULL;
852 /* Initializations */
854 p_prefs_dialog =_p_prefs_dialog,
856 b_advanced = VLC_TRUE;
857 SetAutoLayout( TRUE );
860 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
863 if( config_data->i_type == TYPE_CATEGORY )
865 label = new wxStaticText( this, -1,wxU(_( config_data->psz_name )));
866 wxFont heading_font = label->GetFont();
867 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
868 label->SetFont( heading_font );
869 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
870 sizer->Add( new wxStaticLine( this, 0 ), 0,
871 wxEXPAND | wxLEFT | wxRIGHT, 2 );
874 help = new wxStaticText( this, -1, wxU(_( config_data->psz_help ) ) );
875 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
877 config_sizer = NULL; config_window = NULL;
881 /* Get a pointer to the module */
882 if( config_data->i_type == TYPE_MODULE )
884 p_module = (module_t *)vlc_object_get( p_intf,
885 config_data->i_object_id );
889 /* List the plugins */
891 vlc_bool_t b_found = VLC_FALSE;
892 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
893 if( !p_list ) return;
895 for( i_index = 0; i_index < p_list->i_count; i_index++ )
897 p_module = (module_t *)p_list->p_values[i_index].p_object;
898 if( !strcmp( p_module->psz_object_name, "main" ) )
904 if( !p_module && !b_found )
906 msg_Warn( p_intf, "ohoh, unable to find main module" );
911 if( p_module->i_object_type != VLC_OBJECT_MODULE )
913 /* 0OOoo something went really bad */
917 /* Enumerate config options and add corresponding config boxes
918 * (submodules don't have config options, they are stored in the
920 if( p_module->b_submodule )
921 p_item = ((module_t *)p_module->p_parent)->p_config;
923 p_item = p_module->p_config;
925 /* Find the category if it has been specified */
926 if( config_data->i_type == TYPE_SUBCATEGORY ||
927 config_data->i_type == TYPE_CATSUBCAT )
931 if( p_item->i_type == CONFIG_SUBCATEGORY &&
932 ( config_data->i_type == TYPE_SUBCATEGORY &&
933 p_item->i_value == config_data->i_object_id ) ||
934 ( config_data->i_type == TYPE_CATSUBCAT &&
935 p_item->i_value == config_data->i_subcat_id ) )
939 if( p_item->i_type == CONFIG_HINT_END )
944 /* Add a head title to the panel */
946 if( config_data->i_type == TYPE_SUBCATEGORY ||
947 config_data->i_type == TYPE_CATSUBCAT )
949 psz_head = config_data->psz_name;
954 psz_head = p_module->psz_longname;
957 label = new wxStaticText( this, -1,
958 wxU(_( psz_head ? psz_head : _("Unknown") ) ) );
959 wxFont heading_font = label->GetFont();
960 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
961 label->SetFont( heading_font );
962 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
963 sizer->Add( new wxStaticLine( this, 0 ), 0,
964 wxEXPAND | wxLEFT | wxRIGHT, 2 );
966 /* Now put all the config options into a scrolled window */
967 config_sizer = new wxBoxSizer( wxVERTICAL );
968 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
969 wxDefaultSize, wxBORDER_NONE | wxHSCROLL | wxVSCROLL );
970 config_window->SetAutoLayout( TRUE );
971 config_window->SetScrollRate( 5, 5 );
975 /* If a category has been specified, check we finished the job */
976 if( ( ( config_data->i_type == TYPE_SUBCATEGORY &&
977 p_item->i_value != config_data->i_object_id ) ||
978 ( config_data->i_type == TYPE_CATSUBCAT &&
979 p_item->i_value != config_data->i_subcat_id ) ) &&
980 (p_item->i_type == CONFIG_CATEGORY ||
981 p_item->i_type == CONFIG_SUBCATEGORY ) )
984 ConfigControl *control =
985 CreateConfigControl( VLC_OBJECT(p_intf),
986 p_item, config_window );
988 /* Don't add items that were not recognized */
989 if( control == NULL ) continue;
991 /* Add the config data to our array so we can keep a trace of it */
992 config_array.Add( control );
994 config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
996 while( !( p_item->i_type == CONFIG_HINT_END ||
997 ( ( config_data->i_type == TYPE_SUBCATEGORY ||
998 config_data->i_type == TYPE_CATSUBCAT ) &&
999 ( p_item->i_type == CONFIG_CATEGORY ||
1000 p_item->i_type == CONFIG_SUBCATEGORY ) ) ) && p_item++ );
1003 config_sizer->Layout();
1004 config_window->SetSizer( config_sizer );
1005 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
1006 hidden_text = new wxStaticText( this, -1,
1007 wxU( _( "Some options are available but hidden. " \
1008 "Check \"Advanced options\" to see them." ) ) );
1009 sizer->Add( hidden_text );
1011 /* And at last put a useful help string if available */
1012 if( config_data->psz_help && *config_data->psz_help )
1014 sizer->Add( new wxStaticLine( this, 0 ), 0,
1015 wxEXPAND | wxLEFT | wxRIGHT, 2 );
1016 help = new wxStaticText( this, -1, wxU(_(config_data->psz_help)),
1017 wxDefaultPosition, wxDefaultSize,
1020 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
1023 if( config_data->i_type == TYPE_MODULE )
1025 vlc_object_release( p_module );
1029 vlc_list_release( p_list );
1037 void PrefsPanel::ApplyChanges()
1041 for( size_t i = 0; i < config_array.GetCount(); i++ )
1043 ConfigControl *control = config_array.Item(i);
1045 switch( control->GetType() )
1047 case CONFIG_ITEM_STRING:
1048 case CONFIG_ITEM_FILE:
1049 case CONFIG_ITEM_DIRECTORY:
1050 case CONFIG_ITEM_MODULE:
1051 case CONFIG_ITEM_MODULE_CAT:
1052 case CONFIG_ITEM_MODULE_LIST:
1053 case CONFIG_ITEM_MODULE_LIST_CAT:
1054 config_PutPsz( p_intf, control->GetName().mb_str(),
1055 control->GetPszValue().mb_str() );
1057 case CONFIG_ITEM_KEY:
1058 /* So you don't need to restart to have the changes take effect */
1059 val.i_int = control->GetIntValue();
1060 var_Set( p_intf->p_vlc, control->GetName().mb_str(), val );
1061 case CONFIG_ITEM_INTEGER:
1062 case CONFIG_ITEM_BOOL:
1063 config_PutInt( p_intf, control->GetName().mb_str(),
1064 control->GetIntValue() );
1066 case CONFIG_ITEM_FLOAT:
1067 config_PutFloat( p_intf, control->GetName().mb_str(),
1068 control->GetFloatValue() );
1074 void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
1076 bool hidden = false;
1078 if( b_advanced == b_new_advanced )
1083 if( config_sizer && config_window )
1085 b_advanced = b_new_advanced;
1087 for( size_t i = 0; i < config_array.GetCount(); i++ )
1089 ConfigControl *control = config_array.Item(i);
1090 if( control->IsAdvanced() )
1092 if( !b_advanced ) hidden = true;
1093 control->Show( b_advanced );
1094 config_sizer->Show( control, b_advanced );
1098 config_sizer->Layout();
1099 config_window->FitInside();
1100 config_window->Refresh();
1103 if( hidden && hidden_text )
1105 hidden_text->Show( true );
1106 config_sizer->Show( hidden_text, true );
1108 else if ( hidden_text )
1110 hidden_text->Show( false );
1111 config_sizer->Show( hidden_text, false );