Variants should inherit iso639, iso3166 and brief from parent layout if omitted (#266)

master
M Hickford 2022-01-24 02:16:08 +01:00 committed by GitHub
parent 9b05825e53
commit efa9962432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 3 deletions

View File

@ -870,7 +870,8 @@ parse_variant(struct rxkb_context *ctx, struct rxkb_layout *l,
v->name = strdup(l->name); v->name = strdup(l->name);
v->variant = name; v->variant = name;
v->description = description; v->description = description;
v->brief = brief; // if variant omits brief, inherit from parent layout.
v->brief = brief == NULL ? strdup_safe(l->brief) : brief;
v->popularity = popularity; v->popularity = popularity;
list_append(&ctx->layouts, &v->base.link); list_append(&ctx->layouts, &v->base.link);
@ -880,11 +881,35 @@ parse_variant(struct rxkb_context *ctx, struct rxkb_layout *l,
if (!is_node(ci, "configItem")) if (!is_node(ci, "configItem"))
continue; continue;
bool found_language_list = false;
bool found_country_list = false;
for (node = ci->children; node; node = node->next) { for (node = ci->children; node; node = node->next) {
if (is_node(node, "languageList")) if (is_node(node, "languageList")) {
parse_language_list(node, v); parse_language_list(node, v);
if (is_node(node, "countryList")) found_language_list = true;
}
if (is_node(node, "countryList")) {
parse_country_list(node, v); parse_country_list(node, v);
found_country_list = true;
}
}
if (!found_language_list) {
// inherit from parent layout
struct rxkb_iso639_code* x;
list_for_each(x, &l->iso639s, base.link) {
struct rxkb_iso639_code* code = rxkb_iso639_code_create(&v->base);
code->code = strdup(x->code);
list_append(&v->iso639s, &code->base.link);
}
}
if (!found_country_list) {
// inherit from parent layout
struct rxkb_iso3166_code* x;
list_for_each(x, &l->iso3166s, base.link) {
struct rxkb_iso3166_code* code = rxkb_iso3166_code_create(&v->base);
code->code = strdup(x->code);
list_append(&v->iso3166s, &code->base.link);
}
} }
} }
} else { } else {

View File

@ -620,6 +620,7 @@ test_load_full(void)
struct test_layout system_layouts[] = { struct test_layout system_layouts[] = {
{"l1", NO_VARIANT, "lbrief1", "ldesc1"}, {"l1", NO_VARIANT, "lbrief1", "ldesc1"},
{"l1", "v1", "vbrief1", "vdesc1"}, {"l1", "v1", "vbrief1", "vdesc1"},
{"l1", "v2", NULL, "vdesc2"},
{NULL}, {NULL},
}; };
struct test_option_group system_groups[] = { struct test_option_group system_groups[] = {
@ -654,6 +655,11 @@ test_load_full(void)
assert(cmp_layouts(&system_layouts[1], l)); assert(cmp_layouts(&system_layouts[1], l));
rxkb_layout_unref(l); rxkb_layout_unref(l);
l = fetch_layout(ctx, "l1", "v2");
struct test_layout expected = {"l1", "v2", "lbrief1", "vdesc2"};
assert(cmp_layouts(&expected, l));
rxkb_layout_unref(l);
g = fetch_option_group(ctx, "grp1"); g = fetch_option_group(ctx, "grp1");
assert(cmp_option_groups(&system_groups[0], g, CMP_EXACT)); assert(cmp_option_groups(&system_groups[0], g, CMP_EXACT));
rxkb_option_group_unref(g); rxkb_option_group_unref(g);