[gimp] app: add GInputStream* parameter to GimpDataLoadFunc



commit 6f7e244d75840d99240e28365b84125e5f1fb7bb
Author: Michael Natterer <mitch gimp org>
Date:   Fri Jul 4 03:31:03 2014 +0200

    app: add GInputStream* parameter to GimpDataLoadFunc
    
    and port all loaders to loading from an already open stream.

 app/core/gimpbrush-load.c          |   45 +++++++----------------------
 app/core/gimpbrush-load.h          |    2 +
 app/core/gimpbrushgenerated-load.c |   24 ++++------------
 app/core/gimpbrushgenerated-load.h |    7 ++--
 app/core/gimpbrushpipe-load.c      |   25 +++-------------
 app/core/gimpbrushpipe-load.h      |    7 ++--
 app/core/gimpcurve-load.c          |   12 ++++---
 app/core/gimpcurve-load.h          |    5 ++-
 app/core/gimpdatafactory.c         |   30 ++++++++++++++-----
 app/core/gimpdatafactory.h         |   13 ++++----
 app/core/gimpdynamics-load.c       |   14 +++++----
 app/core/gimpdynamics-load.h       |    7 ++--
 app/core/gimpgradient-load.c       |   31 ++++++++------------
 app/core/gimpgradient-load.h       |   14 +++++----
 app/core/gimppalette-import.c      |    2 +-
 app/core/gimppalette-load.c        |   37 ++---------------------
 app/core/gimppalette-load.h        |    3 --
 app/core/gimppattern-load.c        |   55 ++++++++++--------------------------
 app/core/gimppattern-load.h        |   14 +++++----
 app/core/gimptoolpreset-load.c     |   14 +++++----
 app/core/gimptoolpreset-load.h     |    7 ++--
 21 files changed, 144 insertions(+), 224 deletions(-)
