[Xfce4-commits] <thunar:master> Make the thumbnailer a singleton.

Nick Schermer noreply at xfce.org
Tue Sep 25 19:02:02 CEST 2012


Updating branch refs/heads/master
         to 98c944530cd9cb64ea2b63767a99fe60c1ecee04 (commit)
       from bde6706f2ccc9d04f31b7804c00b88aff3c17918 (commit)

commit 98c944530cd9cb64ea2b63767a99fe60c1ecee04
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Sep 25 18:46:48 2012 +0200

    Make the thumbnailer a singleton.
    
    Saves a lot of dbus traffic when opening multiple windows
    and the object is perfectly capable to generate more requests
    at once.

 thunar/thunar-properties-dialog.c |    2 +-
 thunar/thunar-standard-view.c     |    2 +-
 thunar/thunar-thumbnailer.c       |   22 +++++++++++++++++-----
 thunar/thunar-thumbnailer.h       |    2 +-
 4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/thunar/thunar-properties-dialog.c b/thunar/thunar-properties-dialog.c
index 2aa6196..fe0468d 100644
--- a/thunar/thunar-properties-dialog.c
+++ b/thunar/thunar-properties-dialog.c
@@ -221,7 +221,7 @@ thunar_properties_dialog_init (ThunarPropertiesDialog *dialog)
                             G_CALLBACK (thunar_properties_dialog_reload), dialog);
 
   /* create a new thumbnailer */
-  dialog->thumbnailer = thunar_thumbnailer_new ();
+  dialog->thumbnailer = thunar_thumbnailer_get ();
   dialog->thumbnail_request = 0;
 
   dialog->provider_factory = thunarx_provider_factory_get_default ();
diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c
index 2450dfe..c931c7f 100644
--- a/thunar/thunar-standard-view.c
+++ b/thunar/thunar-standard-view.c
@@ -566,7 +566,7 @@ thunar_standard_view_init (ThunarStandardView *standard_view)
   standard_view->priv->provider_factory = thunarx_provider_factory_get_default ();
 
   /* create a thumbnailer */
-  standard_view->priv->thumbnailer = thunar_thumbnailer_new ();
+  standard_view->priv->thumbnailer = thunar_thumbnailer_get ();
   g_signal_connect (G_OBJECT (standard_view->priv->thumbnailer), "request-finished", G_CALLBACK (thunar_standard_view_finished_thumbnailing), standard_view);
   standard_view->priv->thumbnailing_scheduled = FALSE;
 
diff --git a/thunar/thunar-thumbnailer.c b/thunar/thunar-thumbnailer.c
index c6298ef..eeba176 100644
--- a/thunar/thunar-thumbnailer.c
+++ b/thunar/thunar-thumbnailer.c
@@ -783,20 +783,32 @@ thunar_thumbnailer_idle_free (gpointer data)
 
 
 /**
- * thunar_thumbnailer_new:
+ * thunar_thumbnailer_get:
  *
- * Allocates a new #ThunarThumbnailer object, which can be used to
+ * Return a shared new #ThunarThumbnailer object, which can be used to
  * generate and store thumbnails for files.
  *
  * The caller is responsible to free the returned
  * object using g_object_unref() when no longer needed.
  *
- * Return value: a newly allocated #ThunarThumbnailer.
+ * Return value: a #ThunarThumbnailer.
  **/
 ThunarThumbnailer*
-thunar_thumbnailer_new (void)
+thunar_thumbnailer_get (void)
 {
-  return g_object_new (THUNAR_TYPE_THUMBNAILER, NULL);
+  static ThunarThumbnailer *thumbnailer = NULL;
+
+  if (G_UNLIKELY (thumbnailer == NULL))
+    {
+      thumbnailer = g_object_new (THUNAR_TYPE_THUMBNAILER, NULL);
+      g_object_add_weak_pointer (G_OBJECT (thumbnailer), (gpointer) &thumbnailer);
+    }
+  else
+    {
+      g_object_ref (G_OBJECT (thumbnailer));
+    }
+
+  return thumbnailer;
 }
 
 
diff --git a/thunar/thunar-thumbnailer.h b/thunar/thunar-thumbnailer.h
index 81caf83..d46f94e 100644
--- a/thunar/thunar-thumbnailer.h
+++ b/thunar/thunar-thumbnailer.h
@@ -37,7 +37,7 @@ typedef struct _ThunarThumbnailer      ThunarThumbnailer;
 
 GType              thunar_thumbnailer_get_type        (void) G_GNUC_CONST;
 
-ThunarThumbnailer *thunar_thumbnailer_new             (void) G_GNUC_MALLOC;
+ThunarThumbnailer *thunar_thumbnailer_get             (void) G_GNUC_MALLOC;
 
 gboolean           thunar_thumbnailer_queue_file      (ThunarThumbnailer        *thumbnailer,
                                                        ThunarFile               *file,


More information about the Xfce4-commits mailing list