[gimp] app: change filename in gimp_vectors_export_file() to GFile



commit 632b64fedfd9f2cd89f13f0659d37ae093d70211
Author: Michael Natterer <mitch gimp org>
Date:   Wed Jul 2 14:47:11 2014 +0200

    app: change filename in gimp_vectors_export_file() to GFile

 app/actions/vectors-commands.c   |    8 ++++----
 app/pdb/vectors-cmds.c           |    6 +++++-
 app/vectors/gimpvectors-export.c |   24 ++++++++++++++----------
 app/vectors/gimpvectors-export.h |    2 +-
 tools/pdbgen/pdb/vectors.pdb     |    6 +++++-
 5 files changed, 29 insertions(+), 17 deletions(-)
---
diff --git a/app/actions/vectors-commands.c b/app/actions/vectors-commands.c
index a11ea08..670ee63 100644
--- a/app/actions/vectors-commands.c
+++ b/app/actions/vectors-commands.c
@@ -772,17 +772,17 @@ vectors_export_response (GtkWidget           *widget,
     {
       GtkFileChooser *chooser = GTK_FILE_CHOOSER (widget);
       GimpVectors    *vectors = NULL;
-      gchar          *filename;
+      GFile          *file;
       GError         *error   = NULL;
 
       vectors_export_active_only = dialog->active_only;
 
-      filename = gtk_file_chooser_get_filename (chooser);
+      file = gtk_file_chooser_get_file (chooser);
 
       if (vectors_export_active_only)
         vectors = gimp_image_get_active_vectors (dialog->image);
 
-      if (! gimp_vectors_export_file (dialog->image, vectors, filename, &error))
+      if (! gimp_vectors_export_file (dialog->image, vectors, file, &error))
         {
           gimp_message (dialog->image->gimp, G_OBJECT (widget),
                         GIMP_MESSAGE_ERROR,
@@ -791,7 +791,7 @@ vectors_export_response (GtkWidget           *widget,
           return;
         }
 
-      g_free (filename);
+      g_object_unref (file);
 
       g_object_set_data_full (G_OBJECT (dialog->image->gimp),
                               "gimp-vectors-export-folder",
diff --git a/app/pdb/vectors-cmds.c b/app/pdb/vectors-cmds.c
index e6e30e5..de1bcfc 100644
--- a/app/pdb/vectors-cmds.c
+++ b/app/pdb/vectors-cmds.c
@@ -1284,7 +1284,11 @@ vectors_export_to_file_invoker (GimpProcedure         *procedure,
 
   if (success)
     {
-      success = gimp_vectors_export_file (image, vectors, filename, error);
+      GFile *file = g_file_new_for_path (filename);
+
+      success = gimp_vectors_export_file (image, vectors, file, error);
+
+      g_object_unref (file);
     }
 
   return gimp_procedure_get_return_values (procedure, success,
diff --git a/app/vectors/gimpvectors-export.c b/app/vectors/gimpvectors-export.c
index 2ef3009..51cefd6 100644
--- a/app/vectors/gimpvectors-export.c
+++ b/app/vectors/gimpvectors-export.c
@@ -53,7 +53,7 @@ static gchar   * gimp_vectors_export_path_data  (const GimpVectors *vectors);
  * gimp_vectors_export_file:
  * @image: the #GimpImage from which to export vectors
  * @vectors: a #GimpVectors object or %NULL to export all vectors in @image
- * @filename: the name of the file to write
+ * @file: the file to write
  * @error: return location for errors
  *
  * Exports one or more vectors to a SVG file.
@@ -64,37 +64,41 @@ static gchar   * gimp_vectors_export_path_data  (const GimpVectors *vectors);
 gboolean
 gimp_vectors_export_file (const GimpImage    *image,
                           const GimpVectors  *vectors,
-                          const gchar        *filename,
+                          GFile              *file,
                           GError            **error)
 {
-  FILE    *file;
+  gchar   *path;
+  FILE    *f;
   GString *str;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
   g_return_val_if_fail (vectors == NULL || GIMP_IS_VECTORS (vectors), FALSE);
-  g_return_val_if_fail (filename != NULL, FALSE);
+  g_return_val_if_fail (G_IS_FILE (file), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  file = g_fopen (filename, "w");
-  if (!file)
+  path = g_file_get_path (file);
+  f = g_fopen (path, "w");
+  g_free (path);
+
+  if (! f)
     {
       g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
                   _("Could not open '%s' for writing: %s"),
-                   gimp_filename_to_utf8 (filename), g_strerror (errno));
+                   gimp_file_get_utf8_name (file), g_strerror (errno));
       return FALSE;
     }
 
   str = gimp_vectors_export (image, vectors);
 
-  fprintf (file, "%s", str->str);
+  fprintf (f, "%s", str->str);
 
   g_string_free (str, TRUE);
 
-  if (fclose (file))
+  if (fclose (f))
     {
       g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
                   _("Error while writing '%s': %s"),
-                   gimp_filename_to_utf8 (filename), g_strerror (errno));
+                   gimp_file_get_utf8_name (file), g_strerror (errno));
       return FALSE;
     }
 
diff --git a/app/vectors/gimpvectors-export.h b/app/vectors/gimpvectors-export.h
index 7233c18..4bc2038 100644
--- a/app/vectors/gimpvectors-export.h
+++ b/app/vectors/gimpvectors-export.h
@@ -21,7 +21,7 @@
 
 gboolean   gimp_vectors_export_file   (const GimpImage    *image,
                                        const GimpVectors  *vectors,
-                                       const gchar        *filename,
+                                       GFile              *file,
                                        GError            **error);
 gchar    * gimp_vectors_export_string (const GimpImage    *image,
                                        const GimpVectors  *vectors);
diff --git a/tools/pdbgen/pdb/vectors.pdb b/tools/pdbgen/pdb/vectors.pdb
index aa16512..e4c2ae9 100644
--- a/tools/pdbgen/pdb/vectors.pdb
+++ b/tools/pdbgen/pdb/vectors.pdb
@@ -1264,7 +1264,11 @@ HELP
         headers => [ qw("vectors/gimpvectors-export.h") ],
         code    => <<'CODE'
 {
-  success = gimp_vectors_export_file (image, vectors, filename, error);
+  GFile *file = g_file_new_for_path (filename);
+
+  success = gimp_vectors_export_file (image, vectors, file, error);
+
+  g_object_unref (file);
 }
 CODE
     );


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]