pass NULL GError arg to gimp_pdb_execute_procedure_by_name.

2007-12-02  Manish Singh  <yosh@gimp.org>

        * app/dialogs/about-dialog.c (about_dialog_load_url): pass NULL
        GError arg to gimp_pdb_execute_procedure_by_name.

        * app/xcf/xcf.c
        * app/xcf/xcf-load.[ch]
        * app/xcf/xcf-save.[ch]: throw GErrors from load/save invokers instead
        of gimp_messages.

svn path=/trunk/; revision=24256
This commit is contained in:
Manish Singh 2007-12-03 07:44:49 +00:00 committed by Manish Singh
parent 915ac64ad5
commit c1b28feec1
7 changed files with 107 additions and 137 deletions

View File

@ -1,3 +1,13 @@
2007-12-02 Manish Singh <yosh@gimp.org>
* app/dialogs/about-dialog.c (about_dialog_load_url): pass NULL
GError arg to gimp_pdb_execute_procedure_by_name.
* app/xcf/xcf.c
* app/xcf/xcf-load.[ch]
* app/xcf/xcf-save.[ch]: throw GErrors from load/save invokers instead
of gimp_messages.
2007-12-02 Sven Neumann <sven@gimp.org>
* tools/pdbgen/app.pl: use GError for error reporting in PDB

View File

