[glade/tintou/type-func: 3/3] gladeui: Ensure that we write the "type-func" property when a get-type-function is defined in the ca



commit 2155cca80218ca6ba0dc522fb67ba0ef097826ea
Author: Corentin Noël <corentin noel collabora com>
Date:   Mon Sep 16 10:10:28 2019 +0200

    gladeui: Ensure that we write the "type-func" property when a get-type-function is defined in the catalog

 gladeui/glade-widget-adaptor.c | 31 +++++++++++++++++++++++++++++--
 gladeui/glade-widget-adaptor.h |  2 +-
 gladeui/glade-widget.c         |  5 +++++
 gladeui/glade-xml-utils.c      |  9 +++++++++
 gladeui/glade-xml-utils.h      |  1 +
 5 files changed, 45 insertions(+), 3 deletions(-)
---
diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c
index 04d935d0..a6a38e2c 100644
--- a/gladeui/glade-widget-adaptor.c
+++ b/gladeui/glade-widget-adaptor.c
@@ -58,6 +58,9 @@ typedef struct
 {
   GType        type;                /* GType of the widget */
   GType        real_type;
+  gchar       *type_func;           /* The get_type () function name if the default
+                                     * euristic to define one doesn't work
+                                     */
 
   gchar       *name;                /* Name of the widget, for example GtkButton */
   gchar       *generic_name;        /* Used to generate names of new widgets, for
@@ -762,6 +765,7 @@ glade_widget_adaptor_finalize (GObject *object)
 
   g_clear_object (&priv->cursor);
 
+  g_clear_pointer (&priv->type_func, g_free);
   g_clear_pointer (&priv->name, g_free);
   g_clear_pointer (&priv->generic_name, g_free);
   g_clear_pointer (&priv->title, g_free);
@@ -2755,7 +2759,7 @@ glade_widget_adaptor_from_catalog (GladeCatalog *catalog,
   GladeWidgetAdaptorPrivate *priv;
   GladeWidgetAdaptor *adaptor = NULL;
   gchar *name, *generic_name, *icon_name, *adaptor_icon_name, *adaptor_name,
-      *func_name, *template;
+      *func_name = NULL, *template;
   gchar *title, *translated_title, *parent_name;
   GType object_type, adaptor_type, parent_type;
   gchar *missing_icon = NULL;
@@ -2799,7 +2803,6 @@ glade_widget_adaptor_from_catalog (GladeCatalog *catalog,
                                            GLADE_TAG_GET_TYPE_FUNCTION)) != NULL)
     {
       object_type = glade_util_get_type_from_name (func_name, TRUE);
-      g_free (func_name);
     }
   else if ((template =
             glade_xml_get_property_string (class_node,
@@ -2841,6 +2844,8 @@ glade_widget_adaptor_from_catalog (GladeCatalog *catalog,
       g_warning ("Adaptor class for '%s' already defined",
                  g_type_name (object_type));
       g_free (name);
+      if (func_name)
+        g_free (func_name);
       return NULL;
     }
 
@@ -2865,6 +2870,8 @@ glade_widget_adaptor_from_catalog (GladeCatalog *catalog,
                  (adaptor_name) ? adaptor_name : "");
       g_free (adaptor_name);
       g_free (name);
+      if (func_name)
+        g_free (func_name);
       return NULL;
     }
 
@@ -2906,6 +2913,7 @@ glade_widget_adaptor_from_catalog (GladeCatalog *catalog,
                           "icon-name", adaptor_icon_name, NULL);
   priv = glade_widget_adaptor_get_instance_private (adaptor);
   priv->missing_icon = missing_icon;
+  priv->type_func = g_steal_pointer (&func_name);
 
   g_free (generic_name);
   g_free (icon_name);
@@ -4598,3 +4606,22 @@ glade_widget_adaptor_create_editable (GladeWidgetAdaptor *adaptor,
   return GLADE_WIDGET_ADAPTOR_GET_CLASS
       (adaptor)->create_editable (adaptor, type);
 }
+
+/**
+ * glade_widget_adaptor_get_type_func:
+ * @adaptor: A #GladeWidgetAdaptor
+ *
+ * Get the _get_type () function name if it is set, a %NULL value means that the
+ * default heuristic for getting the GType is enough for both Glade and GtkBuilder.
+ *
+ * Returns: (nullable): The _get_type () function name or %NULL if none is set
+ */
+const gchar *
+glade_widget_adaptor_get_type_func (GladeWidgetAdaptor *adaptor)
+{
+  GladeWidgetAdaptorPrivate *priv = glade_widget_adaptor_get_instance_private (adaptor);
+
+  g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
+
+  return priv->type_func;
+}
diff --git a/gladeui/glade-widget-adaptor.h b/gladeui/glade-widget-adaptor.h
index fad75988..276c48b3 100644
--- a/gladeui/glade-widget-adaptor.h
+++ b/gladeui/glade-widget-adaptor.h
@@ -898,7 +898,7 @@ GladeSignalDef       *glade_widget_adaptor_get_signal_def     (GladeWidgetAdapto
 GladeWidgetAdaptor   *glade_widget_adaptor_get_parent_adaptor (GladeWidgetAdaptor *adaptor);
 
 gboolean              glade_widget_adaptor_has_internal_children (GladeWidgetAdaptor *adaptor);
-
+const gchar          *glade_widget_adaptor_get_type_func      (GladeWidgetAdaptor *adaptor);
 G_END_DECLS
 
 #endif /* _GLADE_WIDGET_ADAPTOR_H_ */
diff --git a/gladeui/glade-widget.c b/gladeui/glade-widget.c
index 9e7718b9..af6893ed 100644
--- a/gladeui/glade-widget.c
+++ b/gladeui/glade-widget.c
@@ -4400,11 +4400,16 @@ glade_widget_write (GladeWidget     *widget,
     }
   else
     {
+      const gchar *type_func = NULL;
       widget_node = glade_xml_node_new (context, GLADE_XML_TAG_WIDGET);
       glade_xml_node_set_property_string (widget_node,
                                           GLADE_XML_TAG_CLASS,
                                           glade_widget_adaptor_get_name (widget->priv->adaptor));
 
+      glade_xml_node_set_property_string (widget_node,
+                                          GLADE_XML_TAG_TYPE_FUNC,
+                                          glade_widget_adaptor_get_type_func (widget->priv->adaptor));
+
       /* Conditionally omit the ID in the output if the name is 'unset'
        */
       if (glade_widget_has_name (widget) || glade_project_writing_preview (widget->priv->project))
diff --git a/gladeui/glade-xml-utils.c b/gladeui/glade-xml-utils.c
index c08df9e7..04165389 100644
--- a/gladeui/glade-xml-utils.c
+++ b/gladeui/glade-xml-utils.c
@@ -449,6 +449,15 @@ glade_xml_get_property_string (GladeXmlNode *node_in, const gchar *name)
   return glade_xml_get_property (node, name);
 }
 
+/**
+ * glade_xml_node_set_property_string:
+ * @node_in: a #GladeXmlNode
+ * @name: the name of the property to set
+ * @string: (nullable): the string value of the property to set
+ *
+ * Set a property as a string in the @node_in. Note that %NULL @string value
+ * Are simply ignored and not written in the XML.
+ */
 void
 glade_xml_node_set_property_string (GladeXmlNode *node_in,
                                     const gchar  *name,
diff --git a/gladeui/glade-xml-utils.h b/gladeui/glade-xml-utils.h
index a19a7d1c..59329ae5 100644
--- a/gladeui/glade-xml-utils.h
+++ b/gladeui/glade-xml-utils.h
@@ -45,6 +45,7 @@ typedef struct _GladeProject        GladeProject;
 #define GLADE_XML_TAG_LIB                         "lib"
 #define GLADE_XML_TAG_PROPERTY                    "property"
 #define GLADE_XML_TAG_CLASS                       "class"
+#define GLADE_XML_TAG_TYPE_FUNC                   "type-func"
 #define GLADE_XML_TAG_ID                          "id"
 #define GLADE_XML_TAG_SIGNAL                      "signal"
 #define GLADE_XML_TAG_HANDLER                     "handler"


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