[bijiben/wip/sadiq/modernize: 5/7] settings: Port to G_DECLARE_FINAL_TYPE



commit d20c7298dcbb69b33fc78595d31c4eebd6a2f220
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date:   Sun Nov 5 18:11:27 2017 +0530

    settings: Port to G_DECLARE_FINAL_TYPE
    
    * Use G_DECLARE_FINAL_TYPE to avoid boilerplate code
    * Don't use private members.
      This class isn't derivable. So there isn't any difference.
    
    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-settings.c |   57 +++++++++++++++++++++++----------------------------
 src/bjb-settings.h |   26 +---------------------
 2 files changed, 28 insertions(+), 55 deletions(-)
---
diff --git a/src/bjb-settings.c b/src/bjb-settings.c
index aed67b4..f00d9e7 100644
--- a/src/bjb-settings.c
+++ b/src/bjb-settings.c
@@ -24,8 +24,10 @@
 #include "bjb-settings-dialog.h"
 
 
-struct _BjbSettingsPrivate
+struct _BjbSettings
 {
+  GSettings parent_instance;
+
   /* Note edition settings */
   gboolean use_system_font;
   gchar *font;
@@ -52,16 +54,11 @@ enum
 
 static GParamSpec *properties[N_PROPERTIES] = { NULL, };
 
-
-#define BJB_SETTINGS_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BJB_TYPE_SETTINGS, BjbSettingsPrivate))
-
-G_DEFINE_TYPE (BjbSettings, bjb_settings, G_TYPE_SETTINGS);
+G_DEFINE_TYPE (BjbSettings, bjb_settings, G_TYPE_SETTINGS)
 
 static void
 bjb_settings_init (BjbSettings *object)
 {
-  object->priv =
-  G_TYPE_INSTANCE_GET_PRIVATE(object,BJB_TYPE_SETTINGS,BjbSettingsPrivate);
 }
 
 static void
@@ -70,11 +67,11 @@ bjb_settings_finalize (GObject *object)
   BjbSettings *self;
 
   self = BJB_SETTINGS (object);
-  g_object_unref (self->priv->system);
+  g_object_unref (self->system);
 
-  g_free (self->priv->font);
-  g_free (self->priv->color);
-  g_free (self->priv->primary);
+  g_free (self->font);
+  g_free (self->color);
+  g_free (self->primary);
 
   G_OBJECT_CLASS (bjb_settings_parent_class)->finalize (object);
 }
