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

Jannis Pohlmann jannis at xfce.org
Fri Apr 24 17:26:32 CEST 2009


Author: jannis
Date: 2009-04-24 15:26:31 +0000 (Fri, 24 Apr 2009)
New Revision: 29902

Modified:
   thunar/branches/migration-to-gio/ChangeLog
   thunar/branches/migration-to-gio/thunar/thunar-enum-types.c
   thunar/branches/migration-to-gio/thunar/thunar-enum-types.h
   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-permissions-chooser.c
Log:
	* thunar/thunar-enum-types.{c,h}, thunar/thunar-file.h: Move
	  ThunarFileMode into the enum types file. Add THUNAR_TYPE_FILE_MODE
	  macro and thunar_file_mode_get_type() function which registers a
	  flags type for file modes.
	* thunar/thunar-io-jobs.{c,h}: Add new jobs
	  thunar_io_jobs_change_group() and thunar_io_jobs_change_mode().
	* thunar/thunar-permissions-chooser.c: Migrate the permissions chooser
	  to the new jobs.

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-24 11:48:30 UTC (rev 29901)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-24 15:26:31 UTC (rev 29902)
@@ -1,5 +1,16 @@
 2009-04-24	Jannis Pohlmann <jannis at xfce.org>
 
+	* thunar/thunar-enum-types.{c,h}, thunar/thunar-file.h: Move
+	  ThunarFileMode into the enum types file. Add THUNAR_TYPE_FILE_MODE
+	  macro and thunar_file_mode_get_type() function which registers a
+	  flags type for file modes.
+	* thunar/thunar-io-jobs.{c,h}: Add new jobs
+	  thunar_io_jobs_change_group() and thunar_io_jobs_change_mode().
+	* thunar/thunar-permissions-chooser.c: Migrate the permissions chooser
+	  to the new jobs.
+
+2009-04-24	Jannis Pohlmann <jannis at xfce.org>
+
 	* thunar/thunar-application, thunar/thunar-io-jobs.{c,h},
 	  thunar/thunar-job.{c,h}, thunar/thunar-transfer-job.c: Re-implement
 	  thunar_application_restore_files() based on a new job called

Modified: thunar/branches/migration-to-gio/thunar/thunar-enum-types.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-enum-types.c	2009-04-24 11:48:30 UTC (rev 29901)
+++ thunar/branches/migration-to-gio/thunar/thunar-enum-types.c	2009-04-24 15:26:31 UTC (rev 29902)
@@ -296,3 +296,36 @@
 	return type;
 }
 
+
+
+GType
+thunar_file_mode_get_type (void)
+{
+	static GType type = G_TYPE_INVALID;
+
+	if (type == G_TYPE_INVALID) 
+    {
+	    static const GFlagsValue values[] = 
+      {
+	      { THUNAR_FILE_MODE_SUID,      "THUNAR_FILE_MODE_SUID",      "suid"      },
+	      { THUNAR_FILE_MODE_SGID,      "THUNAR_FILE_MODE_SGID",      "sgid"      },
+	      { THUNAR_FILE_MODE_STICKY,    "THUNAR_FILE_MODE_STICKY",    "sticky"    },
+	      { THUNAR_FILE_MODE_USR_ALL,   "THUNAR_FILE_MODE_USR_ALL",   "usr-all"   },
+	      { THUNAR_FILE_MODE_USR_READ,  "THUNAR_FILE_MODE_USR_READ",  "usr-read"  },
+	      { THUNAR_FILE_MODE_USR_WRITE, "THUNAR_FILE_MODE_USR_WRITE", "usr-write" },
+	      { THUNAR_FILE_MODE_USR_EXEC,  "THUNAR_FILE_MODE_USR_EXEC",  "usr-exec"  },
+	      { THUNAR_FILE_MODE_GRP_ALL,   "THUNAR_FILE_MODE_GRP_ALL",   "grp-all"   },
+	      { THUNAR_FILE_MODE_GRP_READ,  "THUNAR_FILE_MODE_GRP_READ",  "grp-read"  },
+	      { THUNAR_FILE_MODE_GRP_WRITE, "THUNAR_FILE_MODE_GRP_WRITE", "grp-write" },
+	      { THUNAR_FILE_MODE_GRP_EXEC,  "THUNAR_FILE_MODE_GRP_EXEC",  "grp-exec"  },
+	      { THUNAR_FILE_MODE_OTH_ALL,   "THUNAR_FILE_MODE_OTH_ALL",   "oth-all"   },
+	      { THUNAR_FILE_MODE_OTH_READ,  "THUNAR_FILE_MODE_OTH_READ",  "oth-read"  },
+	      { THUNAR_FILE_MODE_OTH_WRITE, "THUNAR_FILE_MODE_OTH_WRITE", "oth-write" },
+	      { THUNAR_FILE_MODE_OTH_EXEC,  "THUNAR_FILE_MODE_OTH_EXEC",  "oth-exec"  },
+	      { 0,                          NULL,                         NULL        }
+	    };
+	    
+      type = g_flags_register_static ("ThunarFileMode", values);
+    }
+	return type;
+}

