From 8e17cc40106fd1b44b6f48fec0bdc1298b27c2bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Thu, 5 Jun 2008 19:04:56 +0300 Subject: [PATCH] Support for using a custom text domain for configuration strings --- include/vlc_plugin.h | 30 +++++++++++---- src/modules/entry.c | 89 +++++++++++++++++++++++++++++++++----------- 2 files changed, 90 insertions(+), 29 deletions(-) diff --git a/include/vlc_plugin.h b/include/vlc_plugin.h index 77b6c49003..b589300363 100644 --- a/include/vlc_plugin.h +++ b/include/vlc_plugin.h @@ -93,6 +93,7 @@ E_(vlc_entry) ( module_t *p_module ); __VLC_SYMBOL(vlc_entry) ( module_t *p_module ) \ { \ module_config_t *p_config = NULL; \ + const char *domain = NULL; \ if (vlc_module_set (p_module, VLC_MODULE_NAME, \ (const char *)(MODULE_STRING))) \ goto error; \ @@ -151,6 +152,8 @@ E_(vlc_entry) ( module_t *p_module ); if (vlc_module_set (p_submodule, VLC_MODULE_NO_UNLOAD)) \ goto error; +#define set_text_domain( dom ) domain = (dom); + VLC_EXPORT( module_t *, vlc_module_create, ( vlc_object_t * ) ); VLC_EXPORT( module_t *, vlc_submodule_create, ( module_t * ) ); VLC_EXPORT( int, vlc_module_set, (module_t *module, int propid, ...) ); @@ -186,7 +189,7 @@ enum vlc_config_properties VLC_CONFIG_NAME, /* command line name (args=const char *, vlc_callback_t) */ - VLC_CONFIG_DESC, + VLC_CONFIG_DESC_NODOMAIN, /* description (args=const char *, const char *) */ VLC_CONFIG_VALUE, @@ -219,11 +222,11 @@ enum vlc_config_properties VLC_CONFIG_SHORTCUT, /* one-character (short) command line option name (args=char) */ - VLC_CONFIG_LIST, + VLC_CONFIG_LIST_NODOMAIN, /* possible values list * (args=size_t, const *, const char *const *) */ - VLC_CONFIG_ADD_ACTION, + VLC_CONFIG_ADD_ACTION_NODOMAIN, /* add value change callback (args=vlc_callback_t, const char *) */ VLC_CONFIG_OLDNAME, @@ -231,6 +234,17 @@ enum vlc_config_properties VLC_CONFIG_SAFE, /* tag as modifiable by untrusted input item "sources" (args=none) */ + + VLC_CONFIG_DESC, + /* description (args=const char *, const char *, const char *) */ + + VLC_CONFIG_LIST, + /* possible values list + * (args=const char *, size_t, const *, const char *const *) */ + + VLC_CONFIG_ADD_ACTION, + /* add value change callback + * (args=const char *, vlc_callback_t, const char *) */ }; /***************************************************************************** @@ -251,7 +265,7 @@ enum vlc_config_properties #define add_typedesc_inner( type, text, longtext ) \ add_type_inner( type ) \ - vlc_config_set (p_config, VLC_CONFIG_DESC, \ + vlc_config_set (p_config, VLC_CONFIG_DESC, domain, \ (const char *)(text), (const char *)(longtext)); #define add_typeadv_inner( type, text, longtext, advc ) \ @@ -386,21 +400,21 @@ enum vlc_config_properties vlc_config_set (p_config, VLC_CONFIG_SHORTCUT, (int)(ch)); #define change_string_list( list, list_text, list_update_func ) \ - vlc_config_set (p_config, VLC_CONFIG_LIST, \ + vlc_config_set (p_config, VLC_CONFIG_LIST, domain, \ (size_t)(sizeof (list) / sizeof (char *)), \ (const char *const *)(list), \ (const char *const *)(list_text), \ list_update_func); #define change_integer_list( list, list_text, list_update_func ) \ - vlc_config_set (p_config, VLC_CONFIG_LIST, \ + vlc_config_set (p_config, VLC_CONFIG_LIST, domain, \ (size_t)(sizeof (list) / sizeof (int)), \ (const int *)(list), \ (const char *const *)(list_text), \ list_update_func); #define change_float_list( list, list_text, list_update_func ) \ - vlc_config_set (p_config, VLC_CONFIG_LIST, \ + vlc_config_set (p_config, VLC_CONFIG_LIST, domain, \ (size_t)(sizeof (list) / sizeof (float)), \ (const float *)(list), \ (const char *const *)(list_text), \ @@ -414,7 +428,7 @@ enum vlc_config_properties (double)(minv), (double)(maxv)); #define change_action_add( pf_action, text ) \ - vlc_config_set (p_config, VLC_CONFIG_ADD_ACTION, \ + vlc_config_set (p_config, VLC_CONFIG_ADD_ACTION, domain, \ (vlc_callback_t)(pf_action), (const char *)(text)); #define change_internal() \ diff --git a/src/modules/entry.c b/src/modules/entry.c index 909d40171b..3abc6cb8c7 100644 --- a/src/modules/entry.c +++ b/src/modules/entry.c @@ -252,15 +252,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 (dgettext (PACKAGE, text)) : NULL; - item->psz_longtext = - longtext ? strdup (dgettext (PACKAGE, longtext)) : NULL; - ret = 0; + ret = vlc_config_set (item, VLC_CONFIG_DESC, NULL, text, longtext); break; } @@ -352,8 +348,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)); @@ -406,12 +460,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 (dgettext (PACKAGE, text[i])) : NULL; + text[i] ? strdup (dgettext (domain, text[i])) : NULL; dtext[len] = NULL; item->ppsz_list_text = dtext; @@ -430,6 +487,7 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) 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; @@ -448,8 +506,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 (dgettext (PACKAGE, name)); + tabtext[item->i_action] = strdup (dgettext (domain, name)); else tabtext[item->i_action] = NULL; tabtext[item->i_action + 1] = NULL; @@ -458,19 +518,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_SAFE: - item->b_safe = true; - ret = 0; - break; } va_end (ap); -- 2.39.2