@@ -90,19 +87,19 @@ bjb_settings_get_property (GObject    *object,
   switch (prop_id)
   {
     case PROP_USE_SYSTEM_FONT:
-      g_value_set_boolean (value, settings->priv->use_system_font);
+      g_value_set_boolean (value, settings->use_system_font);
       break;
 
     case PROP_FONT:
-      g_value_set_string (value, settings->priv->font);
+      g_value_set_string (value, settings->font);
       break;
 
     case PROP_COLOR:
-      g_value_set_string (value, settings->priv->color);
+      g_value_set_string (value, settings->color);
       break;
 
     case PROP_PRIMARY:
-      g_value_set_string (value, settings->priv->primary);
+      g_value_set_string (value, settings->primary);
       break;
 
     default:
@@ -122,22 +119,22 @@ bjb_settings_set_property (GObject      *object,
   switch (prop_id)
   {
     case PROP_USE_SYSTEM_FONT:
-      settings->priv->use_system_font = g_value_get_boolean (value) ;
+      settings->use_system_font = g_value_get_boolean (value);
       break;
 
     case PROP_FONT:
-      g_free (settings->priv->font);
-      settings->priv->font = g_value_dup_string(value);
+      g_free (settings->font);
+      settings->font = g_value_dup_string (value);
       break;
 
     case PROP_COLOR:
-      g_free (settings->priv->color);
-      settings->priv->color = g_value_dup_string(value);
+      g_free (settings->color);
+      settings->color = g_value_dup_string (value);
       break;
 
     case PROP_PRIMARY:
-      g_free (settings->priv->primary);
-      settings->priv->primary = g_value_dup_string (value);
+      g_free (settings->primary);
+      settings->primary = g_value_dup_string (value);
       break;
 
     default:
@@ -157,7 +154,7 @@ bjb_settings_constructed (GObject *object)
 
   self = BJB_SETTINGS (object);
   settings = G_SETTINGS (object);
-  self->priv->system = g_settings_new ("org.gnome.desktop.interface");
+  self->system = g_settings_new ("org.gnome.desktop.interface");
 
 
   g_settings_bind  (settings, "use-system-font",
@@ -183,8 +180,6 @@ bjb_settings_class_init (BjbSettingsClass *klass)
 {
   GObjectClass* object_class = G_OBJECT_CLASS (klass);
 
-  g_type_class_add_private (klass, sizeof (BjbSettingsPrivate));
-
   object_class->constructed = bjb_settings_constructed;
   object_class->finalize = bjb_settings_finalize;
   object_class->get_property = bjb_settings_get_property;
@@ -242,42 +237,42 @@ bjb_settings_new (void)
 gboolean
 bjb_settings_use_system_font            (BjbSettings *settings)
 {
-  return settings->priv->use_system_font;
+  return settings->use_system_font;
 }
 
 
 void
 bjb_settings_set_use_system_font        (BjbSettings *settings, gboolean value)
 {
-  settings->priv->use_system_font = value;
+  settings->use_system_font = value;
 }
 
 
 const gchar *
 bjb_settings_get_default_font           (BjbSettings *settings)
 {
-  return settings->priv->font;
+  return settings->font;
 }
 
 
 const gchar *
 bjb_settings_get_default_color          (BjbSettings *settings)
 {
-  return settings->priv->color;
+  return settings->color;
 }
 
 
 const gchar *
 bjb_settings_get_default_location       (BjbSettings *settings)
 {
-  return settings->priv->primary;
+  return settings->primary;
 }
 
 
 gchar *
 bjb_settings_get_system_font            (BjbSettings *settings)
 {
-  return g_settings_get_string (settings->priv->system,
+  return g_settings_get_string (settings->system,
                                 "document-font-name");
 }
 
diff --git a/src/bjb-settings.h b/src/bjb-settings.h
index 58ace60..b433c5f 100644
--- a/src/bjb-settings.h
+++ b/src/bjb-settings.h
@@ -24,31 +24,9 @@
 
 G_BEGIN_DECLS
 
-#define BJB_TYPE_SETTINGS             (bjb_settings_get_type ())
-#define BJB_SETTINGS(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), BJB_TYPE_SETTINGS, BjbSettings))
-#define BJB_SETTINGS_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), BJB_TYPE_SETTINGS, 
BjbSettingsClass))
-#define BJB_IS_SETTINGS(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BJB_TYPE_SETTINGS))
-#define BJB_IS_SETTINGS_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), BJB_TYPE_SETTINGS))
-#define BJB_SETTINGS_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), BJB_TYPE_SETTINGS, 
BjbSettingsClass))
+#define BJB_TYPE_SETTINGS (bjb_settings_get_type ())
 
-typedef struct _BjbSettingsClass BjbSettingsClass;
-typedef struct _BjbSettings BjbSettings;
-
-typedef struct _BjbSettingsPrivate BjbSettingsPrivate;
-
-struct _BjbSettingsClass
-{
-  GSettingsClass parent_class;
-};
-
-struct _BjbSettings
-{
-  GSettings parent_instance;
-  BjbSettingsPrivate *priv;
-};
-
-
-GType             bjb_settings_get_type                   (void) G_GNUC_CONST;
+G_DECLARE_FINAL_TYPE (BjbSettings, bjb_settings, BJB, SETTINGS, GSettings)
 
 
 BjbSettings      *bjb_settings_new                        (void);


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