gimp r26626 - in trunk: . plug-ins/common



Author: neo
Date: Sun Aug 17 18:28:55 2008
New Revision: 26626
URL: http://svn.gnome.org/viewvc/gimp?rev=26626&view=rev

Log:
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().



Modified:
   trunk/ChangeLog
   trunk/plug-ins/common/file-desktop-link.c
   trunk/plug-ins/common/file-svg.c

Modified: trunk/plug-ins/common/file-desktop-link.c
==============================================================================
--- trunk/plug-ins/common/file-desktop-link.c	(original)
+++ trunk/plug-ins/common/file-desktop-link.c	Sun Aug 17 18:28:55 2008
@@ -44,7 +44,8 @@
                            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 @@
   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 @@
 
   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 @@
           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
     {
@@ -131,8 +139,9 @@
 }
 
 static gint32
-load_image (const gchar *filename,
-            GimpRunMode  run_mode)
+load_image (const gchar  *filename,
+            GimpRunMode   run_mode,
+            GError      **load_error)
 {
   GKeyFile *file     = g_key_file_new ();
   gchar    *group    = NULL;
@@ -160,8 +169,9 @@
  out:
   if (error)
     {
-      g_message (_("Error loading desktop file '%s': %s"),
-                 gimp_filename_to_utf8 (filename), error->message);
+      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);
     }
 

Modified: trunk/plug-ins/common/file-svg.c
==============================================================================
--- trunk/plug-ins/common/file-svg.c	(original)
+++ trunk/plug-ins/common/file-svg.c	Sun Aug 17 18:28:55 2008
@@ -71,14 +71,16 @@
                     gint             *nreturn_vals,
                     GimpParam       **return_vals);
 
-static gint32      load_image        (const gchar  *filename);
-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 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 GimpPDBStatusType   load_dialog       (const gchar  *filename,
+                                              GError      **error);
 
 
 const GimpPlugInInfo PLUG_IN_INFO =
@@ -173,6 +175,7 @@
   static GimpParam   values[4];
   GimpRunMode        run_mode;
   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
+  GError            *error  = NULL;
 
   INIT_I18N ();
 
@@ -205,8 +208,7 @@
           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 @@
       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)
             {
@@ -253,7 +255,7 @@
 
           gimp_set_data (LOAD_PROC, &load_vals, sizeof (load_vals));
         }
-    }
+     }
   else if (strcmp (name, LOAD_THUMB_PROC) == 0)
     {
       if (nparams < 2)
@@ -277,7 +279,7 @@
           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 @@
       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;
@@ -315,12 +325,16 @@
 
   pixbuf = load_rsvg_pixbuf (filename, &load_vals, &error);
 
-  if (!pixbuf)
+  if (! pixbuf)
     {
       /*  Do not rely on librsvg setting GError on failure!  */
-      g_message (_("Could not open '%s' for reading: %s"),
-                 gimp_filename_to_utf8 (filename),
-                 error ? error->message : _("Unknown reason"));
+      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,43 +680,47 @@
   g_signal_handlers_unblock_by_func (yadj, load_dialog_ratio_callback, NULL);
 }
 
-static gboolean
-load_dialog (const gchar *filename)
-{
-  GtkWidget *dialog;
-  GtkWidget *frame;
-  GtkWidget *hbox;
-  GtkWidget *vbox;
-  GtkWidget *image;
-  GdkPixbuf *preview;
-  GtkWidget *table;
-  GtkWidget *table2;
-  GtkWidget *abox;
-  GtkWidget *res;
-  GtkWidget *label;
-  GtkWidget *spinbutton;
-  GtkWidget *toggle;
-  GtkWidget *toggle2;
-  GtkObject *adj;
-  gboolean   run;
-  GError    *error = NULL;
-
-  SvgLoadVals  vals =
-    {
-      SVG_DEFAULT_RESOLUTION,
-      - SVG_PREVIEW_SIZE,
-      - SVG_PREVIEW_SIZE
-    };
+static GimpPDBStatusType
+load_dialog (const gchar  *filename,
+             GError      **load_error)
+{
+  GtkWidget   *dialog;
+  GtkWidget   *frame;
+  GtkWidget   *hbox;
+  GtkWidget   *vbox;
+  GtkWidget   *image;
+  GdkPixbuf   *preview;
+  GtkWidget   *table;
+  GtkWidget   *table2;
+  GtkWidget   *abox;
+  GtkWidget   *res;
+  GtkWidget   *label;
+  GtkWidget   *spinbutton;
+  GtkWidget   *toggle;
+  GtkWidget   *toggle2;
+  GtkObject   *adj;
+  gboolean     run;
+  GError      *error = NULL;
+  SvgLoadVals  vals  =
+  {
+    SVG_DEFAULT_RESOLUTION,
+    - SVG_PREVIEW_SIZE,
+    - SVG_PREVIEW_SIZE
+  };
 
   preview = load_rsvg_pixbuf (filename, &vals, &error);
 
-  if (!preview)
+  if (! preview)
     {
       /*  Do not rely on librsvg setting GError on failure!  */
-      g_message (_("Could not open '%s' for reading: %s"),
-                 gimp_filename_to_utf8 (filename),
-                 error ? error->message : _("Unknown reason"));
-      return FALSE;
+      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 GIMP_PDB_EXECUTION_ERROR;
     }
 
   gimp_ui_init (PLUG_IN_BINARY, FALSE);
@@ -966,5 +984,5 @@
 
   gtk_widget_destroy (dialog);
 
-  return run;
+  return run ? GIMP_PDB_SUCCESS : GIMP_PDB_CANCEL;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]