@ -209,7 +209,7 @@ about_dialog_load_url (GtkAboutDialog *dialog,
GValueArray *return_vals;
return_vals = gimp_pdb_execute_procedure_by_name (context->gimp->pdb,
context, NULL,
context, NULL, NULL,
PDB_URL_LOAD,
G_TYPE_STRING, url,
G_TYPE_NONE);

View File

@ -120,8 +120,9 @@ static gboolean xcf_load_vector (XcfInfo *info,
GimpImage *
xcf_load_image (Gimp *gimp,
XcfInfo *info)
xcf_load_image (Gimp *gimp,
XcfInfo *info,
GError **error)
{
GimpImage *image;
GimpLayer *layer;
@ -280,9 +281,9 @@ xcf_load_image (Gimp *gimp,
return image;
hard_error:
gimp_message (gimp, G_OBJECT (info->progress), GIMP_MESSAGE_ERROR,
_("This XCF file is corrupt! I could not even "
"salvage any partial image data from it."));
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("This XCF file is corrupt! I could not even "
"salvage any partial image data from it."));
g_object_unref (image);

View File

@ -20,8 +20,9 @@
#define __XCF_LOAD_H__
GimpImage * xcf_load_image (Gimp *gimp,
XcfInfo *info);
GimpImage * xcf_load_image (Gimp *gimp,
XcfInfo *info,
GError **error);
#endif /* __XCF_LOAD_H__ */

View File

@ -156,80 +156,16 @@ static gboolean xcf_save_vectors (XcfInfo *info,
} \
} G_STMT_END
#define xcf_write_int32_print_error(info, data, count) G_STMT_START { \
info->cp += xcf_write_int32 (info->fp, data, count, &error); \
if (error) \
{ \
gimp_message (info->gimp, G_OBJECT (info->progress), \
GIMP_MESSAGE_ERROR, \
_("Error saving XCF file: %s"), \
error->message); \
return FALSE; \
} \
} G_STMT_END
#define xcf_write_int8_print_error(info, data, count) G_STMT_START { \
info->cp += xcf_write_int8 (info->fp, data, count, &error); \
if (error) \
{ \
gimp_message (info->gimp, G_OBJECT (info->progress), \
GIMP_MESSAGE_ERROR, \
_("Error saving XCF file: %s"), \
error->message); \
return FALSE; \
} \
} G_STMT_END
#define xcf_write_float_print_error(info, data, count) G_STMT_START { \
info->cp += xcf_write_float (info->fp, data, count, &error); \
if (error) \
{ \
gimp_message (info->gimp, G_OBJECT (info->progress), \
GIMP_MESSAGE_ERROR, \
_("Error saving XCF file: %s"), \
error->message); \
return FALSE; \
} \
} G_STMT_END
#define xcf_write_string_print_error(info, data, count) G_STMT_START { \
info->cp += xcf_write_string (info->fp, data, count, &error); \
if (error) \
{ \
gimp_message (info->gimp, G_OBJECT (info->progress), \
GIMP_MESSAGE_ERROR, \
_("Error saving XCF file: %s"), \
error->message); \
return FALSE; \
} \
} G_STMT_END
#define xcf_write_prop_type_check_error(info, prop_type) G_STMT_START { \
guint32 _prop_int32 = prop_type; \
xcf_write_int32_check_error (info, &_prop_int32, 1); \
} G_STMT_END
#define xcf_write_prop_type_print_error(info, prop_type) G_STMT_START { \
guint32 _prop_int32 = prop_type; \
xcf_write_int32_print_error (info, &_prop_int32, 1); \
} G_STMT_END
#define xcf_check_error(x) G_STMT_START { \
if (! (x)) \
return FALSE; \
} G_STMT_END
#define xcf_print_error(info, x) G_STMT_START { \
if (! (x)) \
{ \
gimp_message (info->gimp, G_OBJECT (info->progress), \
GIMP_MESSAGE_ERROR, \
_("Error saving XCF file: %s"), \
error->message); \
return FALSE; \
} \
} G_STMT_END
#define xcf_progress_update(info) G_STMT_START \
{ \
progress++; \
@ -276,8 +212,9 @@ xcf_save_choose_format (XcfInfo *info,
}
gint
xcf_save_image (XcfInfo *info,
GimpImage *image)
xcf_save_image (XcfInfo *info,
GimpImage *image,
GError **error)
{
GimpLayer *layer;
GimpLayer *floating_layer;
@ -293,7 +230,7 @@ xcf_save_image (XcfInfo *info,
gboolean have_selection;
gint t1, t2, t3, t4;
gchar version_tag[16];
GError *error = NULL;
GError *tmp_error = NULL;
floating_layer = gimp_image_floating_sel (image);
if (floating_layer)
@ -309,14 +246,14 @@ xcf_save_image (XcfInfo *info,
strcpy (version_tag, "gimp xcf file");
}
xcf_write_int8_print_error (info, (guint8 *) version_tag, 14);
xcf_write_int8_check_error (info, (guint8 *) version_tag, 14);
/* write out the width, height and image type information for the image */
xcf_write_int32_print_error (info, (guint32 *) &image->width, 1);
xcf_write_int32_print_error (info, (guint32 *) &image->height, 1);
xcf_write_int32_check_error (info, (guint32 *) &image->width, 1);
xcf_write_int32_check_error (info, (guint32 *) &image->height, 1);
value = image->base_type;
xcf_write_int32_print_error (info, &value, 1);
xcf_write_int32_check_error (info, &value, 1);
/* determine the number of layers and channels in the image */
nlayers = (guint) gimp_container_num_children (image->layers);
@ -333,7 +270,7 @@ xcf_save_image (XcfInfo *info,
/* write the property information for the image.
*/
xcf_print_error (info, xcf_save_image_props (info, image, &error));
xcf_check_error (xcf_save_image_props (info, image, error));
xcf_progress_update (info);
@ -343,9 +280,9 @@ xcf_save_image (XcfInfo *info,
saved_pos = info->cp;
/* seek to after the offset lists */
xcf_print_error (info, xcf_seek_pos (info,
info->cp + (nlayers + nchannels + 2) * 4,
&error));
xcf_check_error (xcf_seek_pos (info,
info->cp + (nlayers + nchannels + 2) * 4,
error));
for (list = GIMP_LIST (image->layers)->list;
list;
@ -359,15 +296,15 @@ xcf_save_image (XcfInfo *info,
offset = info->cp;
/* write out the layer. */
xcf_print_error (info, xcf_save_layer (info, image, layer, &error));
xcf_check_error (xcf_save_layer (info, image, layer, error));
xcf_progress_update (info);
/* seek back to where we are to write out the next
* layer offset and write it out.
*/
xcf_print_error (info, xcf_seek_pos (info, saved_pos, &error));
xcf_write_int32_print_error (info, &offset, 1);
xcf_check_error (xcf_seek_pos (info, saved_pos, error));
xcf_write_int32_check_error (info, &offset, 1);
/* increment the location we are to write out the
* next offset.
@ -377,17 +314,17 @@ xcf_save_image (XcfInfo *info,
/* seek to the end of the file which is where
* we will write out the next layer.
*/
xcf_print_error (info, xcf_seek_end (info, &error));
xcf_check_error (xcf_seek_end (info, error));
}
/* write out a '0' offset position to indicate the end
* of the layer offsets.
*/
offset = 0;
xcf_print_error (info, xcf_seek_pos (info, saved_pos, &error));
xcf_write_int32_print_error (info, &offset, 1);
xcf_check_error (xcf_seek_pos (info, saved_pos, error));
xcf_write_int32_check_error (info, &offset, 1);
saved_pos = info->cp;
xcf_print_error (info, xcf_seek_end (info, &error));
xcf_check_error (xcf_seek_end (info, error));
list = GIMP_LIST (image->channels)->list;
@ -411,15 +348,15 @@ xcf_save_image (XcfInfo *info,
offset = info->cp;
/* write out the layer. */
xcf_print_error (info, xcf_save_channel (info, image, channel, &error));
xcf_check_error (xcf_save_channel (info, image, channel, error));
xcf_progress_update (info);
/* seek back to where we are to write out the next
* channel offset and write it out.
*/
xcf_print_error (info, xcf_seek_pos (info, saved_pos, &error));
xcf_write_int32_print_error (info, &offset, 1);
xcf_check_error (xcf_seek_pos (info, saved_pos, error));
xcf_write_int32_check_error (info, &offset, 1);
/* increment the location we are to write out the
* next offset.
@ -429,15 +366,15 @@ xcf_save_image (XcfInfo *info,
/* seek to the end of the file which is where
* we will write out the next channel.
*/
xcf_print_error (info, xcf_seek_end (info, &error));
xcf_check_error (xcf_seek_end (info, error));
}
/* write out a '0' offset position to indicate the end
* of the channel offsets.
*/
offset = 0;
xcf_print_error (info, xcf_seek_pos (info, saved_pos, &error));
xcf_write_int32_print_error (info, &offset, 1);
xcf_check_error (xcf_seek_pos (info, saved_pos, error));
xcf_write_int32_check_error (info, &offset, 1);
saved_pos = info->cp;
if (floating_layer)

View File

@ -20,10 +20,11 @@
#define __XCF_SAVE_H__
void xcf_save_choose_format (XcfInfo *info,
GimpImage *image);
gint xcf_save_image (XcfInfo *info,
GimpImage *image);
void xcf_save_choose_format (XcfInfo *info,
GimpImage *image);
gint xcf_save_image (XcfInfo *info,
GimpImage *image,
GError **error);
#endif /* __XCF_SAVE_H__ */

View File

@ -46,20 +46,23 @@
#include "gimp-intl.h"
typedef GimpImage * GimpXcfLoaderFunc (Gimp *gimp,
XcfInfo *info);
typedef GimpImage * GimpXcfLoaderFunc (Gimp *gimp,
XcfInfo *info,
GError **error);
static GValueArray * xcf_load_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args);
static GValueArray * xcf_save_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args);
static GValueArray * xcf_load_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args,
GError **error);
static GValueArray * xcf_save_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args,
GError **error);
static GimpXcfLoaderFunc * const xcf_loaders[] =
@ -226,11 +229,12 @@ xcf_exit (Gimp *gimp)
}
static GValueArray *
xcf_load_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args)
xcf_load_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args,
GError **error)
{
XcfInfo info;
GValueArray *return_vals;
@ -298,16 +302,16 @@ xcf_load_invoker (GimpProcedure *procedure,
if (info.file_version >= 0 &&
info.file_version < G_N_ELEMENTS (xcf_loaders))
{
image = (*(xcf_loaders[info.file_version])) (gimp, &info);
image = (*(xcf_loaders[info.file_version])) (gimp, &info, error);
if (! image)
success = FALSE;
}
else
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR,
_("XCF error: unsupported XCF file version %d "
"encountered"), info.file_version);
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("XCF error: unsupported XCF file version %d "
"encountered"), info.file_version);
success = FALSE;
}
}
@ -319,9 +323,11 @@ xcf_load_invoker (GimpProcedure *procedure,
}
else
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
int save_errno = errno;
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (save_errno),
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (save_errno));
}
return_vals = gimp_procedure_get_return_values (procedure, success);
@ -335,11 +341,12 @@ xcf_load_invoker (GimpProcedure *procedure,
}
static GValueArray *
xcf_save_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args)
xcf_save_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args,
GError **error)
{
XcfInfo info;
GValueArray *return_vals;
@ -382,14 +389,25 @@ xcf_save_invoker (GimpProcedure *procedure,
xcf_save_choose_format (&info, image);
success = xcf_save_image (&info, image);
success = xcf_save_image (&info, image, error);
if (fclose (info.fp) == EOF)
if (success)
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR,
_("Error saving XCF file: %s"), g_strerror (errno));
if (fclose (info.fp) == EOF)
{
int save_errno = errno;
success = FALSE;
g_set_error (error, G_FILE_ERROR,
g_file_error_from_errno (save_errno),
_("Error saving XCF file: %s"),
g_strerror (save_errno));
success = FALSE;
}
}
else
{
fclose (info.fp);
}
if (progress)
@ -397,9 +415,11 @@ xcf_save_invoker (GimpProcedure *procedure,
}
else
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR,
_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
int save_errno = errno;
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (save_errno),
_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename), g_strerror (save_errno));
}
return_vals = gimp_procedure_get_return_values (procedure, success);