Modified: thunar/branches/migration-to-gio/thunar/thunar-enum-types.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-enum-types.h	2009-04-24 11:48:30 UTC (rev 29901)
+++ thunar/branches/migration-to-gio/thunar/thunar-enum-types.h	2009-04-24 15:26:31 UTC (rev 29902)
@@ -261,6 +261,35 @@
 
 GType thunar_job_response_get_type (void) G_GNUC_CONST G_GNUC_INTERNAL;
 
+
+#define THUNAR_TYPE_FILE_MODE (thunar_file_mode_get_type ())
+
+/**
+ * ThunarFileMode:
+ *
+ * Special flags and permissions of a filesystem entity.
+ **/
+typedef enum /*< flags >*/
+{
+  THUNAR_FILE_MODE_SUID       = 04000,
+  THUNAR_FILE_MODE_SGID       = 02000,
+  THUNAR_FILE_MODE_STICKY     = 01000,
+  THUNAR_FILE_MODE_USR_ALL    = 00700,
+  THUNAR_FILE_MODE_USR_READ   = 00400,
+  THUNAR_FILE_MODE_USR_WRITE  = 00200,
+  THUNAR_FILE_MODE_USR_EXEC   = 00100,
+  THUNAR_FILE_MODE_GRP_ALL    = 00070,
+  THUNAR_FILE_MODE_GRP_READ   = 00040,
+  THUNAR_FILE_MODE_GRP_WRITE  = 00020,
+  THUNAR_FILE_MODE_GRP_EXEC   = 00010,
+  THUNAR_FILE_MODE_OTH_ALL    = 00007,
+  THUNAR_FILE_MODE_OTH_READ   = 00004,
+  THUNAR_FILE_MODE_OTH_WRITE  = 00002,
+  THUNAR_FILE_MODE_OTH_EXEC   = 00001,
+} ThunarFileMode;
+
+GType thunar_file_mode_get_type (void) G_GNUC_CONST G_GNUC_INTERNAL;
+
 G_END_DECLS;
 
 #endif /* !__THUNAR_ENUM_TYPES_H__ */

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-04-24 11:48:30 UTC (rev 29901)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-04-24 15:26:31 UTC (rev 29902)
@@ -42,30 +42,6 @@
 #define THUNAR_FILE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_FILE, ThunarFileClass))
 
 /**
- * ThunarFileMode:
- *
- * Special flags and permissions of a filesystem entity.
- **/
-typedef enum /*< flags >*/
-{
-  THUNAR_FILE_MODE_SUID       = 04000,
-  THUNAR_FILE_MODE_SGID       = 02000,
-  THUNAR_FILE_MODE_STICKY     = 01000,
-  THUNAR_FILE_MODE_USR_ALL    = 00700,
-  THUNAR_FILE_MODE_USR_READ   = 00400,
-  THUNAR_FILE_MODE_USR_WRITE  = 00200,
-  THUNAR_FILE_MODE_USR_EXEC   = 00100,
-  THUNAR_FILE_MODE_GRP_ALL    = 00070,
-  THUNAR_FILE_MODE_GRP_READ   = 00040,
-  THUNAR_FILE_MODE_GRP_WRITE  = 00020,
-  THUNAR_FILE_MODE_GRP_EXEC   = 00010,
-  THUNAR_FILE_MODE_OTH_ALL    = 00007,
-  THUNAR_FILE_MODE_OTH_READ   = 00004,
-  THUNAR_FILE_MODE_OTH_WRITE  = 00002,
-  THUNAR_FILE_MODE_OTH_EXEC   = 00001,
-} ThunarFileMode;
-
-/**
  * ThunarFileDateType:
  * @THUNAR_FILE_DATE_ACCESSED : date of last access to the file.
  * @THUNAR_FILE_DATE_CHANGED  : date of last change to the file meta data or the content.

Modified: thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c	2009-04-24 11:48:30 UTC (rev 29901)
+++ thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c	2009-04-24 15:26:31 UTC (rev 29902)
@@ -24,6 +24,7 @@
 
 #include <gio/gio.h>
 
+#include <thunar/thunar-enum-types.h>
 #include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-io-scan-directory.h>
 #include <thunar/thunar-job.h>
@@ -677,3 +678,305 @@
                                                      target_file_list, 
                                                      THUNAR_TRANSFER_JOB_MOVE));
 }
+
+
+
+static gboolean
+_thunar_io_jobs_chown (ThunarJob   *job,
+                       GValueArray *param_values,
+                       GError     **error)
+{
+  ThunarJobResponse response;
+  const gchar      *message;
+  GFileInfo        *info;
+  gboolean          recursive;
+  GError           *err = NULL;
+  GList            *file_list;
+  GList            *lp;
+  gint              uid;
+  gint              gid;
+
+  _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 == 4, 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));
+  uid = g_value_get_int (g_value_array_get_nth (param_values, 1));
+  gid = g_value_get_int (g_value_array_get_nth (param_values, 2));
+  recursive = g_value_get_boolean (g_value_array_get_nth (param_values, 3));
+
+  _thunar_assert ((uid >= 0 || gid >= 0) && !(uid >= 0 && gid >= 0));
+
+  /* collect the files for the chown operation */
+  if (recursive)
+    file_list = _tij_collect_nofollow (job, file_list, &err);
+  else
+    file_list = g_file_list_copy (file_list);
+
+  if (G_UNLIKELY (err != NULL))
+    {
+      g_propagate_error (error, err);
+      return FALSE;
+    }
+
+  /* we know the total list of files to process */
+  thunar_job_set_total_files (job, file_list);
+
+  /* change the ownership of all files */
+  for (lp = file_list; lp != NULL && err == NULL; lp = lp->next)
+    {
+      /* update progress information */
+      thunar_job_processing_file (job, lp);
+
+      /* try to query information about the file */
+      info = g_file_query_info (lp->data, 
+                                G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+                                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                thunar_job_get_cancellable (job),
+                                &err);
+
+      if (G_UNLIKELY (err != NULL))
+        break;
+
+retry_chown:
+      if (uid >= 0)
+        {
+          /* try to change the owner UID */
+          g_file_set_attribute_uint32 (lp->data,
+                                       G_FILE_ATTRIBUTE_UNIX_UID, uid,
+                                       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                       thunar_job_get_cancellable (job),
+                                       &err);
+        }
+      else if (gid >= 0)
+        {
+          /* try to change the owner GID */
+          g_file_set_attribute_uint32 (lp->data,
+                                       G_FILE_ATTRIBUTE_UNIX_GID, gid,
+                                       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                       thunar_job_get_cancellable (job),
+                                       &err);
+        }
+
+      /* check if there was a recoverable error */
+      if (G_UNLIKELY (err != NULL && !thunar_job_is_cancelled (job)))
+        {
+          /* generate a useful error message */
+          message = G_LIKELY (uid >= 0) ? _("Failed to change the owner of \"%s\": %s") 
+                                        : _("Failed to change the group of \"%s\": %s");
+
+          /* ask the user whether to skip/retry this file */
+          response = thunar_job_ask_skip (job, message, 
+                                          g_file_info_get_display_name (info),
+                                          err->message);
+
+          /* clear the error */
+          g_clear_error (&err);
+
+          /* check whether to retry */
+          if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_RETRY))
+            goto retry_chown;
+        }
+
+      /* release file information */
+      g_object_unref (info);
+    }
+
+  /* release the file list */
+  g_file_list_free (file_list);
+
+  if (G_UNLIKELY (err != NULL))
+    {
+      g_propagate_error (error, err);
+      return FALSE;
+    }
+  else
+    {
+      return TRUE;
+    }
+}
+
+
+
+ThunarJob *
+thunar_io_jobs_change_group (GFile    *file,
+                             guint32   gid,
+                             gboolean  recursive)
+{
+  GList file_list;
+
+  _thunar_return_val_if_fail (G_IS_FILE (file), NULL);
+
+  file_list.data = g_object_ref (file);
+  file_list.next = NULL; 
+  file_list.prev = NULL;
+  
+  return thunar_simple_job_launch (_thunar_io_jobs_chown, 4,
+                                   G_TYPE_FILE_LIST, &file_list,
+                                   G_TYPE_INT, -1,
+                                   G_TYPE_INT, (gint) gid,
+                                   G_TYPE_BOOLEAN, recursive);
+
+  g_object_unref (file_list.data);
+}
+
+
+
+static gboolean
+_thunar_io_jobs_chmod (ThunarJob   *job,
+                       GValueArray *param_values,
+                       GError     **error)
+{
+  ThunarJobResponse response;
+  GFileInfo        *info;
+  gboolean          recursive;
+  GError           *err = NULL;
+  GList            *file_list;
+  GList            *lp;
+  ThunarFileMode    dir_mask;
+  ThunarFileMode    dir_mode;
+  ThunarFileMode    file_mask;
+  ThunarFileMode    file_mode;
+  ThunarFileMode    mask;
+  ThunarFileMode    mode;
+  ThunarFileMode    old_mode;
+  ThunarFileMode    new_mode;
+
+  _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 == 6, 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));
+  dir_mask = g_value_get_flags (g_value_array_get_nth (param_values, 1));
+  dir_mode = g_value_get_flags (g_value_array_get_nth (param_values, 2));
+  file_mask = g_value_get_flags (g_value_array_get_nth (param_values, 3));
+  file_mode = g_value_get_flags (g_value_array_get_nth (param_values, 4));
+  recursive = g_value_get_boolean (g_value_array_get_nth (param_values, 5));
+
+  /* collect the files for the chown operation */
+  if (recursive)
+    file_list = _tij_collect_nofollow (job, file_list, &err);
+  else
+    file_list = g_file_list_copy (file_list);
+
+  if (G_UNLIKELY (err != NULL))
+    {
+      g_propagate_error (error, err);
+      return FALSE;
+    }
+
+  /* we know the total list of files to process */
+  thunar_job_set_total_files (job, file_list);
+
+  /* change the ownership of all files */
+  for (lp = file_list; lp != NULL && err == NULL; lp = lp->next)
+    {
+      /* update progress information */
+      thunar_job_processing_file (job, lp);
+
+      /* try to query information about the file */
+      info = g_file_query_info (lp->data, 
+                                G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
+                                G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+                                G_FILE_ATTRIBUTE_UNIX_MODE,
+                                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                thunar_job_get_cancellable (job),
+                                &err);
+
+      if (G_UNLIKELY (err != NULL))
+        break;
+
+retry_chown:
+      /* different actions depending on the type of the file */
+      if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+        {
+          mask = dir_mask;
+          mode = dir_mode;
+        }
+      else
+        {
+          mask = file_mask;
+          mode = file_mode;
+        }
+
+      /* determine the current mode */
+      old_mode = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
+
+      /* generate the new mode, taking the old mode (which contains file type 
+       * information) into account */
+      new_mode = ((old_mode & ~mask) | mode) & 07777;
+
+      /* try to change the file mode */
+      g_file_set_attribute_uint32 (lp->data,
+                                   G_FILE_ATTRIBUTE_UNIX_MODE, new_mode,
+                                   G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                   thunar_job_get_cancellable (job),
+                                   &err);
+
+      /* check if there was a recoverable error */
+      if (G_UNLIKELY (err != NULL && !thunar_job_is_cancelled (job)))
+        {
+          /* ask the user whether to skip/retry this file */
+          response = thunar_job_ask_skip (job, 
+                                          _("Failed to change the permissions of \"%s\": %s"), 
+                                          g_file_info_get_display_name (info),
+                                          err->message);
+
+          /* clear the error */
+          g_clear_error (&err);
+
+          /* check whether to retry */
+          if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_RETRY))
+            goto retry_chown;
+        }
+
+      /* release file information */
+      g_object_unref (info);
+    }
+
+  /* release the file list */
+  g_file_list_free (file_list);
+
+  if (G_UNLIKELY (err != NULL))
+    {
+      g_propagate_error (error, err);
+      return FALSE;
+    }
+  else
+    {
+      return TRUE;
+    }
+  return TRUE;
+}
+
+
+
+ThunarJob *
+thunar_io_jobs_change_mode (GFile         *file,
+                            ThunarFileMode dir_mask,
+                            ThunarFileMode dir_mode,
+                            ThunarFileMode file_mask,
+                            ThunarFileMode file_mode,
+                            gboolean       recursive)
+{
+  GList file_list;
+
+  _thunar_return_val_if_fail (G_IS_FILE (file), NULL);
+
+  file_list.data = g_object_ref (file);
+  file_list.next = NULL; 
+  file_list.prev = NULL;
+  
+  return thunar_simple_job_launch (_thunar_io_jobs_chmod, 6,
+                                   G_TYPE_FILE_LIST, &file_list,
+                                   THUNAR_TYPE_FILE_MODE, dir_mask,
+                                   THUNAR_TYPE_FILE_MODE, dir_mode,
+                                   THUNAR_TYPE_FILE_MODE, file_mask,
+                                   THUNAR_TYPE_FILE_MODE, file_mode,
+                                   G_TYPE_BOOLEAN, recursive);
+
+  g_object_unref (file_list.data);
+}
+

