[Xfce4-commits] r29949 - in thunar/branches/migration-to-gio: . thunar

Jannis Pohlmann jannis at xfce.org
Tue May 12 01:23:09 CEST 2009


Author: jannis
Date: 2009-05-11 23:23:08 +0000 (Mon, 11 May 2009)
New Revision: 29949

Modified:
   thunar/branches/migration-to-gio/ChangeLog
   thunar/branches/migration-to-gio/configure.in.in
   thunar/branches/migration-to-gio/thunar/thunar-dialogs.c
   thunar/branches/migration-to-gio/thunar/thunar-dialogs.h
   thunar/branches/migration-to-gio/thunar/thunar-file.c
   thunar/branches/migration-to-gio/thunar/thunar-file.h
   thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c
   thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h
   thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c
   thunar/branches/migration-to-gio/thunar/thunar-renamer-progress.c
   thunar/branches/migration-to-gio/thunar/thunar-simple-job.c
   thunar/branches/migration-to-gio/thunar/thunar-simple-job.h
   thunar/branches/migration-to-gio/thunar/thunar-standard-view.c
   thunar/branches/migration-to-gio/thunar/thunar-tree-view.c
Log:
	* configure.in.in: Depend on libexo-0.3.101svn-r29948 for
	  exo_job_send_to_mainloop().
	* thunar/thunar-dialogs.{c,h}, thunar/thunar-io-jobs.{c,h},
	  thunar/thunar-dialogs.{c,h}, thunar/thunar-properties-dialog.c,
	  thunar/thunar-standard-view.c, thunar/thunar-tree-view.c: Add new
	  simple job thunar_io_jobs_rename_file() which renames a ThunarFile
	  asynchronously. Make us of it in thunar_dialogs_show_rename_file()
	  which now launches and returns the rename job instead of calling
	  thunar_file_rename() directly. Update ThunarPropertiesDialog,
	  ThunarStandardView and ThunarTreeView to handle the error/finished
	  signals and destroy the job when it's finished.
	* thunar/thunar-file.{c,h}: Add a GCancellable parameter and a boolean
	  parameter called "called_from_job". The latter is used to disable
	  the thunarx_file_info_renamed() and thunar_file_changed() calls. The
	  rename job is responsible to call these in the mainloop of the
	  application after the rename has succeeded.
	* thunar/thunar-simple-job.{c,h}: Add new function
	  thunar_simple_job_get_param_values() which returns the GValueArray
	  created from the parameters passed to thunar_simple_job_launch().

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-05-11 23:23:08 UTC (rev 29949)
@@ -1,3 +1,25 @@
+2009-05-12	Jannis Pohlmann <jannis at xfce.org>
+
+	* configure.in.in: Depend on libexo-0.3.101svn-r29948 for
+	  exo_job_send_to_mainloop().
+	* thunar/thunar-dialogs.{c,h}, thunar/thunar-io-jobs.{c,h}, 
+	  thunar/thunar-dialogs.{c,h}, thunar/thunar-properties-dialog.c,
+	  thunar/thunar-standard-view.c, thunar/thunar-tree-view.c: Add new 
+	  simple job thunar_io_jobs_rename_file() which renames a ThunarFile 
+	  asynchronously. Make us of it in thunar_dialogs_show_rename_file()
+	  which now launches and returns the rename job instead of calling
+	  thunar_file_rename() directly. Update ThunarPropertiesDialog, 
+	  ThunarStandardView and ThunarTreeView to handle the error/finished
+	  signals and destroy the job when it's finished. 
+	* thunar/thunar-file.{c,h}: Add a GCancellable parameter and a boolean
+	  parameter called "called_from_job". The latter is used to disable
+	  the thunarx_file_info_renamed() and thunar_file_changed() calls. The
+	  rename job is responsible to call these in the mainloop of the
+	  application after the rename has succeeded. 
+	* thunar/thunar-simple-job.{c,h}: Add new function
+	  thunar_simple_job_get_param_values() which returns the GValueArray
+	  created from the parameters passed to thunar_simple_job_launch().
+
 2009-05-11	Jannis Pohlmann <jannis at xfce.org>
 
 	* thunar/Makefile.am, thunar/thunar-exec.{c,h}: Import thunar_exec_*()

Modified: thunar/branches/migration-to-gio/configure.in.in
===================================================================
--- thunar/branches/migration-to-gio/configure.in.in	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/configure.in.in	2009-05-11 23:23:08 UTC (rev 29949)
@@ -159,7 +159,7 @@
 dnl ***********************************
 dnl *** Check for required packages ***
 dnl ***********************************
-XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.101svn-r29926])
+XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.101svn-r29948])
 XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.16.0])
 XDT_CHECK_PACKAGE([GIO], [gio-2.0], [2.16.0])
 XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.16.0])

Modified: thunar/branches/migration-to-gio/thunar/thunar-dialogs.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-dialogs.c	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-dialogs.c	2009-05-11 23:23:08 UTC (rev 29949)
@@ -34,6 +34,8 @@
 
 #include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-icon-factory.h>
+#include <thunar/thunar-io-jobs.h>
+#include <thunar/thunar-job.h>
 #include <thunar/thunar-pango-extensions.h>
 #include <thunar/thunar-preferences.h>
 #include <thunar/thunar-private.h>
@@ -48,11 +50,10 @@
  *
  * Displays the Thunar rename dialog for a single file rename.
  *
- * Return value: returns %TRUE if the file has been successfully renamed.
- *               Note that it also returns %FALSE if no rename was required
- *               and thus there is no need for visible updates.
+ * Return value: The #ThunarJob responsible for renaming the file or
+ *               %NULL if there was no renaming required.
  **/
-gboolean
+ThunarJob *
 thunar_dialogs_show_rename_file (GtkWindow *parent,
                                  ThunarFile *file)
 {
@@ -60,24 +61,20 @@
   GtkIconTheme      *icon_theme;
   const gchar       *filename;
   const gchar       *text;
+  ThunarJob         *job = NULL;
   GtkWidget         *dialog;
   GtkWidget         *entry;
   GtkWidget         *label;
   GtkWidget         *image;
   GtkWidget         *table;
   GdkPixbuf         *icon;
-  GError            *error = NULL;
   glong              offset;
   gchar             *title;
   gint               response;
-  gboolean           succeed = FALSE;
 
   _thunar_return_val_if_fail (GTK_IS_WINDOW (parent), FALSE);
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
 
-  /* take an extra reference on the file */
-  g_object_ref (G_OBJECT (file));
-
   /* get the filename of the file */
   filename = thunar_file_get_display_name (file);
 
@@ -138,7 +135,7 @@
 
           /* select the text prior to the dot */
           if (G_LIKELY (offset > 0))
-            gtk_entry_select_region (GTK_ENTRY (entry), 0, offset);
+            gtk_editable_select_region (GTK_EDITABLE (entry), 0, offset);
         }
     }
 
@@ -156,27 +153,14 @@
       if (G_LIKELY (!exo_str_is_equal (filename, text)))
         {
           /* try to rename the file */
-          if (!thunar_file_rename (file, text, &error))
-            {
-              /* display an error message */
-              thunar_dialogs_show_error (GTK_WIDGET (parent), error, _("Failed to rename \"%s\""), filename);
-
-              /* release the error */
-              g_error_free (error);
-            }
-          else
-            {
-              /* we've succeeded */
-              succeed = TRUE;
-            }
+          job = thunar_io_jobs_rename_file (file, text);
         }
     }
 
   /* cleanup */
-  g_object_unref (G_OBJECT (file));
   gtk_widget_destroy (dialog);
 
-  return succeed;
+  return job;
 }
 
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-dialogs.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-dialogs.h	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-dialogs.h	2009-05-11 23:23:08 UTC (rev 29949)
@@ -22,10 +22,11 @@
 
 #include <thunar/thunar-enum-types.h>
 #include <thunar/thunar-file.h>
+#include <thunar/thunar-job.h>
 
 G_BEGIN_DECLS;
 
