gimp r26655 - in trunk: . plug-ins/file-uri



Author: neo
Date: Mon Aug 18 21:18:01 2008
New Revision: 26655
URL: http://svn.gnome.org/viewvc/gimp?rev=26655&view=rev

Log:
2008-08-18  Sven Neumann  <sven gimp org>

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

	* plug-ins/file-uri/uri-backend-libcurl.c
	* plug-ins/file-uri/uri-backend-gnomevfs.c
	* plug-ins/file-uri/uri-backend-gvfs.c
	* plug-ins/file-uri/uri-backend-wget.c: set errors in the 
	G_FILE_ERROR domain and other minor cleanups.



Modified:
   trunk/ChangeLog
   trunk/plug-ins/file-uri/uri-backend-gnomevfs.c
   trunk/plug-ins/file-uri/uri-backend-gvfs.c
   trunk/plug-ins/file-uri/uri-backend-libcurl.c
   trunk/plug-ins/file-uri/uri-backend-wget.c
   trunk/plug-ins/file-uri/uri.c

Modified: trunk/plug-ins/file-uri/uri-backend-gnomevfs.c
==============================================================================
--- trunk/plug-ins/file-uri/uri-backend-gnomevfs.c	(original)
+++ trunk/plug-ins/file-uri/uri-backend-gnomevfs.c	Mon Aug 18 21:18:01 2008
@@ -78,7 +78,8 @@
 {
   if (! gnome_vfs_init ())
     {
-      g_set_error (error, 0, 0, "Could not initialize GnomeVFS");
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                   "%s", "Could not initialize GnomeVFS");
       return FALSE;
     }
 
@@ -267,7 +268,7 @@
 
   if (result != GNOME_VFS_OK)
     {
-      g_set_error (error, 0, 0,
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    _("Could not open '%s' for reading: %s"),
                    src_uri, gnome_vfs_result_to_string (result));
       return FALSE;
@@ -278,7 +279,7 @@
 
   if (result != GNOME_VFS_OK)
     {
-      g_set_error (error, 0, 0,
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    _("Could not open '%s' for writing: %s"),
                    dest_uri, gnome_vfs_result_to_string (result));
       gnome_vfs_close (read_handle);
@@ -307,7 +308,7 @@
           if (result != GNOME_VFS_ERROR_EOF)
             {
               memsize = g_format_size_for_display (sizeof (buffer));
-              g_set_error (error, 0, 0,
+              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                            _("Failed to read %s from '%s': %s"),
                            memsize, src_uri,
                            gnome_vfs_result_to_string (result));
@@ -356,7 +357,7 @@
       if (chunk_written < chunk_read)
         {
           memsize = g_format_size_for_display (chunk_read);
-          g_set_error (error, 0, 0,
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("Failed to write %s to '%s': %s"),
                        memsize, dest_uri,
                        gnome_vfs_result_to_string (result));

Modified: trunk/plug-ins/file-uri/uri-backend-gvfs.c
==============================================================================
--- trunk/plug-ins/file-uri/uri-backend-gvfs.c	(original)
+++ trunk/plug-ins/file-uri/uri-backend-gvfs.c	Mon Aug 18 21:18:01 2008
@@ -286,7 +286,8 @@
 
   if (! g_vfs_is_active (vfs))
     {
-      g_set_error (error, 0, 0, "Initialization of GVfs failed");
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                   "Initialization of GVfs failed");
       return FALSE;
     }
 

Modified: trunk/plug-ins/file-uri/uri-backend-libcurl.c
==============================================================================
--- trunk/plug-ins/file-uri/uri-backend-libcurl.c	(original)
+++ trunk/plug-ins/file-uri/uri-backend-libcurl.c	Mon Aug 18 21:18:01 2008
@@ -54,7 +54,8 @@
 
   if (curl_global_init (CURL_GLOBAL_ALL))
     {
-      g_set_error (error, 0, 0, _("Could not initialize libcurl"));
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                   "%s", _("Could not initialize libcurl"));
       return FALSE;
     }
 
@@ -156,8 +157,9 @@
 
   if ((out_file = g_fopen (tmpname, "wb")) == NULL)
     {
-      g_set_error (error, 0, 0,
-                   _("Could not open output file for writing"));
+      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;
     }
 
@@ -182,7 +184,7 @@
   if ((result = curl_easy_perform (curl_handle)) != 0)
     {
       fclose (out_file);
-      g_set_error (error, 0, 0,
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    _("Could not open '%s' for reading: %s"),
                    uri, curl_easy_strerror (result));
       curl_easy_cleanup (curl_handle);
@@ -194,7 +196,7 @@
   if (response_code != 200)
     {
       fclose (out_file);
-      g_set_error (error, 0, 0,
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    _("Opening '%s' for reading resulted in HTTP "
                      "response code: %d"),
                    uri, response_code);
@@ -216,8 +218,7 @@
                         GimpRunMode   run_mode,
                         GError      **error)
 {
-  g_set_error (error, 0, 0,
-               "EEK! uri_backend_save_image() should not have been called!");
+  g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "not implemented");
 
   return FALSE;
 }

Modified: trunk/plug-ins/file-uri/uri-backend-wget.c
==============================================================================
--- trunk/plug-ins/file-uri/uri-backend-wget.c	(original)
+++ trunk/plug-ins/file-uri/uri-backend-wget.c	Mon Aug 18 21:18:01 2008
@@ -91,7 +91,8 @@
 
   if (pipe (p) != 0)
     {
-      g_set_error (error, 0, 0, "pipe() failed: %s", g_strerror (errno));
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,,
+                   "pipe() failed: %s", g_strerror (errno));
       return FALSE;
     }
 
@@ -100,7 +101,8 @@
 
   if ((pid = fork()) < 0)
     {
-      g_set_error (error, 0, 0, "fork() failed: %s", g_strerror (errno));
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,,
+                   "fork() failed: %s", g_strerror (errno));
       return FALSE;
     }
   else if (pid == 0)
