[gimp] app: prepare for more palette load/import GOI porting



commit bfd8aa69f5bd59d0e52dd3e6198d35f863732b69
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jul 3 16:11:26 2014 +0200

    app: prepare for more palette load/import GOI porting
    
    by passing an open GInputStream to gimp_palette_load_gpl(), all
    palette import functions will become like that.

 app/core/gimppalette-import.c |   24 +++++++++++++---
 app/core/gimppalette-load.c   |   50 ++++++++++++-----------------------
 app/core/gimppalette-load.h   |   57 +++++++++++++++++++++--------------------
 3 files changed, 65 insertions(+), 66 deletions(-)
---
diff --git a/app/core/gimppalette-import.c b/app/core/gimppalette-import.c
index ed89e87..1ba64ed 100644
--- a/app/core/gimppalette-import.c
+++ b/app/core/gimppalette-import.c
@@ -498,31 +498,44 @@ gimp_palette_import_from_file (GimpContext  *context,
                                const gchar  *palette_name,
                                GError      **error)
 {
-  GList *palette_list = NULL;
-  gchar *path;
-  FILE  *f;
+  GList        *palette_list = NULL;
+  GInputStream *input;
+  gchar        *path;
+  FILE         *f;
+  GError       *my_error = NULL;
 
   g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
   g_return_val_if_fail (G_IS_FILE (file), NULL);
   g_return_val_if_fail (palette_name != NULL, NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
+  input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
+  if (! input)
+    {
+      g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
+                   _("Could not open '%s' for reading: %s"),
+                   gimp_file_get_utf8_name (file), my_error->message);
+      g_clear_error (&my_error);
+      return NULL;
+    }
+
+  /* EEK temporary double opening of the file, until all is GIO */
   path = g_file_get_path (file);
   f = g_fopen (path, "rb");
   g_free (path);
-
   if (! f)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for reading: %s"),
                    gimp_file_get_utf8_name (file), g_strerror (errno));
+      g_object_unref (input);
       return NULL;
     }
 
   switch (gimp_palette_load_detect_format (file, f))
     {
     case GIMP_PALETTE_FILE_FORMAT_GPL:
-      palette_list = gimp_palette_load_gpl (context, file, error);
+      palette_list = gimp_palette_load_gpl (context, file, input, error);
       break;
 
     case GIMP_PALETTE_FILE_FORMAT_ACT:
@@ -554,6 +567,7 @@ gimp_palette_import_from_file (GimpContext  *context,
     }
 
   fclose (f);
+  g_object_unref (input);
 
   if (palette_list)
     {
diff --git a/app/core/gimppalette-load.c b/app/core/gimppalette-load.c
index 48503fb..862641b 100644
--- a/app/core/gimppalette-load.c
+++ b/app/core/gimppalette-load.c
@@ -52,42 +52,38 @@ gimp_palette_load (GimpContext  *context,
                    GFile        *file,
                    GError      **error)
 {
-  gchar *path;
-  FILE  *f;
-  GList *glist;
+  GList        *list;
+  GInputStream *input;
+  GError       *my_error = NULL;
 
   g_return_val_if_fail (G_IS_FILE (file), NULL);
-
-  path = g_file_get_path (file);
-
-  g_return_val_if_fail (g_path_is_absolute (path), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-  f = g_fopen (path, "rb");
-  g_free (path);
-
-  if (! f)
+  input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
+  if (! input)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for reading: %s"),
-                   gimp_file_get_utf8_name (file), g_strerror (errno));
+                   gimp_file_get_utf8_name (file), my_error->message);
+      g_clear_error (&my_error);
       return NULL;
     }
 
-  glist = gimp_palette_load_gpl (context, file, error);
-  fclose (f);
+  list = gimp_palette_load_gpl (context, file, input, error);
+
+  g_object_unref (input);
 
-  return glist;
+  return list;
 }
 
 GList *