-gboolean           thunar_dialogs_show_rename_file     (GtkWindow            *parent,
+ThunarJob         *thunar_dialogs_show_rename_file     (GtkWindow            *parent,
                                                         ThunarFile           *file) G_GNUC_INTERNAL;
 
 void               thunar_dialogs_show_about           (GtkWindow            *parent,

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-05-11 23:23:08 UTC (rev 29949)
@@ -777,7 +777,6 @@
 
   /* determine the basename */
   file->basename = g_file_get_basename (file->gfile);
-
   _thunar_assert (file->basename != NULL);
 
   /* determine the custom icon name for .desktop files */
@@ -1151,20 +1150,26 @@
  * Return value: %TRUE on success, else %FALSE.
  **/
 gboolean
-thunar_file_rename (ThunarFile  *file,
-                    const gchar *name,
-                    GError     **error)
+thunar_file_rename (ThunarFile   *file,
+                    const gchar  *name,
+                    GCancellable *cancellable,
+                    gboolean      called_from_job,
+                    GError      **error)
 {
   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);
+  _thunar_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
+  _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
   /* remember the previous file */
-  previous_file = file->gfile;
+  previous_file = g_object_ref (file->gfile);
   
   /* try to rename the file */
-  /* TODO Make this asynchronous */
-  renamed_file = g_file_set_display_name (file->gfile, name, NULL, error);
+  renamed_file = g_file_set_display_name (file->gfile, name, cancellable, error);
 
   /* check if we succeeded */
   if (renamed_file != NULL)
@@ -1172,6 +1177,9 @@
       /* set the new file */
       file->gfile = renamed_file;
 
+      /* reload file information */
+      thunar_file_load (file, NULL, NULL);
+
       /* need to re-register the monitor handle for the new uri */
       watch_count = THUNAR_FILE_GET_WATCH_COUNT (file);
       if (G_LIKELY (watch_count > 0))
@@ -1202,16 +1210,21 @@
 
       G_UNLOCK (file_cache_mutex);
 
-      /* tell the associated folder that the file was renamed */
-      thunarx_file_info_renamed (THUNARX_FILE_INFO (file));
+      if (!called_from_job)
+        {
+          /* tell the associated folder that the file was renamed */
+          thunarx_file_info_renamed (THUNARX_FILE_INFO (file));
 
-      /* emit the file changed signal */
-      thunar_file_changed (file);
-      
+          /* emit the file changed signal */
+          thunar_file_changed (file);
+        }
+
       return TRUE;
     }
   else
     {
+      g_object_unref (previous_file);
+
       return FALSE;
     }
 }

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-05-11 23:23:08 UTC (rev 29949)
@@ -150,6 +150,8 @@
 
 gboolean          thunar_file_rename               (ThunarFile             *file,
                                                     const gchar            *name,
+                                                    GCancellable           *cancellable,
+                                                    gboolean                called_from_job,
                                                     GError                **error);
 
 GdkDragAction     thunar_file_accepts_drop         (ThunarFile             *file,

Modified: thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c	2009-05-11 23:23:08 UTC (rev 29949)
@@ -60,7 +60,7 @@
     }
 
   /* check if we failed */
-  if (G_UNLIKELY (err != NULL || exo_job_is_cancelled (EXO_JOB (job))))
+  if (err != NULL || exo_job_is_cancelled (EXO_JOB (job)))
     {
       if (exo_job_set_error_if_cancelled (EXO_JOB (job), error))
         g_error_free (err);
@@ -161,7 +161,7 @@
                                                    display_name);
 
               /* check if we should overwrite */
-              if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_YES))
+              if (response == THUNAR_JOB_RESPONSE_YES)
                 {
                   /* try to remove the file. fail if not possible */
                   if (g_file_delete (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err))
@@ -187,7 +187,7 @@
               g_clear_error (&err);
 
               /* go back to the beginning if the user wants to retry */
-              if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_RETRY))
+              if (response == THUNAR_JOB_RESPONSE_RETRY)
                 goto again;
             }
         }
@@ -196,14 +196,14 @@
     }
 
   /* check if we have failed */
-  if (G_UNLIKELY (err != NULL))
+  if (err != NULL)
     {
       g_propagate_error (error, err);
       return FALSE;
     }
 
   /* check if the job was cancelled */
-  if (G_UNLIKELY (exo_job_is_cancelled (EXO_JOB (job))))
+  if (exo_job_is_cancelled (EXO_JOB (job)))
     return FALSE;
 
   /* emit the "new-files" signal with the given file list */
@@ -298,7 +298,7 @@
                                                    display_name);
 
               /* check if we should overwrite it */
-              if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_YES))
+              if (response == THUNAR_JOB_RESPONSE_YES)
                 {
                   /* try to remove the file, fail if not possible */
                   if (g_file_delete (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err))
@@ -325,21 +325,21 @@
               err = NULL;
 
               /* go back to the beginning if the user wants to retry */
-              if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_RETRY))
+              if (response == THUNAR_JOB_RESPONSE_RETRY)
                 goto again;
             }
         }
     }
 
   /* check if we have failed */
-  if (G_UNLIKELY (err != NULL))
+  if (err != NULL)
     {
       g_propagate_error (error, err);
       return FALSE;
     }
 
   /* check if the job was cancelled */