---
diff --git a/app/core/gimpbrush-load.c b/app/core/gimpbrush-load.c
index 0c3c34f..c10a120 100644
--- a/app/core/gimpbrush-load.c
+++ b/app/core/gimpbrush-load.c
@@ -110,31 +110,18 @@ static gboolean    abr_rle_decode                (GDataInputStream  *input,
 /*  public functions  */
 
 GList *
-gimp_brush_load (GimpContext  *context,
-                 GFile        *file,
-                 GError      **error)
+gimp_brush_load (GimpContext   *context,
+                 GFile         *file,
+                 GInputStream  *input,
+                 GError       **error)
 {
-  GimpBrush    *brush;
-  GInputStream *input;
-  GError       *my_error = NULL;
+  GimpBrush *brush;
 
   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;
-    }
-
   brush = gimp_brush_load_brush (context, file, input, error);
-
-  g_object_unref (input);
-
   if (! brush)
     return NULL;
 
@@ -427,31 +414,21 @@ gimp_brush_load_brush (GimpContext   *context,
 }
 
 GList *
-gimp_brush_load_abr (GimpContext  *context,
-                     GFile        *file,
-                     GError      **error)
+gimp_brush_load_abr (GimpContext   *context,
+                     GFile         *file,
+                     GInputStream  *input,
+                     GError       **error)
 {
-  GInputStream     *input;
   GDataInputStream *data_input;
   AbrHeader         abr_hdr;
   GList            *brush_list = NULL;
   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;
-    }
-
   data_input = g_data_input_stream_new (input);
-  g_object_unref (input);
 
   g_data_input_stream_set_byte_order (data_input,
                                       G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN);
diff --git a/app/core/gimpbrush-load.h b/app/core/gimpbrush-load.h
index afe9264..ead14e8 100644
--- a/app/core/gimpbrush-load.h
+++ b/app/core/gimpbrush-load.h
@@ -27,6 +27,7 @@
 
 GList     * gimp_brush_load        (GimpContext   *context,
                                     GFile         *file,
+                                    GInputStream  *input,
                                     GError       **error);
 GimpBrush * gimp_brush_load_brush  (GimpContext   *context,
                                     GFile         *file,
@@ -35,6 +36,7 @@ GimpBrush * gimp_brush_load_brush  (GimpContext   *context,
 
 GList     * gimp_brush_load_abr    (GimpContext   *context,
                                     GFile         *file,
+                                    GInputStream  *input,
                                     GError       **error);
 
 
diff --git a/app/core/gimpbrushgenerated-load.c b/app/core/gimpbrushgenerated-load.c
index 1f64146..c737886 100644
--- a/app/core/gimpbrushgenerated-load.c
+++ b/app/core/gimpbrushgenerated-load.c
@@ -35,12 +35,12 @@
 
 
 GList *
-gimp_brush_generated_load (GimpContext  *context,
-                           GFile        *file,
-                           GError      **error)
+gimp_brush_generated_load (GimpContext   *context,
+                           GFile         *file,
+                           GInputStream  *input,
+                           GError       **error)
 {
   GimpBrush               *brush;
-  GInputStream            *input;
   GDataInputStream        *data_input;
   gchar                   *string;
   gsize                    string_len;
@@ -57,22 +57,10 @@ gimp_brush_generated_load (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);
 
   /* make sure the file we are reading is the right type */
   linenum = 1;
diff --git a/app/core/gimpbrushgenerated-load.h b/app/core/gimpbrushgenerated-load.h
index 90b0c32..3f5c622 100644
--- a/app/core/gimpbrushgenerated-load.h
+++ b/app/core/gimpbrushgenerated-load.h
@@ -24,9 +24,10 @@
 #define GIMP_BRUSH_GENERATED_FILE_EXTENSION ".vbr"
 
 
-GList * gimp_brush_generated_load (GimpContext  *context,
-                                   GFile        *file,
-                                   GError      **error);
+GList * gimp_brush_generated_load (GimpContext   *context,
+                                   GFile         *file,
+                                   GInputStream  *input,
+                                   GError       **error);
 
 
 #endif  /*  __GIMP_BRUSH_GENERATED_LOAD_H__  */
diff --git a/app/core/gimpbrushpipe-load.c b/app/core/gimpbrushpipe-load.c
index 7708b26..7ae2db3 100644
--- a/app/core/gimpbrushpipe-load.c
+++ b/app/core/gimpbrushpipe-load.c
@@ -36,12 +36,12 @@
 
 
 GList *
-gimp_brush_pipe_load (GimpContext  *context,
-                      GFile        *file,
-                      GError      **error)
+gimp_brush_pipe_load (GimpContext   *context,
+                      GFile         *file,
+                      GInputStream  *input,
+                      GError       **error)
 {
   GimpBrushPipe     *pipe = NULL;
-  GInputStream      *input;
   GimpPixPipeParams  params;
   gint               i;
   gint               num_of_brushes = 0;
@@ -50,21 +50,11 @@ gimp_brush_pipe_load (GimpContext  *context,
   GString           *buffer;
   gchar              c;
   gsize              bytes_read;
-  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;
-    }
-
   /* The file format starts with a painfully simple text header */
 
   /*  get the name  */
@@ -100,7 +90,6 @@ gimp_brush_pipe_load (GimpContext  *context,
                    _("Fatal parse error in brush file '%s': "
                      "File is corrupt."),
                    gimp_file_get_utf8_name (file));
-      g_object_unref (input);
       return NULL;
     }
 
@@ -125,7 +114,6 @@ gimp_brush_pipe_load (GimpContext  *context,
                    _("Fatal parse error in brush file '%s': "
                      "File is corrupt."),
                    gimp_file_get_utf8_name (file));
-      g_object_unref (input);
       g_object_unref (pipe);
       g_string_free (buffer, TRUE);
       return NULL;
@@ -216,7 +204,6 @@ gimp_brush_pipe_load (GimpContext  *context,
       else
         {
           g_propagate_error (error, my_error);
-          g_object_unref (input);
           g_object_unref (pipe);
           return NULL;
         }
@@ -224,8 +211,6 @@ gimp_brush_pipe_load (GimpContext  *context,
       pipe->n_brushes++;
     }
 
-  g_object_unref (input);
-
   /* Current brush is the first one. */
   pipe->current = pipe->brushes[0];
 
diff --git a/app/core/gimpbrushpipe-load.h b/app/core/gimpbrushpipe-load.h
index 2807a32..40eca5a 100644
--- a/app/core/gimpbrushpipe-load.h
+++ b/app/core/gimpbrushpipe-load.h
@@ -23,9 +23,10 @@
 #define GIMP_BRUSH_PIPE_FILE_EXTENSION ".gih"
 
 
-GList * gimp_brush_pipe_load (GimpContext  *context,
-                              GFile        *file,
-                              GError      **error);
+GList * gimp_brush_pipe_load (GimpContext   *context,
+                              GFile         *file,
+                              GInputStream  *input,
+                              GError       **error);
 
 
 #endif  /* __GIMP_BRUSH_PIPE_LOAD_H__ */
diff --git a/app/core/gimpcurve-load.c b/app/core/gimpcurve-load.c
index 86ea39e..e4b090d 100644
--- a/app/core/gimpcurve-load.c
+++ b/app/core/gimpcurve-load.c
@@ -29,19 +29,21 @@
 
 
 GList *
-gimp_curve_load (GFile   *file,
-                 GError **error)
+gimp_curve_load (GFile         *file,
+                 GInputStream  *input,
+                 GError       **error)
 {
   GimpCurve *curve;
 
   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);
 
   curve = g_object_new (GIMP_TYPE_CURVE, NULL);
 
-  if (gimp_config_deserialize_gfile (GIMP_CONFIG (curve),
-                                     file,
-                                     NULL, error))
+  if (gimp_config_deserialize_stream (GIMP_CONFIG (curve),
+                                      input,
+                                      NULL, error))
     {
       return g_list_prepend (NULL, curve);
     }
diff --git a/app/core/gimpcurve-load.h b/app/core/gimpcurve-load.h
index dd81183..467af6e 100644
--- a/app/core/gimpcurve-load.h
+++ b/app/core/gimpcurve-load.h
@@ -22,8 +22,9 @@
 #define GIMP_CURVE_FILE_EXTENSION ".curve"
 
 
-GList * gimp_curve_load (GFile   *file,
-                         GError **error);
+GList * gimp_curve_load (GFile         *file,
+                         GInputStream  *input,
+                         GError       **error);
 
 
 #endif /* __GIMP_CURVE_LOAD_H__ */
diff --git a/app/core/gimpdatafactory.c b/app/core/gimpdatafactory.c
index 1ccd343..50b12f6 100644
--- a/app/core/gimpdatafactory.c
+++ b/app/core/gimpdatafactory.c
@@ -840,14 +840,15 @@ static void
 gimp_data_factory_load_data (const GimpDatafileData *file_data,
                              gpointer                data)
 {
-  GimpDataLoadContext              *context = data;
-  GimpDataFactory                  *factory = context->factory;
-  GHashTable                       *cache   = context->cache;
-  const GimpDataFactoryLoaderEntry *loader  = NULL;
-  GFile                            *file    = NULL;
-  GError                           *error   = NULL;
-  GList                            *data_list;
+  GimpDataLoadContext              *context   = data;
+  GimpDataFactory                  *factory   = context->factory;
+  GHashTable                       *cache     = context->cache;
+  const GimpDataFactoryLoaderEntry *loader    = NULL;
+  GList                            *data_list = NULL;
+  GFile                            *file;
+  GInputStream                     *input;
   gint                              i;
+  GError                           *error = NULL;
 
   for (i = 0; i < factory->priv->n_loader_entries; i++)
     {
@@ -887,7 +888,20 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
         }
     }
 
-  data_list = loader->load_func (context->context, file, &error);
+  input = G_INPUT_STREAM (g_file_read (file, NULL, &error));
+
+  if (input)
+    {
+      data_list = loader->load_func (context->context, file, input, &error);
+
+      g_object_unref (input);
+    }
+  else
+    {
+      g_prefix_error (&error,
+                      _("Could not open '%s' for reading: "),
+                      gimp_file_get_utf8_name (file));
+    }
 
   if (G_LIKELY (data_list))
     {
diff --git a/app/core/gimpdatafactory.h b/app/core/gimpdatafactory.h
index 119ae2e..edc3f16 100644
--- a/app/core/gimpdatafactory.h
+++ b/app/core/gimpdatafactory.h
@@ -25,12 +25,13 @@
 #include "gimpobject.h"
 
 
-typedef GimpData * (* GimpDataNewFunc)         (GimpContext  *context,
-                                                const gchar  *name);
-typedef GList    * (* GimpDataLoadFunc)        (GimpContext  *context,
-                                                GFile        *file,
-                                                GError      **error);
-typedef GimpData * (* GimpDataGetStandardFunc) (GimpContext  *context);
+typedef GimpData * (* GimpDataNewFunc)         (GimpContext   *context,
+                                                const gchar   *name);
+typedef GList    * (* GimpDataLoadFunc)        (GimpContext   *context,
+                                                GFile         *file,
+                                                GInputStream  *input,
+                                                GError       **error);
+typedef GimpData * (* GimpDataGetStandardFunc) (GimpContext   *context);
 
 
 typedef struct _GimpDataFactoryLoaderEntry GimpDataFactoryLoaderEntry;
diff --git a/app/core/gimpdynamics-load.c b/app/core/gimpdynamics-load.c
index 95c84ad..c0346d6 100644
--- a/app/core/gimpdynamics-load.c
+++ b/app/core/gimpdynamics-load.c
@@ -29,20 +29,22 @@
 
 
 GList *
-gimp_dynamics_load (GimpContext  *context,
-                    GFile        *file,
-                    GError      **error)
+gimp_dynamics_load (GimpContext   *context,
+                    GFile         *file,
+                    GInputStream  *input,
+                    GError       **error)
 {
   GimpDynamics *dynamics;
 
   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);
 
   dynamics = g_object_new (GIMP_TYPE_DYNAMICS, NULL);
 
-  if (gimp_config_deserialize_gfile (GIMP_CONFIG (dynamics),
-                                     file,
-                                     NULL, error))
+  if (gimp_config_deserialize_stream (GIMP_CONFIG (dynamics),
+                                      input,
+                                      NULL, error))
     {
       return g_list_prepend (NULL, dynamics);
     }
diff --git a/app/core/gimpdynamics-load.h b/app/core/gimpdynamics-load.h
index 61d7adb..160742a 100644
--- a/app/core/gimpdynamics-load.h
+++ b/app/core/gimpdynamics-load.h
@@ -22,9 +22,10 @@
 #define GIMP_DYNAMICS_FILE_EXTENSION ".gdyn"
 
 
-GList * gimp_dynamics_load (GimpContext  *context,
-                            GFile        *file,
-                            GError      **error);
+GList * gimp_dynamics_load (GimpContext   *context,
+                            GFile         *file,
+                            GInputStream  *input,
+                            GError       **error);
 
 
 #endif /* __GIMP_DYNAMICS_LOAD_H__ */
diff --git a/app/core/gimpgradient-load.c b/app/core/gimpgradient-load.c
index 2f624d5..400cf4e 100644
--- a/app/core/gimpgradient-load.c
+++ b/app/core/gimpgradient-load.c
@@ -39,15 +39,15 @@
 
 
 GList *
-gimp_gradient_load (GimpContext  *context,
-                    GFile        *file,
-                    GError      **error)
+gimp_gradient_load (GimpContext   *context,
+                    GFile         *file,
+                    GInputStream  *input,
+                    GError       **error)
 {
   GimpGradient        *gradient = NULL;
   GimpGradientSegment *prev;
   gint                 num_segments;
   gint                 i;
-  GInputStream        *input;
   GDataInputStream    *data_input;
   gchar               *line;
   gsize                line_len;
@@ -55,20 +55,10 @@ gimp_gradient_load (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;
-    }
-
   data_input = g_data_input_stream_new (input);
-  g_object_unref (input);
 
   linenum = 1;
   line_len = 1024;
@@ -311,17 +301,22 @@ static const GMarkupParser markup_parser =
 
 
 GList *
-gimp_gradient_load_svg (GimpContext  *context,
-                        GFile        *file,
-                        GError      **error)
+gimp_gradient_load_svg (GimpContext   *context,
+                        GFile         *file,
+                        GInputStream  *input,
+                        GError       **error)
 {
   GimpXmlParser *xml_parser;
   SvgParser      parser = { NULL, };
   gboolean       success;
 
   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);
 
+  /* FIXME input */
+  g_input_stream_close (input, NULL, NULL);
+
   xml_parser = gimp_xml_parser_new (&markup_parser, &parser);
 
   success = gimp_xml_parser_parse_gfile (xml_parser, file, error);
diff --git a/app/core/gimpgradient-load.h b/app/core/gimpgradient-load.h
index 69363f9..62ee78e 100644
--- a/app/core/gimpgradient-load.h
+++ b/app/core/gimpgradient-load.h
@@ -23,12 +23,14 @@
 #define GIMP_GRADIENT_SVG_FILE_EXTENSION ".svg"
 
 
-GList  * gimp_gradient_load     (GimpContext  *context,
-                                 GFile        *file,
-                                 GError      **error);
-GList  * gimp_gradient_load_svg (GimpContext  *context,
-                                 GFile        *file,
-                                 GError      **error);
+GList  * gimp_gradient_load     (GimpContext   *context,
+                                 GFile         *file,
+                                 GInputStream  *input,
+                                 GError       **error);
+GList  * gimp_gradient_load_svg (GimpContext   *context,
+                                 GFile         *file,
+                                 GInputStream  *input,
+                                 GError       **error);
 
 
 #endif /* __GIMP_GRADIENT_LOAD_H__ */
diff --git a/app/core/gimppalette-import.c b/app/core/gimppalette-import.c
index 4234d3d..d77e501 100644
--- a/app/core/gimppalette-import.c
+++ b/app/core/gimppalette-import.c
@@ -515,7 +515,7 @@ gimp_palette_import_from_file (GimpContext  *context,
   switch (gimp_palette_load_detect_format (file, input))
     {
     case GIMP_PALETTE_FILE_FORMAT_GPL:
-      palette_list = gimp_palette_load_gpl (context, file, input, error);
+      palette_list = gimp_palette_load (context, file, input, error);
       break;
 
     case GIMP_PALETTE_FILE_FORMAT_ACT:
diff --git a/app/core/gimppalette-load.c b/app/core/gimppalette-load.c
index bc04e26..ea1548b 100644
--- a/app/core/gimppalette-load.c
+++ b/app/core/gimppalette-load.c
@@ -35,39 +35,10 @@
 
 
 GList *
-gimp_palette_load (GimpContext  *context,
-                   GFile        *file,
-                   GError      **error)
-{
-  GList        *list;
-  GInputStream *input;
-  GError       *my_error = NULL;
-
-  g_return_val_if_fail (G_IS_FILE (file), 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;
-    }
-
-  list = gimp_palette_load_gpl (context, file, input, error);
-
-  g_object_unref (input);
-
-  return list;
-}
-
-GList *
-gimp_palette_load_gpl (GimpContext   *context,
-                       GFile         *file,
-                       GInputStream  *input,
-                       GError       **error)
+gimp_palette_load (GimpContext   *context,
+                   GFile         *file,
+                   GInputStream  *input,
+                   GError       **error)
 {
   GimpPalette      *palette = NULL;
   GimpPaletteEntry *entry;
diff --git a/app/core/gimppalette-load.h b/app/core/gimppalette-load.h
index 6cb67ad..fd05768 100644
--- a/app/core/gimppalette-load.h
+++ b/app/core/gimppalette-load.h
@@ -36,9 +36,6 @@ typedef enum
 
 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,
diff --git a/app/core/gimppattern-load.c b/app/core/gimppattern-load.c
index 95eb8c0..6a46e58 100644
--- a/app/core/gimppattern-load.c
+++ b/app/core/gimppattern-load.c
@@ -35,33 +35,23 @@
 
 
 GList *
-gimp_pattern_load (GimpContext  *context,
-                   GFile        *file,
-                   GError      **error)
+gimp_pattern_load (GimpContext   *context,
+                   GFile         *file,
+                   GInputStream  *input,
+                   GError       **error)
 {
   GimpPattern   *pattern = NULL;
   const Babl    *format  = NULL;
-  GInputStream  *input;
   PatternHeader  header;
   gsize          size;
   gsize          bytes_read;
   gint           bn_size;
-  gchar         *name     = NULL;
-  GError        *my_error = NULL;
+  gchar         *name = 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;
-    }
-
   /*  read the size  */
   if (! g_input_stream_read_all (input, &header, sizeof (header),
                                  &bytes_read, NULL, NULL) ||
@@ -163,46 +153,31 @@ gimp_pattern_load (GimpContext  *context,
       goto error;
     }
 
-  g_object_unref (input);
-
   return g_list_prepend (NULL, pattern);
 
  error:
+
   if (pattern)
     g_object_unref (pattern);
 
-  g_object_unref (input);
-
   return NULL;
 }
 
 GList *
-gimp_pattern_load_pixbuf (GimpContext  *context,
-                          GFile        *file,
-                          GError      **error)
+gimp_pattern_load_pixbuf (GimpContext   *context,
+                          GFile         *file,
+                          GInputStream  *input,
+                          GError       **error)
 {
-  GimpPattern  *pattern;
-  GInputStream *input;
-  GdkPixbuf    *pixbuf;
-  gchar        *name;
-  GError       *my_error = NULL;
+  GimpPattern *pattern;
+  GdkPixbuf   *pixbuf;
+  gchar       *name;
 
   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;
-    }
-
   pixbuf = gdk_pixbuf_new_from_stream (input, NULL, error);
-  g_object_unref (input);
-
   if (! pixbuf)
     return NULL;
 
diff --git a/app/core/gimppattern-load.h b/app/core/gimppattern-load.h
index c874a1d..a011531 100644
--- a/app/core/gimppattern-load.h
+++ b/app/core/gimppattern-load.h
@@ -22,12 +22,14 @@
 #define GIMP_PATTERN_FILE_EXTENSION ".pat"
 
 
-GList * gimp_pattern_load        (GimpContext  *context,
-                                  GFile        *file,
-                                  GError      **error);
-GList * gimp_pattern_load_pixbuf (GimpContext  *context,
-                                  GFile        *file,
-                                  GError      **error);
+GList * gimp_pattern_load        (GimpContext   *context,
+                                  GFile         *file,
+                                  GInputStream  *input,
+                                  GError       **error);
+GList * gimp_pattern_load_pixbuf (GimpContext   *context,
+                                  GFile         *file,
+                                  GInputStream  *input,
+                                  GError       **error);
 
 
 #endif /* __GIMP_PATTERN_LOAD_H__ */
diff --git a/app/core/gimptoolpreset-load.c b/app/core/gimptoolpreset-load.c
index ee6c2d4..9fc956b 100644
--- a/app/core/gimptoolpreset-load.c
+++ b/app/core/gimptoolpreset-load.c
@@ -33,23 +33,25 @@
 
 
 GList *
-gimp_tool_preset_load (GimpContext  *context,
-                       GFile        *file,
-                       GError      **error)
+gimp_tool_preset_load (GimpContext   *context,
+                       GFile         *file,
+                       GInputStream  *input,
+                       GError       **error)
 {
   GimpToolPreset *tool_preset;
 
   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 (G_IS_INPUT_STREAM (input), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   tool_preset = g_object_new (GIMP_TYPE_TOOL_PRESET,
                               "gimp", context->gimp,
                               NULL);
 
-  if (gimp_config_deserialize_gfile (GIMP_CONFIG (tool_preset),
-                                     file,
-                                     NULL, error))
+  if (gimp_config_deserialize_stream (GIMP_CONFIG (tool_preset),
+                                      input,
+                                      NULL, error))
     {
       if (GIMP_IS_CONTEXT (tool_preset->tool_options))
         {
diff --git a/app/core/gimptoolpreset-load.h b/app/core/gimptoolpreset-load.h
index 8061302..a00dac8 100644
--- a/app/core/gimptoolpreset-load.h
+++ b/app/core/gimptoolpreset-load.h
@@ -22,9 +22,10 @@
 #define GIMP_TOOL_PRESET_FILE_EXTENSION ".gtp"
 
 
-GList * gimp_tool_preset_load (GimpContext  *context,
-                               GFile        *file,
-                               GError      **error);
+GList * gimp_tool_preset_load (GimpContext   *context,
+                               GFile         *file,
+                               GInputStream  *input,
+                               GError       **error);
 
 
 #endif /* __GIMP_TOOL_PRESET_LOAD_H__ */


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