[bijiben/wip/sadiq/modernize] biji-item: Port to G_DECLARE_DERIVABLE_TYPE



commit 8d95f8f2d1675daee96193407b740b2d03357508
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date:   Tue Nov 7 10:50:05 2017 +0530

    biji-item: 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
    * Adapt bjb-controller to avoid warnings with non-const
      variables
    
    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/bjb-controller.c    |    8 ++++----
 src/libbiji/biji-item.c |   25 ++++++++++++-------------
 src/libbiji/biji-item.h |   23 +++--------------------
 3 files changed, 19 insertions(+), 37 deletions(-)
---
diff --git a/src/bjb-controller.c b/src/bjb-controller.c
index 938381c..84bd245 100644
--- a/src/bjb-controller.c
+++ b/src/bjb-controller.c
@@ -340,8 +340,8 @@ bjb_controller_add_item_if_needed (BjbController *self,
 static gint
 most_recent_item_first (gconstpointer a, gconstpointer b)
 {
-  BijiItem *one = BIJI_ITEM (a);
-  BijiItem *other = BIJI_ITEM (b);
+  const BijiItem *one = a;
+  const BijiItem *other = b;
   glong result = 0;
 
   /* Always sort notebooks before notes */
@@ -360,8 +360,8 @@ most_recent_item_first (gconstpointer a, gconstpointer b)
    * two notebooks, use the most recent cookbook */
   else
   {
-    result =   biji_item_get_mtime (other)
-             - biji_item_get_mtime (one);
+    result = biji_item_get_mtime ((gpointer) other)
+      - biji_item_get_mtime ((gpointer) one);
   }
 
   return result;
diff --git a/src/libbiji/biji-item.c b/src/libbiji/biji-item.c
index 9189e04..a96bfb2 100644
--- a/src/libbiji/biji-item.c
+++ b/src/libbiji/biji-item.c
@@ -42,14 +42,14 @@ enum {
 static guint biji_item_signals [BIJI_ITEM_SIGNALS] = { 0 };
 
 
-struct BijiItemPrivate_
+typedef struct
 {
   BijiManager *manager;
-};
+} BijiItemPrivate;
 
 static void biji_item_finalize (GObject *object);
 
-G_DEFINE_TYPE (BijiItem, biji_item, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (BijiItem, biji_item, G_TYPE_OBJECT)
 
 
 static void
@@ -58,13 +58,12 @@ biji_item_set_property (GObject      *object,
                         const GValue *value,
                         GParamSpec   *pspec)
 {
-  BijiItem *self = BIJI_ITEM (object);
-
+  BijiItemPrivate *priv = biji_item_get_instance_private (BIJI_ITEM (object));
 
   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);
@@ -79,12 +78,12 @@ biji_item_get_property (GObject    *object,
                         GValue     *value,
                         GParamSpec *pspec)
 {
-  BijiItem *self = BIJI_ITEM (object);
+  BijiItemPrivate *priv = biji_item_get_instance_private (BIJI_ITEM (object));
 
   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);
@@ -146,8 +145,6 @@ biji_item_class_init (BijiItemClass *klass)
                   G_TYPE_NONE,
                   1,
                   G_TYPE_STRING);
-
-  g_type_class_add_private ((gpointer)klass, sizeof (BijiItemPrivate));
 }
 
 
@@ -163,8 +160,6 @@ biji_item_finalize (GObject *object)
 static void
 biji_item_init (BijiItem *self)
 {
-  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, BIJI_TYPE_ITEM, BijiItemPrivate);
-  self->priv->manager = NULL;
 }
 
 const gchar *
@@ -185,9 +180,13 @@ biji_item_get_uuid          (BijiItem *item)
 gpointer
 biji_item_get_manager     (BijiItem *item)
 {
+  BijiItemPrivate *priv;
+
   g_return_val_if_fail (BIJI_IS_ITEM (item), NULL);
 
-  return item->priv->manager;
+  priv = biji_item_get_instance_private (item);
+
+  return priv->manager;
 }
 
 
diff --git a/src/libbiji/biji-item.h b/src/libbiji/biji-item.h
index 64aa5a5..8cca85c 100644
--- a/src/libbiji/biji-item.h
+++ b/src/libbiji/biji-item.h
@@ -27,16 +27,9 @@
 
 G_BEGIN_DECLS
 
-#define BIJI_TYPE_ITEM             (biji_item_get_type ())
-#define BIJI_ITEM(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), BIJI_TYPE_ITEM, BijiItem))
-#define BIJI_ITEM_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), BIJI_TYPE_ITEM, BijiItemClass))
-#define BIJI_IS_ITEM(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BIJI_TYPE_ITEM))
-#define BIJI_IS_ITEM_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), BIJI_TYPE_ITEM))
-#define BIJI_ITEM_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), BIJI_TYPE_ITEM, BijiItemClass))
+#define BIJI_TYPE_ITEM (biji_item_get_type ())
 
-typedef struct BijiItem_         BijiItem;
-typedef struct BijiItemClass_    BijiItemClass;
-typedef struct BijiItemPrivate_  BijiItemPrivate;
+G_DECLARE_DERIVABLE_TYPE (BijiItem, biji_item, BIJI, ITEM, GObject)
 
 /* Icon */
 #define BIJI_ICON_WIDTH 200
@@ -47,14 +40,7 @@ typedef struct BijiItemPrivate_  BijiItemPrivate;
 #define BIJI_EMBLEM_WIDTH BIJI_ICON_WIDTH / 6
 #define BIJI_EMBLEM_HEIGHT BIJI_EMBLEM_WIDTH
 
-struct BijiItem_
-{
-  GObject parent;
-
-  BijiItemPrivate *priv;
-};
-
-struct BijiItemClass_
+struct _BijiItemClass
 {
   GObjectClass parent_class;
 
@@ -87,9 +73,6 @@ struct BijiItemClass_
  * but i just need common stuff */
 
 
-GType biji_item_get_type (void);
-
-
 /*  - note uuid is a location (as in GFile)
  *  - notebook uuid is urn                */
 


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