Skip to content

Commit

Permalink
Merge pull request obsproject#124 from jp9000/new-locale-handling
Browse files Browse the repository at this point in the history
Update to new module locale API
  • Loading branch information
jp9000 committed Jun 25, 2014
2 parents 070f6cb + 1abf915 commit 2ea50ca
Show file tree
Hide file tree
Showing 46 changed files with 210 additions and 208 deletions.
13 changes: 6 additions & 7 deletions libobs/obs-encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ static inline struct obs_encoder_info *get_encoder_info(const char *id)
return NULL;
}

const char *obs_encoder_getdisplayname(const char *id, const char *locale)
const char *obs_encoder_getdisplayname(const char *id)
{
struct obs_encoder_info *ei = get_encoder_info(id);
return ei ? ei->getname(locale) : NULL;
return ei ? ei->getname() : NULL;
}

static bool init_encoder(struct obs_encoder *encoder, const char *name,
Expand Down Expand Up @@ -227,27 +227,26 @@ obs_data_t obs_encoder_defaults(const char *id)
return (info) ? get_defaults(info) : NULL;
}

obs_properties_t obs_get_encoder_properties(const char *id, const char *locale)
obs_properties_t obs_get_encoder_properties(const char *id)
{
const struct obs_encoder_info *ei = get_encoder_info(id);
if (ei && ei->properties) {
obs_data_t defaults = get_defaults(ei);
obs_properties_t properties;

properties = ei->properties(locale);
properties = ei->properties();
obs_properties_apply_settings(properties, defaults);
obs_data_release(defaults);
return properties;
}
return NULL;
}

obs_properties_t obs_encoder_properties(obs_encoder_t encoder,
const char *locale)
obs_properties_t obs_encoder_properties(obs_encoder_t encoder)
{
if (encoder && encoder->info.properties) {
obs_properties_t props;
props = encoder->info.properties(locale);
props = encoder->info.properties();
obs_properties_apply_settings(props, encoder->context.settings);
return props;
}
Expand Down
6 changes: 2 additions & 4 deletions libobs/obs-encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ struct obs_encoder_info {
/**
* Gets the full translated name of this encoder
*
* @param locale Locale to use for translation
* @return Translated name of the encoder
*/
const char *(*getname)(const char *locale);
const char *(*getname)(void);

/**
* Creates the encoder with the specified settings
Expand Down Expand Up @@ -155,10 +154,9 @@ struct obs_encoder_info {
/**
* Gets the property information of this encoder
*
* @param locale The locale to translate with
* @return The properties data
*/
obs_properties_t (*properties)(const char *locale);
obs_properties_t (*properties)(void);

/**
* Updates the settings for this encoder (usually used for things like
Expand Down
3 changes: 3 additions & 0 deletions libobs/obs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct draw_callback {
struct obs_module {
char *name;
void *module;
void (*set_locale)(const char *locale);
};

extern void free_module(struct obs_module *mod);
Expand Down Expand Up @@ -173,6 +174,8 @@ struct obs_core {
signal_handler_t signals;
proc_handler_t procs;

char *locale;

/* segmented into multiple sub-structures to keep things a bit more
* clean and organized */
struct obs_core_video video;
Expand Down
7 changes: 6 additions & 1 deletion libobs/obs-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ int obs_load_module(const char *path)
return errorcode;
}

mod.name = bstrdup(path);
mod.name = bstrdup(path);
mod.set_locale = os_dlsym(mod.module, "obs_module_set_locale");

if (mod.set_locale)
mod.set_locale(obs->locale);

da_push_back(obs->modules, &mod);
return MODULE_SUCCESS;
}
Expand Down
11 changes: 5 additions & 6 deletions libobs/obs-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ MODULE_EXPORT bool obs_module_load(uint32_t libobs_version);
/** Optional: Called when the module is unloaded. */
MODULE_EXPORT void obs_module_unload(void);

/** Called to set the current locale data for the module. */
MODULE_EXPORT void obs_module_set_locale(const char *locale);

/**
* Optional: Declares the author(s) of the module
*
Expand All @@ -59,9 +62,5 @@ MODULE_EXPORT void obs_module_unload(void);
MODULE_EXPORT const char *obs_module_author(void); \
const char *obs_module_author(void) {return name;}

/**
* Optional: Declares the author of the module
*
* @param locale Locale to look up the description for.
*/
MODULE_EXPORT const char *obs_module_description(const char *locale);
/** Optional: Returns a description of the module */
MODULE_EXPORT const char *obs_module_description(void);
12 changes: 6 additions & 6 deletions libobs/obs-output.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ static inline const struct obs_output_info *find_output(const char *id)
return NULL;
}

