]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwindows/preferences.cpp
* modules/video_output/opengl.c: forward control queries to opengl provider.
[vlc] / modules / gui / wxwindows / preferences.cpp
index 8e3038cd9ce64ba553e33f896524361f47dfa684..d5c3f878a25489619db1674db389adeef34b0f62 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * preferences.cpp : wxWindows plugin for vlc
  *****************************************************************************
- * Copyright (C) 2000-2001 VideoLAN
- * $Id: preferences.cpp,v 1.1 2003/03/26 00:56:22 gbazin Exp $
+ * Copyright (C) 2000-2004 VideoLAN
+ * $Id$
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
 #include <stdio.h>
 
 #include <vlc/vlc.h>
+#include <vlc/intf.h>
 
-#ifdef WIN32                                                 /* mingw32 hack */
-#undef Yield
-#undef CreateDialog
-#endif
+#include <vlc_help.h>
 
-/* Let vlc take care of the i18n stuff */
-#define WXINTL_NO_GETTEXT_MACRO
+#include "wxwindows.h"
+#include "preferences_widgets.h"
 
-#include <wx/wxprec.h>
-#include <wx/wx.h>
-#include <wx/notebook.h>
-#include <wx/textctrl.h>
 #include <wx/combobox.h>
-#include <wx/spinctrl.h>
 #include <wx/statline.h>
-#include <wx/treectrl.h>
-
-#include <vlc/intf.h>
-
-#include "wxwindows.h"
+#include <wx/clntdata.h>
+#include <wx/dynarray.h>
 
 #ifndef wxRB_SINGLE
 #   define wxRB_SINGLE 0
 #endif
 
+#define GENERAL_ID 1242
+#define PLUGIN_ID 1243
+#define CAPABILITY_ID 1244
+
 /*****************************************************************************
  * Classes declarations.
  *****************************************************************************/
+class ConfigTreeData;
 class PrefsTreeCtrl : public wxTreeCtrl
 {
 public:
@@ -68,9 +63,15 @@ public:
                    PrefsDialog *p_prefs_dialog, wxBoxSizer *_p_sizer );
     virtual ~PrefsTreeCtrl();
 
+    void ApplyChanges();
+    void CleanChanges();
+
 private:
     /* Event handlers (these functions should _not_ be virtual) */
     void OnSelectTreeItem( wxTreeEvent& event );
+    void OnAdvanced( wxCommandEvent& event );
+
+    ConfigTreeData *FindModuleConfig( ConfigTreeData *config_data );
 
     DECLARE_EVENT_TABLE()
 
@@ -78,34 +79,56 @@ private:
     PrefsDialog *p_prefs_dialog;
     wxBoxSizer *p_sizer;
     wxWindow *p_parent;
+    vlc_bool_t b_advanced;
+
+    wxTreeItemId root_item;
+    wxTreeItemId general_item;
+    wxTreeItemId plugins_item;
 };
 
-class PrefsPanel : public wxScrolledWindow
+WX_DEFINE_ARRAY(ConfigControl *, ArrayOfConfigControls);
+
+class PrefsPanel : public wxPanel
 {
 public:
 
     PrefsPanel() { }
     PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
-                module_t *p_module, char * );
+                PrefsDialog *, int i_object_id, char *, char * );
     virtual ~PrefsPanel() {}
 
-private:
-    void OnFileBrowse( wxCommandEvent& WXUNUSED(event) );
-    void OnDirectoryBrowse( wxCommandEvent& WXUNUSED(event) );
-    DECLARE_EVENT_TABLE()
+    void ApplyChanges();
+    void SwitchAdvanced( vlc_bool_t );
 
+private:
     intf_thread_t *p_intf;
+    PrefsDialog *p_prefs_dialog;
+
+    vlc_bool_t b_advanced;
+
+    wxBoxSizer *config_sizer;
+    wxScrolledWindow *config_window;
+
+    ArrayOfConfigControls config_array;
 };
 
-class ConfigData : public wxTreeItemData
+class ConfigTreeData : public wxTreeItemData
 {
 public:
 
-    ConfigData() { panel == NULL; }
-    virtual ~ConfigData() { if( panel ) delete panel; }
+    ConfigTreeData() { b_submodule = 0; panel = NULL; psz_section = NULL;
+                       psz_help = NULL; }
+    virtual ~ConfigTreeData() { if( panel ) delete panel;
+                                if( psz_section) free(psz_section);
+                                if( psz_help) free(psz_help); }
 
-    wxWindow *panel;
+    vlc_bool_t b_submodule;
+
+    PrefsPanel *panel;
     wxBoxSizer *sizer;
+    int i_object_id;
+    char *psz_section;
+    char *psz_help;
 };
 
 /*****************************************************************************
@@ -117,14 +140,20 @@ enum
 {
     Notebook_Event = wxID_HIGHEST,
     MRL_Event,
-
+    ResetAll_Event,
+    Advanced_Event,
 };
 
-BEGIN_EVENT_TABLE(PrefsDialog, wxDialog)
+BEGIN_EVENT_TABLE(PrefsDialog, wxFrame)
     /* Button events */
     EVT_BUTTON(wxID_OK, PrefsDialog::OnOk)
     EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel)
