[Xfce4-commits] <thunar:jannis/advanced-dbus-api> Add CopyTo and CopyInto D-Bus methods to org.xfce.FileManager.

Jannis Pohlmann noreply at xfce.org
Sat Aug 28 16:52:02 CEST 2010


Updating branch refs/heads/jannis/advanced-dbus-api
         to 95b61c466a2b91bf74bf1a0f46128348873cfb2f (commit)
       from a07fbaf8cb2569f5ab6416f0f0e12a31e22b5b36 (commit)

commit 95b61c466a2b91bf74bf1a0f46128348873cfb2f
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Sat Aug 28 16:48:51 2010 +0200

    Add CopyTo and CopyInto D-Bus methods to org.xfce.FileManager.
    
    These methods can later be used by xfdesktop so it doesn't have to
    implement the file operation algorithms and the corresponding GUI
    elements itself.

 thunar/thunar-dbus-service-infos.xml |   30 ++++++
 thunar/thunar-dbus-service.c         |  163 ++++++++++++++++++++++++++++++++++
 2 files changed, 193 insertions(+), 0 deletions(-)

diff --git a/thunar/thunar-dbus-service-infos.xml b/thunar/thunar-dbus-service-infos.xml
index c2c01c7..b4d2505 100644
--- a/thunar/thunar-dbus-service-infos.xml
+++ b/thunar/thunar-dbus-service-infos.xml
@@ -124,6 +124,36 @@
     <method name="DisplayPreferencesDialog">
       <arg direction="in" name="display" type="s" />
     </method>
+
+
+    <!--
+    CopyTo (source-files : ARRAY OF STRING, target-files : ARRAY OF STRING) : VOID
+
+    working-directory : the directory, relative to which filenames should
+                        be interpreted. optional.
+    source-files      : the source files to copy.
+    target-files      : the destination files to copy to.
+    -->
+    <method name="CopyTo">
+      <arg direction="in" name="working-directory" type="s" />
+      <arg direction="in" name="source-files" type="as" />
+      <arg direction="in" name="target-files" type="as" />
+    </method>
+
+
+    <!--
+    CopyInto (source-files : ARRAY OF STRING, target-file : STRING) : VOID
+
+    working-directory : the directory, relative to which filenames should
+                        be interpreted. optional.
+    source-files      : the source files to copy.
+    target-files      : the destination directory to copy the files to.
+    -->
+    <method name="CopyInto">
+      <arg direction="in" name="working-directory" type="s" />
+      <arg direction="in" name="source-files" type="as" />
+      <arg direction="in" name="target-file" type="s" />
+    </method>
   </interface>
 
 
diff --git a/thunar/thunar-dbus-service.c b/thunar/thunar-dbus-service.c
index 987c8e6..cd20842 100644
--- a/thunar/thunar-dbus-service.c
+++ b/thunar/thunar-dbus-service.c
@@ -43,6 +43,7 @@
 #include <thunar/thunar-preferences-dialog.h>
 #include <thunar/thunar-private.h>
 #include <thunar/thunar-properties-dialog.h>
+#include <thunar/thunar-util.h>
 
 
 
@@ -102,6 +103,16 @@ static gboolean thunar_dbus_service_bulk_rename                 (ThunarDBusServi
                                                                  const gchar            *display,
                                                                  const gchar            *startup_id,
                                                                  GError                **error);