Modified: thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h	2009-04-24 11:48:30 UTC (rev 29901)
+++ thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h	2009-04-24 15:26:31 UTC (rev 29902)
@@ -22,21 +22,31 @@
 #define __THUNAR_IO_JOBS_H__
 
 #include <thunar/thunar-job.h>
+#include <thunar/thunar-enum-types.h>
 
 G_BEGIN_DECLS
 
-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;
-ThunarJob *thunar_io_jobs_unlink_files     (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
-ThunarJob *thunar_io_jobs_move_files       (GList *source_file_list,
-                                            GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
-ThunarJob *thunar_io_jobs_copy_files       (GList *source_file_list,
-                                            GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
-ThunarJob *thunar_io_jobs_link_files       (GList *source_file_list,
-                                            GList *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
-ThunarJob *thunar_io_jobs_trash_files      (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
-ThunarJob *thunar_io_jobs_restore_files    (GList *source_file_list,
-                                            GList *target_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;
+ThunarJob *thunar_io_jobs_unlink_files     (GList         *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_io_jobs_move_files       (GList         *source_file_list,
+                                            GList         *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_io_jobs_copy_files       (GList         *source_file_list,
+                                            GList         *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_io_jobs_link_files       (GList         *source_file_list,
+                                            GList         *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_io_jobs_trash_files      (GList         *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_io_jobs_restore_files    (GList         *source_file_list,
+                                            GList         *target_file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_io_jobs_change_group     (GFile         *file,
+                                            guint32        gid,
+                                            gboolean       recursive) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+ThunarJob *thunar_io_jobs_change_mode      (GFile         *file,
+                                            ThunarFileMode dir_mask,
+                                            ThunarFileMode dir_mode,
+                                            ThunarFileMode file_mask,
+                                            ThunarFileMode file_mode,
+                                            gboolean       recursive) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 
 G_END_DECLS
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-permissions-chooser.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-permissions-chooser.c	2009-04-24 11:48:30 UTC (rev 29901)
+++ thunar/branches/migration-to-gio/thunar/thunar-permissions-chooser.c	2009-04-24 15:26:31 UTC (rev 29902)
@@ -36,6 +36,7 @@
 #include <thunar/thunar-enum-types.h>
 #include <thunar/thunar-gobject-extensions.h>
 #include <thunar/thunar-gtk-extensions.h>
+#include <thunar/thunar-io-jobs.h>
 #include <thunar/thunar-pango-extensions.h>
 #include <thunar/thunar-permissions-chooser.h>
 #include <thunar/thunar-preferences.h>
@@ -98,21 +99,21 @@
                                                                          GtkWidget                      *button);
 static void                 thunar_permissions_chooser_fixperm_clicked  (ThunarPermissionsChooser       *chooser,
                                                                          GtkWidget                      *button);
-static ThunarVfsJobResponse thunar_permissions_chooser_job_ask          (ThunarPermissionsChooser       *chooser,
+static ThunarJobResponse    thunar_permissions_chooser_job_ask          (ThunarPermissionsChooser       *chooser,
                                                                          const gchar                    *message,
-                                                                         ThunarVfsJobResponse            choices,
-                                                                         ThunarVfsJob                   *job);
+                                                                         ThunarJobResponse               choices,
+                                                                         ThunarJob                      *job);
 static void                 thunar_permissions_chooser_job_cancel       (ThunarPermissionsChooser       *chooser);
 static void                 thunar_permissions_chooser_job_error        (ThunarPermissionsChooser       *chooser,
                                                                          GError                         *error,
-                                                                         ThunarVfsJob                   *job);
+                                                                         ThunarJob                      *job);
 static void                 thunar_permissions_chooser_job_finished     (ThunarPermissionsChooser       *chooser,
-                                                                         ThunarVfsJob                   *job);
+                                                                         ThunarJob                      *job);
 static void                 thunar_permissions_chooser_job_percent      (ThunarPermissionsChooser       *chooser,  
                                                                          gdouble                         percent,
-                                                                         ThunarVfsJob                   *job);
+                                                                         ThunarJob                      *job);
 static void                 thunar_permissions_chooser_job_start        (ThunarPermissionsChooser       *chooser,
-                                                                         ThunarVfsJob                   *job,
+                                                                         ThunarJob                      *job,
                                                                          gboolean                        recursive);
 static gboolean             thunar_permissions_chooser_row_separator    (GtkTreeModel                   *model,
                                                                          GtkTreeIter                    *iter,
@@ -127,23 +128,23 @@
 
 struct _ThunarPermissionsChooser
 {
-  GtkVBox __parent__;
+  GtkVBox     __parent__;
 
-  ThunarFile   *file;
+  ThunarFile *file;
 
   /* the main table widget, which contains everything but the job control stuff */
-  GtkWidget    *table;
+  GtkWidget  *table;
 
-  GtkWidget    *user_label;
-  GtkWidget    *group_combo;
-  GtkWidget    *access_combos[3];
-  GtkWidget    *program_button;
-  GtkWidget    *fixperm_label;
-  GtkWidget    *fixperm_button;
+  GtkWidget  *user_label;
+  GtkWidget  *group_combo;
+  GtkWidget  *access_combos[3];
+  GtkWidget  *program_button;
+  GtkWidget  *fixperm_label;
+  GtkWidget  *fixperm_button;
 
   /* job control stuff */
-  ThunarVfsJob *job;
-  GtkWidget    *job_progress;
+  ThunarJob  *job;
+  GtkWidget  *job_progress;
 };
 
 
@@ -458,11 +459,11 @@
   if (G_UNLIKELY (chooser->job != NULL))
     {
       /* cancel the job (if not already done) */
-      thunar_vfs_job_cancel (chooser->job);
+      thunar_job_cancel (chooser->job);
 
       /* disconnect from the job */
       g_signal_handlers_disconnect_matched (chooser->job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, chooser);
-      g_object_unref (G_OBJECT (chooser->job));
+      g_object_unref (chooser->job);
       chooser->job = NULL;
     }
 
@@ -632,10 +633,9 @@
 thunar_permissions_chooser_change_group (ThunarPermissionsChooser *chooser,
                                          guint32                   gid)
 {
-  ThunarVfsJob *job;
-  gboolean      recursive = FALSE;
-  GError       *error = NULL;
-  gint          response;
+  ThunarJob *job;
+  gboolean   recursive = FALSE;
+  gint       response;
 
   _thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
   _thunar_return_if_fail (THUNAR_IS_FILE (chooser->file));
@@ -661,19 +661,9 @@
     }
 
   /* try to allocate the new job */
-  job = thunar_vfs_change_group (thunar_file_get_path (chooser->file), gid, recursive, &error);
-  if (G_UNLIKELY (job == NULL))
-    {
-      /* display an error to the user */
-      thunar_dialogs_show_error (GTK_WIDGET (chooser), error, _("Failed to change group"));
-      g_error_free (error);
-    }
-  else
-    {
-      /* handle the job */
-      thunar_permissions_chooser_job_start (chooser, job, recursive);
-      g_object_unref (G_OBJECT (job));
-    }
+  job = thunar_io_jobs_change_group (thunar_file_get_file (chooser->file), gid, recursive);
+  thunar_permissions_chooser_job_start (chooser, job, recursive);
+  g_object_unref (job);
 }
 
 
@@ -685,10 +675,9 @@
                                         ThunarFileMode            file_mask,
                                         ThunarFileMode            file_mode)
 {
-  ThunarVfsJob *job;
-  gboolean      recursive = FALSE;
-  GError       *error = NULL;
-  gint          response;
+  ThunarJob *job;
+  gboolean   recursive = FALSE;
+  gint       response;
 
   _thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
   _thunar_return_if_fail (THUNAR_IS_FILE (chooser->file));
@@ -714,19 +703,11 @@
     }
 
   /* try to allocate the new job */
-  job = thunar_vfs_change_mode (thunar_file_get_path (chooser->file), dir_mask, dir_mode, file_mask, file_mode, recursive, &error);
-  if (G_UNLIKELY (job == NULL))
-    {
-      /* display an error to the user */
-      thunar_dialogs_show_error (GTK_WIDGET (chooser), error, _("Failed to apply new permissions"));
-      g_error_free (error);
-    }
-  else
-    {
-      /* handle the job */
-      thunar_permissions_chooser_job_start (chooser, job, recursive);
-      g_object_unref (G_OBJECT (job));
-    }
+  job = thunar_io_jobs_change_mode (thunar_file_get_file (chooser->file), 
+                                    dir_mask, dir_mode, file_mask, file_mode, 
+                                    recursive);
+  thunar_permissions_chooser_job_start (chooser, job, recursive);
+  g_object_unref (G_OBJECT (job));
 }
 
 
@@ -1008,10 +989,9 @@
                                             GtkWidget                *button)
 {
   ThunarFileMode mode;
-  ThunarVfsJob  *job;
+  ThunarJob     *job;
   GtkWidget     *dialog;
   GtkWidget     *window;
-  GError        *error = NULL;
   gint           response;
 
   _thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
@@ -1055,36 +1035,29 @@
            | (((mode & THUNAR_FILE_MODE_OTH_READ) != 0) ? THUNAR_FILE_MODE_OTH_EXEC : 0);
 
       /* try to allocate the new job */
-      job = thunar_vfs_change_mode (thunar_file_get_path (chooser->file), 0511, mode, 0000, 0000, FALSE, &error);
-      if (G_UNLIKELY (job == NULL))
-        {
-          /* display an error to the user */
-          thunar_dialogs_show_error (GTK_WIDGET (chooser), error, _("Failed to apply new permissions"));
-          g_error_free (error);
-        }
-      else
-        {
-          /* handle the job */
-          thunar_permissions_chooser_job_start (chooser, job, FALSE);
-          g_object_unref (G_OBJECT (job));
-        }
+      job = thunar_io_jobs_change_mode (thunar_file_get_file (chooser->file), 
+                                        0511, mode, 0000, 0000, FALSE);
+
+      /* handle the job */
+      thunar_permissions_chooser_job_start (chooser, job, FALSE);
+      g_object_unref (job);
     }
 }
 
 
 
-static ThunarVfsJobResponse
+static ThunarJobResponse
 thunar_permissions_chooser_job_ask (ThunarPermissionsChooser *chooser,
                                     const gchar              *message,
-                                    ThunarVfsJobResponse      choices,
-                                    ThunarVfsJob             *job)
+                                    ThunarJobResponse         choices,
+                                    ThunarJob                *job)
 {
   GtkWidget *toplevel;
 
-  _thunar_return_val_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser), THUNAR_VFS_JOB_RESPONSE_CANCEL);
-  _thunar_return_val_if_fail (g_utf8_validate (message, -1, NULL), THUNAR_VFS_JOB_RESPONSE_CANCEL);
-  _thunar_return_val_if_fail (THUNAR_VFS_IS_JOB (job), THUNAR_VFS_JOB_RESPONSE_CANCEL);
-  _thunar_return_val_if_fail (chooser->job == job, THUNAR_VFS_JOB_RESPONSE_CANCEL);
+  _thunar_return_val_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser), THUNAR_JOB_RESPONSE_CANCEL);
+  _thunar_return_val_if_fail (g_utf8_validate (message, -1, NULL), THUNAR_JOB_RESPONSE_CANCEL);
+  _thunar_return_val_if_fail (THUNAR_IS_JOB (job), THUNAR_JOB_RESPONSE_CANCEL);
+  _thunar_return_val_if_fail (chooser->job == job, THUNAR_JOB_RESPONSE_CANCEL);
 
   /* be sure to display the progress bar prior to opening the question dialog */
   gtk_widget_show_now (chooser->job_progress);
