app, libgimp, pdb: new private PDB call _gimp_resource_get_identifiers().

This commit is contained in:
Jehan 2023-07-20 00:46:06 +02:00
parent 1a9c470b82
commit fe58de7f81
5 changed files with 195 additions and 15 deletions

View File

@ -30,7 +30,7 @@
#include "internal-procs.h"
/* 773 procedures registered total */
/* 774 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)

View File

@ -297,6 +297,41 @@ resource_get_name_invoker (GimpProcedure *procedure,
return return_vals;
}
static GimpValueArray *
resource_get_identifiers_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
GimpResource *resource;
gboolean is_internal = FALSE;
gchar *name = NULL;
gchar *collection_id = NULL;
resource = g_value_get_object (gimp_value_array_index (args, 0));
if (success)
{
gimp_data_get_identifiers (GIMP_DATA (resource), &name, &collection_id, &is_internal);
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
{
g_value_set_boolean (gimp_value_array_index (return_vals, 1), is_internal);
g_value_take_string (gimp_value_array_index (return_vals, 2), name);
g_value_take_string (gimp_value_array_index (return_vals, 3), collection_id);
}
return return_vals;
}
static GimpValueArray *
resource_is_editable_invoker (GimpProcedure *procedure,
Gimp *gimp,
@ -673,6 +708,50 @@ register_resource_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-resource-get-identifiers
*/
procedure = gimp_procedure_new (resource_get_identifiers_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-resource-get-identifiers");
gimp_procedure_set_static_help (procedure,
"Returns a triplet identifying the resource.",
"This procedure returns 2 strings and a boolean. The first string is the resource name, similar to what you would obtain calling 'gimp-resource-get-name'. The second is an opaque identifier for the collection this resource belongs to.\n"
"Note: as far as GIMP is concerned, a collection of resource usually corresponds to a single file on disk (which may or may not contain several resources). Therefore the identifier may be derived from the local file path. Nevertheless you should not use this string as such as this is not guaranteed to be always the case. You should consider it as an opaque identifier only to be used again through _'gimp-resource-get-by-identifier'.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2023");
gimp_procedure_add_argument (procedure,
gimp_param_spec_resource ("resource",
"resource",
"The resource",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_boolean ("is-internal",
"is internal",
"Whether this is the identifier for internal data",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_string ("name",
"name",
"The resource's name",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_string ("collection-id",
"collection id",
"The resource's collection identifier",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-resource-is-editable
*/

View File

@ -332,6 +332,60 @@ gimp_resource_get_name (GimpResource *resource)
return name;
}
/**
* _gimp_resource_get_identifiers:
* @resource: The resource.
* @name: (out) (transfer full): The resource's name.
* @collection_id: (out) (transfer full): The resource's collection identifier.
*
* Returns a triplet identifying the resource.
*
* This procedure returns 2 strings and a boolean. The first string is
* the resource name, similar to what you would obtain calling
* gimp_resource_get_name(). The second is an opaque identifier for the
* collection this resource belongs to.
* Note: as far as GIMP is concerned, a collection of resource usually
* corresponds to a single file on disk (which may or may not contain
* several resources). Therefore the identifier may be derived from the
* local file path. Nevertheless you should not use this string as such
* as this is not guaranteed to be always the case. You should consider
* it as an opaque identifier only to be used again through
* _gimp_resource_get_by_identifier().
*
* Returns: Whether this is the identifier for internal data.
*
* Since: 3.0
**/
gboolean
_gimp_resource_get_identifiers (GimpResource *resource,
gchar **name,
gchar **collection_id)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean is_internal = FALSE;
args = gimp_value_array_new_from_types (NULL,
GIMP_TYPE_RESOURCE, resource,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-resource-get-identifiers",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
{
is_internal = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
*name = GIMP_VALUES_DUP_STRING (return_vals, 2);
*collection_id = GIMP_VALUES_DUP_STRING (return_vals, 3);
}
gimp_value_array_unref (return_vals);
return is_internal;
}
/**
* gimp_resource_is_editable:
* @resource: The resource.

View File

@ -32,20 +32,23 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
G_GNUC_INTERNAL GimpResource* _gimp_resource_get_by_name (const gchar *type_name,
const gchar *resource_name);
gboolean gimp_resource_id_is_valid (gint resource_id);
gboolean gimp_resource_id_is_brush (gint resource_id);
gboolean gimp_resource_id_is_pattern (gint resource_id);
gboolean gimp_resource_id_is_gradient (gint resource_id);
gboolean gimp_resource_id_is_palette (gint resource_id);
gboolean gimp_resource_id_is_font (gint resource_id);
gchar* gimp_resource_get_name (GimpResource *resource);
gboolean gimp_resource_is_editable (GimpResource *resource);
GimpResource* gimp_resource_duplicate (GimpResource *resource);
gboolean gimp_resource_rename (GimpResource *resource,
const gchar *new_name);
gboolean gimp_resource_delete (GimpResource *resource);
G_GNUC_INTERNAL GimpResource* _gimp_resource_get_by_name (const gchar *type_name,
const gchar *resource_name);
gboolean gimp_resource_id_is_valid (gint resource_id);
gboolean gimp_resource_id_is_brush (gint resource_id);
gboolean gimp_resource_id_is_pattern (gint resource_id);
gboolean gimp_resource_id_is_gradient (gint resource_id);
gboolean gimp_resource_id_is_palette (gint resource_id);
gboolean gimp_resource_id_is_font (gint resource_id);
gchar* gimp_resource_get_name (GimpResource *resource);
G_GNUC_INTERNAL gboolean _gimp_resource_get_identifiers (GimpResource *resource,
gchar **name,
gchar **collection_id);
gboolean gimp_resource_is_editable (GimpResource *resource);
GimpResource* gimp_resource_duplicate (GimpResource *resource);
gboolean gimp_resource_rename (GimpResource *resource,
const gchar *new_name);
gboolean gimp_resource_delete (GimpResource *resource);
G_END_DECLS

View File

@ -259,6 +259,49 @@ CODE
);
}
sub resource_get_identifiers {
$blurb = "Returns a triplet identifying the resource.";
$help = <<HELP;
This procedure returns 2 strings and a boolean. The first string is the resource
name, similar to what you would obtain calling gimp_resource_get_name(). The
second is an opaque identifier for the collection this resource belongs to.
Note: as far as GIMP is concerned, a collection of resource usually corresponds
to a single file on disk (which may or may not contain several resources).
Therefore the identifier may be derived from the local file path. Nevertheless
you should not use this string as such as this is not guaranteed to be always
the case. You should consider it as an opaque identifier only to be used again
through _gimp_resource_get_by_identifier().
HELP
&jehan_pdb_misc('2023', '3.0');
$lib_private = 1;
@inargs = (
{ name => 'resource', type => 'resource',
desc => 'The resource' }
);
@outargs = (
{ name => 'is_internal', type => 'boolean',
desc => 'Whether this is the identifier for internal data'},
{ name => 'name', type => 'string',
desc => "The resource's name" },
{ name => 'collection_id', type => 'string',
desc => "The resource's collection identifier" }
);
%invoke = (
code => <<'CODE'
{
gimp_data_get_identifiers (GIMP_DATA (resource), &name, &collection_id, &is_internal);
}
CODE
);
}
sub resource_is_editable {
$blurb = "Whether the resource can be edited.";
$help = "Returns TRUE if you have permission to change the resource.";
@ -404,6 +447,7 @@ CODE
resource_id_is_palette
resource_id_is_font
resource_get_name
resource_get_identifiers
resource_is_editable
resource_duplicate
resource_rename