+    EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave)
+    EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll)
+    EVT_CHECKBOX(Advanced_Event, PrefsDialog::OnAdvanced)
 
+    /* Don't destroy the window when the user closes it */
+    EVT_CLOSE(PrefsDialog::OnCancel)
 END_EVENT_TABLE()
 
 // menu and control ids
@@ -135,32 +164,19 @@ enum
 
 BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl)
     EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem)
-END_EVENT_TABLE()
-
-enum
-{
-    FileBrowse_Event = wxID_HIGHEST,
-    DirectoryBrowse_Event,
-
-};
-
-BEGIN_EVENT_TABLE(PrefsPanel, wxScrolledWindow)
-    /* Button events */
-    EVT_BUTTON(FileBrowse_Event, PrefsPanel::OnFileBrowse)
-    EVT_BUTTON(DirectoryBrowse_Event, PrefsPanel::OnDirectoryBrowse)
-
+    EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced)
 END_EVENT_TABLE()
 
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
-PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, Interface *_p_main_interface)
-  :  wxDialog( _p_main_interface, -1, _("Preferences"), wxDefaultPosition,
-               wxSize(600,400), wxDEFAULT_FRAME_STYLE )
+PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent)
+  :  wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition,
+              wxSize(700,450), wxDEFAULT_FRAME_STYLE )
 {
     /* Initializations */
     p_intf = _p_intf;
-    p_main_interface = _p_main_interface;
+    SetIcon( *p_intf->p_sys->p_icon );
 
     /* Create a panel to put everything in */
     wxPanel *panel = new wxPanel( this, -1 );
@@ -168,21 +184,42 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, Interface *_p_main_interface)
 
     /* Create the preferences tree control */
     wxBoxSizer *controls_sizer = new wxBoxSizer( wxHORIZONTAL );
-    PrefsTreeCtrl *prefs_tree =
+    prefs_tree =
         new PrefsTreeCtrl( panel, p_intf, this, controls_sizer );
 
     /* Separation */
     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
 
     /* Create the buttons */
-    wxButton *ok_button = new wxButton( panel, wxID_OK, _("OK") );
+    wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
     ok_button->SetDefault();
-    wxButton *cancel_button = new wxButton( panel, wxID_CANCEL, _("Cancel") );
+    wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
+                                            wxU(_("Cancel")) );
+    wxButton *save_button = new wxButton( panel, wxID_SAVE, wxU(_("Save")) );
+    wxButton *reset_button = new wxButton( panel, ResetAll_Event,
+                                           wxU(_("Reset All")) );
+
+    wxPanel *dummy_panel = new wxPanel( this, -1 );
+    wxCheckBox *advanced_checkbox =
+        new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) );
+
+    if( config_GetInt( p_intf, "advanced" ) )
+    {
+        advanced_checkbox->SetValue(TRUE);
+        wxCommandEvent dummy_event;
+        dummy_event.SetInt(TRUE);
+        OnAdvanced( dummy_event );
+    }
 
     /* Place everything in sizers */
     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
     button_sizer->Add( ok_button, 0, wxALL, 5 );
     button_sizer->Add( cancel_button, 0, wxALL, 5 );
+    button_sizer->Add( save_button, 0, wxALL, 5 );
+    button_sizer->Add( reset_button, 0, wxALL, 5 );
+    button_sizer->Add( dummy_panel, 1, wxALL, 5 );
+    button_sizer->Add( advanced_checkbox, 0, wxALL | wxALIGN_RIGHT |
+                       wxALIGN_CENTER_VERTICAL, 0 );
     button_sizer->Layout();
 
     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
@@ -190,7 +227,7 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, Interface *_p_main_interface)
     panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 );
     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
-                      wxALL, 5 );
+                      wxALL | wxEXPAND, 5 );
     panel_sizer->Layout();
     panel->SetSizer( panel_sizer );
     main_sizer->Add( panel, 1, wxEXPAND, 0 );
