]> git.sesse.net Git - vlc/blobdiff - src/modules/entry.c
Don't use enums. They are cool and all (the compiler even tells when one case is...
[vlc] / src / modules / entry.c
index 2b009af35f6c19d2af4dce33cae10be042f78b3d..3891646c607ccda9d0eb31106e71b38487e34e41 100644 (file)
 
 #include <vlc/vlc.h>
 #include <assert.h>
+#include <stdarg.h>
 
 #include "modules/modules.h"
+#include "config/config.h"
 #include "libvlc.h"
-#include "../libvlc.h"
 
 static const char default_name[] = "unnamed";
 
@@ -64,7 +65,6 @@ module_t *vlc_submodule_create (module_t *module)
     submodule->psz_object_name = module->psz_object_name;
     submodule->psz_shortname = module->psz_shortname;
     submodule->psz_longname = module->psz_longname;
-    submodule->psz_program = module->psz_program;
     submodule->psz_capability = module->psz_capability;
     submodule->i_score = module->i_score;
     submodule->i_cpu = module->i_cpu;
@@ -78,7 +78,7 @@ int vlc_module_set (module_t *module, int propid, void *value)
     {
         case VLC_MODULE_CPU_REQUIREMENT:
             assert (!module->b_submodule);
-            module->i_cpu |= (int)value;
+            module->i_cpu |= (intptr_t)value;
             break;
 
         case VLC_MODULE_SHORTCUT:
@@ -109,11 +109,7 @@ int vlc_module_set (module_t *module, int propid, void *value)
             break;
 
         case VLC_MODULE_SCORE:
-            module->i_score = (int)value;
-            break;
-
-        case VLC_MODULE_PROGRAM:
-            module->psz_program = (char *)value;
+            module->i_score = (intptr_t)value;
             break;
 
         case VLC_MODULE_CB_OPEN:
@@ -134,6 +130,10 @@ int vlc_module_set (module_t *module, int propid, void *value)
                 module->psz_longname = (char *)value;
             break;
 
+        case VLC_MODULE_PROGRAM:
+            msg_Warn (module, "deprecated module property %d", propid);
+            break;
+
         default:
             msg_Err (module, "unknown module property %d", propid);
             msg_Err (module, "LibVLC might be too old to use this module.");
@@ -141,3 +141,143 @@ int vlc_module_set (module_t *module, int propid, void *value)
     }
     return 0;
 }
+
+module_config_t *vlc_config_create (module_t *module, int type)
+{
+    unsigned confsize = module->confsize;
+    module_config_t *tab = module->p_config;
+
+    if ((confsize & 0xf) == 0)
+    {
+        tab = realloc (tab, (confsize + 17) * sizeof (*tab));
+        if (tab == NULL)
+            return NULL;
+
+        module->p_config = tab;
+    }
+    module->confsize++;
+
+    memset (tab + confsize, 0, sizeof (tab[confsize]));
+    return tab + confsize;
+}
+
+int vlc_config_set (module_config_t *restrict item, int id, ...)
+{
+    int ret = -1;
+    va_list ap;
+
+    assert (item != NULL);
+    va_start (ap, id);
+
+    switch (id)
+    {
+        case VLC_CONFIG_NAME:
+        {
+            const char *name = va_arg (ap, const char *);
+            vlc_callback_t cb = va_arg (ap, vlc_callback_t);
+
+            assert (name != NULL);
+            item->psz_name = strdup (name);
+            item->pf_callback = cb;
+            ret = 0;
+            break;
+        }
+
+        case VLC_CONFIG_DESC:
+        {
+            const char *text = va_arg (ap, const char *);
+            const char *longtext = va_arg (ap, const char *);
+
+            item->psz_text = text ? strdup (gettext (text)) : NULL;
+            item->psz_longtext = longtext ? strdup (gettext (text)) : NULL;
+            ret = 0;
+            break;
+        }
+
+        case VLC_CONFIG_VALUE:
+        {
+            if (IsConfigIntegerType (item->i_type))
+            {
+                item->orig.i = item->saved.i =
+                item->value.i = va_arg (ap, int);
+                ret = 0;
+            }
+            else
+            if (IsConfigFloatType (item->i_type))
+            {
+                item->orig.f = item->saved.f =
+                item->value.f = va_arg (ap, double);
+                ret = 0;
+            }
+            else
+            if (IsConfigStringType (item->i_type))
+            {
+                const char *value = va_arg (ap, const char *);
+                item->value.psz = value ? strdup (value) : NULL;
+                item->orig.psz = value ? strdup (value) : NULL;
+                item->saved.psz = value ? strdup (value) : NULL;
+                ret = 0;
+            }
+            break;
+        }
+
+        case VLC_CONFIG_RANGE:
+        {
+            if (IsConfigIntegerType (item->i_type))
+            {
+                item->min.i = va_arg (ap, int);
+                item->max.i = va_arg (ap, int);
+                ret = 0;
+            }
+            else
+            if (IsConfigFloatType (item->i_type))
+            {
+                item->min.f = va_arg (ap, double);
+                item->max.f = va_arg (ap, double);
+                ret = 0;
+            }
+            break;
+        }
+
+        case VLC_CONFIG_ADVANCED:
+            item->b_advanced = VLC_TRUE;
+            ret = 0;
+            break;
+
+        case VLC_CONFIG_VOLATILE:
+            item->b_unsaveable = VLC_TRUE;
+            ret = 0;
+            break;
+
+        case VLC_CONFIG_PERSISTENT:
+            item->b_autosave = VLC_TRUE;
+            ret = 0;
+            break;
+
+        case VLC_CONFIG_RESTART:
+            item->b_restart = VLC_TRUE;
+            ret = 0;
+            break;
+
+        case VLC_CONFIG_PRIVATE:
+            item->b_internal = VLC_TRUE;
+            ret = 0;
+            break;
+
+        case VLC_CONFIG_REMOVED:
+            item->psz_current = "SUPPRESSED";
+            ret = 0;
+            break;
+
+        case VLC_CONFIG_CAPABILITY:
+        {
+            const char *cap = va_arg (ap, const char *);
+            item->psz_type = cap ? strdup (cap) : NULL;
+            ret = 0;
+            break;
+        }
+    }
+
+    va_end (ap);
+    return ret;
+}