[nautilus] progress-info-manager: port away from manual decls



commit 0a84cdf8c692bd63a1f11e96fd68564507cd4ca8
Author: Horia Ion <horiapaulion gmail com>
Date:   Wed Mar 29 20:59:03 2017 +0300

    progress-info-manager: port away from manual decls
    
    This patch reduces the number of macros used to define the type,
    by means of the macro G_DECLARE*, and improves the readability of code.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780697

 src/nautilus-progress-info-manager.c |   45 ++++++++++++++++-----------------
 src/nautilus-progress-info-manager.h |   28 +--------------------
 2 files changed, 23 insertions(+), 50 deletions(-)
---
diff --git a/src/nautilus-progress-info-manager.c b/src/nautilus-progress-info-manager.c
index e4be799..57950a1 100644
--- a/src/nautilus-progress-info-manager.c
+++ b/src/nautilus-progress-info-manager.c
@@ -24,8 +24,10 @@
 
 #include "nautilus-progress-info-manager.h"
 
-struct _NautilusProgressInfoManagerPriv
+struct _NautilusProgressInfoManager
 {
+    GObject parent_instance;
+
     GList *progress_infos;
     GList *current_viewers;
 };
@@ -53,16 +55,16 @@ nautilus_progress_info_manager_finalize (GObject *obj)
     GList *l;
     NautilusProgressInfoManager *self = NAUTILUS_PROGRESS_INFO_MANAGER (obj);
 
-    if (self->priv->progress_infos != NULL)
+    if (self->progress_infos != NULL)
     {
-        g_list_free_full (self->priv->progress_infos, g_object_unref);
+        g_list_free_full (self->progress_infos, g_object_unref);
     }
 
-    for (l = self->priv->current_viewers; l != NULL; l = l->next)
+    for (l = self->current_viewers; l != NULL; l = l->next)
     {
         g_object_weak_unref (l->data, (GWeakNotify) remove_viewer, self);
     }
-    g_list_free (self->priv->current_viewers);
+    g_list_free (self->current_viewers);
 
     G_OBJECT_CLASS (nautilus_progress_info_manager_parent_class)->finalize (obj);
 }
@@ -91,8 +93,7 @@ nautilus_progress_info_manager_constructor (GType                  type,
 static void
 nautilus_progress_info_manager_init (NautilusProgressInfoManager *self)
 {
-    self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_PROGRESS_INFO_MANAGER,
-                                              NautilusProgressInfoManagerPriv);
+    
 }
 
 static void
@@ -122,8 +123,6 @@ nautilus_progress_info_manager_class_init (NautilusProgressInfoManagerClass *kla
                       g_cclosure_marshal_VOID__VOID,
                       G_TYPE_NONE,
                       0);
-
-    g_type_class_add_private (klass, sizeof (NautilusProgressInfoManagerPriv));
 }
 
 NautilusProgressInfoManager *
@@ -136,14 +135,14 @@ void
 nautilus_progress_info_manager_add_new_info (NautilusProgressInfoManager *self,
                                              NautilusProgressInfo        *info)
 {
-    if (g_list_find (self->priv->progress_infos, info) != NULL)
+    if (g_list_find (self->progress_infos, info) != NULL)
     {
         g_warning ("Adding two times the same progress info object to the manager");
         return;
     }
 
-    self->priv->progress_infos =
-        g_list_prepend (self->priv->progress_infos, g_object_ref (info));
+    self->progress_infos =
+        g_list_prepend (self->progress_infos, g_object_ref (info));
 
     g_signal_emit (self, signals[NEW_PROGRESS_INFO], 0, info);
 }
