Commit 849a18b0 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

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

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.


svn path=/trunk/; revision=28103
parent f6cff4b0
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.
2009-03-04 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/image.pdb (image_get_filename): improved docs
......
......@@ -2172,6 +2172,35 @@ image_set_filename_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
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,
......@@ -4623,7 +4652,7 @@ register_image_procs (GimpPDB *pdb)
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",
......@@ -4674,6 +4703,36 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
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
*/
......@@ -4683,7 +4742,7 @@ register_image_procs (GimpPDB *pdb)
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",
......
......@@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 595 procedures registered total */
/* 596 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
......
......@@ -2350,7 +2350,7 @@ gimp_image_set_component_visible (gint32 image_ID,
* 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.
*/
......@@ -2407,15 +2407,49 @@ gimp_image_set_filename (gint32 image_ID,
return success;
}
/**
* 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.
*/
......
......@@ -169,6 +169,7 @@ gboolean gimp_image_set_component_visible (gint32
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,
......
......@@ -1099,6 +1099,23 @@ img_set_filename(PyGimpImage *self, PyObject *value, void *closure)
return 0;
}
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)
{
......@@ -1311,6 +1328,7 @@ static PyGetSetDef img_getsets[] = {
{ "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 }
......
......@@ -2143,7 +2143,7 @@ sub image_get_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 function returns %NULL. See also gimp_image_get_uri().
HELP
&std_pdb_misc;
......@@ -2211,11 +2211,42 @@ CODE
);
}
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 @@ CODE
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 @@ CODE
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';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment