[gnome-dictionary/ebassi/for-master: 1/4] Use modern instance private data for GObject types
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-dictionary/ebassi/for-master: 1/4] Use modern instance private data for GObject types
- Date: Mon, 21 Sep 2020 18:53:33 +0000 (UTC)
commit 604a7d49223fd8a13b46d777206334ae75655ea8
Author: Emmanuele Bassi <ebassi gnome org>
Date: Sat Sep 19 15:05:29 2020 +0100
Use modern instance private data for GObject types
Stop using the old g_type_class_add_private() and related macros.
libgdict/gdict-client-context.c | 18 ++++++++--------
libgdict/gdict-database-chooser.c | 13 ++++--------
libgdict/gdict-source-loader.c | 44 ++++++++-------------------------------
libgdict/gdict-source.c | 32 +++++++---------------------
src/gdict-sidebar.c | 10 ++-------
5 files changed, 31 insertions(+), 86 deletions(-)
---
diff --git a/libgdict/gdict-client-context.c b/libgdict/gdict-client-context.c
index 6875366..a91f349 100644
--- a/libgdict/gdict-client-context.c
+++ b/libgdict/gdict-client-context.c
@@ -157,7 +157,6 @@ enum
static guint gdict_client_context_signals[LAST_SIGNAL] = { 0 };
-#define GDICT_CLIENT_CONTEXT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),
GDICT_TYPE_CLIENT_CONTEXT, GdictClientContextPrivate))
struct _GdictClientContextPrivate
{
#ifdef ENABLE_IPV6
@@ -193,8 +192,9 @@ static void gdict_client_context_iface_init (GdictContextIface *iface);
G_DEFINE_TYPE_WITH_CODE (GdictClientContext,
gdict_client_context,
G_TYPE_OBJECT,
+ G_ADD_PRIVATE (GdictClientContext)
G_IMPLEMENT_INTERFACE (GDICT_TYPE_CONTEXT,
- gdict_client_context_iface_init));
+ gdict_client_context_iface_init))
/* GObject methods */
static void gdict_client_context_set_property (GObject *object,
@@ -366,8 +366,6 @@ gdict_client_context_class_init (GdictClientContextClass *klass)
klass->connected = gdict_client_context_real_connected;
klass->disconnected = gdict_client_context_real_disconnected;
-
- g_type_class_add_private (gobject_class, sizeof (GdictClientContextPrivate));
}
static void
@@ -375,7 +373,7 @@ gdict_client_context_init (GdictClientContext *context)
{
GdictClientContextPrivate *priv;
- priv = GDICT_CLIENT_CONTEXT_GET_PRIVATE (context);
+ priv = gdict_client_context_get_instance_private (context);
context->priv = priv;
priv->hostname = NULL;
@@ -405,8 +403,9 @@ gdict_client_context_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- GdictClientContextPrivate *priv = GDICT_CLIENT_CONTEXT_GET_PRIVATE (object);
-
+ GdictClientContext *self = GDICT_CLIENT_CONTEXT (object);
+ GdictClientContextPrivate *priv = gdict_client_context_get_instance_private (self);
+
switch (prop_id)
{
case PROP_HOSTNAME:
@@ -438,8 +437,9 @@ gdict_client_context_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GdictClientContextPrivate *priv = GDICT_CLIENT_CONTEXT_GET_PRIVATE (object);
-
+ GdictClientContext *self = GDICT_CLIENT_CONTEXT (object);
+ GdictClientContextPrivate *priv = gdict_client_context_get_instance_private (self);
+
switch (prop_id)
{
case PROP_STATUS:
diff --git a/libgdict/gdict-database-chooser.c b/libgdict/gdict-database-chooser.c
index 2c4d5ab..e652844 100644
--- a/libgdict/gdict-database-chooser.c
+++ b/libgdict/gdict-database-chooser.c
@@ -47,9 +47,6 @@
#include "gdict-enum-types.h"
#include "gdict-marshal.h"
-#define GDICT_DATABASE_CHOOSER_GET_PRIVATE(obj) \
-(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDICT_TYPE_DATABASE_CHOOSER, GdictDatabaseChooserPrivate))
-
struct _GdictDatabaseChooserPrivate
{
GtkListStore *store;
@@ -108,9 +105,9 @@ enum
static guint db_chooser_signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (GdictDatabaseChooser,
- gdict_database_chooser,
- GTK_TYPE_BOX)
+G_DEFINE_TYPE_WITH_PRIVATE (GdictDatabaseChooser,
+ gdict_database_chooser,
+ GTK_TYPE_BOX)
static void
set_gdict_context (GdictDatabaseChooser *chooser,
@@ -472,8 +469,6 @@ gdict_database_chooser_class_init (GdictDatabaseChooserClass *klass)
NULL, NULL,
gdict_marshal_VOID__VOID,
G_TYPE_NONE, 0);
-
- g_type_class_add_private (gobject_class, sizeof (GdictDatabaseChooserPrivate));
}
static void
@@ -481,7 +476,7 @@ gdict_database_chooser_init (GdictDatabaseChooser *chooser)
{
GdictDatabaseChooserPrivate *priv;
- chooser->priv = priv = GDICT_DATABASE_CHOOSER_GET_PRIVATE (chooser);
+ chooser->priv = priv = gdict_database_chooser_get_instance_private (chooser);
gtk_orientable_set_orientation (GTK_ORIENTABLE (chooser), GTK_ORIENTATION_VERTICAL);
diff --git a/libgdict/gdict-source-loader.c b/libgdict/gdict-source-loader.c
index 1dd4740..4ba5414 100644
--- a/libgdict/gdict-source-loader.c
+++ b/libgdict/gdict-source-loader.c
@@ -24,9 +24,7 @@
* files inside a set of paths and return a #GdictSource using its name.
*/
-#ifdef HAVE_CONFIG_H
#include "config.h"
-#endif
#include <stdio.h>
#include <stdlib.h>
@@ -47,8 +45,6 @@
#define GDICT_SOURCE_FILE_SUFFIX ".desktop"
-#define GDICT_SOURCE_LOADER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),
GDICT_TYPE_SOURCE_LOADER, GdictSourceLoaderPrivate))
-
struct _GdictSourceLoaderPrivate
{
GSList *paths;
@@ -76,38 +72,18 @@ enum
static guint loader_signals[LAST_SIGNAL] = { 0 };
-
-
-G_DEFINE_TYPE (GdictSourceLoader, gdict_source_loader, G_TYPE_OBJECT);
-
+G_DEFINE_TYPE_WITH_PRIVATE (GdictSourceLoader, gdict_source_loader, G_TYPE_OBJECT)
static void
gdict_source_loader_finalize (GObject *object)
{
- GdictSourceLoaderPrivate *priv = GDICT_SOURCE_LOADER_GET_PRIVATE (object);
-
- if (priv->paths)
- {
- g_slist_foreach (priv->paths,
- (GFunc) g_free,
- NULL);
- g_slist_free (priv->paths);
-
- priv->paths = NULL;
- }
-
- if (priv->sources_by_name)
- g_hash_table_destroy (priv->sources_by_name);
-
- if (priv->sources)
- {
- g_slist_foreach (priv->sources,
- (GFunc) g_object_unref,
- NULL);
- g_slist_free (priv->sources);
-
- priv->sources = NULL;
- }
+ GdictSourceLoader *self = GDICT_SOURCE_LOADER (object);
+ GdictSourceLoaderPrivate *priv = gdict_source_loader_get_instance_private (self);
+
+ g_clear_pointer (&priv->sources_by_name, g_hash_table_unref);
+
+ g_slist_free_full (priv->paths, g_free);
+ g_slist_free_full (priv->sources, g_object_unref);
G_OBJECT_CLASS (gdict_source_loader_parent_class)->finalize (object);
}
@@ -203,8 +179,6 @@ gdict_source_loader_class_init (GdictSourceLoaderClass *klass)
gdict_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GDICT_TYPE_SOURCE);
-
- g_type_class_add_private (klass, sizeof (GdictSourceLoaderPrivate));
}
static void
@@ -212,7 +186,7 @@ gdict_source_loader_init (GdictSourceLoader *loader)
{
GdictSourceLoaderPrivate *priv;
- priv = GDICT_SOURCE_LOADER_GET_PRIVATE (loader);
+ priv = gdict_source_loader_get_instance_private (loader);
loader->priv = priv;
priv->paths = NULL;
diff --git a/libgdict/gdict-source.c b/libgdict/gdict-source.c
index d6f8b62..aff079f 100644
--- a/libgdict/gdict-source.c
+++ b/libgdict/gdict-source.c
@@ -61,9 +61,6 @@
#define SOURCE_KEY_HOSTNAME "Hostname"
#define SOURCE_KEY_PORT "Port"
-
-#define GDICT_SOURCE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDICT_TYPE_SOURCE,
GdictSourcePrivate))
-
struct _GdictSourcePrivate
{
gchar *filename;
@@ -118,8 +115,7 @@ gdict_source_error_quark (void)
}
-G_DEFINE_TYPE (GdictSource, gdict_source, G_TYPE_OBJECT);
-
+G_DEFINE_TYPE_WITH_PRIVATE (GdictSource, gdict_source, G_TYPE_OBJECT)
static void
@@ -197,21 +193,17 @@ gdict_source_get_property (GObject *object,
static void
gdict_source_finalize (GObject *object)
{
- GdictSourcePrivate *priv = GDICT_SOURCE_GET_PRIVATE (object);
+ GdictSource *self = GDICT_SOURCE (object);
+ GdictSourcePrivate *priv = gdict_source_get_instance_private (self);
g_free (priv->filename);
-
- if (priv->keyfile)
- g_key_file_free (priv->keyfile);
-
g_free (priv->name);
g_free (priv->description);
-
g_free (priv->database);
g_free (priv->strategy);
- if (priv->context)
- g_object_unref (priv->context);
+ g_clear_pointer (&priv->keyfile, g_key_file_unref);
+ g_clear_object (&priv->context);
G_OBJECT_CLASS (gdict_source_parent_class)->finalize (object);
}
@@ -338,8 +330,6 @@ gdict_source_class_init (GdictSourceClass *klass)
"The GdictContext bound to this source",
GDICT_TYPE_CONTEXT,
G_PARAM_READABLE));
-
- g_type_class_add_private (klass, sizeof (GdictSourcePrivate));
}
static void
@@ -347,20 +337,12 @@ gdict_source_init (GdictSource *source)
{
GdictSourcePrivate *priv;
- priv = GDICT_SOURCE_GET_PRIVATE (source);
+ priv = gdict_source_get_instance_private (source);
source->priv = priv;
- priv->filename = NULL;
priv->keyfile = g_key_file_new ();
-
- priv->name = NULL;
- priv->description = NULL;
- priv->editable = TRUE;
- priv->database = NULL;
- priv->strategy = NULL;
priv->transport = GDICT_SOURCE_TRANSPORT_INVALID;
-
- priv->context = NULL;
+ priv->editable = TRUE;
}
/**
diff --git a/src/gdict-sidebar.c b/src/gdict-sidebar.c
index bccb89d..8a535d6 100644
--- a/src/gdict-sidebar.c
+++ b/src/gdict-sidebar.c
@@ -20,9 +20,7 @@
* Copyright (C) 2004 Red Hat, Inc.
*/
-#ifdef HAVE_CONFIG_H
#include "config.h"
-#endif
#include <stdio.h>
#include <stdlib.h>
@@ -46,8 +44,6 @@ typedef struct
GtkWidget *menu_item;
} SidebarPage;
-#define GDICT_SIDEBAR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDICT_TYPE_SIDEBAR,
GdictSidebarPrivate))
-
struct _GdictSidebarPrivate
{
GHashTable *pages_by_id;
@@ -72,7 +68,7 @@ enum
static guint sidebar_signals[LAST_SIGNAL] = { 0 };
static GQuark sidebar_page_id_quark = 0;
-G_DEFINE_TYPE (GdictSidebar, gdict_sidebar, GTK_TYPE_BOX);
+G_DEFINE_TYPE_WITH_PRIVATE (GdictSidebar, gdict_sidebar, GTK_TYPE_BOX)
SidebarPage *
sidebar_page_new (const gchar *id,
@@ -300,8 +296,6 @@ gdict_sidebar_class_init (GdictSidebarClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- g_type_class_add_private (gobject_class, sizeof (GdictSidebarPrivate));
-
sidebar_page_id_quark = g_quark_from_static_string ("gdict-sidebar-page-id");
gobject_class->finalize = gdict_sidebar_finalize;
@@ -335,7 +329,7 @@ gdict_sidebar_init (GdictSidebar *sidebar)
GtkWidget *close_button;
GtkWidget *arrow;
- sidebar->priv = priv = GDICT_SIDEBAR_GET_PRIVATE (sidebar);
+ sidebar->priv = priv = gdict_sidebar_get_instance_private (sidebar);
gtk_orientable_set_orientation (GTK_ORIENTABLE (sidebar),
GTK_ORIENTATION_VERTICAL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]