Commit da37e9ff authored by Eric Grivel's avatar Eric Grivel Committed by Martin Nordholts

Bug 596410 - gimp-image-get-filename returns NULL for imported files

Make gimp_image_get_uri() and gimp_image_get_filename() behave as in
the GIMP 2.6 days. Add new functions gimp_image_get_xcf_uri(),
gimp_image_get_exported_uri() and gimp_image_get_imported_uri().
parent 0f58d779
......@@ -91,6 +91,7 @@ The following people have contributed code to GIMP:
Saul Goode
David Gowers
Cameron Gregory
Eric Grivel
Stephen Griffiths
Pavel Grinfeld
Dov Grobgeld
......
......@@ -71,6 +71,7 @@ Plug-ins:
- Update libpng code to not use deprecated API (file-mng and file-png)
- Add an Item class to pygimp
- Correct/update some labels and defaults in the JPEG plug-in's save dialog UI
- Fix "Bug 596410 - gimp-image-get-filename returns NULL for imported files"
Developer documentation:
......
......@@ -1623,6 +1623,34 @@ gimp_image_get_save_a_copy_uri (const GimpImage *image)
GIMP_FILE_SAVE_A_COPY_URI_KEY);
}
/**
* gimp_image_get_any_uri:
* @image: A #GimpImage.
*
* Returns: The XCF file URI, the imported file URI, or the exported
* file URI, in that order of precedence. Only to help implement
* backwards compatibility with GIMP 2.6 API.
**/
const gchar *
gimp_image_get_any_uri (const GimpImage *image)
{
const gchar *uri;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
uri = gimp_image_get_uri (image);
if (! uri)
{
uri = gimp_image_get_imported_uri (image);
if (! uri)
{
uri = gimp_image_get_exported_uri (image);
}
}
return uri;
}
/**
* gimp_image_set_imported_uri:
* @image: A #GimpImage.
......
......@@ -175,6 +175,7 @@ const gchar * gimp_image_get_uri_or_untitled (const GimpImage *image);
const gchar * gimp_image_get_imported_uri (const GimpImage *image);
const gchar * gimp_image_get_exported_uri (const GimpImage *image);
const gchar * gimp_image_get_save_a_copy_uri (const GimpImage *image);
const gchar * gimp_image_get_any_uri (const GimpImage *image);
void gimp_image_set_uri (GimpImage *image,
const gchar *uri);
......
......@@ -2102,7 +2102,7 @@ image_get_filename_invoker (GimpProcedure *procedure,
if (success)
{
filename = gimp_image_get_filename (image);
filename = g_filename_from_uri (gimp_image_get_any_uri (image), NULL, NULL);
}
return_vals = gimp_procedure_get_return_values (procedure, success,
......@@ -2171,6 +2171,35 @@ image_get_uri_invoker (GimpProcedure *procedure,
image = gimp_value_get_image (&args->values[0], gimp);
if (success)
{
uri = g_strdup (gimp_image_get_any_uri (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_xcf_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_image_get_uri (image));
......@@ -2185,6 +2214,64 @@ image_get_uri_invoker (GimpProcedure *procedure,
return return_vals;
}
static GValueArray *
image_get_imported_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_image_get_imported_uri (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_exported_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_image_get_exported_uri (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,
......@@ -4671,7 +4758,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. See also 'gimp-image-get-uri'.",
"This procedure returns the specified image's filename in the filesystem encoding. The image has a filename only if it was loaded or imported from a file or has since been saved or exported. Otherwise, this function returns %NULL. See also 'gimp-image-get-uri'.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
......@@ -4731,7 +4818,7 @@ register_image_procs (GimpPDB *pdb)
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.",
"This procedure returns the URI associated with the specified image. The image has an URI only if it was loaded or imported from a file or has since been saved or exported. Otherwise, this function returns %NULL. See also gimp-image-get-imported-uri to get the URI of the current file if it was imported from a non-GIMP file format and not yet saved, or gimp-image-get-exported-uri if the image has been exported to a non-GIMP file format.",
"Sven Neumann <sven@gimp.org>",
"Sven Neumann",
"2009",
......@@ -4752,6 +4839,96 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-get-xcf-uri
*/
procedure = gimp_procedure_new (image_get_xcf_uri_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-image-get-xcf-uri");
gimp_procedure_set_static_strings (procedure,
"gimp-image-get-xcf-uri",
"Returns the XCF URI for the specified image.",
"This procedure returns the XCF URI associated with the image. If there is no such URI, this procedure returns %NULL.",
"Eric Grivel <gimp@lumenssolutions.com>",
"Eric Grivel",
"2011",
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 imported URI",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-get-imported-uri
*/
procedure = gimp_procedure_new (image_get_imported_uri_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-image-get-imported-uri");
gimp_procedure_set_static_strings (procedure,
"gimp-image-get-imported-uri",
"Returns the imported URI for the specified image.",
"This procedure returns the URI associated with the specified image if the image was imported from a non-native Gimp format. If the image was not imported, or has since been saved in the native Gimp format, this procedure returns %NULL.",
"Eric Grivel <gimp@lumenssolutions.com>",
"Eric Grivel",
"2011",
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 imported URI",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-get-exported-uri
*/
procedure = gimp_procedure_new (image_get_exported_uri_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-image-get-exported-uri");
gimp_procedure_set_static_strings (procedure,
"gimp-image-get-exported-uri",
"Returns the exported URI for the specified image.",
"This procedure returns the URI associated with the specified image if the image was exported a non-native GIMP format. If the image was not exported, this procedure returns %NULL.",
"Eric Grivel <gimp@lumenssolutions.com>",
"Eric Grivel",
"2011",
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 exported URI",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-get-name
*/
......
......@@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 630 procedures registered total */
/* 633 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
......
......@@ -100,6 +100,7 @@
<contributor role="author" last-active="2.4">Saul Goode</contributor>
<contributor role="author" last-active="2.6">David Gowers</contributor>
<contributor role="author" last-active="2.0">Cameron Gregory</contributor>
<contributor role="author" last-active="2.8">Eric Grivel</contributor>
<contributor role="author" last-active="2.8">Stephen Griffiths</contributor>
<contributor role="author" last-active="1.2">Pavel Grinfeld</contributor>
<contributor role="author" last-active="2.4">Dov Grobgeld</contributor>
......
......@@ -359,10 +359,12 @@ EXPORTS
gimp_image_get_colormap
gimp_image_get_component_active
gimp_image_get_component_visible
gimp_image_get_exported_uri
gimp_image_get_filename
gimp_image_get_floating_sel
gimp_image_get_guide_orientation
gimp_image_get_guide_position
gimp_image_get_imported_uri
gimp_image_get_item_position
gimp_image_get_layer_by_tattoo
gimp_image_get_layer_position
......@@ -380,6 +382,7 @@ EXPORTS
gimp_image_get_vectors
gimp_image_get_vectors_by_tattoo
gimp_image_get_vectors_position
gimp_image_get_xcf_uri
gimp_image_grid_get_background_color
gimp_image_grid_get_foreground_color
gimp_image_grid_get_offset
......
......@@ -2229,8 +2229,9 @@ 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. See also gimp_image_get_uri().
* or imported from a file or has since been saved or exported.
* Otherwise, this function returns %NULL. See also
* gimp_image_get_uri().
*
* Returns: The filename.
**/
......@@ -2294,8 +2295,12 @@ gimp_image_set_filename (gint32 image_ID,
* 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.
* The image has an URI only if it was loaded or imported from a file
* or has since been saved or exported. Otherwise, this function
* returns %NULL. See also gimp-image-get-imported-uri to get the URI
* of the current file if it was imported from a non-GIMP file format
* and not yet saved, or gimp-image-get-exported-uri if the image has
* been exported to a non-GIMP file format.
*
* Returns: The URI.
*
......@@ -2321,6 +2326,108 @@ gimp_image_get_uri (gint32 image_ID)
return uri;
}
/**
* gimp_image_get_xcf_uri:
* @image_ID: The image.
*
* Returns the XCF URI for the specified image.
*
* This procedure returns the XCF URI associated with the image. If
* there is no such URI, this procedure returns %NULL.
*
* Returns: The imported URI.
*
* Since: GIMP 2.8
**/
gchar *
gimp_image_get_xcf_uri (gint32 image_ID)
{
GimpParam *return_vals;
gint nreturn_vals;
gchar *uri = NULL;
return_vals = gimp_run_procedure ("gimp-image-get-xcf-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_imported_uri:
* @image_ID: The image.
*
* Returns the imported URI for the specified image.
*
* This procedure returns the URI associated with the specified image
* if the image was imported from a non-native Gimp format. If the
* image was not imported, or has since been saved in the native Gimp
* format, this procedure returns %NULL.
*
* Returns: The imported URI.
*
* Since: GIMP 2.8
**/
gchar *
gimp_image_get_imported_uri (gint32 image_ID)
{
GimpParam *return_vals;
gint nreturn_vals;
gchar *uri = NULL;
return_vals = gimp_run_procedure ("gimp-image-get-imported-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_exported_uri:
* @image_ID: The image.
*
* Returns the exported URI for the specified image.
*
* This procedure returns the URI associated with the specified image
* if the image was exported a non-native GIMP format. If the image was
* not exported, this procedure returns %NULL.
*
* Returns: The exported URI.
*
* Since: GIMP 2.8
**/
gchar *
gimp_image_get_exported_uri (gint32 image_ID)
{
GimpParam *return_vals;
gint nreturn_vals;
gchar *uri = NULL;
return_vals = gimp_run_procedure ("gimp-image-get-exported-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.
......
......@@ -182,6 +182,9 @@ gchar* gimp_image_get_filename (gint32
gboolean gimp_image_set_filename (gint32 image_ID,
const gchar *filename);
gchar* gimp_image_get_uri (gint32 image_ID);
gchar* gimp_image_get_xcf_uri (gint32 image_ID);
gchar* gimp_image_get_imported_uri (gint32 image_ID);
gchar* gimp_image_get_exported_uri (gint32 image_ID);
gchar* gimp_image_get_name (gint32 image_ID);
gboolean gimp_image_get_resolution (gint32 image_ID,
gdouble *xresolution,
......
......@@ -2079,8 +2079,8 @@ sub image_get_filename {
$help = <<'HELP';
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,
filesystem encoding. The image has a filename only if it was loaded or
imported from a file or has since been saved or exported. Otherwise,
this function returns %NULL. See also gimp_image_get_uri().
HELP
......@@ -2099,7 +2099,7 @@ HELP
%invoke = (
code => <<'CODE'
{
filename = gimp_image_get_filename (image);
filename = g_filename_from_uri (gimp_image_get_any_uri (image), NULL, NULL);
}
CODE
);
......@@ -2154,8 +2154,12 @@ sub image_get_uri {
$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.
The image has an URI only if it was loaded or imported from a file or
has since been saved or exported. Otherwise, this function returns
%NULL. See also gimp-image-get-imported-uri to get the URI of the
current file if it was imported from a non-GIMP file format and not
yet saved, or gimp-image-get-exported-uri if the image has been
exported to a non-GIMP file format.
HELP
&neo_pdb_misc('2009', '2.8');
......@@ -2173,12 +2177,111 @@ HELP
%invoke = (
code => <<'CODE'
{
uri = g_strdup (gimp_image_get_any_uri (image));
}
CODE
);
}
sub image_get_xcf_uri {
$blurb = "Returns the XCF URI for the specified image.";
$help = <<'HELP';
This procedure returns the XCF URI associated with the image. If
there is no such URI, this procedure returns %NULL.
HELP
$author = 'Eric Grivel <gimp@lumenssolutions.com>';
$copyright = 'Eric Grivel';
$date = '2011';
$since = '2.8';
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' }
);
@outargs = (
{ name => 'uri', type => 'string',
desc => 'The imported URI' }
);
%invoke = (
code => <<'CODE'
{
uri = g_strdup (gimp_image_get_uri (image));
}
CODE
);
}
sub image_get_imported_uri {
$blurb = "Returns the imported URI for the specified image.";
$help = <<'HELP';
This procedure returns the URI associated with the specified image
if the image was imported from a non-native Gimp format. If the
image was not imported, or has since been saved in the native Gimp
format, this procedure returns %NULL.
HELP
$author = 'Eric Grivel <gimp@lumenssolutions.com>';
$copyright = 'Eric Grivel';
$date = '2011';
$since = '2.8';
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' }
);
@outargs = (
{ name => 'uri', type => 'string',
desc => 'The imported URI' }
);
%invoke = (
code => <<'CODE'
{
uri = g_strdup (gimp_image_get_imported_uri (image));
}
CODE
);
}
sub image_get_exported_uri {
$blurb = "Returns the exported URI for the specified image.";
$help = <<'HELP';
This procedure returns the URI associated with the specified image
if the image was exported a non-native GIMP format. If the
image was not exported, this procedure returns %NULL.
HELP
$author = 'Eric Grivel <gimp@lumenssolutions.com>';
$copyright = 'Eric Grivel';
$date = '2011';
$since = '2.8';
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' }
);
@outargs = (
{ name => 'uri', type => 'string',
desc => 'The exported URI' }
);
%invoke = (
code => <<'CODE'
{
uri = g_strdup (gimp_image_get_exported_uri (image));
}
CODE
);
}
sub image_get_name {
$blurb = "Returns the specified image's name.";
$help = <<'HELP';
......@@ -2742,6 +2845,9 @@ CODE
image_get_component_visible image_set_component_visible
image_get_filename image_set_filename
image_get_uri
image_get_xcf_uri
image_get_imported_uri
image_get_exported_uri
image_get_name
image_get_resolution image_set_resolution
image_get_unit image_set_unit
......@@ -2753,7 +2859,11 @@ CODE
image_get_parasite
image_get_parasite_list);
%exports = (app => [@procs], lib => [@procs[0..42,45..77]]);
# For the lib parameter EXCLUDE functions #43 and #44, which are
# image_add_layer_mask and image_remove_layer_mask.
# If adding or removing functions, make sure the range below is
# updated correctly!
%exports = (app => [@procs], lib => [@procs[0..42,45..80]]);
$desc = 'Image';
$doc_title = 'gimpimage';
......
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