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 );
203 /* Create the buttons */
204 wxButton *ok_button = new wxButton( panel, wxID_OK );
205 ok_button->SetDefault();
206 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL );
207 wxButton *save_button = new wxButton( panel, wxID_SAVE );
208 wxButton *reset_button = new wxButton( panel, ResetAll_Event,
209 wxU(_("Reset All")) );
211 wxPanel *dummy_panel = new wxPanel( this, -1 );
212 wxCheckBox *advanced_checkbox =
213 new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) );
215 if( config_GetInt( p_intf, "advanced" ) )
217 advanced_checkbox->SetValue(TRUE);
218 wxCommandEvent dummy_event;
219 dummy_event.SetInt(TRUE);
220 OnAdvanced( dummy_event );
223 /* Place everything in sizers */
224 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
225 button_sizer->Add( ok_button, 0, wxALL, 5 );
226 button_sizer->Add( cancel_button, 0, wxALL, 5 );
227 button_sizer->Add( save_button, 0, wxALL, 5 );
228 button_sizer->Add( reset_button, 0, wxALL, 5 );
229 button_sizer->Add( dummy_panel, 1, wxALL, 5 );
230 button_sizer->Add( advanced_checkbox, 0, wxALL | wxALIGN_RIGHT |
231 wxALIGN_CENTER_VERTICAL, 0 );
232 button_sizer->Layout();
234 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
235 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
236 panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 );
237 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
238 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
239 wxALL | wxEXPAND, 5 );
240 panel_sizer->Layout();
241 panel->SetSizer( panel_sizer );
242 main_sizer->Add( panel, 1, wxEXPAND, 0 );
243 main_sizer->Layout();
244 SetSizer( main_sizer );
247 PrefsDialog::~PrefsDialog()
251 /*****************************************************************************
253 *****************************************************************************/
256 /*****************************************************************************
258 *****************************************************************************/
259 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
261 prefs_tree->ApplyChanges();
263 prefs_tree->CleanChanges();
266 void PrefsDialog::OnClose( wxCloseEvent& WXUNUSED(event) )
268 wxCommandEvent cevent;
272 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
275 prefs_tree->CleanChanges();
278 void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
280 prefs_tree->ApplyChanges();
281 config_SaveConfigFile( p_intf, NULL );
285 void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
287 wxMessageDialog dlg( this,
288 wxU(_("Beware this will reset your VLC media player preferences.\n"
289 "Are you sure you want to continue?")),
290 wxU(_("Reset Preferences")), wxYES_NO|wxNO_DEFAULT|wxCENTRE );
292 if ( dlg.ShowModal() == wxID_YES )
294 /* TODO: need to reset all the controls */
295 config_ResetAll( p_intf );
296 prefs_tree->CleanChanges();
297 config_SaveConfigFile( p_intf, NULL );
301 void PrefsDialog::OnAdvanced( wxCommandEvent& event )
303 wxCommandEvent newevent( wxEVT_USER_FIRST, Advanced_Event );
304 newevent.SetInt( event.GetInt() );
306 prefs_tree->AddPendingEvent( newevent );
309 /*****************************************************************************
310 * PrefsTreeCtrl class definition.
311 *****************************************************************************/
312 PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
313 PrefsDialog *_p_prefs_dialog,
314 wxBoxSizer *_p_sizer )
315 : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxSize(200,-1),
316 wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT |
317 wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT |
318 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER )
320 vlc_list_t *p_list = NULL;;
322 module_config_t *p_item;
323 int i_index, i_image=0;
325 /* Initializations */
327 p_prefs_dialog = _p_prefs_dialog;
329 p_parent = _p_parent;
330 b_advanced = VLC_FALSE;
332 root_item = AddRoot( wxT("") );
333 wxASSERT_MSG(root_item.IsOk(), wxT("Could not add root item"));
335 wxImageList *p_images = new wxImageList( 16,16,TRUE );
336 p_images->Add( wxIcon( audio_xpm ) );
337 p_images->Add( wxIcon( video_xpm ) );
338 p_images->Add( wxIcon( codec_xpm ) );
339 p_images->Add( wxIcon( type_net_xpm ) );
340 p_images->Add( wxIcon( advanced_xpm ) );
341 p_images->Add( wxIcon( type_playlist_xpm ) );
342 p_images->Add( wxIcon( intf_xpm ) );
343 AssignImageList( p_images );
345 /* List the plugins */
346 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
347 if( !p_list ) return;
349 /* Build the categories list */
350 for( i_index = 0; i_index < p_list->i_count; i_index++ )
352 p_module = (module_t *)p_list->p_values[i_index].p_object;
353 if( !strcmp( p_module->psz_object_name, "main" ) )
356 if( i_index < p_list->i_count )
358 wxTreeItemId current_item;
360 /* We found the main module */
362 /* Enumerate config categories and store a reference so we can
363 * generate their config panel them when it is asked by the user. */
364 p_item = p_module->p_config;
368 ConfigTreeData *config_data;
369 switch( p_item->i_type )
371 case CONFIG_CATEGORY:
372 config_data = new ConfigTreeData;
373 if( p_item->i_value == -1 ) break; // Don't display it
374 config_data->psz_name = strdup( config_CategoryNameGet(
376 psz_help = config_CategoryHelpGet( p_item->i_value );
379 config_data->psz_help = wraptext( strdup( psz_help ), 72 );
383 config_data->psz_help = NULL;
385 config_data->i_type = TYPE_CATEGORY;
386 config_data->i_object_id = p_item->i_value;
388 /* Add the category to the tree */
389 switch( p_item->i_value )
406 current_item = AppendItem( root_item,
407 wxU( config_data->psz_name ),
408 i_image, -1, config_data );
411 case CONFIG_SUBCATEGORY:
412 if( p_item->i_value == -1 ) break; // Don't display it
413 if( p_item->i_value == SUBCAT_VIDEO_GENERAL ||
414 p_item->i_value == SUBCAT_AUDIO_GENERAL )
416 ConfigTreeData *cd = (ConfigTreeData *)
417 GetItemData( current_item );
418 cd->i_type = TYPE_CATSUBCAT;
419 cd->i_subcat_id = p_item->i_value;
420 if( cd->psz_name ) free( cd->psz_name );
421 cd->psz_name = strdup( config_CategoryNameGet(
423 if( cd->psz_help ) free( cd->psz_help );
424 char *psz_help = config_CategoryHelpGet( p_item->i_value );
427 cd->psz_help = wraptext( strdup( psz_help ), 72 );
436 config_data = new ConfigTreeData;
438 config_data->psz_name = strdup( config_CategoryNameGet(
440 psz_help = config_CategoryHelpGet( p_item->i_value );
443 config_data->psz_help = wraptext( strdup( psz_help ), 72 );
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 );
628 /* Update Tree Ctrl */
629 #ifndef WIN32 /* Workaround a bug in win32 implementation */
630 SelectItem( GetFirstChild( root_item, cookie ) );
633 //cannot expand hidden root item
634 //Expand( root_item );
637 PrefsTreeCtrl::~PrefsTreeCtrl(){
640 void PrefsTreeCtrl::ApplyChanges()
642 wxTreeItemIdValue cookie, cookie2, cookie3;
643 ConfigTreeData *config_data;
645 wxTreeItemId category = GetFirstChild( root_item, cookie );
646 while( category.IsOk() )
648 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
649 while( subcategory.IsOk() )
651 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
652 while( module.IsOk() )
654 config_data = (ConfigTreeData *)GetItemData( module );
655 if( config_data && config_data->panel )
657 config_data->panel->ApplyChanges();
659 module = GetNextChild( subcategory, cookie3 );
661 config_data = (ConfigTreeData *)GetItemData( subcategory );
662 if( config_data && config_data->panel )
664 config_data->panel->ApplyChanges();
666 subcategory = GetNextChild( category, cookie2 );
668 config_data = (ConfigTreeData *)GetItemData( category );
669 if( config_data && config_data->panel )
671 config_data->panel->ApplyChanges();
673 category = GetNextChild( root_item, cookie );
677 void PrefsTreeCtrl::CleanChanges()
679 wxTreeItemIdValue cookie, cookie2, cookie3;
680 ConfigTreeData *config_data;
682 config_data = !GetSelection() ? NULL :
683 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
686 config_data->panel->Hide();
687 #if (wxCHECK_VERSION(2,5,0))
688 p_sizer->Detach( config_data->panel );
690 p_sizer->Remove( config_data->panel );
695 wxTreeItemId category = GetFirstChild( root_item, cookie );
696 while( category.IsOk() )
698 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
699 while( subcategory.IsOk() )
701 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
702 while( module.IsOk() )
704 config_data = (ConfigTreeData *)GetItemData( module );
705 if( config_data && config_data->panel )
707 delete config_data->panel;
708 config_data->panel = NULL;
710 module = GetNextChild( subcategory, cookie3 );
712 config_data = (ConfigTreeData *)GetItemData( subcategory );
713 if( config_data && config_data->panel )
715 delete config_data->panel;
716 config_data->panel = NULL;
718 subcategory = GetNextChild( category, cookie2 );
720 config_data = (ConfigTreeData *)GetItemData( category );
721 if( config_data && config_data->panel )
723 delete config_data->panel;
724 config_data->panel = NULL;
726 category = GetNextChild( root_item, cookie );
732 OnSelectTreeItem( event );
736 ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
738 /* We need this complexity because submodules don't have their own config
739 * options. They use the parent module ones. */
741 if( !config_data || !config_data->b_submodule )
746 wxTreeItemIdValue cookie, cookie2, cookie3;
747 ConfigTreeData *config_new;
748 wxTreeItemId category = GetFirstChild( root_item, cookie );
749 while( category.IsOk() )
751 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
752 while( subcategory.IsOk() )
754 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
755 while( module.IsOk() )
757 config_new = (ConfigTreeData *)GetItemData( module );
758 if( config_new && !config_new->b_submodule &&
759 config_new->i_object_id == config_data->i_object_id )
763 module = GetNextChild( subcategory, cookie3 );
765 subcategory = GetNextChild( category, cookie2 );
767 category = GetNextChild( root_item, cookie );
774 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
776 ConfigTreeData *config_data = NULL;
781 #if (wxCHECK_VERSION(2,5,0))
782 p_sizer->Detach( p_current );
784 p_sizer->Remove( p_current );
789 /* Don't use event.GetItem() because we also send fake events */
790 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
794 if( !config_data->panel )
796 /* The panel hasn't been created yet. Let's do it. */
798 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
800 config_data->panel->SwitchAdvanced( b_advanced );
804 config_data->panel->SwitchAdvanced( b_advanced );
805 config_data->panel->Show();
808 p_current = config_data->panel;
810 p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );
815 void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event )
817 b_advanced = event.GetInt();
819 ConfigTreeData *config_data = !GetSelection() ? NULL :
820 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
823 config_data->panel->Hide();
824 #if (wxCHECK_VERSION(2,5,0))
825 p_sizer->Detach( config_data->panel );
827 p_sizer->Remove( config_data->panel );
835 OnSelectTreeItem( event );
839 /*****************************************************************************
840 * PrefsPanel class definition.
841 *****************************************************************************/
842 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
843 PrefsDialog *_p_prefs_dialog,
844 ConfigTreeData *config_data )
845 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
847 module_config_t *p_item;
848 vlc_list_t *p_list = NULL;;
854 module_t *p_module = NULL;
856 /* Initializations */
858 p_prefs_dialog =_p_prefs_dialog,
860 b_advanced = VLC_TRUE;
861 SetAutoLayout( TRUE );
864 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
867 if( config_data->i_type == TYPE_CATEGORY )
869 label = new wxStaticText( this, -1,wxU(_( config_data->psz_name )));
870 wxFont heading_font = label->GetFont();
871 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
872 label->SetFont( heading_font );
873 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
874 sizer->Add( new wxStaticLine( this, 0 ), 0,
875 wxEXPAND | wxLEFT | wxRIGHT, 2 );
878 help = new wxStaticText( this, -1, wxU(_( config_data->psz_help ) ) );
879 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
881 config_sizer = NULL; config_window = NULL;
885 /* Get a pointer to the module */
886 if( config_data->i_type == TYPE_MODULE )
888 p_module = (module_t *)vlc_object_get( p_intf,
889 config_data->i_object_id );
893 /* List the plugins */
895 vlc_bool_t b_found = VLC_FALSE;
896 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
897 if( !p_list ) return;
899 for( i_index = 0; i_index < p_list->i_count; i_index++ )
901 p_module = (module_t *)p_list->p_values[i_index].p_object;
902 if( !strcmp( p_module->psz_object_name, "main" ) )
908 if( !p_module && !b_found )
910 msg_Warn( p_intf, "ohoh, unable to find main module" );
915 if( p_module->i_object_type != VLC_OBJECT_MODULE )
917 /* 0OOoo something went really bad */
921 /* Enumerate config options and add corresponding config boxes
922 * (submodules don't have config options, they are stored in the
924 if( p_module->b_submodule )
925 p_item = ((module_t *)p_module->p_parent)->p_config;
927 p_item = p_module->p_config;
929 /* Find the category if it has been specified */
930 if( config_data->i_type == TYPE_SUBCATEGORY ||
931 config_data->i_type == TYPE_CATSUBCAT )
935 if( p_item->i_type == CONFIG_SUBCATEGORY &&
936 ( config_data->i_type == TYPE_SUBCATEGORY &&
937 p_item->i_value == config_data->i_object_id ) ||
938 ( config_data->i_type == TYPE_CATSUBCAT &&
939 p_item->i_value == config_data->i_subcat_id ) )
943 if( p_item->i_type == CONFIG_HINT_END )
948 /* Add a head title to the panel */
950 if( config_data->i_type == TYPE_SUBCATEGORY ||
951 config_data->i_type == TYPE_CATSUBCAT )
953 psz_head = config_data->psz_name;
958 psz_head = p_module->psz_longname;
961 label = new wxStaticText( this, -1,
962 wxU(_( psz_head ? psz_head : _("Unknown") ) ) );
963 wxFont heading_font = label->GetFont();
964 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
965 label->SetFont( heading_font );
966 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
967 sizer->Add( new wxStaticLine( this, 0 ), 0,
968 wxEXPAND | wxLEFT | wxRIGHT, 2 );
970 /* Now put all the config options into a scrolled window */
971 config_sizer = new wxBoxSizer( wxVERTICAL );
972 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
973 wxDefaultSize, wxBORDER_NONE | wxHSCROLL | wxVSCROLL );
974 config_window->SetAutoLayout( TRUE );
975 config_window->SetScrollRate( 5, 5 );
979 /* If a category has been specified, check we finished the job */
980 if( ( ( config_data->i_type == TYPE_SUBCATEGORY &&
981 p_item->i_value != config_data->i_object_id ) ||
982 ( config_data->i_type == TYPE_CATSUBCAT &&
983 p_item->i_value != config_data->i_subcat_id ) ) &&
984 (p_item->i_type == CONFIG_CATEGORY ||
985 p_item->i_type == CONFIG_SUBCATEGORY ) )
988 ConfigControl *control =
989 CreateConfigControl( VLC_OBJECT(p_intf),
990 p_item, config_window );
992 /* Don't add items that were not recognized */
993 if( control == NULL ) continue;
995 /* Add the config data to our array so we can keep a trace of it */
996 config_array.Add( control );
998 config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
1000 while( !( p_item->i_type == CONFIG_HINT_END ||
1001 ( ( config_data->i_type == TYPE_SUBCATEGORY ||
1002 config_data->i_type == TYPE_CATSUBCAT ) &&
1003 ( p_item->i_type == CONFIG_CATEGORY ||
1004 p_item->i_type == CONFIG_SUBCATEGORY ) ) ) && p_item++ );
1007 config_sizer->Layout();
1008 config_window->SetSizer( config_sizer );
1009 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
1010 hidden_text = new wxStaticText( this, -1,
1011 wxU( _( "Some options are available but hidden. " \
1012 "Check \"Advanced options\" to see them." ) ) );
1013 sizer->Add( hidden_text );
1015 /* And at last put a useful help string if available */
1016 if( config_data->psz_help && *config_data->psz_help )
1018 sizer->Add( new wxStaticLine( this, 0 ), 0,
1019 wxEXPAND | wxLEFT | wxRIGHT, 2 );
1020 help = new wxStaticText( this, -1, wxU(_(config_data->psz_help)),
1021 wxDefaultPosition, wxDefaultSize,
1024 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
1027 if( config_data->i_type == TYPE_MODULE )
1029 vlc_object_release( p_module );
1033 vlc_list_release( p_list );
1041 void PrefsPanel::ApplyChanges()
1045 for( size_t i = 0; i < config_array.GetCount(); i++ )
1047 ConfigControl *control = config_array.Item(i);
1049 switch( control->GetType() )
1051 case CONFIG_ITEM_STRING:
1052 case CONFIG_ITEM_FILE:
1053 case CONFIG_ITEM_DIRECTORY:
1054 case CONFIG_ITEM_MODULE:
1055 case CONFIG_ITEM_MODULE_CAT:
1056 case CONFIG_ITEM_MODULE_LIST:
1057 case CONFIG_ITEM_MODULE_LIST_CAT:
1058 config_PutPsz( p_intf, control->GetName().mb_str(),
1059 control->GetPszValue().mb_str() );
1061 case CONFIG_ITEM_KEY:
1062 /* So you don't need to restart to have the changes take effect */
1063 val.i_int = control->GetIntValue();
1064 var_Set( p_intf->p_vlc, control->GetName().mb_str(), val );
1065 case CONFIG_ITEM_INTEGER:
1066 case CONFIG_ITEM_BOOL:
1067 config_PutInt( p_intf, control->GetName().mb_str(),
1068 control->GetIntValue() );
1070 case CONFIG_ITEM_FLOAT:
1071 config_PutFloat( p_intf, control->GetName().mb_str(),
1072 control->GetFloatValue() );
1078 void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
1080 bool hidden = false;
1082 if( b_advanced == b_new_advanced )
1087 if( config_sizer && config_window )
1089 b_advanced = b_new_advanced;
1091 for( size_t i = 0; i < config_array.GetCount(); i++ )
1093 ConfigControl *control = config_array.Item(i);
1094 if( control->IsAdvanced() )
1096 if( !b_advanced ) hidden = true;
1097 control->Show( b_advanced );
1098 config_sizer->Show( control, b_advanced );
1102 config_sizer->Layout();
1103 config_window->FitInside();
1104 config_window->Refresh();
1107 if( hidden && hidden_text )
1109 hidden_text->Show( true );
1110 config_sizer->Show( hidden_text, true );
1112 else if ( hidden_text )
1114 hidden_text->Show( false );
1115 config_sizer->Show( hidden_text, false );