[Xfce4-commits] <thunar:nick/gseal+clean> Drop usage of GtkObject and use GObject.

Nick Schermer noreply at xfce.org
Fri May 25 20:24:03 CEST 2012


Updating branch refs/heads/nick/gseal+clean
         to 268e8303540e9268e90e2c9532a4eea86bcfa673 (commit)
       from f9e93fe89a1e6ba531b97991cfd664976ddf42b2 (commit)

commit 268e8303540e9268e90e2c9532a4eea86bcfa673
Author: Nick Schermer <nick at xfce.org>
Date:   Fri May 25 19:23:37 2012 +0200

    Drop usage of GtkObject and use GObject.
    
    Implement the destroy signal in ThunarFolder so we can
    drop the usage of GtkObject.

 thunar/thunar-folder.c |   78 ++++++++++++++++++++++++++++++++++++++++++-----
 thunar/thunar-folder.h |    2 +
 2 files changed, 71 insertions(+), 9 deletions(-)

diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c
index 9ea6939..e9da360 100644
--- a/thunar/thunar-folder.c
+++ b/thunar/thunar-folder.c
@@ -44,6 +44,7 @@ enum
 /* signal identifiers */
 enum
 {
+  DESTROY,
   ERROR,
   FILES_ADDED,
   FILES_REMOVED,
@@ -52,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,
@@ -61,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);
@@ -85,9 +88,10 @@ static void     thunar_folder_monitor                     (GFileMonitor
 
 struct _ThunarFolderClass
 {
-  GtkObjectClass __parent__;
+  GObjectClass __parent__;
 
   /* signals */
+  void (*destroy)       (ThunarFolder *folder);
   void (*error)         (ThunarFolder *folder,
                          const GError *error);
   void (*files_added)   (ThunarFolder *folder,
@@ -98,7 +102,7 @@ struct _ThunarFolderClass
 
 struct _ThunarFolder
 {
-  GtkObject __parent__;
+  GObject __parent__;
 
   ThunarJob         *job;
 
@@ -106,6 +110,8 @@ struct _ThunarFolder
   GList             *new_files;
   GList             *files;
 
+  guint              in_destruction : 1;
+
   ThunarFileMonitor *file_monitor;
 
   GFileMonitor      *monitor;
@@ -118,7 +124,7 @@ static GQuark thunar_folder_quark;
 
 
 
-G_DEFINE_TYPE (ThunarFolder, thunar_folder, GTK_TYPE_OBJECT)
+G_DEFINE_TYPE (ThunarFolder, thunar_folder, G_TYPE_OBJECT)
 
 
 
@@ -128,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:
    *
@@ -143,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));
 
@@ -160,6 +169,20 @@ thunar_folder_class_init (ThunarFolderClass *klass)
                                                          "loading",
                                                          FALSE,
                                                          EXO_PARAM_READABLE));
+  /**
+   * ThunarFolder::destroy:
+   * @folder : a #ThunarFolder.
+   *
+   * Emitted when the #ThunarFolder is destroyed.
+   **/
+  folder_signals[DESTROY] =
+    g_signal_new (I_("destroy"),
+                  G_TYPE_FROM_CLASS (gobject_class),
+                  G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+                  G_STRUCT_OFFSET (ThunarFolderClass, destroy),
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
 
   /**
    * ThunarFolder::error:
@@ -227,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 = FALSE;
+    }
+
+  (*G_OBJECT_CLASS (thunar_folder_parent_class)->dispose) (object);
+}
+
+
+
+static void
 thunar_folder_finalize (GObject *object)
 {
   ThunarFolder *folder = THUNAR_FOLDER (object);
@@ -323,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)
@@ -445,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);
@@ -491,7 +539,7 @@ thunar_folder_file_destroyed (ThunarFileMonitor *file_monitor,
   if (G_UNLIKELY (folder->corresponding_file == file))
     {
       /* the folder is useless now */
-      gtk_object_destroy (GTK_OBJECT (folder));
+      thunar_folder_destroy (folder);
     }
   else
     {
@@ -674,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);
 
@@ -792,4 +837,19 @@ thunar_folder_reload (ThunarFolder *folder)
 
 
 
+/**
+ * thunar_folder_destroy:
+ * @folder : a #ThunarFolder instance.
+ *
+ * Destroy the @folder, this is a replacement for
+ * 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));
 
+  if (!folder->in_destruction)
+    g_object_run_dispose (G_OBJECT (folder));
+}
diff --git a/thunar/thunar-folder.h b/thunar/thunar-folder.h
index a111b62..2d9c465 100644
--- a/thunar/thunar-folder.h
+++ b/thunar/thunar-folder.h
@@ -44,6 +44,8 @@ gboolean      thunar_folder_get_loading            (const ThunarFolder *folder);
 
 void          thunar_folder_reload                 (ThunarFolder       *folder);
 
+void          thunar_folder_destroy                (ThunarFolder       *folder);
+
 G_END_DECLS;
 
 #endif /* !__THUNAR_FOLDER_H__ */


More information about the Xfce4-commits mailing list