Commit 2bca4f1c authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Add action through vlc_config_set

parent 194072ae
......@@ -275,6 +275,9 @@ enum vlc_config_properties
VLC_CONFIG_LIST,
/* possible values list
* (args=size_t, const <type> *, const char *const *) */
VLC_CONFIG_ADD_ACTION,
/* add value change callback (args=vlc_callback_t, const char *) */
};
......@@ -465,20 +468,9 @@ VLC_EXPORT( int, vlc_config_set, (module_config_t *, int, ...) );
vlc_config_set (p_config + i_config, VLC_CONFIG_RANGE, \
(double)(minv), (double)(maxv))
#define change_action_add( pf_action, action_text ) \
if( !p_config[i_config].i_action ) \
{ p_config[i_config].ppsz_action_text = 0; \
p_config[i_config].ppf_action = 0; } \
p_config[i_config].ppf_action = (vlc_callback_t *) \
realloc( p_config[i_config].ppf_action, \
(p_config[i_config].i_action + 1) * sizeof(void *) ); \
p_config[i_config].ppsz_action_text = (char **)\
realloc( p_config[i_config].ppsz_action_text, \
(p_config[i_config].i_action + 1) * sizeof(void *) ); \
p_config[i_config].ppf_action[p_config[i_config].i_action] = pf_action; \
p_config[i_config].ppsz_action_text[p_config[i_config].i_action] = \
action_text; \
p_config[i_config].i_action++;
#define change_action_add( pf_action, text ) \
vlc_config_set (p_config + i_config, VLC_CONFIG_ADD_ACTION, \
(vlc_callback_t)(pf_action), (const char *)(text))
#define change_internal() \
vlc_config_set (p_config + i_config, VLC_CONFIG_PRIVATE)
......
......@@ -110,7 +110,7 @@ E_(vlc_entry) ( module_t *p_module );
EXTERN_SYMBOL DLL_SYMBOL int CDECL_SYMBOL \
__VLC_SYMBOL(vlc_entry) ( module_t *p_module ) \
{ \
int i_shortcut = 1, res; \
int res; \
size_t i_config = (size_t)(-1); \
module_config_t *p_config = NULL; \
if (vlc_module_set (p_module, VLC_MODULE_NAME, \
......@@ -122,18 +122,9 @@ E_(vlc_entry) ( module_t *p_module );
#define vlc_module_end( ) \
} \
res = config_Duplicate( p_module, p_config, ++i_config ); \
for( size_t i = 0; i < i_config; i++ ) \
{ \
if( p_config[ i ].i_action ) \
{ \
free( p_config[ i ].ppf_action ); \
free( p_config[ i ].ppsz_action_text ); \
} \
} \
free( p_config ); \
if (res) \
return res; \
(void)i_shortcut; \
return VLC_SUCCESS; \
\
error: \
......
......@@ -520,27 +520,6 @@ int config_Duplicate( module_t *p_module, const module_config_t *p_orig,
{
p_module->p_config[i] = p_orig[i];
p_module->p_config[i].p_lock = &p_module->object_lock;
/* duplicate the actions list */
if( p_orig[i].i_action )
{
int j;
p_module->p_config[i].ppf_action =
malloc( p_orig[i].i_action * sizeof(void *) );
p_module->p_config[i].ppsz_action_text =
malloc( p_orig[i].i_action * sizeof(char *) );
for( j = 0; j < p_orig[i].i_action; j++ )
{
p_module->p_config[i].ppf_action[j] =
p_orig[i].ppf_action[j];
p_module->p_config[i].ppsz_action_text[j] =
strdupnull (p_orig[i].ppsz_action_text[j]);
}
}
p_module->p_config[i].pf_callback = p_orig[i].pf_callback;
}
return VLC_SUCCESS;
}
......
......@@ -355,6 +355,36 @@ int vlc_config_set (module_config_t *restrict item, int id, ...)
ret = 0;
break;
}
case VLC_CONFIG_ADD_ACTION:
{
vlc_callback_t cb = va_arg (ap, vlc_callback_t), *tabcb;
const char *name = va_arg (ap, const char *);
char **tabtext;
tabcb = realloc (item->ppf_action,
(item->i_action + 2) * sizeof (cb));
if (tabcb == NULL)
break;
item->ppf_action = tabcb;
tabcb[item->i_action] = cb;
tabcb[item->i_action + 1] = NULL;
tabtext = realloc (item->ppsz_action_text,
(item->i_action + 2) * sizeof (name));
if (tabtext == NULL)
break;
item->ppsz_action_text = tabtext;
if (name)
tabtext[item->i_action] = strdup (gettext (name));
else
tabtext[item->i_action] = NULL;
tabtext[item->i_action + 1] = NULL;
item->i_action++;
ret = 0;
}
}
va_end (ap);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment