Updating branch refs/heads/jannis/thumbnailer-improvements
         to d2dd3f68af0afaf4035a3ffbc7340d257703a003 (commit)
       from 834e6455488ccfb505127ba175e5366e1c652691 (commit)

commit d2dd3f68af0afaf4035a3ffbc7340d257703a003
Author: Jannis Pohlmann <[email protected]>
Date:   Mon Feb 7 16:34:47 2011 +0100

    Add a ThunarThumbnailCache to ThunarApplication, implement Move().
    
    With this tumblerd can just copy the thumbnail and adjust its meta data
    when a file is renamed. We thereby avoid regenerating thumbnails for
    files that are simply renamed but whose contents don't change at all.
    
    We probably need some extra code to check whether the file type has now
    changed or become incompatible with tumbler. In that case we will have
    to drop the thumbnail. But how often does this really happen?

 thunar/Makefile.am                     |   12 ++
 thunar/thunar-application.c            |   43 ++++--
 thunar/thunar-application.h            |  238 ++++++++++++++++----------------
 thunar/thunar-file.c                   |   19 ++-
 thunar/thunar-thumbnail-cache-dbus.xml |   27 ++++
 thunar/thunar-thumbnail-cache.c        |  213 ++++++++++++++++++++++++++++
 thunar/thunar-thumbnail-cache.h        |   49 +++++++
 7 files changed, 466 insertions(+), 135 deletions(-)

diff --git a/thunar/Makefile.am b/thunar/Makefile.am
index 70d6df5..547fe16 100644
--- a/thunar/Makefile.am
+++ b/thunar/Makefile.am
@@ -200,6 +200,8 @@ Thunar_SOURCES =                                            
        \
        thunar-throbber.h                                               \
        thunar-throbber-fallback.c                                      \
        thunar-throbber-fallback.h                                      \
+       thunar-thumbnail-cache.c                                        \
+       thunar-thumbnail-cache.h                                        \
        thunar-thumbnailer.c                                            \
        thunar-thumbnailer.h                                            \
        thunar-thumbnail-frame.c                                        \
@@ -259,6 +261,7 @@ Thunar_DEPENDENCIES =                                       
                \
 if HAVE_DBUS
 thunar_built_sources +=                                                        
\
        thunar-dbus-service-infos.h                                     \
+       thunar-thumbnail-cache-proxy.h                                  \
        thunar-thumbnailer-proxy.h
 
 thunar_dbus_sources =                                                  \
@@ -266,6 +269,7 @@ thunar_dbus_sources =                                       
                \
        thunar-dbus-client.h                                            \
        thunar-dbus-service.c                                           \
        thunar-dbus-service.h                                           \
+       thunar-thumbnail-cache-proxy.h                                  \
        thunar-thumbnailer-proxy.h
 
 Thunar_CFLAGS +=                                                       \
@@ -343,6 +347,14 @@ thunar-thumbnailer-proxy.h: 
$(srcdir)/thunar-thumbnailer-dbus.xml Makefile
                && sed -i -e 
's/org_freedesktop_thumbnails_Thumbnailer1/thunar_thumbnailer_proxy/g' \
                        thunar-thumbnailer-proxy.h \
        )
+
+thunar-thumbnail-cache-proxy.h: $(srcdir)/thunar-thumbnail-cache-dbus.xml 
Makefile
+       $(AM_V_GEN) ( \
+               dbus-binding-tool --mode=glib-client \
+                       $(srcdir)/thunar-thumbnail-cache-dbus.xml > 
thunar-thumbnail-cache-proxy.h \
+               && sed -i -e 
's/org_freedesktop_thumbnails_Cache1/thunar_thumbnail_cache_proxy/g' \
+                       thunar-thumbnail-cache-proxy.h \
+       )
 endif
 
 thunar-throbber-fallback.c: $(srcdir)/thunar-throbber-fallback.png Makefile
diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c
index 4490105..8a5744a 100644
--- a/thunar/thunar-application.c
+++ b/thunar/thunar-application.c
@@ -1,22 +1,23 @@
-/* $Id$ */
+/* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
  * Copyright (c) 2005-2007 Benedikt Meurer <[email protected]>
  * Copyright (c) 2005      Jeff Franks <[email protected]>
- * Copyright (c) 2009-2010 Jannis Pohlmann <[email protected]>
+ * Copyright (c) 2009-2011 Jannis Pohlmann <[email protected]>
  *
- * This program 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 2 of the License, or (at your option)
- * any later version.
+ * This program 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 2 of 
+ * the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA  02111-1307  USA
+ * You should have received a copy of the GNU General Public 
+ * License along with this program; if not, write to the Free 
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -53,6 +54,7 @@
 #include <thunar/thunar-private.h>
 #include <thunar/thunar-progress-dialog.h>
 #include <thunar/thunar-renamer-dialog.h>
+#include <thunar/thunar-thumbnail-cache.h>
 #include <thunar/thunar-util.h>
 
 
@@ -130,6 +132,8 @@ struct _ThunarApplication
   GtkWidget             *progress_dialog;
   GList                 *windows;
 
+  ThunarThumbnailCache  *thumbnail_cache;
+
   gboolean               daemon;
 
   guint                  show_dialogs_timer_id;
@@ -205,6 +209,7 @@ thunar_application_init (ThunarApplication *application)
 
   /* initialize the application */
   application->preferences = thunar_preferences_get ();
+  application->thumbnail_cache = thunar_thumbnail_cache_new ();
 
   application->files_to_launch = NULL;
   application->progress_dialog = NULL;
@@ -279,6 +284,9 @@ thunar_application_finalize (GObject *object)
     }
   g_list_free (application->windows);
 
+  /* release the thumbnail cache */
+  g_object_unref (G_OBJECT (application->thumbnail_cache));
+
   /* disconnect from the preferences */
   g_object_unref (G_OBJECT (application->preferences));
   
@@ -1985,3 +1993,12 @@ thunar_application_restore_files (ThunarApplication 
*application,
 }
 
 
+
+ThunarThumbnailCache *
+thunar_application_get_thumbnail_cache (ThunarApplication *application)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_APPLICATION (application), NULL);
+  return g_object_ref (application->thumbnail_cache);
+}
+
+
diff --git a/thunar/thunar-application.h b/thunar/thunar-application.h
index cb42877..50845a3 100644
--- a/thunar/thunar-application.h
+++ b/thunar/thunar-application.h
@@ -1,28 +1,30 @@
-/* $Id$ */
+/* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
  * Copyright (c) 2005-2006 Benedikt Meurer <[email protected]>
  * Copyright (c) 2005      Jeff Franks <[email protected]>
- * Copyright (c) 2009      Jannis Pohlmann <[email protected]>
+ * Copyright (c) 2009-2011 Jannis Pohlmann <[email protected]>
  *
- * This program 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 2 of the License, or (at your option)
- * any later version.
+ * This program 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 2 of 
+ * the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA  02111-1307  USA
+ * You should have received a copy of the GNU General Public 
+ * License along with this program; if not, write to the Free 
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 #ifndef __THUNAR_APPLICATION_H__
 #define __THUNAR_APPLICATION_H__
 
 #include <thunar/thunar-window.h>
+#include <thunar/thunar-thumbnail-cache.h>
 
 G_BEGIN_DECLS;
 
@@ -36,110 +38,112 @@ typedef struct _ThunarApplication      ThunarApplication;
 #define THUNAR_IS_APPLICATION_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
THUNAR_TYPE_APPLICATION))
 #define THUNAR_APPLICATION_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
THUNAR_TYPE_APPLICATION, ThunarApplicationClass))
 
-GType              thunar_application_get_type                   (void) 
G_GNUC_CONST;
-
-ThunarApplication *thunar_application_get                        (void);
-
-gboolean           thunar_application_get_daemon                 
(ThunarApplication *application);
-void               thunar_application_set_daemon                 
(ThunarApplication *application,
-                                                                  gboolean     
      daemon);
-
-GList             *thunar_application_get_windows                
(ThunarApplication *application);
-
-gboolean           thunar_application_has_windows                
(ThunarApplication *application);
-
-void               thunar_application_take_window                
(ThunarApplication *application,
-                                                                  GtkWindow    
     *window);
-
-GtkWidget         *thunar_application_open_window                
(ThunarApplication *application,
-                                                                  ThunarFile   
     *directory,
-                                                                  GdkScreen    
     *screen,
-                                                                  const gchar  
     *startup_id);
-
-gboolean           thunar_application_bulk_rename                
(ThunarApplication *application,
-                                                                  const gchar  
     *working_directory,
-                                                                  gchar        
    **filenames,
-                                                                  gboolean     
      standalone,
-                                                                  GdkScreen    
     *screen,
-                                                                  const gchar  
     *startup_id,
-                                                                  GError       
    **error);
-
-GtkWidget         *thunar_application_get_progress_dialog        
(ThunarApplication *application);
-
-gboolean           thunar_application_process_filenames          
(ThunarApplication *application,
-                                                                  const gchar  
     *working_directory,
-                                                                  gchar        
    **filenames,
-                                                                  GdkScreen    
     *screen,
-                                                                  const gchar  
     *startup_id,
-                                                                  GError       
    **error);
-
-gboolean           thunar_application_is_processing              
(ThunarApplication *application);
-
-void               thunar_application_rename_file                
(ThunarApplication *application,
-                                                                  ThunarFile   
     *file,
-                                                                  GdkScreen    
     *screen,
-                                                                  const gchar  
     *startup_id);
-void               thunar_application_create_file                
(ThunarApplication *application,
-                                                                  ThunarFile   
     *parent_directory,
-                                                                  const gchar  
     *content_type,
-                                                                  GdkScreen    
     *screen,
-                                                                  const gchar  
     *startup_id);
-void               thunar_application_create_file_from_template 
(ThunarApplication *application,
-                                                                 ThunarFile    
    *parent_directory,
-                                                                 ThunarFile    
    *template_file,
-                                                                 GdkScreen     
    *screen,
-                                                                 const gchar   
    *startup_id);
-void               thunar_application_copy_to                   
(ThunarApplication *application,
-                                                                 gpointer      
     parent,
-                                                                 GList         
    *source_file_list,
-                                                                 GList         
    *target_file_list,
-                                                                 GClosure      
    *new_files_closure);
-
-void               thunar_application_copy_into                 
(ThunarApplication *application,
-                                                                 gpointer      
     parent,
-                                                                 GList         
    *source_file_list,
-                                                                 GFile         
    *target_file,
-                                                                 GClosure      
    *new_files_closure);
-
-void               thunar_application_link_into                 
(ThunarApplication *application,
-                                                                 gpointer      
     parent,
-                                                                 GList         
    *source_file_list,
-                                                                 GFile         
    *target_file,
-                                                                 GClosure      
    *new_files_closure);
-
-void               thunar_application_move_into                 
(ThunarApplication *application,
-                                                                 gpointer      
     parent,
-                                                                 GList         
    *source_file_list,
-                                                                 GFile         
    *target_file,
-                                                                 GClosure      
    *new_files_closure);
-
-void               thunar_application_unlink_files              
(ThunarApplication *application,
-                                                                 gpointer      
     parent,
-                                                                 GList         
    *file_list,
-                                                                 gboolean      
     permanently);
-
-void               thunar_application_trash                     
(ThunarApplication *application,
-                                                                 gpointer      
     parent,
-                                                                 GList         
    *file_list);
-
-void               thunar_application_creat                     
(ThunarApplication *application,
-                                                                 gpointer      
     parent,
-                                                                 GList         
    *file_list,
-                                                                 GClosure      
    *new_files_closure);
-
-void               thunar_application_mkdir                     
(ThunarApplication *application,
-                                                                 gpointer      
     parent,
-                                                                 GList         
    *file_list,
-                                                                 GClosure      
    *new_files_closure);
-
-void               thunar_application_empty_trash               
(ThunarApplication *application,
-                                                                 gpointer      
     parent,
-                                                                 const gchar   
    *startup_id);
-
-void               thunar_application_restore_files             
(ThunarApplication *application,
-                                                                 gpointer      
     parent,
-                                                                 GList         
    *trash_file_list,
-                                                                 GClosure      
    *new_files_closure);
+GType                 thunar_application_get_type                   (void) 
G_GNUC_CONST;
+
+ThunarApplication    *thunar_application_get                        (void);
+
+gboolean              thunar_application_get_daemon                 
(ThunarApplication *application);
+void                  thunar_application_set_daemon                 
(ThunarApplication *application,
+                                                                     gboolean  
         daemon);
+
+GList                *thunar_application_get_windows                
(ThunarApplication *application);
+
+gboolean              thunar_application_has_windows                
(ThunarApplication *application);
+
+void                  thunar_application_take_window                
(ThunarApplication *application,
+                                                                     GtkWindow 
        *window);
+
+GtkWidget            *thunar_application_open_window                
(ThunarApplication *application,
+                                                                     
ThunarFile        *directory,
+                                                                     GdkScreen 
        *screen,
+                                                                     const 
gchar       *startup_id);
+
+gboolean              thunar_application_bulk_rename                
(ThunarApplication *application,
+                                                                     const 
gchar       *working_directory,
+                                                                     gchar     
       **filenames,
+                                                                     gboolean  
         standalone,
+                                                                     GdkScreen 
        *screen,
+                                                                     const 
gchar       *startup_id,
+                                                                     GError    
       **error);
+
+GtkWidget            *thunar_application_get_progress_dialog        
(ThunarApplication *application);
+
+gboolean              thunar_application_process_filenames          
(ThunarApplication *application,
+                                                                     const 
gchar       *working_directory,
+                                                                     gchar     
       **filenames,
+                                                                     GdkScreen 
        *screen,
+                                                                     const 
gchar       *startup_id,
+                                                                     GError    
       **error);
+
+gboolean              thunar_application_is_processing              
(ThunarApplication *application);
+
+void                  thunar_application_rename_file                
(ThunarApplication *application,
+                                                                     
ThunarFile        *file,
+                                                                     GdkScreen 
        *screen,
+                                                                     const 
gchar       *startup_id);
+void                  thunar_application_create_file                
(ThunarApplication *application,
+                                                                     
ThunarFile        *parent_directory,
+                                                                     const 
gchar       *content_type,
+                                                                     GdkScreen 
        *screen,
+                                                                     const 
gchar       *startup_id);
+void                  thunar_application_create_file_from_template 
(ThunarApplication *application,
+                                                                    ThunarFile 
       *parent_directory,
+                                                                    ThunarFile 
       *template_file,
+                                                                    GdkScreen  
       *screen,
+                                                                    const 
gchar       *startup_id);
+void                  thunar_application_copy_to                   
(ThunarApplication *application,
+                                                                    gpointer   
        parent,
+                                                                    GList      
       *source_file_list,
+                                                                    GList      
       *target_file_list,
+                                                                    GClosure   
       *new_files_closure);
+
+void                  thunar_application_copy_into                 
(ThunarApplication *application,
+                                                                    gpointer   
        parent,
+                                                                    GList      
       *source_file_list,
+                                                                    GFile      
       *target_file,
+                                                                    GClosure   
       *new_files_closure);
+
+void                  thunar_application_link_into                 
(ThunarApplication *application,
+                                                                    gpointer   
        parent,
+                                                                    GList      
       *source_file_list,
+                                                                    GFile      
       *target_file,
+                                                                    GClosure   
       *new_files_closure);
+
+void                  thunar_application_move_into                 
(ThunarApplication *application,
+                                                                    gpointer   
        parent,
+                                                                    GList      
       *source_file_list,
+                                                                    GFile      
       *target_file,
+                                                                    GClosure   
       *new_files_closure);
+
+void                  thunar_application_unlink_files              
(ThunarApplication *application,
+                                                                    gpointer   
        parent,
+                                                                    GList      
       *file_list,
+                                                                    gboolean   
        permanently);
+
+void                  thunar_application_trash                     
(ThunarApplication *application,
+                                                                    gpointer   
        parent,
+                                                                    GList      
       *file_list);
+
+void                  thunar_application_creat                     
(ThunarApplication *application,
+                                                                    gpointer   
        parent,
+                                                                    GList      
       *file_list,
+                                                                    GClosure   
       *new_files_closure);
+
+void                  thunar_application_mkdir                     
(ThunarApplication *application,
+                                                                    gpointer   
        parent,
+                                                                    GList      
       *file_list,
+                                                                    GClosure   
       *new_files_closure);
+
+void                  thunar_application_empty_trash               
(ThunarApplication *application,
+                                                                    gpointer   
        parent,
+                                                                    const 
gchar       *startup_id);
+
+void                  thunar_application_restore_files             
(ThunarApplication *application,
+                                                                    gpointer   
        parent,
+                                                                    GList      
       *trash_file_list,
+                                                                    GClosure   
       *new_files_closure);
+
+ThunarThumbnailCache *thunar_application_get_thumbnail_cache       
(ThunarApplication *application);
 
 G_END_DECLS;
 
diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 1281841..ebb1032 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -1254,11 +1254,13 @@ thunar_file_rename (ThunarFile   *file,
                     gboolean      called_from_job,
                     GError      **error)
 {
-  GKeyFile *key_file;
-  GError   *err = NULL;
-  GFile    *previous_file;
-  GFile    *renamed_file;
-  gint      watch_count;
+  ThunarApplication    *application;
+  ThunarThumbnailCache *thumbnail_cache;
+  GKeyFile             *key_file;
+  GError               *err = NULL;
+  GFile                *previous_file;
+  GFile                *renamed_file;
+  gint                  watch_count;
 
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
   _thunar_return_val_if_fail (g_utf8_validate (name, -1, NULL), FALSE);
@@ -1317,6 +1319,13 @@ thunar_file_rename (ThunarFile   *file,
       /* try to rename the file */
       renamed_file = g_file_set_display_name (file->gfile, name, cancellable, 
error);
 
