[bijiben/wip/sadiq/modernize: 2/2] biji-timeout: Port to G_DECLARE_FINAL_TYPE



commit 0835eb8d2ff2bcd08f0c844e9a15b4fcaacd4607
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date:   Mon Oct 30 18:10:32 2017 +0530

    biji-timeout: Port to G_DECLARE_FINAL_TYPE
    
    G_DECLARE_FINAL_TYPE was introduced in glib 2.44.
    Using this can avoid lots of boilerplate code.
    
    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/biji-timeout.c |   38 +++++++++++++++-----------------------
 src/libbiji/biji-timeout.h |   29 ++++-------------------------
 2 files changed, 19 insertions(+), 48 deletions(-)
---
diff --git a/src/libbiji/biji-timeout.c b/src/libbiji/biji-timeout.c
index 1c59337..a08158e 100644
--- a/src/libbiji/biji-timeout.c
+++ b/src/libbiji/biji-timeout.c
@@ -1,6 +1,7 @@
 /* biji-timeout.c
  * Copyright (C) Pierre-Yves LUYTEN 2012 <py luyten fr>
- * 
+ * Copyright 2017 Mohammed Sadiq <sadiq sadiqpk org>
+ *
  * bijiben is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation, either version 3 of the License, or
@@ -31,25 +32,19 @@ enum {
 
 static guint biji_time_signals [BIJI_TIME_SIGNALS] = { 0 };
 
-/* Private */
-struct _BijiTimeoutPrivate
+struct _BijiTimeout
 {
+  GObject parent_instance;
+
   guint timeout_id;
   guint quit;
 };
 
-#define BIJI_TIMEOUT_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BIJI_TYPE_TIMEOUT, 
BijiTimeoutPrivate))
-
 G_DEFINE_TYPE (BijiTimeout, biji_timeout, G_TYPE_OBJECT);
 
 static void
 biji_timeout_init (BijiTimeout *self)
 {
-  BijiTimeoutPrivate *priv = BIJI_TIMEOUT_GET_PRIVATE(self);
-  self->priv = priv;
-
-  priv->timeout_id = 0;
-  priv->quit = 0;
 }
 
 static void
@@ -59,8 +54,8 @@ biji_timeout_finalize (GObject *object)
 
   biji_timeout_cancel (self);
 
-  if (self->priv->quit !=0)
-    g_signal_handler_disconnect (g_application_get_default(), self->priv->quit);
+  if (self->quit !=0 )
+    g_signal_handler_disconnect (g_application_get_default(), self->quit);
 
   G_OBJECT_CLASS (biji_timeout_parent_class)->finalize (object);
 }
@@ -80,8 +75,6 @@ biji_timeout_class_init (BijiTimeoutClass *klass)
                                                   g_cclosure_marshal_VOID__VOID,
                                                   G_TYPE_NONE,
                                                   0);
-
-  g_type_class_add_private (klass, sizeof (BijiTimeoutPrivate));
 }
 
 BijiTimeout * biji_timeout_new (void)
@@ -94,7 +87,7 @@ static gboolean
 biji_timeout_expired (BijiTimeout *self)
 {
   g_signal_emit (self, biji_time_signals[BIJI_TIME_OUT], 0);
-  self->priv->timeout_id = 0;
+  self->timeout_id = 0;
   return FALSE;
 }
 
@@ -110,11 +103,10 @@ biji_timeout_callback (BijiTimeout *self)
 void
 biji_timeout_cancel (BijiTimeout *self)
 {
-  if (self->priv->timeout_id != 0)
-  {
-    g_source_remove (self->priv->timeout_id);
-    self->priv->timeout_id = 0;
-  }
+  if (self->timeout_id != 0)
+    g_source_remove (self->timeout_id);
+
+  self->timeout_id = 0;
 }
 
 void
@@ -122,10 +114,10 @@ biji_timeout_reset (BijiTimeout *self, guint millis)
 {
   biji_timeout_cancel (self);
 
-  self->priv->timeout_id = g_timeout_add (
+  self->timeout_id = g_timeout_add (
        millis, (GSourceFunc) biji_timeout_callback, self);
 
   /* Ensure to perform timeout if main loop ends */
-  self->priv->quit = g_signal_connect_swapped (g_application_get_default(), "shutdown",
-                                               G_CALLBACK (biji_timeout_expired), self);
+  self->quit = g_signal_connect_swapped (g_application_get_default(), "shutdown",
+                                         G_CALLBACK (biji_timeout_expired), self);
 }
diff --git a/src/libbiji/biji-timeout.h b/src/libbiji/biji-timeout.h
index 9c1380b..edf7f24 100644
--- a/src/libbiji/biji-timeout.h
+++ b/src/libbiji/biji-timeout.h
@@ -1,6 +1,7 @@
 /* biji-timeout.h
  * Copyright (C) Pierre-Yves LUYTEN 2012 <py luyten fr>
- * 
+ * Copyright 2017 Mohammed Sadiq <sadiq sadiqpk org>
+ *
  * bijiben is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation, either version 3 of the License, or
@@ -22,31 +23,9 @@
 
 G_BEGIN_DECLS
 
-#define BIJI_TYPE_TIMEOUT             (biji_timeout_get_type ())
-#define BIJI_TIMEOUT(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), BIJI_TYPE_TIMEOUT, BijiTimeout))
-#define BIJI_TIMEOUT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), BIJI_TYPE_TIMEOUT, 
BijiTimeoutClass))
-#define BIJI_IS_TIMEOUT(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BIJI_TYPE_TIMEOUT))
-#define BIJI_IS_TIMEOUT_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), BIJI_TYPE_TIMEOUT))
-#define BIJI_TIMEOUT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), BIJI_TYPE_TIMEOUT, 
BijiTimeoutClass))
-
-typedef struct _BijiTimeoutClass BijiTimeoutClass;
-typedef struct _BijiTimeout BijiTimeout;
-typedef struct _BijiTimeoutPrivate BijiTimeoutPrivate;
-
-
-struct _BijiTimeoutClass
-{
-  GObjectClass parent_class;
-};
-
-struct _BijiTimeout
-{
-  GObject parent_instance;
-
-  BijiTimeoutPrivate *priv; 
-};
+#define BIJI_TYPE_TIMEOUT (biji_timeout_get_type ())
 
-GType biji_timeout_get_type (void) G_GNUC_CONST;
+G_DECLARE_FINAL_TYPE (BijiTimeout, biji_timeout, BIJI, TIMEOUT, GObject)
 
 BijiTimeout * biji_timeout_new (void);
 


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