Commit 056c8f77 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/tools/gimpimagemaptool.[ch] app/tools/gimpcurvestool.c improved error

2006-08-10  Sven Neumann  <sven@gimp.org>

	* app/tools/gimpimagemaptool.[ch]
	* app/tools/gimpcurvestool.c
	* app/tools/gimplevelstool.c: improved error handling for
	gimp_image_map_tool_settings_load().

	* app/tools/gimpposterizetool.c: added missing include.

	* app/config/gimpconfig-file.c: rephrased error messages.
parent f4b01330
2006-08-10 Sven Neumann <neumann@jpk.com>
2006-08-10 Sven Neumann <sven@gimp.org>
* app/tools/gimpimagemaptool.[ch]
* app/tools/gimpcurvestool.c
* app/tools/gimplevelstool.c: improved error handling for
gimp_image_map_tool_settings_load().
* app/tools/gimpposterizetool.c: added missing include.
* app/config/gimpconfig-file.c: rephrased error messages.
2006-08-10 Sven Neumann <sven@gimp.org>
* plug-ins/metadata/interface.c (metadata_dialog): set a border
......
......@@ -74,7 +74,7 @@ gimp_config_file_copy (const gchar *source,
if (fwrite (buffer, 1, nbytes, dfile) < nbytes)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while writing '%s': %s"),
_("Error writing '%s': %s"),
gimp_filename_to_utf8 (dest), g_strerror (errno));
fclose (sfile);
fclose (dfile);
......@@ -85,7 +85,7 @@ gimp_config_file_copy (const gchar *source,
if (ferror (sfile))
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while reading '%s': %s"),
_("Error reading '%s': %s"),
gimp_filename_to_utf8 (source), g_strerror (errno));
fclose (sfile);
fclose (dfile);
......@@ -97,7 +97,7 @@ gimp_config_file_copy (const gchar *source,
if (fclose (dfile) == EOF)
{
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Error while writing '%s': %s"),
_("Error writing '%s': %s"),
gimp_filename_to_utf8 (dest), g_strerror (errno));
return FALSE;
}
......
......@@ -26,6 +26,7 @@
#include <gdk/gdkkeysyms.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
......@@ -71,60 +72,61 @@
/* local function prototypes */
static void gimp_curves_tool_finalize (GObject *object);
static gboolean gimp_curves_tool_initialize (GimpTool *tool,
GimpDisplay *display);
static void gimp_curves_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display);
static gboolean gimp_curves_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *display);
static void gimp_curves_tool_oper_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
gboolean proximity,
GimpDisplay *display);
static void gimp_curves_tool_color_picked (GimpColorTool *color_tool,
static void gimp_curves_tool_finalize (GObject *object);
static gboolean gimp_curves_tool_initialize (GimpTool *tool,
GimpDisplay *display);
static void gimp_curves_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display);
static gboolean gimp_curves_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *display);
static void gimp_curves_tool_oper_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
gboolean proximity,
GimpDisplay *display);
static void gimp_curves_tool_color_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
GimpRGB *color,
gint color_index);
static void gimp_curves_tool_map (GimpImageMapTool *image_map_tool);
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);
static gboolean gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
gpointer fp);
static void curves_add_point (GimpCurvesTool *tool,
gint channel);
static gboolean curves_key_press (GimpCurvesTool *tool,
GdkEventKey *kevent);
static void curves_update (GimpCurvesTool *tool,
gint update);
static void curves_channel_callback (GtkWidget *widget,
GimpCurvesTool *tool);
static void curves_channel_reset_callback (GtkWidget *widget,
GimpCurvesTool *tool);
static gboolean curves_menu_sensitivity (gint value,
gpointer data);
static void curves_curve_type_callback (GtkWidget *widget,
GimpCurvesTool *tool);
static gboolean curves_graph_events (GtkWidget *widget,
GdkEvent *event,
GimpCurvesTool *tool);
static gboolean curves_graph_expose (GtkWidget *widget,
GdkEventExpose *eevent,
GimpCurvesTool *tool);
GimpImageType sample_type,
GimpRGB *color,
gint color_index);
static void gimp_curves_tool_map (GimpImageMapTool *image_map_tool);
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,
GError **error);
static gboolean gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
gpointer fp);
static void curves_add_point (GimpCurvesTool *tool,
gint channel);
static gboolean curves_key_press (GimpCurvesTool *tool,
GdkEventKey *kevent);
static void curves_update (GimpCurvesTool *tool,
gint update);
static void curves_channel_callback (GtkWidget *widget,
GimpCurvesTool *tool);
static void curves_channel_reset_callback (GtkWidget *widget,
GimpCurvesTool *tool);
static gboolean curves_menu_sensitivity (gint value,
gpointer data);
static void curves_curve_type_callback (GtkWidget *widget,
GimpCurvesTool *tool);
static gboolean curves_graph_events (GtkWidget *widget,
GdkEvent *event,
GimpCurvesTool *tool);
static gboolean curves_graph_expose (GtkWidget *widget,
GdkEventExpose *eevent,
GimpCurvesTool *tool);
G_DEFINE_TYPE (GimpCurvesTool, gimp_curves_tool, GIMP_TYPE_IMAGE_MAP_TOOL)
......@@ -740,8 +742,9 @@ gimp_curves_tool_reset (GimpImageMapTool *image_map_tool)
}
static gboolean
gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
gpointer fp)
gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
gpointer fp,
GError **error)
{
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
FILE *file = fp;
......@@ -751,11 +754,13 @@ gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
gint index[5][CURVES_NUM_POINTS];
gint value[5][CURVES_NUM_POINTS];
if (! fgets (buf, sizeof (buf), file))
return FALSE;
if (strcmp (buf, "# GIMP Curves File\n") != 0)
return FALSE;
if (! fgets (buf, sizeof (buf), file) ||
strcmp (buf, "# GIMP Curves File\n") != 0)
{
g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
_("not a GIMP Levels file"));
return FALSE;
}
for (i = 0; i < 5; i++)
{
......@@ -766,6 +771,8 @@ gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
{
/* FIXME: should have a helpful error message here */
g_printerr ("fields != 2");
g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
_("parse error"));
return FALSE;
}
}
......
......@@ -416,14 +416,15 @@ gimp_image_map_tool_reset (GimpImageMapTool *tool)
}
static gboolean
gimp_image_map_tool_settings_load (GimpImageMapTool *tool,
gpointer file)
gimp_image_map_tool_settings_load (GimpImageMapTool *tool,
gpointer file,
GError **error)
{
GimpImageMapToolClass *tool_class = GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool);
g_return_val_if_fail (tool_class->settings_load != NULL, FALSE);
if (tool_class->settings_load (tool, file))
if (tool_class->settings_load (tool, file, error))
{
gimp_image_map_tool_preview (tool);
return TRUE;
......@@ -572,7 +573,10 @@ gimp_image_map_tool_load_save (GimpImageMapTool *tool,
const gchar *filename,
gboolean save)
{
FILE *file = g_fopen (filename, save ? "wt" : "rt");
FILE *file;
GError *error = NULL;
file = g_fopen (filename, save ? "wt" : "rt");
if (! file)
{
......@@ -592,10 +596,11 @@ gimp_image_map_tool_load_save (GimpImageMapTool *tool,
{
gimp_image_map_tool_settings_save (tool, file);
}
else if (! gimp_image_map_tool_settings_load (tool, file))
else if (! gimp_image_map_tool_settings_load (tool, file, &error))
{
g_message ("Error in reading file '%s'.",
gimp_filename_to_utf8 (filename));
g_message (_("Error reading '%s': %s"),
gimp_filename_to_utf8 (filename), error->message);
g_error_free (error);
}
fclose (file);
......
......@@ -62,14 +62,15 @@ struct _GimpImageMapToolClass
const gchar *save_dialog_title;
/* virtual functions */
void (* map) (GimpImageMapTool *image_map_tool);
void (* dialog) (GimpImageMapTool *image_map_tool);
void (* reset) (GimpImageMapTool *image_map_tool);
gboolean (* settings_load) (GimpImageMapTool *image_map_tool,
gpointer file);
gboolean (* settings_save) (GimpImageMapTool *image_map_tool,
gpointer file);
void (* map) (GimpImageMapTool *image_map_tool);
void (* dialog) (GimpImageMapTool *image_map_tool);
void (* reset) (GimpImageMapTool *image_map_tool);
gboolean (* settings_load) (GimpImageMapTool *image_map_tool,
gpointer file,
GError **error);
gboolean (* settings_save) (GimpImageMapTool *image_map_tool,
gpointer file);
};
......
......@@ -26,6 +26,7 @@
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
......@@ -78,24 +79,25 @@
/* local function prototypes */
static void gimp_levels_tool_finalize (GObject *object);
static void gimp_levels_tool_finalize (GObject *object);
static gboolean gimp_levels_tool_initialize (GimpTool *tool,
GimpDisplay *display);
static gboolean gimp_levels_tool_initialize (GimpTool *tool,
GimpDisplay *display);
static void gimp_levels_tool_color_picked (GimpColorTool *color_tool,
static void gimp_levels_tool_color_picked (GimpColorTool *color_tool,
GimpColorPickState pick_state,
GimpImageType sample_type,
GimpRGB *color,
gint color_index);
static void gimp_levels_tool_map (GimpImageMapTool *image_map_tool);
static void gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool);
static void gimp_levels_tool_reset (GimpImageMapTool *image_map_tool);
static gboolean gimp_levels_tool_settings_load (GimpImageMapTool *image_mao_tool,
gpointer fp);
static gboolean gimp_levels_tool_settings_save (GimpImageMapTool *image_map_tool,
gpointer fp);
GimpImageType sample_type,
GimpRGB *color,
gint color_index);
static void gimp_levels_tool_map (GimpImageMapTool *image_map_tool);
static void gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool);
static void gimp_levels_tool_reset (GimpImageMapTool *image_map_tool);
static gboolean gimp_levels_tool_settings_load (GimpImageMapTool *image_mao_tool,
gpointer fp,
GError **error);
static gboolean gimp_levels_tool_settings_save (GimpImageMapTool *image_map_tool,
gpointer fp);
static void levels_update (GimpLevelsTool *tool,
guint update);
......@@ -644,8 +646,9 @@ gimp_levels_tool_reset (GimpImageMapTool *image_map_tool)
}
static gboolean
gimp_levels_tool_settings_load (GimpImageMapTool *image_map_tool,
gpointer fp)
gimp_levels_tool_settings_load (GimpImageMapTool *image_map_tool,
gpointer fp,
GError **error)
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
FILE *file = fp;
......@@ -658,11 +661,13 @@ gimp_levels_tool_settings_load (GimpImageMapTool *image_map_tool,
gchar buf[50];
gchar *nptr;
if (! fgets (buf, sizeof (buf), file))
return FALSE;
if (strcmp (buf, "# GIMP Levels File\n") != 0)
return FALSE;
if (! fgets (buf, sizeof (buf), file) ||
strcmp (buf, "# GIMP Levels File\n") != 0)
{
g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
_("not a GIMP Levels file"));
return FALSE;
}
for (i = 0; i < 5; i++)
{
......@@ -673,15 +678,15 @@ gimp_levels_tool_settings_load (GimpImageMapTool *image_map_tool,
&high_output[i]);
if (fields != 4)
return FALSE;
goto error;
if (! fgets (buf, 50, file))
return FALSE;
goto error;
gamma[i] = g_ascii_strtod (buf, &nptr);
if (buf == nptr || errno == ERANGE)
return FALSE;
goto error;
}
for (i = 0; i < 5; i++)
......@@ -696,6 +701,11 @@ gimp_levels_tool_settings_load (GimpImageMapTool *image_map_tool,
levels_update (tool, ALL);
return TRUE;
error:
g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
_("parse error"));
return FALSE;
}
static gboolean
......
......@@ -27,6 +27,7 @@
#include "base/gimplut.h"
#include "base/lut-funcs.h"
#include "core/gimp.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpimagemap.h"
......
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