@@ -122,7 +124,6 @@
       execlp ("wget",
               "wget", "-v", "-e", "server-response=off", "-T", timeout_str,
               uri, "-O", tmpname, NULL);
-      g_set_error (error, 0, 0, "exec() failed: wget: %s", g_strerror (errno));
       _exit (127);
     }
   else
@@ -157,7 +158,7 @@
       /* Eat any Location lines */
       if (redirect && fgets (buf, sizeof (buf), input) == NULL)
         {
-          g_set_error (error, 0, 0,
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("wget exited abnormally on URI '%s'"), uri);
           return FALSE;
         }
@@ -177,7 +178,7 @@
       /*  The second line is the local copy of the file  */
       if (fgets (buf, sizeof (buf), input) == NULL)
         {
-          g_set_error (error, 0, 0,
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("wget exited abnormally on URI '%s'"), uri);
           return FALSE;
         }
@@ -196,7 +197,7 @@
     read_connect:
       if (fgets (buf, sizeof (buf), input) == NULL)
         {
-          g_set_error (error, 0, 0,
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("wget exited abnormally on URI '%s'"), uri);
           return FALSE;
         }
@@ -219,13 +220,13 @@
 
       if (fgets (buf, sizeof (buf), input) == NULL)
         {
-          g_set_error (error, 0, 0,
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("wget exited abnormally on URI '%s'"), uri);
           return FALSE;
         }
       else if (! connected)
         {
-          g_set_error (error, 0, 0,
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("A network error occurred: %s"), buf);
 
           DEBUG (buf);
@@ -248,7 +249,7 @@
       /*  The fifth line is either the length of the file or an error  */
       if (fgets (buf, sizeof (buf), input) == NULL)
         {
-          g_set_error (error, 0, 0,
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("wget exited abnormally on URI '%s'"), uri);
           return FALSE;
         }
@@ -258,7 +259,7 @@
         }
       else
         {
-          g_set_error (error, 0, 0,
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("A network error occurred: %s"), buf);
 
           DEBUG (buf);
@@ -270,7 +271,7 @@
 
       if (sscanf (buf, "Length: %37s", sizestr) != 1)
         {
-          g_set_error (error, 0, 0,
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        "Could not parse wget's file length message");
           return FALSE;
         }
@@ -366,7 +367,7 @@
 
       if (! finished)
         {
-          g_set_error (error, 0, 0,
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        "wget exited before finishing downloading URI\n'%s'",
                        uri);
           return FALSE;
@@ -382,7 +383,7 @@
                         GimpRunMode   run_mode,
                         GError      **error)
 {
-  g_set_error (error, 0, 0, "EEK");
+  g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "not implemented");
 
   return FALSE;
 }