-  if (G_UNLIKELY (exo_job_is_cancelled (EXO_JOB (job))))
+  if (exo_job_is_cancelled (EXO_JOB (job)))
     return FALSE;
 
   /* emit the "new-files" signal with the given file list */
@@ -407,12 +407,12 @@
       g_assert (G_IS_FILE (lp->data));
 
       /* skip root folders which cannot be deleted anyway */
-      if (G_UNLIKELY (g_file_is_root (lp->data)))
+      if (g_file_is_root (lp->data))
         continue;
 
 again:
       /* try to delete the file */
-      if (G_UNLIKELY (!g_file_delete (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err)))
+      if (!g_file_delete (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err))
         {
           /* query the file info for the display name */
           info = g_file_query_info (lp->data, 
@@ -451,7 +451,7 @@
           g_clear_error (&err);
 
           /* check whether to retry */
-          if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_RETRY))
+          if (response == THUNAR_JOB_RESPONSE_RETRY)
             goto again;
         }
     }
@@ -729,7 +729,7 @@
   else
     file_list = g_file_list_copy (file_list);
 
-  if (G_UNLIKELY (err != NULL))
+  if (err != NULL)
     {
       g_propagate_error (error, err);
       return FALSE;
@@ -751,7 +751,7 @@
                                 exo_job_get_cancellable (EXO_JOB (job)),
                                 &err);
 
-      if (G_UNLIKELY (err != NULL))
+      if (err != NULL)
         break;
 
 retry_chown:
@@ -775,7 +775,7 @@
         }
 
       /* check if there was a recoverable error */
-      if (G_UNLIKELY (err != NULL && !exo_job_is_cancelled (EXO_JOB (job))))
+      if (err != NULL && !exo_job_is_cancelled (EXO_JOB (job)))
         {
           /* generate a useful error message */
           message = G_LIKELY (uid >= 0) ? _("Failed to change the owner of \"%s\": %s") 
@@ -790,7 +790,7 @@
           g_clear_error (&err);
 
           /* check whether to retry */
-          if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_RETRY))
+          if (response == THUNAR_JOB_RESPONSE_RETRY)
             goto retry_chown;
         }
 
@@ -801,7 +801,7 @@
   /* release the file list */
   g_file_list_free (file_list);
 
-  if (G_UNLIKELY (err != NULL))
+  if (err != NULL)
     {
       g_propagate_error (error, err);
       return FALSE;
@@ -876,7 +876,7 @@
   else
     file_list = g_file_list_copy (file_list);
 
-  if (G_UNLIKELY (err != NULL))
+  if (err != NULL)
     {
       g_propagate_error (error, err);
       return FALSE;
@@ -900,7 +900,7 @@
                                 exo_job_get_cancellable (EXO_JOB (job)),
                                 &err);
 
-      if (G_UNLIKELY (err != NULL))
+      if (err != NULL)
         break;
 
 retry_chown:
@@ -931,7 +931,7 @@
                                    &err);
 
       /* check if there was a recoverable error */
-      if (G_UNLIKELY (err != NULL && !exo_job_is_cancelled (EXO_JOB (job))))
+      if (err != NULL && !exo_job_is_cancelled (EXO_JOB (job)))
         {
           /* ask the user whether to skip/retry this file */
           response = thunar_job_ask_skip (job,
@@ -943,7 +943,7 @@
           g_clear_error (&err);
 
           /* check whether to retry */
-          if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_RETRY))
+          if (response == THUNAR_JOB_RESPONSE_RETRY)
             goto retry_chown;
         }
 
@@ -954,7 +954,7 @@
   /* release the file list */
   g_file_list_free (file_list);
 