const char *obs_output_getdisplayname(const char *id, const char *locale)
const char *obs_output_getdisplayname(const char *id)
{
const struct obs_output_info *info = find_output(id);
return (info != NULL) ? info->getname(locale) : NULL;
return (info != NULL) ? info->getname() : NULL;
}

static const char *output_signals[] = {
Expand Down Expand Up @@ -166,26 +166,26 @@ obs_data_t obs_output_defaults(const char *id)
return (info) ? get_defaults(info) : NULL;
}

obs_properties_t obs_get_output_properties(const char *id, const char *locale)
obs_properties_t obs_get_output_properties(const char *id)
{
const struct obs_output_info *info = find_output(id);
if (info && info->properties) {
obs_data_t defaults = get_defaults(info);
obs_properties_t properties;

properties = info->properties(locale);
properties = info->properties();
obs_properties_apply_settings(properties, defaults);
obs_data_release(defaults);
return properties;
}
return NULL;
}

obs_properties_t obs_output_properties(obs_output_t output, const char *locale)
obs_properties_t obs_output_properties(obs_output_t output)
{
if (output && output->info.properties) {
obs_properties_t props;
props = output->info.properties(locale);
props = output->info.properties();
obs_properties_apply_settings(props, output->context.settings);
return props;
}
Expand Down
4 changes: 2 additions & 2 deletions libobs/obs-output.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct obs_output_info {

uint32_t flags;

const char *(*getname)(const char *locale);
const char *(*getname)(void);

void *(*create)(obs_data_t settings, obs_output_t output);
void (*destroy)(void *data);
Expand All @@ -49,7 +49,7 @@ struct obs_output_info {

void (*defaults)(obs_data_t settings);

obs_properties_t (*properties)(const char *locale);
obs_properties_t (*properties)(void);

void (*pause)(void *data);
};
Expand Down
17 changes: 5 additions & 12 deletions libobs/obs-properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,18 @@ struct obs_property {
};

struct obs_properties {
const char *locale;
void *param;
void (*destroy)(void *param);

struct obs_property *first_property;
struct obs_property **last;
};

obs_properties_t obs_properties_create(const char *locale)
obs_properties_t obs_properties_create(void)
{
struct obs_properties *props;
props = bzalloc(sizeof(struct obs_properties));
props->locale = locale;
props->last = &props->first_property;
props->last = &props->first_property;
return props;
}

Expand All @@ -125,10 +123,10 @@ void *obs_properties_get_param(obs_properties_t props)
return props ? props->param : NULL;
}

obs_properties_t obs_properties_create_param(const char *locale,
void *param, void (*destroy)(void *param))
obs_properties_t obs_properties_create_param(void *param,
void (*destroy)(void *param))
{
struct obs_properties *props = obs_properties_create(locale);
struct obs_properties *props = obs_properties_create();
obs_properties_set_param(props, param, destroy);
return props;
}
Expand Down Expand Up @@ -161,11 +159,6 @@ void obs_properties_destroy(obs_properties_t props)
}
}

const char *obs_properties_locale(obs_properties_t props)
{
return props ? props->locale : NULL;
}

obs_property_t obs_properties_first(obs_properties_t props)
{
return (props != NULL) ? props->first_property : NULL;
Expand Down
8 changes: 3 additions & 5 deletions libobs/obs-properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,15 @@ typedef struct obs_property *obs_property_t;

/* ------------------------------------------------------------------------- */

EXPORT obs_properties_t obs_properties_create(const char *locale);
EXPORT obs_properties_t obs_properties_create_param(const char *locale,
void *param, void (*destroy)(void *param));
EXPORT obs_properties_t obs_properties_create(void);
EXPORT obs_properties_t obs_properties_create_param(void *param,
void (*destroy)(void *param));
EXPORT void obs_properties_destroy(obs_properties_t props);

EXPORT void obs_properties_set_param(obs_properties_t props,
void *param, void (*destroy)(void *param));
EXPORT void *obs_properties_get_param(obs_properties_t props);

EXPORT const char *obs_properties_locale(obs_properties_t props);

EXPORT obs_property_t obs_properties_first(obs_properties_t props);

EXPORT obs_property_t obs_properties_get(obs_properties_t props,
Expand Down
3 changes: 1 addition & 2 deletions libobs/obs-scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ static inline void signal_item_remove(struct obs_scene_item *item)
calldata_free(&params);
}

static const char *scene_getname(const char *locale)
static const char *scene_getname(void)
{
/* TODO: locale */
UNUSED_PARAMETER(locale);
return "Scene";
}

Expand Down
13 changes: 6 additions & 7 deletions libobs/obs-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ static inline const struct obs_service_info *find_service(const char *id)
return NULL;
}