+static gboolean thunar_dbus_service_copy_to                     (ThunarDBusService      *dbus_service,
+                                                                 const gchar            *working_directory,
+                                                                 gchar                 **source_files,
+                                                                 gchar                 **target_files,
+                                                                 GError                **error);
+static gboolean thunar_dbus_service_copy_into                   (ThunarDBusService      *dbus_service,
+                                                                 const gchar            *working_directory,
+                                                                 gchar                 **source_files,
+                                                                 const gchar            *target_filename,
+                                                                 GError                **error);
 static gboolean thunar_dbus_service_launch_files                (ThunarDBusService      *dbus_service,
                                                                  const gchar            *working_directory,
                                                                  gchar                 **filenames,
@@ -678,6 +689,158 @@ thunar_dbus_service_bulk_rename (ThunarDBusService *dbus_service,
 
 
 static gboolean
+thunar_dbus_service_copy_to (ThunarDBusService *dbus_service,
+                             const gchar       *working_directory,
+                             gchar            **source_files,
+                             gchar            **target_files,
+                             GError           **error)
+{
+  ThunarApplication *application;
+  GFile             *file;
+  GList             *source_file_list = NULL;
+  GList             *target_file_list = NULL;
+  gchar             *new_working_dir = NULL;
+  gchar             *old_working_dir = NULL;
+  guint              n;
+
+  /* verify that at least one file to copy is given */
+  if (source_files == NULL || *source_files == NULL)
+    {
+      /* CopyFilesTo() invoked with an empty source file list */
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, 
+                   _("At least one filename must be specified"));
+      return FALSE;
+    }
+
+  /* verify that both arrays have the same size */
+  if (g_strv_length (source_files) != g_strv_length (target_files))
+    {
+      /* CopyFilesTo() invoked with source and target file lists of different size */
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, 
+                   _("The number of source and target filenames has to be the same"));
+      return FALSE;
+    }
+
+  /* change working directory if necessary */
+  if (working_directory != NULL && *working_directory != '\0')
+    old_working_dir = thunar_util_change_working_directory (working_directory);
+
+  /* transform the filename arrays into lists of GFile objects */
+  for (n = 0; source_files[n] != NULL && target_files[n] != NULL; ++n)
+    {
+      file = g_file_new_for_commandline_arg (source_files[n]);
+      source_file_list = g_list_prepend (source_file_list, file);
+
+      file = g_file_new_for_commandline_arg (target_files[n]);
+      target_file_list = g_list_prepend (target_file_list, file);
+    }
+
+  /* reverse the list (we're prepending first and reversing later 
+   * due to performance reasons) */
+  source_file_list = g_list_reverse (source_file_list);
+  target_file_list = g_list_reverse (target_file_list);
+
+  /* switch back to the previous working directory */
+  if (working_directory != NULL && *working_directory != '\0')
+    {
+      new_working_dir = thunar_util_change_working_directory (old_working_dir);
+      g_free (old_working_dir);
+      g_free (new_working_dir);
+    }
+
+  /* let the application process the filenames */
+  application = thunar_application_get ();
+  thunar_application_copy_to (application, NULL, source_file_list, target_file_list, NULL);
+  g_object_unref (G_OBJECT (application));
+  
+  /* release the file lists */
+  g_list_foreach (source_file_list, (GFunc) g_object_unref, NULL);
+  g_list_free (source_file_list);
+  g_list_foreach (target_file_list, (GFunc) g_object_unref, NULL);
+  g_list_free (target_file_list);
+
+  return TRUE;
+}
+
+
+
+static gboolean
+thunar_dbus_service_copy_into (ThunarDBusService *dbus_service,
+                               const gchar       *working_directory,
+                               gchar            **source_files,
+                               const gchar       *target_filename,
+                               GError           **error)
+{
+  ThunarApplication *application;
+  GFile             *file;
+  GFile             *target_file;
+  GList             *source_file_list = NULL;
+  gchar             *new_working_dir = NULL;
+  gchar             *old_working_dir = NULL;
+  guint              n;
+
+  /* verify that at least one file to copy is given */
+  if (source_files == NULL || *source_files == NULL)
+    {
+      /* CopyFilesTo() invoked with an empty source file list */
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, 
+                   _("At least one source filename must be specified"));
+      return FALSE;
+    }
+
+  /* verify that we have a target directory filename */
+  if (target_filename == NULL || *target_filename == '\0')
+    {
+      /* CopyFilesTo() invoked without a target directory filename */
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, 
+                   _("A destination directory must be specified"));
+      return FALSE;
+    }
+
+  /* change working directory if necessary */
+  if (working_directory != NULL && *working_directory != '\0')
+    old_working_dir = thunar_util_change_working_directory (working_directory);
+
+  /* transform the filename array into a list of GFile objects */
+  for (n = 0; source_files[n] != NULL; ++n)
+    {
+      file = g_file_new_for_commandline_arg (source_files[n]);
+      source_file_list = g_list_prepend (source_file_list, file);
+    }
+
+  /* reverse the list (we're prepending first and reversing later 
+   * due to performance reasons) */
+  source_file_list = g_list_reverse (source_file_list);
+
+  /* transform the target filename into a GFile object */
+  target_file = g_file_new_for_commandline_arg (target_filename);
+
+  /* switch back to the previous working directory */
+  if (working_directory != NULL && *working_directory != '\0')
+    {
+      new_working_dir = thunar_util_change_working_directory (old_working_dir);
+      g_free (old_working_dir);
+      g_free (new_working_dir);
+    }
+
+  /* let the application process the filenames */
+  application = thunar_application_get ();
+  thunar_application_copy_into (application, NULL, source_file_list, target_file, NULL);
+  g_object_unref (G_OBJECT (application));
+  
+  /* release the file list */
+  g_list_foreach (source_file_list, (GFunc) g_object_unref, NULL);
+  g_list_free (source_file_list);
+
+  /* release the target file */
+  g_object_unref (target_file);
+
+  return TRUE;
+}
+
+
+
+static gboolean
 thunar_dbus_service_launch_files (ThunarDBusService *dbus_service,
                                   const gchar       *working_directory,
                                   gchar            **filenames,



More information about the Xfce4-commits mailing list