-  if (G_UNLIKELY (err != NULL))
+  if (err != NULL)
     {
       g_propagate_error (error, err);
       return FALSE;
@@ -1042,12 +1042,12 @@
   g_file_list_free (path_list);
 
   /* abort on errors or cancellation */
-  if (G_UNLIKELY (err != NULL))
+  if (err != NULL)
     {
       g_propagate_error (error, err);
       return FALSE;
     }
-  else if (G_UNLIKELY (exo_job_set_error_if_cancelled (EXO_JOB (job), &err)))
+  else if (exo_job_set_error_if_cancelled (EXO_JOB (job), &err))
     {
       g_propagate_error (error, err);
       return FALSE;
@@ -1087,3 +1087,76 @@
   
   return thunar_simple_job_launch (_thunar_io_jobs_ls, 1, G_TYPE_FILE, directory);
 }
+
+
+
+gboolean
+_thunar_io_jobs_rename_notify (ThunarFile *file)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
+
+  /* tell the associated folder that the file was renamed */
+  thunarx_file_info_renamed (THUNARX_FILE_INFO (file));
+
+  /* emit the file changed signal */
+  thunar_file_changed (file);
+
+  return FALSE;
+}
+
+
+
+gboolean
+_thunar_io_jobs_rename (ThunarJob   *job,
+                        GValueArray *param_values,
+                        GError     **error)
+{
+  const gchar *display_name;
+  ThunarFile  *file;
+  GError      *err = NULL;
+
+  _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE);
+  _thunar_return_val_if_fail (param_values != NULL, FALSE);
+  _thunar_return_val_if_fail (param_values->n_values == 2, FALSE);
+  _thunar_return_val_if_fail (G_VALUE_HOLDS (&param_values->values[0], THUNAR_TYPE_FILE), FALSE);
+  _thunar_return_val_if_fail (G_VALUE_HOLDS_STRING (&param_values->values[1]), FALSE);
+  _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  if (exo_job_set_error_if_cancelled (EXO_JOB (job), error))
+    return FALSE;
+
+  /* determine the file and display name */
+  file = g_value_get_object (g_value_array_get_nth (param_values, 0));
+  display_name = g_value_get_string (g_value_array_get_nth (param_values, 1));
+
+  /* try to rename the file */
+  if (thunar_file_rename (file, display_name, exo_job_get_cancellable (EXO_JOB (job)), TRUE, &err))
+    {
+      exo_job_send_to_mainloop (EXO_JOB (job), 
+                                (GSourceFunc) _thunar_io_jobs_rename_notify, 
+                                g_object_ref (file), g_object_unref);
+    }
+
+  /* abort on errors or cancellation */
+  if (err != NULL)
+    {
+      g_propagate_error (error, err);
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+
+
+ThunarJob *
+thunar_io_jobs_rename_file (ThunarFile  *file,
+                            const gchar *display_name)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
+  _thunar_return_val_if_fail (g_utf8_validate (display_name, -1, NULL), NULL);
+
+  return thunar_simple_job_launch (_thunar_io_jobs_rename, 2, 
+                                   THUNAR_TYPE_FILE, file, 
+                                   G_TYPE_STRING, display_name);
+}

Modified: thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h	2009-05-11 23:23:08 UTC (rev 29949)
@@ -48,6 +48,8 @@
                                             ThunarFileMode file_mode,
                                             gboolean       recursive) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 ThunarJob *thunar_io_jobs_list_directory   (GFile         *directory) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_io_jobs_rename_file      (ThunarFile    *file,
+                                            const gchar   *display_name) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 
 G_END_DECLS
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c	2009-05-11 23:23:08 UTC (rev 29949)
@@ -31,6 +31,8 @@
 
 #include <gdk/gdkkeysyms.h>
 
+#include <exo/exo.h>
+
 #include <thunar/thunar-abstract-dialog.h>
 #include <thunar/thunar-chooser-button.h>
 #include <thunar/thunar-dialogs.h>
@@ -39,6 +41,8 @@
 #include <thunar/thunar-gobject-extensions.h>
 #include <thunar/thunar-gtk-extensions.h>
 #include <thunar/thunar-icon-factory.h>
+#include <thunar/thunar-io-jobs.h>
+#include <thunar/thunar-job.h>
 #include <thunar/thunar-marshal.h>
 #include <thunar/thunar-pango-extensions.h>
 #include <thunar/thunar-permissions-chooser.h>
@@ -89,8 +93,6 @@
                                                                ThunarPropertiesDialog      *dialog);
 static void     thunar_properties_dialog_update               (ThunarPropertiesDialog      *dialog);
 static void     thunar_properties_dialog_update_providers     (ThunarPropertiesDialog      *dialog);
-static gboolean thunar_properties_dialog_rename_idle          (gpointer                     user_data);
-static void     thunar_properties_dialog_rename_idle_destroy  (gpointer                     user_data);
 
 
 
@@ -130,7 +132,6 @@
   GtkWidget              *volume_label;
   GtkWidget              *permissions_chooser;
 
-  guint                   rename_idle_id;
 };
 
 
@@ -553,10 +554,6 @@
   /* drop the reference on the provider factory */
   g_object_unref (dialog->provider_factory);
 
-  /* be sure to cancel any pending rename idle source */
-  if (G_UNLIKELY (dialog->rename_idle_id != 0))
-    g_source_remove (dialog->rename_idle_id);
-
   (*G_OBJECT_CLASS (thunar_properties_dialog_parent_class)->finalize) (object);
 }
 