const char *obs_service_getdisplayname(const char *id, const char *locale)
const char *obs_service_getdisplayname(const char *id)
{
const struct obs_service_info *info = find_service(id);
return (info != NULL) ? info->getname(locale) : NULL;
return (info != NULL) ? info->getname() : NULL;
}

obs_service_t obs_service_create(const char *id, const char *name,
Expand Down Expand Up @@ -112,27 +112,26 @@ obs_data_t obs_service_defaults(const char *id)
return (info) ? get_defaults(info) : NULL;
}

obs_properties_t obs_get_service_properties(const char *id, const char *locale)
obs_properties_t obs_get_service_properties(const char *id)
{
const struct obs_service_info *info = find_service(id);
if (info && info->properties) {
obs_data_t defaults = get_defaults(info);
obs_properties_t properties;

properties = info->properties(locale);
properties = info->properties();
obs_properties_apply_settings(properties, defaults);
obs_data_release(defaults);
return properties;
}
return NULL;
}

obs_properties_t obs_service_properties(obs_service_t service,
const char *locale)
obs_properties_t obs_service_properties(obs_service_t service)
{
if (service && service->info.properties) {
obs_properties_t props;
props = service->info.properties(locale);
props = service->info.properties();
obs_properties_apply_settings(props, service->context.settings);
return props;
}
Expand Down
4 changes: 2 additions & 2 deletions libobs/obs-service.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct obs_service_info {
/* required */
const char *id;

const char *(*getname)(const char *locale);
const char *(*getname)(void);
void *(*create)(obs_data_t settings, obs_service_t service);
void (*destroy)(void *data);

Expand All @@ -33,7 +33,7 @@ struct obs_service_info {

void (*defaults)(obs_data_t settings);

obs_properties_t (*properties)(const char *locale);
obs_properties_t (*properties)(void);

/**
* Called when getting ready to start up an output, before the encoders
Expand Down
13 changes: 6 additions & 7 deletions libobs/obs-source.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ bool obs_source_init_context(struct obs_source *source,
source_signals);
}

const char *obs_source_getdisplayname(enum obs_source_type type,
const char *id, const char *locale)
const char *obs_source_getdisplayname(enum obs_source_type type, const char *id)
{
const struct obs_source_info *info = get_source_info(type, id);
return (info != NULL) ? info->getname(locale) : NULL;
return (info != NULL) ? info->getname() : NULL;
}

/* internal initialization */
Expand Down Expand Up @@ -322,26 +321,26 @@ obs_data_t obs_source_settings(enum obs_source_type type, const char *id)
}

obs_properties_t obs_get_source_properties(enum obs_source_type type,
const char *id, const char *locale)
const char *id)
{
const struct obs_source_info *info = get_source_info(type, id);
if (info && info->properties) {
obs_data_t defaults = get_defaults(info);
obs_properties_t properties;

properties = info->properties(locale);
properties = info->properties();
obs_properties_apply_settings(properties, defaults);
obs_data_release(defaults);
return properties;
}
return NULL;
}

obs_properties_t obs_source_properties(obs_source_t source, const char *locale)
obs_properties_t obs_source_properties(obs_source_t source)
{
if (source_valid(source) && source->info.properties) {
obs_properties_t props;
props = source->info.properties(locale);
props = source->info.properties();
obs_properties_apply_settings(props, source->context.settings);
return props;
}
Expand Down
6 changes: 2 additions & 4 deletions libobs/obs-source.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ struct obs_source_info {
/**
* Get the translated name of the source type
*
* @param locale The locale to translate with
* @return The translated name of the source type
*/
const char *(*getname)(const char *locale);
const char *(*getname)(void);

/**
* Creates the source data for the source
Expand Down Expand Up @@ -161,10 +160,9 @@ struct obs_source_info {
/**
* Gets the property information of this source
*
* @param locale The locale to translate with
* @return The properties data
*/
obs_properties_t (*properties)(const char *locale);
obs_properties_t (*properties)(void);

/**
* Updates the settings for this source
Expand Down
Loading

0 comments on commit 2ea50ca

Please sign in to comment.