[Xfce4-commits] <thunar:nick/gtk3> Implement the destroy signal like in GtkObject.

Nick Schermer noreply at xfce.org
Tue May 15 22:16:02 CEST 2012


Updating branch refs/heads/nick/gtk3
         to d9abe12738a256f994f9f8295899e7e0a10f9d26 (commit)
       from 7ba909f108e3cb8ddcb4afcb08e6a40309c42fd8 (commit)

commit d9abe12738a256f994f9f8295899e7e0a10f9d26
Author: Nick Schermer <nick at xfce.org>
Date:   Tue May 15 22:13:48 2012 +0200

    Implement the destroy signal like in GtkObject.

 thunar/thunar-folder.c |   54 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c
index 1b3b971..c697573 100644
--- a/thunar/thunar-folder.c
+++ b/thunar/thunar-folder.c
@@ -53,6 +53,7 @@ enum
 
 
 
+static void     thunar_folder_dispose                     (GObject                *object);
 static void     thunar_folder_finalize                    (GObject                *object);
 static void     thunar_folder_get_property                (GObject                *object,
                                                            guint                   prop_id,
@@ -62,6 +63,7 @@ static void     thunar_folder_set_property                (GObject
                                                            guint                   prop_uid,
                                                            const GValue           *value,
                                                            GParamSpec             *pspec);
+static void     thunar_folder_real_destroy                (ThunarFolder           *folder);
 static void     thunar_folder_error                       (ExoJob                 *job,
                                                            GError                 *error,
                                                            ThunarFolder           *folder);
@@ -108,6 +110,8 @@ struct _ThunarFolder
   GList             *new_files;
   GList             *files;
 
+  guint              in_destruction : 1;
+
   ThunarFileMonitor *file_monitor;
 
   GFileMonitor      *monitor;
@@ -130,10 +134,13 @@ thunar_folder_class_init (ThunarFolderClass *klass)
   GObjectClass *gobject_class;
 
   gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->dispose = thunar_folder_dispose;
   gobject_class->finalize = thunar_folder_finalize;
   gobject_class->get_property = thunar_folder_get_property;
   gobject_class->set_property = thunar_folder_set_property;
 
+  klass->destroy = thunar_folder_real_destroy;
+
   /**
    * ThunarFolder::corresponding-file:
    *
@@ -145,7 +152,7 @@ thunar_folder_class_init (ThunarFolderClass *klass)
                                                         "corresponding-file",
                                                         "corresponding-file",
                                                         THUNAR_TYPE_FILE,
-                                                        G_PARAM_READABLE 
+                                                        G_PARAM_READABLE
                                                         | G_PARAM_WRITABLE
                                                         | G_PARAM_CONSTRUCT_ONLY));
 
@@ -171,7 +178,7 @@ thunar_folder_class_init (ThunarFolderClass *klass)
   folder_signals[DESTROY] =
     g_signal_new (I_("destroy"),
                   G_TYPE_FROM_CLASS (gobject_class),
-                  G_SIGNAL_RUN_LAST,
+                  G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
                   G_STRUCT_OFFSET (ThunarFolderClass, destroy),
                   NULL, NULL,
                   g_cclosure_marshal_VOID__VOID,
@@ -243,6 +250,23 @@ thunar_folder_init (ThunarFolder *folder)
 
 
 static void
+thunar_folder_dispose (GObject *object)
+{
+  ThunarFolder *folder = THUNAR_FOLDER (object);
+
+  if (!folder->in_destruction)
+    {
+      folder->in_destruction = TRUE;
+      g_signal_emit (G_OBJECT (folder), folder_signals[DESTROY], 0);
+      folder->in_destruction = TRUE;
+    }
+
+  (*G_OBJECT_CLASS (thunar_folder_parent_class)->dispose) (object);
+}
+
+
+
+static void
 thunar_folder_finalize (GObject *object)
 {
   ThunarFolder *folder = THUNAR_FOLDER (object);
@@ -339,6 +363,14 @@ thunar_folder_set_property (GObject      *object,
 
 
 static void
+thunar_folder_real_destroy (ThunarFolder *folder)
+{
+  g_signal_handlers_destroy (G_OBJECT (folder));
+}
+
+
+
+static void
 thunar_folder_error (ExoJob       *job,
                      GError       *error,
                      ThunarFolder *folder)
@@ -461,7 +493,7 @@ thunar_folder_finished (ExoJob       *job,
   folder->job = NULL;
 
   /* add us to the file alteration monitor */
-  folder->monitor = g_file_monitor_directory (thunar_file_get_file (folder->corresponding_file), 
+  folder->monitor = g_file_monitor_directory (thunar_file_get_file (folder->corresponding_file),
                                               G_FILE_MONITOR_NONE, NULL, NULL);
   if (G_LIKELY (folder->monitor != NULL))
     g_signal_connect (folder->monitor, "changed", G_CALLBACK (thunar_folder_monitor), folder);
@@ -690,9 +722,6 @@ thunar_folder_get_for_file (ThunarFile *file)
       /* allocate the new instance */
       folder = g_object_new (THUNAR_TYPE_FOLDER, "corresponding-file", file, NULL);
 
-      /* drop the floating reference */
-      g_object_ref_sink (G_OBJECT (folder));
-
       /* connect the folder to the file */
       g_object_set_qdata (G_OBJECT (file), thunar_folder_quark, folder);
 
@@ -813,17 +842,14 @@ thunar_folder_reload (ThunarFolder *folder)
  * @folder : a #ThunarFolder instance.
  *
  * Destroy the @folder, this is a replacement for
- * the old GtkObject:destroy signal which was been
- * removed in gtk3.
+ * the old gtk_object_destroy function which has been
+ * removed from gtk3.
  **/
 void
 thunar_folder_destroy (ThunarFolder *folder)
 {
   _thunar_return_if_fail (THUNAR_IS_FOLDER (folder));
-  
-  /* TODO maybe this can be moved to the dispose signal and
-   * emitted once there. there we can use g_object_unref on
-   * folders */
-  g_signal_emit (G_OBJECT (folder), folder_signals[DESTROY], 0);
-  g_object_unref (G_OBJECT (folder));
+
+  if (!folder->in_destruction)
+    g_object_run_dispose (G_OBJECT (folder));
 }


More information about the Xfce4-commits mailing list