@@ -648,13 +645,65 @@
 
 
 static void
+thunar_properties_dialog_rename_error (ExoJob                 *job,
+                                       GError                 *error,
+                                       ThunarPropertiesDialog *dialog)
+{
+  _thunar_return_if_fail (EXO_IS_JOB (job));
+  _thunar_return_if_fail (error != NULL);
+  _thunar_return_if_fail (THUNAR_IS_PROPERTIES_DIALOG (dialog));
+
+  /* display an error message */
+  thunar_dialogs_show_error (GTK_WIDGET (dialog), error, _("Failed to rename \"%s\""),
+                             thunar_file_get_display_name (dialog->file));
+}
+
+
+
+static void
+thunar_properties_dialog_rename_finished (ExoJob                 *job,
+                                          ThunarPropertiesDialog *dialog)
+{
+  const gchar *new_name;
+
+  _thunar_return_if_fail (EXO_IS_JOB (job));
+  _thunar_return_if_fail (THUNAR_IS_PROPERTIES_DIALOG (dialog));
+
+  /* determine the new display name */
+  new_name = thunar_file_get_display_name (dialog->file);
+
+  /* reset the entry widget to the new name */
+  gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), new_name);
+
+  g_signal_handlers_disconnect_matched (job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, dialog);
+  g_object_unref (job);
+}
+
+
+
+static void
 thunar_properties_dialog_activate (GtkWidget              *entry,
                                    ThunarPropertiesDialog *dialog)
 {
-  if (G_LIKELY (dialog->rename_idle_id == 0))
+  const gchar *old_name;
+  ThunarJob   *job;
+  gchar       *new_name;
+
+  /* check if we still have a valid file and if the user is allowed to rename */
+  if (G_UNLIKELY (dialog->file == NULL || !GTK_WIDGET_SENSITIVE (dialog->name_entry)))
+    return;
+
+  /* determine new and old name */
+  new_name = gtk_editable_get_chars (GTK_EDITABLE (dialog->name_entry), 0, -1);
+  old_name = thunar_file_get_display_name (dialog->file);
+  if (g_utf8_collate (new_name, old_name) != 0)
     {
-      dialog->rename_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT, thunar_properties_dialog_rename_idle,
-                                                dialog, thunar_properties_dialog_rename_idle_destroy);
+      job = thunar_io_jobs_rename_file (dialog->file, new_name);
+      if (job != NULL)
+        {
+          g_signal_connect (job, "error", G_CALLBACK (thunar_properties_dialog_rename_error), dialog);
+          g_signal_connect (job, "finished", G_CALLBACK (thunar_properties_dialog_rename_finished), dialog);
+        }
     }
 }
 
@@ -977,55 +1026,6 @@
 
 
 
-static gboolean
-thunar_properties_dialog_rename_idle (gpointer user_data)
-{
-  ThunarPropertiesDialog *dialog = THUNAR_PROPERTIES_DIALOG (user_data);
-  const gchar            *old_name;
-  GError                 *error = NULL;
-  gchar                  *new_name;
-
-  /* check if we still have a valid file and if the user is allowed to rename */
-  if (G_UNLIKELY (dialog->file == NULL || !GTK_WIDGET_SENSITIVE (dialog->name_entry)))
-    return FALSE;
-
-  GDK_THREADS_ENTER ();
-
-  /* determine new and old name */
-  new_name = gtk_editable_get_chars (GTK_EDITABLE (dialog->name_entry), 0, -1);
-  old_name = thunar_file_get_display_name (dialog->file);
-  if (g_utf8_collate (new_name, old_name) != 0)
-    {
-      /* try to rename the file to the new name */
-      if (!thunar_file_rename (dialog->file, new_name, &error))
-        {
-          /* reset the entry widget to the old name */
-          gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), old_name);
-
-          /* display an error message */
-          thunar_dialogs_show_error (GTK_WIDGET (dialog), error, _("Failed to rename \"%s\""), old_name);
-
-          /* release the error */
-          g_error_free (error);
-        }
-    }
-  g_free (new_name);
-
-  GDK_THREADS_LEAVE ();
-
-  return FALSE;
-}
-
-
-
-static void
-thunar_properties_dialog_rename_idle_destroy (gpointer user_data)
-{
-  THUNAR_PROPERTIES_DIALOG (user_data)->rename_idle_id = 0;
-}
-
-
-
 /**
  * thunar_properties_dialog_new:
  *

Modified: thunar/branches/migration-to-gio/thunar/thunar-renamer-progress.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-renamer-progress.c	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-renamer-progress.c	2009-05-11 23:23:08 UTC (rev 29949)
@@ -200,7 +200,7 @@
       oldname = g_strdup (thunar_file_get_display_name (pair->file));
 
       /* try to rename the file */
