[libgda] gda-tree-mgr-label: ported to G_DECLARE/G_DEFINE



commit 06da04a6d0a3279c37c46e3ba78810b8c5719947
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Sep 19 15:18:37 2018 -0500

    gda-tree-mgr-label: ported to G_DECLARE/G_DEFINE

 libgda/gda-decl.h           |  3 --
 libgda/gda-tree-mgr-label.c | 87 ++++++++++++---------------------------------
 libgda/gda-tree-mgr-label.h | 18 ++--------
 libgda/gda-tree-node.h      |  1 +
 libgda/gda-tree.h           |  1 +
 5 files changed, 27 insertions(+), 83 deletions(-)
---
diff --git a/libgda/gda-decl.h b/libgda/gda-decl.h
index cc218b15f..eafc0d461 100644
--- a/libgda/gda-decl.h
+++ b/libgda/gda-decl.h
@@ -73,9 +73,6 @@ typedef struct _GdaMetaStructClass   GdaMetaStructClass;
  */
 typedef gboolean (*GdaSqlReservedKeywordsFunc) (const gchar *word);
 
-typedef struct _GdaTreeManager GdaTreeManager;
-typedef struct _GdaTreeManagerClass GdaTreeManagerClass;
-
 typedef struct _GdaTreeNode GdaTreeNode;
 typedef struct _GdaTreeNodeClass GdaTreeNodeClass;
 
diff --git a/libgda/gda-tree-mgr-label.c b/libgda/gda-tree-mgr-label.c
index 53f394be1..006bce211 100644
--- a/libgda/gda-tree-mgr-label.c
+++ b/libgda/gda-tree-mgr-label.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2009 - 2013 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2010 David King <davidk openismus com>
+ * Copyright (C) 2018 Daniel Espinosa <esodan gmail com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -24,12 +25,12 @@
 #include "gda-tree-mgr-label.h"
 #include "gda-tree-node.h"
 
-struct _GdaTreeMgrLabelPriv {
+typedef struct {
        gchar         *label; /* imposed upon construction */
-};
+} GdaTreeMgrLabelPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GdaTreeMgrLabel, gda_tree_mgr_label, GDA_TYPE_TREE_MANAGER)
 
-static void gda_tree_mgr_label_class_init (GdaTreeMgrLabelClass *klass);
-static void gda_tree_mgr_label_init       (GdaTreeMgrLabel *tmgr1, GdaTreeMgrLabelClass *klass);
 static void gda_tree_mgr_label_dispose    (GObject *object);
 static void gda_tree_mgr_label_set_property (GObject *object,
                                              guint param_id,
@@ -61,8 +62,6 @@ gda_tree_mgr_label_class_init (GdaTreeMgrLabelClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-       parent_class = g_type_class_peek_parent (klass);
-
        /* virtual methods */
        ((GdaTreeManagerClass*) klass)->update_children = gda_tree_mgr_label_update_children;
 
@@ -79,11 +78,7 @@ gda_tree_mgr_label_class_init (GdaTreeMgrLabelClass *klass)
 }
 
 static void
-gda_tree_mgr_label_init (GdaTreeMgrLabel *mgr, G_GNUC_UNUSED GdaTreeMgrLabelClass *klass)
-{
-       g_return_if_fail (GDA_IS_TREE_MGR_LABEL (mgr));
-       mgr->priv = g_new0 (GdaTreeMgrLabelPriv, 1);
-}
+gda_tree_mgr_label_init (GdaTreeMgrLabel *mgr) {}
 
 static void
 gda_tree_mgr_label_dispose (GObject *object)
@@ -91,69 +86,33 @@ gda_tree_mgr_label_dispose (GObject *object)
        GdaTreeMgrLabel *mgr = (GdaTreeMgrLabel *) object;
 
        g_return_if_fail (GDA_IS_TREE_MGR_LABEL (mgr));
+       GdaTreeMgrLabelPrivate *priv = gda_tree_mgr_label_get_instance_private (mgr);
 
-       if (mgr->priv) {
-               g_free (mgr->priv->label);
-               g_free (mgr->priv);
-               mgr->priv = NULL;
-       }
+       g_free (priv->label);
+       priv->label = NULL;
 
        /* chain to parent class */
        parent_class->dispose (object);
 }
 
-/**
- * gda_tree_mgr_label_get_type:
- *
- * Since: 4.2
- */
-GType
-gda_tree_mgr_label_get_type (void)
-{
-        static GType type = 0;
-
-        if (G_UNLIKELY (type == 0)) {
-                static GMutex registering;
-                static const GTypeInfo info = {
-                        sizeof (GdaTreeMgrLabelClass),
-                        (GBaseInitFunc) NULL,
-                        (GBaseFinalizeFunc) NULL,
-                        (GClassInitFunc) gda_tree_mgr_label_class_init,
-                        NULL,
-                        NULL,
-                        sizeof (GdaTreeMgrLabel),
-                        0,
-                        (GInstanceInitFunc) gda_tree_mgr_label_init,
-                       0
-                };
-
-                g_mutex_lock (&registering);
-                if (type == 0)
-                        type = g_type_register_static (GDA_TYPE_TREE_MANAGER, "GdaTreeMgrLabel", &info, 0);
-                g_mutex_unlock (&registering);
-        }
-        return type;
-}
-
 static void
 gda_tree_mgr_label_set_property (GObject *object,
                                   guint param_id,
                                   const GValue *value,
                                   GParamSpec *pspec)
 {
-        GdaTreeMgrLabel *mgr;
+       GdaTreeMgrLabel *mgr;
 
-        mgr = GDA_TREE_MGR_LABEL (object);
-        if (mgr->priv) {
-                switch (param_id) {
+       mgr = GDA_TREE_MGR_LABEL (object);
+       GdaTreeMgrLabelPrivate *priv = gda_tree_mgr_label_get_instance_private (mgr);
+       switch (param_id) {
                case PROP_LABEL:
-                       mgr->priv->label = g_value_dup_string (value);
+                       priv->label = g_value_dup_string (value);
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                        break;
-                }
-        }
+       }
 }
 
 static void