@@ -212,59 +249,46 @@ PrefsDialog::~PrefsDialog()
  *****************************************************************************/
 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
 {
+    prefs_tree->ApplyChanges();
     this->Hide();
+    prefs_tree->CleanChanges();
 }
 
 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
 {
     this->Hide();
+    prefs_tree->CleanChanges();
 }
 
-void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
+void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
 {
-    ConfigData *config_data;
-
-    config_data = (ConfigData *)GetItemData( event.GetOldItem() );
-    if( config_data && config_data->panel )
-    {
-        config_data->panel->Hide();
-        p_sizer->Remove( config_data->panel );
-    }
-
-    config_data = (ConfigData *)GetItemData( event.GetItem() );
-    if( config_data && config_data->panel )
-    {
-        config_data->panel->Show();
-        config_data->panel->FitInside();
-        p_sizer->Add( config_data->panel, 2, wxEXPAND | wxALL, 0 );
-        p_sizer->Layout();
-    }
+    prefs_tree->ApplyChanges();
+    config_SaveConfigFile( p_intf, NULL );
+    this->Hide();
 }
 
-void PrefsPanel::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
+void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
 {
-    wxFileDialog dialog( this, _("Open file"), "", "", "*.*",
-                         wxOPEN );
+    wxMessageDialog dlg( this,
+        wxU(_("Beware this will reset your VLC media player preferences.\n"
+              "Are you sure you want to continue?")),
+        wxU(_("Reset Preferences")), wxYES_NO|wxNO_DEFAULT|wxCENTRE );
 
-    if( dialog.ShowModal() == wxID_OK )
+    if ( dlg.ShowModal() == wxID_YES )
     {
-#if 0
-        file_combo->SetValue( dialog.GetPath() );      
-#endif
+        /* TODO: need to reset all the controls */
+        config_ResetAll( p_intf );
+        prefs_tree->CleanChanges();
+        config_SaveConfigFile( p_intf, NULL );
     }
 }
 
-void PrefsPanel::OnDirectoryBrowse( wxCommandEvent& WXUNUSED(event) )
+void PrefsDialog::OnAdvanced( wxCommandEvent& event )
 {
-    wxFileDialog dialog( this, _("Open file"), "", "", "*.*",
-                         wxOPEN );
+    wxCommandEvent newevent( wxEVT_USER_FIRST, Advanced_Event );
+    newevent.SetInt( event.GetInt() );
 
-    if( dialog.ShowModal() == wxID_OK )
-    {
-#if 0
-        file_combo->SetValue( dialog.GetPath() );      
-#endif
-    }
+    prefs_tree->AddPendingEvent( newevent );
 }
 
 /*****************************************************************************
@@ -288,8 +312,9 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
     p_prefs_dialog = _p_prefs_dialog;
     p_sizer = _p_sizer;
     p_parent = _p_parent;
+    b_advanced = VLC_FALSE;
 
-    wxTreeItemId root_item = AddRoot( "" );
+    root_item = AddRoot( wxT("") );
 
     /* List the plugins */
     p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
@@ -298,6 +323,13 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
     /*
      * Build a tree of the main options
      */
