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

Jannis Pohlmann jannis at xfce.org
Tue Apr 21 14:28:18 CEST 2009


Author: jannis
Date: 2009-04-21 12:28:17 +0000 (Tue, 21 Apr 2009)
New Revision: 29877

Added:
   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-simple-job.c
   thunar/branches/migration-to-gio/thunar/thunar-simple-job.h
Modified:
   thunar/branches/migration-to-gio/ChangeLog
   thunar/branches/migration-to-gio/thunar/Makefile.am
   thunar/branches/migration-to-gio/thunar/thunar-application.c
   thunar/branches/migration-to-gio/thunar/thunar-job.c
   thunar/branches/migration-to-gio/thunar/thunar-job.h
   thunar/branches/migration-to-gio/thunar/thunar-standard-view.c
Log:
	* 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
	  implementing thunar_io_job_create_files() as an equivalent to
	  thunar_vfs_create_files(). The "new-files" signal is not implemented
	  yet because it would break the new_files_closure.
	* thunar/thunar-application.c: Add JobLauncher function pointer type
	  as an equivalent to Launcher. Add thunar_application_launch_job() as
	  an equivalent to thunar_application_launch() based on ThunarJob
	  instead of ThunarVfsJob. Modify creat_stub() according to this. Use
	  thunar_application_launch_job() in thunar_application_creat().
	* thunar/thunar-job.{c,h}: Implement thunar_job_ask_skip().
	* thunar/thunar-standard-view.c: Pass a GFile list instaed of a
	  ThunarVfsPath list to thunar_application_creat().

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-21 11:23:09 UTC (rev 29876)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-21 12:28:17 UTC (rev 29877)
@@ -1,5 +1,22 @@
 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
+	  implementing thunar_io_job_create_files() as an equivalent to
+	  thunar_vfs_create_files(). The "new-files" signal is not implemented
+	  yet because it would break the new_files_closure.
+	* thunar/thunar-application.c: Add JobLauncher function pointer type
+	  as an equivalent to Launcher. Add thunar_application_launch_job() as
+	  an equivalent to thunar_application_launch() based on ThunarJob
+	  instead of ThunarVfsJob. Modify creat_stub() according to this. Use
+	  thunar_application_launch_job() in thunar_application_creat().
+	* thunar/thunar-job.{c,h}: Implement thunar_job_ask_skip().
+	* thunar/thunar-standard-view.c: Pass a GFile list instaed of a
+	  ThunarVfsPath list to thunar_application_creat().
+
+2009-04-21	Jannis Pohlmann <jannis at xfce.org>
+
 	* thunar/thunar-enum-types.c: Remove vfs_ from
 	  thunar_vfs_job_response_get_type().
 	* thunar/thunar-gio-extensions.c: Include exo.h for the I_() macro.

Modified: thunar/branches/migration-to-gio/thunar/Makefile.am
===================================================================
--- thunar/branches/migration-to-gio/thunar/Makefile.am	2009-04-21 11:23:09 UTC (rev 29876)
+++ thunar/branches/migration-to-gio/thunar/Makefile.am	2009-04-21 12:28:17 UTC (rev 29877)
@@ -96,6 +96,8 @@
 	thunar-icon-renderer.h						\
 	thunar-icon-view.c						\
 	thunar-icon-view.h						\
+	thunar-io-jobs.c						\
+	thunar-io-jobs.h						\
 	thunar-job.c							\
 	thunar-job.h							\
 	thunar-launcher.c						\
@@ -157,6 +159,8 @@
 	thunar-shortcuts-view.h						\
 	thunar-side-pane.c						\
 	thunar-side-pane.h						\
+	thunar-simple-job.c						\
+	thunar-simple-job.h						\
 	thunar-size-label.c						\
 	thunar-size-label.h						\
 	thunar-standard-view.c						\

Modified: thunar/branches/migration-to-gio/thunar/thunar-application.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-application.c	2009-04-21 11:23:09 UTC (rev 29876)
+++ thunar/branches/migration-to-gio/thunar/thunar-application.c	2009-04-21 12:28:17 UTC (rev 29877)
@@ -2,6 +2,7 @@
 /*-
  * Copyright (c) 2005-2007 Benedikt Meurer <benny at xfce.org>
  * Copyright (c) 2005      Jeff Franks <jcfranks at xfce.org>
+ * Copyright (c) 2009      Jannis Pohlmann <jannis at xfce.org>
  *
  * 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
@@ -39,6 +40,7 @@
 #include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-gdk-extensions.h>
 #include <thunar/thunar-gobject-extensions.h>
+#include <thunar/thunar-io-jobs.h>
 #include <thunar/thunar-preferences.h>
 #include <thunar/thunar-private.h>
 #include <thunar/thunar-progress-dialog.h>
@@ -52,8 +54,12 @@
                                    GList   *target_path_list,
                                    GError **error);
 
+/* Prototype for the Thunar job launchers */
+typedef ThunarJob *(*JobLauncher) (GList  *source_path_list,
+                                   GList  *target_path_list);
 
 
+
 /* Property identifiers */
 enum
 {
@@ -90,6 +96,14 @@
                                                              GList                  *source_path_list,
                                                              GList                  *target_path_list,
                                                              GClosure               *new_files_closure);
+static void       thunar_application_launch_job             (ThunarApplication      *application,
+                                                             gpointer                parent,
+                                                             const gchar            *icon_name,
+                                                             const gchar            *title,
+                                                             JobLauncher             launcher,
+                                                             GList                  *source_path_list,
+                                                             GList                  *target_path_list,
+                                                             GClosure               *new_files_closure);
 static GtkWidget *thunar_application_open_window_with_role  (ThunarApplication      *application,
                                                              const gchar            *role,
                                                              ThunarFile             *directory,
@@ -495,6 +509,67 @@
 
 
 
+static void
+thunar_application_launch_job (ThunarApplication *application,
+                               gpointer           parent,
+                               const gchar       *icon_name,
+                               const gchar       *title,
+                               JobLauncher        launcher,
+                               GList             *source_path_list,
+                               GList             *target_path_list,
+                               GClosure          *new_files_closure)
+{
+  ThunarJob *job;
+  GtkWindow *window;
+  GtkWidget *dialog;
+  GdkScreen *screen;
+
+  _thunar_return_if_fail (parent == NULL || GDK_IS_SCREEN (parent) || GTK_IS_WIDGET (parent));
+
+  /* parse the parent pointer */
+  screen = thunar_util_parse_parent (parent, &window);
+
+  /* try to allocate a new job for the operation */
+  job = (*launcher) (source_path_list, target_path_list);
+    
+  /* TODO connect the "new-files" closure (if any)
+  if (G_LIKELY (new_files_closure != NULL))
+    g_signal_connect_closure (G_OBJECT (job), "new-files", new_files_closure, FALSE);
+  */
+
+  /* allocate a progress dialog for the job */
+  dialog = g_object_new (THUNAR_TYPE_PROGRESS_DIALOG,
+                         "icon-name", icon_name,
+                         "title", title,
+                         "job", job,
+                         "screen", screen,
+                         NULL);
+
+  /* connect to the parent (if any) */
+  if (G_LIKELY (window != NULL))
+    gtk_window_set_transient_for (GTK_WINDOW (dialog), window);
+
+  /* be sure to destroy the dialog when the job is done */
+  g_signal_connect_after (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), dialog);
+
+  /* hook up the dialog window */
+  thunar_application_take_window (application, GTK_WINDOW (dialog));
+
+  /* Set up a timer to show the dialog, to make sure we don't
+   * just popup and destroy a dialog for a very short job.
+   */
+  if (G_LIKELY (application->show_dialogs_timer_id == 0))
+    {
+      application->show_dialogs_timer_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 750, thunar_application_show_dialogs,
+                                                               application, thunar_application_show_dialogs_destroy);
+    }
+
+  /* drop our reference on the job */
+  g_object_unref (job);
+}
+
+
+
 static GtkWidget*
 thunar_application_open_window_with_role (ThunarApplication *application,
                                           const gchar       *role,
@@ -1412,12 +1487,11 @@
 
 
 
-static ThunarVfsJob*
-creat_stub (GList   *source_path_list,
-            GList   *target_path_list,
-            GError **error)
+static ThunarJob*
+creat_stub (GList *source_path_list,
+            GList *target_path_list)
 {
-  return thunar_vfs_create_files (source_path_list, error);
+  return thunar_io_job_create_files (source_path_list);
 }
 
 
@@ -1443,11 +1517,11 @@
 {
   _thunar_return_if_fail (parent == NULL || GDK_IS_SCREEN (parent) || GTK_IS_WIDGET (parent));
   _thunar_return_if_fail (THUNAR_IS_APPLICATION (application));
-
+  
   /* launch the operation */
-  thunar_application_launch (application, parent, "stock_new",
-                             _("Creating files..."), creat_stub,
-                             path_list, path_list, new_files_closure);
+  thunar_application_launch_job (application, parent, "stock_new",
+                                 _("Creating files..."), creat_stub,
+                                 path_list, path_list, new_files_closure);
 }
 
 

Added: thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c	                        (rev 0)
+++ thunar/branches/migration-to-gio/thunar/thunar-io-jobs.c	2009-04-21 12:28:17 UTC (rev 29877)
@@ -0,0 +1,173 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * 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
+
+#include <gio/gio.h>
+
+#include <thunar/thunar-gio-extensions.h>
+#include <thunar/thunar-job.h>
+#include <thunar/thunar-private.h>
+#include <thunar/thunar-simple-job.h>
+
+
+
+static gboolean
+_thunar_io_job_create (ThunarJob   *job,
+                       GValueArray *param_values,
+                       GError     **error)
+{
+  GFileOutputStream *stream;
+  ThunarJobResponse  response = THUNAR_JOB_RESPONSE_CANCEL;
+  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);
+
+  /* get the file list */
+  file_list = g_value_get_boxed (g_value_array_get_nth (param_values, 0));
+
+  /* we know the total amount of files to be processed */
+  thunar_job_set_total_files (job, file_list);
+
+  /* iterate over all files in the 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 file */
+      stream = g_file_create (lp->data, 
+                              G_FILE_CREATE_NONE, 
+                              thunar_job_get_cancellable (job),
+                              &err);
+
+      /* abort if the job was cancelled */
+      if (thunar_job_is_cancelled (job))
+        break;
+
+      /* check if creating failed */
+      if (stream == NULL)
+        {
+          if (err->code == G_IO_ERROR_EXISTS)
+            {
+              g_error_free (err);
+              err = NULL;
+
+              /* 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 */
+              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 display name of the file */
+              basename = g_file_get_basename (lp->data);
+              display_name = g_filename_display_basename (lp->data);
+              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 empty file \"%s\": %s"),
+                                              display_name, err->message);
+              g_free (display_name);
+
+              /* go back to the beginning if the user wants to retry */
+              if (G_UNLIKELY (response == THUNAR_JOB_RESPONSE_RETRY))
+                goto again;
+            }
+        }
+      else
+        g_object_unref (stream);
+    }
+
+  /* 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_job_create_files (GList *file_list)
+{
+  return thunar_simple_job_launch (_thunar_io_job_create, 1,
+                                   G_TYPE_FILE_LIST, file_list);
+}

Added: thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h	                        (rev 0)
+++ thunar/branches/migration-to-gio/thunar/thunar-io-jobs.h	2009-04-21 12:28:17 UTC (rev 29877)
@@ -0,0 +1,32 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * 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_IO_JOBS_H__
+#define __THUNAR_IO_JOBS_H__
+
+#include <thunar/thunar-job.h>
+
+G_BEGIN_DECLS
+
+ThunarJob *thunar_io_job_create_files (GList *file_list) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+
+G_END_DECLS
+
+#endif /* !__THUNAR_IO_JOBS_H__ */