-      if (!thunar_file_rename (pair->file, pair->name, &error))
+      if (!thunar_file_rename (pair->file, pair->name, NULL, FALSE, &error))
         {
           /* determine the toplevel widget */
           toplevel = (GtkWindow *) gtk_widget_get_toplevel (GTK_WIDGET (renamer_progress));

Modified: thunar/branches/migration-to-gio/thunar/thunar-simple-job.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-simple-job.c	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-simple-job.c	2009-05-11 23:23:08 UTC (rev 29949)
@@ -221,3 +221,12 @@
   /* launch the job */
   return THUNAR_JOB (exo_job_launch (EXO_JOB (simple_job)));
 }
+
+
+
+GValueArray *
+thunar_simple_job_get_param_values (ThunarSimpleJob *job)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_SIMPLE_JOB (job), NULL);
+  return job->param_values;
+}

Modified: thunar/branches/migration-to-gio/thunar/thunar-simple-job.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-simple-job.h	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-simple-job.h	2009-05-11 23:23:08 UTC (rev 29949)
@@ -52,11 +52,12 @@
 #define THUNAR_IS_SIMPLE_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_SIMPLE_JOB))
 #define THUNAR_SIMPLE_JOB_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_SIMPLE_JOB, ThunarSimpleJobClass))
 
-GType      thunar_simple_job_get_type  (void) G_GNUC_CONST;
+GType      thunar_simple_job_get_type           (void) G_GNUC_CONST;
 
-ThunarJob *thunar_simple_job_launch    (ThunarSimpleJobFunc func,
-                                        guint               n_param_values,
-                                        ...) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_simple_job_launch             (ThunarSimpleJobFunc func,
+                                                 guint               n_param_values,
+                                                 ...) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+GValueArray *thunar_simple_job_get_param_values (ThunarSimpleJob    *job);
 
 G_END_DECLS
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-standard-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-standard-view.c	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-standard-view.c	2009-05-11 23:23:08 UTC (rev 29949)
@@ -44,6 +44,7 @@
 #include <thunar/thunar-private.h>
 #include <thunar/thunar-properties-dialog.h>
 #include <thunar/thunar-renamer-dialog.h>
+#include <thunar/thunar-simple-job.h>
 #include <thunar/thunar-standard-view.h>
 #include <thunar/thunar-standard-view-ui.h>
 #include <thunar/thunar-templates-action.h>
@@ -2197,11 +2198,63 @@
 
 
 static void
+thunar_standard_view_rename_error (ExoJob             *job,
+                                   GError             *error,
+                                   ThunarStandardView *standard_view)
+{
+  GValueArray *param_values;
+  ThunarFile  *file;
+
+  _thunar_return_if_fail (EXO_IS_JOB (job));
+  _thunar_return_if_fail (error != NULL);
+  _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view));
+
+  param_values = thunar_simple_job_get_param_values (THUNAR_SIMPLE_JOB (job));
+  file = g_value_get_object (g_value_array_get_nth (param_values, 0));
+
+  /* display an error message */
+  thunar_dialogs_show_error (GTK_WIDGET (standard_view), error, 
+                             _("Failed to rename \"%s\""),
+                             thunar_file_get_display_name (file));
+}
+
+
+
+static void
+thunar_standard_view_rename_finished (ExoJob             *job,
+                                      ThunarStandardView *standard_view)
+{
+  GValueArray *param_values;
+  ThunarFile  *file;
+
+  _thunar_return_if_fail (EXO_IS_JOB (job));
+  _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view));
+
+  param_values = thunar_simple_job_get_param_values (THUNAR_SIMPLE_JOB (job));
+  file = g_value_get_object (g_value_array_get_nth (param_values, 0));
+
+  /* make sure the file is still visible */
+  thunar_view_scroll_to_file (THUNAR_VIEW (standard_view), file, TRUE, FALSE, 0.0f, 0.0f);
+
+  /* update the selection, so we get updated actions, statusbar,
+   * etc. with the new file name and probably new mime type.
+   */
+  thunar_standard_view_selection_changed (standard_view);
+
+  /* destroy the job */
+  g_signal_handlers_disconnect_matched (job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, standard_view);
+  g_object_unref (job);
+}
+
+
+
+static void
 thunar_standard_view_action_rename (GtkAction          *action,
                                     ThunarStandardView *standard_view)
 {
   ThunarFile *file;
   GtkWidget  *window;
+  ThunarJob  *job;
 
   _thunar_return_if_fail (GTK_IS_ACTION (action));
   _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view));
@@ -2216,15 +2269,11 @@
       file = THUNAR_FILE (standard_view->selected_files->data);
 
       /* run the rename dialog */
-      if (thunar_dialogs_show_rename_file (GTK_WINDOW (window), file))
+      job = thunar_dialogs_show_rename_file (GTK_WINDOW (window), file);
+      if (G_LIKELY (job != NULL))
         {
-          /* make sure the file is still visible */
-          thunar_view_scroll_to_file (THUNAR_VIEW (standard_view), file, TRUE, FALSE, 0.0f, 0.0f);
-
-          /* update the selection, so we get updated actions, statusbar,
-           * etc. with the new file name and probably new mime type.
-           */
-          thunar_standard_view_selection_changed (standard_view);
+          g_signal_connect (job, "error", G_CALLBACK (thunar_standard_view_rename_error), standard_view);
+          g_signal_connect (job, "finished", G_CALLBACK (thunar_standard_view_rename_finished), standard_view);
         }
     }
   else if (g_list_length (standard_view->selected_files) > 1)

Modified: thunar/branches/migration-to-gio/thunar/thunar-tree-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-tree-view.c	2009-05-11 22:48:08 UTC (rev 29948)
+++ thunar/branches/migration-to-gio/thunar/thunar-tree-view.c	2009-05-11 23:23:08 UTC (rev 29949)
@@ -37,6 +37,7 @@
 #include <thunar/thunar-private.h>
 #include <thunar/thunar-properties-dialog.h>
 #include <thunar/thunar-shortcuts-icon-renderer.h>
+#include <thunar/thunar-simple-job.h>
 #include <thunar/thunar-tree-model.h>
 #include <thunar/thunar-tree-view.h>
 
@@ -1650,10 +1651,47 @@
 
 
 static void
+thunar_tree_view_rename_error (ExoJob         *job,
+                               GError         *error,
+                               ThunarTreeView *view)
+{
+  GValueArray *param_values;
+  ThunarFile  *file;
+
+  _thunar_return_if_fail (EXO_IS_JOB (job));
+  _thunar_return_if_fail (error != NULL);
+  _thunar_return_if_fail (THUNAR_IS_TREE_VIEW (view));
+
+  param_values = thunar_simple_job_get_param_values (THUNAR_SIMPLE_JOB (job));
+  file = g_value_get_object (g_value_array_get_nth (param_values, 0));
+
+  /* display an error message */
+  thunar_dialogs_show_error (GTK_WIDGET (view), error, _("Failed to rename \"%s\""),
+                             thunar_file_get_display_name (file));
+}
+
+
+
+static void
+thunar_tree_view_rename_finished (ExoJob         *job,
+                                  ThunarTreeView *view)
+{
+  _thunar_return_if_fail (EXO_IS_JOB (job));
+  _thunar_return_if_fail (THUNAR_IS_TREE_VIEW (view));
+
+  /* destroy the job */
+  g_signal_handlers_disconnect_matched (job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, view);
+  g_object_unref (job);
+}
+
+
+
+static void
 thunar_tree_view_action_rename (ThunarTreeView *view)
 {
   ThunarFile *file;
   GtkWidget  *window;
+  ThunarJob  *job;
 
   _thunar_return_if_fail (THUNAR_IS_TREE_VIEW (view));
   
@@ -1665,10 +1703,15 @@
       window = gtk_widget_get_toplevel (GTK_WIDGET (view));
       
       /* run the rename dialog */
-      thunar_dialogs_show_rename_file (GTK_WINDOW (window), file);
+      job = thunar_dialogs_show_rename_file (GTK_WINDOW (window), file);
+      if (G_LIKELY (job != NULL))
+        {
+          g_signal_connect (job, "error", G_CALLBACK (thunar_tree_view_rename_error), view);
+          g_signal_connect (job, "finished", G_CALLBACK (thunar_tree_view_rename_finished), view);
+        }
       
       /* release the file */
-      g_object_unref (G_OBJECT (file));
+      g_object_unref (file);
     }
 }
 




More information about the Xfce4-commits mailing list