@@ -154,15 +153,15 @@ nautilus_progress_info_manager_remove_finished_or_cancelled_infos (NautilusProgr
     GList *l;
     GList *next;
 
-    l = self->priv->progress_infos;
+    l = self->progress_infos;
     while (l != NULL)
     {
         next = l->next;
         if (nautilus_progress_info_get_is_finished (l->data) ||
             nautilus_progress_info_get_is_cancelled (l->data))
         {
-            self->priv->progress_infos = g_list_remove (self->priv->progress_infos,
-                                                        l->data);
+            self->progress_infos = g_list_remove (self->progress_infos,
+                                                  l->data);
         }
         l = next;
     }
@@ -171,7 +170,7 @@ nautilus_progress_info_manager_remove_finished_or_cancelled_infos (NautilusProgr
 GList *
 nautilus_progress_info_manager_get_all_infos (NautilusProgressInfoManager *self)
 {
-    return self->priv->progress_infos;
+    return self->progress_infos;
 }
 
 gboolean
@@ -179,7 +178,7 @@ nautilus_progress_manager_are_all_infos_finished_or_cancelled (NautilusProgressI
 {
     GList *l;
 
-    for (l = self->priv->progress_infos; l != NULL; l = l->next)
+    for (l = self->progress_infos; l != NULL; l = l->next)
     {
         if (!(nautilus_progress_info_get_is_finished (l->data) ||
               nautilus_progress_info_get_is_cancelled (l->data)))
@@ -195,9 +194,9 @@ static void
 remove_viewer (NautilusProgressInfoManager *self,
                GObject                     *viewer)
 {
-    self->priv->current_viewers = g_list_remove (self->priv->current_viewers, viewer);
+    self->current_viewers = g_list_remove (self->current_viewers, viewer);
 
-    if (self->priv->current_viewers == NULL)
+    if (self->current_viewers == NULL)
     {
         g_signal_emit (self, signals[HAS_VIEWERS_CHANGED], 0);
     }
@@ -209,12 +208,12 @@ nautilus_progress_manager_add_viewer (NautilusProgressInfoManager *self,
 {
     GList *viewers;
 
-    viewers = self->priv->current_viewers;
+    viewers = self->current_viewers;
     if (g_list_find (viewers, viewer) == NULL)
     {
         g_object_weak_ref (viewer, (GWeakNotify) remove_viewer, self);
         viewers = g_list_append (viewers, viewer);
-        self->priv->current_viewers = viewers;
+        self->current_viewers = viewers;
 
         if (g_list_length (viewers) == 1)
         {
@@ -227,7 +226,7 @@ void
 nautilus_progress_manager_remove_viewer (NautilusProgressInfoManager *self,
                                          GObject                     *viewer)
 {
-    if (g_list_find (self->priv->current_viewers, viewer) != NULL)
+    if (g_list_find (self->current_viewers, viewer) != NULL)
     {
         g_object_weak_unref (viewer, (GWeakNotify) remove_viewer, self);
         remove_viewer (self, viewer);
@@ -237,5 +236,5 @@ nautilus_progress_manager_remove_viewer (NautilusProgressInfoManager *self,
 gboolean
 nautilus_progress_manager_has_viewers (NautilusProgressInfoManager *self)
 {
-    return self->priv->current_viewers != NULL;
+    return self->current_viewers != NULL;
 }
diff --git a/src/nautilus-progress-info-manager.h b/src/nautilus-progress-info-manager.h
index 5719902..9eeba7e 100644
--- a/src/nautilus-progress-info-manager.h
+++ b/src/nautilus-progress-info-manager.h
@@ -28,33 +28,7 @@
 #include "nautilus-progress-info.h"
 
 #define NAUTILUS_TYPE_PROGRESS_INFO_MANAGER nautilus_progress_info_manager_get_type()
-#define NAUTILUS_PROGRESS_INFO_MANAGER(obj) \
-  (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_PROGRESS_INFO_MANAGER, NautilusProgressInfoManager))
-#define NAUTILUS_PROGRESS_INFO_MANAGER_CLASS(klass) \
-  (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PROGRESS_INFO_MANAGER, NautilusProgressInfoManagerClass))
-#define NAUTILUS_IS_PROGRESS_INFO_MANAGER(obj) \
-  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_PROGRESS_INFO_MANAGER))
-#define NAUTILUS_IS_PROGRESS_INFO_MANAGER_CLASS(klass) \
-  (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PROGRESS_INFO_MANAGER))
-#define NAUTILUS_PROGRESS_INFO_MANAGER_GET_CLASS(obj) \
-  (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_PROGRESS_INFO_MANAGER, NautilusProgressInfoManagerClass))
-
-typedef struct _NautilusProgressInfoManager NautilusProgressInfoManager;
-typedef struct _NautilusProgressInfoManagerClass NautilusProgressInfoManagerClass;
-typedef struct _NautilusProgressInfoManagerPriv NautilusProgressInfoManagerPriv;
-
-struct _NautilusProgressInfoManager {
-  GObject parent;
-
-  /* private */
-  NautilusProgressInfoManagerPriv *priv;
-};
-
-struct _NautilusProgressInfoManagerClass {
-  GObjectClass parent_class;
-};
-
-GType nautilus_progress_info_manager_get_type (void);
+G_DECLARE_FINAL_TYPE (NautilusProgressInfoManager, nautilus_progress_info_manager, NAUTILUS, 
PROGRESS_INFO_MANAGER, GObject)
 
 NautilusProgressInfoManager* nautilus_progress_info_manager_dup_singleton (void);
 


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