Modified: thunar/branches/migration-to-gio/thunar/thunar-job.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-job.c	2009-04-21 11:23:09 UTC (rev 29876)
+++ thunar/branches/migration-to-gio/thunar/thunar-job.c	2009-04-21 12:28:17 UTC (rev 29877)
@@ -81,6 +81,7 @@
 struct _ThunarJobPrivate
 {
   ThunarJobResponse earlier_ask_overwrite_response;
+  ThunarJobResponse earlier_ask_skip_response;
   GIOSchedulerJob  *scheduler_job;
   GCancellable     *cancellable;
   GList            *total_files;
@@ -248,6 +249,8 @@
 {
   job->priv = THUNAR_JOB_GET_PRIVATE (job);
   job->priv->cancellable = g_cancellable_new ();
+  job->priv->earlier_ask_overwrite_response = 0;
+  job->priv->earlier_ask_skip_response = 0;
   job->priv->running = FALSE;
   job->priv->scheduler_job = NULL;
 }
@@ -582,6 +585,59 @@
 
 
 
+ThunarJobResponse 
+thunar_job_ask_skip (ThunarJob   *job,
+                     const gchar *format,
+                     ...)
+{
+  ThunarJobResponse response;
+  va_list           var_args;
+  
+  _thunar_return_val_if_fail (THUNAR_IS_JOB (job), THUNAR_JOB_RESPONSE_CANCEL);
+  _thunar_return_val_if_fail (format != NULL, THUNAR_JOB_RESPONSE_CANCEL);
+
+  /* check if the user already cancelled the job */
+  if (G_UNLIKELY (thunar_job_is_cancelled (job)))
+    return THUNAR_JOB_RESPONSE_CANCEL;
+
+  /* check if the user said "Skip All" earlier */
+  if (G_UNLIKELY (job->priv->earlier_ask_skip_response == THUNAR_JOB_RESPONSE_YES_ALL))
+    return THUNAR_JOB_RESPONSE_YES;
+
+  /* ask the user what he wants to do */
+  va_start (var_args, format);
+  response = _thunar_job_ask_valist (job, format, var_args,
+                                     _("Do you want to skip it?"),
+                                     THUNAR_JOB_RESPONSE_YES 
+                                     | THUNAR_JOB_RESPONSE_YES_ALL
+                                     | THUNAR_JOB_RESPONSE_CANCEL
+                                     | THUNAR_JOB_RESPONSE_RETRY);
+  va_end (var_args);
+
+  /* remember the response */
+  job->priv->earlier_ask_skip_response = response;
+
+  /* translate the response */
+  switch (response)
+    {
+    case THUNAR_JOB_RESPONSE_YES_ALL:
+      response = THUNAR_JOB_RESPONSE_YES;
+      break;
+
+    case THUNAR_JOB_RESPONSE_YES:
+    case THUNAR_JOB_RESPONSE_CANCEL:
+    case THUNAR_JOB_RESPONSE_RETRY:
+      break;
+
+    default:
+      _thunar_assert_not_reached ();
+    }
+
+  return response;
+}
+
+
+
 void
 thunar_job_info_message (ThunarJob   *job,
                          const gchar *message)
@@ -612,7 +668,6 @@
 {
   _thunar_return_if_fail (THUNAR_IS_JOB (job));
   _thunar_return_if_fail (error != NULL);
-  _thunar_return_if_fail (g_utf8_validate (error->message, -1, NULL));
 
   g_signal_emit (job, job_signals[ERROR], 0, error);
 }

Modified: thunar/branches/migration-to-gio/thunar/thunar-job.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-job.h	2009-04-21 11:23:09 UTC (rev 29876)
+++ thunar/branches/migration-to-gio/thunar/thunar-job.h	2009-04-21 12:28:17 UTC (rev 29877)
@@ -85,6 +85,9 @@
 ThunarJobResponse thunar_job_ask_overwrite          (ThunarJob       *job,
                                                      const gchar     *format,
                                                      ...);
+ThunarJobResponse thunar_job_ask_skip               (ThunarJob       *job,
+                                                     const gchar     *format,
+                                                     ...);
 void              thunar_job_info_message           (ThunarJob       *job,
                                                      const gchar     *message);
 void              thunar_job_percent                (ThunarJob       *job,

Added: thunar/branches/migration-to-gio/thunar/thunar-simple-job.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-simple-job.c	                        (rev 0)
+++ thunar/branches/migration-to-gio/thunar/thunar-simple-job.c	2009-04-21 12:28:17 UTC (rev 29877)
@@ -0,0 +1,224 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2006 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_MEMORY_H
+#include <memory.h>
+#endif
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <gobject/gvaluecollector.h>
+
+#include <thunar/thunar-job.h>
+#include <thunar/thunar-private.h>
+#include <thunar/thunar-simple-job.h>
+
+
+
+static void     thunar_simple_job_class_init (ThunarSimpleJobClass *klass);
+static void     thunar_simple_job_finalize   (GObject              *object);
+static gboolean thunar_simple_job_execute    (ThunarJob            *job,
+                                              GError              **error);
+
+
+
+struct _ThunarSimpleJobClass
+{
+  ThunarJobClass __parent__;
+};
+
+struct _ThunarSimpleJob
+{
+  ThunarJob           __parent__;
+  ThunarSimpleJobFunc func;
+  GValueArray        *param_values;
+};
+
+
+
+static GObjectClass *thunar_simple_job_parent_class;
+
+
+
+GType
+thunar_simple_job_get_type (void)
+{
+  static GType type = G_TYPE_INVALID;
+
+  if (G_UNLIKELY (type == G_TYPE_INVALID))
+    {
+      type = g_type_register_static_simple (THUNAR_TYPE_JOB, 
+                                            "ThunarSimpleJob",
+                                            sizeof (ThunarSimpleJobClass),
+                                            (GClassInitFunc) thunar_simple_job_class_init,
+                                            sizeof (ThunarSimpleJob),
+                                            NULL, 
+                                            0);
+    }
+
+  return type;
+}
+
+
+
+static void
+thunar_simple_job_class_init (ThunarSimpleJobClass *klass)
+{
+  ThunarJobClass *thunarjob_class;
+  GObjectClass   *gobject_class;
+
+  /* determine the parent type class */
+  thunar_simple_job_parent_class = g_type_class_peek_parent (klass);
+
+  gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->finalize = thunar_simple_job_finalize;
+
+  thunarjob_class = THUNAR_JOB_CLASS (klass);
+  thunarjob_class->execute = thunar_simple_job_execute;
+}
+
+
+
+static void
+thunar_simple_job_finalize (GObject *object)
+{
+  ThunarSimpleJob *simple_job = THUNAR_SIMPLE_JOB (object);
+
+  /* release the param values */
+  g_value_array_free (simple_job->param_values);
+
+  (*G_OBJECT_CLASS (thunar_simple_job_parent_class)->finalize) (object);
+}
+
+
+
+static gboolean
+thunar_simple_job_execute (ThunarJob *job,
+                           GError  **error)
+{
+  ThunarSimpleJob *simple_job = THUNAR_SIMPLE_JOB (job);
+  gboolean         success = TRUE;
+  GError          *err = NULL;
+
+  _thunar_return_val_if_fail (THUNAR_IS_SIMPLE_JOB (job), FALSE);
+  _thunar_return_val_if_fail (simple_job->func != NULL, FALSE);
+
+  /* try to execute the job using the supplied function */
+  success = (*simple_job->func) (job, simple_job->param_values, &err);
+
+  if (!success)
+    {
+      g_assert (err != NULL || thunar_job_is_cancelled (job));
+
+      /* set error if the job was cancelled. otherwise just propagate 
+       * the results of the processing function */
+      if (thunar_job_set_error_if_cancelled (job, error))
+        {
+          if (err != NULL)
+            g_error_free (err);
+        }
+      else
+        {
+          if (err != NULL)
+            g_propagate_error (error, err);
+        }
+
+      return FALSE;
+    }
+  else
+    return TRUE;
+}
+
+
+
+/**
+ * thunar_simple_job_launch:
+ * @func           : the #ThunarSimpleJobFunc to execute the job.
+ * @n_param_values : the number of parameters to pass to the @func.
+ * @...            : a list of #GType and parameter pairs (exactly
+ *                   @n_param_values pairs) that are passed to @func.
+ *
+ * Allocates a new #ThunarSimpleJob, which executes the specified
+ * @func with the specified parameters.
+ *
+ * For example the listdir @func expects a #ThunarPath for the
+ * folder to list, so the call to thunar_simple_job_launch()
+ * would look like this:
+ *
+ * <informalexample><programlisting>
+ * thunar_simple_job_launch (_thunar_io_jobs_listdir, 1,
+ *                               THUNAR_TYPE_PATH, path);
+ * </programlisting></informalexample>
+ *
+ * The caller is responsible to release the returned object using
+ * thunar_job_unref() when no longer needed.
+ *
+ * Return value: the launched #ThunarJob.
+ **/
+ThunarJob*
+thunar_simple_job_launch (ThunarSimpleJobFunc func,
+                          guint               n_param_values,
+                          ...)
+{
+  ThunarSimpleJob *simple_job;
+  va_list          var_args;
+  GValue           value = { 0, };
+  gchar           *error_message;
+  gint             n;
+
+  /* allocate and initialize the simple job */
+  simple_job = g_object_new (THUNAR_TYPE_SIMPLE_JOB, NULL);
+  simple_job->func = func;
+  simple_job->param_values = g_value_array_new (n_param_values);
+
+  /* collect the parameters */
+  va_start (var_args, n_param_values);
+  for (n = 0; n < n_param_values; ++n)
+    {
+      /* initialize the value to hold the next parameter */
+      g_value_init (&value, va_arg (var_args, GType));
+
+      /* collect the value from the stack */
+      G_VALUE_COLLECT (&value, var_args, 0, &error_message);
+
+      /* check if an error occurred */
+      if (G_UNLIKELY (error_message != NULL))
+        {
+          g_error ("%s: %s", G_STRLOC, error_message);
+          g_free (error_message);
+        }
+
+      g_value_array_insert (simple_job->param_values, n, &value);
+      g_value_unset (&value);
+    }
+  va_end (var_args);
+
+  /* launch the job */
+  return thunar_job_launch (THUNAR_JOB (simple_job));
+}

Added: thunar/branches/migration-to-gio/thunar/thunar-simple-job.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-simple-job.h	                        (rev 0)
+++ thunar/branches/migration-to-gio/thunar/thunar-simple-job.h	2009-04-21 12:28:17 UTC (rev 29877)
@@ -0,0 +1,64 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2006 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __THUNAR_SIMPLE_JOB_H__
+#define __THUNAR_SIMPLE_JOB_H__
+
+#include <thunar/thunar-job.h>
+
+G_BEGIN_DECLS
+
+/**
+ * ThunarSimpleJobFunc:
+ * @job            : a #ThunarJob.
+ * @param_values   : a #GValueArray of the #GValue<!---->s passed to 
+ *                   thunar_simple_job_launch().
+ * @error          : return location for errors.
+ *
+ * Used by the #ThunarSimpleJob to process the @job. See thunar_simple_job_launch()
+ * for further details.
+ *
+ * Return value: %TRUE on success, %FALSE in case of an error.
+ **/
+typedef gboolean (*ThunarSimpleJobFunc) (ThunarJob   *job,
+                                         GValueArray *param_values,
+                                         GError     **error);
+
+
+typedef struct _ThunarSimpleJobClass ThunarSimpleJobClass;
+typedef struct _ThunarSimpleJob      ThunarSimpleJob;
+
+#define THUNAR_TYPE_SIMPLE_JOB            (thunar_simple_job_get_type ())
+#define THUNAR_SIMPLE_JOB(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_SIMPLE_JOB, ThunarSimpleJob))
+#define THUNAR_SIMPLE_JOB_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_SIMPLE_JOB, ThunarSimpleJobClass))
+#define THUNAR_IS_SIMPLE_JOB(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_SIMPLE_JOB))
+#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;
+
+ThunarJob *thunar_simple_job_launch    (ThunarSimpleJobFunc func,
+                                        guint               n_param_values,
+                                        ...) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+
+G_END_DECLS
+
+#endif /* !__THUNAR_SIMPLE_JOB_H__ */

Modified: thunar/branches/migration-to-gio/thunar/thunar-standard-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-standard-view.c	2009-04-21 11:23:09 UTC (rev 29876)
+++ thunar/branches/migration-to-gio/thunar/thunar-standard-view.c	2009-04-21 12:28:17 UTC (rev 29877)
@@ -1806,17 +1806,17 @@
       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 */
           application = thunar_application_get ();
           thunar_application_creat (application, GTK_WIDGET (standard_view), &path_list,
                                     thunar_standard_view_new_files_closure (standard_view));
-          g_object_unref (G_OBJECT (application));
+          g_object_unref (application);
 
           /* release the path */
-          thunar_vfs_path_unref (path_list.data);
+          g_object_unref (path_list.data);
         }
 
       /* release the file name in the local encoding */




More information about the Xfce4-commits mailing list