gimp r28103 - in trunk: . app/pdb libgimp plug-ins/pygimp tools/pdbgen/pdb



Author: neo
Date: Wed Mar  4 19:35:18 2009
New Revision: 28103
URL: http://svn.gnome.org/viewvc/gimp?rev=28103&view=rev

Log:
2009-03-04  Sven Neumann  <sven gimp org>

	Bug 574149 â Can't get name/filename of files loaded from URI

	* tools/pdbgen/pdb/image.pdb: added new procedure 
gimp-image-get-uri.

	* app/pdb/image-cmds.c
	* libgimp/gimpimage_pdb.c: regenerated.

	* plug-ins/pygimp/pygimp-image.c: wrap the new procedure into an
	Image attribute.



Modified:
   trunk/ChangeLog
   trunk/app/pdb/image-cmds.c
   trunk/app/pdb/internal-procs.c
   trunk/libgimp/gimpimage_pdb.c
   trunk/libgimp/gimpimage_pdb.h
   trunk/plug-ins/pygimp/pygimp-image.c
   trunk/tools/pdbgen/pdb/image.pdb

Modified: trunk/app/pdb/image-cmds.c
==============================================================================
--- trunk/app/pdb/image-cmds.c	(original)
+++ trunk/app/pdb/image-cmds.c	Wed Mar  4 19:35:18 2009
@@ -2173,6 +2173,35 @@
 }
 
 static GValueArray *
