[Xfce4-commits] <thunar:master> Add new D-Bus method CreateFileFromTemplate().

Jannis Pohlmann noreply at xfce.org
Sun Oct 24 17:48:01 CEST 2010


Updating branch refs/heads/master
         to 64a79dd953388f3422bee879e2080dd9ebaf2cb8 (commit)
       from c842353205b8d9c4c739088720d2e39206411552 (commit)

commit 64a79dd953388f3422bee879e2080dd9ebaf2cb8
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Sun Oct 24 17:42:17 2010 +0200

    Add new D-Bus method CreateFileFromTemplate().
    
    This method takes a working directory, a template URI or absolute path
    and the usual screen/startup-id pair. It can be used to predefine the
    name, extension and content type of the create file dialog.

 thunar/thunar-application.c          |   75 ++++++++++++-
 thunar/thunar-application.h          |  203 +++++++++++++++++-----------------
 thunar/thunar-dbus-service-infos.xml |   20 +++-
 thunar/thunar-dbus-service.c         |   42 +++++++
 4 files changed, 237 insertions(+), 103 deletions(-)

diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c
index 88fb291..2419154 100644
--- a/thunar/thunar-application.c
+++ b/thunar/thunar-application.c
@@ -1281,9 +1281,9 @@ thunar_application_rename_file (ThunarApplication *application,
 
 
 /**
- * thunar_application_create_folder:
+ * thunar_application_create_file:
  * @application      : a #ThunarApplication.
- * @parent_directory : the #ThunarFile of the parent directory
+ * @parent_directory : the #ThunarFile of the parent directory.
  * @content_type     : the content type of the new file.
  * @screen           : the #GdkScreen on which to open the window or %NULL
  *                     to open on the default screen.
@@ -1349,6 +1349,77 @@ thunar_application_create_file (ThunarApplication *application,
 
 
 /**
+ * thunar_application_create_file_from_template:
+ * @application      : a #ThunarApplication.
+ * @parent_directory : the #ThunarFile of the parent directory.
+ * @template_file    : the #ThunarFile of the template.
+ * @screen           : the #GdkScreen on which to open the window or %NULL
+ *                     to open on the default screen.
+ * @startup_id       : startup id from startup notification passed along
+ *                     with dbus to make focus stealing work properly.
+ *
+ * Prompts the user to create a new file or directory in @parent_directory
+ * from an existing @template_file which predefines the name and extension
+ * in the create dialog.
+ **/
+void
+thunar_application_create_file_from_template (ThunarApplication *application,
+                                              ThunarFile        *parent_directory,
+                                              ThunarFile        *template_file,
+                                              GdkScreen         *screen,
+                                              const gchar       *startup_id)
+{
+  GList  source_path_list;
+  GList  target_path_list;
+  gchar *name;
+  gchar *title;
+
+  _thunar_return_if_fail (THUNAR_IS_APPLICATION (application));
+  _thunar_return_if_fail (THUNAR_IS_FILE (parent_directory));
+  _thunar_return_if_fail (THUNAR_IS_FILE (template_file));
+  _thunar_return_if_fail (GDK_IS_SCREEN (screen));
+  _thunar_return_if_fail (startup_id != NULL);
+
+  /* generate a title for the create dialog */
+  title = g_strdup_printf (_("Create Document from template \"%s\""),
+                           thunar_file_get_display_name (template_file));
+
+  /* TODO pass the startup ID to the rename dialog */
+
+  /* ask the user to enter a name for the new document */
+  name = thunar_show_create_dialog (screen, 
+                                    thunar_file_get_content_type (template_file),
+                                    thunar_file_get_display_name (template_file), 
+                                    title);
+  if (G_LIKELY (name != NULL))
+    {
+      /* fake the source file list */
+      source_path_list.data = thunar_file_get_file (template_file);
+      source_path_list.prev = source_path_list.next = NULL;
+
+      /* fake the target path list */
+      target_path_list.data = g_file_get_child (thunar_file_get_file (parent_directory), name);
+      target_path_list.next = target_path_list.prev = NULL;
+
+      /* launch the operation */
+      thunar_application_copy_to (application, screen, 
+                                  &source_path_list, &target_path_list,
+                                  NULL);
+
+      /* release the target path */
+      g_object_unref (target_path_list.data);
+
+      /* release the file name */
+      g_free (name);
+    }
+
+  /* clean up */
+  g_free (title);
+}
+
+
+
+/**
  * thunar_application_copy_to:
  * @application       : a #ThunarApplication.
  * @parent            : a #GdkScreen, a #GtkWidget or %NULL.
diff --git a/thunar/thunar-application.h b/thunar/thunar-application.h
index eb04f94..cb42877 100644
--- a/thunar/thunar-application.h
+++ b/thunar/thunar-application.h
@@ -36,105 +36,110 @@ typedef struct _ThunarApplication      ThunarApplication;
 #define THUNAR_IS_APPLICATION_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_APPLICATION))
 #define THUNAR_APPLICATION_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_APPLICATION, ThunarApplicationClass))
 
-GType              thunar_application_get_type            (void) G_GNUC_CONST;
-
-ThunarApplication *thunar_application_get                 (void);
-
-gboolean           thunar_application_get_daemon          (ThunarApplication *application);
-void               thunar_application_set_daemon          (ThunarApplication *application,
-                                                           gboolean           daemon);
-
-GList             *thunar_application_get_windows         (ThunarApplication *application);
-
-gboolean           thunar_application_has_windows         (ThunarApplication *application);
-
-void               thunar_application_take_window         (ThunarApplication *application,
-                                                           GtkWindow         *window);
-
-GtkWidget         *thunar_application_open_window         (ThunarApplication *application,
-                                                           ThunarFile        *directory,
-                                                           GdkScreen         *screen,
-                                                           const gchar       *startup_id);
-
-gboolean           thunar_application_bulk_rename         (ThunarApplication *application,
-                                                           const gchar       *working_directory,
-                                                           gchar            **filenames,
-                                                           gboolean           standalone,
-                                                           GdkScreen         *screen,
-                                                           const gchar       *startup_id,
-                                                           GError           **error);
-
-GtkWidget         *thunar_application_get_progress_dialog (ThunarApplication *application);
-
-gboolean           thunar_application_process_filenames   (ThunarApplication *application,
-                                                           const gchar       *working_directory,
-                                                           gchar            **filenames,
-                                                           GdkScreen         *screen,
-                                                           const gchar       *startup_id,
-                                                           GError           **error);
-
-gboolean           thunar_application_is_processing       (ThunarApplication *application);
-
-void               thunar_application_rename_file         (ThunarApplication *application,
-                                                           ThunarFile        *file,
-                                                           GdkScreen         *screen,
-                                                           const gchar       *startup_id);
-void               thunar_application_create_file         (ThunarApplication *application,
-                                                           ThunarFile        *parent_directory,
-                                                           const gchar       *content_type,
-                                                           GdkScreen         *screen,
-                                                           const gchar       *startup_id);
-void               thunar_application_copy_to             (ThunarApplication *application,
-                                                           gpointer           parent,
-                                                           GList             *source_file_list,
-                                                           GList             *target_file_list,
-                                                           GClosure          *new_files_closure);
-
-void               thunar_application_copy_into           (ThunarApplication *application,
-                                                           gpointer           parent,
-                                                           GList             *source_file_list,
-                                                           GFile             *target_file,
-                                                           GClosure          *new_files_closure);
-
-void               thunar_application_link_into           (ThunarApplication *application,
-                                                           gpointer           parent,
-                                                           GList             *source_file_list,
-                                                           GFile             *target_file,
-                                                           GClosure          *new_files_closure);
-
-void               thunar_application_move_into           (ThunarApplication *application,
-                                                           gpointer           parent,
-                                                           GList             *source_file_list,
-                                                           GFile             *target_file,
-                                                           GClosure          *new_files_closure);
-
-void               thunar_application_unlink_files        (ThunarApplication *application,
-                                                           gpointer           parent,
-                                                           GList             *file_list,
-                                                           gboolean           permanently);
-
-void               thunar_application_trash               (ThunarApplication *application,
-                                                           gpointer           parent,
-                                                           GList             *file_list);
-
-void               thunar_application_creat               (ThunarApplication *application,
-                                                           gpointer           parent,
-                                                           GList             *file_list,
-                                                           GClosure          *new_files_closure);
-
-void               thunar_application_mkdir               (ThunarApplication *application,
-                                                           gpointer           parent,
-                                                           GList             *file_list,
-                                                           GClosure          *new_files_closure);
-
-void               thunar_application_empty_trash         (ThunarApplication *application,
-                                                           gpointer           parent,
-                                                           const gchar       *startup_id);
-
-void               thunar_application_restore_files       (ThunarApplication *application,
-                                                           gpointer           parent,
-                                                           GList             *trash_file_list,
-                                                           GClosure          *new_files_closure);
+GType              thunar_application_get_type                   (void) G_GNUC_CONST;
+
+ThunarApplication *thunar_application_get                        (void);
+
+gboolean           thunar_application_get_daemon                 (ThunarApplication *application);
+void               thunar_application_set_daemon                 (ThunarApplication *application,
+                                                                  gboolean           daemon);
+
+GList             *thunar_application_get_windows                (ThunarApplication *application);
+
+gboolean           thunar_application_has_windows                (ThunarApplication *application);
+
+void               thunar_application_take_window                (ThunarApplication *application,
+                                                                  GtkWindow         *window);
+
+GtkWidget         *thunar_application_open_window                (ThunarApplication *application,
+                                                                  ThunarFile        *directory,
+                                                                  GdkScreen         *screen,
+                                                                  const gchar       *startup_id);
+
+gboolean           thunar_application_bulk_rename                (ThunarApplication *application,
+                                                                  const gchar       *working_directory,
+                                                                  gchar            **filenames,
+                                                                  gboolean           standalone,
+                                                                  GdkScreen         *screen,
+                                                                  const gchar       *startup_id,
+                                                                  GError           **error);
+
+GtkWidget         *thunar_application_get_progress_dialog        (ThunarApplication *application);
+
+gboolean           thunar_application_process_filenames          (ThunarApplication *application,
+                                                                  const gchar       *working_directory,
+                                                                  gchar            **filenames,
+                                                                  GdkScreen         *screen,
+                                                                  const gchar       *startup_id,
+                                                                  GError           **error);
+
+gboolean           thunar_application_is_processing              (ThunarApplication *application);
+
+void               thunar_application_rename_file                (ThunarApplication *application,
+                                                                  ThunarFile        *file,
+                                                                  GdkScreen         *screen,
+                                                                  const gchar       *startup_id);
+void               thunar_application_create_file                (ThunarApplication *application,
+                                                                  ThunarFile        *parent_directory,
+                                                                  const gchar       *content_type,
+                                                                  GdkScreen         *screen,
+                                                                  const gchar       *startup_id);
+void               thunar_application_create_file_from_template (ThunarApplication *application,
+                                                                 ThunarFile        *parent_directory,
+                                                                 ThunarFile        *template_file,
+                                                                 GdkScreen         *screen,
+                                                                 const gchar       *startup_id);
+void               thunar_application_copy_to                   (ThunarApplication *application,
+                                                                 gpointer           parent,
+                                                                 GList             *source_file_list,
+                                                                 GList             *target_file_list,
+                                                                 GClosure          *new_files_closure);
+
+void               thunar_application_copy_into                 (ThunarApplication *application,
+                                                                 gpointer           parent,
+                                                                 GList             *source_file_list,
+                                                                 GFile             *target_file,
+                                                                 GClosure          *new_files_closure);
+
+void               thunar_application_link_into                 (ThunarApplication *application,
+                                                                 gpointer           parent,
+                                                                 GList             *source_file_list,
+                                                                 GFile             *target_file,
+                                                                 GClosure          *new_files_closure);
+
+void               thunar_application_move_into                 (ThunarApplication *application,
+                                                                 gpointer           parent,
+                                                                 GList             *source_file_list,
+                                                                 GFile             *target_file,
+                                                                 GClosure          *new_files_closure);
+
+void               thunar_application_unlink_files              (ThunarApplication *application,
+                                                                 gpointer           parent,
+                                                                 GList             *file_list,
+                                                                 gboolean           permanently);
+
+void               thunar_application_trash                     (ThunarApplication *application,
+                                                                 gpointer           parent,
+                                                                 GList             *file_list);
+
+void               thunar_application_creat                     (ThunarApplication *application,
+                                                                 gpointer           parent,
+                                                                 GList             *file_list,
+                                                                 GClosure          *new_files_closure);
+
+void               thunar_application_mkdir                     (ThunarApplication *application,
+                                                                 gpointer           parent,
+                                                                 GList             *file_list,
+                                                                 GClosure          *new_files_closure);
+
+void               thunar_application_empty_trash               (ThunarApplication *application,
+                                                                 gpointer           parent,
+                                                                 const gchar       *startup_id);
+
+void               thunar_application_restore_files             (ThunarApplication *application,
+                                                                 gpointer           parent,
+                                                                 GList             *trash_file_list,
+                                                                 GClosure          *new_files_closure);
 
 G_END_DECLS;
 
diff --git a/thunar/thunar-dbus-service-infos.xml b/thunar/thunar-dbus-service-infos.xml
index 4e3818c..0a8dba8 100644
--- a/thunar/thunar-dbus-service-infos.xml
+++ b/thunar/thunar-dbus-service-infos.xml
@@ -288,7 +288,7 @@
     </method>
 
     <!--
-      CreateFile (working_directory : STRING, display : STRING, startup_id : STRING) : VOID
+      CreateFile (working_directory : content_type : STRING, STRING, display : STRING, startup_id : STRING) : VOID
 
       parent_directory : the parent directory in which the file will be created.
       content_type     : content type of the file to be created (text/plain assumed 
@@ -304,6 +304,23 @@
       <arg direction="in" name="display" type="s" />
       <arg direction="in" name="startup_id" type="s" />
     </method>
+
+    <!--
+      CreateFileFromTemplate(working_directory : STRING, template_uri : STRING, display : STRING, start_id : STRING) : VOID
+
+      parent_directory : the parent directory in which the file will be created.
+      template_uri     : the URI or absolute path to the template file.
+      display          : the screen on which to launch the filenames or ""
+                         to use the default screen of the file manager.
+      startup_id       : the DESKTOP_STARTUP_ID environment variable for properly
+                         handling startup notification and focus stealing.
+    -->
+    <method name="CreateFileFromTemplate">
+      <arg direction="in" name="parent_directory" type="s" />
+      <arg direction="in" name="template_uri" type="s" />
+      <arg direction="in" name="display" type="s" />
+      <arg direction="in" name="startup_id" type="s" />
+    </method>
   </interface>
 
 
@@ -439,7 +456,6 @@
       <arg direction="in" name="startup_id" type="s" />
     </method>
 
-
     <!--
       Terminate () : VOID
 
diff --git a/thunar/thunar-dbus-service.c b/thunar/thunar-dbus-service.c
index c8fcc03..8a864a9 100644
--- a/thunar/thunar-dbus-service.c
+++ b/thunar/thunar-dbus-service.c
@@ -147,6 +147,12 @@ static gboolean thunar_dbus_service_create_file                 (ThunarDBusServi
                                                                  const gchar            *display,
                                                                  const gchar            *startup_id,
                                                                  GError                **error);
+static gboolean thunar_dbus_service_create_file_from_template   (ThunarDBusService      *dbus_service,
+                                                                 const gchar            *parent_directory,
+                                                                 const gchar            *template_uri,
+                                                                 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_filenames,
@@ -872,6 +878,42 @@ thunar_dbus_service_create_file (ThunarDBusService *dbus_service,
 
 
 static gboolean
+thunar_dbus_service_create_file_from_template (ThunarDBusService *dbus_service,
+                                               const gchar       *parent_directory,
+                                               const gchar       *template_uri,
+                                               const gchar       *display,
+                                               const gchar       *startup_id,
+                                               GError           **error)
+{
+  ThunarApplication *application;
+  ThunarFile        *file;
+  ThunarFile        *template_file;
+  GdkScreen         *screen;
+
+  /* parse uri and display parameters */
+  if (!thunar_dbus_service_parse_uri_and_display (dbus_service, parent_directory, display, &file, &screen, error))
+    return FALSE;
+
+  /* try to determine the file for the template URI */
+  template_file = thunar_file_get_for_uri (template_uri, error);
+  if(template_file == NULL)
+    return FALSE;
+
+  /* popup a new window for the folder */
+  application = thunar_application_get ();
+  thunar_application_create_file_from_template (application, file, template_file, screen, startup_id);
+  g_object_unref (G_OBJECT (application));
+
+  /* cleanup */
+  g_object_unref (G_OBJECT (screen));
+  g_object_unref (G_OBJECT (file));
+
+  return TRUE;
+}
+
+
+
+static gboolean
 thunar_dbus_service_transfer_files (ThunarDBusTransferMode transfer_mode,
                                     const gchar           *working_directory,
                                     const gchar * const   *source_filenames,



More information about the Xfce4-commits mailing list