Commit 62719d67 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Unabstract image map tool settings load/save a bit before it's turned into

2008-05-19  Michael Natterer  <mitch@gimp.org>

	Unabstract image map tool settings load/save a bit before it's
	turned into generic load/save for all image map tools:

	* app/gegl/gimpcurvesconfig.[ch]
	* app/gegl/gimplevelsconfig.[ch]: add GError** to save_cruft()
	functions.

	* app/tools/gimpimagemaptool.[ch]: add GError to
	::settings_save(), changed "file" parameter of ::settings_load()
	and ::settings_save() to "filename", removed
	gimp_image_map_tool_load_save() utility function and moved the
	code to the settings_load() and settings_save() utility functions.

	* app/tools/gimpcurvestool.c
	* app/tools/gimplevelstool.c: changed accordingly. Open and close
	the settings files here.


svn path=/trunk/; revision=25714
parent 537caeb0
2008-05-19 Michael Natterer <mitch@gimp.org>
Unabstract image map tool settings load/save a bit before it's
turned into generic load/save for all image map tools:
* app/gegl/gimpcurvesconfig.[ch]
* app/gegl/gimplevelsconfig.[ch]: add GError** to save_cruft()
functions.
* app/tools/gimpimagemaptool.[ch]: add GError to
::settings_save(), changed "file" parameter of ::settings_load()
and ::settings_save() to "filename", removed
gimp_image_map_tool_load_save() utility function and moved the
code to the settings_load() and settings_save() utility functions.
* app/tools/gimpcurvestool.c
* app/tools/gimplevelstool.c: changed accordingly. Open and close
the settings files here.
2008-05-19 Sven Neumann <sven@gimp.org>
* plug-ins/common/psd-save.c (save_layer_and_mask): corrected
......
......@@ -433,14 +433,16 @@ gimp_curves_config_load_cruft (GimpCurvesConfig *config,
}
gboolean
gimp_curves_config_save_cruft (GimpCurvesConfig *config,
gpointer fp)
gimp_curves_config_save_cruft (GimpCurvesConfig *config,
gpointer fp,
GError **error)
{
FILE *file = fp;
gint i;
g_return_val_if_fail (GIMP_IS_CURVES_CONFIG (config), FALSE);
g_return_val_if_fail (file != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
fprintf (file, "# GIMP Curves File\n");
......
......@@ -59,7 +59,8 @@ gboolean gimp_curves_config_load_cruft (GimpCurvesConfig *config,
gpointer fp,
GError **error);
gboolean gimp_curves_config_save_cruft (GimpCurvesConfig *config,
gpointer fp);
gpointer fp,
GError **error);
/* temp cruft */
......
......@@ -710,14 +710,16 @@ gimp_levels_config_load_cruft (GimpLevelsConfig *config,
}
gboolean
gimp_levels_config_save_cruft (GimpLevelsConfig *config,
gpointer fp)
gimp_levels_config_save_cruft (GimpLevelsConfig *config,
gpointer fp,
GError **error)
{
FILE *file = fp;
gint i;
g_return_val_if_fail (GIMP_IS_LEVELS_CONFIG (config), FALSE);
g_return_val_if_fail (file != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
fprintf (file, "# GIMP Levels File\n");
......
......@@ -80,7 +80,8 @@ gboolean gimp_levels_config_load_cruft (GimpLevelsConfig *config,
gpointer fp,
GError **error);
gboolean gimp_levels_config_save_cruft (GimpLevelsConfig *config,
gpointer fp);
gpointer fp,
GError **error);
/* temp cruft */
......
......@@ -18,9 +18,13 @@
#include "config.h"
#include <errno.h>
#include <glib/gstdio.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
......@@ -91,10 +95,11 @@ static void gimp_curves_tool_map (GimpImageMapTool *image_m
static void gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool);
static void gimp_curves_tool_reset (GimpImageMapTool *image_map_tool);
static gboolean gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
gpointer fp,
const gchar *filename,
GError **error);
static gboolean gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
gpointer fp);
const gchar *filename,
GError **error);
static void gimp_curves_tool_config_notify (GObject *object,
GParamSpec *pspec,
......@@ -596,21 +601,56 @@ gimp_curves_tool_reset (GimpImageMapTool *image_map_tool)
static gboolean
gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
gpointer fp,
const gchar *filename,
GError **error)
{
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
FILE *file;
gboolean success;
file = g_fopen (filename, "rt");
if (! file)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename),
g_strerror (errno));
return FALSE;
}
success = gimp_curves_config_load_cruft (tool->config, file, error);
fclose (file);
return gimp_curves_config_load_cruft (tool->config, fp, error);
return success;
}
static gboolean
gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
gpointer fp)
gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
const gchar *filename,
GError **error)
{
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
FILE *file;
gboolean success;
file = g_fopen (filename, "wt");
if (! file)
{
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));
return FALSE;
}
success = gimp_curves_config_save_cruft (tool->config, file, error);
fclose (file);
return gimp_curves_config_save_cruft (tool->config, fp);
return success;
}
static void
......
......@@ -634,32 +634,64 @@ gimp_image_map_tool_create_map (GimpImageMapTool *tool)
}
static gboolean
gimp_image_map_tool_settings_load (GimpImageMapTool *tool,
gpointer file,
GError **error)
gimp_image_map_tool_settings_load (GimpImageMapTool *tool,
const gchar *filename)
{
GimpImageMapToolClass *tool_class = GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool);
GError *error = NULL;
g_return_val_if_fail (tool_class->settings_load != NULL, FALSE);
if (tool_class->settings_load (tool, file, error))
if (! tool_class->settings_load (tool, filename, &error))
{
gimp_image_map_tool_preview (tool);
return TRUE;
gimp_message (GIMP_TOOL (tool)->tool_info->gimp, G_OBJECT (tool->shell),
GIMP_MESSAGE_ERROR, error->message);
g_clear_error (&error);
return FALSE;
}
return FALSE;
gimp_image_map_tool_preview (tool);
g_object_set (GIMP_TOOL_GET_OPTIONS (tool),
"settings", filename,
NULL);
return TRUE;
}
static gboolean
gimp_image_map_tool_settings_save (GimpImageMapTool *tool,
gpointer file)
const gchar *filename)
{
GimpImageMapToolClass *tool_class = GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool);
GError *error = NULL;
gchar *display_name;
g_return_val_if_fail (tool_class->settings_save != NULL, FALSE);
return tool_class->settings_save (tool, file);
if (! tool_class->settings_save (tool, filename, &error))
{
gimp_message (GIMP_TOOL (tool)->tool_info->gimp, G_OBJECT (tool->shell),
GIMP_MESSAGE_ERROR, error->message);
g_clear_error (&error);
return FALSE;
}
display_name = g_filename_display_name (filename);
gimp_message (GIMP_TOOL (tool)->tool_info->gimp,
G_OBJECT (GIMP_TOOL (tool)->display),
GIMP_MESSAGE_INFO,
_("Settings saved to '%s'"),
display_name);
g_free (display_name);
g_object_set (GIMP_TOOL_GET_OPTIONS (tool),
"settings", filename,
NULL);
return TRUE;
}
static void
......@@ -869,61 +901,6 @@ gimp_image_map_tool_preview (GimpImageMapTool *image_map_tool)
}
}
static void
gimp_image_map_tool_load_save (GimpImageMapTool *tool,
const gchar *filename,
gboolean save)
{
FILE *file;
GError *error = NULL;
file = g_fopen (filename, save ? "wt" : "rt");
if (! file)
{
const gchar *format = save ?
_("Could not open '%s' for writing: %s") :
_("Could not open '%s' for reading: %s");
gimp_message (GIMP_TOOL (tool)->tool_info->gimp, G_OBJECT (tool->shell),
GIMP_MESSAGE_ERROR,
format,
gimp_filename_to_utf8 (filename),
g_strerror (errno));
return;
}
g_object_set (GIMP_TOOL_GET_OPTIONS (tool),
"settings", filename,
NULL);
if (save)
{
if (gimp_image_map_tool_settings_save (tool, file))
{
gchar *name = g_filename_display_name (filename);
gimp_message (GIMP_TOOL (tool)->tool_info->gimp,
G_OBJECT (GIMP_TOOL (tool)->display),
GIMP_MESSAGE_INFO,
_("Settings saved to '%s'"),
name);
g_free (name);
}
}
else if (! gimp_image_map_tool_settings_load (tool, file, &error))
{
gimp_message (GIMP_TOOL (tool)->tool_info->gimp, G_OBJECT (tool->shell),
GIMP_MESSAGE_ERROR,
_("Error reading '%s': %s"),
gimp_filename_to_utf8 (filename),
error->message);
g_error_free (error);
}
fclose (file);
}
static void
settings_dialog_response (GtkWidget *dialog,
gint response_id,
......@@ -939,7 +916,10 @@ settings_dialog_response (GtkWidget *dialog,
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
gimp_image_map_tool_load_save (tool, filename, save);
if (save)
gimp_image_map_tool_settings_save (tool, filename);
else
gimp_image_map_tool_settings_load (tool, filename);
g_free (filename);
}
......@@ -976,7 +956,7 @@ gimp_image_map_tool_load_ext_clicked (GtkWidget *widget,
if (filename)
{
gimp_image_map_tool_load_save (tool, filename, FALSE);
gimp_image_map_tool_settings_load (tool, filename);
g_free (filename);
}
else
......@@ -1010,7 +990,7 @@ gimp_image_map_tool_save_ext_clicked (GtkWidget *widget,
if (filename)
{
gimp_image_map_tool_load_save (tool, filename, TRUE);
gimp_image_map_tool_settings_save (tool, filename);
g_free (filename);
}
else
......
......@@ -79,10 +79,11 @@ struct _GimpImageMapToolClass
void (* reset) (GimpImageMapTool *image_map_tool);
gboolean (* settings_load) (GimpImageMapTool *image_map_tool,
gpointer file,
const gchar *filename,
GError **error);
gboolean (* settings_save) (GimpImageMapTool *image_map_tool,
gpointer file);
const gchar *filename,
GError **error);
};
......
......@@ -18,9 +18,13 @@
#include "config.h"
#include <errno.h>
#include <glib/gstdio.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
......@@ -84,10 +88,11 @@ static void gimp_levels_tool_dialog_unmap (GtkWidget *dialog,
GimpLevelsTool *tool);
static void gimp_levels_tool_reset (GimpImageMapTool *im_tool);
static gboolean gimp_levels_tool_settings_load (GimpImageMapTool *im_tool,
gpointer fp,
const gchar *filename,
GError **error);
static gboolean gimp_levels_tool_settings_save (GimpImageMapTool *im_tool,
gpointer fp);
const gchar *filename,
GError **error);
static void gimp_levels_tool_config_notify (GObject *object,
GParamSpec *pspec,
......@@ -718,21 +723,56 @@ gimp_levels_tool_reset (GimpImageMapTool *image_map_tool)
static gboolean
gimp_levels_tool_settings_load (GimpImageMapTool *image_map_tool,
gpointer fp,
const gchar *filename,
GError **error)
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
FILE *file;
gboolean success;
file = g_fopen (filename, "rt");
if (! file)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename),
g_strerror (errno));
return FALSE;
}
success = gimp_levels_config_load_cruft (tool->config, file, error);
fclose (file);
return gimp_levels_config_load_cruft (tool->config, fp, error);
return success;
}
static gboolean
gimp_levels_tool_settings_save (GimpImageMapTool *image_map_tool,
gpointer fp)
gimp_levels_tool_settings_save (GimpImageMapTool *image_map_tool,
const gchar *filename,
GError **error)
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
FILE *file;
gboolean success;
file = g_fopen (filename, "wt");
if (! file)
{
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));
return FALSE;
}
success = gimp_levels_config_save_cruft (tool->config, file, error);
fclose (file);
return gimp_levels_config_save_cruft (tool->config, fp);
return success;
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment