[bijiben] provider: Port to G_DECLARE_DERIVABLE_TYPE



commit 7aa5f243fbdf983f744c8af7659c40c9a7568e60
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date:   Sun Nov 26 11:25:59 2017 +0530

    provider: Port to G_DECLARE_DERIVABLE_TYPE
    
    * Use G_DECLARE_DERIVABLE_TYPE to avoid boilerplate code
    * Adapt private member identifier names to suite with
      G_DECLARE_DERIVABLE_TYPE signature
    
    This is a part of effort to clean up codebase and make the code more
    maintainable.
    https://bugzilla.gnome.org/show_bug.cgi?id=789696

 src/libbiji/provider/biji-provider.c |   24 +++++++++++-------------
 src/libbiji/provider/biji-provider.h |   31 +++++--------------------------
 2 files changed, 16 insertions(+), 39 deletions(-)
---
diff --git a/src/libbiji/provider/biji-provider.c b/src/libbiji/provider/biji-provider.c
index 6d4fb40..d351040 100644
--- a/src/libbiji/provider/biji-provider.c
+++ b/src/libbiji/provider/biji-provider.c
@@ -52,13 +52,12 @@ static guint biji_provider_signals[PROVIDER_SIGNALS] = { 0 };
 static GParamSpec *properties[PROVIDER_PROP] = { NULL, };
 
 
-struct BijiProviderPrivate_
+typedef struct
 {
-  BijiManager        *manager;
-};
-
-G_DEFINE_TYPE (BijiProvider, biji_provider, G_TYPE_OBJECT)
+  BijiManager *manager;
+} BijiProviderPrivate;
 
+G_DEFINE_TYPE_WITH_PRIVATE (BijiProvider, biji_provider, G_TYPE_OBJECT)
 
 
 
@@ -88,7 +87,9 @@ biji_provider_helper_free          (BijiProviderHelper *helper)
 BijiManager *
 biji_provider_get_manager                (BijiProvider *provider)
 {
-  return provider->priv->manager;
+  BijiProviderPrivate *priv = biji_provider_get_instance_private (provider);
+
+  return priv->manager;
 }
 
 
@@ -123,8 +124,6 @@ biji_provider_finalize (GObject *object)
 static void
 biji_provider_init (BijiProvider *self)
 {
-  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BIJI_TYPE_PROVIDER, BijiProviderPrivate);
-  self->priv->manager = NULL;
 }
 
 
@@ -155,12 +154,12 @@ biji_provider_set_property (GObject      *object,
                             GParamSpec   *pspec)
 {
   BijiProvider *self = BIJI_PROVIDER (object);
-
+  BijiProviderPrivate *priv = biji_provider_get_instance_private (self);
 
   switch (property_id)
     {
     case PROP_BOOK:
-      self->priv->manager = g_value_dup_object (value);
+      priv->manager = g_value_dup_object (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -175,11 +174,12 @@ biji_provider_get_property (GObject    *object,
                             GParamSpec *pspec)
 {
   BijiProvider *self = BIJI_PROVIDER (object);
+  BijiProviderPrivate *priv = biji_provider_get_instance_private (self);
 
   switch (property_id)
     {
     case PROP_BOOK:
-      g_value_set_object (value, self->priv->manager);
+      g_value_set_object (value, priv->manager);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -232,6 +232,4 @@ biji_provider_class_init (BijiProviderClass *klass)
 
 
   g_object_class_install_properties (g_object_class, PROVIDER_PROP, properties);
-
-  g_type_class_add_private ((gpointer)klass, sizeof (BijiProviderPrivate));
 }
diff --git a/src/libbiji/provider/biji-provider.h b/src/libbiji/provider/biji-provider.h
index f1dc94d..5f9dfe1 100644
--- a/src/libbiji/provider/biji-provider.h
+++ b/src/libbiji/provider/biji-provider.h
@@ -21,22 +21,14 @@
 #include <glib-object.h>
 #include <glib/gi18n.h>  // translate providers type
 
-#include "../biji-info-set.h"
-#include "../biji-manager.h"
+#include "biji-info-set.h"
+#include "biji-manager.h"
 
 G_BEGIN_DECLS
 
+#define BIJI_TYPE_PROVIDER (biji_provider_get_type ())
 
-#define BIJI_TYPE_PROVIDER             (biji_provider_get_type ())
-#define BIJI_PROVIDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), BIJI_TYPE_PROVIDER, BijiProvider))
-#define BIJI_PROVIDER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), BIJI_TYPE_PROVIDER, 
BijiProviderClass))
-#define BIJI_IS_PROVIDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BIJI_TYPE_PROVIDER))
-#define BIJI_IS_PROVIDER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), BIJI_TYPE_PROVIDER))
-#define BIJI_PROVIDER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), BIJI_TYPE_PROVIDER, 
BijiProviderClass))
-
-typedef struct BijiProvider_         BijiProvider;
-typedef struct BijiProviderClass_    BijiProviderClass;
-typedef struct BijiProviderPrivate_  BijiProviderPrivate;
+G_DECLARE_DERIVABLE_TYPE (BijiProvider, biji_provider, BIJI, PROVIDER, GObject)
 
 
 typedef struct
@@ -52,15 +44,7 @@ typedef struct
 
 } BijiProviderInfo;
 
-
-struct BijiProvider_
-{
-  GObject parent;
-  BijiProviderPrivate *priv;
-};
-
-
-struct BijiProviderClass_
+struct _BijiProviderClass
 {
   GObjectClass parent_class;
 
@@ -139,11 +123,6 @@ typedef struct
   BijiItemsGroup group;
 } BijiProviderHelper;
 
-
-GType                      biji_provider_get_type             (void);
-
-
-
 BijiProviderHelper*        biji_provider_helper_new           (BijiProvider *provider,
                                                                BijiItemsGroup group);
 


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