[gimp] app: get rid of manual object type registration
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: get rid of manual object type registration
- Date: Sat, 29 Jun 2019 14:42:41 +0000 (UTC)
commit e72a9d88a51c162684a61b8819a43d1190df87ca
Author: Michael Natterer <mitch gimp org>
Date: Sat Jun 29 16:41:41 2019 +0200
app: get rid of manual object type registration
and all deprecated use of private instance registration.
app/config/gimpgeglconfig.c | 47 ++++++++---------------------
app/core/gimpdata.c | 73 ++++++++++-----------------------------------
app/core/gimpdata.h | 7 +++--
app/core/gimpobject.c | 56 ++++++++++------------------------
app/widgets/gimppdbdialog.c | 47 +++++------------------------
5 files changed, 58 insertions(+), 172 deletions(-)
---
diff --git a/app/config/gimpgeglconfig.c b/app/config/gimpgeglconfig.c
index 9ccbfa9197..c876c939fc 100644
--- a/app/config/gimpgeglconfig.c
+++ b/app/config/gimpgeglconfig.c
@@ -55,9 +55,7 @@ enum
};
-static void gimp_gegl_config_class_init (GimpGeglConfigClass *klass);
-static void gimp_gegl_config_init (GimpGeglConfig *config,
- GimpGeglConfigClass *klass);
+static void gimp_gegl_config_constructed (GObject *object);
static void gimp_gegl_config_finalize (GObject *object);
static void gimp_gegl_config_set_property (GObject *object,
guint property_id,
@@ -69,36 +67,10 @@ static void gimp_gegl_config_get_property (GObject *object,
GParamSpec *pspec);
-static GObjectClass *parent_class = NULL;
+G_DEFINE_TYPE (GimpGeglConfig, gimp_gegl_config, G_TYPE_OBJECT)
+#define parent_class gimp_gegl_config_parent_class
-GType
-gimp_gegl_config_get_type (void)
-{
- static GType config_type = 0;
-
- if (! config_type)
- {
- const GTypeInfo config_info =
- {
- sizeof (GimpGeglConfigClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gimp_gegl_config_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GimpGeglConfig),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gimp_gegl_config_init,
- };
-
- config_type = g_type_register_static (G_TYPE_OBJECT,
- "GimpGeglConfig",
- &config_info, 0);
- }
-
- return config_type;
-}
static void
gimp_gegl_config_class_init (GimpGeglConfigClass *klass)
@@ -110,6 +82,7 @@ gimp_gegl_config_class_init (GimpGeglConfigClass *klass)
parent_class = g_type_class_peek_parent (klass);
+ object_class->constructed = gimp_gegl_config_constructed;
object_class->finalize = gimp_gegl_config_finalize;
object_class->set_property = gimp_gegl_config_set_property;
object_class->get_property = gimp_gegl_config_get_property;
@@ -182,10 +155,16 @@ gimp_gegl_config_class_init (GimpGeglConfigClass *klass)
}
static void
-gimp_gegl_config_init (GimpGeglConfig *config,
- GimpGeglConfigClass *klass)
+gimp_gegl_config_init (GimpGeglConfig *config)
{
- gimp_debug_add_instance (G_OBJECT (config), G_OBJECT_CLASS (klass));
+}
+
+static void
+gimp_gegl_config_constructed (GObject *object)
+{
+ G_OBJECT_CLASS (parent_class)->constructed (object);
+
+ gimp_debug_add_instance (object, G_OBJECT_GET_CLASS (object));
}
static void
diff --git a/app/core/gimpdata.c b/app/core/gimpdata.c
index d8ee11ba07..e4640f3970 100644
--- a/app/core/gimpdata.c
+++ b/app/core/gimpdata.c
@@ -52,8 +52,6 @@ enum
};
-typedef struct _GimpDataPrivate GimpDataPrivate;
-
struct _GimpDataPrivate
{
GFile *file;
@@ -73,16 +71,11 @@ struct _GimpDataPrivate
GList *tags;
};
-#define GIMP_DATA_GET_PRIVATE(data) \
- G_TYPE_INSTANCE_GET_PRIVATE (data, GIMP_TYPE_DATA, GimpDataPrivate)
+#define GIMP_DATA_GET_PRIVATE(obj) (((GimpData *) (obj))->priv)
-static void gimp_data_class_init (GimpDataClass *klass);
static void gimp_data_tagged_iface_init (GimpTaggedInterface *iface);
-static void gimp_data_init (GimpData *data,
- GimpDataClass *data_class);
-
static void gimp_data_constructed (GObject *object);
static void gimp_data_finalize (GObject *object);
static void gimp_data_set_property (GObject *object,
@@ -114,47 +107,15 @@ static gchar * gimp_data_get_identifier (GimpTagged *tagged);
static gchar * gimp_data_get_checksum (GimpTagged *tagged);
-static guint data_signals[LAST_SIGNAL] = { 0 };
-
-static GimpViewableClass *parent_class = NULL;
-
+G_DEFINE_TYPE_WITH_CODE (GimpData, gimp_data, GIMP_TYPE_VIEWABLE,
+ G_ADD_PRIVATE (GimpData)
+ G_IMPLEMENT_INTERFACE (GIMP_TYPE_TAGGED,
+ gimp_data_tagged_iface_init))
-GType
-gimp_data_get_type (void)
-{
- static GType data_type = 0;
+#define parent_class gimp_data_parent_class
- if (! data_type)
- {
- const GTypeInfo data_info =
- {
- sizeof (GimpDataClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gimp_data_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GimpData),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gimp_data_init,
- };
-
- const GInterfaceInfo tagged_info =
- {
- (GInterfaceInitFunc) gimp_data_tagged_iface_init,
- NULL, /* interface_finalize */
- NULL /* interface_data */
- };
-
- data_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
- "GimpData",
- &data_info, 0);
-
- g_type_add_interface_static (data_type, GIMP_TYPE_TAGGED, &tagged_info);
- }
+static guint data_signals[LAST_SIGNAL] = { 0 };
- return data_type;
-}
static void
gimp_data_class_init (GimpDataClass *klass)
@@ -212,8 +173,6 @@ gimp_data_class_init (GimpDataClass *klass)
NULL,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
-
- g_type_class_add_private (klass, sizeof (GimpDataPrivate));
}
static void
@@ -227,21 +186,16 @@ gimp_data_tagged_iface_init (GimpTaggedInterface *iface)
}
static void
-gimp_data_init (GimpData *data,
- GimpDataClass *data_class)
+gimp_data_init (GimpData *data)
{
- GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (data);
+ GimpDataPrivate *private = gimp_data_get_instance_private (data);
+
+ data->priv = private;
private->writable = TRUE;
private->deletable = TRUE;
private->dirty = TRUE;
- /* look at the passed class pointer, not at GIMP_DATA_GET_CLASS(data)
- * here, because the latter is always GimpDataClass itself
- */
- if (! data_class->save)
- private->writable = FALSE;
-
/* freeze the data object during construction */
gimp_data_freeze (data);
}
@@ -249,8 +203,13 @@ gimp_data_init (GimpData *data,
static void
gimp_data_constructed (GObject *object)
{
+ GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object);
+
G_OBJECT_CLASS (parent_class)->constructed (object);
+ if (! GIMP_DATA_GET_CLASS (object)->save)
+ private->writable = FALSE;
+
gimp_data_thaw (GIMP_DATA (object));
}
diff --git a/app/core/gimpdata.h b/app/core/gimpdata.h
index 0b6858b7dd..44cd26cbdb 100644
--- a/app/core/gimpdata.h
+++ b/app/core/gimpdata.h
@@ -42,11 +42,14 @@ typedef enum
#define GIMP_DATA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_DATA, GimpDataClass))
-typedef struct _GimpDataClass GimpDataClass;
+typedef struct _GimpDataPrivate GimpDataPrivate;
+typedef struct _GimpDataClass GimpDataClass;
struct _GimpData
{
- GimpViewable parent_instance;
+ GimpViewable parent_instance;
+
+ GimpDataPrivate *priv;
};
struct _GimpDataClass
diff --git a/app/core/gimpobject.c b/app/core/gimpobject.c
index 5dab4de51d..0f3baf72df 100644
--- a/app/core/gimpobject.c
+++ b/app/core/gimpobject.c
@@ -56,9 +56,7 @@ struct _GimpObjectPrivate
};
-static void gimp_object_class_init (GimpObjectClass *klass);
-static void gimp_object_init (GimpObject *object,
- GimpObjectClass *klass);
+static void gimp_object_constructed (GObject *object);
static void gimp_object_dispose (GObject *object);
static void gimp_object_finalize (GObject *object);
static void gimp_object_set_property (GObject *object,
@@ -74,38 +72,13 @@ static gint64 gimp_object_real_get_memsize (GimpObject *object,
static void gimp_object_name_normalize (GimpObject *object);
-static GObjectClass *parent_class = NULL;
+G_DEFINE_TYPE_WITH_CODE (GimpObject, gimp_object, G_TYPE_OBJECT,
+ G_ADD_PRIVATE (GimpObject))
-static guint object_signals[LAST_SIGNAL] = { 0 };
+#define parent_class gimp_object_parent_class
+static guint object_signals[LAST_SIGNAL] = { 0 };
-GType
-gimp_object_get_type (void)
-{
- static GType object_type = 0;
-
- if (! object_type)
- {
- const GTypeInfo object_info =
- {
- sizeof (GimpObjectClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gimp_object_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GimpObject),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gimp_object_init,
- };
-
- object_type = g_type_register_static (G_TYPE_OBJECT,
- "GimpObject",
- &object_info, 0);
- }
-
- return object_type;
-}
static void
gimp_object_class_init (GimpObjectClass *klass)
@@ -132,6 +105,7 @@ gimp_object_class_init (GimpObjectClass *klass)
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ object_class->constructed = gimp_object_constructed;
object_class->dispose = gimp_object_dispose;
object_class->finalize = gimp_object_finalize;
object_class->set_property = gimp_object_set_property;
@@ -147,21 +121,23 @@ gimp_object_class_init (GimpObjectClass *klass)
NULL,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
- g_type_class_add_private (klass,
- sizeof (GimpObjectPrivate));
}
static void
-gimp_object_init (GimpObject *object,
- GimpObjectClass *klass)
+gimp_object_init (GimpObject *object)
{
- object->p = G_TYPE_INSTANCE_GET_PRIVATE (object,
- GIMP_TYPE_OBJECT,
- GimpObjectPrivate);
+ object->p = gimp_object_get_instance_private (object);
+
object->p->name = NULL;
object->p->normalized = NULL;
+}
+
+static void
+gimp_object_constructed (GObject *object)
+{
+ G_OBJECT_CLASS (parent_class)->constructed (object);
- gimp_debug_add_instance (G_OBJECT (object), G_OBJECT_CLASS (klass));
+ gimp_debug_add_instance (object, G_OBJECT_GET_CLASS (object));
}
static void
diff --git a/app/widgets/gimppdbdialog.c b/app/widgets/gimppdbdialog.c
index 4b99d1f0cd..a9bdd45f3c 100644
--- a/app/widgets/gimppdbdialog.c
+++ b/app/widgets/gimppdbdialog.c
@@ -54,10 +54,6 @@ enum
};
-static void gimp_pdb_dialog_class_init (GimpPdbDialogClass *klass);
-static void gimp_pdb_dialog_init (GimpPdbDialog *dialog,
- GimpPdbDialogClass *klass);
-
static void gimp_pdb_dialog_constructed (GObject *object);
static void gimp_pdb_dialog_dispose (GObject *object);
static void gimp_pdb_dialog_set_property (GObject *object,
@@ -76,37 +72,10 @@ static void gimp_pdb_dialog_plug_in_closed (GimpPlugInManager *manager,
GimpPdbDialog *dialog);
-static GimpDialogClass *parent_class = NULL;
-
+G_DEFINE_ABSTRACT_TYPE (GimpPdbDialog, gimp_pdb_dialog, GIMP_TYPE_DIALOG)
-GType
-gimp_pdb_dialog_get_type (void)
-{
- static GType dialog_type = 0;
+#define parent_class gimp_pdb_dialog_parent_class
- if (! dialog_type)
- {
- const GTypeInfo dialog_info =
- {
- sizeof (GimpPdbDialogClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gimp_pdb_dialog_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GimpPdbDialog),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gimp_pdb_dialog_init,
- };
-
- dialog_type = g_type_register_static (GIMP_TYPE_DIALOG,
- "GimpPdbDialog",
- &dialog_info,
- G_TYPE_FLAG_ABSTRACT);
- }
-
- return dialog_type;
-}
static void
gimp_pdb_dialog_class_init (GimpPdbDialogClass *klass)
@@ -166,11 +135,8 @@ gimp_pdb_dialog_class_init (GimpPdbDialogClass *klass)
}
static void
-gimp_pdb_dialog_init (GimpPdbDialog *dialog,
- GimpPdbDialogClass *klass)
+gimp_pdb_dialog_init (GimpPdbDialog *dialog)
{
- klass->dialogs = g_list_prepend (klass->dialogs, dialog);
-
gtk_dialog_add_button (GTK_DIALOG (dialog),
_("_Close"), GTK_RESPONSE_CLOSE);
}
@@ -178,11 +144,14 @@ gimp_pdb_dialog_init (GimpPdbDialog *dialog,
static void
gimp_pdb_dialog_constructed (GObject *object)
{
- GimpPdbDialog *dialog = GIMP_PDB_DIALOG (object);
- const gchar *signal_name;
+ GimpPdbDialog *dialog = GIMP_PDB_DIALOG (object);
+ GimpPdbDialogClass *klass = GIMP_PDB_DIALOG_GET_CLASS (object);
+ const gchar *signal_name;
G_OBJECT_CLASS (parent_class)->constructed (object);
+ klass->dialogs = g_list_prepend (klass->dialogs, dialog);
+
gimp_assert (GIMP_IS_PDB (dialog->pdb));
gimp_assert (GIMP_IS_CONTEXT (dialog->caller_context));
gimp_assert (g_type_is_a (dialog->select_type, GIMP_TYPE_OBJECT));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]