+    ConfigTreeData *config_data = new ConfigTreeData;
+    config_data->i_object_id = GENERAL_ID;
+    config_data->psz_help = wraptext( GENERAL_HELP, 72 , ISUTF8 );
+    config_data->psz_section = strdup( GENERAL_TITLE );
+    general_item = AppendItem( root_item, wxU(_("General settings")),
+                                -1, -1, config_data );
+
     for( i_index = 0; i_index < p_list->i_count; i_index++ )
     {
         p_module = (module_t *)p_list->p_values[i_index].p_object;
@@ -308,71 +340,114 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
     {
         /* We found the main module */
 
-        /* Enumerate config options and add corresponding config boxes */
+        /* Enumerate config categories and store a reference so we can
+         * generate their config panel them when it is asked by the user. */
         p_item = p_module->p_config;
 
         if( p_item ) do
         {
-            if( p_item->b_advanced && !config_GetInt( p_intf, "advanced" ))
-            {
-                continue;
-            }
             switch( p_item->i_type )
             {
             case CONFIG_HINT_CATEGORY:
-                ConfigData *config_data = new ConfigData;
-                config_data->panel =
-                    new PrefsPanel( p_parent, p_intf,
-                                    p_module, p_item->psz_text );
-                config_data->panel->Hide();
+                ConfigTreeData *config_data = new ConfigTreeData;
+                config_data->psz_section = strdup(p_item->psz_text);
+                if( p_item->psz_longtext )
+                {
+                    config_data->psz_help =
+                        wraptext( p_item->psz_longtext, 72 , ISUTF8 );
+                }
+                else
+                {
+                    config_data->psz_help = NULL;
+                }
+                config_data->i_object_id = p_module->i_object_id;
 
                 /* Add the category to the tree */
-                AppendItem( root_item, p_item->psz_text, -1, -1, config_data );
+                AppendItem( general_item, wxU(p_item->psz_text),
+                            -1, -1, config_data );
                 break;
             }
         }
         while( p_item->i_type != CONFIG_HINT_END && p_item++ );
 
-        SortChildren( root_item );
+        SortChildren( general_item );
     }
 
+
     /*
      * Build a tree of all the plugins
      */
-
-    wxTreeItemId plugins_item = AppendItem( root_item, _("Plugins") );
+    config_data = new ConfigTreeData;
+    config_data->i_object_id = PLUGIN_ID;
+    config_data->psz_help = wraptext( PLUGIN_HELP, 72, ISUTF8 );
+    config_data->psz_section = strdup( PLUGIN_TITLE );
+    plugins_item = AppendItem( root_item, wxU(_("Modules")),
+                        -1, -1,config_data );
 
     for( i_index = 0; i_index < p_list->i_count; i_index++ )
     {
         p_module = (module_t *)p_list->p_values[i_index].p_object;
 
-        /* Find the capabiltiy child item */
+        /* Exclude the main module */
+        if( !strcmp( p_module->psz_object_name, "main" ) )
+            continue;
+
+        /* Exclude empty plugins (submodules don't have config options, they
+         * are stored in the parent module) */
+        if( p_module->b_submodule )
+            p_item = ((module_t *)p_module->p_parent)->p_config;
+        else
+            p_item = p_module->p_config;
+
+        if( !p_item ) continue;
+        do
+        {
+            if( p_item->i_type & CONFIG_ITEM )
+                break;
+        }
+        while( p_item->i_type != CONFIG_HINT_END && p_item++ );
+        if( p_item->i_type == CONFIG_HINT_END ) continue;
+
+        /* Find the capability child item */
         long cookie; size_t i_child_index;
         wxTreeItemId capability_item = GetFirstChild( plugins_item, cookie);
         for( i_child_index = 0;
              i_child_index < GetChildrenCount( plugins_item, FALSE );
              i_child_index++ )
         {
-            if( !GetItemText(capability_item).Cmp(p_module->psz_capability) )
+            if( !GetItemText(capability_item).Cmp(
+                    wxU(p_module->psz_capability ) ) )
             {
                 break;
             }
             capability_item = GetNextChild( plugins_item, cookie );
         }
 
-        if( i_child_index == GetChildrenCount( plugins_item, FALSE ) )
+        if( i_child_index == GetChildrenCount( plugins_item, FALSE ) &&
+            p_module->psz_capability && *p_module->psz_capability )
         {
             /* We didn't find it, add it */
+            ConfigTreeData *config_data = new ConfigTreeData;
+            config_data->psz_section =
+                wraptext( GetCapabilityHelp( p_module->psz_capability , 1 ),
+                          72, ISUTF8 );
+            config_data->psz_help =
+                wraptext( GetCapabilityHelp( p_module->psz_capability , 2 ),
+                          72, ISUTF8 );
+            config_data->i_object_id = CAPABILITY_ID;
             capability_item = AppendItem( plugins_item,
-                                          p_module->psz_capability );
+                                          wxU(p_module->psz_capability),
+                                          -1,-1,config_data );
         }
 
         /* Add the plugin to the tree */
-        ConfigData *config_data = new ConfigData;
-        config_data->panel =
-            new PrefsPanel( p_parent, p_intf, p_module, NULL );
-        config_data->panel->Hide();
-        AppendItem( capability_item, p_module->psz_object_name, -1, -1,
+        ConfigTreeData *config_data = new ConfigTreeData;
+        config_data->b_submodule = p_module->b_submodule;
+        config_data->i_object_id = p_module->b_submodule ?
+            ((module_t *)p_module->p_parent)->i_object_id :
+            p_module->i_object_id;
+        config_data->psz_help = NULL;
+        AppendItem( capability_item, wxU(p_module->psz_object_name), -1, -1,
                     config_data );
     }
 
@@ -384,8 +459,8 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
          i_child_index < GetChildrenCount( plugins_item, FALSE );
          i_child_index++ )
     {
-        capability_item = GetNextChild( plugins_item, cookie );
         SortChildren( capability_item );
+        capability_item = GetNextChild( plugins_item, cookie );
     }
 
     /* Clean-up everything */