@@ -1092,7 +1065,7 @@
   /* determine the toplevel window for the chooser */
   toplevel = gtk_widget_get_toplevel (GTK_WIDGET (chooser));
   if (G_UNLIKELY (toplevel == NULL))
-    return THUNAR_VFS_JOB_RESPONSE_CANCEL;
+    return THUNAR_JOB_RESPONSE_CANCEL;
 
   /* display the question dialog */
   return thunar_dialogs_show_job_ask (GTK_WINDOW (toplevel), message, choices);
@@ -1110,7 +1083,7 @@
     return;
 
   /* cancel the job (if not already done) */
-  thunar_vfs_job_cancel (chooser->job);
+  thunar_job_cancel (chooser->job);
 
   /* disconnect from the job */
   g_signal_handlers_disconnect_matched (chooser->job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, chooser);
@@ -1129,13 +1102,13 @@
 static void
 thunar_permissions_chooser_job_error (ThunarPermissionsChooser *chooser,
                                       GError                   *error,
-                                      ThunarVfsJob             *job)
+                                      ThunarJob                *job)
 {
   GtkWidget *toplevel;
   
   _thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
   _thunar_return_if_fail (error != NULL && error->message != NULL);
-  _thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
+  _thunar_return_if_fail (THUNAR_IS_JOB (job));
   _thunar_return_if_fail (chooser->job == job);
 
   /* be sure to display the progress bar prior to opening the error dialog */
@@ -1154,10 +1127,10 @@
 
 static void
 thunar_permissions_chooser_job_finished (ThunarPermissionsChooser *chooser,
-                                         ThunarVfsJob             *job)
+                                         ThunarJob                *job)
 {
   _thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
-  _thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
+  _thunar_return_if_fail (THUNAR_IS_JOB (job));
   _thunar_return_if_fail (chooser->job == job);
 
   /* we can just use job_cancel(), since the job is already done */
@@ -1169,10 +1142,10 @@
 static void
 thunar_permissions_chooser_job_percent (ThunarPermissionsChooser *chooser,  
                                         gdouble                   percent,
-                                        ThunarVfsJob             *job)
+                                        ThunarJob                *job)
 {
   _thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
-  _thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
+  _thunar_return_if_fail (THUNAR_IS_JOB (job));
   _thunar_return_if_fail (chooser->job == job);
 
   gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (chooser->job_progress), percent / 100.0);
