plug-ins/common/file-desktop-link.c

2008-08-17  Sven Neumann  <sven@gimp.org>

	* plug-ins/common/file-desktop-link.c

	* plug-ins/common/file-svg.c: changed to pass error messages 
with
	the return values instead of calling g_message().


svn path=/trunk/; revision=26626
This commit is contained in:
Sven Neumann 2008-08-17 18:28:55 +00:00 committed by Sven Neumann
parent d6e27a35a9
commit 2c348c7a71
3 changed files with 91 additions and 56 deletions

View File

@ -1,3 +1,10 @@
2008-08-17 Sven Neumann <sven@gimp.org>
* plug-ins/common/file-desktop-link.c
* plug-ins/common/file-svg.c: changed to pass error messages with
the return values instead of calling g_message().
2008-08-17 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/scripts/frosty-logo.scm

View File

@ -44,7 +44,8 @@ static void run (const gchar *name,
GimpParam **return_vals);
static gint32 load_image (const gchar *filename,
GimpRunMode run_mode);
GimpRunMode run_mode,
GError **error);
const GimpPlugInInfo PLUG_IN_INFO =
@ -99,6 +100,7 @@ run (const gchar *name,
static GimpParam values[2];
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
GError *error = NULL;
gint32 image_ID;
run_mode = param[0].data.d_int32;
@ -111,7 +113,7 @@ run (const gchar *name,
if (strcmp (name, LOAD_PROC) == 0)
{
image_ID = load_image (param[1].data.d_string, run_mode);
image_ID = load_image (param[1].data.d_string, run_mode, &error);
if (image_ID != -1)
{
@ -121,6 +123,12 @@ run (const gchar *name,
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = image_ID;
}
else if (error)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING;
values[1].data.d_string = error->message;
}
}
else
{
@ -132,7 +140,8 @@ run (const gchar *name,
static gint32
load_image (const gchar *filename,
GimpRunMode run_mode)
GimpRunMode run_mode,
GError **load_error)
{
GKeyFile *file = g_key_file_new ();
gchar *group = NULL;
@ -160,7 +169,8 @@ load_image (const gchar *filename,
out:
if (error)
{
g_message (_("Error loading desktop file '%s': %s"),
g_set_error (load_error, error->domain, error->code,
_("Error loading desktop file '%s': %s"),
gimp_filename_to_utf8 (filename), error->message);
g_error_free (error);
}

View File

@ -71,14 +71,16 @@ static void run (const gchar *name,
gint *nreturn_vals,
GimpParam **return_vals);
static gint32 load_image (const gchar *filename);
static gint32 load_image (const gchar *filename,
GError **error);
static GdkPixbuf * load_rsvg_pixbuf (const gchar *filename,
SvgLoadVals *vals,
GError **error);
static gboolean load_rsvg_size (const gchar *filename,
SvgLoadVals *vals,
GError **error);
static gboolean load_dialog (const gchar *filename);
static GimpPDBStatusType load_dialog (const gchar *filename,
GError **error);
const GimpPlugInInfo PLUG_IN_INFO =
@ -173,6 +175,7 @@ run (const gchar *name,
static GimpParam values[4];
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GError *error = NULL;
INIT_I18N ();
@ -205,8 +208,7 @@ run (const gchar *name,
break;
case GIMP_RUN_INTERACTIVE:
if (!load_dialog (param[1].data.d_string))
status = GIMP_PDB_CANCEL;
status = load_dialog (param[1].data.d_string, &error);
break;
case GIMP_RUN_WITH_LAST_VALS:
@ -225,7 +227,7 @@ run (const gchar *name,
if (status == GIMP_PDB_SUCCESS)
{
const gchar *filename = param[1].data.d_string;
gint32 image_ID = load_image (filename);
gint32 image_ID = load_image (filename, &error);
if (image_ID != -1)
{
@ -277,7 +279,7 @@ run (const gchar *name,
load_vals.width = - param[1].data.d_int32;
load_vals.height = - param[1].data.d_int32;
image_ID = load_image (filename);
image_ID = load_image (filename, NULL);
if (image_ID != -1)
{
@ -300,11 +302,19 @@ run (const gchar *name,
status = GIMP_PDB_CALLING_ERROR;
}
if (status != GIMP_PDB_SUCCESS && error)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING;
values[1].data.d_string = error->message;
}
values[0].data.d_status = status;
}
static gint32
load_image (const gchar *filename)
load_image (const gchar *filename,
GError **load_error)
{
gint32 image;
gint32 layer;
@ -318,9 +328,13 @@ load_image (const gchar *filename)
if (! pixbuf)
{
/* Do not rely on librsvg setting GError on failure! */
g_message (_("Could not open '%s' for reading: %s"),
g_set_error (load_error,
error ? error->domain : 0, error ? error->code : 0,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename),
error ? error->message : _("Unknown reason"));
g_clear_error (&error);
return -1;
}
@ -666,8 +680,9 @@ load_dialog_set_ratio (gdouble x,
g_signal_handlers_unblock_by_func (yadj, load_dialog_ratio_callback, NULL);
}
static gboolean
load_dialog (const gchar *filename)
static GimpPDBStatusType
load_dialog (const gchar *filename,
GError **load_error)
{
GtkWidget *dialog;
GtkWidget *frame;
@ -686,7 +701,6 @@ load_dialog (const gchar *filename)
GtkObject *adj;
gboolean run;
GError *error = NULL;
SvgLoadVals vals =
{
SVG_DEFAULT_RESOLUTION,
@ -699,10 +713,14 @@ load_dialog (const gchar *filename)
if (! preview)
{
/* Do not rely on librsvg setting GError on failure! */
g_message (_("Could not open '%s' for reading: %s"),
g_set_error (load_error,
error ? error->domain : 0, error ? error->code : 0,
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename),
error ? error->message : _("Unknown reason"));
return FALSE;
g_clear_error (&error);
return GIMP_PDB_EXECUTION_ERROR;
}
gimp_ui_init (PLUG_IN_BINARY, FALSE);
@ -966,5 +984,5 @@ load_dialog (const gchar *filename)
gtk_widget_destroy (dialog);
return run;
return run ? GIMP_PDB_SUCCESS : GIMP_PDB_CANCEL;
}