@@ -394,157 +469,408 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
     p_sizer->Add( this, 1, wxEXPAND | wxALL, 0 );
     p_sizer->Layout();
 
+    /* Update Tree Ctrl */
+#ifndef WIN32 /* Workaround a bug in win32 implementation */
+    SelectItem( GetFirstChild( root_item, cookie ) );
+#endif
+
+    Expand( general_item );
 }
 
 PrefsTreeCtrl::~PrefsTreeCtrl()
 {
 }
 
+void PrefsTreeCtrl::ApplyChanges()
+{
+    long cookie, cookie2;
+    ConfigTreeData *config_data;
+
+    /* Apply changes to the main module */
+    wxTreeItemId item = GetFirstChild( general_item, cookie );
+    for( size_t i_child_index = 0;
+         i_child_index < GetChildrenCount( general_item, FALSE );
+         i_child_index++ )
+    {
+        config_data = (ConfigTreeData *)GetItemData( item );
+        if( config_data && config_data->panel )
+        {
+            config_data->panel->ApplyChanges();
+        }
+
+        item = GetNextChild( general_item, cookie );
+    }
+
+    /* Apply changes to the plugins */
+    item = GetFirstChild( plugins_item, cookie );
+    for( size_t i_child_index = 0;
+         i_child_index < GetChildrenCount( plugins_item, FALSE );
+         i_child_index++ )
+    {
+        wxTreeItemId item2 = GetFirstChild( item, cookie2 );
+        for( size_t i_child_index = 0;
+             i_child_index < GetChildrenCount( item, FALSE );
+             i_child_index++ )
+        {
+            config_data = (ConfigTreeData *)GetItemData( item2 );
+            if( config_data && config_data->panel )
+            {
+                config_data->panel->ApplyChanges();
+            }
+
+            item2 = GetNextChild( item, cookie2 );
+        }
+
+        item = GetNextChild( plugins_item, cookie );
+    }
+}
+
+void PrefsTreeCtrl::CleanChanges()
+{
+    long cookie, cookie2;
+    ConfigTreeData *config_data;
+
+    config_data = !GetSelection() ? NULL :
+        FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
+    if( config_data  )
+    {
+        config_data->panel->Hide();
+        p_sizer->Remove( config_data->panel );
+    }
+
+    /* Clean changes for the main module */
+    wxTreeItemId item = GetFirstChild( general_item, cookie );
+    for( size_t i_child_index = 0;
+         i_child_index < GetChildrenCount( general_item, FALSE );
+         i_child_index++ )
+    {
+        config_data = (ConfigTreeData *)GetItemData( item );
+        if( config_data && config_data->panel )
+        {
+            delete config_data->panel;
+            config_data->panel = NULL;
+        }
+
+        item = GetNextChild( general_item, cookie );
+    }
+
+    /* Clean changes for the plugins */
+    item = GetFirstChild( plugins_item, cookie );
+    for( size_t i_child_index = 0;
+         i_child_index < GetChildrenCount( plugins_item, FALSE );
+         i_child_index++ )
+    {
+        wxTreeItemId item2 = GetFirstChild( item, cookie2 );
+        for( size_t i_child_index = 0;
+             i_child_index < GetChildrenCount( item, FALSE );
+             i_child_index++ )
+        {
+            config_data = (ConfigTreeData *)GetItemData( item2 );
+
+            if( config_data && config_data->panel )
+            {
+                delete config_data->panel;
+                config_data->panel = NULL;
+            }
+
+            item2 = GetNextChild( item, cookie2 );
+        }
+
+        item = GetNextChild( plugins_item, cookie );
+    }
+
+    if( GetSelection() )
+    {
+        wxTreeEvent event;
+        OnSelectTreeItem( event );
+    }
+}
+
+ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
+{
+    /* We need this complexity because submodules don't have their own config
+     * options. They use the parent module ones. */
+
+    if( !config_data || !config_data->b_submodule )
+    {
+        return config_data;
+    }
+
+    long cookie, cookie2;
+    ConfigTreeData *config_new;
+    wxTreeItemId item = GetFirstChild( plugins_item, cookie );
+    for( size_t i_child_index = 0;
+         i_child_index < GetChildrenCount( plugins_item, FALSE );
+         i_child_index++ )
+    {
+        wxTreeItemId item2 = GetFirstChild( item, cookie2 );
+        for( size_t i_child_index = 0;
+             i_child_index < GetChildrenCount( item, FALSE );
+             i_child_index++ )
+        {
+            config_new = (ConfigTreeData *)GetItemData( item2 );
+            if( config_new && !config_new->b_submodule &&
+                config_new->i_object_id == config_data->i_object_id )
+            {
+                return config_new;
+            }
+
+            item2 = GetNextChild( item, cookie2 );
+        }
+
+        item = GetNextChild( plugins_item, cookie );
+    }
+
+    /* Found nothing */
+    return NULL;
+}
+
+void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
+{
+    ConfigTreeData *config_data = NULL;
+
+    if( event.GetOldItem() )
+        config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
+                                        event.GetOldItem() ) );
+    if( config_data && config_data->panel )
+    {
+        config_data->panel->Hide();
+        p_sizer->Remove( config_data->panel );
+    }
+
+    /* Don't use event.GetItem() because we also send fake events */
+    config_data = FindModuleConfig( (ConfigTreeData *)GetItemData(
+                                    GetSelection() ) );
+    if( config_data )
+    {
+        if( !config_data->panel )
+        {
+            /* The panel hasn't been created yet. Let's do it. */
+            config_data->panel =
+                new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
+                                config_data->i_object_id,
+                                config_data->psz_section,
+                                config_data->psz_help );
+            config_data->panel->SwitchAdvanced( b_advanced );
+        }
+        else
+        {
+            config_data->panel->SwitchAdvanced( b_advanced );
+            config_data->panel->Show();
+        }
+
+        p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 );
+        p_sizer->Layout();
+    }
+}
+
+void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event )
+{
+    b_advanced = event.GetInt();
+
+    ConfigTreeData *config_data = !GetSelection() ? NULL :
+        FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) );
+    if( config_data  )
+    {
+        config_data->panel->Hide();
+        p_sizer->Remove( config_data->panel );
+    }
+
+    if( GetSelection() )
+    {
+        wxTreeEvent event;
+        OnSelectTreeItem( event );
+    }
+}
+
 /*****************************************************************************
  * PrefsPanel class definition.
  *****************************************************************************/
 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
-                        module_t *p_module, char *psz_section )
-  :  wxScrolledWindow( parent, -1, wxDefaultPosition, wxDefaultSize )
+                        PrefsDialog *_p_prefs_dialog,
+                        int i_object_id, char *psz_section, char *psz_help )
+  :  wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
 {
     module_config_t *p_item;
+
     wxStaticText *label;
-    wxComboBox *combo;
-    wxRadioButton *radio;
-    wxSpinCtrl *spin;
-    wxCheckBox *checkbox;
-    wxTextCtrl *textctrl;
-    wxButton *button;
-    wxStaticLine *static_line;
-    wxBoxSizer *horizontal_sizer;
+    wxStaticText *help;
+    wxArrayString array;
+
+    module_t *p_module = NULL;
 
     /* Initializations */
     p_intf = _p_intf;
+    p_prefs_dialog =_p_prefs_dialog,
+
+    b_advanced = VLC_TRUE;
     SetAutoLayout( TRUE );
-    SetScrollRate( 5, 5 );
 
     wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
 
-    /* Enumerate config options and add corresponding config boxes */
-    p_item = p_module->p_config;
 
-    /* Find the category if it has been specified */
-    if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY )
+    if( i_object_id == PLUGIN_ID || i_object_id == GENERAL_ID ||
+        i_object_id == CAPABILITY_ID )
+    {
+        label = new wxStaticText( this, -1,wxU(_( psz_section )));
+        wxFont heading_font = label->GetFont();
+        heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
+        label->SetFont( heading_font );
+        sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
+        sizer->Add( new wxStaticLine( this, 0 ), 0,
+                    wxEXPAND | wxLEFT | wxRIGHT, 2 );
+
+        help = new wxStaticText( this, -1, wxU(_( psz_help ) ) );
+        sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
+
+        config_sizer = NULL; config_window = NULL;
+    }
+    else
     {
-        while( !p_item->i_type == CONFIG_HINT_CATEGORY ||
-               strcmp( psz_section, p_item->psz_text ) )
+        /* Get a pointer to the module */
+        p_module = (module_t *)vlc_object_get( p_intf,  i_object_id );
+        if( p_module->i_object_type != VLC_OBJECT_MODULE )
         {
-            if( p_item->i_type == CONFIG_HINT_END )
-                break;
-            p_item++;
+            /* 0OOoo something went really bad */
+            return;
         }
-    }
 
-    /* Add a head title to the panel */
-    wxStaticBox *static_box = new wxStaticBox( this, -1, "" );
-    wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( static_box,
-                                                        wxHORIZONTAL );
-    label = new wxStaticText( this, -1,
-                              psz_section ? p_item->psz_text :
-                              p_module->psz_longname );
+        /* Enumerate config options and add corresponding config boxes
+         * (submodules don't have config options, they are stored in the
+         *  parent module) */
+        if( p_module->b_submodule )
+            p_item = ((module_t *)p_module->p_parent)->p_config;
+        else
+            p_item = p_module->p_config;
 
-    box_sizer->Add( label, 1, wxALL, 5 );
-    sizer->Add( box_sizer, 0, wxEXPAND | wxALL, 5 );
+        /* Find the category if it has been specified */
+        if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY )
+        {
+            while( !p_item->i_type == CONFIG_HINT_CATEGORY ||
+                   strcmp( psz_section, p_item->psz_text ) )
+            {
+                if( p_item->i_type == CONFIG_HINT_END )
+                    break;
+                p_item++;
+            }
+        }
 
-    if( p_item ) do
-    {
-        if( p_item->b_advanced && !config_GetInt( p_intf, "advanced" ) )
+        /* Add a head title to the panel */
+        label = new wxStaticText( this, -1,
+                                  wxU(_(psz_section ? p_item->psz_text :
+                                  p_module->psz_longname )));
+        wxFont heading_font = label->GetFont();
+        heading_font.SetPointSize( heading_font.GetPointSize() + 5 );
+        label->SetFont( heading_font );
+        sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 );
+        sizer->Add( new wxStaticLine( this, 0 ), 0,
+                    wxEXPAND | wxLEFT | wxRIGHT, 2 );
+
+        /* Now put all the config options into a scrolled window */
+        config_sizer = new wxBoxSizer( wxVERTICAL );
+        config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
+            wxDefaultSize, wxBORDER_NONE | wxHSCROLL | wxVSCROLL );
+        config_window->SetAutoLayout( TRUE );
+        config_window->SetScrollRate( 5, 5 );
+
+        if( p_item ) do
         {
-            continue;
+            /* If a category has been specified, check we finished the job */
+            if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY &&
+                strcmp( psz_section, p_item->psz_text ) )
+                break;
+
+            ConfigControl *control =
+                CreateConfigControl( VLC_OBJECT(p_intf),
+                                     p_item, config_window );
+
+            /* Don't add items that were not recognized */
+            if( control == NULL ) continue;
+
+            /* Add the config data to our array so we can keep a trace of it */
+            config_array.Add( control );
+
+            config_sizer->Add( control, 0, wxEXPAND | wxALL, 2 );
         }
+        while( p_item->i_type != CONFIG_HINT_END && p_item++ );
 
-        /* If a category has been specified, check we finished the job */
-        if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY &&
-            strcmp( psz_section, p_item->psz_text ) )
-            break;
+        config_sizer->Layout();
+        config_window->SetSizer( config_sizer );
+        sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 );
 
-        switch( p_item->i_type )
+        /* And at last put a useful help string if available */
+        if( psz_help && *psz_help )
         {
-        case CONFIG_HINT_CATEGORY:
-#if 0
-            label = new wxStaticText(this, -1, p_item->psz_text);
-            sizer->Add( label, 0, wxALL, 5 );
-#endif
-            break;
+            sizer->Add( new wxStaticLine( this, 0 ), 0,
+                        wxEXPAND | wxLEFT | wxRIGHT, 2 );
+            help = new wxStaticText( this, -1, wxU(_(psz_help)),
+                                     wxDefaultPosition, wxDefaultSize,
+                                     wxALIGN_LEFT,
+                                     wxT("") );
+            sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 );
+        }
 
