From 9ddab745e39a4272dc97559aecc3aea42da78c1e Mon Sep 17 00:00:00 2001
From: basos g <noxelia 4t gmail d0t c0m>
Date: Mon, 6 Apr 2009 13:51:20 +0000
Subject: [PATCH 17/20] ADD for module configs: list of slave config options

A list of slave list config options could optionally be related
to a module config item. It's purpose is to add a gui capability
of updating slave list configs that depend on a master (list) config
on-the-fly.
A use case of this is at capture device panels where capability lists
are populated according to the selected input device.
---
 include/vlc_configuration.h |    4 ++++
 include/vlc_plugin.h        |   10 ++++++++++
 src/config/core.c           |    9 +++++++++
 src/modules/entry.c         |   18 ++++++++++++++++++
 4 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h
index c68be17..0e9942c 100644
--- a/include/vlc_configuration.h
+++ b/include/vlc_configuration.h
@@ -171,6 +171,10 @@ struct module_config_t
     char       **ppsz_list_text;          /* Friendly names for list values */
     int          i_list;                               /* Options list size */
     vlc_callback_t pf_update_list; /*callback to initialize dropdownlists */
+    char **      ppsz_slaves;   /* Makes this config to be commited when an
+                     element of the list is selected on the gui. Also this
+                     list of related options will be updated (pf_update_list) on-the-fly */
+    int          i_slaves;  /* slaves list size */
 
     /* Actions list */
     vlc_callback_t *ppf_action;    /* List of possible actions for a config */
diff --git a/include/vlc_plugin.h b/include/vlc_plugin.h
index 53a1b10..ce0edd2 100644
--- a/include/vlc_plugin.h
+++ b/include/vlc_plugin.h
@@ -106,6 +106,10 @@ enum vlc_module_properties
     /* add value change callback
      * (args=const char *, vlc_callback_t, const char *) */
 
+    VLC_CONFIG_SLAVELIST,
+    /* optional list of slave (list) configs that are affected from this
+     * (args=const char *, size_t )    */
+
     /* Insert new VLC_CONFIG_* here */
 };
 
@@ -416,6 +420,12 @@ enum vlc_module_properties
                     (const char *const *)(list_text), \
                     (vlc_callback_t)(list_update_func));
 
+#define change_slave_list( list ) \
+    compile_time_assert( list, change_slave_list_parameter_cannot_be_NULL ) \
+    vlc_config_set( p_config, VLC_CONFIG_SLAVELIST, \
+                    (size_t)(sizeof( list ) / sizeof( char * ) ), \
+                    (const char* const *) (list));
+
 
 #define change_integer_range( minv, maxv ) \
     vlc_config_set (p_config, VLC_CONFIG_RANGE, (int)(minv), (int)(maxv));
diff --git a/src/config/core.c b/src/config/core.c
index 9f6bc6f..24cfe31 100644
--- a/src/config/core.c
+++ b/src/config/core.c
@@ -534,6 +534,15 @@ void config_Free( module_t *p_module )
             free( p_item->ppf_action );
             free( p_item->ppsz_action_text );
         }
+
+        if ( p_item->ppsz_slaves )
+        {
+            for( i = 0; i < p_item->i_slaves; i++ )
+            {
+                free( p_item->ppsz_slaves[i] );
+            }
+            free( p_item->ppsz_slaves );
+        }
     }
 
     free (p_module->p_config);
diff --git a/src/modules/entry.c b/src/modules/entry.c
index 6af3fba..997105f 100644
--- a/src/modules/entry.c
+++ b/src/modules/entry.c
@@ -461,6 +461,24 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
             break;
         }
 
+        case VLC_CONFIG_SLAVELIST:
+        {
+            size_t len = va_arg (ap, size_t);
+
+            const char *const *src = va_arg (ap, const char *const *);
+            char **dst = malloc (sizeof (char *) * (len + 1));
+
+            if (dst != NULL)
+            {
+                for (size_t i = 0; i < len; i++)
+                    dst[i] = src[i] ? strdup (src[i]) : NULL;
+                dst[len] = NULL;
+            }
+            item->ppsz_slaves = dst;
+            item->i_slaves = len;
+            break;
+        }
+
         default:
             fprintf (stderr, "LibVLC: unknown module property %d\n", propid);
             fprintf (stderr, "LibVLC: too old to use this module?\n");
-- 
1.6.1.3

