diff options
author | Sergey Udaltsov <svu@gnome.org> | 2008-04-14 21:52:47 +0000 |
---|---|---|
committer | Sergey Udaltsov <svu@gnome.org> | 2008-04-14 21:52:47 +0000 |
commit | 3be5407e80f5cf3994af63f2f0478c4bb46a9484 (patch) | |
tree | e11a22874ee52bae8178eed7ceb22fe7b851fc46 | |
parent | 4964ab4d84d32558ecf716c89252814265ba1d8e (diff) | |
download | libxklavier-3be5407e80f5cf3994af63f2f0478c4bb46a9484.tar.gz |
process country lists
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | libxklavier/xkl_config_item.h | 5 | ||||
-rw-r--r-- | libxklavier/xklavier_config.c | 67 | ||||
-rw-r--r-- | tests/test_config.c | 24 |
5 files changed, 86 insertions, 18 deletions
@@ -1,3 +1,9 @@ +2008-04-14 svu + + * configure.in, libxklavier/xkl_config_item.h, + libxklavier/xklavier_config.c, tests/test_config.c: processing the + country lists + 2008-03-10 svu * NEWS: preparing 3.5 diff --git a/configure.in b/configure.in index 4603b27..62e974e 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ AC_INIT(libxklavier/xklavier.c) PACKAGE=libxklavier MAJOR_VERSION=3 -MINOR_VERSION=5 +MINOR_VERSION=6 VERSION=$MAJOR_VERSION.$MINOR_VERSION VERSION_INFO=12:0:0 diff --git a/libxklavier/xkl_config_item.h b/libxklavier/xkl_config_item.h index 6caf7f7..0e72579 100644 --- a/libxklavier/xkl_config_item.h +++ b/libxklavier/xkl_config_item.h @@ -90,6 +90,11 @@ extern "C" { #define XCI_PROP_VENDOR "vendor" /** + * Extra property for the XklConfigItem, defining the list of countryes (used for layouts/variants) + */ +#define XCI_PROP_COUNTRY_LIST "countryList" + +/** * The XklConfigItem class, derived from GObject */ struct _XklConfigItemClass { diff --git a/libxklavier/xklavier_config.c b/libxklavier/xklavier_config.c index d8b28e0..b961f90 100644 --- a/libxklavier/xklavier_config.c +++ b/libxklavier/xklavier_config.c @@ -45,6 +45,8 @@ static xmlXPathCompExprPtr option_groups_xpath; #define XML_TAG_DESCR "description" #define XML_TAG_SHORT_DESCR "shortDescription" #define XML_TAG_VENDOR "vendor" +#define XML_TAG_COUNTRY_LIST "countryList" +#define XML_TAG_ISO3166ID "iso3166Id" // gettext domain for translations #define XKB_DOMAIN "xkeyboard-config" @@ -89,6 +91,7 @@ xkl_find_nonlocalized_element(xmlNodePtr ptr, const gchar * tag_name) { xmlNodePtr found_element = NULL; + /* Look through all siblings, trying to find a node with proper name */ while (ptr != NULL) { char *node_name = (char *) ptr->name; if (ptr->type != XML_TEXT_NODE) { @@ -111,14 +114,18 @@ xkl_read_config_item(XklConfigRegistry * config, xmlNodePtr iptr, { xmlNodePtr name_element, ptr; xmlNodePtr desc_element = NULL, short_desc_element = - NULL, vendor_element = NULL; + NULL, vendor_element = NULL, country_list_element = + NULL, country_ptr = NULL; gchar *vendor = NULL; + gchar **countries = NULL; + gint n_countries, idx = 0; *item->name = 0; *item->short_description = 0; *item->description = 0; g_object_set_data(G_OBJECT(item), XCI_PROP_VENDOR, NULL); + g_object_set_data(G_OBJECT(item), XCI_PROP_COUNTRY_LIST, NULL); if (!xkl_xml_find_config_item_child(iptr, &ptr)) return FALSE; @@ -135,19 +142,9 @@ xkl_read_config_item(XklConfigRegistry * config, xmlNodePtr iptr, desc_element = xkl_find_nonlocalized_element(ptr, XML_TAG_DESCR); vendor_element = xkl_find_nonlocalized_element(ptr, XML_TAG_VENDOR); + country_list_element = + xkl_find_nonlocalized_element(ptr, XML_TAG_COUNTRY_LIST); - if (vendor_element != NULL && vendor_element->children != NULL) { - vendor = - g_strdup((const char *) vendor_element->children-> - content); - g_object_set_data_full(G_OBJECT(item), XCI_PROP_VENDOR, - vendor, g_free); - } - - /* - * Actually, here we should have some code to find - * the correct localized description... - */ if (name_element != NULL && name_element->children != NULL) strncat(item->name, (char *) name_element->children->content, @@ -168,6 +165,50 @@ xkl_read_config_item(XklConfigRegistry * config, xmlNodePtr iptr, (const char *) desc_element->children-> content), XKL_MAX_CI_DESC_LENGTH - 1); } + + if (vendor_element != NULL && vendor_element->children != NULL) { + vendor = + g_strdup((const char *) vendor_element->children-> + content); + g_object_set_data_full(G_OBJECT(item), XCI_PROP_VENDOR, + vendor, g_free); + } + + if (country_list_element != NULL + && country_list_element->children != NULL) { + n_countries = 0; + + /* First, count countries */ + country_ptr = country_list_element->children; + while (NULL != + (country_ptr = + xkl_find_nonlocalized_element(country_ptr, + XML_TAG_ISO3166ID))) + { + n_countries++; + country_ptr = country_ptr->next; + } + + if (n_countries != 0) { + countries = g_new0(gchar *, n_countries); + /* Then, actually, populate the list */ + country_ptr = country_list_element->children; + for (idx = 0; + NULL != (country_ptr = + xkl_find_nonlocalized_element + (country_ptr, XML_TAG_ISO3166ID)); + country_ptr = country_ptr->next, idx++) { + countries[idx] = + g_strdup((const char *) country_ptr-> + children->content); + } + g_object_set_data_full(G_OBJECT(item), + XCI_PROP_COUNTRY_LIST, + countries, (GDestroyNotify) + g_strfreev); + } + } + return TRUE; } diff --git a/tests/test_config.c b/tests/test_config.c index b53d76f..76bc42f 100644 --- a/tests/test_config.c +++ b/tests/test_config.c @@ -92,22 +92,38 @@ print_model(XklConfigRegistry * config, const XklConfigItem * item, } static void +print_xci(XklConfigRegistry * config, const XklConfigItem * item, + gint indent) +{ + gchar **countries = (gchar **) g_object_get_data(G_OBJECT(item), + XCI_PROP_COUNTRY_LIST); + gint i; + printf("%*s[%s][%s][%s]\n", indent, "", item->name, + item->description, item->short_description); + if (countries != NULL) + for (i = 0; i < g_strv_length(countries); i++) + printf("%*s country: [%s]\n", indent, "", + countries[i]); +} + +static void print_variant(XklConfigRegistry * config, const XklConfigItem * item, gpointer data) { - printf(" [%s][%s][%s]\n", item->name, - item->description, item->short_description); + print_xci(config, item, 2); } + static void print_layout(XklConfigRegistry * config, const XklConfigItem * item, gpointer data) { - printf("[%s][%s][%s]\n", item->name, item->description, - item->short_description); + print_xci(config, item, 0); + xkl_config_registry_foreach_layout_variant(config, item->name, print_variant, data); } + int main(int argc, char *const argv[]) { |