+image_get_uri_invoker (GimpProcedure      *procedure,
+                       Gimp               *gimp,
+                       GimpContext        *context,
+                       GimpProgress       *progress,
+                       const GValueArray  *args,
+                       GError            **error)
+{
+  gboolean success = TRUE;
+  GValueArray *return_vals;
+  GimpImage *image;
+  gchar *uri = NULL;
+
+  image = gimp_value_get_image (&args->values[0], gimp);
+
+  if (success)
+    {
+      uri = g_strdup (gimp_object_get_name (GIMP_OBJECT (image)));
+    }
+
+  return_vals = gimp_procedure_get_return_values (procedure, success,
+                                                  error ? *error : NULL);
+
+  if (success)
+    g_value_take_string (&return_vals->values[1], uri);
+
+  return return_vals;
+}
+
+static GValueArray *
 image_get_name_invoker (GimpProcedure      *procedure,
                         Gimp               *gimp,
                         GimpContext        *context,
@@ -4623,7 +4652,7 @@
   gimp_procedure_set_static_strings (procedure,
                                      "gimp-image-get-filename",
                                      "Returns the specified image's filename.",
-                                     "This procedure returns the specified image's filename in the filesystem encoding. The image has a filename only if it was loaded from a local filesystem or has since been saved locally. Otherwise, this function returns %NULL.",
+                                     "This procedure returns the specified image's filename in the filesystem encoding. The image has a filename only if it was loaded from a local filesystem or has since been saved locally. Otherwise, this function returns %NULL. See also 'gimp-image-get-uri'.",
                                      "Spencer Kimball & Peter Mattis",
                                      "Spencer Kimball & Peter Mattis",
                                      "1995-1996",
@@ -4675,6 +4704,36 @@
   g_object_unref (procedure);
 
   /*
+   * gimp-image-get-uri
+   */
+  procedure = gimp_procedure_new (image_get_uri_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-image-get-uri");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-image-get-uri",
+                                     "Returns the URI for the specified image.",
+                                     "This procedure returns the URI associated with the specified image. The image has an URI only if it was loaded from a file or has since been saved. Otherwise, this function returns %NULL.",
+                                     "Sven Neumann <sven gimp org>",
+                                     "Sven Neumann",
+                                     "2009",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_image_id ("image",
+                                                         "image",
+                                                         "The image",
+                                                         pdb->gimp, FALSE,
+                                                         GIMP_PARAM_READWRITE));
+  gimp_procedure_add_return_value (procedure,
+                                   gimp_param_spec_string ("uri",
+                                                           "uri",
+                                                           "The URI",
+                                                           FALSE, FALSE, FALSE,
+                                                           NULL,
+                                                           GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
    * gimp-image-get-name
    */
   procedure = gimp_procedure_new (image_get_name_invoker);
@@ -4683,7 +4742,7 @@
   gimp_procedure_set_static_strings (procedure,
                                      "gimp-image-get-name",
                                      "Returns the specified image's name.",
-                                     "This procedure returns the image's name. If the image has a filename, then this is the base name (the last component of the path).",
+                                     "This procedure returns the image's name. If the image has a filename or an URI, then this is the base name (the last component of the path). Otherwise it is the translated string \"Untitled\".",
                                      "Spencer Kimball & Peter Mattis",
                                      "Spencer Kimball & Peter Mattis",
                                      "1995-1996",

Modified: trunk/app/pdb/internal-procs.c
==============================================================================
--- trunk/app/pdb/internal-procs.c	(original)
+++ trunk/app/pdb/internal-procs.c	Wed Mar  4 19:35:18 2009
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 595 procedures registered total */
+/* 596 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)

Modified: trunk/libgimp/gimpimage_pdb.c
==============================================================================
--- trunk/libgimp/gimpimage_pdb.c	(original)
+++ trunk/libgimp/gimpimage_pdb.c	Wed Mar  4 19:35:18 2009
@@ -2350,7 +2350,7 @@
  * This procedure returns the specified image's filename in the
  * filesystem encoding. The image has a filename only if it was loaded
  * from a local filesystem or has since been saved locally. Otherwise,
- * this function returns %NULL.
+ * this function returns %NULL. See also gimp_image_get_uri().
  *
  * Returns: The filename.
  */
@@ -2408,14 +2408,48 @@
 }
 
 /**
+ * gimp_image_get_uri:
+ * @image_ID: The image.
+ *
+ * Returns the URI for the specified image.
+ *
+ * This procedure returns the URI associated with the specified image.
+ * The image has an URI only if it was loaded from a file or has since
+ * been saved. Otherwise, this function returns %NULL.
+ *
+ * Returns: The URI.
+ *
+ * Since: GIMP 2.8
+ */
+gchar *
+gimp_image_get_uri (gint32 image_ID)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gchar *uri = NULL;
+
+  return_vals = gimp_run_procedure ("gimp-image-get-uri",
+                                    &nreturn_vals,
+                                    GIMP_PDB_IMAGE, image_ID,
+                                    GIMP_PDB_END);
+
+  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+    uri = g_strdup (return_vals[1].data.d_string);
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return uri;
+}
+
+/**
  * gimp_image_get_name:
  * @image_ID: The image.
  *
  * Returns the specified image's name.
  *
- * This procedure returns the image's name. If the image has a
- * filename, then this is the base name (the last component of the
- * path).
+ * This procedure returns the image's name. If the image has a filename
+ * or an URI, then this is the base name (the last component of the
+ * path). Otherwise it is the translated string \"Untitled\".
  *
  * Returns: The name.
  */

Modified: trunk/libgimp/gimpimage_pdb.h
==============================================================================
--- trunk/libgimp/gimpimage_pdb.h	(original)
+++ trunk/libgimp/gimpimage_pdb.h	Wed Mar  4 19:35:18 2009
@@ -169,6 +169,7 @@
 gchar*                   gimp_image_get_filename             (gint32                  image_ID);
 gboolean                 gimp_image_set_filename             (gint32                  image_ID,
                                                               const gchar            *filename);
+gchar*                   gimp_image_get_uri                  (gint32                  image_ID);
 gchar*                   gimp_image_get_name                 (gint32                  image_ID);
 gboolean                 gimp_image_get_resolution           (gint32                  image_ID,
                                                               gdouble                *xresolution,

Modified: trunk/plug-ins/pygimp/pygimp-image.c
==============================================================================
--- trunk/plug-ins/pygimp/pygimp-image.c	(original)
+++ trunk/plug-ins/pygimp/pygimp-image.c	Wed Mar  4 19:35:18 2009
@@ -1100,6 +1100,23 @@
 }
 
 static PyObject *
+img_get_uri(PyGimpImage *self, void *closure)
+{
+    gchar *uri;
+
+    uri = gimp_image_get_uri(self->ID);
+
+    if (uri) {
+	PyObject *ret = PyString_FromString(uri);
+	g_free(uri);
+	return ret;
+    }
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+static PyObject *
 img_get_floating_selection(PyGimpImage *self, void *closure)
 {
     gint32 id;
@@ -1311,6 +1328,7 @@
     { "tattoo_state", (getter)img_get_tattoo_state,
       (setter)img_set_tattoo_state },
     { "unit", (getter)img_get_unit, (setter)img_set_unit },
+    { "uri", (getter)img_get_uri, (setter)0 },
     { "vectors", (getter)img_get_vectors, (setter)0 },
     { "width", (getter)img_get_width, (setter)0 },
     { NULL, (getter)0, (setter)0 }

Modified: trunk/tools/pdbgen/pdb/image.pdb
==============================================================================
--- trunk/tools/pdbgen/pdb/image.pdb	(original)
+++ trunk/tools/pdbgen/pdb/image.pdb	Wed Mar  4 19:35:18 2009
@@ -2143,7 +2143,7 @@
 This procedure returns the specified image's filename in the
 filesystem encoding. The image has a filename only if it was loaded
 from a local filesystem or has since been saved locally. Otherwise,
-this function returns %NULL.
+this function returns %NULL. See also gimp_image_get_uri().
 HELP
 
     &std_pdb_misc;
@@ -2211,11 +2211,42 @@
     );
 }
 
+sub image_get_uri {
+    $blurb = "Returns the URI for the specified image.";
+
+    $help = <<'HELP';
+This procedure returns the URI associated with the specified image.
+The image has an URI only if it was loaded from a file or has since
+been saved. Otherwise, this function returns %NULL.
+HELP
+
+    &neo_pdb_misc('2009', '2.8');
+
+    @inargs = (
+	{ name => 'image', type => 'image',
+	  desc => 'The image' }
+    );
+
+    @outargs = (
+	{ name => 'uri', type => 'string',
+	  desc => 'The URI' }
+    );
+
+    %invoke = (
+	code => <<'CODE'
+{
+  uri = g_strdup (gimp_object_get_name (GIMP_OBJECT (image)));
+}
+CODE
+    );
+}
+
 sub image_get_name {
     $blurb = "Returns the specified image's name.";
     $help  =  <<'HELP';
-This procedure returns the image's name. If the image has a filename,
-then this is the base name (the last component of the path).
+This procedure returns the image's name. If the image has a filename or
+an URI, then this is the base name (the last component of the path).
+Otherwise it is the translated string "Untitled".
 HELP
 
     &std_pdb_misc;
@@ -2666,7 +2697,8 @@
 	    image_get_component_active image_set_component_active
 	    image_get_component_visible image_set_component_visible
 	    image_get_filename image_set_filename
-	    image_get_name
+	    image_get_uri
+            image_get_name
 	    image_get_resolution image_set_resolution
 	    image_get_unit image_set_unit
 	    image_get_tattoo_state image_set_tattoo_state
@@ -2674,7 +2706,7 @@
             image_get_channel_by_tattoo
             image_get_vectors_by_tattoo);
 
-%exports = (app => [ procs], lib => [ procs[0  46,49..76]]);
+%exports = (app => [ procs], lib => [ procs[0  46,49..77]]);
 
 $desc = 'Image';
 



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