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

Jannis Pohlmann jannis at xfce.org
Tue Apr 21 15:33:08 CEST 2009


Author: jannis
Date: 2009-04-21 13:33:08 +0000 (Tue, 21 Apr 2009)
New Revision: 29878

Modified:
   thunar/branches/migration-to-gio/ChangeLog
   thunar/branches/migration-to-gio/thunar/thunar-application.c
   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-location-buttons.c
   thunar/branches/migration-to-gio/thunar/thunar-standard-view.c
   thunar/branches/migration-to-gio/thunar/thunar-tree-view.c
Log:
	* thunar/thunar-application.c, thunar/thunar-io-jobs.{c,h},
	  thunar/thunar-location-buttons.c, thunar/thunar-standard-view.c,
	  thunar/thunar-tree-view.c: Add new simple job
	  thunar_io_jobs_make_directories(). Rename all I/O job functions from
	  thunar_io_job_*() to thunar_io_jobs*(). Use the make directories job
	  in thunar_application_mkdir() and modify mkdir_stub() according to
	  this. Pass a GFile list to thunar_application_mkdir() in
	  ThunarLocationButtons, ThunarStandardView and ThunarTreeView.

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-21 12:28:17 UTC (rev 29877)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-21 13:33:08 UTC (rev 29878)
@@ -1,5 +1,16 @@
 2009-04-21	Jannis Pohlmann <jannis at xfce.org>
 
+	* thunar/thunar-application.c, thunar/thunar-io-jobs.{c,h},
+	  thunar/thunar-location-buttons.c, thunar/thunar-standard-view.c,
+	  thunar/thunar-tree-view.c: Add new simple job
+	  thunar_io_jobs_make_directories(). Rename all I/O job functions from
+	  thunar_io_job_*() to thunar_io_jobs*(). Use the make directories job
+	  in thunar_application_mkdir() and modify mkdir_stub() according to
+	  this. Pass a GFile list to thunar_application_mkdir() in 
+	  ThunarLocationButtons, ThunarStandardView and ThunarTreeView.
+
+2009-04-21	Jannis Pohlmann <jannis at xfce.org>
+
 	* thunar/Makefile.am, thunar/thunar-io-jobs.{c,h},
 	  thunar/thunar-simple.job.{c,h}: Add ThunarSimpleJob class which is
 	  equivalent to ThunarVfsSimpleJob. Add the first simple job by

Modified: thunar/branches/migration-to-gio/thunar/thunar-application.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-application.c	2009-04-21 12:28:17 UTC (rev 29877)
+++ thunar/branches/migration-to-gio/thunar/thunar-application.c	2009-04-21 13:33:08 UTC (rev 29878)
@@ -1491,7 +1491,7 @@
 creat_stub (GList *source_path_list,
             GList *target_path_list)
 {
-  return thunar_io_job_create_files (source_path_list);
+  return thunar_io_jobs_create_files (source_path_list);
 }
 
 
@@ -1526,12 +1526,11 @@
 
 
 
-static ThunarVfsJob*
-mkdir_stub (GList   *source_path_list,
-            GList   *target_path_list,
-            GError **error)
+static ThunarJob*
+mkdir_stub (GList *source_path_list,
+            GList *target_path_list)
 {
-  return thunar_vfs_make_directories (source_path_list, error);
+  return thunar_io_jobs_make_directories (source_path_list);
 }
 
 
@@ -1559,9 +1558,9 @@
   _thunar_return_if_fail (THUNAR_IS_APPLICATION (application));
 
   /* launch the operation */
-  thunar_application_launch (application, parent, "stock_folder",
-                             _("Creating directories..."), mkdir_stub,
-                             path_list, path_list, new_files_closure);
+  thunar_application_launch_job (application, parent, "stock_folder",
+                                 _("Creating directories..."), mkdir_stub,
+                                 path_list, path_list, new_files_closure);
 }
 
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c	2009-04-21 12:28:17 UTC (rev 29877)
+++ thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c	2009-04-21 13:33:08 UTC (rev 29878)
@@ -32,7 +32,7 @@
 
 
 static gboolean
