1 /*****************************************************************************
2 * preferences.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: preferences.cpp,v 1.18 2003/06/05 21:22:28 gbazin Exp $
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() */
34 #ifdef WIN32 /* mingw32 hack */
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
42 #include <wx/wxprec.h>
44 #include <wx/window.h>
45 #include <wx/notebook.h>
46 #include <wx/textctrl.h>
47 #include <wx/combobox.h>
48 #include <wx/spinctrl.h>
49 #include <wx/statline.h>
50 #include <wx/treectrl.h>
51 #include <wx/clntdata.h>
52 #include <wx/dynarray.h>
56 #if defined MODULE_NAME_IS_skins
57 # include "../skins/src/skin_common.h"
60 #include "wxwindows.h"
63 # define wxRB_SINGLE 0
66 /*****************************************************************************
67 * Classes declarations.
68 *****************************************************************************/
69 class PrefsTreeCtrl : public wxTreeCtrl
74 PrefsTreeCtrl( wxWindow *parent, intf_thread_t *_p_intf,
75 PrefsDialog *p_prefs_dialog, wxBoxSizer *_p_sizer );
76 virtual ~PrefsTreeCtrl();
82 /* Event handlers (these functions should _not_ be virtual) */
83 void OnSelectTreeItem( wxTreeEvent& event );
87 intf_thread_t *p_intf;
88 PrefsDialog *p_prefs_dialog;
92 wxTreeItemId root_item;
93 wxTreeItemId plugins_item;
98 ConfigData( wxPanel *_panel, int _i_conf_type,
99 vlc_bool_t _b_advanced, char *psz_name )
100 { panel = _panel; b_advanced = _b_advanced; b_config_list = VLC_FALSE;
101 i_config_type = _i_conf_type; option_name = wxU(psz_name); }
103 vlc_bool_t b_advanced;
105 vlc_bool_t b_config_list;
109 wxComboBox *combobox;
110 wxRadioButton *radio;
111 wxSpinCtrl *spinctrl;
112 wxCheckBox *checkbox;
113 wxTextCtrl *textctrl;
118 wxString option_name;
121 WX_DEFINE_ARRAY(ConfigData *, ArrayOfConfigData);
123 class PrefsPanel : public wxPanel
128 PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
129 PrefsDialog *_p_prefs_dialog, int i_object_id, char * );
130 virtual ~PrefsPanel() {}
135 void OnAdvanced( wxCommandEvent& WXUNUSED(event) );
136 DECLARE_EVENT_TABLE()
138 intf_thread_t *p_intf;
139 PrefsDialog *p_prefs_dialog;
141 vlc_bool_t b_advanced;
143 wxBoxSizer *config_sizer;
144 wxScrolledWindow *config_window;
146 ArrayOfConfigData config_array;
149 class ConfigTreeData : public wxTreeItemData
153 ConfigTreeData() { panel = NULL; psz_section = NULL; }
154 virtual ~ConfigTreeData() { if( panel ) delete panel; }
162 class ConfigEvtHandler : public wxEvtHandler
165 ConfigEvtHandler( intf_thread_t *p_intf, PrefsDialog *p_prefs_dialog );
166 virtual ~ConfigEvtHandler();
168 void ConfigEvtHandler::OnCommandEvent( wxCommandEvent& event );
172 DECLARE_EVENT_TABLE()
174 intf_thread_t *p_intf;
175 PrefsDialog *p_prefs_dialog;
178 /*****************************************************************************
180 *****************************************************************************/
182 /* IDs for the controls and the menu commands */
185 Notebook_Event = wxID_HIGHEST,
191 BEGIN_EVENT_TABLE(PrefsDialog, wxFrame)
193 EVT_BUTTON(wxID_OK, PrefsDialog::OnOk)
194 EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel)
195 EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave)
196 EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll)
198 /* Don't destroy the window when the user closes it */
199 EVT_CLOSE(PrefsDialog::OnCancel)
202 // menu and control ids
205 PrefsTree_Ctrl = wxID_HIGHEST
208 BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
209 EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem)
212 BEGIN_EVENT_TABLE(PrefsPanel, wxPanel)
214 EVT_CHECKBOX(Advanced_Event, PrefsPanel::OnAdvanced)
218 BEGIN_EVENT_TABLE(ConfigEvtHandler, wxEvtHandler)
219 EVT_BUTTON(-1, ConfigEvtHandler::OnCommandEvent)
220 EVT_TEXT(-1, ConfigEvtHandler::OnCommandEvent)
221 EVT_RADIOBOX(-1, ConfigEvtHandler::OnCommandEvent)
222 EVT_SPINCTRL(-1, ConfigEvtHandler::OnCommandEvent)
225 /*****************************************************************************
227 *****************************************************************************/
228 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent)
229 : wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition,
230 wxSize(650,450), wxDEFAULT_FRAME_STYLE )
232 /* Initializations */
234 SetIcon( *p_intf->p_sys->p_icon );
236 /* Create a panel to put everything in */
237 wxPanel *panel = new wxPanel( this, -1 );
238 panel->SetAutoLayout( TRUE );
240 /* Create the preferences tree control */
241 wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL );
243 new PrefsTreeCtrl( panel, p_intf, this, controls_sizer );
246 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
248 /* Create the buttons */
249 wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
250 ok_button->SetDefault();
251 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
253 wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("Save")) );
254 wxButton *reset_button = new wxButton( panel, ResetAll_Event,
255 wxU(_("Reset All")) );
257 /* Place everything in sizers */
258 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
259 button_sizer->Add( ok_button, 0, wxALL, 5 );
260 button_sizer->Add( cancel_button, 0, wxALL, 5 );
261 button_sizer->Add( save_button, 0, wxALL, 5 );
262 button_sizer->Add( reset_button, 0, wxALL, 5 );
263 button_sizer->Layout();
265 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
266 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
267 panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 );
268 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
269 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
271 panel_sizer->Layout();
272 panel->SetSizer( panel_sizer );
273 main_sizer->Add( panel, 1, wxEXPAND, 0 );
274 main_sizer->Layout();
275 SetSizer( main_sizer );
278 PrefsDialog::~PrefsDialog()
282 /*****************************************************************************
284 *****************************************************************************/
287 /*****************************************************************************
289 *****************************************************************************/
290 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
292 prefs_tree->ApplyChanges();
294 prefs_tree->CleanChanges();
297 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
300 prefs_tree->CleanChanges();
303 void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
305 prefs_tree->ApplyChanges();
306 config_SaveConfigFile( p_intf, NULL );
309 void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
311 wxMessageDialog dlg( this,
312 wxU(_("Beware this will reset your VLC Media Player config file.\n"
313 "Are you sure you want to continue?")),
314 wxU(_("Reset config file")), wxYES_NO|wxNO_DEFAULT|wxCENTRE );
316 if ( dlg.ShowModal() == wxID_YES )
318 /* TODO: need to reset all the controls */
319 config_ResetAll( p_intf );
320 prefs_tree->CleanChanges();
321 config_SaveConfigFile( p_intf, NULL );
325 /*****************************************************************************
326 * PrefsTreeCtrl class definition.
327 *****************************************************************************/
328 PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
329 PrefsDialog *_p_prefs_dialog,
330 wxBoxSizer *_p_sizer )
331 : wxTreeCtrl( _p_parent, PrefsTree_Ctrl, wxDefaultPosition, wxDefaultSize,
332 wxTR_NO_LINES | wxTR_FULL_ROW_HIGHLIGHT |
333 wxTR_LINES_AT_ROOT | wxTR_HIDE_ROOT |
334 wxTR_HAS_BUTTONS | wxTR_TWIST_BUTTONS | wxSUNKEN_BORDER )
338 module_config_t *p_item;
341 /* Initializations */
343 p_prefs_dialog = _p_prefs_dialog;
345 p_parent = _p_parent;
347 root_item = AddRoot( wxT("") );
349 /* List the plugins */
350 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
351 if( !p_list ) return;
354 * Build a tree of the main options
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 /* We found the main module */
366 /* Enumerate config categories and store a reference so we can
367 * generate their config panel them when it is asked by the user. */
368 p_item = p_module->p_config;
372 switch( p_item->i_type )
374 case CONFIG_HINT_CATEGORY:
375 ConfigTreeData *config_data = new ConfigTreeData;
376 config_data->psz_section = strdup(p_item->psz_text);
377 config_data->i_object_id = p_module->i_object_id;
379 /* Add the category to the tree */
380 AppendItem( root_item, wxU(p_item->psz_text),
381 -1, -1, config_data );
385 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
387 SortChildren( root_item );
392 * Build a tree of all the plugins
394 plugins_item = AppendItem( root_item, wxU(_("Plugins")) );
396 for( i_index = 0; i_index < p_list->i_count; i_index++ )
398 p_module = (module_t *)p_list->p_values[i_index].p_object;
400 /* Exclude the main module */
401 if( !strcmp( p_module->psz_object_name, "main" ) )
404 /* Exclude empty plugins */
405 p_item = p_module->p_config;
406 if( !p_item ) continue;
409 if( p_item->i_type & CONFIG_ITEM )
412 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
413 if( p_item->i_type == CONFIG_HINT_END ) continue;
415 /* Find the capability child item */
416 long cookie; size_t i_child_index;
417 wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);
418 for( i_child_index = 0;
419 i_child_index < GetChildrenCount( plugins_item, FALSE );
422 if( !GetItemText(capability_item).Cmp(
423 wxU(p_module->psz_capability ) ) )
427 capability_item = GetNextChild( plugins_item, cookie );
430 if( i_child_index == GetChildrenCount( plugins_item, FALSE ) &&
431 p_module->psz_capability && *p_module->psz_capability )
433 /* We didn't find it, add it */
434 capability_item = AppendItem( plugins_item,
435 wxU(p_module->psz_capability) );
438 /* Add the plugin to the tree */
439 ConfigTreeData *config_data = new ConfigTreeData;
440 config_data->i_object_id = p_module->i_object_id;
441 AppendItem( capability_item, wxU(p_module->psz_object_name), -1, -1,
445 /* Sort all this mess */
446 long cookie; size_t i_child_index;
447 SortChildren( plugins_item );
448 wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);
449 for( i_child_index = 0;
450 i_child_index < GetChildrenCount( plugins_item, FALSE );
453 capability_item = GetNextChild( plugins_item, cookie );
454 SortChildren( capability_item );
457 /* Clean-up everything */
458 vlc_list_release( p_list );
460 p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );
463 /* Update Tree Ctrl */
464 #ifndef WIN32 /* Workaround a bug in win32 implementation */
465 SelectItem( GetFirstChild( root_item, cookie ) );
469 PrefsTreeCtrl::~PrefsTreeCtrl()
473 void PrefsTreeCtrl::ApplyChanges()
475 long cookie, cookie2;
476 ConfigTreeData *config_data;
478 /* Apply changes to the main module */
479 wxTreeItemId item = GetFirstChild( root_item, cookie );
480 for( size_t i_child_index = 0;
481 i_child_index < GetChildrenCount( root_item, FALSE );
484 config_data = (ConfigTreeData *)GetItemData( item );
485 if( config_data && config_data->panel )
487 config_data->panel->ApplyChanges();
490 item = GetNextChild( root_item, cookie );
493 /* Apply changes to the plugins */
494 item = GetFirstChild( plugins_item, cookie );
495 for( size_t i_child_index = 0;
496 i_child_index < GetChildrenCount( plugins_item, FALSE );
499 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
500 for( size_t i_child_index = 0;
501 i_child_index < GetChildrenCount( item, FALSE );
504 config_data = (ConfigTreeData *)GetItemData( item2 );
505 if( config_data && config_data->panel )
507 config_data->panel->ApplyChanges();
510 item2 = GetNextChild( item, cookie2 );
513 item = GetNextChild( plugins_item, cookie );
517 void PrefsTreeCtrl::CleanChanges()
519 long cookie, cookie2;
520 ConfigTreeData *config_data;
522 /* Clean changes for the main module */
523 wxTreeItemId item = GetFirstChild( root_item, cookie );
524 for( size_t i_child_index = 0;
525 i_child_index < GetChildrenCount( root_item, FALSE );
528 config_data = (ConfigTreeData *)GetItemData( item );
529 if( config_data && config_data->panel )
531 if( item == GetSelection() )
533 config_data->panel->Hide();
534 p_sizer->Remove( config_data->panel );
537 delete config_data->panel;
538 config_data->panel = NULL;
540 if( item == GetSelection() )
543 OnSelectTreeItem( event );
547 item = GetNextChild( root_item, cookie );
550 /* Clean changes for the plugins */
551 item = GetFirstChild( plugins_item, cookie );
552 for( size_t i_child_index = 0;
553 i_child_index < GetChildrenCount( plugins_item, FALSE );
556 wxTreeItemId item2 = GetFirstChild( item, cookie2 );
557 for( size_t i_child_index = 0;
558 i_child_index < GetChildrenCount( item, FALSE );
561 config_data = (ConfigTreeData *)GetItemData( item2 );
563 if( config_data && config_data->panel )
565 if( item2 == GetSelection() )
567 config_data->panel->Hide();
568 p_sizer->Remove( config_data->panel );
571 delete config_data->panel;
572 config_data->panel = NULL;
574 if( item2 == GetSelection() )
577 OnSelectTreeItem( event );
581 item2 = GetNextChild( item, cookie2 );
584 item = GetNextChild( plugins_item, cookie );
588 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
590 ConfigTreeData *config_data;
592 config_data = (ConfigTreeData *)GetItemData( event.GetOldItem() );
593 if( config_data && config_data->panel )
595 config_data->panel->Hide();
596 p_sizer->Remove( config_data->panel );
599 /* Don't use event.GetItem() because we also send fake events */
600 config_data = (ConfigTreeData *)GetItemData( GetSelection() );
603 if( !config_data->panel )
605 /* The panel hasn't been created yet. Let's do it. */
607 new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
608 config_data->i_object_id,
609 config_data->psz_section );
613 config_data->panel->Show();
616 p_sizer->Add( config_data->panel, 2, wxEXPAND | wxALL, 0 );
621 /*****************************************************************************
622 * PrefsPanel class definition.
623 *****************************************************************************/
624 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
625 PrefsDialog *_p_prefs_dialog,
626 int i_object_id, char *psz_section )
627 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
629 module_config_t *p_item;
636 wxCheckBox *checkbox;
637 wxTextCtrl *textctrl;
641 /* Initializations */
643 p_prefs_dialog =_p_prefs_dialog,
645 b_advanced = VLC_TRUE;
646 SetAutoLayout( TRUE );
648 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
650 /* Get a pointer to the module */
651 module_t *p_module = (module_t *)vlc_object_get( p_intf, i_object_id );
652 if( p_module->i_object_type != VLC_OBJECT_MODULE )
654 /* 0OOoo something went really bad */
658 /* Enumerate config options and add corresponding config boxes */
659 p_item = p_module->p_config;
661 /* Find the category if it has been specified */
662 if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY )
664 while( !p_item->i_type == CONFIG_HINT_CATEGORY ||
665 strcmp( psz_section, p_item->psz_text ) )
667 if( p_item->i_type == CONFIG_HINT_END )
673 /* Add a head title to the panel */
674 wxStaticBox *static_box = new wxStaticBox( this, -1, wxT("") );
675 wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( static_box,
677 label = new wxStaticText( this, -1,
678 wxU(psz_section ? p_item->psz_text :
679 p_module->psz_longname) );
681 box_sizer->Add( label, 1, wxALL, 5 );
682 sizer->Add( box_sizer, 0, wxEXPAND | wxALL, 5 );
684 /* Now put all the config options into a scrolled window */
685 config_sizer = new wxBoxSizer( wxVERTICAL );
686 config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
687 wxDefaultSize, wxSTATIC_BORDER | wxHSCROLL | wxVSCROLL );
688 config_window->SetAutoLayout( TRUE );
689 config_window->SetScrollRate( 5, 5 );
693 /* If a category has been specified, check we finished the job */
694 if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY &&
695 strcmp( psz_section, p_item->psz_text ) )
698 /* put each config option in a separate panel so we can hide advanced
700 wxPanel *panel = new wxPanel( config_window, -1, wxDefaultPosition,
702 wxBoxSizer *panel_sizer = new wxBoxSizer( wxHORIZONTAL );
703 ConfigData *config_data =
704 new ConfigData( panel, p_item->i_type,
705 p_item->b_advanced, p_item->psz_name );
707 switch( p_item->i_type )
709 case CONFIG_ITEM_MODULE:
710 label = new wxStaticText(panel, -1, wxU(p_item->psz_text));
711 combo = new wxComboBox( panel, -1, wxU(p_item->psz_value),
712 wxDefaultPosition, wxDefaultSize,
713 0, NULL, wxCB_READONLY | wxCB_SORT );
715 /* build a list of available modules */
716 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
717 combo->Append( wxU(_("Default")), (void *)NULL );
718 combo->SetSelection( 0 );
719 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
721 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
723 if( !strcmp( p_parser->psz_capability,
726 combo->Append( wxU(p_parser->psz_longname),
727 p_parser->psz_object_name );
728 if( p_item->psz_value &&
729 !strcmp(p_item->psz_value, p_parser->psz_object_name) )
730 combo->SetValue( wxU(p_parser->psz_longname) );
734 combo->SetToolTip( wxU(p_item->psz_longtext) );
735 config_data->control.combobox = combo;
736 panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
737 panel_sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
740 case CONFIG_ITEM_STRING:
741 case CONFIG_ITEM_FILE:
742 case CONFIG_ITEM_DIRECTORY:
743 label = new wxStaticText(panel, -1, wxU(p_item->psz_text));
744 panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
746 if( !p_item->ppsz_list )
748 textctrl = new wxTextCtrl( panel, -1, wxU(p_item->psz_value),
749 wxDefaultPosition, wxDefaultSize,
751 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
752 config_data->control.textctrl = textctrl;
753 panel_sizer->Add( textctrl, 1, wxALL, 5 );
757 combo = new wxComboBox( panel, -1, wxU(p_item->psz_value),
758 wxDefaultPosition, wxDefaultSize,
759 0, NULL, wxCB_READONLY | wxCB_SORT );
761 /* build a list of available options */
762 for( int i_index = 0; p_item->ppsz_list[i_index]; i_index++ )
764 combo->Append( wxU(p_item->ppsz_list[i_index]) );
767 if( p_item->psz_value )
768 combo->SetValue( wxU(p_item->psz_value) );
769 combo->SetToolTip( wxU(p_item->psz_longtext) );
770 config_data->control.combobox = combo;
771 config_data->b_config_list = VLC_TRUE;
772 panel_sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
775 if( p_item->i_type == CONFIG_ITEM_FILE )
777 button = new wxButton( panel, -1, wxU(_("Browse...")) );
778 panel_sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
779 button->SetClientData((void *)config_data);
783 case CONFIG_ITEM_INTEGER:
784 label = new wxStaticText(panel, -1, wxU(p_item->psz_text));
785 spin = new wxSpinCtrl( panel, -1,
786 wxString::Format(wxT("%d"),p_item->i_value),
787 wxDefaultPosition, wxDefaultSize,
789 -16000, 16000, p_item->i_value);
790 spin->SetToolTip( wxU(p_item->psz_longtext) );
791 config_data->control.spinctrl = spin;
792 panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
793 panel_sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
795 spin->SetClientData((void *)config_data);
798 case CONFIG_ITEM_FLOAT:
799 label = new wxStaticText(panel, -1, wxU(p_item->psz_text));
800 spin = new wxSpinCtrl( panel, -1,
801 wxString::Format(wxT("%f"),p_item->f_value),
802 wxDefaultPosition, wxDefaultSize,
804 -16000, 16000, (int)p_item->f_value);
805 spin->SetToolTip( wxU(p_item->psz_longtext) );
806 config_data->control.spinctrl = spin;
807 panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
808 panel_sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
811 case CONFIG_ITEM_BOOL:
812 checkbox = new wxCheckBox( panel, -1, wxU(p_item->psz_text) );
813 if( p_item->i_value ) checkbox->SetValue(TRUE);
814 checkbox->SetToolTip( wxU(p_item->psz_longtext) );
815 config_data->control.checkbox = checkbox;
816 panel_sizer->Add( checkbox, 0, wxALL, 5 );
820 delete panel; panel = NULL;
826 /* Don't add items that were not recognized */
827 if( panel == NULL ) continue;
829 panel_sizer->Layout();
830 panel->SetSizerAndFit( panel_sizer );
832 /* Add the config data to our array so we can keep a trace of it */
833 config_array.Add( config_data );
835 config_sizer->Add( panel, 0, wxEXPAND | wxALL, 2 );
837 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
839 /* Display a nice message if no configuration options are available */
840 if( !config_array.GetCount() )
842 config_sizer->Add( new wxStaticText( config_window, -1,
843 wxU(_("No configuration options available")) ), 1,
844 wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER, 2 );
847 config_sizer->Layout();
848 config_window->SetSizer( config_sizer );
849 sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
851 /* Intercept all menu events in our custom event handler */
852 config_window->PushEventHandler(
853 new ConfigEvtHandler( p_intf, p_prefs_dialog ) );
856 wxCommandEvent dummy_event;
857 b_advanced = !config_GetInt( p_intf, "advanced" );
858 OnAdvanced( dummy_event );
860 /* Create advanced checkbox */
861 if( config_array.GetCount() )
863 wxCheckBox *advanced_checkbox =
864 new wxCheckBox( this, Advanced_Event, wxU(_("Advanced options")) );
866 if( b_advanced ) advanced_checkbox->SetValue(TRUE);
867 sizer->Add( advanced_checkbox, 0, wxALL|wxALIGN_RIGHT, 0 );
874 void PrefsPanel::ApplyChanges()
876 for( size_t i = 0; i < config_array.GetCount(); i++ )
878 ConfigData *config_data = config_array.Item(i);
880 switch( config_data->i_config_type )
882 case CONFIG_ITEM_MODULE:
883 config_PutPsz( p_intf, config_data->option_name.mb_str(), (char *)
884 config_data->control.combobox->GetClientData(
885 config_data->control.combobox->GetSelection() ) );
887 case CONFIG_ITEM_STRING:
888 case CONFIG_ITEM_FILE:
889 case CONFIG_ITEM_DIRECTORY:
890 if( !config_data->b_config_list )
891 config_PutPsz( p_intf, config_data->option_name.mb_str(),
892 config_data->control.textctrl->GetValue().mb_str() );
894 config_PutPsz( p_intf, config_data->option_name.mb_str(),
895 config_data->control.combobox->GetValue().mb_str() );
897 case CONFIG_ITEM_BOOL:
898 config_PutInt( p_intf, config_data->option_name.mb_str(),
899 config_data->control.checkbox->IsChecked() );
901 case CONFIG_ITEM_INTEGER:
902 config_PutInt( p_intf, config_data->option_name.mb_str(),
903 config_data->control.spinctrl->GetValue() );
905 case CONFIG_ITEM_FLOAT:
906 config_PutFloat( p_intf, config_data->option_name.mb_str(),
907 config_data->control.spinctrl->GetValue() );
913 void PrefsPanel::OnAdvanced( wxCommandEvent& WXUNUSED(event) )
915 b_advanced = !b_advanced;
917 for( size_t i = 0; i < config_array.GetCount(); i++ )
919 ConfigData *config_data = config_array.Item(i);
920 if( config_data->b_advanced )
922 config_data->panel->Show( b_advanced );
923 config_sizer->Show( config_data->panel, b_advanced );
927 config_sizer->Layout();
928 config_window->FitInside();
929 config_window->Refresh();
932 /*****************************************************************************
933 * A small helper class which intercepts all events
934 *****************************************************************************/
935 ConfigEvtHandler::ConfigEvtHandler( intf_thread_t *_p_intf,
936 PrefsDialog *_p_prefs_dialog )
938 /* Initializations */
940 p_prefs_dialog = _p_prefs_dialog;
943 ConfigEvtHandler::~ConfigEvtHandler()
947 void ConfigEvtHandler::OnCommandEvent( wxCommandEvent& event )
949 if( !event.GetEventObject() )
955 ConfigData *config_data = (ConfigData *)
956 ((wxEvtHandler *)event.GetEventObject())->GetClientData();
964 if( config_data->i_config_type == CONFIG_ITEM_FILE )
966 wxFileDialog dialog( p_prefs_dialog, wxU(_("Open file")),
967 wxT(""), wxT(""), wxT("*.*"), wxOPEN | wxSAVE );
969 if( dialog.ShowModal() == wxID_OK )
971 config_data->control.textctrl->SetValue( dialog.GetPath() );
975 switch( config_data->i_config_type )
977 case CONFIG_ITEM_MODULE:
979 case CONFIG_ITEM_STRING:
981 case CONFIG_ITEM_FILE:
983 case CONFIG_ITEM_INTEGER:
985 case CONFIG_ITEM_FLOAT:
987 case CONFIG_ITEM_BOOL: