]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwindows/preferences_widgets.cpp
* preferences_widget.cpp: fixed a compilation error
[vlc] / modules / gui / wxwindows / preferences_widgets.cpp
index 71da8bff80fa26396eae4fa947bd058f441a0b41..a82ad10f7bf070c4c42ac64ed9fb19bb383bbb19 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 2000-2004 VideoLAN
  * $Id$
  *
- * Authors: Gildas Bazin <gbazin@netcourrier.com>
+ * Authors: Gildas Bazin <gbazin@videolan.org>
  *          Sigmund Augdal <sigmunau@idi.ntnu.no>
  *
  * This program is free software; you can redistribute it and/or modify
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
 
-#include <vlc_help.h>
+#include <vlc_config_cat.h>
 
 #include "wxwindows.h"
 #include "preferences_widgets.h"
 
+#include <wx/statline.h>
+
 /*****************************************************************************
  * CreateConfigControl wrapper
  *****************************************************************************/
@@ -51,6 +53,9 @@ ConfigControl *CreateConfigControl( vlc_object_t *p_this,
     case CONFIG_ITEM_MODULE:
         p_control = new ModuleConfigControl( p_this, p_item, parent );
         break;
+    case CONFIG_ITEM_MODULE_LIST_CAT:
+        p_control = new ModuleListCatConfigControl( p_this, p_item, parent );
+        break;
 
     case CONFIG_ITEM_STRING:
         if( !p_item->i_list )
@@ -95,6 +100,10 @@ ConfigControl *CreateConfigControl( vlc_object_t *p_this,
         p_control = new BoolConfigControl( p_this, p_item, parent );
         break;
 
+    case CONFIG_SECTION:
+        p_control = new SectionConfigControl( p_this, p_item, parent );
+        break;
+
     default:
         break;
     }
@@ -259,7 +268,7 @@ ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
     combo->Append( wxU(_("Default")), (void *)NULL );
     combo->SetSelection( 0 );
-    for( int i_index = 0; i_index < p_list->i_count; i_index++ )
+    for( unsigned int i_index = 0; i_index < p_list->i_count; i_index++ )
     {
         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
 
@@ -291,6 +300,104 @@ wxString ModuleConfigControl::GetPszValue()
     return wxU( (char *)combo->GetClientData( combo->GetSelection() ));
 }
 
+/*****************************************************************************
+ * ModuleListCatonfigControl implementation
+ *****************************************************************************/
+BEGIN_EVENT_TABLE(ModuleListCatConfigControl, wxPanel)
+    EVT_CHECKBOX( wxID_HIGHEST , ModuleListCatConfigControl::OnUpdate )
+END_EVENT_TABLE()
+
+
+ModuleListCatConfigControl::ModuleListCatConfigControl( vlc_object_t *p_this,
+                                                     module_config_t *p_item,
+                                                     wxWindow *parent )
+  : ConfigControl( p_this, p_item, parent )
+{
+    vlc_list_t *p_list;
+    module_t *p_parser;
+
+    delete sizer;
+    sizer = new wxBoxSizer( wxVERTICAL );
+    label = new wxStaticText(this, -1, wxU(p_item->psz_text));
+    sizer->Add( label );
+
+    text = new wxTextCtrl( this, -1, wxU(p_item->psz_value),
+                           wxDefaultPosition,wxSize( 300, 20 ) );
+
+
+    /* build a list of available modules */
+    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
+    for( unsigned int i_index = 0; i_index < p_list->i_count; i_index++ )
+    {
+        p_parser = (module_t *)p_list->p_values[i_index].p_object ;
+
+        if( !strcmp( p_parser->psz_object_name, "main" ) )
+              continue;
+
+        module_config_t *p_config = p_parser->p_config;
+        if( p_config ) do
+        {
+            /* Hack: required subcategory is stored in i_min */
+            if( p_config->i_type == CONFIG_SUBCATEGORY &&
+                p_config->i_value == p_item->i_min )
+            {
+                moduleCheckBox *mc = new moduleCheckBox;
+                mc->checkbox = new wxCheckBox( this, wxID_HIGHEST,
+                                               wxU(p_parser->psz_longname));
+                mc->psz_module = strdup( p_parser->psz_object_name );
+                pp_checkboxes.push_back( mc );
+
+                if( p_item->psz_value &&
+                    strstr( p_item->psz_value, p_parser->psz_object_name ) )
+                {
+                    mc->checkbox->SetValue( true );
+                }
+                sizer->Add( mc->checkbox );
+            }
+        } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
+    }
+    vlc_list_release( p_list );
+
+    text->SetToolTip( wxU(p_item->psz_longtext) );
+    sizer->Add(text, wxEXPAND );
+
+    sizer->Add (new wxStaticText( this, -1, wxU( vlc_wraptext( _("Select modules that you want. To get more advanced control, you can also modify the resulting chain by yourself") , 72, ISUTF8 ) ) ) );
+
+    sizer->Layout();
+    this->SetSizerAndFit( sizer );
+}
+
+ModuleListCatConfigControl::~ModuleListCatConfigControl()
+{
+    ;
+}
+
+wxString ModuleListCatConfigControl::GetPszValue()
+{
+    return wxU( text->GetValue().c_str() ) ;
+}
+
+void  ModuleListCatConfigControl::OnUpdate( wxCommandEvent &event )
+{
+    wxString newtext = wxU("");
+    for( int i = 0 ; i< pp_checkboxes.size() ; i++ )
+    {
+        if( pp_checkboxes[i]->checkbox->IsChecked() )
+        {
+            if( newtext.Len() == 0 )
+            {
+                newtext = newtext + wxU( pp_checkboxes[i]->psz_module );
+            }
+            else
+            {
+                newtext += wxU( "," );
+                newtext += wxU(pp_checkboxes[i]->psz_module);
+            }
+        }
+    }
+    text->SetValue( newtext );
+}
+
 /*****************************************************************************
  * StringConfigControl implementation
  *****************************************************************************/
@@ -335,6 +442,9 @@ StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
                                                   wxWindow *parent )
   : ConfigControl( p_this, p_item, parent )
 {
+    psz_default_value = p_item->psz_value;
+    if( psz_default_value ) psz_default_value = strdup( psz_default_value );
+
     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
     combo = new wxComboBox( this, -1, wxT(""),
@@ -359,12 +469,16 @@ StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
 
 StringListConfigControl::~StringListConfigControl()
 {
+    if( psz_default_value ) free( psz_default_value );
 }
 
 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
 {
+    vlc_bool_t b_found = VLC_FALSE;
+    int i_index;
+
     /* build a list of available options */
-    for( int i_index = 0; i_index < p_item->i_list; i_index++ )
+    for( i_index = 0; i_index < p_item->i_list; i_index++ )
     {
         combo->Append( ( p_item->ppsz_list_text &&
                          p_item->ppsz_list_text[i_index] ) ?
@@ -380,8 +494,18 @@ void StringListConfigControl::UpdateCombo( module_config_t *p_item )
                                p_item->ppsz_list_text[i_index] ) ?
                              wxU(p_item->ppsz_list_text[i_index]) :
                              wxL2U(p_item->ppsz_list[i_index]) );
+            b_found = VLC_TRUE;
         }
     }
+
+    if( p_item->psz_value && !b_found )
+    {
+        /* Add custom entry to list */
+        combo->Append( wxL2U(p_item->psz_value) );
+        combo->SetClientData( i_index, (void *)psz_default_value );
+        combo->SetSelection( i_index );
+        combo->SetValue( wxL2U(p_item->psz_value) );
+    }
 }
 
 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
@@ -403,7 +527,7 @@ void StringListConfigControl::OnAction( wxCommandEvent& event )
 
     vlc_value_t val;
     wxString value = GetPszValue();
-    (const char *)val.psz_string = value.mb_str();
+    *((const char **)&val.psz_string) = value.mb_str();
     p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
 
     if( p_item->b_dirty )
@@ -494,6 +618,11 @@ wxString FileConfigControl::GetPszValue()
 /*****************************************************************************
  * IntegerConfigControl implementation
  *****************************************************************************/
+BEGIN_EVENT_TABLE(IntegerConfigControl, wxPanel)
+    EVT_TEXT(-1, IntegerConfigControl::OnUpdate)
+    EVT_COMMAND_SCROLL(-1, IntegerConfigControl::OnUpdate)
+END_EVENT_TABLE()
+
 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
                                             module_config_t *p_item,
                                             wxWindow *parent )
@@ -505,12 +634,13 @@ IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
                                             p_item->i_value),
                            wxDefaultPosition, wxDefaultSize,
                            wxSP_ARROW_KEYS,
-                           -10000000, 10000000, p_item->i_value);
+                           -100000000, 100000000, p_item->i_value);
     spin->SetToolTip( wxU(p_item->psz_longtext) );
     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
     sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
     sizer->Layout();
     this->SetSizerAndFit( sizer );
+    i_value = p_item->i_value;
 }
 
 IntegerConfigControl::~IntegerConfigControl()
@@ -520,7 +650,15 @@ IntegerConfigControl::~IntegerConfigControl()
 
 int IntegerConfigControl::GetIntValue()
 {
-    return spin->GetValue();
+    /* We avoid using GetValue because of a recursion bug with wxSpinCtrl with
+     * wxGTK. */
+    return i_value; //spin->GetValue();
+}
+
+void IntegerConfigControl::OnUpdate( wxCommandEvent &event )
+{
+    i_value = event.GetInt();
+    ConfigControl::OnUpdate( event );
 }
 
 /*****************************************************************************
@@ -621,6 +759,10 @@ int IntegerListConfigControl::GetIntValue()
 /*****************************************************************************
  * RangedIntConfigControl implementation
  *****************************************************************************/
+BEGIN_EVENT_TABLE(RangedIntConfigControl, wxPanel)
+    EVT_COMMAND_SCROLL(-1, RangedIntConfigControl::OnUpdate)
+END_EVENT_TABLE()
+
 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
                                                 module_config_t *p_item,
                                                 wxWindow *parent )
@@ -650,6 +792,10 @@ int RangedIntConfigControl::GetIntValue()
 /*****************************************************************************
  * FloatConfigControl implementation
  *****************************************************************************/
+BEGIN_EVENT_TABLE(FloatConfigControl, wxPanel)
+    EVT_TEXT(-1, FloatConfigControl::OnUpdate)
+END_EVENT_TABLE()
+
 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
                                         module_config_t *p_item,
                                         wxWindow *parent )
@@ -684,6 +830,10 @@ float FloatConfigControl::GetFloatValue()
 /*****************************************************************************
  * BoolConfigControl implementation
  *****************************************************************************/
+BEGIN_EVENT_TABLE(BoolConfigControl, wxPanel)
+    EVT_CHECKBOX(-1, BoolConfigControl::OnUpdate)
+END_EVENT_TABLE()
+
 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
                                       module_config_t *p_item,
                                       wxWindow *parent )
@@ -704,12 +854,27 @@ BoolConfigControl::~BoolConfigControl()
 
 int BoolConfigControl::GetIntValue()
 {
-    if( checkbox->IsChecked() )
-    {
-        return 1;
-    }
-    else
-    {
-        return 0;
-    }
+    if( checkbox->IsChecked() ) return 1;
+    else return 0;
+}
+
+/*****************************************************************************
+ * SectionConfigControl implementation
+ *****************************************************************************/
+SectionConfigControl::SectionConfigControl( vlc_object_t *p_this,
+                                            module_config_t *p_item,
+                                            wxWindow *parent )
+  : ConfigControl( p_this, p_item, parent )
+{
+    delete sizer;
+    sizer = new wxBoxSizer( wxVERTICAL );
+    sizer->Add( new wxStaticText( this, -1, wxU( p_item->psz_text ) ) );
+    sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND, 5 );
+    sizer->Layout();
+    this->SetSizerAndFit( sizer );
+}
+
+SectionConfigControl::~SectionConfigControl()
+{
+    ;
 }