+      /* notify the thumbnail cache that we can now also move the thumbnail */
+      application = thunar_application_get ();
+      thumbnail_cache = thunar_application_get_thumbnail_cache (application);
+      thunar_thumbnail_cache_move_file (thumbnail_cache, previous_file, 
renamed_file);
+      g_object_unref (thumbnail_cache);
+      g_object_unref (application);
+
       /* check if we succeeded */
       if (renamed_file != NULL)
         {
diff --git a/thunar/thunar-thumbnail-cache-dbus.xml 
b/thunar/thunar-thumbnail-cache-dbus.xml
new file mode 100644
index 0000000..0d4ca87
--- /dev/null
+++ b/thunar/thunar-thumbnail-cache-dbus.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<node name="/org/freedesktop/thumbnails/Cache1">
+  <interface name="org.freedesktop.thumbnails.Cache1">
+    <method name="Move">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="as" name="from_uris" direction="in" />
+      <arg type="as" name="to_uris" direction="in" />
+    </method>
+
+    <method name="Copy">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="as" name="from_uris" direction="in" />
+      <arg type="as" name="to_uris" direction="in" />
+    </method>
+
+    <method name="Delete">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="as" name="uris" direction="in" />
+    </method>
+
+    <method name="Cleanup">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="s" name="uri_prefix" direction="in" />
+      <arg type="u" name="since" direction="in" />
+    </method>
+  </interface>
+</node>
diff --git a/thunar/thunar-thumbnail-cache.c b/thunar/thunar-thumbnail-cache.c
new file mode 100644
index 0000000..c71c672
--- /dev/null
+++ b/thunar/thunar-thumbnail-cache.c
@@ -0,0 +1,213 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2011 Jannis Pohlmann <[email protected]>
+ *
+ * This program 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 2 of 
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public 
+ * License along with this program; if not, write to the Free 
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_DBUS
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+
+#include <thunar/thunar-thumbnail-cache-proxy.h>
+#endif
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include <thunar/thunar-private.h>
+#include <thunar/thunar-thumbnail-cache.h>
+
+
+
+static void thunar_thumbnail_cache_finalize (GObject *object);
+
+
+
+struct _ThunarThumbnailCacheClass
+{
+  GObjectClass __parent__;
+};
+
+struct _ThunarThumbnailCache
+{
+  GObject     __parent__;
+
+#ifdef HAVE_DBUS
+  DBusGProxy *cache_proxy;
+
+  GMutex     *lock;
+#endif
+};
+
+
+
+G_DEFINE_TYPE (ThunarThumbnailCache, thunar_thumbnail_cache, G_TYPE_OBJECT)
+
+
+
+static void
+thunar_thumbnail_cache_class_init (ThunarThumbnailCacheClass *klass)
+{
+  GObjectClass *gobject_class;
+
+  /* Determine the parent type class */
+  thunar_thumbnail_cache_parent_class = g_type_class_peek_parent (klass);
+
+  gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->finalize = thunar_thumbnail_cache_finalize; 
+}
+
+
+
+static void
+thunar_thumbnail_cache_init (ThunarThumbnailCache *cache)
+{
+#ifdef HAVE_DBUS
+  DBusGConnection *connection;
+
+  /* try to connect to D-Bus */
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+  if (connection != NULL)
+    {
+      /* create a proxy for the thumbnail cache service */
+      cache->cache_proxy =
+        dbus_g_proxy_new_for_name (connection,
+                                   "org.freedesktop.thumbnails.Cache1",
+                                   "/org/freedesktop/thumbnails/Cache1",
+                                   "org.freedesktop.thumbnails.Cache1");
+
+      /* release the D-Bus connection */
+      dbus_g_connection_unref (connection);
+    }
+
+  /* create a new mutex for accessing the cache from different threads */
+  cache->lock = g_mutex_new ();
+#endif
+}
+
+
+
+static void
+thunar_thumbnail_cache_finalize (GObject *object)
+{
+  ThunarThumbnailCache *cache = THUNAR_THUMBNAIL_CACHE (object);
+
+#ifdef HAVE_DBUS
+  /* acquire a cache lock */
+  g_mutex_lock (cache->lock);
+
+  /* check if we have a valid cache proxy */
+  if (cache->cache_proxy != NULL)
+    {
+      /* release the cache proxy itself */
+      g_object_unref (cache->cache_proxy);
+    }
+
+  /* release the cache lock */
+  g_mutex_unlock (cache->lock);
+
+  /* release the mutex itself */
+  g_mutex_free (cache->lock);
+#endif
+
+  (*G_OBJECT_CLASS (thunar_thumbnail_cache_parent_class)->finalize) (object);
+}
+
+
+
+#ifdef HAVE_DBUS
+static void
+thunar_thumbnail_cache_move_async_reply (DBusGProxy *proxy,
+                                         GError     *error,
+                                         gpointer    user_data)
+{
+  _thunar_return_if_fail (DBUS_IS_G_PROXY (proxy));
+}
+
+
+
+static void
+thunar_thumbnail_cache_move_async (ThunarThumbnailCache *cache,
+                                   const gchar         **source_uris,
+                                   const gchar         **target_uris)
+{
+  _thunar_return_if_fail (THUNAR_IS_THUMBNAIL_CACHE (cache));
+  _thunar_return_if_fail (source_uris != NULL);
+  _thunar_return_if_fail (target_uris != NULL);
+
+  /* request a thumbnail cache update asynchronously */
+  thunar_thumbnail_cache_proxy_move_async (cache->cache_proxy,
+                                           source_uris, target_uris,
+                                           
thunar_thumbnail_cache_move_async_reply,
+                                           NULL);
+}
+#endif /* HAVE_DBUS */
+
+
+
+ThunarThumbnailCache *
+thunar_thumbnail_cache_new (void)
+{
+  return g_object_new (THUNAR_TYPE_THUMBNAIL_CACHE, NULL);
+}
+
+
+
+void
+thunar_thumbnail_cache_move_file (ThunarThumbnailCache *cache,
+                                  GFile                *source_file,
+                                  GFile                *target_file)
+{
+  gchar *source_uris[2] = { NULL, NULL };
+  gchar *target_uris[2] = { NULL, NULL };
+
+  _thunar_return_if_fail (THUNAR_IS_THUMBNAIL_CACHE (cache));
+  _thunar_return_if_fail (G_IS_FILE (source_file));
+  _thunar_return_if_fail (G_IS_FILE (target_file));
+
+#ifdef HAVE_DBUS
+  /* acquire a cache lock */
+  g_mutex_lock (cache->lock);
+
+  /* check if we have a valid proxy for the cache service */
+  if (cache->cache_proxy != NULL)
+    {
+      /* build the source and target URI arrays */
+      source_uris[0] = g_file_get_uri (source_file);
+      target_uris[0] = g_file_get_uri (target_file);
+
+      /* notify the thumbnail cache of the move operation. the cache
+       * can thereby copy the thumbnail and we avoid regenerating it
+       * just because the file name changed */
+      thunar_thumbnail_cache_move_async (cache,
+                                         (const gchar **)source_uris, 
+                                         (const gchar **)target_uris);
+
+      /* release the source and target URI */
+      g_free (source_uris[0]);
+      g_free (target_uris[0]);
+    }
+
+  /* release the cache lock */
+  g_mutex_unlock (cache->lock);
+#endif
+}
diff --git a/thunar/thunar-thumbnail-cache.h b/thunar/thunar-thumbnail-cache.h
new file mode 100644
index 0000000..848d707
--- /dev/null
+++ b/thunar/thunar-thumbnail-cache.h
@@ -0,0 +1,49 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2011 Jannis Pohlmann <[email protected]>
+ *
+ * This program 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 2 of 
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public 
+ * License along with this program; if not, write to the Free 
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __THUNAR_THUMBNAIL_CACHE_H__
+#define __THUNAR_THUMBNAIL_CACHE_H__
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define THUNAR_TYPE_THUMBNAIL_CACHE            
(thunar_thumbnail_cache_get_type ())
+#define THUNAR_THUMBNAIL_CACHE(obj)            (G_TYPE_CHECK_INSTANCE_CAST 
((obj), THUNAR_TYPE_THUMBNAIL_CACHE, ThunarThumbnailCache))
+#define THUNAR_THUMBNAIL_CACHE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST 
((klass), THUNAR_TYPE_THUMBNAIL_CACHE, ThunarThumbnailCacheClass))
+#define THUNAR_IS_THUMBNAIL_CACHE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE 
((obj), THUNAR_TYPE_THUMBNAIL_CACHE))
+#define THUNAR_IS_THUMBNAIL_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE 
((klass), THUNAR_TYPE_THUMBNAIL_CACHE)
+#define THUNAR_THUMBNAIL_CACHE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS 
((obj), THUNAR_TYPE_THUMBNAIL_CACHE, ThunarThumbnailCacheClass))
+
+typedef struct _ThunarThumbnailCachePrivate ThunarThumbnailCachePrivate;
+typedef struct _ThunarThumbnailCacheClass   ThunarThumbnailCacheClass;
+typedef struct _ThunarThumbnailCache        ThunarThumbnailCache;
+
+GType                 thunar_thumbnail_cache_get_type  (void) G_GNUC_CONST;
+
+ThunarThumbnailCache *thunar_thumbnail_cache_new       (void) G_GNUC_MALLOC 
G_GNUC_WARN_UNUSED_RESULT;
+
+void                  thunar_thumbnail_cache_move_file (ThunarThumbnailCache 
*cache,
+                                                        GFile                
*source_file,
+                                                        GFile                
*target_file);
+
+G_END_DECLS
+
+#endif /* !__THUNAR_THUMBNAIL_CACHE_H__ */
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to