[gimp] app: port levels cruft format saving to GIO
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: port levels cruft format saving to GIO
- Date: Wed, 2 Jul 2014 21:48:17 +0000 (UTC)
commit 4e6a6079f4d6dfa3107c306f33a512c8fd8ff1d9
Author: Michael Natterer <mitch gimp org>
Date: Wed Jul 2 23:45:16 2014 +0200
app: port levels cruft format saving to GIO
app/operations/gimpcurvesconfig.c | 2 +-
app/operations/gimplevelsconfig.c | 59 +++++++++++++++++++++++++++++-------
app/operations/gimplevelsconfig.h | 2 +-
app/tools/gimplevelstool.c | 25 +---------------
4 files changed, 50 insertions(+), 38 deletions(-)
---
diff --git a/app/operations/gimpcurvesconfig.c b/app/operations/gimpcurvesconfig.c
index a8b1dd6..fd581b0 100644
--- a/app/operations/gimpcurvesconfig.c
+++ b/app/operations/gimpcurvesconfig.c
@@ -659,7 +659,7 @@ gimp_curves_config_save_cruft (GimpCurvesConfig *config,
bytes_written != string->len)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
- _("Writing brush file '%s' failed: %s"),
+ _("Writing curves file '%s' failed: %s"),
gimp_file_get_utf8_name (file),
my_error->message);
g_clear_error (&my_error);
diff --git a/app/operations/gimplevelsconfig.c b/app/operations/gimplevelsconfig.c
index f433e0b..167951f 100644
--- a/app/operations/gimplevelsconfig.c
+++ b/app/operations/gimplevelsconfig.c
@@ -28,6 +28,7 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib/gstdio.h>
+#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpconfig/gimpconfig.h"
@@ -814,30 +815,64 @@ gimp_levels_config_load_cruft (GimpLevelsConfig *config,
gboolean
gimp_levels_config_save_cruft (GimpLevelsConfig *config,
- gpointer fp,
+ GFile *file,
GError **error)
{
- FILE *file = fp;
- gint i;
+ GOutputStream *output;
+ GString *string;
+ gsize bytes_written;
+ gint i;
+ GError *my_error = NULL;
g_return_val_if_fail (GIMP_IS_LEVELS_CONFIG (config), FALSE);
- g_return_val_if_fail (file != NULL, FALSE);
+ g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- fprintf (file, "# GIMP Levels File\n");
+ output = G_OUTPUT_STREAM (g_file_replace (file,
+ NULL, FALSE, G_FILE_CREATE_NONE,
+ NULL, error));
+ if (! output)
+ {
+ g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
+ _("Could not open '%s' for writing: %s"),
+ gimp_file_get_utf8_name (file),
+ my_error->message);
+ g_clear_error (&my_error);
+ return FALSE;
+ }
+
+ string = g_string_new ("# GIMP Levels File\n");
for (i = 0; i < 5; i++)
{
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
- fprintf (file, "%d %d %d %d %s\n",
- (gint) (config->low_input[i] * 255.999),
- (gint) (config->high_input[i] * 255.999),
- (gint) (config->low_output[i] * 255.999),
- (gint) (config->high_output[i] * 255.999),
- g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
- config->gamma[i]));
+ g_string_append_printf (string,
+ "%d %d %d %d %s\n",
+ (gint) (config->low_input[i] * 255.999),
+ (gint) (config->high_input[i] * 255.999),
+ (gint) (config->low_output[i] * 255.999),
+ (gint) (config->high_output[i] * 255.999),
+ g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
+ config->gamma[i]));
}
+ if (! g_output_stream_write_all (output, string->str, string->len,
+ &bytes_written, NULL, &my_error) ||
+ bytes_written != string->len)
+ {
+ g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
+ _("Writing levels file '%s' failed: %s"),
+ gimp_file_get_utf8_name (file),
+ my_error->message);
+ g_clear_error (&my_error);
+ g_string_free (string, TRUE);
+ g_object_unref (output);
+ return FALSE;
+ }
+
+ g_string_free (string, TRUE);
+ g_object_unref (output);
+
return TRUE;
}
diff --git a/app/operations/gimplevelsconfig.h b/app/operations/gimplevelsconfig.h
index 1ad5930..84b4b1b 100644
--- a/app/operations/gimplevelsconfig.h
+++ b/app/operations/gimplevelsconfig.h
@@ -79,7 +79,7 @@ gboolean gimp_levels_config_load_cruft (GimpLevelsConfig *config,
gpointer fp,
GError **error);
gboolean gimp_levels_config_save_cruft (GimpLevelsConfig *config,
- gpointer fp,
+ GFile *file,
GError **error);
diff --git a/app/tools/gimplevelstool.c b/app/tools/gimplevelstool.c
index 587c577..1181b82 100644
--- a/app/tools/gimplevelstool.c
+++ b/app/tools/gimplevelstool.c
@@ -673,30 +673,7 @@ gimp_levels_tool_settings_export (GimpImageMapTool *image_map_tool,
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
if (tool->export_old_format)
- {
- gchar *path;
- FILE *f;
- gboolean success;
-
- path = g_file_get_path (file);
- f = g_fopen (path, "wt");
- 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_file_get_utf8_name (file),
- g_strerror (errno));
- return FALSE;
- }
-
- success = gimp_levels_config_save_cruft (tool->config, f, error);
-
- fclose (f);
-
- return success;
- }
+ return gimp_levels_config_save_cruft (tool->config, file, error);
return GIMP_IMAGE_MAP_TOOL_CLASS (parent_class)->settings_export (image_map_tool,
file,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]