summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Udaltsov <svu@gnome.org>2009-06-24 11:14:43 +0000
committerSergey Udaltsov <svu@gnome.org>2009-06-24 11:14:43 +0000
commitdf596d227ae8a14184186dd313dfa6d001411ec4 (patch)
treece0e567626fee8b4adcf4bcad98f5b930bf05bbb
parentf86e28f5dbfbf5e7cc014819ffc23d5528d726ef (diff)
Avoiding duplicated config items from main and extras
-rw-r--r--ChangeLog5
-rw-r--r--libxklavier/xklavier_config.c120
-rw-r--r--libxklavier/xklavier_config_iso.c42
3 files changed, 111 insertions, 56 deletions
diff --git a/ChangeLog b/ChangeLog
index 31f282f..aa2bd5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-06-24 svu
+
+ * libxklavier/xklavier_config.c, libxklavier/xklavier_config_iso.c: avoiding
+ duplicated config items (in main and extras)
+
2009-06-23 svu
* configure.in, libxklavier/xkl_config_registry.h,
diff --git a/libxklavier/xklavier_config.c b/libxklavier/xklavier_config.c
index ad0af8f..f829cef 100644
--- a/libxklavier/xklavier_config.c
+++ b/libxklavier/xklavier_config.c
@@ -167,7 +167,8 @@ xkl_read_config_item(XklConfigRegistry * config, gint doc_index,
return FALSE;
if (doc_index > 0)
- g_object_set_data(G_OBJECT(item), XCI_PROP_EXTRA_ITEM, GINT_TO_POINTER(TRUE));
+ g_object_set_data(G_OBJECT(item), XCI_PROP_EXTRA_ITEM,
+ GINT_TO_POINTER(TRUE));
ptr = ptr->children;
@@ -253,6 +254,7 @@ xkl_read_config_item(XklConfigRegistry * config, gint doc_index,
static void
xkl_config_registry_foreach_in_nodeset(XklConfigRegistry * config,
+ GSList ** processed_ids,
gint doc_index, xmlNodeSetPtr nodes,
ConfigItemProcessFunc func,
gpointer data)
@@ -263,8 +265,18 @@ xkl_config_registry_foreach_in_nodeset(XklConfigRegistry * config,
XklConfigItem *ci = xkl_config_item_new();
for (i = nodes->nodeNr; --i >= 0;) {
if (xkl_read_config_item
- (config, doc_index, *pnode, ci))
- func(config, ci, data);
+ (config, doc_index, *pnode, ci)) {
+ if (g_slist_find_custom
+ (*processed_ids, ci->name,
+ (GCompareFunc) g_ascii_strcasecmp) ==
+ NULL) {
+ func(config, ci, data);
+ *processed_ids =
+ g_slist_append(*processed_ids,
+ g_strdup
+ (ci->name));
+ }
+ }
pnode++;
}
@@ -280,14 +292,15 @@ xkl_config_registry_foreach_in_xpath(XklConfigRegistry * config,
gpointer data)
{
xmlXPathObjectPtr xpath_obj;
- gint i;
+ gint di;
+ GSList *processed_ids = NULL;
if (!xkl_config_registry_is_initialized(config))
return;
- for (i = XKL_NUMBER_OF_REGISTRY_DOCS; --i >= 0;) {
+ for (di = 0; di < XKL_NUMBER_OF_REGISTRY_DOCS; di++) {
xmlXPathContextPtr xmlctxt =
- xkl_config_registry_priv(config, xpath_contexts[i]);
+ xkl_config_registry_priv(config, xpath_contexts[di]);
if (xmlctxt == NULL)
continue;
@@ -295,11 +308,14 @@ xkl_config_registry_foreach_in_xpath(XklConfigRegistry * config,
if (xpath_obj == NULL)
continue;
- xkl_config_registry_foreach_in_nodeset(config, i,
+ xkl_config_registry_foreach_in_nodeset(config,
+ &processed_ids, di,
xpath_obj->nodesetval,
func, data);
xmlXPathFreeObject(xpath_obj);
}
+ g_slist_foreach(processed_ids, (GFunc) g_free, NULL);
+ g_slist_free(processed_ids);
}
void
@@ -314,15 +330,17 @@ xkl_config_registry_foreach_in_xpath_with_param(XklConfigRegistry
{
char xpath_expr[1024];
xmlXPathObjectPtr xpath_obj;
- gint i;
+ gint di;
+ GSList *processed_ids = NULL;
if (!xkl_config_registry_is_initialized(config))
return;
+
g_snprintf(xpath_expr, sizeof xpath_expr, format, value);
- for (i = XKL_NUMBER_OF_REGISTRY_DOCS; --i >= 0;) {
+ for (di = 0; di < XKL_NUMBER_OF_REGISTRY_DOCS; di++) {
xmlXPathContextPtr xmlctxt =
- xkl_config_registry_priv(config, xpath_contexts[i]);
+ xkl_config_registry_priv(config, xpath_contexts[di]);
if (xmlctxt == NULL)
continue;
@@ -331,11 +349,14 @@ xkl_config_registry_foreach_in_xpath_with_param(XklConfigRegistry
if (xpath_obj == NULL)
continue;
- xkl_config_registry_foreach_in_nodeset(config, i,
+ xkl_config_registry_foreach_in_nodeset(config,
+ &processed_ids, di,
xpath_obj->nodesetval,
func, data);
xmlXPathFreeObject(xpath_obj);
}
+ g_slist_foreach(processed_ids, (GFunc) g_free, NULL);
+ g_slist_free(processed_ids);
}
static gboolean
@@ -349,7 +370,7 @@ xkl_config_registry_find_object(XklConfigRegistry * config,
xmlNodeSetPtr nodes;
gboolean rv = FALSE;
gchar xpath_expr[1024];
- gint i;
+ gint di;
if (!xkl_config_registry_is_initialized(config))
return FALSE;
@@ -357,9 +378,9 @@ xkl_config_registry_find_object(XklConfigRegistry * config,
g_snprintf(xpath_expr, sizeof xpath_expr, format, arg1,
pitem->name);
- for (i = XKL_NUMBER_OF_REGISTRY_DOCS; --i >= 0;) {
+ for (di = 0; di < XKL_NUMBER_OF_REGISTRY_DOCS; di++) {
xmlXPathContextPtr xmlctxt =
- xkl_config_registry_priv(config, xpath_contexts[i]);
+ xkl_config_registry_priv(config, xpath_contexts[di]);
if (xmlctxt == NULL)
continue;
@@ -371,7 +392,7 @@ xkl_config_registry_find_object(XklConfigRegistry * config,
nodes = xpath_obj->nodesetval;
if (nodes != NULL && nodes->nodeTab != NULL
&& nodes->nodeNr > 0) {
- rv = xkl_read_config_item(config, i,
+ rv = xkl_read_config_item(config, di,
nodes->nodeTab[0],
pitem);
if (pnode != NULL) {
@@ -612,21 +633,22 @@ xkl_config_registry_load_helper(XklConfigRegistry * config,
void
xkl_config_registry_free(XklConfigRegistry * config)
{
- gint i;
if (xkl_config_registry_is_initialized(config)) {
- for (i = XKL_NUMBER_OF_REGISTRY_DOCS; --i >= 0;) {
+ gint di;
+ for (di = 0; di < XKL_NUMBER_OF_REGISTRY_DOCS; di++) {
xmlXPathContextPtr xmlctxt =
xkl_config_registry_priv(config,
- xpath_contexts[i]);
+ xpath_contexts[di]);
if (xmlctxt == NULL)
continue;
xmlXPathFreeContext(xmlctxt);
xmlFreeDoc(xkl_config_registry_priv
- (config, docs[i]));
+ (config, docs[di]));
xkl_config_registry_priv(config,
- xpath_contexts[i]) = NULL;
- xkl_config_registry_priv(config, docs[i]) = NULL;
+ xpath_contexts[di]) =
+ NULL;
+ xkl_config_registry_priv(config, docs[di]) = NULL;
}
}
@@ -672,18 +694,19 @@ xkl_config_registry_foreach_option_group(XklConfigRegistry *
func, gpointer data)
{
xmlXPathObjectPtr xpath_obj;
- gint i, j;
+ gint di, j;
+ GSList *processed_ids = NULL;
if (!xkl_config_registry_is_initialized(config))
return;
- for (i = XKL_NUMBER_OF_REGISTRY_DOCS; --i >= 0;) {
+ for (di = 0; di < XKL_NUMBER_OF_REGISTRY_DOCS; di++) {
xmlNodeSetPtr nodes;
xmlNodePtr *pnode;
XklConfigItem *ci;
xmlXPathContextPtr xmlctxt =
- xkl_config_registry_priv(config, xpath_contexts[i]);
+ xkl_config_registry_priv(config, xpath_contexts[di]);
if (xmlctxt == NULL)
continue;
@@ -697,26 +720,35 @@ xkl_config_registry_foreach_option_group(XklConfigRegistry *
ci = xkl_config_item_new();
for (j = nodes->nodeNr; --j >= 0;) {
- if (xkl_read_config_item(config, i, *pnode, ci)) {
- gboolean allow_multisel = TRUE;
- xmlChar *sallow_multisel =
- xmlGetProp(*pnode,
- (unsigned char *)
- XCI_PROP_ALLOW_MULTIPLE_SELECTION);
- if (sallow_multisel != NULL) {
- allow_multisel =
- !g_ascii_strcasecmp
- ("true", (char *)
- sallow_multisel);
- xmlFree(sallow_multisel);
- g_object_set_data(G_OBJECT
- (ci),
- XCI_PROP_ALLOW_MULTIPLE_SELECTION,
- GINT_TO_POINTER
- (allow_multisel));
+ if (xkl_read_config_item(config, di, *pnode, ci)) {
+ if (g_slist_find_custom
+ (processed_ids, ci->name,
+ (GCompareFunc) g_ascii_strcasecmp) ==
+ NULL) {
+ gboolean allow_multisel = TRUE;
+ xmlChar *sallow_multisel =
+ xmlGetProp(*pnode,
+ (unsigned char *)
+ XCI_PROP_ALLOW_MULTIPLE_SELECTION);
+ if (sallow_multisel != NULL) {
+ allow_multisel =
+ !g_ascii_strcasecmp
+ ("true", (char *)
+ sallow_multisel);
+ xmlFree(sallow_multisel);
+ g_object_set_data(G_OBJECT
+ (ci),
+ XCI_PROP_ALLOW_MULTIPLE_SELECTION,
+ GINT_TO_POINTER
+ (allow_multisel));
+ }
+
+ func(config, ci, data);
+ processed_ids =
+ g_slist_append(processed_ids,
+ g_strdup
+ (ci->name));
}
-
- func(config, ci, data);
}
pnode++;
@@ -724,6 +756,8 @@ xkl_config_registry_foreach_option_group(XklConfigRegistry *
g_object_unref(G_OBJECT(ci));
xmlXPathFreeObject(xpath_obj);
}
+ g_slist_foreach(processed_ids, (GFunc) g_free, NULL);
+ g_slist_free(processed_ids);
}
void
diff --git a/libxklavier/xklavier_config_iso.c b/libxklavier/xklavier_config_iso.c
index dfbb7a7..e9911a9 100644
--- a/libxklavier/xklavier_config_iso.c
+++ b/libxklavier/xklavier_config_iso.c
@@ -211,7 +211,7 @@ xkl_config_registry_foreach_iso_code(XklConfigRegistry * config,
const gchar **xpath_expr;
gpointer key, value;
XklConfigItem *ci;
- gint i;
+ gint di;
if (!xkl_config_registry_is_initialized(config))
return;
@@ -219,14 +219,14 @@ xkl_config_registry_foreach_iso_code(XklConfigRegistry * config,
code_pairs = g_hash_table_new(g_str_hash, g_str_equal);
for (xpath_expr = xpath_exprs; *xpath_expr; xpath_expr++) {
- for (i = XKL_NUMBER_OF_REGISTRY_DOCS; --i >= 0;) {
+ for (di = 0; di < XKL_NUMBER_OF_REGISTRY_DOCS; di++) {
gint ni;
xmlNodePtr *node;
xmlNodeSetPtr nodes;
xmlXPathContextPtr xmlctxt =
xkl_config_registry_priv(config,
- xpath_contexts[i]);
+ xpath_contexts[di]);
if (xmlctxt == NULL)
continue;
@@ -333,7 +333,6 @@ xkl_config_registry_foreach_iso_variant(XklConfigRegistry *
const gchar **xpath_expr;
const gboolean *is_low_id = should_code_be_lowered1;
gchar *low_iso_code;
- gint i;
if (!xkl_config_registry_is_initialized(config))
return;
@@ -344,10 +343,13 @@ xkl_config_registry_foreach_iso_variant(XklConfigRegistry *
xpath_expr++, is_low_id++) {
const gchar *aic = *is_low_id ? low_iso_code : iso_code;
gchar *xpe = g_strdup_printf(*xpath_expr, aic);
- for (i = XKL_NUMBER_OF_REGISTRY_DOCS; --i >= 0;) {
+ gint di;
+ GSList *processed_ids = NULL;
+
+ for (di = 0; di < XKL_NUMBER_OF_REGISTRY_DOCS; di++) {
xmlXPathContextPtr xmlctxt =
xkl_config_registry_priv(config,
- xpath_contexts[i]);
+ xpath_contexts[di]);
if (xmlctxt == NULL)
continue;
@@ -363,9 +365,22 @@ xkl_config_registry_foreach_iso_variant(XklConfigRegistry *
XklConfigItem *ci = xkl_config_item_new();
for (ni = nodes->nodeNr; --ni >= 0;) {
if (xkl_read_config_item
- (config, i, *node, ci))
- func(config, ci, NULL,
- data);
+ (config, di, *node, ci)) {
+ if (g_slist_find_custom
+ (processed_ids,
+ ci->name,
+ (GCompareFunc)
+ g_ascii_strcasecmp) ==
+ NULL) {
+ func(config, ci,
+ NULL, data);
+ processed_ids =
+ g_slist_append
+ (processed_ids,
+ g_strdup
+ (ci->name));
+ }
+ }
node++;
}
g_object_unref(G_OBJECT(ci));
@@ -380,10 +395,11 @@ xkl_config_registry_foreach_iso_variant(XklConfigRegistry *
xpath_expr++, is_low_id++) {
const gchar *aic = *is_low_id ? low_iso_code : iso_code;
gchar *xpe = g_strdup_printf(*xpath_expr, aic);
- for (i = XKL_NUMBER_OF_REGISTRY_DOCS; --i >= 0;) {
+ gint di;
+ for (di = 0; di < XKL_NUMBER_OF_REGISTRY_DOCS; di++) {
xmlXPathContextPtr xmlctxt =
xkl_config_registry_priv(config,
- xpath_contexts[i]);
+ xpath_contexts[di]);
if (xmlctxt == NULL)
continue;
@@ -400,9 +416,9 @@ xkl_config_registry_foreach_iso_variant(XklConfigRegistry *
XklConfigItem *pci = xkl_config_item_new();
for (ni = nodes->nodeNr; --ni >= 0;) {
if (xkl_read_config_item
- (config, i, *node, ci) &&
+ (config, di, *node, ci) &&
xkl_read_config_item
- (config, i,
+ (config, di,
(*node)->parent->parent, pci))
func(config, pci, ci,
data);