-        case CONFIG_ITEM_MODULE:
-            /* build a list of available modules */
-
-            label = new wxStaticText(this, -1, p_item->psz_text);
-            combo = new wxComboBox( this, -1, "", wxPoint(20,25),
-                                    wxSize(120, -1), 0, NULL );
-            combo->SetToolTip( p_item->psz_longtext );
-            horizontal_sizer = new wxBoxSizer( wxHORIZONTAL );
-            horizontal_sizer->Add( label, 0, wxALL, 5 );
-            horizontal_sizer->Add( combo, 0, wxALL, 5 );
-            sizer->Add( horizontal_sizer, 0, wxALL, 5 );
-            break;
+        vlc_object_release( p_module );
+    }
+    sizer->Layout();
+    SetSizer( sizer );
+}
+
+void PrefsPanel::ApplyChanges()
+{
+    vlc_value_t val;
 
+    for( size_t i = 0; i < config_array.GetCount(); i++ )
+    {
+        ConfigControl *control = config_array.Item(i);
+
+        switch( control->GetType() )
+        {
         case CONFIG_ITEM_STRING:
         case CONFIG_ITEM_FILE:
-            label = new wxStaticText(this, -1, p_item->psz_text);
-            textctrl = new wxTextCtrl( this, -1, "",
-                                       wxDefaultPosition, wxDefaultSize,
-                                       wxTE_PROCESS_ENTER);
-#if 0
-            combo = new wxComboBox( this, -1, "", wxPoint(20,25),
-                                    wxSize(120, -1), 0, NULL );
-#endif
-            textctrl->SetToolTip( p_item->psz_longtext );
-            horizontal_sizer = new wxBoxSizer( wxHORIZONTAL );
-            horizontal_sizer->Add( label, 0, wxALL, 5 );
-            horizontal_sizer->Add( textctrl, 0, wxALL, 5 );
-            if( p_item->i_type == CONFIG_ITEM_FILE )
-            {
-                button = new wxButton( this, -1, _("Browse...") );
-                horizontal_sizer->Add( button, 0, wxALL, 5 );
-            }
-            sizer->Add( horizontal_sizer, 0, wxALL, 5 );
+        case CONFIG_ITEM_DIRECTORY:
+        case CONFIG_ITEM_MODULE:
+            config_PutPsz( p_intf, control->GetName().mb_str(),
+                           control->GetPszValue().mb_str() );
             break;
-
+        case CONFIG_ITEM_KEY:
+            /* So you don't need to restart to have the changes take effect */
+            val.i_int = control->GetIntValue();
+            var_Set( p_intf->p_vlc, control->GetName().mb_str(), val );
         case CONFIG_ITEM_INTEGER:
-            label = new wxStaticText(this, -1, p_item->psz_text);
-            spin = new wxSpinCtrl( this, -1, p_item->psz_text,
-                                   wxDefaultPosition, wxDefaultSize,
-                                   wxSP_ARROW_KEYS,
-                                   0, 16000, 8);
-            spin->SetToolTip( p_item->psz_longtext );
-            horizontal_sizer = new wxBoxSizer( wxHORIZONTAL );
-            horizontal_sizer->Add( label, 0, wxALL, 5 );
-            horizontal_sizer->Add( spin, 0, wxALL, 5 );
-            sizer->Add( horizontal_sizer, 0, wxALL, 5 );
+        case CONFIG_ITEM_BOOL:
+            config_PutInt( p_intf, control->GetName().mb_str(),
+                           control->GetIntValue() );
             break;
-
         case CONFIG_ITEM_FLOAT:
-            label = new wxStaticText(this, -1, p_item->psz_text);
-            spin = new wxSpinCtrl( this, -1, p_item->psz_text,
-                                   wxDefaultPosition, wxDefaultSize,
-                                   wxSP_ARROW_KEYS,
-                                   0, 16000, 8);
-            spin->SetToolTip( p_item->psz_longtext );
-            horizontal_sizer = new wxBoxSizer( wxHORIZONTAL );
-            horizontal_sizer->Add( label, 0, wxALL, 5 );
-            horizontal_sizer->Add( spin, 0, wxALL, 5 );
-            sizer->Add( horizontal_sizer, 0, wxALL, 5 );
-            break;
-
-        case CONFIG_ITEM_BOOL:
-            checkbox = new wxCheckBox( this, -1, p_item->psz_text );
-            checkbox->SetToolTip( p_item->psz_longtext );
-            horizontal_sizer = new wxBoxSizer( wxHORIZONTAL );
-            horizontal_sizer->Add( checkbox, 0, wxALL, 5 );
-            sizer->Add( horizontal_sizer, 0, wxALL, 5 );
+            config_PutFloat( p_intf, control->GetName().mb_str(),
+                             control->GetFloatValue() );
             break;
         }
     }
-    while( p_item->i_type != CONFIG_HINT_END && p_item++ );
+}
 
+void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced )
+{
+    if( b_advanced == b_new_advanced ) return;
 
-    sizer->Layout();
-    SetSizer( sizer );
+    if( config_sizer && config_window )
+    {
+        b_advanced = b_new_advanced;
+
+        for( size_t i = 0; i < config_array.GetCount(); i++ )
+        {
+            ConfigControl *control = config_array.Item(i);
+            if( control->IsAdvanced() )
+            {
+                control->Show( b_advanced );
+                config_sizer->Show( control, b_advanced );
+            }
+        }
+
+        config_sizer->Layout();
+        config_window->FitInside();
+        config_window->Refresh();
+    }
+    return;
 }