00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028 #include <errno.h>
00029 #include <string.h>
00030 #include <stdio.h>
00031
00032 #include <vlc/vlc.h>
00033 #include <vlc/intf.h>
00034
00035 #include <vlc_config_cat.h>
00036
00037 #include "wxwidgets.h"
00038 #include "preferences_widgets.h"
00039
00040 #include <wx/combobox.h>
00041 #include <wx/statline.h>
00042 #include <wx/clntdata.h>
00043 #include <wx/dynarray.h>
00044 #include <wx/imaglist.h>
00045
00046 #include "bitmaps/type_net.xpm"
00047 #include "bitmaps/codec.xpm"
00048 #include "bitmaps/video.xpm"
00049 #include "bitmaps/type_playlist.xpm"
00050 #include "bitmaps/advanced.xpm"
00051 #include "bitmaps/intf.xpm"
00052 #include "bitmaps/audio.xpm"
00053
00054 #ifndef wxRB_SINGLE
00055 # define wxRB_SINGLE 0
00056 #endif
00057
00058 #define TYPE_CATEGORY 0
00059 #define TYPE_CATSUBCAT 1
00060 #define TYPE_SUBCATEGORY 2
00061 #define TYPE_MODULE 3
00062
00063
00064
00065
00066 class ConfigTreeData;
00067 class PrefsTreeCtrl : public wxTreeCtrl
00068 {
00069 public:
00070
00071 PrefsTreeCtrl() { }
00072 PrefsTreeCtrl( wxWindow *parent, intf_thread_t *_p_intf,
00073 PrefsDialog *p_prefs_dialog, wxBoxSizer *_p_sizer );
00074 virtual ~PrefsTreeCtrl();
00075
00076 void ApplyChanges();
00077 void CleanChanges();
00078
00079 private:
00080
00081 void OnSelectTreeItem( wxTreeEvent& event );
00082 void OnAdvanced( wxCommandEvent& event );
00083
00084 ConfigTreeData *FindModuleConfig( ConfigTreeData *config_data );
00085
00086 DECLARE_EVENT_TABLE()
00087
00088 intf_thread_t *p_intf;
00089 PrefsDialog *p_prefs_dialog;
00090 wxBoxSizer *p_sizer;
00091 wxWindow *p_parent;
00092 vlc_bool_t b_advanced;
00093
00094 wxTreeItemId root_item;
00095 wxTreeItemId plugins_item;
00096 };
00097
00098 WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
00099
00100 class PrefsPanel : public wxPanel
00101 {
00102 public:
00103
00104 PrefsPanel() { }
00105 PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
00106 PrefsDialog *, ConfigTreeData* );
00107 virtual ~PrefsPanel() {}
00108
00109 void ApplyChanges();
00110 void SwitchAdvanced( vlc_bool_t );
00111
00112 private:
00113 intf_thread_t *p_intf;
00114 PrefsDialog *p_prefs_dialog;
00115
00116 vlc_bool_t b_advanced;
00117
00118 wxStaticText *hidden_text;
00119 wxBoxSizer *config_sizer;
00120 wxScrolledWindow *config_window;
00121
00122 ArrayOfConfigControls config_array;
00123 };
00124
00125 class ConfigTreeData : public wxTreeItemData
00126 {
00127 public:
00128
00129 ConfigTreeData() { b_submodule = 0; panel = NULL; psz_name = NULL;
00130 psz_help = NULL; }
00131 virtual ~ConfigTreeData() {
00132 if( panel ) delete panel;
00133 if( psz_name ) free( psz_name );
00134 if( psz_help ) free( psz_help );
00135 };
00136
00137 vlc_bool_t b_submodule;
00138
00139 PrefsPanel *panel;
00140 wxBoxSizer *sizer;
00141
00142 int i_object_id;
00143 int i_subcat_id;
00144 int i_type;
00145 char *psz_name;
00146 char *psz_help;
00147 };
00148
00149
00150
00151
00152
00153
00154 enum
00155 {
00156 Notebook_Event = wxID_HIGHEST,
00157 MRL_Event,
00158 ResetAll_Event,
00159 Advanced_Event,
00160 };
00161
00162 BEGIN_EVENT_TABLE(PrefsDialog, wxFrame)
00163
00164 EVT_BUTTON(wxID_OK, PrefsDialog::OnOk)
00165 EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel)
00166 EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave)
00167 EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll)
00168 EVT_CHECKBOX(Advanced_Event, PrefsDialog::OnAdvanced)
00169
00170
00171 EVT_CLOSE(PrefsDialog::OnClose)
00172 END_EVENT_TABLE()
00173
00174
00175 enum
00176 {
00177 PrefsTree_Ctrl = wxID_HIGHEST
00178 };
00179
00180 BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
00181 EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem)
00182 EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced)
00183 END_EVENT_TABLE()
00184
00185
00186
00187
00188 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent)
00189 : wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition,
00190 wxSize(700,450), wxDEFAULT_FRAME_STYLE )
00191 {
00192
00193 p_intf = _p_intf;
00194 SetIcon( *p_intf->p_sys->p_icon );
00195
00196
00197 wxPanel *panel = new wxPanel( this, -1 );
00198 panel->SetAutoLayout( TRUE );
00199
00200
00201 wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL );
00202 prefs_tree =
00203 new PrefsTreeCtrl( panel, p_intf, this, controls_sizer );
00204
00205
00206 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
00207
00208
00209 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
00210 ok_button->SetDefault();
00211 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
00212 wxU(_("Cancel")) );
00213 wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("Save")) );
00214 wxButton *reset_button = new wxButton( panel, ResetAll_Event,
00215 wxU(_("Reset All")) );
00216
00217 wxPanel *dummy_panel = new wxPanel( this, -1 );
00218 wxCheckBox *advanced_checkbox =
00219 new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) );
00220
00221 if( config_GetInt( p_intf, "advanced" ) )
00222 {
00223 advanced_checkbox->SetValue(TRUE);
00224 wxCommandEvent dummy_event;
00225 dummy_event.SetInt(TRUE);
00226 OnAdvanced( dummy_event );
00227 }
00228
00229
00230 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
00231 button_sizer->Add( ok_button, 0, wxALL, 5 );
00232 button_sizer->Add( cancel_button, 0, wxALL, 5 );
00233 button_sizer->Add( save_button, 0, wxALL, 5 );
00234 button_sizer->Add( reset_button, 0, wxALL, 5 );
00235 button_sizer->Add( dummy_panel, 1, wxALL, 5 );
00236 button_sizer->Add( advanced_checkbox, 0, wxALL | wxALIGN_RIGHT |
00237 wxALIGN_CENTER_VERTICAL, 0 );
00238 button_sizer->Layout();
00239
00240 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
00241 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
00242 panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 );
00243 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
00244 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
00245 wxALL | wxEXPAND, 5 );
00246 panel_sizer->Layout();
00247 panel->SetSizer( panel_sizer );
00248 main_sizer->Add( panel, 1, wxEXPAND, 0 );
00249 main_sizer->Layout();
00250 SetSizer( main_sizer );
00251 }
00252
00253 PrefsDialog::~PrefsDialog()
00254 {
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
00266 {
00267 prefs_tree->ApplyChanges();
00268 this->Hide();
00269 prefs_tree->CleanChanges();
00270 }
00271
00272 void PrefsDialog::OnClose( wxCloseEvent& WXUNUSED(event) )
00273 {
00274 wxCommandEvent cevent;
00275 OnCancel(cevent);
00276 }
00277
00278 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
00279 {
00280 this->Hide();
00281 prefs_tree->CleanChanges();
00282 }
00283
00284 void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
00285 {
00286 prefs_tree->ApplyChanges();
00287 config_SaveConfigFile( p_intf, NULL );
00288 this->Hide();
00289 }
00290
00291 void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
00292 {
00293 wxMessageDialog dlg( this,
00294 wxU(_("Beware this will reset your VLC media player preferences.\n"
00295 "Are you sure you want to continue?")),
00296 wxU(_("Reset Preferences")), wxYES_NO|wxNO_DEFAULT|wxCENTRE );
00297
00298 if ( dlg.ShowModal() == wxID_YES )
00299 {
00300
00301 config_ResetAll( p_intf );
00302 prefs_tree->CleanChanges();
00303 config_SaveConfigFile( p_intf, NULL );
00304 }
00305 }
00306
00307 void PrefsDialog::OnAdvanced( wxCommandEvent& event )
00308 {
00309 wxCommandEvent newevent( wxEVT_USER_FIRST, Advanced_Event );
00310 newevent.SetInt( event.GetInt() );
00311
00312 prefs_tree->AddPendingEvent( newevent );
00313 }
00314
00315
00316
00317
00318 PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
00319 PrefsDialog *_p_prefs_dialog,
00320 wxBoxSizer *_p_sizer )
00321 : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxSize(200,-1),
00322 wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT |
00323 wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT |
00324 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER )
00325 {
00326 vlc_list_t *p_list = NULL;;
00327 module_t *p_module;
00328 module_config_t *p_item;
00329 int i_index, i_image=0;
00330
00331
00332 p_intf = _p_intf;
00333 p_prefs_dialog = _p_prefs_dialog;
00334 p_sizer = _p_sizer;
00335 p_parent = _p_parent;
00336 b_advanced = VLC_FALSE;
00337
00338 root_item = AddRoot( wxT("") );
00339 wxASSERT_MSG(root_item.IsOk(), wxT("Could not add root item"));
00340
00341 wxImageList *p_images = new wxImageList( 16,16,TRUE );
00342 p_images->Add( wxIcon( audio_xpm ) );
00343 p_images->Add( wxIcon( video_xpm ) );
00344 p_images->Add( wxIcon( codec_xpm ) );
00345 p_images->Add( wxIcon( type_net_xpm ) );
00346 p_images->Add( wxIcon( advanced_xpm ) );
00347 p_images->Add( wxIcon( type_playlist_xpm ) );
00348 p_images->Add( wxIcon( intf_xpm ) );
00349 AssignImageList( p_images );
00350
00351
00352 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
00353 if( !p_list ) return;
00354
00355
00356 for( i_index = 0; i_index < p_list->i_count; i_index++ )
00357 {
00358 p_module = (module_t *)p_list->p_values[i_index].p_object;
00359 if( !strcmp( p_module->psz_object_name, "main" ) )
00360 break;
00361 }
00362 if( i_index < p_list->i_count )
00363 {
00364 wxTreeItemId current_item;
00365 char *psz_help;
00366
00367
00368
00369
00370 p_item = p_module->p_config;
00371
00372 if( p_item ) do
00373 {
00374 ConfigTreeData *config_data;
00375 switch( p_item->i_type )
00376 {
00377 case CONFIG_CATEGORY:
00378 config_data = new ConfigTreeData;
00379 config_data->psz_name = strdup( config_CategoryNameGet(
00380 p_item->i_value ) );
00381 psz_help = config_CategoryHelpGet( p_item->i_value );
00382 if( psz_help )
00383 {
00384 config_data->psz_help = wraptext( strdup( psz_help ),
00385 72 , 1 );
00386 }
00387 else
00388 {
00389 config_data->psz_help = NULL;
00390 }
00391 config_data->i_type = TYPE_CATEGORY;
00392 config_data->i_object_id = p_item->i_value;
00393
00394
00395 switch( p_item->i_value )
00396 {
00397 case CAT_AUDIO:
00398 i_image = 0; break;
00399 case CAT_VIDEO:
00400 i_image = 1; break;
00401 case CAT_INPUT:
00402 i_image = 2; break;
00403 case CAT_SOUT:
00404 i_image = 3; break;
00405 case CAT_ADVANCED:
00406 i_image = 4; break;
00407 case CAT_PLAYLIST:
00408 i_image = 5; break;
00409 case CAT_INTERFACE:
00410 i_image = 6; break;
00411 }
00412 current_item = AppendItem( root_item,
00413 wxU( config_data->psz_name ),
00414 i_image, -1, config_data );
00415
00416 break;
00417 case CONFIG_SUBCATEGORY:
00418 if( p_item->i_value == SUBCAT_VIDEO_GENERAL ||
00419 p_item->i_value == SUBCAT_AUDIO_GENERAL )
00420 {
00421 ConfigTreeData *cd = (ConfigTreeData *)
00422 GetItemData( current_item );
00423 cd->i_type = TYPE_CATSUBCAT;
00424 cd->i_subcat_id = p_item->i_value;
00425 if( cd->psz_name ) free( cd->psz_name );
00426 cd->psz_name = strdup( config_CategoryNameGet(
00427 p_item->i_value ) );
00428 if( cd->psz_help ) free( cd->psz_help );
00429 char *psz_help = config_CategoryHelpGet( p_item->i_value );
00430 if( psz_help )
00431 {
00432 cd->psz_help = wraptext( strdup( psz_help ),72 ,
00433 1 );
00434 }
00435 else
00436 {
00437 cd->psz_help = NULL;
00438 }
00439 continue;
00440 }
00441
00442 config_data = new ConfigTreeData;
00443
00444 config_data->psz_name = strdup( config_CategoryNameGet(
00445 p_item->i_value ) );
00446 psz_help = config_CategoryHelpGet( p_item->i_value );
00447 if( psz_help )
00448 {
00449 config_data->psz_help = wraptext( strdup( psz_help ) ,
00450 72 , 1 );
00451 }
00452 else
00453 {
00454 config_data->psz_help = NULL;
00455 }
00456 config_data->i_type = TYPE_SUBCATEGORY;
00457 config_data->i_object_id = p_item->i_value;
00458
00459 #ifdef __WXMSW__
00460 switch( p_item->i_value / 100 )
00461 {
00462 case CAT_AUDIO:
00463 i_image = 0; break;
00464 case CAT_VIDEO:
00465 i_image = 1; break;
00466 case CAT_INPUT:
00467 i_image = 2; break;
00468 case CAT_SOUT:
00469 i_image = 3; break;
00470 case CAT_ADVANCED:
00471 i_image = 4; break;
00472 case CAT_PLAYLIST:
00473 i_image = 5; break;
00474 case CAT_INTERFACE:
00475 i_image = 6; break;
00476 }
00477 #else
00478 i_image = -1;
00479 #endif
00480 AppendItem( current_item, wxU( config_data->psz_name ),
00481 i_image, -1, config_data );
00482 break;
00483 }
00484 }
00485 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
00486
00487 }
00488
00489
00490
00491
00492
00493 for( i_index = 0; i_index < p_list->i_count; i_index++ )
00494 {
00495 int i_category = -1;
00496 int i_subcategory = -1;
00497 int i_options = 0;
00498
00499 p_module = (module_t *)p_list->p_values[i_index].p_object;
00500
00501
00502 if( !strcmp( p_module->psz_object_name, "main" ) )
00503 continue;
00504
00505
00506
00507 if( p_module->b_submodule )
00508 continue;
00509
00510 else
00511 p_item = p_module->p_config;
00512
00513
00514 if( !p_item ) continue;
00515 do
00516 {
00517 if( p_item->i_type == CONFIG_CATEGORY )
00518 {
00519 i_category = p_item->i_value;
00520 }
00521 else if( p_item->i_type == CONFIG_SUBCATEGORY )
00522 {
00523 i_subcategory = p_item->i_value;
00524 }
00525 if( p_item->i_type & CONFIG_ITEM )
00526 i_options ++;
00527 if( i_options > 0 && i_category >= 0 && i_subcategory >= 0 )
00528 {
00529 break;
00530 }
00531 }
00532 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
00533
00534 if( !i_options ) continue;
00535
00536
00537 wxTreeItemIdValue cookie;
00538 vlc_bool_t b_found = VLC_FALSE;
00539
00540 wxTreeItemId category_item = GetFirstChild( root_item , cookie);
00541 while( category_item.IsOk() )
00542 {
00543 ConfigTreeData *config_data =
00544 (ConfigTreeData *)GetItemData( category_item );
00545 if( config_data->i_object_id == i_category )
00546 {
00547 b_found = VLC_TRUE;
00548 break;
00549 }
00550 category_item = GetNextChild( root_item, cookie );
00551 }
00552
00553 if( !b_found ) continue;
00554
00555
00556 b_found = VLC_FALSE;
00557
00558 wxTreeItemId subcategory_item = GetFirstChild( category_item, cookie );
00559 while( subcategory_item.IsOk() )
00560 {
00561 ConfigTreeData *config_data =
00562 (ConfigTreeData *)GetItemData( subcategory_item );
00563 if( config_data->i_object_id == i_subcategory )
00564 {
00565 b_found = VLC_TRUE;
00566 break;
00567 }
00568 subcategory_item = GetNextChild( category_item, cookie );
00569 }
00570 if( !b_found )
00571 {
00572 subcategory_item = category_item;
00573 }
00574
00575
00576 ConfigTreeData *config_data = new ConfigTreeData;
00577 config_data->b_submodule = p_module->b_submodule;
00578 config_data->i_type = TYPE_MODULE;
00579 config_data->i_object_id = p_module->b_submodule ?
00580 ((module_t *)p_module->p_parent)->i_object_id :
00581 p_module->i_object_id;
00582 config_data->psz_help = NULL;
00583
00584
00585 #ifdef __WXMSW__
00586 switch( i_subcategory / 100 )
00587 {
00588 case CAT_AUDIO:
00589 i_image = 0; break;
00590 case CAT_VIDEO:
00591 i_image = 1; break;
00592 case CAT_INPUT:
00593 i_image = 2; break;
00594 case CAT_SOUT:
00595 i_image = 3; break;
00596 case CAT_ADVANCED:
00597 i_image = 4; break;
00598 case CAT_PLAYLIST:
00599 i_image = 5; break;
00600 case CAT_INTERFACE:
00601 i_image = 6; break;
00602 }
00603 #else
00604 i_image = -1;
00605 #endif
00606 AppendItem( subcategory_item, wxU( p_module->psz_shortname ?
00607 p_module->psz_shortname : p_module->psz_object_name )
00608 , i_image, -1,
00609 config_data );
00610 }
00611
00612
00613 wxTreeItemIdValue cookie;
00614 size_t i_child_index;
00615 wxTreeItemId capability_item = GetFirstChild( root_item, cookie);
00616 for( i_child_index = 0;
00617 (capability_item.IsOk() &&
00618
00619 (i_child_index < GetChildrenCount( root_item, FALSE )));
00620 i_child_index++ )
00621 {
00622 SortChildren( capability_item );
00623
00624 capability_item = GetNextChild( root_item, cookie );
00625 }
00626
00627
00628 vlc_list_release( p_list );
00629
00630 p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );
00631 p_sizer->Layout();
00632
00633
00634 #ifndef WIN32
00635 SelectItem( GetFirstChild( root_item, cookie ) );
00636 #endif
00637
00638
00639
00640 }
00641
00642 PrefsTreeCtrl::~PrefsTreeCtrl(){
00643 }
00644
00645 void PrefsTreeCtrl::ApplyChanges()
00646 {
00647 wxTreeItemIdValue cookie, cookie2, cookie3;
00648 ConfigTreeData *config_data;
00649
00650 wxTreeItemId category = GetFirstChild( root_item, cookie );
00651 while( category.IsOk() )
00652 {
00653 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
00654 while( subcategory.IsOk() )
00655 {
00656 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
00657 while( module.IsOk() )
00658 {
00659 config_data = (ConfigTreeData *)GetItemData( module );
00660 if( config_data && config_data->panel )
00661 {
00662 config_data->panel->ApplyChanges();
00663 }
00664 module = GetNextChild( subcategory, cookie3 );
00665 }
00666 config_data = (ConfigTreeData *)GetItemData( subcategory );
00667 if( config_data && config_data->panel )
00668 {
00669 config_data->panel->ApplyChanges();
00670 }
00671 subcategory = GetNextChild( category, cookie2 );
00672 }
00673 config_data = (ConfigTreeData *)GetItemData( category );
00674 if( config_data && config_data->panel )
00675 {
00676 config_data->panel->ApplyChanges();
00677 }
00678 category = GetNextChild( root_item, cookie );
00679 }
00680 }
00681
00682 void PrefsTreeCtrl::CleanChanges()
00683 {
00684 wxTreeItemIdValue cookie, cookie2, cookie3;
00685 ConfigTreeData *config_data;
00686
00687 config_data = !GetSelection() ? NULL :
00688 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
00689 if( config_data )
00690 {
00691 config_data->panel->Hide();
00692 #if (wxCHECK_VERSION(2,5,0))
00693 p_sizer->Detach( config_data->panel );
00694 #else
00695 p_sizer->Remove( config_data->panel );
00696 #endif
00697 }
00698
00699 wxTreeItemId category = GetFirstChild( root_item, cookie );
00700 while( category.IsOk() )
00701 {
00702 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
00703 while( subcategory.IsOk() )
00704 {
00705 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
00706 while( module.IsOk() )
00707 {
00708 config_data = (ConfigTreeData *)GetItemData( module );
00709 if( config_data && config_data->panel )
00710 {
00711 delete config_data->panel;
00712 config_data->panel = NULL;
00713 }
00714 module = GetNextChild( subcategory, cookie3 );
00715 }
00716 config_data = (ConfigTreeData *)GetItemData( subcategory );
00717 if( config_data && config_data->panel )
00718 {
00719 delete config_data->panel;
00720 config_data->panel = NULL;
00721 }
00722 subcategory = GetNextChild( category, cookie2 );
00723 }
00724 config_data = (ConfigTreeData *)GetItemData( category );
00725 if( config_data && config_data->panel )
00726 {
00727 delete config_data->panel;
00728 config_data->panel = NULL;
00729 }
00730 category = GetNextChild( root_item, cookie );
00731 }
00732
00733 if( GetSelection() )
00734 {
00735 wxTreeEvent event;
00736 OnSelectTreeItem( event );
00737 }
00738 }
00739
00740 ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
00741 {
00742
00743
00744
00745 if( !config_data || !config_data->b_submodule )
00746 {
00747 return config_data;
00748 }
00749
00750 wxTreeItemIdValue cookie, cookie2, cookie3;
00751 ConfigTreeData *config_new;
00752 wxTreeItemId category = GetFirstChild( root_item, cookie );
00753 while( category.IsOk() )
00754 {
00755 wxTreeItemId subcategory = GetFirstChild( category, cookie2 );
00756 while( subcategory.IsOk() )
00757 {
00758 wxTreeItemId module = GetFirstChild( subcategory, cookie3 );
00759 while( module.IsOk() )
00760 {
00761 config_new = (ConfigTreeData *)GetItemData( module );
00762 if( config_new && !config_new->b_submodule &&
00763 config_new->i_object_id == config_data->i_object_id )
00764 {
00765 return config_new;
00766 }
00767 module = GetNextChild( subcategory, cookie3 );
00768 }
00769 subcategory = GetNextChild( category, cookie2 );
00770 }
00771 category = GetNextChild( root_item, cookie );
00772 }
00773
00774
00775 return NULL;
00776 }
00777
00778 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
00779 {
00780 ConfigTreeData *config_data = NULL;
00781
00782 if( event.GetOldItem() )
00783 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
00784 event.GetOldItem() ) );
00785 if( config_data && config_data->panel )
00786 {
00787 config_data->panel->Hide();
00788 #if (wxCHECK_VERSION(2,5,0))
00789 p_sizer->Detach( config_data->panel );
00790 #else
00791 p_sizer->Remove( config_data->panel );
00792 #endif
00793 }
00794
00795
00796 config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
00797 GetSelection() ) );
00798 if( config_data )
00799 {
00800 if( !config_data->panel )
00801 {
00802
00803 config_data->panel =
00804 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
00805 config_data );
00806 config_data->panel->SwitchAdvanced( b_advanced );
00807 }
00808 else
00809 {
00810 config_data->panel->SwitchAdvanced( b_advanced );
00811 config_data->panel->Show();
00812 }
00813
00814 p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );
00815 p_sizer->Layout();
00816 }
00817 }
00818
00819 void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event )
00820 {
00821 b_advanced = event.GetInt();
00822
00823 ConfigTreeData *config_data = !GetSelection() ? NULL :
00824 FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
00825 if( config_data )
00826 {
00827 config_data->panel->Hide();
00828 #if (wxCHECK_VERSION(2,5,0))
00829 p_sizer->Detach( config_data->panel );
00830 #else
00831 p_sizer->Remove( config_data->panel );
00832 #endif
00833 }
00834
00835 if( GetSelection() )
00836 {
00837 wxTreeEvent event;
00838 OnSelectTreeItem( event );
00839 }
00840 }
00841
00842
00843
00844
00845 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
00846 PrefsDialog *_p_prefs_dialog,
00847 ConfigTreeData *config_data )
00848 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
00849 {
00850 module_config_t *p_item;
00851 vlc_list_t *p_list = NULL;;
00852
00853 wxStaticText *label;
00854 wxStaticText *help;
00855 wxArrayString array;
00856
00857 module_t *p_module = NULL;
00858
00859
00860 p_intf = _p_intf;
00861 p_prefs_dialog =_p_prefs_dialog,
00862
00863 b_advanced = VLC_TRUE;
00864 SetAutoLayout( TRUE );
00865 Hide();
00866
00867 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
00868
00869
00870 if( config_data->i_type == TYPE_CATEGORY )
00871 {
00872 label = new wxStaticText( this, -1,wxU(_( config_data->psz_name )));
00873 wxFont heading_font = label->GetFont();
00874 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
00875 label->SetFont( heading_font );
00876 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
00877 sizer->Add( new wxStaticLine( this, 0 ), 0,
00878 wxEXPAND | wxLEFT | wxRIGHT, 2 );
00879
00880 hidden_text = NULL;
00881 help = new wxStaticText( this, -1, wxU(_( config_data->psz_help ) ) );
00882 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
00883
00884 config_sizer = NULL; config_window = NULL;
00885 }
00886 else
00887 {
00888
00889 if( config_data->i_type == TYPE_MODULE )
00890 {
00891 p_module = (module_t *)vlc_object_get( p_intf,
00892 config_data->i_object_id );
00893 }
00894 else
00895 {
00896
00897 int i_index;
00898 vlc_bool_t b_found = VLC_FALSE;
00899 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
00900 if( !p_list ) return;
00901
00902 for( i_index = 0; i_index < p_list->i_count; i_index++ )
00903 {
00904 p_module = (module_t *)p_list->p_values[i_index].p_object;
00905 if( !strcmp( p_module->psz_object_name, "main" ) )
00906 {
00907 b_found = VLC_TRUE;
00908 break;
00909 }
00910 }
00911 if( !p_module && !b_found )
00912 {
00913 msg_Warn( p_intf, "ohoh, unable to find main module" );
00914 return;
00915 }
00916 }
00917
00918 if( p_module->i_object_type != VLC_OBJECT_MODULE )
00919 {
00920
00921 return;
00922 }
00923
00924
00925
00926
00927 if( p_module->b_submodule )
00928 p_item = ((module_t *)p_module->p_parent)->p_config;
00929 else
00930 p_item = p_module->p_config;
00931
00932
00933 if( config_data->i_type == TYPE_SUBCATEGORY ||
00934 config_data->i_type == TYPE_CATSUBCAT )
00935 {
00936 do
00937 {
00938 if( p_item->i_type == CONFIG_SUBCATEGORY &&
00939 ( config_data->i_type == TYPE_SUBCATEGORY &&
00940 p_item->i_value == config_data->i_object_id ) ||
00941 ( config_data->i_type == TYPE_CATSUBCAT &&
00942 p_item->i_value == config_data->i_subcat_id ) )
00943 {
00944 break;
00945 }
00946 if( p_item->i_type == CONFIG_HINT_END )
00947 break;
00948 } while( p_item++ );
00949 }
00950
00951
00952 char *psz_head;
00953 if( config_data->i_type == TYPE_SUBCATEGORY ||
00954 config_data->i_type == TYPE_CATSUBCAT )
00955 {
00956 psz_head = config_data->psz_name;
00957 p_item++;
00958 }
00959 else
00960 {
00961 psz_head = p_module->psz_longname;
00962 }
00963
00964 label = new wxStaticText( this, -1,
00965 wxU(_( psz_head ? psz_head : _("Unknown") ) ) );
00966 wxFont heading_font = label->GetFont();
00967 heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
00968 label->SetFont( heading_font );
00969 sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
00970 sizer->Add( new wxStaticLine( this, 0 ), 0,
00971 wxEXPAND | wxLEFT | wxRIGHT, 2 );
00972
00973
00974 config_sizer = new wxBoxSizer( wxVERTICAL );
00975 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
00976 wxDefaultSize, wxBORDER_NONE | wxHSCROLL | wxVSCROLL );
00977 config_window->SetAutoLayout( TRUE );
00978 config_window->SetScrollRate( 5, 5 );
00979
00980 if( p_item ) do
00981 {
00982
00983 if( ( ( config_data->i_type == TYPE_SUBCATEGORY &&
00984 p_item->i_value != config_data->i_object_id ) ||
00985 ( config_data->i_type == TYPE_CATSUBCAT &&
00986 p_item->i_value != config_data->i_subcat_id ) ) &&
00987 (p_item->i_type == CONFIG_CATEGORY ||
00988 p_item->i_type == CONFIG_SUBCATEGORY ) )
00989 break;
00990
00991 ConfigControl *control =
00992 CreateConfigControl( VLC_OBJECT(p_intf),
00993 p_item, config_window );
00994
00995
00996 if( control == NULL ) continue;
00997
00998
00999 config_array.Add( control );
01000
01001 config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
01002 }
01003 while( !( p_item->i_type == CONFIG_HINT_END ||
01004 ( ( config_data->i_type == TYPE_SUBCATEGORY ||
01005 config_data->i_type == TYPE_CATSUBCAT ) &&
01006 ( p_item->i_type == CONFIG_CATEGORY ||
01007 p_item->i_type == CONFIG_SUBCATEGORY ) ) ) && p_item++ );
01008
01009
01010 config_sizer->Layout();
01011 config_window->SetSizer( config_sizer );
01012 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
01013 hidden_text = new wxStaticText( this, -1,
01014 wxU( _( "Some options are available but hidden. " \
01015 "Check \"Advanced options\" to see them." ) ) );
01016 sizer->Add( hidden_text );
01017
01018
01019 if( config_data->psz_help && *config_data->psz_help )
01020 {
01021 sizer->Add( new wxStaticLine( this, 0 ), 0,
01022 wxEXPAND | wxLEFT | wxRIGHT, 2 );
01023 help = new wxStaticText( this, -1, wxU(_(config_data->psz_help)),
01024 wxDefaultPosition, wxDefaultSize,
01025 wxALIGN_LEFT,
01026 wxT("") );
01027 sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
01028 }
01029
01030 if( config_data->i_type == TYPE_MODULE )
01031 {
01032 vlc_object_release( p_module );
01033 }
01034 else
01035 {
01036 vlc_list_release( p_list );
01037 }
01038 }
01039 sizer->Layout();
01040 SetSizer( sizer );
01041 Show();
01042 }
01043
01044 void PrefsPanel::ApplyChanges()
01045 {
01046 vlc_value_t val;
01047
01048 for( size_t i = 0; i < config_array.GetCount(); i++ )
01049 {
01050 ConfigControl *control = config_array.Item(i);
01051
01052 switch( control->GetType() )
01053 {
01054 case CONFIG_ITEM_STRING:
01055 case CONFIG_ITEM_FILE:
01056 case CONFIG_ITEM_DIRECTORY:
01057 case CONFIG_ITEM_MODULE:
01058 case CONFIG_ITEM_MODULE_CAT:
01059 case CONFIG_ITEM_MODULE_LIST:
01060 case CONFIG_ITEM_MODULE_LIST_CAT:
01061 config_PutPsz( p_intf, control->GetName().mb_str(),
01062 control->GetPszValue().mb_str() );
01063 break;
01064 case CONFIG_ITEM_KEY:
01065
01066 val.i_int = control->GetIntValue();
01067 var_Set( p_intf->p_vlc, control->GetName().mb_str(), val );
01068 case CONFIG_ITEM_INTEGER:
01069 case CONFIG_ITEM_BOOL:
01070 config_PutInt( p_intf, control->GetName().mb_str(),
01071 control->GetIntValue() );
01072 break;
01073 case CONFIG_ITEM_FLOAT:
01074 config_PutFloat( p_intf, control->GetName().mb_str(),
01075 control->GetFloatValue() );
01076 break;
01077 }
01078 }
01079 }
01080
01081 void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
01082 {
01083 bool hidden = false;
01084
01085 if( b_advanced == b_new_advanced )
01086 {
01087 goto hide;
01088 }
01089
01090 if( config_sizer && config_window )
01091 {
01092 b_advanced = b_new_advanced;
01093
01094 for( size_t i = 0; i < config_array.GetCount(); i++ )
01095 {
01096 ConfigControl *control = config_array.Item(i);
01097 if( control->IsAdvanced() )
01098 {
01099 if( !b_advanced ) hidden = true;
01100 control->Show( b_advanced );
01101 config_sizer->Show( control, b_advanced );
01102 }
01103 }
01104
01105 config_sizer->Layout();
01106 config_window->FitInside();
01107 config_window->Refresh();
01108 }
01109 hide:
01110 if( hidden && hidden_text )
01111 {
01112 hidden_text->Show( true );
01113 config_sizer->Show( hidden_text, true );
01114 }
01115 else if ( hidden_text )
01116 {
01117 hidden_text->Show( false );
01118 config_sizer->Show( hidden_text, false );
01119 }
01120 return;
01121 }