[glade/glade-3-20] Use new utility function to parse boolean values.



commit ea1bd81f6ec45f9f09a0b0121467df6189be6cd4
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Sat Nov 18 12:01:56 2017 -0300

    Use new utility function to parse boolean values.
    
    Fixes bug 790452 "Glade saves invalid GtkBuilder XML"

 gladeui/glade-property-class.c |    8 ++++--
 gladeui/glade-xml-utils.c      |   48 ++++-----------------------------------
 2 files changed, 10 insertions(+), 46 deletions(-)
---
diff --git a/gladeui/glade-property-class.c b/gladeui/glade-property-class.c
index beb9578..c82c642 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 283f14c..10a3072 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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]