-gimp_palette_load_gpl (GimpContext  *context,
-                       GFile        *file,
-                       GError      **error)
+gimp_palette_load_gpl (GimpContext   *context,
+                       GFile         *file,
+                       GInputStream  *input,
+                       GError       **error)
 {
   GimpPalette      *palette = NULL;
   GimpPaletteEntry *entry;
-  GInputStream     *input;
   GDataInputStream *data_input;
   gchar            *str;
   gsize             str_len;
@@ -97,22 +93,10 @@ gimp_palette_load_gpl (GimpContext  *context,
   GError           *my_error = NULL;
 
   g_return_val_if_fail (G_IS_FILE (file), NULL);
+  g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-  input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error));
-  if (! input)
-    {
-      g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
-                   _("Could not open '%s' for reading: %s"),
-                   gimp_file_get_utf8_name (file), my_error->message);
-      g_clear_error (&my_error);
-      return NULL;
-    }
-  else
-    {
-      data_input = g_data_input_stream_new (input);
-      g_object_unref (input);
-    }
+  data_input = g_data_input_stream_new (input);
 
   r = g = b = 0;
 
diff --git a/app/core/gimppalette-load.h b/app/core/gimppalette-load.h
index b2ba5d6..0291c61 100644
--- a/app/core/gimppalette-load.h
+++ b/app/core/gimppalette-load.h
@@ -34,35 +34,36 @@ typedef enum
 } GimpPaletteFileFormat;
 
 
-GList               * gimp_palette_load               (GimpContext  *context,
-                                                       GFile        *file,
-                                                       GError      **error);
-GList               * gimp_palette_load_gpl           (GimpContext  *context,
-                                                       GFile        *file,
-                                                       GError      **error);
-GList               * gimp_palette_load_act           (GimpContext  *context,
-                                                       GFile        *file,
-                                                       FILE         *f,
-                                                       GError      **error);
-GList               * gimp_palette_load_riff          (GimpContext  *context,
-                                                       GFile        *file,
-                                                       FILE         *f,
-                                                       GError      **error);
-GList               * gimp_palette_load_psp           (GimpContext  *context,
-                                                       GFile        *file,
-                                                       FILE         *f,
-                                                       GError      **error);
-GList               * gimp_palette_load_aco           (GimpContext  *context,
-                                                       GFile        *file,
-                                                       FILE         *f,
-                                                       GError      **error);
-GList               * gimp_palette_load_css           (GimpContext  *context,
-                                                       GFile        *file,
-                                                       FILE         *f,
-                                                       GError      **error);
+GList               * gimp_palette_load               (GimpContext   *context,
+                                                       GFile         *file,
+                                                       GError       **error);
+GList               * gimp_palette_load_gpl           (GimpContext   *context,
+                                                       GFile         *file,
+                                                       GInputStream  *input,
+                                                       GError       **error);
+GList               * gimp_palette_load_act           (GimpContext   *context,
+                                                       GFile         *file,
+                                                       FILE          *f,
+                                                       GError       **error);
+GList               * gimp_palette_load_riff          (GimpContext   *context,
+                                                       GFile         *file,
+                                                       FILE          *f,
+                                                       GError       **error);
+GList               * gimp_palette_load_psp           (GimpContext   *context,
+                                                       GFile         *file,
+                                                       FILE          *f,
+                                                       GError       **error);
+GList               * gimp_palette_load_aco           (GimpContext   *context,
+                                                       GFile         *file,
+                                                       FILE          *f,
+                                                       GError       **error);
+GList               * gimp_palette_load_css           (GimpContext   *context,
+                                                       GFile         *file,
+                                                       FILE          *f,
+                                                       GError       **error);
 
-GimpPaletteFileFormat gimp_palette_load_detect_format (GFile        *file,
-                                                       FILE         *f);
+GimpPaletteFileFormat gimp_palette_load_detect_format (GFile         *file,
+                                                       FILE          *f);
 
 
 #endif /* __GIMP_PALETTE_H__ */


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