@@ -162,19 +121,18 @@ gda_tree_mgr_label_get_property (GObject *object,
                                   GValue *value,
                                   GParamSpec *pspec)
 {
-        GdaTreeMgrLabel *mgr;
+       GdaTreeMgrLabel *mgr;
 
-        mgr = GDA_TREE_MGR_LABEL (object);
-        if (mgr->priv) {
-                switch (param_id) {
+       mgr = GDA_TREE_MGR_LABEL (object);
+       GdaTreeMgrLabelPrivate *priv = gda_tree_mgr_label_get_instance_private (mgr);
+       switch (param_id) {
                case PROP_LABEL:
-                       g_value_set_string (value, mgr->priv->label);
+                       g_value_set_string (value, priv->label);
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                        break;
-                }
-        }
+       }
 }
 
 /**
@@ -208,7 +166,8 @@ gda_tree_mgr_label_update_children (GdaTreeManager *manager, GdaTreeNode *node,
 
        GdaTreeMgrLabel *mgr = GDA_TREE_MGR_LABEL (manager);
        GdaTreeNode *snode;
+       GdaTreeMgrLabelPrivate *priv = gda_tree_mgr_label_get_instance_private (mgr);
 
-       snode = gda_tree_manager_create_node (manager, node, mgr->priv->label ? mgr->priv->label : _("No 
name"));
+       snode = gda_tree_manager_create_node (manager, node, priv->label ? priv->label : _("No name"));
        return g_slist_prepend (NULL, snode);
 }
diff --git a/libgda/gda-tree-mgr-label.h b/libgda/gda-tree-mgr-label.h
index 047ae8412..c1364ed8c 100644
--- a/libgda/gda-tree-mgr-label.h
+++ b/libgda/gda-tree-mgr-label.h
@@ -26,23 +26,10 @@
 G_BEGIN_DECLS
 
 #define GDA_TYPE_TREE_MGR_LABEL            (gda_tree_mgr_label_get_type())
-#define GDA_TREE_MGR_LABEL(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_TREE_MGR_LABEL, 
GdaTreeMgrLabel))
-#define GDA_TREE_MGR_LABEL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_TREE_MGR_LABEL, 
GdaTreeMgrLabelClass))
-#define GDA_IS_TREE_MGR_LABEL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE(obj, GDA_TYPE_TREE_MGR_LABEL))
-#define GDA_IS_TREE_MGR_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GDA_TYPE_TREE_MGR_LABEL))
-#define GDA_TREE_MGR_LABEL_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), GDA_TYPE_TREE_MGR_LABEL, 
GdaTreeMgrLabelClass))
-
-typedef struct _GdaTreeMgrLabel GdaTreeMgrLabel;
-typedef struct _GdaTreeMgrLabelPriv GdaTreeMgrLabelPriv;
-typedef struct _GdaTreeMgrLabelClass GdaTreeMgrLabelClass;
-
-struct _GdaTreeMgrLabel {
-       GdaTreeManager        object;
-       GdaTreeMgrLabelPriv *priv;
-};
+G_DECLARE_DERIVABLE_TYPE (GdaTreeMgrLabel, gda_tree_mgr_label, GDA, TREE_MGR_LABEL, GdaTreeManager)
 
 struct _GdaTreeMgrLabelClass {
-       GdaTreeManagerClass   object_class;
+  GdaTreeManagerClass parent_class;
 };
 
 /**
@@ -56,7 +43,6 @@ struct _GdaTreeMgrLabelClass {
  * is useful to create "sections" in a #GdaTree hierarchy.
  */
 
-GType              gda_tree_mgr_label_get_type                 (void) G_GNUC_CONST;
 GdaTreeManager*    gda_tree_mgr_label_new                      (const gchar *label);
 
 G_END_DECLS
diff --git a/libgda/gda-tree-node.h b/libgda/gda-tree-node.h
index a7e9d4085..5e0650c9f 100644
--- a/libgda/gda-tree-node.h
+++ b/libgda/gda-tree-node.h
@@ -21,6 +21,7 @@
 #define __GDA_TREE_NODE_H__
 
 #include <glib-object.h>
+#include <libgda/gda-tree-manager.h>
 #include "gda-decl.h"
 
 G_BEGIN_DECLS
diff --git a/libgda/gda-tree.h b/libgda/gda-tree.h
index ca29231ca..96b180245 100644
--- a/libgda/gda-tree.h
+++ b/libgda/gda-tree.h
@@ -22,6 +22,7 @@
 
 #include <glib-object.h>
 #include <stdio.h>
+#include <libgda/gda-tree-manager.h>
 #include "gda-decl.h"
 
 G_BEGIN_DECLS


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