[evolution-data-server/wip/tintou/modern-gobject] [camel-object] use latest standards for GObject subclass definition
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/wip/tintou/modern-gobject] [camel-object] use latest standards for GObject subclass definition
- Date: Mon, 8 Oct 2018 13:37:38 +0000 (UTC)
commit bbf1c992de68e6d15008ff29fc35f804f07709db
Author: Corentin Noël <corentin elementary io>
Date: Mon Oct 8 15:36:10 2018 +0200
[camel-object] use latest standards for GObject subclass definition
src/camel/camel-object.c | 29 ++++++++++++-----------------
src/camel/camel-object.h | 31 ++++---------------------------
2 files changed, 16 insertions(+), 44 deletions(-)
---
diff --git a/src/camel/camel-object.c b/src/camel/camel-object.c
index 6f9003d61..d550663d6 100644
--- a/src/camel/camel-object.c
+++ b/src/camel/camel-object.c
@@ -32,20 +32,16 @@
#define d(x)
-#define CAMEL_OBJECT_GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE \
- ((obj), CAMEL_TYPE_OBJECT, CamelObjectPrivate))
-
-struct _CamelObjectPrivate {
+typedef struct {
gchar *state_filename;
-};
+} CamelObjectPrivate;
enum {
PROP_0,
PROP_STATE_FILENAME
};
-G_DEFINE_ABSTRACT_TYPE (CamelObject, camel_object, G_TYPE_OBJECT)
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (CamelObject, camel_object, G_TYPE_OBJECT)
/* State file for CamelObject data.
* Any later versions should only append data.
@@ -127,9 +123,7 @@ object_get_property (GObject *object,
static void
object_finalize (GObject *object)
{
- CamelObjectPrivate *priv;
-
- priv = CAMEL_OBJECT_GET_PRIVATE (object);
+ CamelObjectPrivate *priv = camel_object_get_instance_private (CAMEL_OBJECT (object));
g_free (priv->state_filename);
@@ -371,8 +365,6 @@ camel_object_class_init (CamelObjectClass *class)
{
GObjectClass *object_class;
- g_type_class_add_private (class, sizeof (CamelObjectPrivate));
-
object_class = G_OBJECT_CLASS (class);
object_class->set_property = object_set_property;
object_class->get_property = object_get_property;
@@ -403,7 +395,6 @@ camel_object_class_init (CamelObjectClass *class)
static void
camel_object_init (CamelObject *object)
{
- object->priv = CAMEL_OBJECT_GET_PRIVATE (object);
}
G_DEFINE_QUARK (camel-error-quark, camel_error)
@@ -513,9 +504,11 @@ camel_object_state_write (CamelObject *object)
const gchar *
camel_object_get_state_filename (CamelObject *object)
{
+ CamelObjectPrivate *priv = camel_object_get_instance_private (object);
+
g_return_val_if_fail (CAMEL_IS_OBJECT (object), NULL);
- return object->priv->state_filename;
+ return priv->state_filename;
}
/**
@@ -533,13 +526,15 @@ void
camel_object_set_state_filename (CamelObject *object,
const gchar *state_filename)
{
+ CamelObjectPrivate *priv = camel_object_get_instance_private (object);
+
g_return_if_fail (CAMEL_IS_OBJECT (object));
- if (g_strcmp0 (object->priv->state_filename, state_filename) == 0)
+ if (g_strcmp0 (priv->state_filename, state_filename) == 0)
return;
- g_free (object->priv->state_filename);
- object->priv->state_filename = g_strdup (state_filename);
+ g_free (priv->state_filename);
+ priv->state_filename = g_strdup (state_filename);
g_object_notify (G_OBJECT (object), "state-filename");
}
diff --git a/src/camel/camel-object.h b/src/camel/camel-object.h
index 6ba5756e0..ca9edb31c 100644
--- a/src/camel/camel-object.h
+++ b/src/camel/camel-object.h
@@ -31,24 +31,13 @@
#include <stdarg.h>
#include <gio/gio.h>
+G_BEGIN_DECLS
+
/* Standard GObject macros */
#define CAMEL_TYPE_OBJECT \
(camel_object_get_type ())
-#define CAMEL_OBJECT(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST \
- ((obj), CAMEL_TYPE_OBJECT, CamelObject))
-#define CAMEL_OBJECT_CLASS(cls) \
- (G_TYPE_CHECK_CLASS_CAST \
- ((cls), CAMEL_TYPE_OBJECT, CamelObjectClass))
-#define CAMEL_IS_OBJECT(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE \
- ((obj), CAMEL_TYPE_OBJECT))
-#define CAMEL_IS_OBJECT_CLASS(cls) \
- (G_TYPE_CHECK_CLASS_TYPE \
- ((cls), CAMEL_TYPE_OBJECT))
-#define CAMEL_OBJECT_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS \
- ((obj), CAMEL_TYPE_OBJECT, CamelObjectClass))
+
+G_DECLARE_DERIVABLE_TYPE(CamelObject, camel_object, CAMEL, OBJECT, GObject)
/**
* CAMEL_ERROR:
@@ -58,12 +47,6 @@
#define CAMEL_ERROR \
(camel_error_quark ())
-G_BEGIN_DECLS
-
-typedef struct _CamelObject CamelObject;
-typedef struct _CamelObjectClass CamelObjectClass;
-typedef struct _CamelObjectPrivate CamelObjectPrivate;
-
/**
* CamelParamFlags:
* @CAMEL_PARAM_PERSISTENT:
@@ -90,11 +73,6 @@ typedef enum {
CAMEL_ERROR_GENERIC /* lazy fallback error */
} CamelError;
-struct _CamelObject {
- GObject parent;
- CamelObjectPrivate *priv;
-};
-
struct _CamelObjectClass {
GObjectClass parent_class;
@@ -107,7 +85,6 @@ struct _CamelObjectClass {
gpointer reserved[20];
};
-GType camel_object_get_type (void);
GQuark camel_error_quark (void) G_GNUC_CONST;
gint camel_object_state_read (CamelObject *object);
gint camel_object_state_write (CamelObject *object);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]