X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fentry.c;h=3c2628a945cd0a37a8412dd25cb26d503ee90375;hb=848489c3863b1b7ddbe542aa3e746063722b9280;hp=fa57d2b3c5c0dba5305fefdc9ae2b94da7c0568f;hpb=99fab9089e9e1709d9c3a4bc5ced0c137ac59134;p=vlc diff --git a/src/modules/entry.c b/src/modules/entry.c index fa57d2b3c5..3c2628a945 100644 --- a/src/modules/entry.c +++ b/src/modules/entry.c @@ -1,7 +1,8 @@ /***************************************************************************** * entry.c : Callbacks for module entry point ***************************************************************************** - * Copyright (C) 2001-2007 the VideoLAN team + * Copyright (C) 2007 the VideoLAN team + * Copyright © 2007-2008 Rémi Denis-Courmont * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,13 +23,17 @@ # include "config.h" #endif -#include +#include +#include #include #include #include "modules/modules.h" #include "config/configuration.h" #include "libvlc.h" +#ifndef ENABLE_NLS +# define dgettext(d, m) ((char *)(m)) +#endif static const char default_name[] = "unnamed"; @@ -40,9 +45,10 @@ module_t *vlc_module_create (vlc_object_t *obj) if (module == NULL) return NULL; - module->b_reentrant = module->b_unloadable = VLC_TRUE; - module->psz_object_name = module->psz_longname = default_name; - module->psz_capability = ""; + module->b_reentrant = module->b_unloadable = true; + module->psz_object_name = strdup( default_name ); + module->psz_longname = default_name; + module->psz_capability = (char*)""; module->i_score = 1; module->i_config_items = module->i_bool_items = 0; @@ -62,13 +68,13 @@ module_t *vlc_submodule_create (module_t *module) return NULL; vlc_object_attach (submodule, module); - submodule->b_submodule = VLC_TRUE; + submodule->b_submodule = true; /* Muahahaha! Heritage! Polymorphism! Ugliness!! */ memcpy (submodule->pp_shortcuts, module->pp_shortcuts, sizeof (submodule->pp_shortcuts)); - submodule->psz_object_name = module->psz_object_name; + submodule->psz_object_name = strdup( module->psz_object_name ); submodule->psz_shortname = module->psz_shortname; submodule->psz_longname = module->psz_longname; submodule->psz_capability = module->psz_capability; @@ -78,13 +84,17 @@ module_t *vlc_submodule_create (module_t *module) } -int vlc_module_set (module_t *module, int propid, void *value) +int vlc_module_set (module_t *module, int propid, ...) { + va_list ap; + int ret = VLC_SUCCESS; + + va_start (ap, propid); switch (propid) { case VLC_MODULE_CPU_REQUIREMENT: assert (!module->b_submodule); - module->i_cpu |= (intptr_t)value; + module->i_cpu |= va_arg (ap, int); break; case VLC_MODULE_SHORTCUT: @@ -92,60 +102,106 @@ int vlc_module_set (module_t *module, int propid, void *value) unsigned i; for (i = 0; module->pp_shortcuts[i] != NULL; i++); if (i >= (MODULE_SHORTCUT_MAX - 1)) - return VLC_ENOMEM; + { + ret = VLC_ENOMEM; + break; + } - module->pp_shortcuts[i] = (char *)value; + module->pp_shortcuts[i] = va_arg (ap, char *); break; } - case VLC_MODULE_SHORTNAME: - module->psz_shortname = (char *)value; + case VLC_MODULE_SHORTNAME_NODOMAIN: + { + const char *name = va_arg (ap, char *); + ret = vlc_module_set (module, VLC_MODULE_SHORTNAME, NULL, name); break; + } - case VLC_MODULE_DESCRIPTION: - module->psz_longname = (char *)value; + case VLC_MODULE_DESCRIPTION_NODOMAIN: + { + const char *desc = va_arg (ap, char *); + ret = vlc_module_set (module, VLC_MODULE_DESCRIPTION, NULL, desc); break; + } - case VLC_MODULE_HELP: - module->psz_help = (char *)value; + case VLC_MODULE_HELP_NODOMAIN: + { + const char *help = va_arg (ap, char *); + ret = vlc_module_set (module, VLC_MODULE_HELP, NULL, help); break; + } case VLC_MODULE_CAPABILITY: - module->psz_capability = (char *)value; + module->psz_capability = va_arg (ap, char *); break; case VLC_MODULE_SCORE: - module->i_score = (intptr_t)value; + module->i_score = va_arg (ap, int); + break; + + case VLC_MODULE_PROGRAM: + msg_Warn (module, "deprecated module property %d", propid); break; case VLC_MODULE_CB_OPEN: - module->pf_activate = (int (*) (vlc_object_t *))value; + module->pf_activate = va_arg (ap, int (*) (vlc_object_t *)); break; case VLC_MODULE_CB_CLOSE: - module->pf_deactivate = (void (*) (vlc_object_t *))value; + module->pf_deactivate = va_arg (ap, void (*) (vlc_object_t *)); break; - case VLC_MODULE_UNLOADABLE: - module->b_unloadable = (value != NULL); + case VLC_MODULE_NO_UNLOAD: + module->b_unloadable = false; break; case VLC_MODULE_NAME: - module->pp_shortcuts[0] = module->psz_object_name = (char *)value; + { + const char *value = va_arg (ap, const char *); + free( module->psz_object_name ); + module->psz_object_name = strdup( value ); + module->pp_shortcuts[0] = value; if (module->psz_longname == default_name) - module->psz_longname = (char *)value; + module->psz_longname = value; break; + } - case VLC_MODULE_PROGRAM: - msg_Warn (module, "deprecated module property %d", propid); + case VLC_MODULE_SHORTNAME: + { + const char *domain = va_arg (ap, const char *); + if (domain == NULL) + domain = PACKAGE; + module->psz_shortname = dgettext (domain, va_arg (ap, char *)); + break; + } + + case VLC_MODULE_DESCRIPTION: + { + const char *domain = va_arg (ap, const char *); + if (domain == NULL) + domain = PACKAGE; + module->psz_longname = dgettext (domain, va_arg (ap, char *)); break; + } + + case VLC_MODULE_HELP: + { + const char *domain = va_arg (ap, const char *); + if (domain == NULL) + domain = PACKAGE; + module->psz_help = dgettext (domain, va_arg (ap, char *)); + break; + } default: msg_Err (module, "unknown module property %d", propid); msg_Err (module, "LibVLC might be too old to use this module."); - return VLC_EGENERIC; + ret = VLC_EGENERIC; + break; } - return 0; + va_end (ap); + return ret; } module_config_t *vlc_config_create (module_t *module, int type) @@ -164,7 +220,7 @@ module_config_t *vlc_config_create (module_t *module, int type) memset (tab + confsize, 0, sizeof (tab[confsize])); tab[confsize].i_type = type; - tab[confsize].p_lock = &module->object_lock; + tab[confsize].p_lock = &(vlc_internals(module)->lock); if (type & CONFIG_ITEM) { @@ -199,14 +255,11 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) break; } - case VLC_CONFIG_DESC: + case VLC_CONFIG_DESC_NODOMAIN: { const char *text = va_arg (ap, const char *); const char *longtext = va_arg (ap, const char *); - - item->psz_text = text ? strdup ( _(text)) : NULL; - item->psz_longtext = longtext ? strdup ( _(longtext)) : NULL; - ret = 0; + ret = vlc_config_set (item, VLC_CONFIG_DESC, NULL, text, longtext); break; } @@ -256,32 +309,32 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) } case VLC_CONFIG_ADVANCED: - item->b_advanced = VLC_TRUE; + item->b_advanced = true; ret = 0; break; case VLC_CONFIG_VOLATILE: - item->b_unsaveable = VLC_TRUE; + item->b_unsaveable = true; ret = 0; break; case VLC_CONFIG_PERSISTENT: - item->b_autosave = VLC_TRUE; + item->b_autosave = true; ret = 0; break; case VLC_CONFIG_RESTART: - item->b_restart = VLC_TRUE; + item->b_restart = true; ret = 0; break; case VLC_CONFIG_PRIVATE: - item->b_internal = VLC_TRUE; + item->b_internal = true; ret = 0; break; case VLC_CONFIG_REMOVED: - item->b_removed = VLC_TRUE; + item->b_removed = true; ret = 0; break; @@ -298,8 +351,66 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) ret = 0; break; + case VLC_CONFIG_LIST_NODOMAIN: + { + size_t len = va_arg (ap, size_t); + if (IsConfigIntegerType (item->i_type)) + { + const int *src = va_arg (ap, const int *); + const char *const *text = va_arg (ap, const char *const *); + ret = vlc_config_set (item, VLC_CONFIG_LIST, NULL, len, src, + text); + } + else + if (IsConfigStringType (item->i_type)) + { + const char *const *src = va_arg (ap, const char *const *); + const char *const *text = va_arg (ap, const char *const *); + ret = vlc_config_set (item, VLC_CONFIG_LIST, NULL, len, src, + text); + } + break; + } + + case VLC_CONFIG_ADD_ACTION_NODOMAIN: + { + vlc_callback_t cb = va_arg (ap, vlc_callback_t); + const char *name = va_arg (ap, const char *); + ret = vlc_config_set (item, VLC_CONFIG_ADD_ACTION, NULL, cb, name); + break; + } + + case VLC_CONFIG_OLDNAME: + { + const char *oldname = va_arg (ap, const char *); + item->psz_oldname = oldname ? strdup (oldname) : NULL; + ret = 0; + break; + } + + case VLC_CONFIG_SAFE: + item->b_safe = true; + ret = 0; + break; + + case VLC_CONFIG_DESC: + { + const char *domain = va_arg (ap, const char *); + const char *text = va_arg (ap, const char *); + const char *longtext = va_arg (ap, const char *); + + if (domain == NULL) + domain = PACKAGE; + item->psz_text = text ? strdup (dgettext (domain, text)) : NULL; + item->psz_longtext = + longtext ? strdup (dgettext (domain, longtext)) : NULL; + ret = 0; + break; + } + case VLC_CONFIG_LIST: { + const char *domain = va_arg (ap, const char *); size_t len = va_arg (ap, size_t); char **dtext = malloc (sizeof (char *) * (len + 1)); @@ -352,11 +463,15 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) break; /* Copy textual descriptions */ + if (domain == NULL) + domain = PACKAGE; + const char *const *text = va_arg (ap, const char *const *); if (text != NULL) { for (size_t i = 0; i < len; i++) - dtext[i] = text[i] ? strdup ( _(text[i])) : NULL; + dtext[i] = + text[i] ? strdup (dgettext (domain, text[i])) : NULL; dtext[len] = NULL; item->ppsz_list_text = dtext; @@ -368,12 +483,14 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) } item->i_list = len; + item->pf_update_list = va_arg (ap, vlc_callback_t); ret = 0; break; } case VLC_CONFIG_ADD_ACTION: { + const char *domain = va_arg (ap, const char *); vlc_callback_t cb = va_arg (ap, vlc_callback_t), *tabcb; const char *name = va_arg (ap, const char *); char **tabtext; @@ -392,8 +509,10 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) break; item->ppsz_action_text = tabtext; + if (domain == NULL) + domain = PACKAGE; if (name) - tabtext[item->i_action] = strdup ( _(name)); + tabtext[item->i_action] = strdup (dgettext (domain, name)); else tabtext[item->i_action] = NULL; tabtext[item->i_action + 1] = NULL; @@ -402,19 +521,6 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) ret = 0; break; } - - case VLC_CONFIG_OLDNAME: - { - const char *oldname = va_arg (ap, const char *); - item->psz_oldname = oldname ? strdup (oldname) : NULL; - ret = 0; - break; - } - - case VLC_CONFIG_UNSAFE: - item->b_unsafe = VLC_TRUE; - ret = 0; - break; } va_end (ap);