summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Pablo Ugarte <juanpablougarte@gmail.com>2017-11-18 12:01:56 -0300
committerJuan Pablo Ugarte <juanpablougarte@gmail.com>2017-11-18 12:01:56 -0300
commite527b48cd00f9df87bf19f745f9058c3d6d8680f (patch)
tree0babe5c2c93f3764c6285637ac25e8ac3cbd249e
parent7f9cfb30062b1087b78693a3d96af76c7702946b (diff)
downloadglade-e527b48cd00f9df87bf19f745f9058c3d6d8680f.tar.gz
Use new utility function to parse boolean values.
Fixes bug 790452 "Glade saves invalid GtkBuilder XML"
-rw-r--r--gladeui/glade-property-class.c8
-rw-r--r--gladeui/glade-xml-utils.c48
2 files changed, 10 insertions, 46 deletions
diff --git a/gladeui/glade-property-class.c b/gladeui/glade-property-class.c
index beb95780..c82c6425 100644
--- a/gladeui/glade-property-class.c
+++ b/gladeui/glade-property-class.c
@@ -867,10 +867,12 @@ glade_property_class_make_gvalue_from_string (GladePropertyClass *property_class
g_value_set_uint (value, g_utf8_get_char (string));
else if (G_IS_PARAM_SPEC_BOOLEAN (property_class->pspec))
{
- if (strcmp (string, GLADE_TAG_TRUE) == 0)
- g_value_set_boolean (value, TRUE);
- else
+ gboolean val;
+ if (glade_utils_boolean_from_string (string, &val))
g_value_set_boolean (value, FALSE);
+ else
+ g_value_set_boolean (value, val);
+
}
else if (G_IS_PARAM_SPEC_OBJECT (property_class->pspec))
{
diff --git a/gladeui/glade-xml-utils.c b/gladeui/glade-xml-utils.c
index 283f14ce..10a30721 100644
--- a/gladeui/glade-xml-utils.c
+++ b/gladeui/glade-xml-utils.c
@@ -41,6 +41,7 @@
#include "glade-xml-utils.h"
#include "glade-catalog.h"
+#include "glade-utils.h"
#include <libxml/tree.h>
#include <libxml/parser.h>
@@ -307,12 +308,6 @@ glade_xml_set_property (xmlNodePtr node,
xmlSetProp (node, BAD_CAST (name), BAD_CAST (value));
}
-#define GLADE_TAG_TRUE "True"
-#define GLADE_TAG_FALSE "False"
-#define GLADE_TAG_TRUE2 "TRUE"
-#define GLADE_TAG_FALSE2 "FALSE"
-#define GLADE_TAG_TRUE3 "yes"
-#define GLADE_TAG_FALSE3 "no"
/*
* Get a String value for a node either carried as an attibute or as
* the content of a child.
@@ -330,21 +325,8 @@ glade_xml_get_boolean (GladeXmlNode *node_in,
if (value == NULL)
return _default;
- if (strcmp (value, GLADE_TAG_FALSE) == 0)
- ret = FALSE;
- else if (strcmp (value, GLADE_TAG_FALSE2) == 0)
- ret = FALSE;
- else if (strcmp (value, GLADE_TAG_FALSE3) == 0)
- ret = FALSE;
- else if (strcmp (value, GLADE_TAG_TRUE) == 0)
- ret = TRUE;
- else if (strcmp (value, GLADE_TAG_TRUE2) == 0)
- ret = TRUE;
- else if (strcmp (value, GLADE_TAG_TRUE3) == 0)
- ret = TRUE;
- else
+ if (glade_utils_boolean_from_string (value, &ret))
g_warning ("Boolean tag unrecognized *%s*\n", value);
-
g_free (value);
return ret;
@@ -367,21 +349,8 @@ glade_xml_get_property_boolean (GladeXmlNode *node_in,
if (value == NULL)
return _default;
- if (strcmp (value, GLADE_TAG_FALSE) == 0)
- ret = FALSE;
- else if (strcmp (value, GLADE_TAG_FALSE2) == 0)
- ret = FALSE;
- else if (strcmp (value, GLADE_TAG_FALSE3) == 0)
- ret = FALSE;
- else if (strcmp (value, GLADE_TAG_TRUE) == 0)
- ret = TRUE;
- else if (strcmp (value, GLADE_TAG_TRUE2) == 0)
- ret = TRUE;
- else if (strcmp (value, GLADE_TAG_TRUE3) == 0)
- ret = TRUE;
- else
+ if (glade_utils_boolean_from_string (value, &ret))
g_warning ("Boolean tag unrecognized *%s*\n", value);
-
g_free (value);
return ret;
@@ -442,18 +411,11 @@ glade_xml_node_set_property_boolean (GladeXmlNode *node_in,
xmlNodePtr node = (xmlNodePtr) node_in;
if (value)
- glade_xml_set_property (node, name, GLADE_TAG_TRUE);
+ glade_xml_set_property (node, name, "True");
else
- glade_xml_set_property (node, name, GLADE_TAG_FALSE);
+ glade_xml_set_property (node, name, "False");
}
-#undef GLADE_TAG_TRUE
-#undef GLADE_TAG_FALSE
-#undef GLADE_TAG_TRUE2
-#undef GLADE_TAG_FALSE2
-#undef GLADE_TAG_TRUE3
-#undef GLADE_TAG_FALSE3
-
gchar *
glade_xml_get_value_string_required (GladeXmlNode *node_in,
const gchar *name,