@@ -1183,22 +1156,22 @@
 
 static void
 thunar_permissions_chooser_job_start (ThunarPermissionsChooser *chooser,
-                                      ThunarVfsJob             *job,
+                                      ThunarJob                *job,
                                       gboolean                  recursive)
 {
   _thunar_return_if_fail (THUNAR_IS_PERMISSIONS_CHOOSER (chooser));
-  _thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
+  _thunar_return_if_fail (THUNAR_IS_JOB (job));
   _thunar_return_if_fail (chooser->job == NULL);
 
   /* take a reference to the job and connect signals */
-  chooser->job = g_object_ref (G_OBJECT (job));
-  g_signal_connect_swapped (G_OBJECT (job), "ask", G_CALLBACK (thunar_permissions_chooser_job_ask), chooser);
-  g_signal_connect_swapped (G_OBJECT (job), "error", G_CALLBACK (thunar_permissions_chooser_job_error), chooser);
-  g_signal_connect_swapped (G_OBJECT (job), "finished", G_CALLBACK (thunar_permissions_chooser_job_finished), chooser);
+  chooser->job = g_object_ref (job);
+  g_signal_connect_swapped (job, "ask", G_CALLBACK (thunar_permissions_chooser_job_ask), chooser);
+  g_signal_connect_swapped (job, "error", G_CALLBACK (thunar_permissions_chooser_job_error), chooser);
+  g_signal_connect_swapped (job, "finished", G_CALLBACK (thunar_permissions_chooser_job_finished), chooser);
 
   /* don't connect percent for single file operations */
   if (G_UNLIKELY (recursive))
-    g_signal_connect_swapped (G_OBJECT (job), "percent", G_CALLBACK (thunar_permissions_chooser_job_percent), chooser);
+    g_signal_connect_swapped (job, "percent", G_CALLBACK (thunar_permissions_chooser_job_percent), chooser);
   
   /* setup the progress bar */
   gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (chooser->job_progress), 0.0);




More information about the Xfce4-commits mailing list