Modified: trunk/plug-ins/file-uri/uri.c
==============================================================================
--- trunk/plug-ins/file-uri/uri.c	(original)
+++ trunk/plug-ins/file-uri/uri.c	Mon Aug 18 21:18:01 2008
@@ -51,11 +51,13 @@
                                           GimpParam       **return_vals);
 
 static gint32              load_image    (const gchar      *uri,
-                                          GimpRunMode       run_mode);
+                                          GimpRunMode       run_mode,
+                                          GError          **error);
 static GimpPDBStatusType   save_image    (const gchar      *uri,
                                           gint32            image_ID,
                                           gint32            drawable_ID,
-                                          gint32            run_mode);
+                                          gint32            run_mode,
+                                          GError          **error);
 
 static gchar             * get_temp_name (const gchar      *uri,
                                           gboolean         *name_image);
@@ -173,15 +175,19 @@
 
   if (! uri_backend_init (PLUG_IN_BINARY, TRUE, run_mode, &error))
     {
-      g_message (error->message);
-      g_clear_error (&error);
+      if (error)
+        {
+          *nreturn_vals = 2;
+          values[1].type          = GIMP_PDB_STRING;
+          values[1].data.d_string = error->message;
+        }
 
       return;
     }
 
   if (! strcmp (name, LOAD_PROC) && uri_backend_get_load_protocols ())
     {
-      image_ID = load_image (param[2].data.d_string, run_mode);
+      image_ID = load_image (param[2].data.d_string, run_mode, &error);
 
       if (image_ID != -1)
         {
@@ -197,7 +203,7 @@
       status = save_image (param[3].data.d_string,
                            param[1].data.d_int32,
                            param[2].data.d_int32,
-                           run_mode);
+                           run_mode, &error);
     }
   else
     {
@@ -206,21 +212,28 @@
 
   uri_backend_shutdown ();
 
+  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 *uri,
-            GimpRunMode  run_mode)
+load_image (const gchar  *uri,
+            GimpRunMode   run_mode,
+            GError      **error)
 {
   gchar    *tmpname    = NULL;
   gint32    image_ID   = -1;
   gboolean  name_image = FALSE;
-  GError   *error      = NULL;
 
   tmpname = get_temp_name (uri, &name_image);
 
-  if (uri_backend_load_image (uri, tmpname, run_mode, &error))
+  if (uri_backend_load_image (uri, tmpname, run_mode, error))
     {
       image_ID = gimp_file_load (run_mode, tmpname, tmpname);
 
@@ -231,11 +244,11 @@
           else
             gimp_image_set_filename (image_ID, "");
         }
-    }
-  else if (error)
-    {
-      g_message ("%s", error->message);
-      g_clear_error (&error);
+      else
+        {
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                       "%s", gimp_get_pdb_error ());
+        }
     }
 
   g_unlink (tmpname);
@@ -245,43 +258,38 @@
 }
 
 static GimpPDBStatusType
-save_image (const gchar *uri,
-            gint32       image_ID,
-            gint32       drawable_ID,
-            gint32       run_mode)
+save_image (const gchar  *uri,
+            gint32        image_ID,
+            gint32        drawable_ID,
+            gint32        run_mode,
+            GError      **error)
 {
-  gchar  *tmpname;
-  GError *error = NULL;
+  GimpPDBStatusType  status = GIMP_PDB_EXECUTION_ERROR;
+  gchar             *tmpname;
 
   tmpname = get_temp_name (uri, NULL);
 
-  if (! (gimp_file_save (run_mode,
-                         image_ID,
-                         drawable_ID,
-                         tmpname,
-                         tmpname) && valid_file (tmpname)))
+  if (gimp_file_save (run_mode,
+                      image_ID,
+                      drawable_ID,
+                      tmpname,
+                      tmpname) && valid_file (tmpname))
     {
-      g_unlink (tmpname);
-      g_free (tmpname);
-
-      return GIMP_PDB_EXECUTION_ERROR;
+      if (uri_backend_save_image (uri, tmpname, run_mode, error))
+        {
+          status = GIMP_PDB_SUCCESS;
+        }
     }
-
-  if (! uri_backend_save_image (uri, tmpname, run_mode, &error))
+  else
     {
-      g_message ("%s", error->message);
-      g_clear_error (&error);
-
-      g_unlink (tmpname);
-      g_free (tmpname);
-
-      return GIMP_PDB_EXECUTION_ERROR;
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                   "%s", gimp_get_pdb_error ());
     }
 
   g_unlink (tmpname);
   g_free (tmpname);
 
-  return GIMP_PDB_SUCCESS;
+  return status;
 }
 
 static gchar *



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