diff options
-rw-r--r-- | navit/command.c | 28 | ||||
-rw-r--r-- | navit/osd.c | 24 | ||||
-rw-r--r-- | navit/osd.h | 1 |
3 files changed, 44 insertions, 9 deletions
diff --git a/navit/command.c b/navit/command.c index 8594aa851..68e64d309 100644 --- a/navit/command.c +++ b/navit/command.c @@ -112,7 +112,7 @@ command_attr_type(struct result *res) } static int -command_object_get_attr(struct attr *object, enum attr_type attr_type, struct attr *ret) +command_object_get_attr(struct context *ctx, struct attr *object, enum attr_type attr_type, struct attr *ret) { struct object_func *func=object_func_lookup(object->type); if (!func || !func->get_attr) @@ -125,7 +125,7 @@ command_get_attr(struct context *ctx, struct result *res) { int result; enum attr_type attr_type=command_attr_type(res); - result=command_object_get_attr(&res->attr, attr_type, &res->attr); + result=command_object_get_attr(ctx, &res->attr, attr_type, &res->attr); if (result) { res->var=res->attrn; res->varlen=res->attrnlen; @@ -314,7 +314,7 @@ command_call_function(struct context *ctx, struct result *res) ctx->error=missing_closing_brace; return; } - if (command_object_get_attr(&res->attr, attr_callback_list, &cbl)) { + if (command_object_get_attr(ctx, &res->attr, attr_callback_list, &cbl)) { int valid; dbg(0,"function call %s from %s\n",function, attr_to_name(res->attr.type)); callback_list_call_attr_4(cbl.u.callback_list, attr_command, function, list, NULL, &valid); @@ -663,16 +663,34 @@ command_evaluate_to_string(struct attr *attr, char *expr, int **error) char *ret; command_evaluate_to(attr, expr, &ctx, &res); - if (error) - *error=ctx.error; if (!ctx.error) ret=get_string(&ctx, &res); + if (error) + *error=ctx.error; if (ctx.error) return NULL; else return ret; } +int +command_evaluate_to_int(struct attr *attr, char *expr, int **error) +{ + struct result res; + struct context ctx; + char *ret; + + command_evaluate_to(attr, expr, &ctx, &res); + if (!ctx.error) + ret=get_int(&ctx, &res); + if (error) + *error=ctx.error; + if (ctx.error) + return 0; + else + return ret; +} + void command_evaluate(struct attr *attr, char *expr) { diff --git a/navit/osd.c b/navit/osd.c index f18abe652..4df2126df 100644 --- a/navit/osd.c +++ b/navit/osd.c @@ -147,6 +147,10 @@ osd_set_std_attr(struct attr **attrs, struct osd_item *item, int flags) if (attr) item->osd_configuration = attr->u.num; + attr=attr_search(attrs, NULL, attr_enable_expression); + if (attr) + item->enable_expression = g_strdup(attr->u.str); + attr = attr_search(attrs, NULL, attr_w); if (attr) { if (attr->u.num > ATTR_REL_MAXABS) { @@ -208,11 +212,23 @@ osd_set_std_attr(struct attr **attrs, struct osd_item *item, int flags) void osd_std_config(struct osd_item *item, struct navit *navit) { - struct attr osd_configuration; + struct attr attr; dbg(1,"enter\n"); - if (!navit_get_attr(navit, attr_osd_configuration, &osd_configuration, NULL)) - osd_configuration.u.num=-1; - item->configured = !!(osd_configuration.u.num & item->osd_configuration); + if (item->enable_expression) { + int error,configured; + attr.type=attr_navit; + attr.u.navit=navit; + configured=command_evaluate_to_int(&navit, item->enable_expression, &error); + if (error) { + dbg(0,"evaluating %s resulted in error %d\n", item->enable_expression, error); + configured=0; + } + item->configured = !!configured; + } else { + if (!navit_get_attr(navit, attr_osd_configuration, &attr, NULL)) + attr.u.num=-1; + item->configured = !!(attr.u.num & item->osd_configuration); + } graphics_overlay_disable(item->gr, !item->configured); } diff --git a/navit/osd.h b/navit/osd.h index 99b760dd4..21c27897e 100644 --- a/navit/osd.h +++ b/navit/osd.h @@ -44,6 +44,7 @@ struct osd_item { struct callback *resize_cb; int pressed; char *command; + char *enable_expression; }; /* prototypes */ |