-_thunar_io_job_create (ThunarJob   *job,
+_thunar_io_jobs_create (ThunarJob   *job,
                        GValueArray *param_values,
                        GError     **error)
 {
@@ -128,7 +128,7 @@
             {
               /* determine display name of the file */
               basename = g_file_get_basename (lp->data);
-              display_name = g_filename_display_basename (lp->data);
+              display_name = g_filename_display_basename (basename);
               g_free (basename);
 
               /* ask the user whether to skip/retry this path (cancels the job if not) */
@@ -136,6 +136,9 @@
                                               display_name, err->message);
               g_free (display_name);
 
+              g_error_free (err);
+              err = NULL;
+
               /* go back to the beginning if the user wants to retry */
               if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_RETRY))
                 goto again;
@@ -166,8 +169,143 @@
 
 
 ThunarJob *
-thunar_io_job_create_files (GList *file_list)
+thunar_io_jobs_create_files (GList *file_list)
 {
-  return thunar_simple_job_launch (_thunar_io_job_create, 1,
+  return thunar_simple_job_launch (_thunar_io_jobs_create, 1,
                                    G_TYPE_FILE_LIST, file_list);
 }
+
+
+
+static gboolean
+_thunar_io_jobs_mkdir (ThunarJob   *job,
+                       GValueArray *param_values,
+                       GError     **error)
+{
+  ThunarJobResponse response;
+  GFileInfo        *info;
+  GError           *err = NULL;
+  GList            *file_list;
+  GList            *lp;
+  gchar            *basename;
+  gchar            *display_name;
+
+  _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 > 0, FALSE);
+  _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  file_list = g_value_get_boxed (g_value_array_get_nth (param_values, 0));
+
+  /* we know the total list of files to process */
+  thunar_job_set_total_files (job, file_list);
+
+  for (lp = file_list; 
+       err == NULL && lp != NULL && !thunar_job_is_cancelled (job);
+       lp = lp->next)
+    {
+      g_assert (G_IS_FILE (lp->data));
+
+      /* update progress information */
+      thunar_job_processing_file (job, lp);
+
+again:
+      /* try to create the directory */
+      if (!g_file_make_directory (lp->data, thunar_job_get_cancellable (job), &err))
+        {
+          if (err->code == G_IO_ERROR_EXISTS)
+            {
+              g_error_free (err);
+              err = NULL;
+
+              /* abort if the job was cancelled */
+              if (thunar_job_is_cancelled (job))
+                break;
+
+              /* the file already exists, query its display name */
+              info = g_file_query_info (lp->data,
+                                        G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+                                        G_FILE_QUERY_INFO_NONE,
+                                        thunar_job_get_cancellable (job),
+                                        NULL);
+
+              /* abort if the job was cancelled */
+              if (thunar_job_is_cancelled (job))
+                break;
+
+              /* determine the display name, using the basename as a fallback */
+              if (info != NULL)
+                {
+                  display_name = g_strdup (g_file_info_get_display_name (info));
+                  g_object_unref (info);
+                }
+              else
+                {
+                  basename = g_file_get_basename (lp->data);
+                  display_name = g_filename_display_name (basename);
+                  g_free (basename);
+                }
+
+              /* ask the user whether he wants to overwrite the existing file */
+              response = thunar_job_ask_overwrite (job, _("The file \"%s\" already exists"),
+                                                   display_name);
+
+              /* check if we should overwrite it */
+              if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_YES))
+                {
+                  /* try to remove the file, fail if not possible */
+                  if (g_file_delete (lp->data, thunar_job_get_cancellable (job), &err))
+                    goto again;
+                }
+
+              /* clean up */
+              g_free (display_name);
+            }
+          else
+            {
+              /* determine the display name of the file */
+              basename = g_file_get_basename (lp->data);
+              display_name = g_filename_display_basename (basename);
+              g_free (basename);
+
+              /* ask the user whether to skip/retry this path (cancels the job if not) */
+              response = thunar_job_ask_skip (job, _("Failed to create directory \"%s\": %s"),
+                                              display_name, err->message);
+              g_free (display_name);
+
+              g_error_free (err);
+              err = NULL;
+
+              /* go back to the beginning if the user wants to retry */
+              if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_RETRY))
+                goto again;
+            }
+        }
+    }
+
+  /* check if we have failed */
+  if (G_UNLIKELY (err != NULL))
+    {
+      g_propagate_error (error, err);
+      return FALSE;
+    }
+
+  /* check if the job was cancelled */
+  if (G_UNLIKELY (thunar_job_is_cancelled (job)))
+    return FALSE;
+
+  /* TODO emit the "new-files" signal with the given file list 
+  thunar_job_new_files (job, file_list);
+  */
+
+  return TRUE;
+}
+
+
+
+ThunarJob *
+thunar_io_jobs_make_directories (GList *file_list)
+{
+  return thunar_simple_job_launch (_thunar_io_jobs_mkdir, 1,
+                                   G_TYPE_FILE_LIST, file_list);
+}

Modified: thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h	2009-04-21 12:28:17 UTC (rev 29877)
+++ thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h	2009-04-21 13:33:08 UTC (rev 29878)
@@ -25,7 +25,8 @@
 
 G_BEGIN_DECLS
 
-ThunarJob *thunar_io_job_create_files (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_io_jobs_create_files     (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_io_jobs_make_directories (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 
 G_END_DECLS
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-location-buttons.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-location-buttons.c	2009-04-21 12:28:17 UTC (rev 29877)
+++ thunar/branches/migration-to-gio/thunar/thunar-location-buttons.c	2009-04-21 13:33:08 UTC (rev 29878)
@@ -1340,7 +1340,7 @@
   if (G_LIKELY (name != NULL))
     {
       /* fake the path list */
-      path_list.data = thunar_vfs_path_relative (thunar_file_get_path (directory), name);
+      path_list.data = g_file_resolve_relative_path (thunar_file_get_file (directory), name);
       path_list.next = path_list.prev = NULL;
 
       /* launch the operation */
@@ -1349,7 +1349,7 @@
       g_object_unref (G_OBJECT (application));
 
       /* release the path */
-      thunar_vfs_path_unref (path_list.data);
+      g_object_unref (path_list.data);
 
       /* release the file name */
       g_free (name);

Modified: thunar/branches/migration-to-gio/thunar/thunar-standard-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-standard-view.c	2009-04-21 12:28:17 UTC (rev 29877)
+++ thunar/branches/migration-to-gio/thunar/thunar-standard-view.c	2009-04-21 13:33:08 UTC (rev 29878)
@@ -1850,7 +1850,7 @@
       if (G_LIKELY (current_directory != NULL))
         {
           /* fake the path list */
-          path_list.data = thunar_vfs_path_relative (thunar_file_get_path (current_directory), name);
+          path_list.data = g_file_resolve_relative_path (thunar_file_get_file (current_directory), name);
           path_list.next = path_list.prev = NULL;
 
           /* launch the operation */
@@ -1860,7 +1860,7 @@
           g_object_unref (G_OBJECT (application));
 
           /* release the path */
-          thunar_vfs_path_unref (path_list.data);
+          g_object_unref (path_list.data);
         }
 
       /* release the file name */

Modified: thunar/branches/migration-to-gio/thunar/thunar-tree-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-tree-view.c	2009-04-21 12:28:17 UTC (rev 29877)
+++ thunar/branches/migration-to-gio/thunar/thunar-tree-view.c	2009-04-21 13:33:08 UTC (rev 29878)
@@ -1544,7 +1544,7 @@
   if (G_LIKELY (name != NULL))
     {
       /* fake the path list */
-      path_list.data = thunar_vfs_path_relative (thunar_file_get_path (directory), name);
+      path_list.data = g_file_resolve_relative_path (thunar_file_get_file (directory), name);
       path_list.next = path_list.prev = NULL;
 
       /* launch the operation */
@@ -1553,7 +1553,7 @@
       g_object_unref (G_OBJECT (application));
 
       /* release the path */
-      thunar_vfs_path_unref (path_list.data);
+      g_object_unref (path_list.data);
 
       /* release the file name */
       g_free (name);




More information about the Xfce4-commits mailing list